Browse Source

fix: child component taro export bug #707

richard1015 4 years ago
parent
commit
d148930408
3 changed files with 6 additions and 149 deletions
  1. 4 2
      jd/generate-nutui-taro-vue.js
  2. 2 0
      src/config.json
  3. 0 147
      src/packages/__VUE/tabbaritem/index.taro.vue

+ 4 - 2
jd/generate-nutui-taro-vue.js

@@ -7,9 +7,11 @@ let importScssStr = `\n`;
 const packages = [];
 config.nav.map((item) => {
   item.packages.forEach((element) => {
-    let { name, show, type, taro, exportEmpty } = element;
+    let { name, show, type, taro, exportEmpty, exportEmptyTaro } = element;
     if (taro && (show || exportEmpty)) {
-      importStr += `import ${name} from './__VUE/${name.toLowerCase()}/index${exportEmpty ? '' : '.taro'}.vue';\n`;
+      importStr += `import ${name} from './__VUE/${name.toLowerCase()}/index${
+        exportEmpty && !exportEmptyTaro ? '' : '.taro'
+      }.vue';\n`;
       importScssStr += `import './__VUE/${name.toLowerCase()}/index.scss';\n`;
       packages.push(name);
     }

+ 2 - 0
src/config.json

@@ -301,6 +301,7 @@
           "type": "component",
           "show": false,
           "exportEmpty": true,
+          "exportEmptyTaro": true,
           "desc": "折叠面板-item",
           "author": "Ymm0008"
         },
@@ -440,6 +441,7 @@
           "show": false,
           "taro": true,
           "exportEmpty": true,
+          "exportEmptyTaro": true,
           "desc": "轮播图子组件",
           "author": "suzigang"
         },

+ 0 - 147
src/packages/__VUE/tabbaritem/index.taro.vue

@@ -1,147 +0,0 @@
-<template>
-  <div
-    class="nut-tabbar-item"
-    :class="{ 'nut-tabbar-item__icon--unactive': state.active != state.index }"
-    :style="{
-      color:
-        state.active == state.index ? state.activeColor : state.unactiveColor
-    }"
-    @click="change(state.index)"
-  >
-    <view class="nut-tabbar-item_icon-box">
-      <view
-        class="nut-tabbar-item_icon-box_tips nut-tabbar-item_icon-box_num"
-        v-if="num && num <= 99"
-      >
-        {{ num }}
-      </view>
-      <view
-        class="nut-tabbar-item_icon-box_tips nut-tabbar-item_icon-box_nums"
-        v-else-if="num && num > 100"
-        >{{ '99+' }}</view
-      >
-      <view v-if="icon">
-        <nut-icon
-          class="nut-tabbar-item_icon-box_icon"
-          :size="state.size"
-          :name="icon"
-          :font-class-name="fontClassName"
-          :class-prefix="classPrefix"
-        ></nut-icon>
-      </view>
-      <div
-        v-if="!icon && activeImg"
-        class="nut-tabbar-item_icon-box_icon"
-        :style="{
-          backgroundImage: `url(${
-            state.active == state.index ? activeImg : img
-          })`,
-          width: state.size,
-          height: state.size
-        }"
-      ></div>
-      <view
-        :class="[
-          'nut-tabbar-item_icon-box_nav-word',
-          { 'nut-tabbar-item_icon-box_big-word': !icon && !activeImg }
-        ]"
-        >{{ tabTitle }}</view
-      >
-    </view>
-  </div>
-</template>
-<script lang="ts">
-import { createComponent } from '../../utils/create';
-import {
-  ComponentInternalInstance,
-  computed,
-  getCurrentInstance,
-  inject,
-  reactive,
-  watch
-} from 'vue';
-const { create } = createComponent('tabbar-item');
-export default create({
-  props: {
-    tabTitle: {
-      // 标签页的标题
-      type: String,
-      default: ''
-    },
-    icon: {
-      // 标签页显示的icon
-      type: String,
-      default: ''
-    },
-    href: {
-      // 标签页的跳转链接
-      type: String,
-      default: ''
-    },
-    num: {
-      // 页签右上角的数字角标
-      type: String,
-      default: ''
-    },
-    activeImg: {
-      type: String,
-      default: ''
-    },
-    img: {
-      type: String,
-      default: ''
-    },
-    classPrefix: {
-      type: String,
-      default: 'nut-icon'
-    },
-    fontClassName: {
-      type: String,
-      default: 'nutui-iconfont'
-    }
-  },
-  setup(props, ctx) {
-    const parent: any = inject('parent');
-    console.log(props.classPrefix);
-
-    const state = reactive({
-      size: parent.size,
-      unactiveColor: parent.unactiveColor, // 未选中的颜色
-      activeColor: parent.activeColor, // 选中的颜色
-      active: parent.modelValue, // 是否选中
-      index: 0
-    });
-    const relation = (child: ComponentInternalInstance): void => {
-      if (child.proxy) {
-        let index = parent.children.length;
-        state.index = index;
-        let obj = Object.assign({}, child.proxy, { index });
-        parent.children.push(obj);
-      }
-    };
-    relation(getCurrentInstance() as ComponentInternalInstance);
-    function change(index: Number) {
-      parent.changeIndex(index);
-    }
-    const choosed = computed(() => {
-      if (parent) {
-        return parent.modelValue;
-      }
-      return null;
-    });
-
-    watch(choosed, (value, oldValue) => {
-      state.active = value;
-      setTimeout(() => {
-        if (parent.children[value].href) {
-          window.location.href = parent.children[value].href;
-        }
-      });
-    });
-    return {
-      state,
-      change
-    };
-  }
-});
-</script>