stellar-ui-v2 1.40.26 → 1.40.27
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/ste-index-item/ste-index-item.vue +10 -5
- package/components/ste-scroll-to/mixin.js +3 -2
- package/components/ste-scroll-to/ste-scroll-to.vue +0 -4
- package/components/ste-scroll-to-item/ste-scroll-to-item.vue +7 -2
- package/components/ste-swipe-action/ste-swipe-action.vue +2 -2
- package/components/ste-swiper-item/ste-swiper-item.vue +49 -55
- package/components/ste-tab/ste-tab.vue +39 -8
- package/components/ste-table/ste-table.vue +4 -24
- package/components/ste-table-column/ste-table-column.vue +6 -13
- package/components/ste-tabs/ste-tabs.vue +25 -13
- package/package.json +1 -1
- package/utils/mixin.js +27 -19
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view class="ste-
|
|
2
|
+
<view class="ste-index-item-root" data-test="index-item">
|
|
3
3
|
<slot name="title">
|
|
4
4
|
<block v-if="title">
|
|
5
5
|
<ste-sticky v-if="sticky">
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
</slot>
|
|
11
11
|
<slot>
|
|
12
12
|
<view class="index-item-text-list">
|
|
13
|
-
<view class="index-item-text" data-test="index-item-text" v-for="(text, i) in list" :key="i"
|
|
13
|
+
<view class="index-item-text" data-test="index-item-text" v-for="(text, i) in list" :key="i"
|
|
14
|
+
@click="onClickItem(text)">
|
|
14
15
|
{{ text }}
|
|
15
16
|
</view>
|
|
16
17
|
</view>
|
|
@@ -30,7 +31,7 @@ import { childMixin } from '../../utils/mixin.js';
|
|
|
30
31
|
*/
|
|
31
32
|
export default {
|
|
32
33
|
name: 'ste-index-item',
|
|
33
|
-
mixins: [childMixin('ste-index-list')],
|
|
34
|
+
mixins: [childMixin('ste-index-list', ['setActive', 'getView'])],
|
|
34
35
|
props: {
|
|
35
36
|
title: {
|
|
36
37
|
type: [String, null],
|
|
@@ -59,12 +60,15 @@ export default {
|
|
|
59
60
|
onClickItem(item) {
|
|
60
61
|
this.parent.onClickItem(this.title, item);
|
|
61
62
|
},
|
|
63
|
+
async getView() {
|
|
64
|
+
return await utils.querySelector('.ste-index-item-root', this)
|
|
65
|
+
}
|
|
62
66
|
},
|
|
63
67
|
};
|
|
64
68
|
</script>
|
|
65
69
|
|
|
66
70
|
<style lang="scss" scoped>
|
|
67
|
-
.ste-
|
|
71
|
+
.ste-index-item-root {
|
|
68
72
|
width: 100%;
|
|
69
73
|
|
|
70
74
|
.index-item-title {
|
|
@@ -96,4 +100,5 @@ export default {
|
|
|
96
100
|
border-bottom: 2rpx solid #f9f9f9;
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
|
-
}
|
|
103
|
+
}
|
|
104
|
+
</style>
|
|
@@ -55,6 +55,7 @@ export default {
|
|
|
55
55
|
},
|
|
56
56
|
childrenTops() {
|
|
57
57
|
if (!this.children.length) return;
|
|
58
|
+
if (this.scrollType === 'active') return;
|
|
58
59
|
this.scrollType = 'init';
|
|
59
60
|
this.setScrollTopByIndex(this.dataActive);
|
|
60
61
|
},
|
|
@@ -89,8 +90,8 @@ export default {
|
|
|
89
90
|
const childrenTops = [];
|
|
90
91
|
for (let i = 0; i < this.children.length; i++) {
|
|
91
92
|
const comp = this.children[i];
|
|
92
|
-
const
|
|
93
|
-
const top =
|
|
93
|
+
const childView = await comp.getView();
|
|
94
|
+
const top = childView.top - box.top;
|
|
94
95
|
childrenTops.push(top > max + 10 ? max + 10 : top);
|
|
95
96
|
}
|
|
96
97
|
let diff = this.childrenTops.length !== childrenTops.length;
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script>
|
|
8
|
-
import utils from '../../utils/utils.js';
|
|
9
8
|
import { childMixin } from '../../utils/mixin.js';
|
|
9
|
+
import utils from '../../utils/utils.js';
|
|
10
10
|
/**
|
|
11
11
|
* ste-scroll-to-item 锚点项
|
|
12
12
|
* @description 锚点项
|
|
@@ -14,7 +14,12 @@ import { childMixin } from '../../utils/mixin.js';
|
|
|
14
14
|
*/
|
|
15
15
|
export default {
|
|
16
16
|
name: 'ste-scroll-to-item',
|
|
17
|
-
mixins: [childMixin('ste-scroll-to')],
|
|
17
|
+
mixins: [childMixin('ste-scroll-to', ['getView'])],
|
|
18
|
+
methods: {
|
|
19
|
+
async getView() {
|
|
20
|
+
return await utils.querySelector('.ste-scroll-to-item-root', this)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
18
23
|
};
|
|
19
24
|
</script>
|
|
20
25
|
|
|
@@ -59,7 +59,7 @@ export default {
|
|
|
59
59
|
group: '展示组件',
|
|
60
60
|
title: 'SwipeAction 滑动单元格',
|
|
61
61
|
name: 'ste-swipe-action',
|
|
62
|
-
mixins: [childMixin('ste-swipe-action-group')],
|
|
62
|
+
mixins: [childMixin('ste-swipe-action-group', ['open', 'close', 'onchange'])],
|
|
63
63
|
props: {
|
|
64
64
|
mode: {
|
|
65
65
|
type: [String, null],
|
|
@@ -129,7 +129,7 @@ export default {
|
|
|
129
129
|
};
|
|
130
130
|
},
|
|
131
131
|
},
|
|
132
|
-
mounted() {
|
|
132
|
+
mounted() {},
|
|
133
133
|
methods: {
|
|
134
134
|
/**
|
|
135
135
|
* 打开侧滑
|
|
@@ -5,66 +5,60 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
/**
|
|
9
|
+
* ste-swiper 轮播
|
|
10
|
+
* @description 轮播组件
|
|
11
|
+
* @tutorial https://stellar-ui.intecloud.com.cn/?projectName=stellar-ui&menu=%E7%BB%84%E4%BB%B6&active=ste-swiper
|
|
12
|
+
* */
|
|
13
|
+
import { childMixin } from '../../utils/mixin.js';
|
|
14
|
+
export default {
|
|
15
|
+
name: 'ste-swiper-item',
|
|
16
|
+
mixins: [childMixin('ste-swiper', ['setTransform', 'setLinearScale'])],
|
|
17
|
+
data() {
|
|
18
|
+
return {
|
|
19
|
+
transformX: 0,
|
|
20
|
+
transformY: 0,
|
|
21
|
+
transformZ: 0,
|
|
22
|
+
linearScale: 1,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
computed: {
|
|
26
|
+
cmpStyle() {
|
|
20
27
|
return {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
transformZ: 0,
|
|
24
|
-
linearScale: 1,
|
|
28
|
+
transform: `translate3d(${this.transformX}px,${this.transformY}px,${this.transformZ}px) scale(${this.linearScale})`,
|
|
29
|
+
transformOrigin: 'center center',
|
|
25
30
|
};
|
|
26
31
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
32
|
+
},
|
|
33
|
+
methods: {
|
|
34
|
+
setTransform({ x = 0, y = 0, z = 0 }) {
|
|
35
|
+
if (this.transformX !== x) this.transformX = x;
|
|
36
|
+
if (this.transformY !== y) this.transformY = y;
|
|
37
|
+
if (this.transformZ !== z) this.transformZ = z;
|
|
34
38
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
x = 0,
|
|
38
|
-
y = 0,
|
|
39
|
-
z = 0
|
|
40
|
-
}) {
|
|
41
|
-
if (this.transformX !== x) this.transformX = x;
|
|
42
|
-
if (this.transformY !== y) this.transformY = y;
|
|
43
|
-
if (this.transformZ !== z) this.transformZ = z;
|
|
44
|
-
},
|
|
45
|
-
setLinearScale(scale) {
|
|
46
|
-
this.linearScale = scale;
|
|
47
|
-
},
|
|
39
|
+
setLinearScale(scale) {
|
|
40
|
+
this.linearScale = scale;
|
|
48
41
|
},
|
|
49
|
-
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
50
44
|
</script>
|
|
51
45
|
|
|
52
46
|
<style>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
</style>
|
|
47
|
+
.ste-swiper-item-root {
|
|
48
|
+
width: 100%;
|
|
49
|
+
height: 100%;
|
|
50
|
+
/* 添加此行以确保在循环播放时不会出现闪烁 */
|
|
51
|
+
will-change: transform;
|
|
52
|
+
/* 隐藏背面,避免翻转时闪烁 */
|
|
53
|
+
backface-visibility: hidden;
|
|
54
|
+
/* CSS containment 优化 */
|
|
55
|
+
contain: layout style paint;
|
|
56
|
+
/* 抗锯齿 */
|
|
57
|
+
-webkit-font-smoothing: antialiased;
|
|
58
|
+
-moz-osx-font-smoothing: grayscale;
|
|
59
|
+
/* 优化图像渲染 */
|
|
60
|
+
image-rendering: -webkit-optimize-contrast;
|
|
61
|
+
/* 确保子元素也使用硬件加速 */
|
|
62
|
+
transform-style: flat;
|
|
63
|
+
}
|
|
64
|
+
</style>
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script>
|
|
8
|
-
import utils from '../../utils/utils.js';
|
|
9
8
|
import { childMixin } from '../../utils/mixin.js';
|
|
10
9
|
/**
|
|
11
10
|
* ste-tab 标签页选项
|
|
@@ -67,14 +66,46 @@ export default {
|
|
|
67
66
|
default: () => false,
|
|
68
67
|
},
|
|
69
68
|
},
|
|
69
|
+
data() {
|
|
70
|
+
return {};
|
|
71
|
+
},
|
|
70
72
|
watch: {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
title() {
|
|
74
|
+
this.updateParent();
|
|
75
|
+
},
|
|
76
|
+
subTitle() {
|
|
77
|
+
this.updateParent();
|
|
78
|
+
},
|
|
79
|
+
image() {
|
|
80
|
+
this.updateParent();
|
|
81
|
+
},
|
|
82
|
+
name() {
|
|
83
|
+
this.updateParent();
|
|
84
|
+
},
|
|
85
|
+
index() {
|
|
86
|
+
this.updateParent();
|
|
87
|
+
},
|
|
88
|
+
disabled() {
|
|
89
|
+
this.updateParent();
|
|
90
|
+
},
|
|
91
|
+
showDot() {
|
|
92
|
+
this.updateParent();
|
|
93
|
+
},
|
|
94
|
+
badge() {
|
|
95
|
+
this.updateParent();
|
|
96
|
+
},
|
|
97
|
+
showZeroBadge() {
|
|
98
|
+
this.updateParent();
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
onMounted() {
|
|
102
|
+
this.updateParent();
|
|
103
|
+
},
|
|
104
|
+
methods: {
|
|
105
|
+
updateParent() {
|
|
106
|
+
if (this.parent && typeof this.parent.getChildrenProps === 'function') {
|
|
107
|
+
this.parent.getChildrenProps();
|
|
108
|
+
}
|
|
78
109
|
},
|
|
79
110
|
},
|
|
80
111
|
};
|
|
@@ -15,13 +15,7 @@
|
|
|
15
15
|
<ste-icon code="" :color="selectionIconColor.disabled || selectionColor.disabled" :size="checkIconSize" v-if="canCheckStates.length === 0" />
|
|
16
16
|
<template v-else>
|
|
17
17
|
<ste-icon code="" :color="selectionIconColor.main || selectionColor.main" :size="checkIconSize" v-if="checkAllState == 'all'" @click="changeCheckAll" />
|
|
18
|
-
<ste-icon
|
|
19
|
-
code=""
|
|
20
|
-
:color="selectionIconColor.main || selectionColor.main"
|
|
21
|
-
:size="checkIconSize"
|
|
22
|
-
v-else-if="checkAllState == 'indeterminate'"
|
|
23
|
-
@click="changeCheckAll"
|
|
24
|
-
/>
|
|
18
|
+
<ste-icon code="" :color="selectionIconColor.main || selectionColor.main" :size="checkIconSize" v-else-if="checkAllState == 'indeterminate'" @click="changeCheckAll" />
|
|
25
19
|
<ste-icon code="" :color="selectionIconColor.unSelected || selectionColor.unSelected" :size="checkIconSize" v-else @click="changeCheckAll" />
|
|
26
20
|
</template>
|
|
27
21
|
</view>
|
|
@@ -33,14 +27,7 @@
|
|
|
33
27
|
<template v-if="height || height > 0">
|
|
34
28
|
<scroll-view scroll-y class="ste-table-scroll" @scrolltolower="handleScrollToLower">
|
|
35
29
|
<view class="ste-table-body">
|
|
36
|
-
<view
|
|
37
|
-
class="ste-table-row"
|
|
38
|
-
:class="[getRowClass(row, rowIndex)]"
|
|
39
|
-
:style="[getRowStyle(row, rowIndex)]"
|
|
40
|
-
v-for="(row, rowIndex) in tableData"
|
|
41
|
-
:key="rowIndex"
|
|
42
|
-
@click="rowClick(row, $event)"
|
|
43
|
-
>
|
|
30
|
+
<view class="ste-table-row" :class="[getRowClass(row, rowIndex)]" :style="[getRowStyle(row, rowIndex)]" v-for="(row, rowIndex) in tableData" :key="rowIndex" @click="rowClick(row, $event)">
|
|
44
31
|
<slot :row="row"></slot>
|
|
45
32
|
</view>
|
|
46
33
|
<view class="ste-table-row sum" v-if="showSummary">
|
|
@@ -58,14 +45,7 @@
|
|
|
58
45
|
</template>
|
|
59
46
|
<template v-else>
|
|
60
47
|
<view class="ste-table-body">
|
|
61
|
-
<view
|
|
62
|
-
class="ste-table-row"
|
|
63
|
-
:class="[getRowClass(row, rowIndex)]"
|
|
64
|
-
:style="[getRowStyle(row, rowIndex)]"
|
|
65
|
-
v-for="(row, rowIndex) in tableData"
|
|
66
|
-
:key="rowIndex"
|
|
67
|
-
@click="rowClick(row, $event)"
|
|
68
|
-
>
|
|
48
|
+
<view class="ste-table-row" :class="[getRowClass(row, rowIndex)]" :style="[getRowStyle(row, rowIndex)]" v-for="(row, rowIndex) in tableData" :key="rowIndex" @click="rowClick(row, $event)">
|
|
69
49
|
<slot :row="row"></slot>
|
|
70
50
|
</view>
|
|
71
51
|
<view class="ste-table-row sum" v-if="showSummary">
|
|
@@ -295,7 +275,7 @@ export default {
|
|
|
295
275
|
const rowIndex = Math.floor(index / colNums); // 计算出当前元素属于哪一行
|
|
296
276
|
const colIndex = index % colNums; // 计算出当前元素属于哪一列
|
|
297
277
|
const row = this.tableData[rowIndex];
|
|
298
|
-
child.
|
|
278
|
+
child.setRow({ ...row, rowIndex, colIndex });
|
|
299
279
|
});
|
|
300
280
|
},
|
|
301
281
|
initColumns(childs) {
|
|
@@ -2,20 +2,10 @@
|
|
|
2
2
|
<view class="ste-table-cell" :class="[cmpRootClass]" :style="[cmpRootStyle, cmpCellStyle]" @click="cellClick">
|
|
3
3
|
<template v-if="type">
|
|
4
4
|
<view class="cell-box" v-if="type == 'checkbox'" @click.stop="changeCheck">
|
|
5
|
-
<check-box-icon
|
|
6
|
-
:disabled="cmpDisableCheck"
|
|
7
|
-
:readonly="cmpReadonlyCheck"
|
|
8
|
-
:checked="cmpShowCheck"
|
|
9
|
-
:iconColorConfig="cmpSelectionIconColor"
|
|
10
|
-
/>
|
|
5
|
+
<check-box-icon :disabled="cmpDisableCheck" :readonly="cmpReadonlyCheck" :checked="cmpShowCheck" :iconColorConfig="cmpSelectionIconColor" />
|
|
11
6
|
</view>
|
|
12
7
|
<view class="cell-box" v-if="type == 'radio'" @click.stop="changeCheck">
|
|
13
|
-
<radio-icon
|
|
14
|
-
:disabled="cmpDisableCheck"
|
|
15
|
-
:readonly="cmpReadonlyCheck"
|
|
16
|
-
:checked="cmpShowCheck"
|
|
17
|
-
:iconColorConfig="cmpSelectionIconColor"
|
|
18
|
-
/>
|
|
8
|
+
<radio-icon :disabled="cmpDisableCheck" :readonly="cmpReadonlyCheck" :checked="cmpShowCheck" :iconColorConfig="cmpSelectionIconColor" />
|
|
19
9
|
</view>
|
|
20
10
|
<view class="cell-box" v-if="type == 'index'">
|
|
21
11
|
{{ row.rowIndex + 1 }}
|
|
@@ -60,7 +50,7 @@ import { childMixin } from '../../utils/mixin.js';
|
|
|
60
50
|
*/
|
|
61
51
|
export default {
|
|
62
52
|
name: 'ste-table-column',
|
|
63
|
-
mixins: [childMixin('ste-table')],
|
|
53
|
+
mixins: [childMixin('ste-table', ['setRow'])],
|
|
64
54
|
components: { RadioIcon, CheckBoxIcon, SubTable, TablePopover },
|
|
65
55
|
options: {
|
|
66
56
|
virtualHost: true,
|
|
@@ -236,6 +226,9 @@ export default {
|
|
|
236
226
|
this.changeCheck();
|
|
237
227
|
}
|
|
238
228
|
},
|
|
229
|
+
setRow(row = {}) {
|
|
230
|
+
this.row = row;
|
|
231
|
+
},
|
|
239
232
|
},
|
|
240
233
|
};
|
|
241
234
|
</script>
|
|
@@ -170,6 +170,7 @@ export default {
|
|
|
170
170
|
pullTransform: false,
|
|
171
171
|
_updateChildrenTimeout: null,
|
|
172
172
|
_updateTabsTimeout: null,
|
|
173
|
+
_upadteChildrenTimeout: null,
|
|
173
174
|
};
|
|
174
175
|
},
|
|
175
176
|
computed: {
|
|
@@ -192,9 +193,11 @@ export default {
|
|
|
192
193
|
},
|
|
193
194
|
cmpDisabledIndexs() {
|
|
194
195
|
const list = [];
|
|
196
|
+
|
|
195
197
|
this.cmpTabList.forEach((m, i) => {
|
|
196
198
|
if (m.disabled) list.push(i);
|
|
197
199
|
});
|
|
200
|
+
|
|
198
201
|
return list;
|
|
199
202
|
},
|
|
200
203
|
cmpRootStyle() {
|
|
@@ -369,8 +372,7 @@ export default {
|
|
|
369
372
|
this.showComponent = false;
|
|
370
373
|
clearTimeout(this._updateChildrenTimeout);
|
|
371
374
|
this._updateChildrenTimeout = setTimeout(() => {
|
|
372
|
-
this.getChildrenProps()
|
|
373
|
-
this.$nextTick(async () => {
|
|
375
|
+
this.getChildrenProps().then(async () => {
|
|
374
376
|
this.listBoxEl = await utils.querySelector('.tab-list-box', this);
|
|
375
377
|
this.listEl = await utils.querySelector('.tab-list-box .tab-list.view-list', this);
|
|
376
378
|
this.tabEls = await utils.querySelector('.tab-list-box .tab-list.view-list .tab-item', this, true);
|
|
@@ -379,17 +381,27 @@ export default {
|
|
|
379
381
|
}, 100);
|
|
380
382
|
},
|
|
381
383
|
getChildrenProps() {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
384
|
+
return new Promise((resolve, reject) => {
|
|
385
|
+
clearTimeout(this._upadteChildrenTimeout);
|
|
386
|
+
this._upadteChildrenTimeout = setTimeout(() => {
|
|
387
|
+
try {
|
|
388
|
+
this.tabPropsList = this.children.map((m) => ({
|
|
389
|
+
title: m.title,
|
|
390
|
+
subTitle: m.subTitle,
|
|
391
|
+
image: m.image,
|
|
392
|
+
name: m.name,
|
|
393
|
+
index: m.index,
|
|
394
|
+
disabled: m.disabled,
|
|
395
|
+
showDot: m.showDot,
|
|
396
|
+
badge: m.badge,
|
|
397
|
+
showZeroBadge: m.showZeroBadge,
|
|
398
|
+
}));
|
|
399
|
+
resolve();
|
|
400
|
+
} catch (e) {
|
|
401
|
+
reject(e);
|
|
402
|
+
}
|
|
403
|
+
}, 100);
|
|
404
|
+
});
|
|
393
405
|
},
|
|
394
406
|
onClickTab(tab, index) {
|
|
395
407
|
this.$emit('click-tab', { index, ...tab });
|
package/package.json
CHANGED
package/utils/mixin.js
CHANGED
|
@@ -7,7 +7,7 @@ export function parentMixin(name) {
|
|
|
7
7
|
provide() {
|
|
8
8
|
return {
|
|
9
9
|
[name]: {
|
|
10
|
-
getParent: () => this
|
|
10
|
+
getParent: () => this,
|
|
11
11
|
},
|
|
12
12
|
};
|
|
13
13
|
},
|
|
@@ -23,7 +23,7 @@ export function parentMixin(name) {
|
|
|
23
23
|
* 子组件混入对象
|
|
24
24
|
* @param {String} parentName 父组件名称
|
|
25
25
|
*/
|
|
26
|
-
export function childMixin(parentName) {
|
|
26
|
+
export function childMixin(parentName, methodNames = []) {
|
|
27
27
|
return {
|
|
28
28
|
options: {
|
|
29
29
|
virtualHost: true,
|
|
@@ -31,37 +31,45 @@ export function childMixin(parentName) {
|
|
|
31
31
|
inject: {
|
|
32
32
|
[parentName]: {
|
|
33
33
|
value: parentName,
|
|
34
|
-
default: null
|
|
35
|
-
}
|
|
34
|
+
default: null,
|
|
35
|
+
},
|
|
36
36
|
},
|
|
37
37
|
data() {
|
|
38
38
|
return {
|
|
39
|
-
parent: {
|
|
39
|
+
parent: {
|
|
40
|
+
children: [],
|
|
41
|
+
},
|
|
40
42
|
};
|
|
41
43
|
},
|
|
42
44
|
created() {
|
|
43
|
-
this
|
|
44
|
-
|
|
45
|
+
if (this[parentName] && this[parentName]?.getParent) {
|
|
46
|
+
this.parent = this[parentName].getParent();
|
|
47
|
+
this.setParentData();
|
|
48
|
+
}
|
|
45
49
|
},
|
|
46
50
|
beforeDestroy() {
|
|
47
51
|
// 判断当前页面是否存在parent和chldren,一般在checkbox和checkbox-group父子联动的场景会有此情况
|
|
48
52
|
// 组件销毁时,移除子组件在父组件children数组中的实例,释放资源,避免数据混乱
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.parent.children.
|
|
52
|
-
// 如果相等,则移除
|
|
53
|
-
if (child === this) {
|
|
54
|
-
this.parent.children.splice(index, 1);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
53
|
+
const ids = this.parent.children.map((item) => item._uid);
|
|
54
|
+
if (ids.indexOf(this._uid) !== -1) {
|
|
55
|
+
this.parent.children.splice(ids.indexOf(this._uid), 1);
|
|
57
56
|
}
|
|
58
57
|
},
|
|
59
58
|
methods: {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
setParentData() {
|
|
60
|
+
const child = Object.assign({ _uid: this._uid }, this.$props);
|
|
61
|
+
methodNames.forEach((name) => {
|
|
62
|
+
child[name] = (...a) => {
|
|
63
|
+
if (this[name]) {
|
|
64
|
+
return this[name](...a);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
const ids = this.parent.children.map((item) => item._uid);
|
|
69
|
+
if (ids.indexOf(child._uid) === -1) {
|
|
70
|
+
this.parent.children.push(child);
|
|
63
71
|
}
|
|
64
72
|
},
|
|
65
73
|
},
|
|
66
74
|
};
|
|
67
|
-
}
|
|
75
|
+
}
|