|
@@ -10,7 +10,7 @@ import { nextTick } from '@tarojs/taro';
|
|
|
const { create, componentName } = createComponent('collapse');
|
|
const { create, componentName } = createComponent('collapse');
|
|
|
export default create({
|
|
export default create({
|
|
|
props: {
|
|
props: {
|
|
|
- active: {
|
|
|
|
|
|
|
+ modelValue: {
|
|
|
type: [String, Number, Array]
|
|
type: [String, Number, Array]
|
|
|
},
|
|
},
|
|
|
accordion: {
|
|
accordion: {
|
|
@@ -18,7 +18,7 @@ export default create({
|
|
|
default: false
|
|
default: false
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- emits: ['update:active', 'change'],
|
|
|
|
|
|
|
+ emits: ['update:modelValue', 'change'],
|
|
|
setup(props, { emit, slots }) {
|
|
setup(props, { emit, slots }) {
|
|
|
const collapseDom: any = ref(null);
|
|
const collapseDom: any = ref(null);
|
|
|
const classes = computed(() => {
|
|
const classes = computed(() => {
|
|
@@ -29,12 +29,12 @@ export default create({
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const changeVal = (val: string | number | Array<string | number>) => {
|
|
const changeVal = (val: string | number | Array<string | number>) => {
|
|
|
- emit('update:active', val);
|
|
|
|
|
|
|
+ emit('update:modelValue', val);
|
|
|
emit('change', val);
|
|
emit('change', val);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const changeValAry = (name: string) => {
|
|
const changeValAry = (name: string) => {
|
|
|
- const activeItem: any = props.active instanceof Object ? Object.values(props.active) : props.active;
|
|
|
|
|
|
|
+ const activeItem: any = props.modelValue instanceof Object ? Object.values(props.modelValue) : props.modelValue;
|
|
|
let index = -1;
|
|
let index = -1;
|
|
|
|
|
|
|
|
activeItem.forEach((item: string | number, idx: number) => {
|
|
activeItem.forEach((item: string | number, idx: number) => {
|
|
@@ -47,14 +47,14 @@ export default create({
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const isExpanded = (name: string | number | Array<string | number>) => {
|
|
const isExpanded = (name: string | number | Array<string | number>) => {
|
|
|
- const { accordion, active } = props;
|
|
|
|
|
|
|
+ const { accordion, modelValue } = props;
|
|
|
if (accordion) {
|
|
if (accordion) {
|
|
|
- return typeof active === 'number' || typeof active === 'string' ? active == name : false;
|
|
|
|
|
|
|
+ return typeof modelValue === 'number' || typeof modelValue === 'string' ? modelValue == name : false;
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const activeIndex = () => {
|
|
const activeIndex = () => {
|
|
|
- const activeCollapse: any = props.active;
|
|
|
|
|
|
|
+ const activeCollapse: any = props.modelValue;
|
|
|
const childrenList: any = slots.default?.();
|
|
const childrenList: any = slots.default?.();
|
|
|
let act: any = [];
|
|
let act: any = [];
|
|
|
childrenList.forEach((item: any, index: number) => {
|
|
childrenList.forEach((item: any, index: number) => {
|
|
@@ -78,19 +78,15 @@ export default create({
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
watch(
|
|
watch(
|
|
|
- () => props.active,
|
|
|
|
|
- (newval: any, oldval) => {
|
|
|
|
|
|
|
+ () => props.modelValue,
|
|
|
|
|
+ (newval: any) => {
|
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
|
let domsProps: any = slots?.default?.();
|
|
let domsProps: any = slots?.default?.();
|
|
|
let doms: any = childrenDom.value;
|
|
let doms: any = childrenDom.value;
|
|
|
Array.from(doms).forEach((item: any, index: number) => {
|
|
Array.from(doms).forEach((item: any, index: number) => {
|
|
|
if (typeof newval == 'number' || typeof newval == 'string') {
|
|
if (typeof newval == 'number' || typeof newval == 'string') {
|
|
|
- if (domsProps[index]) {
|
|
|
|
|
- if (domsProps[index].props) {
|
|
|
|
|
- item.changeOpen(newval == domsProps[index].props.name ? true : false);
|
|
|
|
|
- } else {
|
|
|
|
|
- item.changeOpen(newval == item.name ? true : false);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (domsProps[index] && domsProps[index].props) {
|
|
|
|
|
+ item.changeOpen(newval == domsProps[index].props.name ? true : false);
|
|
|
} else {
|
|
} else {
|
|
|
item.changeOpen(newval == item.name ? true : false);
|
|
item.changeOpen(newval == item.name ? true : false);
|
|
|
}
|
|
}
|