progress.uvue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <script>
  2. import { state, setEventCallbackNum } from '@/store/index.uts'
  3. import { ItemType } from '@/components/enum-data/enum-data-types'
  4. export default {
  5. data() {
  6. return {
  7. title: 'progress',
  8. pgList: [0, 0, 0, 0] as number[],
  9. curPercent: 0,
  10. showInfo: true,
  11. borderRadius: 0,
  12. fontSize: 16,
  13. strokeWidth: 3,
  14. backgroundColor: '#EBEBEB',
  15. // 组件属性 autotest
  16. active_boolean: false,
  17. show_info_boolean: false,
  18. duration_input: 30,
  19. percent_input: 0,
  20. stroke_width_input: 6,
  21. activeColor_input: "#09BB07",
  22. backgroundColor_input: "#EBEBEB",
  23. active_mode_enum: [{ "value": 0, "name": "backwards" }, { "value": 1, "name": "forwards" }] as ItemType[],
  24. active_mode_enum_current: 0
  25. }
  26. },
  27. methods: {
  28. // 自动化测试
  29. getEventCallbackNum() : number {
  30. return state.eventCallbackNum
  31. },
  32. // 自动化测试
  33. setEventCallbackNum(num : number) {
  34. setEventCallbackNum(num)
  35. },
  36. setProgress() {
  37. this.pgList = [20, 40, 60, 80] as number[]
  38. },
  39. clearProgress() {
  40. this.pgList = [0, 0, 0, 0] as number[]
  41. },
  42. activeend(e : UniProgressActiveendEvent) {
  43. // 自动化测试
  44. if ((e.target?.tagName ?? '').includes('PROGRESS')) {
  45. this.setEventCallbackNum(state.eventCallbackNum + 1)
  46. }
  47. if (e.type === 'activeend') {
  48. this.setEventCallbackNum(state.eventCallbackNum + 2)
  49. }
  50. this.curPercent = e.detail.curPercent
  51. },
  52. progress_touchstart() { console.log("手指触摸动作开始") },
  53. progress_touchmove() { console.log("手指触摸后移动") },
  54. progress_touchcancel() { console.log("手指触摸动作被打断,如来电提醒,弹窗") },
  55. progress_touchend() { console.log("手指触摸动作结束") },
  56. progress_tap() { console.log("手指触摸后马上离开") },
  57. change_active_boolean(checked : boolean) { this.active_boolean = checked },
  58. change_show_info_boolean(checked : boolean) { this.show_info_boolean = checked },
  59. confirm_duration_input(value : number) { this.duration_input = value },
  60. confirm_percent_input(value : number) { this.percent_input = value },
  61. confirm_stroke_width_input(value : number) { this.stroke_width_input = value },
  62. confirm_activeColor_input(value : string) { this.activeColor_input = value },
  63. confirm_backgroundColor_input(value : string) { this.backgroundColor_input = value },
  64. radio_change_active_mode_enum(checked : number) { this.active_mode_enum_current = checked }
  65. }
  66. }
  67. </script>
  68. <template>
  69. <view class="main">
  70. <progress :duration="duration_input" :percent="percent_input" :show-info="show_info_boolean"
  71. :stroke-width="stroke_width_input" :activeColor="activeColor_input" :backgroundColor="backgroundColor_input"
  72. :active="active_boolean" :active-mode="active_mode_enum[active_mode_enum_current].name"
  73. @touchstart="progress_touchstart" @touchmove="progress_touchmove" @touchcancel="progress_touchcancel"
  74. @touchend="progress_touchend" @tap="progress_tap" style="width: 80%">
  75. </progress>
  76. </view>
  77. <scroll-view style="flex: 1">
  78. <view class="content">
  79. <page-head title="组件属性"></page-head>
  80. <boolean-data :defaultValue="false" title="进度条从左往右的动画" @change="change_active_boolean"></boolean-data>
  81. <boolean-data :defaultValue="false" title="在进度条右侧显示百分比" @change="change_show_info_boolean"></boolean-data>
  82. <input-data defaultValue="30" title="进度增加1%所需毫秒数" type="number" @confirm="confirm_duration_input"></input-data>
  83. <input-data defaultValue="0" title="百分比0~100" type="number" @confirm="confirm_percent_input"></input-data>
  84. <input-data defaultValue="6" title="进度条线的宽度,单位px" type="number"
  85. @confirm="confirm_stroke_width_input"></input-data>
  86. <input-data defaultValue="#09BB07" title="已选择的进度条的颜色" type="text"
  87. @confirm="confirm_activeColor_input"></input-data>
  88. <input-data defaultValue="#EBEBEB" title="未选择的进度条的颜色" type="text"
  89. @confirm="confirm_backgroundColor_input"></input-data>
  90. <enum-data :items="active_mode_enum" title="backwards: 动画从头播;forwards:动画从上次结束点接着播"
  91. @change="radio_change_active_mode_enum"></enum-data>
  92. </view>
  93. <view>
  94. <page-head title="默认及使用"></page-head>
  95. <view class="uni-padding-wrap uni-common-mt">
  96. <view class="progress-box">
  97. <progress :percent="pgList[0]" :active="true" :border-radius="borderRadius" :show-info="showInfo"
  98. :font-size="fontSize" :stroke-width="strokeWidth" :background-color="backgroundColor" class="progress p"
  99. @activeend="activeend" />
  100. </view>
  101. <view class="progress-box">
  102. <progress :percent="pgList[1]" :stroke-width="3" class="progress p1" />
  103. </view>
  104. <view class="progress-box">
  105. <progress :percent="pgList[2]" :stroke-width="3" class="progress p2" />
  106. </view>
  107. <view class="progress-box">
  108. <progress :percent="pgList[3]" activeColor="#10AEFF" :stroke-width="3" class="progress p3" />
  109. </view>
  110. <view class="progress-control">
  111. <button type="primary" @click="setProgress" class="button">
  112. 设置进度
  113. </button>
  114. <button type="warn" @click="clearProgress" class="button">
  115. 清除进度
  116. </button>
  117. </view>
  118. </view>
  119. </view>
  120. </scroll-view>
  121. </template>
  122. <style>
  123. .main {
  124. max-height: 250px;
  125. padding: 5px 0;
  126. border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  127. flex-direction: row;
  128. justify-content: center;
  129. }
  130. .progress-box {
  131. height: 25px;
  132. margin-bottom: 30px;
  133. }
  134. .button {
  135. margin-top: 10px;
  136. }
  137. </style>