@tdesign/uniapp 0.7.3 → 0.8.0
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.
- package/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/dist/action-sheet/README.md +1 -1
- package/dist/action-sheet/action-sheet.vue +158 -150
- package/dist/action-sheet/props.ts +2 -2
- package/dist/action-sheet/type.ts +1 -1
- package/dist/avatar/avatar.vue +89 -87
- package/dist/avatar-group/avatar-group.vue +69 -67
- package/dist/back-top/back-top.vue +60 -58
- package/dist/badge/badge.vue +69 -59
- package/dist/button/button.vue +121 -116
- package/dist/button/props.ts +2 -2
- package/dist/button/type.ts +1 -1
- package/dist/calendar/calendar-header.vue +4 -4
- package/dist/calendar/calendar.vue +308 -297
- package/dist/calendar/template.vue +1 -1
- package/dist/cascader/README.en-US.md +2 -1
- package/dist/cascader/README.md +2 -1
- package/dist/cascader/cascader.vue +340 -328
- package/dist/cascader/props.ts +6 -1
- package/dist/cascader/type.ts +6 -0
- package/dist/cell/cell.vue +127 -121
- package/dist/cell-group/cell-group.vue +32 -30
- package/dist/check-tag/check-tag.vue +73 -71
- package/dist/checkbox/checkbox.vue +127 -127
- package/dist/checkbox/props.ts +6 -6
- package/dist/checkbox/type.ts +3 -3
- package/dist/checkbox-group/checkbox-group.vue +175 -173
- package/dist/checkbox-group/props.ts +6 -6
- package/dist/checkbox-group/type.ts +4 -4
- package/dist/col/col.vue +26 -24
- package/dist/collapse/collapse.vue +83 -81
- package/dist/collapse-panel/collapse-panel.vue +121 -119
- package/dist/collapse-panel/props.ts +4 -4
- package/dist/collapse-panel/type.ts +2 -2
- package/dist/color-picker/README.md +1 -1
- package/dist/color-picker/color-picker.vue +324 -322
- package/dist/color-picker/props.ts +2 -2
- package/dist/color-picker/template.vue +14 -10
- package/dist/common/common.ts +1 -0
- package/dist/common/style/theme/index.css +5 -5
- package/dist/common/utils.js +7 -2
- package/dist/common/validator.js +172 -0
- package/dist/config-provider/README.en-US.md +184 -0
- package/dist/config-provider/README.md +234 -0
- package/dist/config-provider/config-provider.vue +105 -0
- package/dist/config-provider/config-store.js +70 -0
- package/dist/config-provider/props.ts +16 -0
- package/dist/config-provider/reactive-state.js +39 -0
- package/dist/config-provider/type.ts +401 -0
- package/dist/config-provider/use-config.js +29 -0
- package/dist/config-provider/utils.js +29 -0
- package/dist/count-down/count-down.vue +98 -97
- package/dist/date-time-picker/date-time-picker.vue +410 -395
- package/dist/demo/demo.vue +1 -0
- package/dist/dialog/dialog.vue +175 -173
- package/dist/divider/divider.vue +38 -36
- package/dist/draggable/draggable.vue +60 -58
- package/dist/drawer/README.md +1 -1
- package/dist/drawer/drawer.vue +48 -46
- package/dist/dropdown-item/dropdown-item.vue +209 -207
- package/dist/dropdown-item/props.ts +4 -4
- package/dist/dropdown-item/type.ts +3 -3
- package/dist/dropdown-menu/dropdown-menu.vue +93 -99
- package/dist/empty/empty.vue +43 -42
- package/dist/fab/fab.vue +88 -86
- package/dist/footer/footer.vue +36 -34
- package/dist/form/README.en-US.md +17 -24
- package/dist/form/README.md +18 -25
- package/dist/form/form.css +1 -166
- package/dist/form/form.vue +251 -236
- package/dist/form/props.ts +2 -21
- package/dist/form/type.ts +7 -70
- package/dist/form-item/README.en-US.md +4 -5
- package/dist/form-item/README.md +4 -5
- package/dist/form-item/form-item.css +69 -96
- package/dist/form-item/form-item.vue +315 -336
- package/dist/form-item/form-model.ts +125 -173
- package/dist/form-item/props.ts +4 -17
- package/dist/form-item/type.ts +43 -1
- package/dist/grid/grid.vue +53 -51
- package/dist/grid-item/grid-item.vue +121 -119
- package/dist/guide/README.md +1 -1
- package/dist/guide/guide.vue +281 -277
- package/dist/icon/README.md +2 -4
- package/dist/icon/icon.vue +78 -76
- package/dist/image/README.md +1 -1
- package/dist/image/image.vue +103 -101
- package/dist/image-viewer/image-viewer.vue +160 -158
- package/dist/image-viewer/props.ts +2 -2
- package/dist/image-viewer/type.ts +1 -1
- package/dist/index.js +3 -0
- package/dist/indexes/indexes.vue +264 -267
- package/dist/indexes-anchor/indexes-anchor.vue +41 -41
- package/dist/input/input.vue +192 -192
- package/dist/input/props.ts +6 -6
- package/dist/input/type.ts +3 -3
- package/dist/link/link.vue +73 -71
- package/dist/loading/loading.vue +59 -59
- package/dist/locale/ar_KW.ts +157 -0
- package/dist/locale/en_US.ts +146 -0
- package/dist/locale/it_IT.ts +145 -0
- package/dist/locale/ja_JP.ts +132 -0
- package/dist/locale/ko_KR.ts +132 -0
- package/dist/locale/ru_RU.ts +157 -0
- package/dist/locale/zh_CN.ts +133 -0
- package/dist/locale/zh_TW.ts +132 -0
- package/dist/message/message.vue +181 -173
- package/dist/message/props.ts +2 -2
- package/dist/message/type.ts +1 -1
- package/dist/message-item/message-item.vue +192 -184
- package/dist/mixins/using-config.js +39 -0
- package/dist/navbar/navbar.vue +201 -199
- package/dist/notice-bar/notice-bar.vue +175 -171
- package/dist/notice-bar/props.ts +2 -2
- package/dist/notice-bar/type.ts +1 -1
- package/dist/npm/dayjs/esm/locale/ar.js +81 -0
- package/dist/npm/dayjs/esm/locale/it.js +39 -0
- package/dist/overlay/overlay.vue +50 -48
- package/dist/picker/picker.vue +168 -161
- package/dist/picker-item/picker-item.vue +269 -269
- package/dist/popover/README.md +1 -1
- package/dist/popover/popover.vue +262 -261
- package/dist/popover/props.ts +4 -4
- package/dist/popover/type.ts +2 -2
- package/dist/popup/popup.vue +46 -45
- package/dist/progress/README.md +1 -1
- package/dist/progress/progress.vue +76 -76
- package/dist/pull-down-refresh/props.ts +2 -2
- package/dist/pull-down-refresh/pull-down-refresh.vue +240 -234
- package/dist/pull-down-refresh/type.ts +1 -1
- package/dist/qrcode/README.md +1 -1
- package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +340 -338
- package/dist/qrcode/components/qrcode-status/qrcode-status.vue +6 -6
- package/dist/qrcode/qrcode.vue +93 -87
- package/dist/radio/props.ts +6 -6
- package/dist/radio/radio.vue +118 -120
- package/dist/radio/type.ts +3 -3
- package/dist/radio-group/props.ts +4 -4
- package/dist/radio-group/radio-group.vue +136 -134
- package/dist/radio-group/type.ts +4 -4
- package/dist/rate/computed.js +2 -2
- package/dist/rate/props.ts +4 -4
- package/dist/rate/rate.vue +155 -154
- package/dist/rate/type.ts +2 -2
- package/dist/result/result.vue +41 -39
- package/dist/row/row.vue +38 -36
- package/dist/scroll-view/scroll-view.vue +24 -22
- package/dist/search/props.ts +2 -2
- package/dist/search/search.vue +127 -125
- package/dist/search/type.ts +1 -1
- package/dist/side-bar/side-bar.vue +57 -55
- package/dist/side-bar-item/side-bar-item.vue +86 -86
- package/dist/skeleton/skeleton.vue +126 -124
- package/dist/slider/README.md +1 -1
- package/dist/slider/props.ts +2 -2
- package/dist/slider/slider.vue +457 -457
- package/dist/slider/type.ts +1 -1
- package/dist/step-item/step-item.vue +77 -75
- package/dist/stepper/props.ts +2 -2
- package/dist/stepper/stepper.vue +168 -149
- package/dist/stepper/type.ts +1 -1
- package/dist/steps/props.ts +2 -2
- package/dist/steps/steps.vue +83 -81
- package/dist/steps/type.ts +1 -1
- package/dist/sticky/sticky.vue +104 -102
- package/dist/swipe-cell/swipe-cell.vue +91 -89
- package/dist/swiper/README.md +1 -1
- package/dist/swiper/swiper.vue +91 -89
- package/dist/swiper-nav/swiper-nav.vue +38 -36
- package/dist/switch/props.ts +2 -2
- package/dist/switch/switch.vue +62 -62
- package/dist/switch/type.ts +1 -1
- package/dist/tab-bar/tab-bar.vue +88 -86
- package/dist/tab-bar-item/tab-bar-item.vue +85 -82
- package/dist/tab-panel/tab-panel.vue +66 -64
- package/dist/tabs/tabs.vue +294 -287
- package/dist/tag/tag.vue +79 -77
- package/dist/textarea/props.ts +6 -6
- package/dist/textarea/textarea.vue +127 -126
- package/dist/textarea/type.ts +3 -3
- package/dist/toast/toast.vue +107 -106
- package/dist/transition/transition.vue +30 -28
- package/dist/tree-select/tree-select.vue +151 -151
- package/dist/types/config-provider.d.ts +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/popover.d.ts +7 -0
- package/dist/upload/README.en-US.md +13 -14
- package/dist/upload/README.md +11 -12
- package/dist/upload/props.ts +2 -4
- package/dist/upload/type.ts +12 -11
- package/dist/upload/upload.css +1 -1
- package/dist/upload/upload.vue +672 -512
- package/dist/watermark/watermark.vue +151 -149
- package/global.d.ts +2 -0
- package/package.json +15 -3
- package/dist/form/form-item-props.ts +0 -56
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
<!-- 防止转成 px 后,尺寸没铺满 -->
|
|
17
17
|
<!-- 750rpx => 100% -->
|
|
18
|
-
<
|
|
18
|
+
<template-vue
|
|
19
19
|
ref="templateVue"
|
|
20
20
|
:class-prefix="classPrefix"
|
|
21
21
|
:custom-style="tools._style(['width: 100%', customStyle])"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
<slot name="footer" />
|
|
40
40
|
</t-popup>
|
|
41
41
|
<block v-else>
|
|
42
|
-
<
|
|
42
|
+
<template-vue
|
|
43
43
|
ref="templateVue"
|
|
44
44
|
:class-prefix="classPrefix"
|
|
45
45
|
:custom-style="tools._style([customStyle])"
|
|
@@ -122,7 +122,7 @@ const getFormatList = (format, color) => {
|
|
|
122
122
|
};
|
|
123
123
|
|
|
124
124
|
const genSwatchList = (prop) => {
|
|
125
|
-
if (prop
|
|
125
|
+
if (prop == undefined) {
|
|
126
126
|
return DEFAULT_SYSTEM_SWATCH_COLORS;
|
|
127
127
|
}
|
|
128
128
|
if (!prop || !prop.length) {
|
|
@@ -131,369 +131,371 @@ const genSwatchList = (prop) => {
|
|
|
131
131
|
return prop;
|
|
132
132
|
};
|
|
133
133
|
|
|
134
|
-
export default
|
|
135
|
-
name,
|
|
136
|
-
options: {
|
|
137
|
-
styleIsolation: 'shared',
|
|
138
|
-
},
|
|
134
|
+
export default {
|
|
139
135
|
components: {
|
|
140
136
|
TPopup,
|
|
141
137
|
TemplateVue,
|
|
142
138
|
},
|
|
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
|
-
|
|
139
|
+
...uniComponent({
|
|
140
|
+
name,
|
|
141
|
+
options: {
|
|
142
|
+
styleIsolation: 'shared',
|
|
143
|
+
},
|
|
144
|
+
props: {
|
|
145
|
+
...props,
|
|
146
|
+
},
|
|
147
|
+
emits: [
|
|
148
|
+
'palette-bar-change',
|
|
149
|
+
'close',
|
|
150
|
+
'change',
|
|
151
|
+
'update:visible',
|
|
152
|
+
],
|
|
153
|
+
data() {
|
|
154
|
+
return {
|
|
155
|
+
prefix,
|
|
156
|
+
classPrefix: name,
|
|
157
|
+
panelRect: {
|
|
158
|
+
width: SATURATION_PANEL_DEFAULT_WIDTH,
|
|
159
|
+
height: SATURATION_PANEL_DEFAULT_HEIGHT,
|
|
160
|
+
},
|
|
161
|
+
sliderRect: {
|
|
162
|
+
width: SLIDER_DEFAULT_WIDTH,
|
|
163
|
+
left: 0,
|
|
164
|
+
},
|
|
165
|
+
saturationInfo: {
|
|
166
|
+
saturation: 0,
|
|
167
|
+
value: 0,
|
|
168
|
+
},
|
|
169
|
+
saturationThumbStyle: {
|
|
170
|
+
left: 0,
|
|
171
|
+
top: 0,
|
|
172
|
+
},
|
|
173
|
+
sliderInfo: {
|
|
174
|
+
value: 0, // hue
|
|
175
|
+
},
|
|
176
|
+
hueSliderStyle: {
|
|
177
|
+
left: 0,
|
|
178
|
+
},
|
|
179
|
+
alphaSliderStyle: {
|
|
180
|
+
left: 0,
|
|
181
|
+
},
|
|
182
|
+
innerValue: props.defaultValue.default || props.value.default,
|
|
183
|
+
showPrimaryColorPreview: false,
|
|
184
|
+
previewColor: props.defaultValue.default || props.value.default,
|
|
185
|
+
formatList: [],
|
|
186
|
+
innerSwatchList: genSwatchList(props.swatchColors.default),
|
|
187
|
+
isMultiple: props.type.default === 'multiple',
|
|
188
|
+
defaultOverlayProps: {},
|
|
189
|
+
tools,
|
|
190
|
+
color: {},
|
|
191
|
+
dataVisible: this.visible,
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
watch: {
|
|
195
|
+
format: {
|
|
196
|
+
handler() {
|
|
197
|
+
this.setCoreStyle();
|
|
198
|
+
},
|
|
199
|
+
deep: true,
|
|
177
200
|
},
|
|
178
|
-
|
|
179
|
-
|
|
201
|
+
swatchColors: {
|
|
202
|
+
handler(value) {
|
|
203
|
+
this.innerSwatchList = genSwatchList(value);
|
|
204
|
+
},
|
|
205
|
+
immediate: true,
|
|
180
206
|
},
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
isMultiple: props.type.default === 'multiple',
|
|
187
|
-
defaultOverlayProps: {},
|
|
188
|
-
tools,
|
|
189
|
-
color: {},
|
|
190
|
-
dataVisible: this.visible,
|
|
191
|
-
};
|
|
192
|
-
},
|
|
193
|
-
watch: {
|
|
194
|
-
format: {
|
|
195
|
-
handler() {
|
|
196
|
-
this.setCoreStyle();
|
|
207
|
+
type: {
|
|
208
|
+
handler(value) {
|
|
209
|
+
this.isMultiple = value === 'multiple';
|
|
210
|
+
},
|
|
211
|
+
immediate: true,
|
|
197
212
|
},
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
213
|
+
visible: {
|
|
214
|
+
handler(v) {
|
|
215
|
+
this.dataVisible = v;
|
|
216
|
+
},
|
|
217
|
+
immediate: true,
|
|
203
218
|
},
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
219
|
+
usePopup: 'onWatchPopupVisible',
|
|
220
|
+
dataVisible: 'onWatchPopupVisible',
|
|
221
|
+
|
|
222
|
+
value(v) {
|
|
223
|
+
if (v) {
|
|
224
|
+
this.init();
|
|
225
|
+
}
|
|
209
226
|
},
|
|
210
|
-
immediate: true,
|
|
211
227
|
},
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
},
|
|
216
|
-
immediate: true,
|
|
228
|
+
created() {
|
|
229
|
+
this.color = new Color(props.defaultValue.default || props.value.default || DEFAULT_COLOR);
|
|
230
|
+
this.formatList = getFormatList(props.format.default, this.color);
|
|
217
231
|
},
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
value(v) {
|
|
222
|
-
if (v) {
|
|
232
|
+
mounted() {
|
|
233
|
+
setTimeout(() => {
|
|
223
234
|
this.init();
|
|
224
|
-
}
|
|
235
|
+
}, 33);
|
|
236
|
+
this.debouncedUpdateEleRect = debounce(e => this.updateEleRect(e), 150);
|
|
225
237
|
},
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
this.color = new Color(props.defaultValue.default || props.value.default || DEFAULT_COLOR);
|
|
229
|
-
this.formatList = getFormatList(props.format.default, this.color);
|
|
230
|
-
},
|
|
231
|
-
mounted() {
|
|
232
|
-
setTimeout(() => {
|
|
233
|
-
this.init();
|
|
234
|
-
}, 33);
|
|
235
|
-
this.debouncedUpdateEleRect = debounce(e => this.updateEleRect(e), 150);
|
|
236
|
-
},
|
|
237
|
-
beforeUnmount() {
|
|
238
|
-
clearTimeout(this.timer);
|
|
239
|
-
},
|
|
240
|
-
methods: {
|
|
241
|
-
init() {
|
|
242
|
-
const { value, defaultValue } = this;
|
|
243
|
-
const innerValue = value || defaultValue;
|
|
244
|
-
if (innerValue) {
|
|
245
|
-
this.innerValue = innerValue;
|
|
246
|
-
}
|
|
247
|
-
this.color = new Color(innerValue || DEFAULT_COLOR);
|
|
248
|
-
this.updateColor();
|
|
249
|
-
this.getEleReact();
|
|
238
|
+
beforeUnmount() {
|
|
239
|
+
clearTimeout(this.timer);
|
|
250
240
|
},
|
|
241
|
+
methods: {
|
|
242
|
+
init() {
|
|
243
|
+
const { value, defaultValue } = this;
|
|
244
|
+
const innerValue = value || defaultValue;
|
|
245
|
+
if (innerValue) {
|
|
246
|
+
this.innerValue = innerValue;
|
|
247
|
+
}
|
|
248
|
+
this.color = new Color(innerValue || DEFAULT_COLOR);
|
|
249
|
+
this.updateColor();
|
|
250
|
+
this.getEleReact();
|
|
251
|
+
},
|
|
251
252
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
253
|
+
updateEleRect(e) {
|
|
254
|
+
if (!e) return;
|
|
255
|
+
|
|
256
|
+
const { scrollTop } = e.detail;
|
|
257
|
+
const { width, height, left, initTop } = this.panelRect;
|
|
258
|
+
this.panelRect = {
|
|
259
|
+
width,
|
|
260
|
+
height,
|
|
261
|
+
left,
|
|
262
|
+
top: initTop - scrollTop,
|
|
263
|
+
initTop,
|
|
264
|
+
};
|
|
265
|
+
},
|
|
265
266
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
267
|
+
getEleReact() {
|
|
268
|
+
const saturationSelector = `.${name}__saturation`;
|
|
269
|
+
const sliderSelector = `.${name}__slider`;
|
|
270
|
+
// }
|
|
271
|
+
if (!this.$refs.templateVue) return;
|
|
272
|
+
|
|
273
|
+
Promise.all([
|
|
274
|
+
this.$refs.templateVue.getRect(saturationSelector),
|
|
275
|
+
this.$refs.templateVue.getRect(sliderSelector),
|
|
276
|
+
])
|
|
277
|
+
.then(([saturationRect, sliderRect]) => {
|
|
278
|
+
this.panelRect = {
|
|
279
|
+
width: saturationRect.width || SATURATION_PANEL_DEFAULT_WIDTH,
|
|
280
|
+
height: saturationRect.height || SATURATION_PANEL_DEFAULT_HEIGHT,
|
|
281
|
+
left: saturationRect.left || 0,
|
|
282
|
+
top: saturationRect.top || 0,
|
|
283
|
+
initTop: saturationRect.top || 0,
|
|
284
|
+
};
|
|
285
|
+
this.sliderRect = {
|
|
286
|
+
left: sliderRect.left || 0,
|
|
287
|
+
width: sliderRect.width || SLIDER_DEFAULT_WIDTH,
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
setTimeout(() => {
|
|
291
|
+
this.setCoreStyle();
|
|
292
|
+
}, 33);
|
|
293
|
+
})
|
|
294
|
+
.catch(() => {
|
|
295
|
+
});
|
|
296
|
+
},
|
|
296
297
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
298
|
+
clickSwatch(e) {
|
|
299
|
+
const swatch = e.currentTarget.dataset.value;
|
|
300
|
+
this.color.update(swatch);
|
|
301
|
+
this.emitColorChange('preset');
|
|
302
|
+
this.setCoreStyle();
|
|
303
|
+
},
|
|
303
304
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
305
|
+
setCoreStyle() {
|
|
306
|
+
this.sliderInfo = {
|
|
307
|
+
value: this.color.hue,
|
|
308
|
+
};
|
|
309
|
+
this.hueSliderStyle = this.getSliderThumbStyle({ value: this.color.hue, maxValue: HUE_MAX });
|
|
310
|
+
this.alphaSliderStyle = this.getSliderThumbStyle({ value: this.color.alpha * 100, maxValue: ALPHA_MAX });
|
|
311
|
+
this.saturationInfo = {
|
|
312
|
+
saturation: this.color.saturation,
|
|
313
|
+
value: this.color.value,
|
|
314
|
+
};
|
|
315
|
+
this.saturationThumbStyle = this.getSaturationThumbStyle({
|
|
316
|
+
saturation: this.color.saturation,
|
|
317
|
+
value: this.color.value,
|
|
318
|
+
});
|
|
319
|
+
this.previewColor = this.color.rgba;
|
|
320
|
+
this.formatList = getFormatList(this.format, this.color);
|
|
321
|
+
},
|
|
321
322
|
|
|
322
|
-
|
|
323
|
-
|
|
323
|
+
emitColorChange(trigger) {
|
|
324
|
+
this.innerValue = this.formatValue();
|
|
324
325
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
326
|
+
this.$emit('change', {
|
|
327
|
+
value: this.formatValue(),
|
|
328
|
+
context: {
|
|
329
|
+
trigger,
|
|
330
|
+
color: getColorObject(this.color),
|
|
331
|
+
},
|
|
332
|
+
});
|
|
333
|
+
},
|
|
333
334
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
335
|
+
defaultEmptyColor() {
|
|
336
|
+
return DEFAULT_COLOR;
|
|
337
|
+
},
|
|
337
338
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
updateColor() {
|
|
340
|
+
const result = this.innerValue || this.defaultEmptyColor();
|
|
341
|
+
this.color.update(result);
|
|
342
|
+
},
|
|
342
343
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
344
|
+
getSaturationAndValueByCoordinate(coordinate) {
|
|
345
|
+
const { width, height } = this.panelRect;
|
|
346
|
+
const { x, y } = coordinate;
|
|
347
|
+
let saturation = x / width;
|
|
348
|
+
let value = 1 - y / height;
|
|
349
|
+
saturation = Math.min(1, Math.max(0, saturation));
|
|
350
|
+
value = Math.min(1, Math.max(0, value));
|
|
351
|
+
|
|
352
|
+
return {
|
|
353
|
+
saturation,
|
|
354
|
+
value,
|
|
355
|
+
};
|
|
356
|
+
},
|
|
350
357
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
value
|
|
354
|
-
|
|
355
|
-
|
|
358
|
+
getSaturationThumbStyle({ saturation, value }) {
|
|
359
|
+
const { width, height } = this.panelRect;
|
|
360
|
+
const top = Math.round((1 - value) * height);
|
|
361
|
+
const left = Math.round(saturation * width);
|
|
362
|
+
return {
|
|
363
|
+
color: this.color.rgb,
|
|
364
|
+
left: `${left}px`,
|
|
365
|
+
top: `${top}px`,
|
|
366
|
+
};
|
|
367
|
+
},
|
|
356
368
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
369
|
+
getSliderThumbStyle({ value, maxValue }) {
|
|
370
|
+
const { width } = this.sliderRect;
|
|
371
|
+
if (!width) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const left = Math.round((value / maxValue) * 100);
|
|
375
|
+
return {
|
|
376
|
+
left: `${left}%`,
|
|
377
|
+
color: this.color.rgb,
|
|
378
|
+
};
|
|
379
|
+
},
|
|
367
380
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
381
|
+
onChangeSaturation({ saturation, value }) {
|
|
382
|
+
const { saturation: sat, value: val } = this.color;
|
|
383
|
+
let changeTrigger = 'palette-saturation-brightness';
|
|
384
|
+
if (value !== val && saturation !== sat) {
|
|
385
|
+
this.color.saturation = saturation;
|
|
386
|
+
this.color.value = value;
|
|
387
|
+
changeTrigger = 'palette-saturation-brightness';
|
|
388
|
+
} else if (saturation !== sat) {
|
|
389
|
+
this.color.saturation = saturation;
|
|
390
|
+
changeTrigger = 'palette-saturation';
|
|
391
|
+
} else if (value !== val) {
|
|
392
|
+
this.color.value = value;
|
|
393
|
+
changeTrigger = 'palette-brightness';
|
|
394
|
+
} else {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
this.$emit('palette-bar-change', {
|
|
399
|
+
color: getColorObject(this.color),
|
|
400
|
+
});
|
|
379
401
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
if (value !== val && saturation !== sat) {
|
|
384
|
-
this.color.saturation = saturation;
|
|
385
|
-
this.color.value = value;
|
|
386
|
-
changeTrigger = 'palette-saturation-brightness';
|
|
387
|
-
} else if (saturation !== sat) {
|
|
388
|
-
this.color.saturation = saturation;
|
|
389
|
-
changeTrigger = 'palette-saturation';
|
|
390
|
-
} else if (value !== val) {
|
|
391
|
-
this.color.value = value;
|
|
392
|
-
changeTrigger = 'palette-brightness';
|
|
393
|
-
} else {
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
this.$emit('palette-bar-change', {
|
|
398
|
-
color: getColorObject(this.color),
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
this.emitColorChange(changeTrigger);
|
|
402
|
-
this.setCoreStyle();
|
|
403
|
-
},
|
|
402
|
+
this.emitColorChange(changeTrigger);
|
|
403
|
+
this.setCoreStyle();
|
|
404
|
+
},
|
|
404
405
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
406
|
+
formatValue() {
|
|
407
|
+
return this.color.getFormatsColorMap()[this.format] || this.color.css;
|
|
408
|
+
},
|
|
408
409
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
410
|
+
onChangeSlider({ value, isAlpha }) {
|
|
411
|
+
if (isAlpha) {
|
|
412
|
+
this.color.alpha = value / 100;
|
|
413
|
+
} else {
|
|
414
|
+
this.color.hue = value;
|
|
415
|
+
}
|
|
415
416
|
|
|
416
|
-
|
|
417
|
+
this.emitColorChange(isAlpha ? 'palette-alpha-bar' : 'palette-hue-bar');
|
|
417
418
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
handleSaturationDrag(e) {
|
|
422
|
-
const { usePopup, fixed } = this;
|
|
423
|
-
const coordinate = getCoordinate(e, this.panelRect, usePopup || fixed);
|
|
424
|
-
const { saturation, value } = this.getSaturationAndValueByCoordinate(coordinate);
|
|
425
|
-
this.onChangeSaturation({ saturation, value });
|
|
426
|
-
},
|
|
419
|
+
this.setCoreStyle();
|
|
420
|
+
},
|
|
427
421
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
422
|
+
handleSaturationDrag(e) {
|
|
423
|
+
const { usePopup, fixed } = this;
|
|
424
|
+
const coordinate = getCoordinate(e, this.panelRect, usePopup || fixed);
|
|
425
|
+
const { saturation, value } = this.getSaturationAndValueByCoordinate(coordinate);
|
|
426
|
+
this.onChangeSaturation({ saturation, value });
|
|
427
|
+
},
|
|
433
428
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
429
|
+
handleSliderDrag(e, isAlpha = false) {
|
|
430
|
+
const { width } = this.sliderRect;
|
|
431
|
+
const coordinate = getCoordinate(e, this.sliderRect);
|
|
432
|
+
const { x } = coordinate;
|
|
433
|
+
const maxValue = isAlpha ? ALPHA_MAX : HUE_MAX;
|
|
439
434
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
break;
|
|
446
|
-
case 'hue-slider':
|
|
447
|
-
this.handleSliderDrag(e);
|
|
448
|
-
break;
|
|
449
|
-
case 'alpha-slider':
|
|
450
|
-
this.handleSliderDrag(e, true);
|
|
451
|
-
break;
|
|
452
|
-
default:
|
|
453
|
-
break;
|
|
454
|
-
}
|
|
455
|
-
},
|
|
435
|
+
let value = Math.round((x / width) * maxValue * 100) / 100;
|
|
436
|
+
if (value < 0) value = 0;
|
|
437
|
+
if (value > maxValue) value = maxValue;
|
|
438
|
+
this.onChangeSlider({ value, isAlpha });
|
|
439
|
+
},
|
|
456
440
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
441
|
+
handleDiffDrag(e) {
|
|
442
|
+
const dragType = e.target.dataset.type || e.currentTarget.dataset.type;
|
|
443
|
+
switch (dragType) {
|
|
444
|
+
case 'saturation':
|
|
445
|
+
this.handleSaturationDrag(e);
|
|
446
|
+
break;
|
|
447
|
+
case 'hue-slider':
|
|
448
|
+
this.handleSliderDrag(e);
|
|
449
|
+
break;
|
|
450
|
+
case 'alpha-slider':
|
|
451
|
+
this.handleSliderDrag(e, true);
|
|
452
|
+
break;
|
|
453
|
+
default:
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
},
|
|
460
457
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
458
|
+
onTouchStart(e) {
|
|
459
|
+
this.handleDiffDrag(e);
|
|
460
|
+
},
|
|
464
461
|
|
|
465
|
-
|
|
466
|
-
nextTick().then(() => {
|
|
462
|
+
onTouchMove(e) {
|
|
467
463
|
this.handleDiffDrag(e);
|
|
468
|
-
}
|
|
469
|
-
},
|
|
464
|
+
},
|
|
470
465
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
466
|
+
onTouchEnd(e) {
|
|
467
|
+
nextTick().then(() => {
|
|
468
|
+
this.handleDiffDrag(e);
|
|
469
|
+
});
|
|
470
|
+
},
|
|
476
471
|
|
|
477
|
-
|
|
478
|
-
|
|
472
|
+
close(trigger) {
|
|
473
|
+
if (this.autoClose) {
|
|
474
|
+
this.dataVisible = false;
|
|
475
|
+
this.$emit('update:visible', false);
|
|
476
|
+
}
|
|
479
477
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
478
|
+
this.$emit('close', { trigger });
|
|
479
|
+
},
|
|
480
|
+
|
|
481
|
+
onVisibleChange() {
|
|
482
|
+
this.close('overlay');
|
|
483
|
+
},
|
|
483
484
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
485
|
+
onWatchPopupVisible() {
|
|
486
|
+
if (this.timer) {
|
|
487
|
+
clearTimeout(this.timer);
|
|
488
|
+
}
|
|
488
489
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
490
|
+
if (this.usePopup && this.dataVisible) {
|
|
491
|
+
this.timer = setTimeout(() => {
|
|
492
|
+
this.getEleReact();
|
|
493
|
+
}, 350); // popup 的 transition-duration 为 300ms,为保证 popup 已渲染完毕,故使用 350ms
|
|
494
|
+
}
|
|
495
|
+
},
|
|
494
496
|
},
|
|
495
|
-
},
|
|
496
|
-
}
|
|
497
|
+
}),
|
|
498
|
+
};
|
|
497
499
|
|
|
498
500
|
</script>
|
|
499
501
|
<style scoped src="./color-picker.css"></style>
|