wedux-ui 0.1.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/LICENSE +21 -0
- package/README.md +184 -0
- package/miniprogram_dist/behaviors/formField.js +35 -0
- package/miniprogram_dist/components/avatar/avatar.js +70 -0
- package/miniprogram_dist/components/avatar/avatar.json +4 -0
- package/miniprogram_dist/components/avatar/avatar.scss +68 -0
- package/miniprogram_dist/components/avatar/avatar.wxml +15 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.js +45 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.json +7 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.scss +4 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.wxml +3 -0
- package/miniprogram_dist/components/back-top/back-top.js +68 -0
- package/miniprogram_dist/components/back-top/back-top.json +4 -0
- package/miniprogram_dist/components/back-top/back-top.scss +43 -0
- package/miniprogram_dist/components/back-top/back-top.wxml +10 -0
- package/miniprogram_dist/components/badge/badge.js +100 -0
- package/miniprogram_dist/components/badge/badge.json +4 -0
- package/miniprogram_dist/components/badge/badge.scss +98 -0
- package/miniprogram_dist/components/badge/badge.wxml +11 -0
- package/miniprogram_dist/components/button/button.js +152 -0
- package/miniprogram_dist/components/button/button.json +4 -0
- package/miniprogram_dist/components/button/button.scss +499 -0
- package/miniprogram_dist/components/button/button.wxml +21 -0
- package/miniprogram_dist/components/button-group/button-group.js +51 -0
- package/miniprogram_dist/components/button-group/button-group.json +4 -0
- package/miniprogram_dist/components/button-group/button-group.scss +8 -0
- package/miniprogram_dist/components/button-group/button-group.wxml +3 -0
- package/miniprogram_dist/components/calendar/calendar.js +308 -0
- package/miniprogram_dist/components/calendar/calendar.json +4 -0
- package/miniprogram_dist/components/calendar/calendar.scss +141 -0
- package/miniprogram_dist/components/calendar/calendar.wxml +47 -0
- package/miniprogram_dist/components/card/card.js +44 -0
- package/miniprogram_dist/components/card/card.json +4 -0
- package/miniprogram_dist/components/card/card.scss +143 -0
- package/miniprogram_dist/components/card/card.wxml +31 -0
- package/miniprogram_dist/components/checkbox/checkbox.js +43 -0
- package/miniprogram_dist/components/checkbox/checkbox.json +4 -0
- package/miniprogram_dist/components/checkbox/checkbox.scss +77 -0
- package/miniprogram_dist/components/checkbox/checkbox.wxml +13 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.js +43 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.json +4 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.scss +39 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.wxml +8 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.js +84 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.json +4 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.scss +9 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.wxml +3 -0
- package/miniprogram_dist/components/color-picker/color-picker.js +348 -0
- package/miniprogram_dist/components/color-picker/color-picker.json +7 -0
- package/miniprogram_dist/components/color-picker/color-picker.scss +383 -0
- package/miniprogram_dist/components/color-picker/color-picker.wxml +232 -0
- package/miniprogram_dist/components/date-picker/date-picker.js +1289 -0
- package/miniprogram_dist/components/date-picker/date-picker.json +7 -0
- package/miniprogram_dist/components/date-picker/date-picker.scss +468 -0
- package/miniprogram_dist/components/date-picker/date-picker.wxml +214 -0
- package/miniprogram_dist/components/divider/divider.js +34 -0
- package/miniprogram_dist/components/divider/divider.json +4 -0
- package/miniprogram_dist/components/divider/divider.scss +75 -0
- package/miniprogram_dist/components/divider/divider.wxml +8 -0
- package/miniprogram_dist/components/drawer/drawer.js +104 -0
- package/miniprogram_dist/components/drawer/drawer.json +4 -0
- package/miniprogram_dist/components/drawer/drawer.scss +171 -0
- package/miniprogram_dist/components/drawer/drawer.wxml +22 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.js +38 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.json +4 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.scss +22 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.wxml +7 -0
- package/miniprogram_dist/components/flex/flex.js +81 -0
- package/miniprogram_dist/components/flex/flex.json +4 -0
- package/miniprogram_dist/components/flex/flex.scss +4 -0
- package/miniprogram_dist/components/flex/flex.wxml +3 -0
- package/miniprogram_dist/components/float-button/float-button.js +78 -0
- package/miniprogram_dist/components/float-button/float-button.json +4 -0
- package/miniprogram_dist/components/float-button/float-button.scss +54 -0
- package/miniprogram_dist/components/float-button/float-button.wxml +9 -0
- package/miniprogram_dist/components/form/form.js +142 -0
- package/miniprogram_dist/components/form/form.json +4 -0
- package/miniprogram_dist/components/form/form.scss +11 -0
- package/miniprogram_dist/components/form/form.wxml +3 -0
- package/miniprogram_dist/components/form/validator.js +220 -0
- package/miniprogram_dist/components/form-item/form-item.js +240 -0
- package/miniprogram_dist/components/form-item/form-item.json +4 -0
- package/miniprogram_dist/components/form-item/form-item.scss +59 -0
- package/miniprogram_dist/components/form-item/form-item.wxml +33 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.js +54 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.json +4 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.scss +7 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.wxml +1 -0
- package/miniprogram_dist/components/h/h.js +60 -0
- package/miniprogram_dist/components/h/h.json +4 -0
- package/miniprogram_dist/components/h/h.scss +53 -0
- package/miniprogram_dist/components/h/h.wxml +1 -0
- package/miniprogram_dist/components/highlight/highlight.js +77 -0
- package/miniprogram_dist/components/highlight/highlight.json +4 -0
- package/miniprogram_dist/components/highlight/highlight.scss +8 -0
- package/miniprogram_dist/components/highlight/highlight.wxml +12 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.js +31 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.json +4 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.scss +31 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.wxml +12 -0
- package/miniprogram_dist/components/input/input.js +59 -0
- package/miniprogram_dist/components/input/input.json +4 -0
- package/miniprogram_dist/components/input/input.scss +96 -0
- package/miniprogram_dist/components/input/input.wxml +34 -0
- package/miniprogram_dist/components/input-otp/input-otp.js +106 -0
- package/miniprogram_dist/components/input-otp/input-otp.json +4 -0
- package/miniprogram_dist/components/input-otp/input-otp.scss +122 -0
- package/miniprogram_dist/components/input-otp/input-otp.wxml +38 -0
- package/miniprogram_dist/components/layout/layout.js +50 -0
- package/miniprogram_dist/components/layout/layout.json +4 -0
- package/miniprogram_dist/components/layout/layout.scss +10 -0
- package/miniprogram_dist/components/layout/layout.wxml +3 -0
- package/miniprogram_dist/components/layout-content/layout-content.js +47 -0
- package/miniprogram_dist/components/layout-content/layout-content.json +4 -0
- package/miniprogram_dist/components/layout-content/layout-content.scss +5 -0
- package/miniprogram_dist/components/layout-content/layout-content.wxml +13 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.js +59 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.json +4 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.scss +23 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.wxml +16 -0
- package/miniprogram_dist/components/layout-header/layout-header.js +59 -0
- package/miniprogram_dist/components/layout-header/layout-header.json +4 -0
- package/miniprogram_dist/components/layout-header/layout-header.scss +23 -0
- package/miniprogram_dist/components/layout-header/layout-header.wxml +16 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.js +48 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.json +4 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.scss +13 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.wxml +5 -0
- package/miniprogram_dist/components/list/list.js +55 -0
- package/miniprogram_dist/components/list/list.json +4 -0
- package/miniprogram_dist/components/list/list.scss +51 -0
- package/miniprogram_dist/components/list/list.wxml +9 -0
- package/miniprogram_dist/components/list-item/list-item.js +24 -0
- package/miniprogram_dist/components/list-item/list-item.json +4 -0
- package/miniprogram_dist/components/list-item/list-item.scss +51 -0
- package/miniprogram_dist/components/list-item/list-item.wxml +14 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.js +77 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.json +4 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.scss +63 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.wxml +35 -0
- package/miniprogram_dist/components/number-animation/number-animation.js +124 -0
- package/miniprogram_dist/components/number-animation/number-animation.json +4 -0
- package/miniprogram_dist/components/number-animation/number-animation.scss +3 -0
- package/miniprogram_dist/components/number-animation/number-animation.wxml +1 -0
- package/miniprogram_dist/components/popover/popover.js +183 -0
- package/miniprogram_dist/components/popover/popover.json +4 -0
- package/miniprogram_dist/components/popover/popover.scss +69 -0
- package/miniprogram_dist/components/popover/popover.wxml +19 -0
- package/miniprogram_dist/components/qr-code/qr-code.js +216 -0
- package/miniprogram_dist/components/qr-code/qr-code.json +4 -0
- package/miniprogram_dist/components/qr-code/qr-code.scss +8 -0
- package/miniprogram_dist/components/qr-code/qr-code.wxml +16 -0
- package/miniprogram_dist/components/radio/radio.js +38 -0
- package/miniprogram_dist/components/radio/radio.json +4 -0
- package/miniprogram_dist/components/radio/radio.scss +50 -0
- package/miniprogram_dist/components/radio/radio.wxml +12 -0
- package/miniprogram_dist/components/radio-button/radio-button.js +39 -0
- package/miniprogram_dist/components/radio-button/radio-button.json +4 -0
- package/miniprogram_dist/components/radio-button/radio-button.scss +39 -0
- package/miniprogram_dist/components/radio-button/radio-button.wxml +8 -0
- package/miniprogram_dist/components/radio-group/radio-group.js +72 -0
- package/miniprogram_dist/components/radio-group/radio-group.json +4 -0
- package/miniprogram_dist/components/radio-group/radio-group.scss +9 -0
- package/miniprogram_dist/components/radio-group/radio-group.wxml +3 -0
- package/miniprogram_dist/components/rate/rate.js +90 -0
- package/miniprogram_dist/components/rate/rate.json +4 -0
- package/miniprogram_dist/components/rate/rate.scss +59 -0
- package/miniprogram_dist/components/rate/rate.wxml +16 -0
- package/miniprogram_dist/components/select/select.js +201 -0
- package/miniprogram_dist/components/select/select.json +7 -0
- package/miniprogram_dist/components/select/select.scss +235 -0
- package/miniprogram_dist/components/select/select.wxml +79 -0
- package/miniprogram_dist/components/stepper/stepper.js +113 -0
- package/miniprogram_dist/components/stepper/stepper.json +4 -0
- package/miniprogram_dist/components/stepper/stepper.scss +73 -0
- package/miniprogram_dist/components/stepper/stepper.wxml +23 -0
- package/miniprogram_dist/components/switch/switch.js +42 -0
- package/miniprogram_dist/components/switch/switch.json +4 -0
- package/miniprogram_dist/components/switch/switch.scss +77 -0
- package/miniprogram_dist/components/switch/switch.wxml +10 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.js +53 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.json +4 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.scss +53 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.wxml +12 -0
- package/miniprogram_dist/components/tag/tag.js +87 -0
- package/miniprogram_dist/components/tag/tag.json +4 -0
- package/miniprogram_dist/components/tag/tag.scss +138 -0
- package/miniprogram_dist/components/tag/tag.wxml +12 -0
- package/miniprogram_dist/components/textarea/textarea.js +46 -0
- package/miniprogram_dist/components/textarea/textarea.json +4 -0
- package/miniprogram_dist/components/textarea/textarea.scss +51 -0
- package/miniprogram_dist/components/textarea/textarea.wxml +20 -0
- package/miniprogram_dist/components/theme-provider/presets.js +101 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.js +34 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.json +4 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.scss +3 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.wxml +3 -0
- package/miniprogram_dist/components/time-picker/time-picker.js +136 -0
- package/miniprogram_dist/components/time-picker/time-picker.json +7 -0
- package/miniprogram_dist/components/time-picker/time-picker.scss +135 -0
- package/miniprogram_dist/components/time-picker/time-picker.wxml +47 -0
- package/miniprogram_dist/components/tooltip/tooltip.js +179 -0
- package/miniprogram_dist/components/tooltip/tooltip.json +4 -0
- package/miniprogram_dist/components/tooltip/tooltip.scss +66 -0
- package/miniprogram_dist/components/tooltip/tooltip.wxml +17 -0
- package/miniprogram_dist/components/tree/tree.js +647 -0
- package/miniprogram_dist/components/tree/tree.json +4 -0
- package/miniprogram_dist/components/tree/tree.scss +178 -0
- package/miniprogram_dist/components/tree/tree.wxml +59 -0
- package/miniprogram_dist/components/tree-select/tree-select.js +260 -0
- package/miniprogram_dist/components/tree-select/tree-select.json +8 -0
- package/miniprogram_dist/components/tree-select/tree-select.scss +250 -0
- package/miniprogram_dist/components/tree-select/tree-select.wxml +118 -0
- package/miniprogram_dist/components/upload/upload.js +387 -0
- package/miniprogram_dist/components/upload/upload.json +4 -0
- package/miniprogram_dist/components/upload/upload.scss +258 -0
- package/miniprogram_dist/components/upload/upload.wxml +142 -0
- package/miniprogram_dist/components/watermark/watermark.js +260 -0
- package/miniprogram_dist/components/watermark/watermark.json +4 -0
- package/miniprogram_dist/components/watermark/watermark.scss +35 -0
- package/miniprogram_dist/components/watermark/watermark.wxml +13 -0
- package/miniprogram_dist/libs/qrcodegen.js +714 -0
- package/miniprogram_dist/libs/seemly.min.js +547 -0
- package/miniprogram_dist/libs/tempo_1_0_0.js +1264 -0
- package/miniprogram_dist/libs/validator_13_56_26.min.js +5282 -0
- package/miniprogram_dist/styles/demo.scss +96 -0
- package/miniprogram_dist/styles/iconfont.scss +91 -0
- package/miniprogram_dist/styles/theme.scss +126 -0
- package/miniprogram_dist/styles/tokens.scss +292 -0
- package/miniprogram_dist/utils/relations.js +21 -0
- package/package.json +25 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
.w-radio-button {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
border-radius: var(--radius-md);
|
|
6
|
+
background: var(--color-bg-base);
|
|
7
|
+
color: var(--color-text-primary);
|
|
8
|
+
font-size: var(--font-size-md);
|
|
9
|
+
line-height: 1;
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
transition:
|
|
12
|
+
background 0.2s,
|
|
13
|
+
color 0.2s;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.w-radio-button--size-medium {
|
|
17
|
+
height: var(--size-tag-height-lg);
|
|
18
|
+
padding: 0 var(--spacing-lg);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.w-radio-button--size-small {
|
|
22
|
+
height: var(--size-tag-height-md);
|
|
23
|
+
padding: 0 var(--spacing-md);
|
|
24
|
+
font-size: var(--font-size-sm);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.w-radio-button--checked {
|
|
28
|
+
background: var(--color-brand);
|
|
29
|
+
color: var(--color-text-anti);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.w-radio-button--round {
|
|
33
|
+
border-radius: var(--radius-full);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.w-radio-button--disabled {
|
|
37
|
+
opacity: 0.4;
|
|
38
|
+
pointer-events: none;
|
|
39
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<view
|
|
2
|
+
class="w-radio-button {{_checked ? 'w-radio-button--checked' : ''}} {{(disabled || _groupDisabled) ? 'w-radio-button--disabled' : ''}} w-radio-button--size-{{_groupSize || 'medium'}} {{round ? 'w-radio-button--round' : ''}}"
|
|
3
|
+
hover-class="none"
|
|
4
|
+
bindtap="handleTap"
|
|
5
|
+
>
|
|
6
|
+
<text wx:if="{{label}}">{{label}}</text>
|
|
7
|
+
<slot wx:else></slot>
|
|
8
|
+
</view>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const formField = require('../../behaviors/formField');
|
|
2
|
+
|
|
3
|
+
Component({
|
|
4
|
+
behaviors: ['wx://form-field', formField],
|
|
5
|
+
|
|
6
|
+
relations: {
|
|
7
|
+
'../form-item/form-item': {
|
|
8
|
+
type: 'ancestor',
|
|
9
|
+
},
|
|
10
|
+
'../radio/radio': {
|
|
11
|
+
type: 'descendant',
|
|
12
|
+
linked() {
|
|
13
|
+
this._updateChildren();
|
|
14
|
+
},
|
|
15
|
+
linkChanged() {
|
|
16
|
+
this._updateChildren();
|
|
17
|
+
},
|
|
18
|
+
unlinked() {
|
|
19
|
+
this._updateChildren();
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
'../radio-button/radio-button': {
|
|
23
|
+
type: 'descendant',
|
|
24
|
+
linked() {
|
|
25
|
+
this._updateChildren();
|
|
26
|
+
},
|
|
27
|
+
linkChanged() {
|
|
28
|
+
this._updateChildren();
|
|
29
|
+
},
|
|
30
|
+
unlinked() {
|
|
31
|
+
this._updateChildren();
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
properties: {
|
|
37
|
+
value: { type: null, value: null },
|
|
38
|
+
disabled: { type: Boolean, value: false },
|
|
39
|
+
size: { type: String, value: '' },
|
|
40
|
+
vertical: { type: Boolean, value: false },
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
data: {},
|
|
44
|
+
|
|
45
|
+
observers: {
|
|
46
|
+
'value, disabled, size, _formItemSize, _formItemDisabled'() {
|
|
47
|
+
this._updateChildren();
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
methods: {
|
|
52
|
+
_updateChildren() {
|
|
53
|
+
const radios = this.getRelationNodes('../radio/radio') || [];
|
|
54
|
+
const radioButtons = this.getRelationNodes('../radio-button/radio-button') || [];
|
|
55
|
+
const children = [...radios, ...radioButtons];
|
|
56
|
+
if (!children.length) return;
|
|
57
|
+
const ctx = {
|
|
58
|
+
size: this.data.size || this.data._formItemSize,
|
|
59
|
+
disabled: this.data.disabled || this.data._formItemDisabled,
|
|
60
|
+
currentValue: this.data.value,
|
|
61
|
+
};
|
|
62
|
+
children.forEach((child) => {
|
|
63
|
+
child._setGroupContext(ctx);
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
_handleChildChange(value) {
|
|
68
|
+
this.triggerEvent('update:value', { value });
|
|
69
|
+
this._notifyChange();
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const formField = require('../../behaviors/formField');
|
|
2
|
+
|
|
3
|
+
Component({
|
|
4
|
+
behaviors: ['wx://form-field', formField],
|
|
5
|
+
|
|
6
|
+
relations: {
|
|
7
|
+
'../form-item/form-item': {
|
|
8
|
+
type: 'ancestor',
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
properties: {
|
|
13
|
+
value: { type: Number, value: 0 },
|
|
14
|
+
count: { type: Number, value: 5 },
|
|
15
|
+
allowHalf: { type: Boolean, value: false },
|
|
16
|
+
readonly: { type: Boolean, value: false },
|
|
17
|
+
disabled: { type: Boolean, value: false },
|
|
18
|
+
clearable: { type: Boolean, value: false },
|
|
19
|
+
size: { type: String, value: '' },
|
|
20
|
+
color: { type: String, value: '' },
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
data: {
|
|
24
|
+
_stars: [],
|
|
25
|
+
_activeStyle: '',
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
observers: {
|
|
29
|
+
'value, count, allowHalf'(value, count) {
|
|
30
|
+
const stars = [];
|
|
31
|
+
for (let i = 0; i < count; i++) {
|
|
32
|
+
const diff = value - i;
|
|
33
|
+
let state = 'inactive';
|
|
34
|
+
if (diff >= 1) {
|
|
35
|
+
state = 'full';
|
|
36
|
+
} else if (this.data.allowHalf && diff >= 0.5) {
|
|
37
|
+
state = 'half';
|
|
38
|
+
}
|
|
39
|
+
stars.push({ index: i, state });
|
|
40
|
+
}
|
|
41
|
+
this.setData({ _stars: stars });
|
|
42
|
+
},
|
|
43
|
+
color(color) {
|
|
44
|
+
this.setData({
|
|
45
|
+
_activeStyle: color ? `color: ${color};` : '',
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
methods: {
|
|
51
|
+
handleTap(e) {
|
|
52
|
+
if (this.data.readonly || this._isDisabled()) return;
|
|
53
|
+
const { index } = e.currentTarget.dataset;
|
|
54
|
+
const { allowHalf, clearable, value } = this.data;
|
|
55
|
+
|
|
56
|
+
let newValue;
|
|
57
|
+
if (allowHalf) {
|
|
58
|
+
// Use touch position to determine half or full
|
|
59
|
+
const query = this.createSelectorQuery();
|
|
60
|
+
query.select(`.w-rate__item-${index}`).boundingClientRect();
|
|
61
|
+
query.exec((res) => {
|
|
62
|
+
if (!res || !res[0]) return;
|
|
63
|
+
const rect = res[0];
|
|
64
|
+
const touch = e.detail || {};
|
|
65
|
+
const x = (touch.x || 0) - rect.left;
|
|
66
|
+
const isHalf = x < rect.width / 2;
|
|
67
|
+
newValue = isHalf ? index + 0.5 : index + 1;
|
|
68
|
+
|
|
69
|
+
if (clearable && newValue === value) {
|
|
70
|
+
this._doUpdate(null);
|
|
71
|
+
} else {
|
|
72
|
+
this._doUpdate(newValue);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
newValue = index + 1;
|
|
77
|
+
if (clearable && newValue === value) {
|
|
78
|
+
this._doUpdate(null);
|
|
79
|
+
} else {
|
|
80
|
+
this._doUpdate(newValue);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
_doUpdate(val) {
|
|
86
|
+
this.triggerEvent('update:value', { value: val });
|
|
87
|
+
this._notifyChange();
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
.w-rate {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
flex-wrap: nowrap;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.w-rate__item {
|
|
8
|
+
position: relative;
|
|
9
|
+
transition: transform 0.15s;
|
|
10
|
+
padding: 0 var(--spacing-rate-gap);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.w-rate__item--interactive:active {
|
|
14
|
+
transform: scale(0.9);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.w-rate__icon {
|
|
18
|
+
font-size: var(--size-rate);
|
|
19
|
+
line-height: 1;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.w-rate__icon--inactive {
|
|
23
|
+
color: var(--color-rate-inactive);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.w-rate__icon--active {
|
|
27
|
+
position: absolute;
|
|
28
|
+
top: 0;
|
|
29
|
+
left: var(--spacing-rate-gap);
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
width: 0;
|
|
32
|
+
color: var(--color-rate-active);
|
|
33
|
+
pointer-events: none;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.w-rate__icon-inner {
|
|
37
|
+
white-space: nowrap;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* Full star */
|
|
41
|
+
.w-rate__item--active .w-rate__icon--active {
|
|
42
|
+
width: 100%;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Half star */
|
|
46
|
+
.w-rate__item--half .w-rate__icon--active {
|
|
47
|
+
width: 50%;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* Size: small */
|
|
51
|
+
.w-rate--size-small .w-rate__icon {
|
|
52
|
+
font-size: var(--size-rate-sm);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* Disabled */
|
|
56
|
+
.w-rate--disabled {
|
|
57
|
+
opacity: 0.4;
|
|
58
|
+
pointer-events: none;
|
|
59
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<view
|
|
2
|
+
class="w-rate w-rate--size-{{size || _formItemSize || 'medium'}} {{(disabled || _formItemDisabled) ? 'w-rate--disabled' : ''}} {{readonly ? 'w-rate--readonly' : ''}}"
|
|
3
|
+
>
|
|
4
|
+
<view
|
|
5
|
+
wx:for="{{_stars}}"
|
|
6
|
+
wx:key="index"
|
|
7
|
+
class="w-rate__item w-rate__item-{{item.index}} {{item.state === 'full' ? 'w-rate__item--active' : ''}} {{item.state === 'half' ? 'w-rate__item--half' : ''}} {{!(disabled || _formItemDisabled || readonly) ? 'w-rate__item--interactive' : ''}}"
|
|
8
|
+
data-index="{{item.index}}"
|
|
9
|
+
bindtap="handleTap"
|
|
10
|
+
>
|
|
11
|
+
<view class="w-rate__icon w-rate__icon--inactive">★</view>
|
|
12
|
+
<view class="w-rate__icon w-rate__icon--active" style="{{_activeStyle}}">
|
|
13
|
+
<view class="w-rate__icon-inner">★</view>
|
|
14
|
+
</view>
|
|
15
|
+
</view>
|
|
16
|
+
</view>
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
const formField = require('../../behaviors/formField');
|
|
2
|
+
|
|
3
|
+
Component({
|
|
4
|
+
behaviors: ['wx://form-field', formField],
|
|
5
|
+
|
|
6
|
+
relations: {
|
|
7
|
+
'../form-item/form-item': {
|
|
8
|
+
type: 'ancestor',
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
properties: {
|
|
13
|
+
value: { type: null, value: null },
|
|
14
|
+
options: { type: Array, value: [] },
|
|
15
|
+
multiple: { type: Boolean, value: false },
|
|
16
|
+
maxCount: { type: Number, value: 0 },
|
|
17
|
+
clearable: { type: Boolean, value: false },
|
|
18
|
+
disabled: { type: Boolean, value: false },
|
|
19
|
+
readonly: { type: Boolean, value: false },
|
|
20
|
+
placeholder: { type: String, value: '请选择' },
|
|
21
|
+
size: { type: String, value: '' },
|
|
22
|
+
status: { type: String, value: '' },
|
|
23
|
+
title: { type: String, value: '' },
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
data: {
|
|
27
|
+
_visible: false,
|
|
28
|
+
_displayText: '',
|
|
29
|
+
_pickerValue: [0],
|
|
30
|
+
// Multiple mode
|
|
31
|
+
_selectedValues: [],
|
|
32
|
+
_selectedMap: {},
|
|
33
|
+
_selectedTags: [],
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
lifetimes: {
|
|
37
|
+
attached() {
|
|
38
|
+
this._syncFromValue();
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
observers: {
|
|
43
|
+
'value, options'() {
|
|
44
|
+
this._syncFromValue();
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
methods: {
|
|
49
|
+
_findLabel(val) {
|
|
50
|
+
const { options } = this.data;
|
|
51
|
+
for (const opt of options) {
|
|
52
|
+
if (opt.value === val) return opt.label;
|
|
53
|
+
}
|
|
54
|
+
return String(val);
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
_findIndex(val) {
|
|
58
|
+
const { options } = this.data;
|
|
59
|
+
const idx = options.findIndex((opt) => opt.value === val);
|
|
60
|
+
return idx >= 0 ? idx : 0;
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
_syncFromValue() {
|
|
64
|
+
const { value, options, multiple } = this.data;
|
|
65
|
+
if (!options || options.length === 0) {
|
|
66
|
+
this.setData({
|
|
67
|
+
_displayText: '',
|
|
68
|
+
_pickerValue: [0],
|
|
69
|
+
_selectedValues: [],
|
|
70
|
+
_selectedMap: {},
|
|
71
|
+
_selectedTags: [],
|
|
72
|
+
});
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (multiple) {
|
|
77
|
+
const arr = Array.isArray(value) ? value : [];
|
|
78
|
+
const tags = arr
|
|
79
|
+
.map((v) => {
|
|
80
|
+
const opt = options.find((o) => o.value === v);
|
|
81
|
+
return opt ? { label: opt.label, value: opt.value } : null;
|
|
82
|
+
})
|
|
83
|
+
.filter(Boolean);
|
|
84
|
+
const map = {};
|
|
85
|
+
arr.forEach((v) => {
|
|
86
|
+
map[v] = true;
|
|
87
|
+
});
|
|
88
|
+
this.setData({ _selectedValues: arr, _selectedMap: map, _selectedTags: tags });
|
|
89
|
+
} else {
|
|
90
|
+
if (value === null || value === undefined || value === '') {
|
|
91
|
+
this.setData({ _displayText: '', _pickerValue: [0] });
|
|
92
|
+
} else {
|
|
93
|
+
const label = this._findLabel(value);
|
|
94
|
+
const idx = this._findIndex(value);
|
|
95
|
+
this.setData({ _displayText: label, _pickerValue: [idx] });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
handleTap() {
|
|
101
|
+
if (this._isDisabled() || this.data.readonly) return;
|
|
102
|
+
|
|
103
|
+
const { value, options, multiple } = this.data;
|
|
104
|
+
|
|
105
|
+
if (multiple) {
|
|
106
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
107
|
+
const map = {};
|
|
108
|
+
arr.forEach((v) => {
|
|
109
|
+
map[v] = true;
|
|
110
|
+
});
|
|
111
|
+
this.setData({ _visible: true, _selectedValues: arr, _selectedMap: map });
|
|
112
|
+
} else {
|
|
113
|
+
const idx =
|
|
114
|
+
value !== null && value !== undefined && value !== '' ? this._findIndex(value) : 0;
|
|
115
|
+
this.setData({ _visible: true, _pickerValue: [idx] });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
this.triggerEvent('open');
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
handlePickerChange(e) {
|
|
122
|
+
this.setData({ _pickerValue: e.detail.value });
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
handleOptionTap(e) {
|
|
126
|
+
const val = e.currentTarget.dataset.value;
|
|
127
|
+
const { _selectedValues, maxCount } = this.data;
|
|
128
|
+
const arr = [..._selectedValues];
|
|
129
|
+
const idx = arr.indexOf(val);
|
|
130
|
+
|
|
131
|
+
if (idx >= 0) {
|
|
132
|
+
arr.splice(idx, 1);
|
|
133
|
+
} else {
|
|
134
|
+
if (maxCount > 0 && arr.length >= maxCount) return;
|
|
135
|
+
arr.push(val);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const map = {};
|
|
139
|
+
arr.forEach((v) => {
|
|
140
|
+
map[v] = true;
|
|
141
|
+
});
|
|
142
|
+
this.setData({ _selectedValues: arr, _selectedMap: map });
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
handleConfirm() {
|
|
146
|
+
const { multiple, options, _pickerValue, _selectedValues } = this.data;
|
|
147
|
+
|
|
148
|
+
this.setData({ _visible: false });
|
|
149
|
+
|
|
150
|
+
if (multiple) {
|
|
151
|
+
const tags = _selectedValues
|
|
152
|
+
.map((v) => {
|
|
153
|
+
const opt = options.find((o) => o.value === v);
|
|
154
|
+
return opt ? { label: opt.label, value: opt.value } : null;
|
|
155
|
+
})
|
|
156
|
+
.filter(Boolean);
|
|
157
|
+
this.setData({ _selectedTags: tags });
|
|
158
|
+
this.triggerEvent('update:value', { value: [..._selectedValues] });
|
|
159
|
+
} else {
|
|
160
|
+
const idx = _pickerValue[0] || 0;
|
|
161
|
+
const selected = options[idx];
|
|
162
|
+
if (selected) {
|
|
163
|
+
this.triggerEvent('update:value', { value: selected.value });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
this._notifyChange();
|
|
168
|
+
this.triggerEvent('close');
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
handleCancel() {
|
|
172
|
+
this.setData({ _visible: false });
|
|
173
|
+
this.triggerEvent('close');
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
handleClear() {
|
|
177
|
+
const { multiple } = this.data;
|
|
178
|
+
const emptyVal = multiple ? [] : '';
|
|
179
|
+
this.triggerEvent('update:value', { value: emptyVal });
|
|
180
|
+
this.triggerEvent('clear');
|
|
181
|
+
this._notifyChange();
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
handleTriggerClear() {
|
|
185
|
+
const { multiple } = this.data;
|
|
186
|
+
const emptyVal = multiple ? [] : '';
|
|
187
|
+
this.triggerEvent('update:value', { value: emptyVal });
|
|
188
|
+
this.triggerEvent('clear');
|
|
189
|
+
this._notifyChange();
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
handleTagRemove(e) {
|
|
193
|
+
if (this._isDisabled() || this.data.readonly) return;
|
|
194
|
+
const val = e.currentTarget.dataset.value;
|
|
195
|
+
const { value } = this.data;
|
|
196
|
+
const arr = Array.isArray(value) ? value.filter((v) => v !== val) : [];
|
|
197
|
+
this.triggerEvent('update:value', { value: arr });
|
|
198
|
+
this._notifyChange();
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
});
|