Browse Source

fix: collapse 优化

Ymm0008 3 years ago
parent
commit
5c55e726ef

+ 3 - 2
src/packages/__VUE/collapse/index.taro.vue

@@ -34,9 +34,8 @@ export default create({
     };
 
     const changeValAry = (name: string) => {
-      const activeItem: any = props.modelValue instanceof Object ? Object.values(props.modelValue) : props.modelValue;
+      const activeItem: any = props.modelValue;
       let index = -1;
-
       activeItem.forEach((item: string | number, idx: number) => {
         if (String(item) == String(name)) {
           index = idx;
@@ -84,6 +83,8 @@ export default create({
           let domsProps: any = slots?.default?.();
           let doms: any = childrenDom.value;
           Array.from(doms).forEach((item: any, index: number) => {
+            console.log(index);
+
             if (typeof newval == 'number' || typeof newval == 'string') {
               if (domsProps[index] && domsProps[index].props) {
                 item.changeOpen(newval == domsProps[index].props.name ? true : false);

+ 17 - 7
src/packages/__VUE/collapseitem/index.taro.vue

@@ -156,11 +156,12 @@ export default create({
     };
     const open = () => {
       proxyData.openExpanded = !proxyData.openExpanded;
-      // let time = contentRef.value.childNodes?.length || 1;
-      setTimeout(() => {
-        animation();
-      }, 700);
-      // }, 500 * time);
+      setTimeout(
+        () => {
+          animation();
+        },
+        init.value ? 500 : 0
+      );
     };
 
     const defaultOpen = () => {
@@ -214,7 +215,9 @@ export default create({
         if (tm && tm.length > 0) {
           let h = tm[0]['height'];
           item1.conHeight = h;
-          // resetHeight(h);
+          setTimeout(() => {
+            init.value && handleOpen();
+          }, 500);
         }
       });
     };
@@ -224,6 +227,9 @@ export default create({
         let ary: any = Array.from(item1.$el.children);
         let h = ary[1].children[0]['offsetHeight'];
         item1.conHeight = h;
+        setTimeout(() => {
+          init.value && handleOpen();
+        }, 500);
       });
     };
 
@@ -239,7 +245,7 @@ export default create({
         }
       });
     };
-    onMounted(() => {
+    const handleOpen = () => {
       const { name } = props;
       const active = parent && parent.props.modelValue;
       if (typeof active == 'number' || typeof active == 'string') {
@@ -252,6 +258,10 @@ export default create({
           defaultOpen();
         }
       }
+      init.value = false;
+    };
+    const init = ref(true);
+    onMounted(() => {
       // 获取 DOM 元素
       if (Taro.getEnv() === 'WEB') {
         getRefHeight();

+ 0 - 6
src/sites/mobile-taro/vue/src/exhibition/pages/collapse/index.vue

@@ -66,12 +66,6 @@ export default {
     const change = (name: string) => {
       console.log(`点击了name是${name}的面板`);
     };
-    // const content = ref("");
-    // onMounted(() => {
-    //   setTimeout(() => {
-    //     content.value = "京东到家:教师节期间 创意花束销量增长53倍";
-    //   }, 500);
-    // })
     return {
       change,
       ...toRefs(data),