|
@@ -4,7 +4,7 @@
|
|
|
</view>
|
|
</view>
|
|
|
</template>
|
|
</template>
|
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
|
-import { provide, ref, watch } from 'vue';
|
|
|
|
|
|
|
+import { getCurrentInstance, onMounted, provide, ref, watch } from 'vue';
|
|
|
import { createComponent } from '@/packages/utils/create';
|
|
import { createComponent } from '@/packages/utils/create';
|
|
|
const { create } = createComponent('collapse');
|
|
const { create } = createComponent('collapse');
|
|
|
export default create({
|
|
export default create({
|
|
@@ -55,24 +55,20 @@ export default create({
|
|
|
emits: ['update:active', 'change'],
|
|
emits: ['update:active', 'change'],
|
|
|
setup(props, { emit, slots }) {
|
|
setup(props, { emit, slots }) {
|
|
|
const collapseDom: any = ref(null);
|
|
const collapseDom: any = ref(null);
|
|
|
|
|
+ const collapseChldren: any = ref([]);
|
|
|
watch(
|
|
watch(
|
|
|
() => props.active,
|
|
() => props.active,
|
|
|
(newval: any, oldval) => {
|
|
(newval: any, oldval) => {
|
|
|
- let domsProps: any = slots?.default?.();
|
|
|
|
|
- let doms: any = collapseDom.value?.children;
|
|
|
|
|
- Array.from(doms).forEach((dom: any, index: number) => {
|
|
|
|
|
- const item = dom['__vueParentComponent']['ctx'];
|
|
|
|
|
|
|
+ let doms: any = collapseChldren.value;
|
|
|
|
|
+ Array.from(doms).forEach((item: any) => {
|
|
|
if (typeof newval == 'number' || typeof newval == 'string') {
|
|
if (typeof newval == 'number' || typeof newval == 'string') {
|
|
|
- if (newval == domsProps[index].props.name) {
|
|
|
|
|
|
|
+ if (newval == item.name) {
|
|
|
item.changeOpen(!item.openExpanded);
|
|
item.changeOpen(!item.openExpanded);
|
|
|
} else {
|
|
} else {
|
|
|
item.changeOpen(false);
|
|
item.changeOpen(false);
|
|
|
}
|
|
}
|
|
|
} else if (Object.values(newval) instanceof Array) {
|
|
} else if (Object.values(newval) instanceof Array) {
|
|
|
- if (
|
|
|
|
|
- newval.indexOf(Number(domsProps[index].props.name)) > -1 ||
|
|
|
|
|
- newval.indexOf(String(domsProps[index].props.name)) > -1
|
|
|
|
|
- ) {
|
|
|
|
|
|
|
+ if (newval.indexOf(Number(item.name)) > -1 || newval.indexOf(String(item.name)) > -1) {
|
|
|
item.changeOpen(true);
|
|
item.changeOpen(true);
|
|
|
} else {
|
|
} else {
|
|
|
item.changeOpen(false);
|
|
item.changeOpen(false);
|
|
@@ -83,6 +79,10 @@ export default create({
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ onMounted(() => {
|
|
|
|
|
+ collapseChldren.value = (getCurrentInstance() as any).provides.collapseParent.children || [];
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
const changeVal = (val: string | number | Array<string | number>) => {
|
|
const changeVal = (val: string | number | Array<string | number>) => {
|
|
|
emit('update:active', val);
|
|
emit('update:active', val);
|
|
|
emit('change', val);
|
|
emit('change', val);
|