dolphin-weex-ui 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,49 @@
1
1
  <template>
2
2
  <div class="dof-slider" @touchstart="onTouchStart" @horizontalpan="onTouchMove" @touchend="onTouchEnd">
3
3
  <div class="dof-slider-track" ref="track" :style="trackStyle">
4
- <div :class="['dof-slider-bar', barColor ? '' : `dof-slider-bar--${this.theme}`]" ref="bar" :style="barStyle">
5
- <div class="dof-slider-button" v-for="(itemStyle, i) in buttonStyle" :key="i" :style="itemStyle"></div>
4
+ <div v-if="isThinBar" class="dof-slider-thin-bar" :style="thinBarStyle">
5
+ <div
6
+ class="dof-slider-thin-bar-left"
7
+ v-if="gradientBarConfig.mid"
8
+ :style="{
9
+ backgroundImage: `linear-gradient(to right, ${gradientBarConfig.start}, ${gradientBarConfig.mid})`,
10
+ right: midWidth + 'px'
11
+ }"
12
+ ></div>
13
+ <div
14
+ v-if="gradientBarConfig.mid"
15
+ class="dof-slider-thin-bar-right"
16
+ :style="{
17
+ backgroundImage: `linear-gradient(to right, ${gradientBarConfig.mid}, ${gradientBarConfig.end})`,
18
+ left: midWidth + 'px'
19
+ }"
20
+ ></div>
21
+ <div
22
+ class="dof-slider-thin-bar-left"
23
+ v-if="!gradientBarConfig.mid"
24
+ :style="{
25
+ backgroundImage: `linear-gradient(to right, ${gradientBarConfig.start}, ${gradientBarConfig.end})`,
26
+ right: 0 + 'px'
27
+ }"
28
+ ></div>
29
+ </div>
30
+ <div
31
+ :class="['dof-slider-bar', barColor || isThinBar ? '' : `dof-slider-bar--${this.theme}`]"
32
+ ref="bar"
33
+ :style="barStyle"
34
+ >
35
+ <div
36
+ :class="['dof-slider-button', isTouching ? 'dof-slider-button-touching' : '']"
37
+ v-for="(itemStyle, i) in buttonStyle"
38
+ :key="i"
39
+ :style="itemStyle"
40
+ ></div>
6
41
  </div>
7
42
  </div>
8
43
  <div class="dof-slider-scales" v-if="$slots.default">
9
44
  <slot></slot>
10
45
  </div>
46
+ <div class="dof-slider-disabled-mask" v-if="isThinBar && disabled" @touchstart="() => {}"></div>
11
47
  </div>
12
48
  </template>
13
49
 
@@ -68,6 +104,10 @@ export default {
68
104
  delay: {
69
105
  type: Number,
70
106
  default: 50
107
+ },
108
+ gradientBarConfig: {
109
+ type: Object,
110
+ default: () => ({})
71
111
  }
72
112
  },
73
113
  model: {
@@ -82,7 +122,8 @@ export default {
82
122
  width: 0,
83
123
  dragTargetIndex: null, // 0 1
84
124
  startRight: null,
85
- prevScreenX: null
125
+ prevScreenX: null,
126
+ isTouching: false
86
127
  }
87
128
  },
88
129
  computed: {
@@ -90,17 +131,29 @@ export default {
90
131
  isBoth() {
91
132
  return Object.prototype.toString.call(this.value) === '[object Array]'
92
133
  },
134
+ // 是否细bar
135
+ isThinBar() {
136
+ return this.gradientBarConfig.start && this.gradientBarConfig.end
137
+ },
93
138
  scope() {
94
139
  return this.max - this.min
95
140
  },
96
141
  interactive() {
97
142
  return !this.disabled && !this.readonly
98
143
  },
144
+ _trackHeight() {
145
+ if (this.isThinBar) return this.buttonSize * 1.6
146
+ return this.trackHeight
147
+ },
99
148
  trackStyle() {
100
149
  const res = {
101
- height: `${this.trackHeight}px`,
150
+ height: `${this._trackHeight}px`,
102
151
  backgroundColor: this.trackColor,
103
- borderRadius: `${this.trackHeight / 2}px`
152
+ borderRadius: `${this._trackHeight / 2}px`
153
+ }
154
+ // 细bar样式
155
+ if (this.isThinBar) {
156
+ res.backgroundColor = 'transparent'
104
157
  }
105
158
  return res
106
159
  },
@@ -113,23 +166,23 @@ export default {
113
166
  }
114
167
 
115
168
  // const width = ((this.value - this.min) / this.scope) * this.width
116
- // const widthCss = clamp(width+this.trackHeight, this.trackHeight, this.width)
169
+ // const widthCss = clamp(width+this._trackHeight, this._trackHeight, this.width)
117
170
 
118
- // fix: 修复value带来的width小于this.trackHeight时,bar宽度不变
171
+ // fix: 修复value带来的width小于this._trackHeight时,bar宽度不变
119
172
  const width = percent * this.width
120
- let widthCss = this.trackHeight
173
+ let widthCss = this._trackHeight
121
174
  if (percent < 0) {
122
- widthCss = this.trackHeight
175
+ widthCss = this._trackHeight
123
176
  } else if (percent > 1) {
124
- widthCss = this.width + this.trackHeight
177
+ widthCss = this.width + this._trackHeight
125
178
  } else {
126
179
  // 正常滑动
127
- widthCss = width + this.trackHeight
180
+ widthCss = width + this._trackHeight
128
181
  }
129
182
  const res = {
130
183
  width: `${widthCss}px`,
131
- borderRadius: `${this.trackHeight / 2}px`,
132
- height: `${this.trackHeight}px`
184
+ borderRadius: `${this._trackHeight / 2}px`,
185
+ height: `${this._trackHeight}px`
133
186
  }
134
187
 
135
188
  if (this.isBoth) res.left = ((Math.max(this.value[0], this.min) - this.min) / this.scope) * this.width + 'px'
@@ -137,24 +190,45 @@ export default {
137
190
  if (this.barColor) {
138
191
  res.backgroundColor = this.barColor
139
192
  }
193
+ // 细bar样式
194
+ if (this.isThinBar) {
195
+ res.backgroundColor = 'transparent'
196
+ }
140
197
  return res
141
198
  },
142
199
  buttonStyle() {
200
+ // const buttonSize = !this.isTouching ? `${this.buttonSize}` : `${this.buttonSize + 16}`
201
+ const buttonSize = this.buttonSize
143
202
  const res = {
144
- top: `${(this.trackHeight - this.buttonSize) / 2}px`,
145
- // right: `${(this.trackHeight - this.buttonSize) / 2}px`,
146
- width: `${this.buttonSize}px`,
147
- height: `${this.buttonSize}px`,
148
- borderRadius: `${this.buttonSize / 2}px`,
203
+ top: `${(this._trackHeight - buttonSize) / 2}px`,
204
+ // right: `${(this._trackHeight - this.buttonSize) / 2}px`,
205
+ width: `${buttonSize}px`,
206
+ height: `${buttonSize}px`,
207
+ borderRadius: `${buttonSize / 2}px`,
149
208
  backgroundColor: this.buttonColor
150
209
  }
151
- const buttonPadding = (this.trackHeight - this.buttonSize) / 2
210
+ const buttonPadding = (this._trackHeight - buttonSize) / 2
152
211
  return this.isBoth
153
212
  ? [
154
213
  { ...res, left: `${buttonPadding}px` },
155
214
  { ...res, right: `${buttonPadding}px` }
156
215
  ]
157
216
  : [{ ...res, right: `${buttonPadding}px` }]
217
+ },
218
+ thinBarStyle() {
219
+ const buttonPadding = (this._trackHeight - this.buttonSize) / 2
220
+ const res = {
221
+ top: `${(this._trackHeight - 4) / 2}px`,
222
+ left: `${buttonPadding}px`,
223
+ right: `${buttonPadding}px`,
224
+ height: '4px'
225
+ // ios 线性渐变要写成行内
226
+ // backgroundImage: `linear-gradient(to right, ${this.gradientBarConfig.start}, ${this.gradientBarConfig.end});`
227
+ }
228
+ return res
229
+ },
230
+ midWidth() {
231
+ return this.width / 2
158
232
  }
159
233
  },
160
234
  mounted() {
@@ -163,7 +237,7 @@ export default {
163
237
  res => {
164
238
  if (res.result) {
165
239
  // 实际可滑动长度(可变化范围)= bar宽度 - btn宽度
166
- this.width = res.size.width - this.trackHeight
240
+ this.width = res.size.width - this._trackHeight
167
241
  }
168
242
  },
169
243
  this.delay
@@ -174,7 +248,7 @@ export default {
174
248
  if (!this.interactive) {
175
249
  return
176
250
  }
177
-
251
+ if (this.isThinBar) this.isTouching = true
178
252
  this.touch.start(e)
179
253
 
180
254
  if (this.isBoth) {
@@ -216,6 +290,7 @@ export default {
216
290
  if (!this.interactive) {
217
291
  return
218
292
  }
293
+ this.isTouching = false
219
294
  // 点按
220
295
  if (this.startValue === this.current) {
221
296
  const total = this.width
@@ -281,6 +356,7 @@ export default {
281
356
  <style scoped>
282
357
  .dof-slider {
283
358
  flex-direction: column;
359
+ position: relative;
284
360
  }
285
361
 
286
362
  .dof-slider-track {
@@ -323,10 +399,40 @@ export default {
323
399
 
324
400
  .dof-slider-button {
325
401
  position: absolute;
402
+ transition-property: transform;
403
+ transition-duration: 0.3s;
404
+ transition-delay: 0s;
405
+ transform: scale(1);
406
+ }
407
+ .dof-slider-button-touching {
408
+ transform: scale(1.5);
326
409
  }
327
410
  .dof-slider-scales {
328
411
  position: relative;
329
412
  margin-top: 16px;
330
413
  height: 24px;
331
414
  }
415
+ .dof-slider-thin-bar {
416
+ position: absolute;
417
+ }
418
+ .dof-slider-thin-bar-left {
419
+ position: absolute;
420
+ height: 4px;
421
+ top: 0px;
422
+ left: 0px;
423
+ }
424
+ .dof-slider-thin-bar-right {
425
+ position: absolute;
426
+ height: 4px;
427
+ top: 0px;
428
+ right: 0px;
429
+ }
430
+ .dof-slider-disabled-mask {
431
+ position: absolute;
432
+ top: 0;
433
+ left: 0;
434
+ right: 0;
435
+ bottom: 0;
436
+ background-color: rgba(0, 0, 0, 0.5);
437
+ }
332
438
  </style>
@@ -13,6 +13,11 @@ export default {
13
13
  value: {
14
14
  type: Number,
15
15
  required: true
16
+ },
17
+ color: {
18
+ type: String,
19
+ required: false,
20
+ default: '#8a8a8f'
16
21
  }
17
22
  },
18
23
  computed: {
@@ -23,9 +28,16 @@ export default {
23
28
  return this.value <= this.$parent.min
24
29
  },
25
30
  style() {
26
- const style = {}
31
+ const style = {
32
+ color: this.color
33
+ }
27
34
  const left = ((this.value - this.$parent.min) / this.$parent.scope) * this.$parent.width
28
35
  style.left = `${left}px`
36
+ // 防止超出的情况
37
+ if (this.isLast) {
38
+ delete style.left
39
+ style.right = '0px'
40
+ }
29
41
  return style
30
42
  }
31
43
  }
@@ -47,6 +59,6 @@ export default {
47
59
  }
48
60
 
49
61
  .dof-slider-scale--last {
50
- /* transform: translate(-100%, 0px); */
62
+ /* transform: translate(-50%, 0px); */
51
63
  }
52
64
  </style>
@@ -125,6 +125,10 @@
125
125
  border-width: 0px;
126
126
  background-color: #1f94d2;
127
127
  }
128
+ .switch-active-colmo {
129
+ border-width: 0px;
130
+ background-color: #b35336;
131
+ }
128
132
  .switch-disabled {
129
133
  opacity: 0.3;
130
134
  }