|
3 | 3 | <view class="u-demo-wrap">
|
4 | 4 | <view class="u-demo-title">演示效果</view>
|
5 | 5 | <view class="u-demo-area">
|
6 |
| - <view class="u-demo-result-line"> |
7 |
| - {{input ? input : 'Picker值'}} |
8 |
| - </view> |
9 |
| - <u-picker :mode="mode" :defaultTime="defaultTime" v-model="show" |
10 |
| - :defaultRegion="defaultRegion" :params="params" @confirm="confirm"></u-picker> |
| 6 | + <view class="u-demo-result-line">{{ input ? input : 'Picker值' }}</view> |
| 7 | + <u-picker |
| 8 | + :mode="mode" |
| 9 | + :defaultTime="defaultTime" |
| 10 | + v-model="show" |
| 11 | + :defaultRegion="defaultRegion" |
| 12 | + :params="params" |
| 13 | + @confirm="confirm" |
| 14 | + :defaultSelector="defaultSelector" |
| 15 | + :range="range" |
| 16 | + :range-key="rangKey" |
| 17 | + @columnchange="columnchange" |
| 18 | + ></u-picker> |
11 | 19 | </view>
|
12 | 20 | </view>
|
13 | 21 | <view class="u-config-wrap">
|
14 |
| - <view class="u-config-title u-border-bottom"> |
15 |
| - 参数配置 |
16 |
| - </view> |
| 22 | + <view class="u-config-title u-border-bottom">参数配置</view> |
17 | 23 | <view class="u-config-item">
|
18 | 24 | <view class="u-item-title">Picker开关</view>
|
19 | 25 | <u-subsection vibrateShort :current="status" :list="['显示', '隐藏']" @change="statusChange"></u-subsection>
|
20 | 26 | </view>
|
21 | 27 | <view class="u-config-item">
|
22 | 28 | <view class="u-item-title">模式选择</view>
|
23 |
| - <u-subsection vibrateShort :list="['时间', '地区']" @change="modeChange"></u-subsection> |
| 29 | + <u-subsection vibrateShort :list="['单列', '多列', '时间', '地区']" @change="modeChange"></u-subsection> |
24 | 30 | </view>
|
25 | 31 | <view class="u-config-item">
|
26 | 32 | <view class="u-item-title">默认时间</view>
|
|
39 | 45 | </template>
|
40 | 46 |
|
41 | 47 | <script>
|
42 |
| - export default { |
43 |
| - data() { |
44 |
| - return { |
45 |
| - show: false, |
46 |
| - input: '', |
47 |
| - mode: 'time', |
48 |
| - defaultTime: '2019-12-11 20:15:35', |
49 |
| - defaultRegion: ['广东省', '深圳市', '宝安区'], |
50 |
| - params: { |
51 |
| - year: true, |
52 |
| - month: true, |
53 |
| - day: true, |
54 |
| - hour: true, |
55 |
| - minute: true, |
56 |
| - second: true, |
57 |
| - province: true, |
58 |
| - city: true, |
59 |
| - area: true |
60 |
| - } |
| 48 | +export default { |
| 49 | + data() { |
| 50 | + return { |
| 51 | + show: false, |
| 52 | + input: '', |
| 53 | + rangKey: 'name', |
| 54 | + mode: 'selector', |
| 55 | + range: ['一', '片', '冰', '心', '在', '玉', '壶'], |
| 56 | + defaultTime: '2019-12-11 20:15:35', |
| 57 | + defaultSelector: [0], |
| 58 | + defaultRegion: ['广东省', '深圳市', '宝安区'], |
| 59 | + params: { |
| 60 | + year: true, |
| 61 | + month: true, |
| 62 | + day: true, |
| 63 | + hour: true, |
| 64 | + minute: true, |
| 65 | + second: true, |
| 66 | + province: true, |
| 67 | + city: true, |
| 68 | + area: true |
61 | 69 | }
|
| 70 | + }; |
| 71 | + }, |
| 72 | + computed: { |
| 73 | + status() { |
| 74 | + return this.show == true ? 0 : 1; |
| 75 | + } |
| 76 | + }, |
| 77 | + methods: { |
| 78 | + statusChange(index) { |
| 79 | + this.show = index == 0 ? true : false; |
62 | 80 | },
|
63 |
| - computed: { |
64 |
| - status() { |
65 |
| - return this.show == true ? 0 : 1; |
| 81 | + modeChange(index) { |
| 82 | + this.mode = ['selector', 'multiSelector', 'time', 'region'][index]; |
| 83 | + if (this.mode == 'selector') { |
| 84 | + this.range = ['一', '片', '冰', '心', '在', '玉', '壶']; |
| 85 | + this.defaultSelector = [0]; |
| 86 | + } |
| 87 | + if (this.mode == 'multiSelector') { |
| 88 | + this.range = [['亚洲', '欧洲'], ['中国', '日本'], ['北京', '上海', '广州']]; |
| 89 | + this.defaultSelector = [0, 0, 0]; |
66 | 90 | }
|
| 91 | + this.show = true; |
| 92 | + }, |
| 93 | + defaultTimeChange(index) { |
| 94 | + this.defaultTime = index == 0 ? '2019-12-11 20:15:35' : '2020-02-05 13:09:42'; |
| 95 | + this.mode = 'time'; |
| 96 | + this.show = true; |
67 | 97 | },
|
68 |
| - methods: { |
69 |
| - statusChange(index) { |
70 |
| - this.show = index == 0 ? true : false; |
71 |
| - }, |
72 |
| - modeChange(index) { |
73 |
| - this.mode = index == 0 ? 'time' : 'region'; |
74 |
| - this.show = true; |
75 |
| - }, |
76 |
| - defaultTimeChange(index) { |
77 |
| - this.defaultTime = index == 0 ? '2019-12-11 20:15:35' : '2020-02-05 13:09:42'; |
78 |
| - this.mode = 'time'; |
79 |
| - this.show = true; |
80 |
| - }, |
81 |
| - defaultRegionChange(index) { |
82 |
| - this.defaultRegion = index == 0 ? ['广东省', '深圳市', '宝安区'] : ['海南省','三亚市', '海棠区']; |
83 |
| - this.mode = 'region'; |
84 |
| - this.show = true; |
85 |
| - }, |
86 |
| - minSecChange(index) { |
87 |
| - if(index == 0) { |
88 |
| - this.params.hour = true; |
89 |
| - this.params.minute = true; |
90 |
| - this.params.second = true; |
91 |
| - } |
92 |
| - if(index == 1) { |
93 |
| - this.params.hour = false; |
94 |
| - this.params.minute = false; |
95 |
| - this.params.second = false; |
96 |
| - } |
97 |
| - this.mode = 'time'; |
98 |
| - this.show = true; |
99 |
| - }, |
100 |
| - confirm(e) { |
101 |
| - this.input = ''; |
102 |
| - if(this.mode == 'time') { |
103 |
| - if(this.params.year) this.input += e.year; |
104 |
| - if(this.params.month) this.input += '-' + e.month; |
105 |
| - if(this.params.day) this.input += '-' + e.day; |
106 |
| - if(this.params.hour) this.input += " " + e.day; |
107 |
| - if(this.params.minute) this.input += ':' + e.minute; |
108 |
| - if(this.params.second) this.input += ':' + e.second; |
109 |
| - } else { |
110 |
| - this.input = e.province.label + '-' + e.city.label + '-' + e.area.label; |
111 |
| - } |
| 98 | + defaultRegionChange(index) { |
| 99 | + this.defaultRegion = index == 0 ? ['广东省', '深圳市', '宝安区'] : ['海南省', '三亚市', '海棠区']; |
| 100 | + this.mode = 'region'; |
| 101 | + this.show = true; |
| 102 | + }, |
| 103 | + minSecChange(index) { |
| 104 | + if (index == 0) { |
| 105 | + this.params.hour = true; |
| 106 | + this.params.minute = true; |
| 107 | + this.params.second = true; |
| 108 | + } |
| 109 | + if (index == 1) { |
| 110 | + this.params.hour = false; |
| 111 | + this.params.minute = false; |
| 112 | + this.params.second = false; |
112 | 113 | }
|
| 114 | + this.mode = 'time'; |
| 115 | + this.show = true; |
113 | 116 | },
|
| 117 | + confirm(e) { |
| 118 | + this.input = ''; |
| 119 | + if (this.mode == 'time') { |
| 120 | + if (this.params.year) this.input += e.year; |
| 121 | + if (this.params.month) this.input += '-' + e.month; |
| 122 | + if (this.params.day) this.input += '-' + e.day; |
| 123 | + if (this.params.hour) this.input += ' ' + e.day; |
| 124 | + if (this.params.minute) this.input += ':' + e.minute; |
| 125 | + if (this.params.second) this.input += ':' + e.second; |
| 126 | + } else if (this.mode == 'region') { |
| 127 | + this.input = e.province.label + '-' + e.city.label + '-' + e.area.label; |
| 128 | + } else if (this.mode == 'selector') { |
| 129 | + this.input = this.range[e[0]]; |
| 130 | + } else if (this.mode == 'multiSelector') { |
| 131 | + this.input = this.range[0][e[0]] + '-' + this.range[1][e[1]] + '-' + this.range[2][e[2]]; |
| 132 | + } |
| 133 | + }, |
| 134 | + columnchange(e) { |
| 135 | + let column = e.column, index = e.index; |
| 136 | + this.defaultSelector.splice(column, 1, index) |
| 137 | + switch (column) { |
| 138 | + case 0: |
| 139 | + switch (index) { |
| 140 | + case 0: |
| 141 | + this.range[1] = ['中国', '日本'] |
| 142 | + this.range[2] = ['北京', '上海', '广州'] |
| 143 | + break |
| 144 | + case 1: |
| 145 | + this.range[1] = ['英国', '法国'] |
| 146 | + this.range[2] = ['伦敦', '曼彻斯特'] |
| 147 | + break |
| 148 | + } |
| 149 | + this.defaultSelector.splice(1, 1, 0) |
| 150 | + this.defaultSelector.splice(2, 1, 0) |
| 151 | + break |
| 152 | + case 1: //拖动第2列 |
| 153 | + switch (this.defaultSelector[0]) { //判断第一列是什么 |
| 154 | + case 0: |
| 155 | + switch (this.defaultSelector[1]) { |
| 156 | + case 0: |
| 157 | + this.range[2] = ['北京', '上海', '广州'] |
| 158 | + break |
| 159 | + case 1: |
| 160 | + this.range[2] = ['东京','北海道'] |
| 161 | + break |
| 162 | + } |
| 163 | + break |
| 164 | + case 1: |
| 165 | + switch (this.defaultSelector[1]) { |
| 166 | + case 0: |
| 167 | + this.range[2] = ['伦敦', '曼彻斯特'] |
| 168 | + break |
| 169 | + case 1: |
| 170 | + this.range[2] = ['巴黎', '马赛'] |
| 171 | + break |
| 172 | + } |
| 173 | + break |
| 174 | + } |
| 175 | + this.defaultSelector.splice(2, 1, 0) |
| 176 | + break |
| 177 | + } |
| 178 | + this.$forceUpdate() |
| 179 | + } |
114 | 180 | }
|
| 181 | +}; |
115 | 182 | </script>
|
116 | 183 |
|
117 | 184 | <style lang="scss" scoped>
|
118 |
| - .input { |
119 |
| - border: 1px solid $u-light-color; |
120 |
| - border-radius: 4px; |
121 |
| - margin-bottom: 20px; |
122 |
| - height: 30px; |
123 |
| - font-size: 26rpx; |
124 |
| - flex: 1; |
125 |
| - } |
126 |
| - |
127 |
| - .input-wrap { |
128 |
| - display: flex; |
129 |
| - } |
| 185 | +.input { |
| 186 | + border: 1px solid $u-light-color; |
| 187 | + border-radius: 4px; |
| 188 | + margin-bottom: 20px; |
| 189 | + height: 30px; |
| 190 | + font-size: 26rpx; |
| 191 | + flex: 1; |
| 192 | +} |
| 193 | +
|
| 194 | +.input-wrap { |
| 195 | + display: flex; |
| 196 | +} |
130 | 197 | </style>
|
0 commit comments