uview-plus 3.7.36 → 3.8.32
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/README.md +0 -1
- package/changelog.md +2047 -1782
- package/components/u-action-sheet/u-action-sheet.vue +54 -16
- package/components/u-agreement/u-agreement.vue +2 -1
- package/components/u-alert/u-alert.vue +8 -10
- package/components/u-button/u-button.vue +35 -5
- package/components/u-calendar/calendar.js +1 -0
- package/components/u-calendar/header.vue +98 -9
- package/components/u-calendar/month.vue +10 -7
- package/components/u-calendar/props.js +5 -0
- package/components/u-calendar/u-calendar.vue +109 -2
- package/components/u-car-keyboard/u-car-keyboard.vue +7 -7
- package/components/u-card/u-card.vue +6 -6
- package/components/u-cascader/u-cascader.vue +32 -12
- package/components/u-cate-tab/u-cate-tab.vue +49 -48
- package/components/u-cell/u-cell.vue +24 -4
- package/components/u-cell-group/u-cell-group.vue +10 -3
- package/components/u-checkbox/u-checkbox.vue +6 -6
- package/components/u-choose/u-choose.vue +9 -4
- package/components/u-city-locate/u-city-locate.vue +28 -22
- package/components/u-color-picker/u-color-picker.vue +15 -15
- package/components/u-cropper/u-cropper.vue +409 -387
- package/components/u-datetime-picker/u-datetime-picker.vue +79 -10
- package/components/u-dragsort/u-dragsort.vue +3 -0
- package/components/u-dropdown/u-dropdown.vue +15 -2
- package/components/u-dropdown-item/u-dropdown-item.vue +3 -3
- package/components/u-form-item/u-form-item.vue +6 -1
- package/components/u-gap/u-gap.vue +5 -1
- package/components/u-goods-sku/u-goods-sku.vue +16 -15
- package/components/u-index-anchor/u-index-anchor.vue +13 -2
- package/components/u-index-list/u-index-list.vue +18 -5
- package/components/u-input/input.js +3 -3
- package/components/u-input/u-input.vue +27 -5
- package/components/u-keyboard/u-keyboard.vue +11 -6
- package/components/u-loading-page/loadingPage.js +1 -1
- package/components/u-loading-page/u-loading-page.vue +18 -12
- package/components/u-navbar/navbar.js +2 -3
- package/components/u-navbar/theme-vars.scss +21 -0
- package/components/u-navbar/u-navbar.vue +30 -6
- package/components/u-notice-bar/theme-vars.scss +25 -0
- package/components/u-notice-bar/u-notice-bar.vue +24 -5
- package/components/u-number-box/numberBox.js +4 -4
- package/components/u-number-box/u-number-box.vue +27 -13
- package/components/u-number-keyboard/u-number-keyboard.vue +6 -6
- package/components/u-picker/picker.js +43 -43
- package/components/u-picker/u-picker.vue +14 -2
- package/components/u-popup/popup.js +1 -1
- package/components/u-popup/u-popup.vue +14 -6
- package/components/u-poster/u-poster.vue +12 -10
- package/components/u-pull-refresh/u-pull-refresh.vue +6 -6
- package/components/u-qrcode/qrcode.js +35 -29
- package/components/u-qrcode/u-qrcode.vue +17 -12
- package/components/u-radio/u-radio.vue +6 -6
- package/components/u-rate/rate.js +2 -2
- package/components/u-rate/u-rate.vue +98 -21
- package/components/u-search/search.js +3 -3
- package/components/u-search/u-search.vue +29 -6
- package/components/u-select/u-select.vue +141 -73
- package/components/u-signature/u-signature.vue +35 -16
- package/components/u-skeleton/u-skeleton.vue +7 -2
- package/components/u-slider/u-slider.vue +30 -31
- package/components/u-steps-item/u-steps-item.vue +20 -17
- package/components/u-subsection/theme-vars.scss +41 -0
- package/components/u-subsection/u-subsection.vue +69 -16
- package/components/u-swipe-action-item/u-swipe-action-item.vue +11 -5
- package/components/u-switch/theme-vars.scss +41 -0
- package/components/u-switch/u-switch.vue +44 -15
- package/components/u-tabbar/u-tabbar.vue +5 -5
- package/components/u-tabbar-item/u-tabbar-item.vue +16 -5
- package/components/u-table/u-table.vue +18 -3
- package/components/u-table2/tableRow.vue +43 -41
- package/components/u-table2/u-table2.vue +56 -50
- package/components/u-tabs/u-tabs.vue +14 -1
- package/components/u-tag/theme-vars.scss +21 -0
- package/components/u-tag/u-tag.vue +17 -7
- package/components/u-td/u-td.vue +5 -3
- package/components/u-text/text.js +1 -1
- package/components/u-text/u-text.vue +15 -13
- package/components/u-textarea/props.js +2 -2
- package/components/u-textarea/textarea.js +1 -1
- package/components/u-textarea/u-textarea.vue +115 -61
- package/components/u-th/u-th.vue +5 -4
- package/components/u-title/u-title.vue +1 -0
- package/components/u-toast/u-toast.vue +13 -9
- package/components/u-tooltip/u-tooltip.vue +1 -0
- package/components/u-tree/u-tree.vue +491 -51
- package/components/u-upload/u-upload.vue +34 -6
- package/index.js +178 -27
- package/index.scss +5 -1
- package/libs/config/color.js +1 -2
- package/libs/config/config.js +2 -0
- package/libs/config/props.js +1 -1
- package/libs/css/theme-vars-core.scss +201 -0
- package/libs/css/theme-vars.scss +1 -0
- package/libs/function/index.js +7 -7
- package/libs/mixin/mixin.js +111 -4
- package/libs/root/index.js +151 -0
- package/libs/root/nvue-root.vue +72 -0
- package/libs/root/page.js +269 -0
- package/libs/root/root-toast-host.vue +31 -0
- package/libs/root/root.js +44 -0
- package/libs/root/runtime.js +11 -0
- package/libs/root/utils.js +115 -0
- package/libs/theme/runtime.js +392 -0
- package/libs/theme/theme.js +682 -0
- package/libs/util/gcanvas/bridge/bridge-weex.js +0 -0
- package/libs/util/gcanvas/context-2d/FillStyleLinearGradient.js +0 -0
- package/libs/util/gcanvas/context-2d/FillStylePattern.js +0 -0
- package/libs/util/gcanvas/context-2d/FillStyleRadialGradient.js +0 -0
- package/libs/util/gcanvas/context-2d/RenderingContext.js +0 -0
- package/libs/util/gcanvas/context-webgl/ActiveInfo.js +0 -0
- package/libs/util/gcanvas/context-webgl/Buffer.js +0 -0
- package/libs/util/gcanvas/context-webgl/Framebuffer.js +0 -0
- package/libs/util/gcanvas/context-webgl/GLenum.js +0 -0
- package/libs/util/gcanvas/context-webgl/GLmethod.js +0 -0
- package/libs/util/gcanvas/context-webgl/GLtype.js +0 -0
- package/libs/util/gcanvas/context-webgl/Program.js +0 -0
- package/libs/util/gcanvas/context-webgl/Renderbuffer.js +0 -0
- package/libs/util/gcanvas/context-webgl/RenderingContext.js +0 -0
- package/libs/util/gcanvas/context-webgl/Shader.js +0 -0
- package/libs/util/gcanvas/context-webgl/ShaderPrecisionFormat.js +0 -0
- package/libs/util/gcanvas/context-webgl/Texture.js +0 -0
- package/libs/util/gcanvas/context-webgl/UniformLocation.js +0 -0
- package/libs/util/gcanvas/context-webgl/classUtils.js +0 -0
- package/libs/util/gcanvas/env/canvas.js +0 -0
- package/libs/util/gcanvas/env/image.js +0 -0
- package/libs/util/gcanvas/env/tool.js +0 -0
- package/libs/util/gcanvas/index.js +0 -0
- package/package.json +3 -2
- package/theme.scss +113 -32
- package/types/comps/qrcode.d.ts +6 -0
- package/types/index.d.ts +47 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<view class="u-toast">
|
|
3
3
|
<u-overlay
|
|
4
4
|
:show="isShow"
|
|
5
|
-
:zIndex="tmpConfig.
|
|
5
|
+
:zIndex="tmpConfig.zIndex"
|
|
6
6
|
:custom-style="overlayStyle"
|
|
7
7
|
>
|
|
8
8
|
<view
|
|
@@ -112,6 +112,10 @@
|
|
|
112
112
|
}
|
|
113
113
|
// 将遮罩设置为100%透明度,避免出现灰色背景
|
|
114
114
|
style.backgroundColor = 'rgba(0, 0, 0, 0)'
|
|
115
|
+
// overlay=false时不阻止点击穿透
|
|
116
|
+
if (!this.tmpConfig.overlay) {
|
|
117
|
+
style.pointerEvents = 'none'
|
|
118
|
+
}
|
|
115
119
|
return style
|
|
116
120
|
},
|
|
117
121
|
iconStyle() {
|
|
@@ -205,20 +209,20 @@
|
|
|
205
209
|
$u-toast-content-text-font-size:15px !default;
|
|
206
210
|
$u-toast-up-icon:10rpx !default;
|
|
207
211
|
$u-toast-u-type-primary-color:$u-primary !default;
|
|
208
|
-
$u-toast-u-type-primary-background-color
|
|
209
|
-
$u-toast-u-type-primary-border-color
|
|
212
|
+
$u-toast-u-type-primary-background-color:$u-primary-light !default;
|
|
213
|
+
$u-toast-u-type-primary-border-color:$u-primary-disabled !default;
|
|
210
214
|
$u-toast-u-type-primary-border-width:1px !default;
|
|
211
215
|
$u-toast-u-type-success-color: $u-success !default;
|
|
212
|
-
$u-toast-u-type-success-background-color:
|
|
213
|
-
$u-toast-u-type-success-border-color:
|
|
216
|
+
$u-toast-u-type-success-background-color: $u-success-light !default;
|
|
217
|
+
$u-toast-u-type-success-border-color: $u-success-disabled !default;
|
|
214
218
|
$u-toast-u-type-success-border-width: 1px !default;
|
|
215
219
|
$u-toast-u-type-error-color:$u-error !default;
|
|
216
|
-
$u-toast-u-type-error-background-color
|
|
217
|
-
$u-toast-u-type-error-border-color
|
|
220
|
+
$u-toast-u-type-error-background-color:$u-error-light !default;
|
|
221
|
+
$u-toast-u-type-error-border-color:$u-error-disabled !default;
|
|
218
222
|
$u-toast-u-type-error-border-width: 1px !default;
|
|
219
223
|
$u-toast-u-type-warning-color:$u-warning !default;
|
|
220
|
-
$u-toast-u-type-warning-background-color
|
|
221
|
-
$u-toast-u-type-warning-border-color
|
|
224
|
+
$u-toast-u-type-warning-background-color:$u-warning-light !default;
|
|
225
|
+
$u-toast-u-type-warning-border-color:$u-warning-disabled !default;
|
|
222
226
|
$u-toast-u-type-warning-border-width: 1px !default;
|
|
223
227
|
$u-toast-u-type-default-color:#fff !default;
|
|
224
228
|
$u-toast-u-type-default-background-color:#585858 !default;
|
|
@@ -1,41 +1,81 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view class="u-tree">
|
|
3
|
-
<
|
|
4
|
-
v-for="
|
|
5
|
-
:key="
|
|
6
|
-
|
|
7
|
-
:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
<view
|
|
4
|
+
v-for="item in visibleNodes"
|
|
5
|
+
:key="item.key"
|
|
6
|
+
class="u-tree-node"
|
|
7
|
+
:class="getNodeClass(item)"
|
|
8
|
+
>
|
|
9
|
+
<view
|
|
10
|
+
class="u-tree-node__content"
|
|
11
|
+
:style="getNodeContentStyle(item)"
|
|
12
|
+
@tap="handleNodeClick(item)"
|
|
13
|
+
>
|
|
14
|
+
<view class="u-tree-node__switcher" @tap.stop="handleExpandClick(item)">
|
|
15
|
+
<up-icon
|
|
16
|
+
v-if="item.hasChildren"
|
|
17
|
+
:name="item.expanded ? collapseIcon : expandIcon"
|
|
18
|
+
:size="iconSize"
|
|
19
|
+
:color="switcherColor"
|
|
20
|
+
/>
|
|
21
|
+
</view>
|
|
22
|
+
<up-checkbox
|
|
23
|
+
v-if="showCheckbox"
|
|
24
|
+
class="u-tree-node__checkbox"
|
|
25
|
+
usedAlone
|
|
26
|
+
:size="checkboxSize"
|
|
27
|
+
:checked="item.checked"
|
|
28
|
+
:disabled="item.disabled"
|
|
29
|
+
@change="handleCheckboxChange(item, $event)"
|
|
30
|
+
/>
|
|
31
|
+
<view class="u-tree-node__label">
|
|
32
|
+
<!-- #ifndef MP-WEIXIN -->
|
|
33
|
+
<slot
|
|
34
|
+
:node="item.node"
|
|
35
|
+
:data="item.node"
|
|
36
|
+
:level="item.level + 1"
|
|
37
|
+
:expanded="item.expanded"
|
|
38
|
+
:checked="item.checked"
|
|
39
|
+
:indeterminate="item.indeterminate"
|
|
40
|
+
:disabled="item.disabled"
|
|
41
|
+
>
|
|
42
|
+
<text class="u-tree-node__text">{{ getNodeLabel(item.node) }}</text>
|
|
43
|
+
</slot>
|
|
44
|
+
<!-- #endif -->
|
|
45
|
+
<!-- #ifdef MP-WEIXIN -->
|
|
46
|
+
<text class="u-tree-node__text">{{ getNodeLabel(item.node) }}</text>
|
|
47
|
+
<!-- #endif -->
|
|
48
|
+
</view>
|
|
49
|
+
</view>
|
|
50
|
+
</view>
|
|
17
51
|
</view>
|
|
18
52
|
</template>
|
|
19
53
|
|
|
20
54
|
<script>
|
|
21
|
-
import
|
|
55
|
+
import { mpMixin } from '../../libs/mixin/mpMixin';
|
|
56
|
+
import { mixin } from '../../libs/mixin/mixin';
|
|
22
57
|
|
|
23
58
|
export default {
|
|
24
59
|
name: 'u-tree',
|
|
25
|
-
|
|
60
|
+
mixins: [mpMixin, mixin],
|
|
26
61
|
props: {
|
|
27
62
|
data: {
|
|
28
63
|
type: Array,
|
|
29
|
-
|
|
64
|
+
default: () => []
|
|
30
65
|
},
|
|
31
66
|
props: {
|
|
32
67
|
type: Object,
|
|
33
68
|
default: () => ({
|
|
34
69
|
label: 'label',
|
|
35
70
|
children: 'children',
|
|
36
|
-
nodeKey: 'id'
|
|
71
|
+
nodeKey: 'id',
|
|
72
|
+
disabled: 'disabled'
|
|
37
73
|
})
|
|
38
74
|
},
|
|
75
|
+
nodeKey: {
|
|
76
|
+
type: String,
|
|
77
|
+
default: ''
|
|
78
|
+
},
|
|
39
79
|
showCheckbox: {
|
|
40
80
|
type: Boolean,
|
|
41
81
|
default: false
|
|
@@ -44,74 +84,474 @@ export default {
|
|
|
44
84
|
type: Boolean,
|
|
45
85
|
default: false
|
|
46
86
|
},
|
|
87
|
+
defaultExpandedKeys: {
|
|
88
|
+
type: Array,
|
|
89
|
+
default: () => []
|
|
90
|
+
},
|
|
91
|
+
defaultCheckedKeys: {
|
|
92
|
+
type: Array,
|
|
93
|
+
default: () => []
|
|
94
|
+
},
|
|
47
95
|
expandOnClickNode: {
|
|
48
96
|
type: Boolean,
|
|
49
97
|
default: true
|
|
50
98
|
},
|
|
99
|
+
checkOnClickNode: {
|
|
100
|
+
type: Boolean,
|
|
101
|
+
default: false
|
|
102
|
+
},
|
|
51
103
|
checkStrictly: {
|
|
52
104
|
type: Boolean,
|
|
53
105
|
default: false
|
|
106
|
+
},
|
|
107
|
+
accordion: {
|
|
108
|
+
type: Boolean,
|
|
109
|
+
default: false
|
|
110
|
+
},
|
|
111
|
+
highlightCurrent: {
|
|
112
|
+
type: Boolean,
|
|
113
|
+
default: false
|
|
114
|
+
},
|
|
115
|
+
currentNodeKey: {
|
|
116
|
+
type: [String, Number],
|
|
117
|
+
default: ''
|
|
118
|
+
},
|
|
119
|
+
indent: {
|
|
120
|
+
type: [String, Number],
|
|
121
|
+
default: 32
|
|
122
|
+
},
|
|
123
|
+
iconSize: {
|
|
124
|
+
type: [String, Number],
|
|
125
|
+
default: 14
|
|
126
|
+
},
|
|
127
|
+
checkboxSize: {
|
|
128
|
+
type: [String, Number],
|
|
129
|
+
default: 16
|
|
130
|
+
},
|
|
131
|
+
expandIcon: {
|
|
132
|
+
type: String,
|
|
133
|
+
default: 'play-right-fill'
|
|
134
|
+
},
|
|
135
|
+
collapseIcon: {
|
|
136
|
+
type: String,
|
|
137
|
+
default: 'arrow-down-fill'
|
|
54
138
|
}
|
|
55
139
|
},
|
|
56
140
|
data() {
|
|
57
141
|
return {
|
|
58
|
-
treeData: []
|
|
142
|
+
treeData: [],
|
|
143
|
+
currentKey: '',
|
|
144
|
+
nodeMap: {},
|
|
145
|
+
privateKeySeed: 0
|
|
59
146
|
};
|
|
60
147
|
},
|
|
61
|
-
|
|
62
|
-
|
|
148
|
+
computed: {
|
|
149
|
+
treeProps() {
|
|
150
|
+
return Object.assign({
|
|
151
|
+
label: 'label',
|
|
152
|
+
children: 'children',
|
|
153
|
+
nodeKey: 'id',
|
|
154
|
+
disabled: 'disabled'
|
|
155
|
+
}, this.props || {});
|
|
156
|
+
},
|
|
157
|
+
labelKey() {
|
|
158
|
+
return this.treeProps.label;
|
|
159
|
+
},
|
|
160
|
+
childrenKey() {
|
|
161
|
+
return this.treeProps.children;
|
|
162
|
+
},
|
|
163
|
+
disabledKey() {
|
|
164
|
+
return this.treeProps.disabled;
|
|
165
|
+
},
|
|
166
|
+
keyField() {
|
|
167
|
+
return this.nodeKey || this.treeProps.nodeKey || 'id';
|
|
168
|
+
},
|
|
169
|
+
visibleNodes() {
|
|
170
|
+
const result = [];
|
|
171
|
+
this.collectVisibleNodes(this.treeData, 0, result);
|
|
172
|
+
return result;
|
|
173
|
+
},
|
|
174
|
+
switcherColor() {
|
|
175
|
+
return this.upThemeVar('--up-content-color', '#606266');
|
|
176
|
+
}
|
|
63
177
|
},
|
|
64
178
|
watch: {
|
|
65
179
|
data: {
|
|
66
|
-
handler(
|
|
67
|
-
this.
|
|
68
|
-
this.initExpandedState(this.treeData, this.defaultExpandAll);
|
|
180
|
+
handler() {
|
|
181
|
+
this.initTree();
|
|
69
182
|
},
|
|
70
183
|
deep: true,
|
|
71
184
|
immediate: true
|
|
185
|
+
},
|
|
186
|
+
props: {
|
|
187
|
+
handler() {
|
|
188
|
+
this.initTree();
|
|
189
|
+
},
|
|
190
|
+
deep: true
|
|
191
|
+
},
|
|
192
|
+
nodeKey() {
|
|
193
|
+
this.initTree();
|
|
194
|
+
},
|
|
195
|
+
defaultExpandAll() {
|
|
196
|
+
this.initTree();
|
|
197
|
+
},
|
|
198
|
+
defaultExpandedKeys() {
|
|
199
|
+
this.initTree();
|
|
200
|
+
},
|
|
201
|
+
defaultCheckedKeys() {
|
|
202
|
+
this.initTree();
|
|
203
|
+
},
|
|
204
|
+
checkStrictly() {
|
|
205
|
+
this.initTree();
|
|
206
|
+
},
|
|
207
|
+
currentNodeKey: {
|
|
208
|
+
handler(value) {
|
|
209
|
+
this.currentKey = value;
|
|
210
|
+
},
|
|
211
|
+
immediate: true
|
|
72
212
|
}
|
|
73
213
|
},
|
|
74
|
-
emits: [
|
|
214
|
+
emits: [
|
|
215
|
+
'node-click',
|
|
216
|
+
'check-change',
|
|
217
|
+
'check',
|
|
218
|
+
'node-expand',
|
|
219
|
+
'node-collapse',
|
|
220
|
+
'current-change'
|
|
221
|
+
],
|
|
75
222
|
methods: {
|
|
76
223
|
initTree() {
|
|
77
|
-
this.
|
|
78
|
-
this.
|
|
224
|
+
this.privateKeySeed = 0;
|
|
225
|
+
this.nodeMap = {};
|
|
226
|
+
this.treeData = this.cloneNodes(this.data || [], null, 0);
|
|
227
|
+
if (!this.checkStrictly) {
|
|
228
|
+
this.syncParentChecked(this.treeData);
|
|
229
|
+
}
|
|
79
230
|
},
|
|
80
|
-
|
|
231
|
+
cloneNodes(nodes, parent, level) {
|
|
232
|
+
const list = [];
|
|
233
|
+
nodes.forEach((node, index) => {
|
|
234
|
+
const clone = Object.assign({}, node);
|
|
235
|
+
const key = this.resolveNodeKey(clone, parent, index);
|
|
236
|
+
const children = Array.isArray(node[this.childrenKey]) ? node[this.childrenKey] : [];
|
|
237
|
+
const expanded = this.defaultExpandAll || this.includesKey(this.defaultExpandedKeys, key) || clone.expanded === true;
|
|
238
|
+
const checked = this.includesKey(this.defaultCheckedKeys, key) || clone.checked === true;
|
|
239
|
+
|
|
240
|
+
clone.__uTreeKey = key;
|
|
241
|
+
clone.expanded = expanded;
|
|
242
|
+
clone.checked = checked;
|
|
243
|
+
clone.indeterminate = false;
|
|
244
|
+
clone[this.childrenKey] = this.cloneNodes(children, clone, level + 1);
|
|
245
|
+
if (checked && !this.checkStrictly) {
|
|
246
|
+
this.setChildrenChecked(clone, true);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
this.nodeMap[key] = {
|
|
250
|
+
node: clone,
|
|
251
|
+
parent,
|
|
252
|
+
level
|
|
253
|
+
};
|
|
254
|
+
list.push(clone);
|
|
255
|
+
});
|
|
256
|
+
return list;
|
|
257
|
+
},
|
|
258
|
+
resolveNodeKey(node, parent, index) {
|
|
259
|
+
const rawKey = node[this.keyField];
|
|
260
|
+
if (rawKey !== undefined && rawKey !== null && rawKey !== '') {
|
|
261
|
+
return rawKey;
|
|
262
|
+
}
|
|
263
|
+
const parentKey = parent ? parent.__uTreeKey : 'root';
|
|
264
|
+
this.privateKeySeed += 1;
|
|
265
|
+
return parentKey + '-' + index + '-' + this.privateKeySeed;
|
|
266
|
+
},
|
|
267
|
+
collectVisibleNodes(nodes, level, result) {
|
|
81
268
|
nodes.forEach(node => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
269
|
+
const children = this.getChildren(node);
|
|
270
|
+
const key = this.getNodeKey(node);
|
|
271
|
+
result.push({
|
|
272
|
+
key,
|
|
273
|
+
node,
|
|
274
|
+
level,
|
|
275
|
+
hasChildren: children.length > 0,
|
|
276
|
+
expanded: node.expanded === true,
|
|
277
|
+
checked: node.checked === true,
|
|
278
|
+
indeterminate: node.indeterminate === true,
|
|
279
|
+
disabled: this.isNodeDisabled(node)
|
|
280
|
+
});
|
|
281
|
+
if (children.length > 0 && node.expanded === true) {
|
|
282
|
+
this.collectVisibleNodes(children, level + 1, result);
|
|
85
283
|
}
|
|
86
284
|
});
|
|
87
285
|
},
|
|
88
|
-
|
|
286
|
+
getChildren(node) {
|
|
287
|
+
const children = node ? node[this.childrenKey] : [];
|
|
288
|
+
return Array.isArray(children) ? children : [];
|
|
289
|
+
},
|
|
290
|
+
getNodeKey(node) {
|
|
291
|
+
return node ? node.__uTreeKey : '';
|
|
292
|
+
},
|
|
293
|
+
getNodeLabel(node) {
|
|
294
|
+
const label = node ? node[this.labelKey] : '';
|
|
295
|
+
return label === undefined || label === null ? '' : label;
|
|
296
|
+
},
|
|
297
|
+
isNodeDisabled(node) {
|
|
298
|
+
return !!(node && node[this.disabledKey]);
|
|
299
|
+
},
|
|
300
|
+
includesKey(keys, key) {
|
|
301
|
+
return Array.isArray(keys) && keys.indexOf(key) !== -1;
|
|
302
|
+
},
|
|
303
|
+
getNodeClass(item) {
|
|
304
|
+
const classes = [];
|
|
305
|
+
if (this.highlightCurrent && item.key === this.currentKey) {
|
|
306
|
+
classes.push('u-tree-node--current');
|
|
307
|
+
}
|
|
308
|
+
if (item.disabled) {
|
|
309
|
+
classes.push('u-tree-node--disabled');
|
|
310
|
+
}
|
|
311
|
+
return classes.join(' ');
|
|
312
|
+
},
|
|
313
|
+
getNodeContentStyle(item) {
|
|
314
|
+
return {
|
|
315
|
+
paddingLeft: this.getIndentValue(item.level)
|
|
316
|
+
};
|
|
317
|
+
},
|
|
318
|
+
getIndentValue(level) {
|
|
319
|
+
const indent = String(this.indent);
|
|
320
|
+
const matched = indent.match(/^(\d+(?:\.\d+)?)(.*)$/);
|
|
321
|
+
if (!matched) {
|
|
322
|
+
return indent;
|
|
323
|
+
}
|
|
324
|
+
const unit = matched[2] || 'rpx';
|
|
325
|
+
return (Number(matched[1]) * level) + unit;
|
|
326
|
+
},
|
|
327
|
+
handleNodeClick(item) {
|
|
328
|
+
const node = item.node;
|
|
329
|
+
const oldCurrentNode = this.getCurrentNode();
|
|
330
|
+
|
|
331
|
+
this.currentKey = item.key;
|
|
332
|
+
if (this.expandOnClickNode && item.hasChildren) {
|
|
333
|
+
this.toggleExpand(item);
|
|
334
|
+
}
|
|
335
|
+
if (this.checkOnClickNode && this.showCheckbox && !item.disabled) {
|
|
336
|
+
this.setNodeChecked(node, !node.checked, true);
|
|
337
|
+
this.emitCheck(node);
|
|
338
|
+
}
|
|
339
|
+
|
|
89
340
|
this.$emit('node-click', node);
|
|
341
|
+
if (oldCurrentNode !== node) {
|
|
342
|
+
this.$emit('current-change', node, oldCurrentNode);
|
|
343
|
+
}
|
|
90
344
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
345
|
+
handleExpandClick(item) {
|
|
346
|
+
if (!item.hasChildren) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
this.toggleExpand(item);
|
|
350
|
+
},
|
|
351
|
+
toggleExpand(item) {
|
|
352
|
+
const node = item.node;
|
|
353
|
+
const nextExpanded = node.expanded !== true;
|
|
354
|
+
if (this.accordion && nextExpanded) {
|
|
355
|
+
this.collapseSiblingNodes(node);
|
|
356
|
+
}
|
|
357
|
+
node.expanded = nextExpanded;
|
|
358
|
+
this.$emit(nextExpanded ? 'node-expand' : 'node-collapse', node);
|
|
359
|
+
},
|
|
360
|
+
collapseSiblingNodes(node) {
|
|
361
|
+
const parent = this.getParentNode(node);
|
|
362
|
+
const siblings = parent ? this.getChildren(parent) : this.treeData;
|
|
363
|
+
siblings.forEach(sibling => {
|
|
364
|
+
if (sibling !== node) {
|
|
365
|
+
sibling.expanded = false;
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
},
|
|
369
|
+
handleCheckboxChange(item, checked) {
|
|
370
|
+
if (item.disabled) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
this.setNodeChecked(item.node, checked, true);
|
|
374
|
+
this.$emit('check-change', item.node, checked);
|
|
375
|
+
this.emitCheck(item.node);
|
|
376
|
+
},
|
|
377
|
+
setNodeChecked(node, checked, deep) {
|
|
378
|
+
node.checked = checked;
|
|
379
|
+
node.indeterminate = false;
|
|
380
|
+
if (!this.checkStrictly && deep !== false) {
|
|
381
|
+
this.setChildrenChecked(node, checked);
|
|
382
|
+
}
|
|
383
|
+
if (!this.checkStrictly) {
|
|
384
|
+
this.updateParentChecked(node);
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
setChildrenChecked(node, checked) {
|
|
388
|
+
this.getChildren(node).forEach(child => {
|
|
389
|
+
if (!this.isNodeDisabled(child)) {
|
|
390
|
+
child.checked = checked;
|
|
391
|
+
child.indeterminate = false;
|
|
392
|
+
this.setChildrenChecked(child, checked);
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
},
|
|
396
|
+
updateParentChecked(node) {
|
|
397
|
+
const parent = this.getParentNode(node);
|
|
398
|
+
if (!parent) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const children = this.getChildren(parent).filter(child => !this.isNodeDisabled(child));
|
|
402
|
+
const allChecked = children.length > 0 && children.every(child => child.checked === true);
|
|
403
|
+
const someChecked = children.some(child => child.checked === true || child.indeterminate === true);
|
|
404
|
+
parent.checked = allChecked;
|
|
405
|
+
parent.indeterminate = !allChecked && someChecked;
|
|
406
|
+
this.updateParentChecked(parent);
|
|
407
|
+
},
|
|
408
|
+
syncParentChecked(nodes) {
|
|
409
|
+
nodes.forEach(node => {
|
|
410
|
+
const children = this.getChildren(node);
|
|
411
|
+
if (children.length > 0) {
|
|
412
|
+
this.syncParentChecked(children);
|
|
413
|
+
const enabledChildren = children.filter(child => !this.isNodeDisabled(child));
|
|
414
|
+
const allChecked = enabledChildren.length > 0 && enabledChildren.every(child => child.checked === true);
|
|
415
|
+
const someChecked = enabledChildren.some(child => child.checked === true || child.indeterminate === true);
|
|
416
|
+
node.checked = allChecked;
|
|
417
|
+
node.indeterminate = !allChecked && someChecked;
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
},
|
|
421
|
+
getParentNode(node) {
|
|
422
|
+
const mapItem = this.nodeMap[this.getNodeKey(node)];
|
|
423
|
+
return mapItem ? mapItem.parent : null;
|
|
424
|
+
},
|
|
425
|
+
walkNodes(nodes, callback) {
|
|
426
|
+
nodes.forEach(node => {
|
|
427
|
+
callback(node);
|
|
428
|
+
this.walkNodes(this.getChildren(node), callback);
|
|
429
|
+
});
|
|
430
|
+
},
|
|
431
|
+
getNodeByKey(key) {
|
|
432
|
+
const mapItem = this.nodeMap[key];
|
|
433
|
+
return mapItem ? mapItem.node : null;
|
|
434
|
+
},
|
|
435
|
+
getCheckedNodes(leafOnly) {
|
|
436
|
+
const result = [];
|
|
437
|
+
this.walkNodes(this.treeData, node => {
|
|
438
|
+
const isLeaf = this.getChildren(node).length === 0;
|
|
439
|
+
if (node.checked === true && (!leafOnly || isLeaf)) {
|
|
440
|
+
result.push(node);
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
return result;
|
|
444
|
+
},
|
|
445
|
+
getCheckedKeys(leafOnly) {
|
|
446
|
+
return this.getCheckedNodes(leafOnly).map(node => this.getNodeKey(node));
|
|
447
|
+
},
|
|
448
|
+
getHalfCheckedNodes() {
|
|
449
|
+
const result = [];
|
|
450
|
+
this.walkNodes(this.treeData, node => {
|
|
451
|
+
if (node.indeterminate === true) {
|
|
452
|
+
result.push(node);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
return result;
|
|
456
|
+
},
|
|
457
|
+
getHalfCheckedKeys() {
|
|
458
|
+
return this.getHalfCheckedNodes().map(node => this.getNodeKey(node));
|
|
459
|
+
},
|
|
460
|
+
setCheckedKeys(keys, leafOnly) {
|
|
461
|
+
const checkedKeys = Array.isArray(keys) ? keys : [];
|
|
462
|
+
this.walkNodes(this.treeData, node => {
|
|
463
|
+
node.checked = false;
|
|
464
|
+
node.indeterminate = false;
|
|
465
|
+
});
|
|
466
|
+
checkedKeys.forEach(key => {
|
|
467
|
+
const node = this.getNodeByKey(key);
|
|
468
|
+
if (node) {
|
|
469
|
+
const isLeaf = this.getChildren(node).length === 0;
|
|
470
|
+
if (!leafOnly || isLeaf) {
|
|
471
|
+
this.setNodeChecked(node, true, !this.checkStrictly);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
if (!this.checkStrictly) {
|
|
476
|
+
this.syncParentChecked(this.treeData);
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
setChecked(key, checked, deep) {
|
|
480
|
+
const node = typeof key === 'object' ? key : this.getNodeByKey(key);
|
|
481
|
+
if (node) {
|
|
482
|
+
this.setNodeChecked(node, checked, deep);
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
setCurrentKey(key) {
|
|
486
|
+
this.currentKey = key;
|
|
487
|
+
},
|
|
488
|
+
getCurrentKey() {
|
|
489
|
+
return this.currentKey;
|
|
490
|
+
},
|
|
491
|
+
getCurrentNode() {
|
|
492
|
+
return this.getNodeByKey(this.currentKey);
|
|
493
|
+
},
|
|
494
|
+
emitCheck(node) {
|
|
495
|
+
this.$emit('check', node, {
|
|
496
|
+
checkedNodes: this.getCheckedNodes(false),
|
|
497
|
+
checkedKeys: this.getCheckedKeys(false),
|
|
498
|
+
halfCheckedNodes: this.getHalfCheckedNodes(),
|
|
499
|
+
halfCheckedKeys: this.getHalfCheckedKeys()
|
|
500
|
+
});
|
|
108
501
|
}
|
|
109
502
|
}
|
|
110
503
|
};
|
|
111
504
|
</script>
|
|
112
505
|
|
|
113
|
-
<style scoped>
|
|
506
|
+
<style lang="scss" scoped>
|
|
114
507
|
.u-tree {
|
|
115
508
|
font-size: 28rpx;
|
|
509
|
+
color: var(--up-main-color, #303133);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
.u-tree-node__content {
|
|
513
|
+
display: flex;
|
|
514
|
+
flex-direction: row;
|
|
515
|
+
align-items: center;
|
|
516
|
+
min-height: 72rpx;
|
|
517
|
+
box-sizing: border-box;
|
|
518
|
+
border-radius: 8rpx;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
.u-tree-node--current .u-tree-node__content {
|
|
522
|
+
background-color: var(--up-primary-light, #ecf5ff);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
.u-tree-node--disabled {
|
|
526
|
+
opacity: 0.55;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
.u-tree-node__switcher {
|
|
530
|
+
width: 36rpx;
|
|
531
|
+
height: 36rpx;
|
|
532
|
+
display: flex;
|
|
533
|
+
flex-direction: row;
|
|
534
|
+
align-items: center;
|
|
535
|
+
justify-content: center;
|
|
536
|
+
flex-shrink: 0;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
.u-tree-node__checkbox {
|
|
540
|
+
margin-left: 8rpx;
|
|
541
|
+
margin-right: 8rpx;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
.u-tree-node__label {
|
|
545
|
+
flex: 1;
|
|
546
|
+
min-width: 0;
|
|
547
|
+
display: flex;
|
|
548
|
+
flex-direction: row;
|
|
549
|
+
align-items: center;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
.u-tree-node__text {
|
|
553
|
+
color: var(--up-main-color, #303133);
|
|
554
|
+
font-size: 28rpx;
|
|
555
|
+
line-height: 40rpx;
|
|
116
556
|
}
|
|
117
|
-
</style>
|
|
557
|
+
</style>
|