@netang/quasar 0.2.11 → 0.2.13
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/components/data/index.vue +20 -20
- package/components/dialog/index.vue +2 -2
- package/components/dragger/index.vue +203 -203
- package/components/field-date/methods.js +100 -100
- package/components/field-text/index.vue +165 -165
- package/components/input-number/index.vue +21 -13
- package/components/list-menu/index.vue +149 -149
- package/components/list-menu-item/index.vue +79 -79
- package/components/price/index.vue +188 -188
- package/components/private/components/index.js +11 -11
- package/components/table-pagination/index.vue +192 -192
- package/components/thumbnail/index.vue +72 -72
- package/components/value-format/index.vue +274 -274
- package/configs/area3.js +1 -1
- package/docs/css/index.css +3 -3
- package/package.json +1 -1
- package/sass/line.scss +39 -39
- package/sass/quasar/btn.scss +46 -46
- package/sass/quasar/common.scss +3 -3
- package/sass/quasar/drawer.scss +6 -6
- package/sass/quasar/loading.scss +6 -6
- package/sass/quasar/toolbar.scss +22 -22
- package/store/index.js +29 -29
- package/utils/$auth.js +127 -127
- package/utils/$rule.js +13 -13
- package/utils/$ruleValid.js +10 -10
- package/utils/alert.js +12 -12
- package/utils/area.js +400 -400
- package/utils/arr.js +51 -51
- package/utils/bus.js +6 -6
- package/utils/confirm.js +11 -11
- package/utils/copy.js +30 -30
- package/utils/dictOptions.js +28 -28
- package/utils/loading.js +15 -15
- package/utils/notify.js +13 -13
- package/utils/price.js +18 -18
- package/utils/symbols.js +18 -18
- package/utils/toast.js +13 -13
- package/utils/useAuth.js +30 -30
- package/utils/useRouter.js +47 -47
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<q-field
|
|
3
|
-
class="n-field-fieldset"
|
|
4
|
-
:label="label"
|
|
5
|
-
:stack-label="stackLabel"
|
|
6
|
-
:outlined="outlined"
|
|
7
|
-
:dense="dense"
|
|
8
|
-
:readonly="readonly"
|
|
9
|
-
v-bind="$attrs"
|
|
10
|
-
>
|
|
11
|
-
<template v-slot:control>
|
|
12
|
-
|
|
13
|
-
<!-- 如果有默认插槽 -->
|
|
14
|
-
<template v-if="$slots.default">
|
|
15
|
-
|
|
16
|
-
<!-- 如果开启复制 -->
|
|
17
|
-
<div
|
|
18
|
-
class="full-width"
|
|
19
|
-
:class="valueClass"
|
|
20
|
-
:style="valueStyle"
|
|
21
|
-
@click="onCopy"
|
|
22
|
-
v-if="! noCopy"
|
|
23
|
-
>
|
|
24
|
-
<slot
|
|
25
|
-
:value="value"
|
|
26
|
-
/>
|
|
27
|
-
</div>
|
|
28
|
-
|
|
29
|
-
<!-- 否则仅展示 -->
|
|
30
|
-
<div
|
|
31
|
-
class="full-width"
|
|
32
|
-
:class="valueClass"
|
|
33
|
-
:style="valueStyle"
|
|
34
|
-
v-else
|
|
35
|
-
>
|
|
36
|
-
<slot
|
|
37
|
-
:value="value"
|
|
38
|
-
/>
|
|
39
|
-
</div>
|
|
40
|
-
</template>
|
|
41
|
-
|
|
42
|
-
<!-- 否则如果开启复制 -->
|
|
43
|
-
<div
|
|
44
|
-
class="full-width"
|
|
45
|
-
:class="valueClass"
|
|
46
|
-
:style="valueStyle"
|
|
47
|
-
@click="onCopy"
|
|
48
|
-
v-else-if="! noCopy"
|
|
49
|
-
>{{value}}</div>
|
|
50
|
-
|
|
51
|
-
<!-- 否则仅展示 -->
|
|
52
|
-
<div
|
|
53
|
-
class="full-width"
|
|
54
|
-
:class="valueClass"
|
|
55
|
-
:style="valueStyle"
|
|
56
|
-
v-else
|
|
57
|
-
>{{value}}</div>
|
|
58
|
-
|
|
59
|
-
</template>
|
|
60
|
-
|
|
61
|
-
<template
|
|
62
|
-
v-for="slotName in slotNames"
|
|
63
|
-
v-slot:[slotName]
|
|
64
|
-
>
|
|
65
|
-
<slot
|
|
66
|
-
:name="slotName"
|
|
67
|
-
:value="value"
|
|
68
|
-
/>
|
|
69
|
-
</template>
|
|
70
|
-
</q-field>
|
|
71
|
-
</template>
|
|
72
|
-
|
|
73
|
-
<script>
|
|
74
|
-
import { computed } from 'vue'
|
|
75
|
-
|
|
76
|
-
import $n_omit from 'lodash/omit'
|
|
77
|
-
|
|
78
|
-
import $n_isValidObject from '@netang/utils/isValidObject'
|
|
79
|
-
|
|
80
|
-
import $n_copy from '../../utils/copy'
|
|
81
|
-
|
|
82
|
-
export default {
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* 标识
|
|
86
|
-
*/
|
|
87
|
-
name: 'NFieldText',
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* 声明属性
|
|
91
|
-
*/
|
|
92
|
-
props: {
|
|
93
|
-
// 标签
|
|
94
|
-
label: [Array, String, Number],
|
|
95
|
-
// 值
|
|
96
|
-
value: [String, Number],
|
|
97
|
-
// 复制文字
|
|
98
|
-
copyText: [String, Number],
|
|
99
|
-
// 标签始终显示在字段上方
|
|
100
|
-
stackLabel: {
|
|
101
|
-
type: Boolean,
|
|
102
|
-
default: true,
|
|
103
|
-
},
|
|
104
|
-
// 线条
|
|
105
|
-
outlined: {
|
|
106
|
-
type: Boolean,
|
|
107
|
-
default: true,
|
|
108
|
-
},
|
|
109
|
-
// 紧凑模式
|
|
110
|
-
dense: {
|
|
111
|
-
type: Boolean,
|
|
112
|
-
default: true,
|
|
113
|
-
},
|
|
114
|
-
// 只读模式
|
|
115
|
-
readonly: {
|
|
116
|
-
type: Boolean,
|
|
117
|
-
default: true,
|
|
118
|
-
},
|
|
119
|
-
// 禁止复制
|
|
120
|
-
noCopy: Boolean,
|
|
121
|
-
// 值类名
|
|
122
|
-
valueClass: String,
|
|
123
|
-
// 值样式
|
|
124
|
-
valueStyle: [String, Object, Array],
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* 组合式
|
|
129
|
-
*/
|
|
130
|
-
setup(props, { slots }) {
|
|
131
|
-
|
|
132
|
-
// ==========【计算属性】==========================================================================================
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* 插槽标识数组
|
|
136
|
-
*/
|
|
137
|
-
const slotNames = computed(function() {
|
|
138
|
-
return $n_isValidObject(slots) ? Object.keys($n_omit(slots, [ 'default' ])) : []
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
// ==========【方法】=============================================================================================
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 复制
|
|
145
|
-
*/
|
|
146
|
-
function onCopy() {
|
|
147
|
-
const val = props.copyText || props.value
|
|
148
|
-
if (val) {
|
|
149
|
-
$n_copy(val, `复制【${props.label}】成功`)
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// ==========【返回】=============================================================================================
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
// 字段组件传参
|
|
157
|
-
// fieldProps,
|
|
158
|
-
// 插槽标识数组
|
|
159
|
-
slotNames,
|
|
160
|
-
// 复制
|
|
161
|
-
onCopy,
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
}
|
|
165
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<q-field
|
|
3
|
+
class="n-field-fieldset"
|
|
4
|
+
:label="label"
|
|
5
|
+
:stack-label="stackLabel"
|
|
6
|
+
:outlined="outlined"
|
|
7
|
+
:dense="dense"
|
|
8
|
+
:readonly="readonly"
|
|
9
|
+
v-bind="$attrs"
|
|
10
|
+
>
|
|
11
|
+
<template v-slot:control>
|
|
12
|
+
|
|
13
|
+
<!-- 如果有默认插槽 -->
|
|
14
|
+
<template v-if="$slots.default">
|
|
15
|
+
|
|
16
|
+
<!-- 如果开启复制 -->
|
|
17
|
+
<div
|
|
18
|
+
class="full-width"
|
|
19
|
+
:class="valueClass"
|
|
20
|
+
:style="valueStyle"
|
|
21
|
+
@click="onCopy"
|
|
22
|
+
v-if="! noCopy"
|
|
23
|
+
>
|
|
24
|
+
<slot
|
|
25
|
+
:value="value"
|
|
26
|
+
/>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<!-- 否则仅展示 -->
|
|
30
|
+
<div
|
|
31
|
+
class="full-width"
|
|
32
|
+
:class="valueClass"
|
|
33
|
+
:style="valueStyle"
|
|
34
|
+
v-else
|
|
35
|
+
>
|
|
36
|
+
<slot
|
|
37
|
+
:value="value"
|
|
38
|
+
/>
|
|
39
|
+
</div>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<!-- 否则如果开启复制 -->
|
|
43
|
+
<div
|
|
44
|
+
class="full-width"
|
|
45
|
+
:class="valueClass"
|
|
46
|
+
:style="valueStyle"
|
|
47
|
+
@click="onCopy"
|
|
48
|
+
v-else-if="! noCopy"
|
|
49
|
+
>{{value}}</div>
|
|
50
|
+
|
|
51
|
+
<!-- 否则仅展示 -->
|
|
52
|
+
<div
|
|
53
|
+
class="full-width"
|
|
54
|
+
:class="valueClass"
|
|
55
|
+
:style="valueStyle"
|
|
56
|
+
v-else
|
|
57
|
+
>{{value}}</div>
|
|
58
|
+
|
|
59
|
+
</template>
|
|
60
|
+
|
|
61
|
+
<template
|
|
62
|
+
v-for="slotName in slotNames"
|
|
63
|
+
v-slot:[slotName]
|
|
64
|
+
>
|
|
65
|
+
<slot
|
|
66
|
+
:name="slotName"
|
|
67
|
+
:value="value"
|
|
68
|
+
/>
|
|
69
|
+
</template>
|
|
70
|
+
</q-field>
|
|
71
|
+
</template>
|
|
72
|
+
|
|
73
|
+
<script>
|
|
74
|
+
import { computed } from 'vue'
|
|
75
|
+
|
|
76
|
+
import $n_omit from 'lodash/omit'
|
|
77
|
+
|
|
78
|
+
import $n_isValidObject from '@netang/utils/isValidObject'
|
|
79
|
+
|
|
80
|
+
import $n_copy from '../../utils/copy'
|
|
81
|
+
|
|
82
|
+
export default {
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 标识
|
|
86
|
+
*/
|
|
87
|
+
name: 'NFieldText',
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 声明属性
|
|
91
|
+
*/
|
|
92
|
+
props: {
|
|
93
|
+
// 标签
|
|
94
|
+
label: [Array, String, Number],
|
|
95
|
+
// 值
|
|
96
|
+
value: [String, Number],
|
|
97
|
+
// 复制文字
|
|
98
|
+
copyText: [String, Number],
|
|
99
|
+
// 标签始终显示在字段上方
|
|
100
|
+
stackLabel: {
|
|
101
|
+
type: Boolean,
|
|
102
|
+
default: true,
|
|
103
|
+
},
|
|
104
|
+
// 线条
|
|
105
|
+
outlined: {
|
|
106
|
+
type: Boolean,
|
|
107
|
+
default: true,
|
|
108
|
+
},
|
|
109
|
+
// 紧凑模式
|
|
110
|
+
dense: {
|
|
111
|
+
type: Boolean,
|
|
112
|
+
default: true,
|
|
113
|
+
},
|
|
114
|
+
// 只读模式
|
|
115
|
+
readonly: {
|
|
116
|
+
type: Boolean,
|
|
117
|
+
default: true,
|
|
118
|
+
},
|
|
119
|
+
// 禁止复制
|
|
120
|
+
noCopy: Boolean,
|
|
121
|
+
// 值类名
|
|
122
|
+
valueClass: String,
|
|
123
|
+
// 值样式
|
|
124
|
+
valueStyle: [String, Object, Array],
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 组合式
|
|
129
|
+
*/
|
|
130
|
+
setup(props, { slots }) {
|
|
131
|
+
|
|
132
|
+
// ==========【计算属性】==========================================================================================
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 插槽标识数组
|
|
136
|
+
*/
|
|
137
|
+
const slotNames = computed(function() {
|
|
138
|
+
return $n_isValidObject(slots) ? Object.keys($n_omit(slots, [ 'default' ])) : []
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
// ==========【方法】=============================================================================================
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 复制
|
|
145
|
+
*/
|
|
146
|
+
function onCopy() {
|
|
147
|
+
const val = props.copyText || props.value
|
|
148
|
+
if (val) {
|
|
149
|
+
$n_copy(val, `复制【${props.label}】成功`)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ==========【返回】=============================================================================================
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
// 字段组件传参
|
|
157
|
+
// fieldProps,
|
|
158
|
+
// 插槽标识数组
|
|
159
|
+
slotNames,
|
|
160
|
+
// 复制
|
|
161
|
+
onCopy,
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
</script>
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
:disable="disable"
|
|
8
8
|
:readonly="readonly"
|
|
9
9
|
v-model="currentValue"
|
|
10
|
+
@update:model-value="onUpdate"
|
|
10
11
|
@blur="onBlur"
|
|
11
12
|
v-bind="$attrs"
|
|
12
13
|
>
|
|
@@ -313,19 +314,7 @@ export default {
|
|
|
313
314
|
/**
|
|
314
315
|
* 监听 当前最小值 / 当前最大值 / 当前小数位数
|
|
315
316
|
*/
|
|
316
|
-
watch([currentMin, currentMax, currentDecimalLength],
|
|
317
|
-
|
|
318
|
-
// 格式化当前值
|
|
319
|
-
const val = formatToCurrentValue(currentValue.value, false)
|
|
320
|
-
|
|
321
|
-
// 如果当前值有变化
|
|
322
|
-
if (val !== currentValue.value) {
|
|
323
|
-
// 更新当前值
|
|
324
|
-
currentValue.value = val
|
|
325
|
-
// 更新值
|
|
326
|
-
emitModelValue(formatToModelValue(val))
|
|
327
|
-
}
|
|
328
|
-
})
|
|
317
|
+
watch([currentMin, currentMax, currentDecimalLength], onUpdate)
|
|
329
318
|
|
|
330
319
|
// ==========【方法】=============================================================================================
|
|
331
320
|
|
|
@@ -446,6 +435,23 @@ export default {
|
|
|
446
435
|
return ''
|
|
447
436
|
}
|
|
448
437
|
|
|
438
|
+
/**
|
|
439
|
+
* 更新值触发
|
|
440
|
+
*/
|
|
441
|
+
function onUpdate() {
|
|
442
|
+
|
|
443
|
+
// 格式化当前值
|
|
444
|
+
const newVal = formatToCurrentValue(currentValue.value, false)
|
|
445
|
+
|
|
446
|
+
// 如果当前值有变化
|
|
447
|
+
if (newVal !== currentValue.value) {
|
|
448
|
+
// 更新当前值
|
|
449
|
+
currentValue.value = newVal
|
|
450
|
+
// 更新值
|
|
451
|
+
emitModelValue(formatToModelValue(newVal))
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
449
455
|
/**
|
|
450
456
|
* 失去焦点触发
|
|
451
457
|
*/
|
|
@@ -504,6 +510,8 @@ export default {
|
|
|
504
510
|
// 当前是否禁用增加按钮
|
|
505
511
|
currentDisablePlus,
|
|
506
512
|
|
|
513
|
+
// 更新值触发
|
|
514
|
+
onUpdate,
|
|
507
515
|
// 失去焦点触发
|
|
508
516
|
onBlur,
|
|
509
517
|
// 改变值
|
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<q-list
|
|
3
|
-
:dark="dark"
|
|
4
|
-
>
|
|
5
|
-
<n-list-menu-item
|
|
6
|
-
:data="data"
|
|
7
|
-
@item-click="onItemClick"
|
|
8
|
-
/>
|
|
9
|
-
</q-list>
|
|
10
|
-
</template>
|
|
11
|
-
|
|
12
|
-
<script>
|
|
13
|
-
import { watch } from 'vue'
|
|
14
|
-
|
|
15
|
-
import $n_has from 'lodash/has'
|
|
16
|
-
import $n_isValidArray from '@netang/utils/isValidArray'
|
|
17
|
-
|
|
18
|
-
import NListMenuItem from '../list-menu-item'
|
|
19
|
-
|
|
20
|
-
export default {
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 标识
|
|
24
|
-
*/
|
|
25
|
-
name: 'NListMenu',
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 组件
|
|
29
|
-
*/
|
|
30
|
-
components: {
|
|
31
|
-
NListMenuItem,
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 声明属性
|
|
36
|
-
*/
|
|
37
|
-
props: {
|
|
38
|
-
// 数据
|
|
39
|
-
data: Array,
|
|
40
|
-
// 是否暗色
|
|
41
|
-
dark: Boolean,
|
|
42
|
-
// 激活 key
|
|
43
|
-
activeKey: {
|
|
44
|
-
type: String,
|
|
45
|
-
default: 'id',
|
|
46
|
-
},
|
|
47
|
-
// 激活值
|
|
48
|
-
activeValue: [String, Number],
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 声明事件
|
|
53
|
-
*/
|
|
54
|
-
emits: [
|
|
55
|
-
// 单个元素点击
|
|
56
|
-
'itemClick',
|
|
57
|
-
],
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* 组合式
|
|
61
|
-
*/
|
|
62
|
-
setup(props, { emit }) {
|
|
63
|
-
|
|
64
|
-
// ==========【方法】============================================================================================
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 单个元素点击
|
|
68
|
-
*/
|
|
69
|
-
function onItemClick(item) {
|
|
70
|
-
emit('itemClick', item)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 设置激活状态
|
|
75
|
-
*/
|
|
76
|
-
function setActive() {
|
|
77
|
-
|
|
78
|
-
const parentAll = {}
|
|
79
|
-
|
|
80
|
-
// 获取父节点
|
|
81
|
-
function getParent({ attr }) {
|
|
82
|
-
if (
|
|
83
|
-
// 如果不是根节点
|
|
84
|
-
attr.pid
|
|
85
|
-
// 有父节点
|
|
86
|
-
&& $n_has(parentAll, attr.pid)
|
|
87
|
-
) {
|
|
88
|
-
const parentItem = parentAll[attr.pid]
|
|
89
|
-
|
|
90
|
-
// 设为展开
|
|
91
|
-
parentItem.expanded = true
|
|
92
|
-
|
|
93
|
-
getParent(parentItem)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// 获取子节点
|
|
98
|
-
function getChildren(data) {
|
|
99
|
-
|
|
100
|
-
for (const item of data) {
|
|
101
|
-
|
|
102
|
-
// 设为折叠
|
|
103
|
-
item.expanded = false
|
|
104
|
-
|
|
105
|
-
// 如果是父节点
|
|
106
|
-
if (item.children.length) {
|
|
107
|
-
parentAll[item.id] = item
|
|
108
|
-
getChildren(item.children)
|
|
109
|
-
|
|
110
|
-
// 否则如果是匹配的子节点
|
|
111
|
-
} else if (props.activeValue && item.attr[props.activeKey] === props.activeValue) {
|
|
112
|
-
|
|
113
|
-
// 设为展开
|
|
114
|
-
item.expanded = true
|
|
115
|
-
|
|
116
|
-
getParent(item)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
getChildren(props.data)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// ==========【监听数据】=========================================================================================
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* 监听声明值
|
|
128
|
-
*/
|
|
129
|
-
watch([()=>props.data, ()=>props.activeValue], function() {
|
|
130
|
-
|
|
131
|
-
// 设置激活状态
|
|
132
|
-
if ($n_isValidArray(props.data)) {
|
|
133
|
-
setActive()
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
}, {
|
|
137
|
-
// 立即执行
|
|
138
|
-
immediate: true,
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
// ==========【返回】=========================================================================================
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
// 单个元素点击
|
|
145
|
-
onItemClick,
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<q-list
|
|
3
|
+
:dark="dark"
|
|
4
|
+
>
|
|
5
|
+
<n-list-menu-item
|
|
6
|
+
:data="data"
|
|
7
|
+
@item-click="onItemClick"
|
|
8
|
+
/>
|
|
9
|
+
</q-list>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script>
|
|
13
|
+
import { watch } from 'vue'
|
|
14
|
+
|
|
15
|
+
import $n_has from 'lodash/has'
|
|
16
|
+
import $n_isValidArray from '@netang/utils/isValidArray'
|
|
17
|
+
|
|
18
|
+
import NListMenuItem from '../list-menu-item'
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 标识
|
|
24
|
+
*/
|
|
25
|
+
name: 'NListMenu',
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 组件
|
|
29
|
+
*/
|
|
30
|
+
components: {
|
|
31
|
+
NListMenuItem,
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 声明属性
|
|
36
|
+
*/
|
|
37
|
+
props: {
|
|
38
|
+
// 数据
|
|
39
|
+
data: Array,
|
|
40
|
+
// 是否暗色
|
|
41
|
+
dark: Boolean,
|
|
42
|
+
// 激活 key
|
|
43
|
+
activeKey: {
|
|
44
|
+
type: String,
|
|
45
|
+
default: 'id',
|
|
46
|
+
},
|
|
47
|
+
// 激活值
|
|
48
|
+
activeValue: [String, Number],
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 声明事件
|
|
53
|
+
*/
|
|
54
|
+
emits: [
|
|
55
|
+
// 单个元素点击
|
|
56
|
+
'itemClick',
|
|
57
|
+
],
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 组合式
|
|
61
|
+
*/
|
|
62
|
+
setup(props, { emit }) {
|
|
63
|
+
|
|
64
|
+
// ==========【方法】============================================================================================
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 单个元素点击
|
|
68
|
+
*/
|
|
69
|
+
function onItemClick(item) {
|
|
70
|
+
emit('itemClick', item)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 设置激活状态
|
|
75
|
+
*/
|
|
76
|
+
function setActive() {
|
|
77
|
+
|
|
78
|
+
const parentAll = {}
|
|
79
|
+
|
|
80
|
+
// 获取父节点
|
|
81
|
+
function getParent({ attr }) {
|
|
82
|
+
if (
|
|
83
|
+
// 如果不是根节点
|
|
84
|
+
attr.pid
|
|
85
|
+
// 有父节点
|
|
86
|
+
&& $n_has(parentAll, attr.pid)
|
|
87
|
+
) {
|
|
88
|
+
const parentItem = parentAll[attr.pid]
|
|
89
|
+
|
|
90
|
+
// 设为展开
|
|
91
|
+
parentItem.expanded = true
|
|
92
|
+
|
|
93
|
+
getParent(parentItem)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 获取子节点
|
|
98
|
+
function getChildren(data) {
|
|
99
|
+
|
|
100
|
+
for (const item of data) {
|
|
101
|
+
|
|
102
|
+
// 设为折叠
|
|
103
|
+
item.expanded = false
|
|
104
|
+
|
|
105
|
+
// 如果是父节点
|
|
106
|
+
if (item.children.length) {
|
|
107
|
+
parentAll[item.id] = item
|
|
108
|
+
getChildren(item.children)
|
|
109
|
+
|
|
110
|
+
// 否则如果是匹配的子节点
|
|
111
|
+
} else if (props.activeValue && item.attr[props.activeKey] === props.activeValue) {
|
|
112
|
+
|
|
113
|
+
// 设为展开
|
|
114
|
+
item.expanded = true
|
|
115
|
+
|
|
116
|
+
getParent(item)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
getChildren(props.data)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ==========【监听数据】=========================================================================================
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 监听声明值
|
|
128
|
+
*/
|
|
129
|
+
watch([()=>props.data, ()=>props.activeValue], function() {
|
|
130
|
+
|
|
131
|
+
// 设置激活状态
|
|
132
|
+
if ($n_isValidArray(props.data)) {
|
|
133
|
+
setActive()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
}, {
|
|
137
|
+
// 立即执行
|
|
138
|
+
immediate: true,
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
// ==========【返回】=========================================================================================
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
// 单个元素点击
|
|
145
|
+
onItemClick,
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
</script>
|