progress.uvue 6.0 KB
Newer Older
1
<script>
雪洛's avatar
雪洛 已提交
2
import { ItemType } from '@/components/enum-data/enum-data'
3 4 5 6 7 8 9 10 11 12 13
export default {
	data() {
		return {
			title: 'progress',
			pgList: [0, 0, 0, 0] as number[],
			curPercent: 0,
			showInfo: true,
			borderRadius: 0,
			fontSize: 16,
			strokeWidth: 3,
			backgroundColor: '#EBEBEB',
Y
yurj26 已提交
14

15 16 17 18 19 20 21 22 23 24
			// 组件属性 autotest
			active_boolean: false,
			show_info_boolean: false,
			duration_input: 30,
			percent_input: 0,
			stroke_width_input: 6,
			activeColor_input: "#09BB07",
			backgroundColor_input: "#EBEBEB",
			active_mode_enum: [{ "value": 0, "name": "backwards" }, { "value": 1, "name": "forwards" }] as ItemType[],
			active_mode_enum_current: 0
25
		}
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
	},
	methods: {
		setProgress() {
			this.pgList = [20, 40, 60, 80] as number[]
		},
		clearProgress() {
			this.pgList = [0, 0, 0, 0] as number[]
		},
		activeend(e : ProgressActiveendEvent) {
			this.curPercent = e.detail.curPercent
		},
		progress_touchstart() { console.log("手指触摸动作开始") },
		progress_touchmove() { console.log("手指触摸后移动") },
		progress_touchcancel() { console.log("手指触摸动作被打断,如来电提醒,弹窗") },
		progress_touchend() { console.log("手指触摸动作结束") },
		progress_tap() { console.log("手指触摸后马上离开") },
		change_active_boolean(checked : boolean) { this.active_boolean = checked },
		change_show_info_boolean(checked : boolean) { this.show_info_boolean = checked },
		confirm_duration_input(value : number) { this.duration_input = value },
		confirm_percent_input(value : number) { this.percent_input = value },
		confirm_stroke_width_input(value : number) { this.stroke_width_input = value },
		confirm_activeColor_input(value : string) { this.activeColor_input = value },
		confirm_backgroundColor_input(value : string) { this.backgroundColor_input = value },
		radio_change_active_mode_enum(checked : number) { this.active_mode_enum_current = checked }
50
	}
51
}
Y
init  
yurj26 已提交
52 53
</script>

54
<template>
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  <view class="main">
    <progress
      :duration="duration_input"
      :percent="percent_input"
      :show-info="show_info_boolean"
      :stroke-width="stroke_width_input"
      :activeColor="activeColor_input"
      :backgroundColor="backgroundColor_input"
      :active="active_boolean"
      :active-mode="active_mode_enum[active_mode_enum_current].name"
      @touchstart="progress_touchstart"
      @touchmove="progress_touchmove"
      @touchcancel="progress_touchcancel"
      @touchend="progress_touchend"
      @tap="progress_tap"
      style="width: 80%"
    >
      <text>uni-app-x</text>
    </progress>
  </view>
75

76 77 78
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
A
Anne_LXM 已提交
79
    <view class="content">
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
      <page-head title="组件属性"></page-head>
      <boolean-data
        :defaultValue="false"
        title="进度条从左往右的动画"
        @change="change_active_boolean"
      ></boolean-data>
      <boolean-data
        :defaultValue="false"
        title="在进度条右侧显示百分比"
        @change="change_show_info_boolean"
      ></boolean-data>
      <input-data
        defaultValue="30"
        title="进度增加1%所需毫秒数"
        type="number"
        @confirm="confirm_duration_input"
      ></input-data>
      <input-data
        defaultValue="0"
        title="百分比0~100"
        type="number"
        @confirm="confirm_percent_input"
      ></input-data>
      <input-data
        defaultValue="6"
        title="进度条线的宽度,单位px"
        type="number"
        @confirm="confirm_stroke_width_input"
      ></input-data>
      <input-data
        defaultValue="#09BB07"
        title="已选择的进度条的颜色"
        type="text"
        @confirm="confirm_activeColor_input"
      ></input-data>
      <input-data
        defaultValue="#EBEBEB"
        title="未选择的进度条的颜色"
        type="text"
        @confirm="confirm_backgroundColor_input"
      ></input-data>
      <enum-data
        :items="active_mode_enum"
        title="backwards: 动画从头播;forwards:动画从上次结束点接着播"
        @change="radio_change_active_mode_enum"
      ></enum-data>
    </view>
127

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    <view>
      <page-head title="默认及使用"></page-head>
      <view class="uni-padding-wrap uni-common-mt">
        <view class="progress-box">
          <progress
            :percent="pgList[0]"
            :active="true"
            :border-radius="borderRadius"
            :show-info="showInfo"
            :font-size="fontSize"
            :stroke-width="strokeWidth"
            :background-color="backgroundColor"
            class="progress p"
            @activeend="activeend"
          />
        </view>
        <view class="progress-box">
          <progress
            :percent="pgList[1]"
            :stroke-width="3"
            class="progress p1"
          />
        </view>
        <view class="progress-box">
          <progress
            :percent="pgList[2]"
            :stroke-width="3"
            class="progress p2"
          />
        </view>
        <view class="progress-box">
          <progress
            :percent="pgList[3]"
            activeColor="#10AEFF"
            :stroke-width="3"
            class="progress p3"
          />
        </view>
        <view class="progress-control">
          <button type="primary" @click="setProgress" class="button">
            设置进度
          </button>
          <button type="warn" @click="clearProgress" class="button">
            清除进度
          </button>
        </view>
      </view>
    </view>
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
179 180
</template>

Y
init  
yurj26 已提交
181
<style>
182 183 184 185 186 187 188
.main {
  max-height: 500rpx;
  padding: 10rpx 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  flex-direction: row;
  justify-content: center;
}
189

190 191 192 193 194
.main .list-item {
  width: 100%;
  height: 200rpx;
  border: 1px solid #666;
}
195

196 197 198 199
.progress-box {
  height: 50rpx;
  margin-bottom: 60rpx;
}
Y
init  
yurj26 已提交
200

201 202 203 204
.button {
  margin-top: 20rpx;
}
</style>