ソースを参照

feat: 处理组件tsc问题 (#1922)

ailululu 3 年 前
コミット
514c6cad02

+ 1 - 1
src/packages/__VUE/addresslist/index.taro.vue

@@ -96,7 +96,7 @@ export default create({
   emits: ['delIcon', 'editIcon', 'itemClick', 'longCopy', 'longSet', 'longDel', 'swipeDel', 'add'],
   emits: ['delIcon', 'editIcon', 'itemClick', 'longCopy', 'longSet', 'longDel', 'swipeDel', 'add'],
 
 
   setup(props, { emit }) {
   setup(props, { emit }) {
-    const dataArray = ref([]);
+    const dataArray = ref([]) as any;
     const dataInfo = reactive({
     const dataInfo = reactive({
       id: 2,
       id: 2,
       addressName: '姓名',
       addressName: '姓名',

+ 1 - 1
src/packages/__VUE/addresslist/index.vue

@@ -96,7 +96,7 @@ export default create({
   emits: ['delIcon', 'editIcon', 'itemClick', 'longCopy', 'longSet', 'longDel', 'swipeDel', 'add'],
   emits: ['delIcon', 'editIcon', 'itemClick', 'longCopy', 'longSet', 'longDel', 'swipeDel', 'add'],
 
 
   setup(props, { emit }) {
   setup(props, { emit }) {
-    const dataArray = ref([]);
+    const dataArray = ref([]) as any;
     const dataInfo = reactive({
     const dataInfo = reactive({
       id: 2,
       id: 2,
       addressName: '姓名',
       addressName: '姓名',

+ 6 - 7
src/packages/__VUE/avatar/index.taro.vue

@@ -30,7 +30,7 @@
   </view>
   </view>
 </template>
 </template>
 <script lang="ts">
 <script lang="ts">
-import { toRefs, onMounted, computed, inject, reactive, ref } from 'vue';
+import { toRefs, onMounted, computed, inject, reactive, ref, Ref } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('avatar');
 const { componentName, create } = createComponent('avatar');
 export default create({
 export default create({
@@ -69,7 +69,7 @@ export default create({
     const { size, shape, bgColor, color, icon } = toRefs(props);
     const { size, shape, bgColor, color, icon } = toRefs(props);
     const sizeValue = ['large', 'normal', 'small'];
     const sizeValue = ['large', 'normal', 'small'];
     const avatarGroup: any = inject('avatarGroup', null);
     const avatarGroup: any = inject('avatarGroup', null);
-    const avatarRef = ref(null);
+    const avatarRef = ref(null) as Ref;
     const visible = reactive({
     const visible = reactive({
       lightTheme: false
       lightTheme: false
     });
     });
@@ -82,7 +82,6 @@ export default create({
     onMounted(() => {
     onMounted(() => {
       const children = avatarGroup?.avatarGroupRef?.value?.children;
       const children = avatarGroup?.avatarGroupRef?.value?.children;
       if (children) {
       if (children) {
-        // console.log('parent', avatarGroup);
         avatarLength(children);
         avatarLength(children);
       }
       }
     });
     });
@@ -115,7 +114,7 @@ export default create({
     });
     });
 
 
     const iconStyles = computed(() => {
     const iconStyles = computed(() => {
-      return !!icon.value ? icon.value : '';
+      return icon?.value ? icon.value : '';
     });
     });
 
 
     const isShowText = computed(() => {
     const isShowText = computed(() => {
@@ -136,12 +135,12 @@ export default create({
       }
       }
     };
     };
 
 
-    const activeAvatar = (event: any) => {
+    const activeAvatar = (event: MouseEvent) => {
       emit('active-avatar', event);
       emit('active-avatar', event);
     };
     };
 
 
-    const onError = (event: any) => {
-      emit('onError', event);
+    const onError = () => {
+      emit('onError');
     };
     };
 
 
     return {
     return {

+ 5 - 6
src/packages/__VUE/avatar/index.vue

@@ -30,7 +30,7 @@
   </view>
   </view>
 </template>
 </template>
 <script lang="ts">
 <script lang="ts">
-import { toRefs, onMounted, computed, inject, reactive, ref } from 'vue';
+import { toRefs, onMounted, computed, inject, reactive, ref, Ref } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('avatar');
 const { componentName, create } = createComponent('avatar');
 export default create({
 export default create({
@@ -69,7 +69,7 @@ export default create({
     const { size, shape, bgColor, color, icon } = toRefs(props);
     const { size, shape, bgColor, color, icon } = toRefs(props);
     const sizeValue = ['large', 'normal', 'small'];
     const sizeValue = ['large', 'normal', 'small'];
     const avatarGroup: any = inject('avatarGroup', null);
     const avatarGroup: any = inject('avatarGroup', null);
-    const avatarRef = ref(null);
+    const avatarRef = ref(null) as Ref;
     const visible = reactive({
     const visible = reactive({
       lightTheme: false
       lightTheme: false
     });
     });
@@ -82,7 +82,6 @@ export default create({
     onMounted(() => {
     onMounted(() => {
       const children = avatarGroup?.avatarGroupRef?.value?.children;
       const children = avatarGroup?.avatarGroupRef?.value?.children;
       if (children) {
       if (children) {
-        // console.log('children', children);
         avatarLength(children);
         avatarLength(children);
       }
       }
     });
     });
@@ -115,7 +114,7 @@ export default create({
     });
     });
 
 
     const iconStyles = computed(() => {
     const iconStyles = computed(() => {
-      return !!icon.value ? icon.value : '';
+      return icon?.value ? icon.value : '';
     });
     });
 
 
     const isShowText = computed(() => {
     const isShowText = computed(() => {
@@ -141,8 +140,8 @@ export default create({
       emit('active-avatar', event);
       emit('active-avatar', event);
     };
     };
 
 
-    const onError = (event: MouseEvent) => {
-      emit('onError', event);
+    const onError = () => {
+      emit('onError');
     };
     };
 
 
     return {
     return {

+ 6 - 8
src/packages/__VUE/category/index.taro.vue

@@ -17,15 +17,15 @@
   </div>
   </div>
 </template>
 </template>
 <script lang="ts">
 <script lang="ts">
-import { Ref, ref, toRefs, warn, watch, onMounted } from 'vue';
+import { PropType, ref } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('category');
 const { componentName, create } = createComponent('category');
 
 
-//经典分类
-//商品池
-//自定义
+export type CategoryType = {
+  catName?: string;
+  [key: string]: any;
+};
 
 
-interface props {}
 export default create({
 export default create({
   props: {
   props: {
     //分类模式
     //分类模式
@@ -36,7 +36,7 @@ export default create({
 
 
     //左侧导航栏
     //左侧导航栏
     category: {
     category: {
-      type: Array,
+      type: Array as PropType<CategoryType>,
       default: () => []
       default: () => []
     }
     }
   },
   },
@@ -50,8 +50,6 @@ export default create({
       emit('change', index);
       emit('change', index);
     };
     };
 
 
-    onMounted(() => {});
-
     return {
     return {
       getChildList,
       getChildList,
       checkIndex,
       checkIndex,

+ 8 - 11
src/packages/__VUE/category/index.vue

@@ -7,7 +7,7 @@
             :class="[checkIndex == index ? 'nut-category__cateListItemChecked' : 'nut-category__cateListItem']"
             :class="[checkIndex == index ? 'nut-category__cateListItemChecked' : 'nut-category__cateListItem']"
             @click="getChildList(index)"
             @click="getChildList(index)"
           >
           >
-            {{ item?.catName }}
+            {{ item.catName }}
           </div>
           </div>
         </div>
         </div>
       </div>
       </div>
@@ -17,15 +17,15 @@
   </div>
   </div>
 </template>
 </template>
 <script lang="ts">
 <script lang="ts">
-import { Ref, ref, toRefs, warn, watch, onMounted } from 'vue';
+import { PropType, ref } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('category');
 const { componentName, create } = createComponent('category');
 
 
-//经典分类
-//商品池
-//自定义
+export type CategoryType = {
+  catName?: string;
+  [key: string]: any;
+};
 
 
-interface props {}
 export default create({
 export default create({
   props: {
   props: {
     //分类模式
     //分类模式
@@ -33,11 +33,10 @@ export default create({
       type: String,
       type: String,
       default: 'classify'
       default: 'classify'
     },
     },
-
     //左侧导航栏
     //左侧导航栏
     category: {
     category: {
-      type: Array,
-      default: () => []
+      type: Array as PropType<CategoryType>,
+      default: []
     }
     }
   },
   },
 
 
@@ -50,8 +49,6 @@ export default create({
       emit('change', index);
       emit('change', index);
     };
     };
 
 
-    onMounted(() => {});
-
     return {
     return {
       getChildList,
       getChildList,
       checkIndex,
       checkIndex,

+ 14 - 9
src/packages/__VUE/categorypane/index.taro.vue

@@ -39,22 +39,27 @@
     <!-- 自定义 -->
     <!-- 自定义 -->
 
 
     <div v-if="type == 'custom'" class="nut-categorypane__selfItemList">
     <div v-if="type == 'custom'" class="nut-categorypane__selfItemList">
-      <div v-for="(sku, key) in customCategory" class="nut-categorypane__skuName" :key="key" @click="onChange()">
+      <div v-for="(sku, key) in customCategory" class="nut-categorypane__skuName" :key="key" @click="onChange(sku)">
         {{ sku?.catName }}
         {{ sku?.catName }}
       </div>
       </div>
     </div>
     </div>
   </div>
   </div>
 </template>
 </template>
 <script lang="ts">
 <script lang="ts">
-import { Ref, ref, toRefs, warn, watch, onMounted } from 'vue';
+import { PropType } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('category-pane');
 const { componentName, create } = createComponent('category-pane');
 
 
-//经典分类
-//商品池
-//自定义
+export type ChildType = {
+  catName?: string;
+  catType?: number;
+  [key: string]: any;
+};
+export type CustomType = {
+  catName?: string;
+  [key: string]: any;
+};
 
 
-interface props {}
 export default create({
 export default create({
   props: {
   props: {
     //分类模式
     //分类模式
@@ -65,19 +70,19 @@ export default create({
 
 
     //右侧导航数据
     //右侧导航数据
     categoryChild: {
     categoryChild: {
-      type: Array,
+      type: Array as PropType<ChildType>,
       default: () => []
       default: () => []
     },
     },
 
 
     //模式传入自定义数据
     //模式传入自定义数据
     customCategory: {
     customCategory: {
-      type: Array,
+      type: Array as PropType<CustomType>,
       default: () => []
       default: () => []
     }
     }
   },
   },
 
 
   setup(props, { emit }) {
   setup(props, { emit }) {
-    const onChange = (sku: any) => {
+    const onChange = (sku: string) => {
       emit('onChange', sku);
       emit('onChange', sku);
     };
     };
 
 

+ 13 - 8
src/packages/__VUE/categorypane/index.vue

@@ -46,15 +46,20 @@
   </div>
   </div>
 </template>
 </template>
 <script lang="ts">
 <script lang="ts">
-import { Ref, ref, toRefs, warn, watch, onMounted } from 'vue';
+import { PropType } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('category-pane');
 const { componentName, create } = createComponent('category-pane');
 
 
-//经典分类
-//商品池
-//自定义
+export type ChildType = {
+  catName?: string;
+  catType?: number;
+  [key: string]: any;
+};
+export type CustomType = {
+  catName?: string;
+  [key: string]: any;
+};
 
 
-interface props {}
 export default create({
 export default create({
   props: {
   props: {
     //分类模式
     //分类模式
@@ -65,19 +70,19 @@ export default create({
 
 
     //右侧导航数据
     //右侧导航数据
     categoryChild: {
     categoryChild: {
-      type: Array,
+      type: Array as PropType<ChildType>,
       default: () => []
       default: () => []
     },
     },
 
 
     //模式传入自定义数据
     //模式传入自定义数据
     customCategory: {
     customCategory: {
-      type: Array,
+      type: Array as PropType<CustomType>,
       default: () => []
       default: () => []
     }
     }
   },
   },
 
 
   setup(props, { emit }) {
   setup(props, { emit }) {
-    const onChange = (sku: any) => {
+    const onChange = (sku: string) => {
       emit('onChange', sku);
       emit('onChange', sku);
     };
     };
 
 

+ 2 - 2
src/packages/__VUE/navbar/index.taro.vue

@@ -36,7 +36,7 @@
 </template>
 </template>
 
 
 <script lang="ts">
 <script lang="ts">
-import { onMounted, computed, toRefs, ref } from 'vue';
+import { onMounted, computed, toRefs, ref, ComputedRef } from 'vue';
 import { useTaroRect } from '@/packages/utils/useTaroRect';
 import { useTaroRect } from '@/packages/utils/useTaroRect';
 import { createComponent } from '@/packages/utils/create';
 import { createComponent } from '@/packages/utils/create';
 import Taro from '@tarojs/taro';
 import Taro from '@tarojs/taro';
@@ -84,7 +84,7 @@ export default create({
       };
       };
     });
     });
 
 
-    const styles = computed(() => {
+    const styles: ComputedRef = computed(() => {
       return {
       return {
         zIndex: zIndex.value
         zIndex: zIndex.value
       };
       };

+ 7 - 7
src/packages/__VUE/navbar/index.vue

@@ -36,7 +36,7 @@
 </template>
 </template>
 
 
 <script lang="ts">
 <script lang="ts">
-import { onMounted, computed, toRefs, ref, nextTick } from 'vue';
+import { onMounted, computed, toRefs, ref, nextTick, ComputedRef, Ref } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('navbar');
 const { componentName, create } = createComponent('navbar');
 export default create({
 export default create({
@@ -71,9 +71,9 @@ export default create({
   emits: ['on-click-back', 'on-click-title', 'on-click-icon', 'on-click-right'],
   emits: ['on-click-back', 'on-click-title', 'on-click-icon', 'on-click-right'],
   setup(props, { emit }) {
   setup(props, { emit }) {
     const { border, fixed, safeAreaInsetTop, placeholder, zIndex } = toRefs(props);
     const { border, fixed, safeAreaInsetTop, placeholder, zIndex } = toRefs(props);
-    const navBarWrap = ref(null);
-    const navBarHtml = ref(null);
-    let navHeight = ref(0);
+    const navBarWrap = ref(null) as Ref;
+    const navBarHtml = ref<HTMLElement | null>(null);
+    let navHeight = ref();
     const classes = computed(() => {
     const classes = computed(() => {
       const prefixCls = componentName;
       const prefixCls = componentName;
       return {
       return {
@@ -84,7 +84,7 @@ export default create({
       };
       };
     });
     });
 
 
-    const styles = computed(() => {
+    const styles: ComputedRef = computed(() => {
       return {
       return {
         zIndex: zIndex.value
         zIndex: zIndex.value
       };
       };
@@ -93,8 +93,8 @@ export default create({
     onMounted(() => {
     onMounted(() => {
       if (fixed.value && placeholder.value) {
       if (fixed.value && placeholder.value) {
         nextTick(() => {
         nextTick(() => {
-          navHeight = navBarHtml?.value?.getBoundingClientRect().height;
-          navBarWrap.value.style.height = navHeight + 'px';
+          navHeight.value = navBarHtml?.value?.getBoundingClientRect().height;
+          navBarWrap.value.style.height = navHeight.value + 'px';
         });
         });
       }
       }
     });
     });

+ 1 - 1
src/packages/__VUE/price/demo.vue

@@ -13,7 +13,7 @@
     </nut-cell-group>
     </nut-cell-group>
     <h2>{{ translate('title2') }}</h2>
     <h2>{{ translate('title2') }}</h2>
     <nut-cell>
     <nut-cell>
-      <nut-price :price="8888" decimal-digits="0" size="normal" :need-symbol="true" :thousands="true" />
+      <nut-price :price="8888" :decimal-digits="0" size="normal" :need-symbol="true" :thousands="true" />
     </nut-cell>
     </nut-cell>
     <h2>{{ translate('title3') }}</h2>
     <h2>{{ translate('title3') }}</h2>
     <nut-cell>
     <nut-cell>

+ 2 - 2
src/packages/__VUE/price/doc.en-US.md

@@ -39,7 +39,7 @@ app.use(Price);
 
 
 ``` html
 ``` html
 <template>
 <template>
-    <nut-price :price="8888" decimal-digits="0" size="normal" :need-symbol="true" :thousands="true" />
+    <nut-price :price="8888" :decimal-digits="0" size="normal" :need-symbol="true" :thousands="true" />
 </template>
 </template>
 ```
 ```
 
 
@@ -113,7 +113,7 @@ app.use(Price);
 | price          | Price                                                      | Number | String | 0       |
 | price          | Price                                                      | Number | String | 0       |
 | need-symbol    | Add symbol                                                 | Boolean          | true   |
 | need-symbol    | Add symbol                                                 | Boolean          | true   |
 | symbol         | Symbol type                                                | String           | &yen;  |
 | symbol         | Symbol type                                                | String           | &yen;  |
-| decimal-digits | Decimal digits                                             | Number | String | 2      |
+| decimal-digits | Decimal digits                                             | Number | 2      |
 | thousands      | Thousands separation                                       | Boolean          | false  |
 | thousands      | Thousands separation                                       | Boolean          | false  |
 | position       | The symbol appear before or after the price,`before`、`after` | String           | before |
 | position       | The symbol appear before or after the price,`before`、`after` | String           | before |
 | size           | Size,`large`、`normal`、`small`                            | String           | large |
 | size           | Size,`large`、`normal`、`small`                            | String           | large |

+ 2 - 2
src/packages/__VUE/price/doc.md

@@ -39,7 +39,7 @@ app.use(Price);
 
 
 ``` html
 ``` html
 <template>
 <template>
-    <nut-price :price="8888" decimal-digits="0" size="normal" :need-symbol="true" :thousands="true" />
+    <nut-price :price="8888" :decimal-digits="0" size="normal" :need-symbol="true" :thousands="true" />
 </template>
 </template>
 ```
 ```
 
 
@@ -113,7 +113,7 @@ app.use(Price);
 | price          | 价格数量                                | Number | String | 0      |
 | price          | 价格数量                                | Number | String | 0      |
 | need-symbol    | 是否需要加上 symbol 符号                 | Boolean          | true   |
 | need-symbol    | 是否需要加上 symbol 符号                 | Boolean          | true   |
 | symbol         | 符号类型                                | String           | &yen;  |
 | symbol         | 符号类型                                | String           | &yen;  |
-| decimal-digits | 小数位位数                              | Number | String  | 2     |
+| decimal-digits | 小数位位数                              | Number  | 2     |
 | thousands      | 是否按照千分号形式显示                    | Boolean          | false  |
 | thousands      | 是否按照千分号形式显示                    | Boolean          | false  |
 | position       | 符号显示在价格前或者后,`before`、`after`  | String           | before |
 | position       | 符号显示在价格前或者后,`before`、`after`  | String           | before |
 | size           | 价格尺寸,`large`、`normal`、`small`     | String           | large |
 | size           | 价格尺寸,`large`、`normal`、`small`     | String           | large |

+ 1 - 1
src/packages/__VUE/price/index.taro.vue

@@ -40,7 +40,7 @@ export default create({
       default: '&yen;'
       default: '&yen;'
     },
     },
     decimalDigits: {
     decimalDigits: {
-      type: [Number, String],
+      type: Number,
       default: 2
       default: 2
     },
     },
     thousands: {
     thousands: {

+ 1 - 1
src/packages/__VUE/price/index.vue

@@ -42,7 +42,7 @@ export default create({
       default: '&yen;'
       default: '&yen;'
     },
     },
     decimalDigits: {
     decimalDigits: {
-      type: [Number, String],
+      type: Number,
       default: 2
       default: 2
     },
     },
     thousands: {
     thousands: {

+ 1 - 1
src/sites/mobile-taro/vue/src/exhibition/pages/price/index.vue

@@ -13,7 +13,7 @@
     </nut-cell-group>
     </nut-cell-group>
     <h2>不保留小数</h2>
     <h2>不保留小数</h2>
     <nut-cell>
     <nut-cell>
-      <nut-price :price="8888" decimal-digits="0" size="normal" :need-symbol="true" :thousands="true" />
+      <nut-price :price="8888" :decimal-digits="0" size="normal" :need-symbol="true" :thousands="true" />
     </nut-cell>
     </nut-cell>
     <h2>调整 symbol 符号位置</h2>
     <h2>调整 symbol 符号位置</h2>
     <nut-cell>
     <nut-cell>