浏览代码

upd: ts declare optimization

suzigang 3 年之前
父节点
当前提交
9c3d41ade2

+ 3 - 6
src/packages/__VUE/button/index.taro.vue

@@ -20,9 +20,6 @@ import { PropType, CSSProperties, toRefs, computed } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('button');
 import Icon from '../icon/index.taro.vue';
-export type ButtonType = 'default' | 'primary' | 'info' | 'success' | 'warning' | 'danger';
-export type ButtonSize = 'large' | 'normal' | 'small' | 'mini';
-export type ButtonShape = 'square' | 'round';
 export default create({
   components: {
     [Icon.name]: Icon
@@ -30,7 +27,7 @@ export default create({
   props: {
     color: String,
     shape: {
-      type: String as PropType<ButtonShape>,
+      type: String as PropType<import('./type').ButtonShape>,
       default: 'round'
     },
     plain: {
@@ -46,11 +43,11 @@ export default create({
       default: false
     },
     type: {
-      type: String as PropType<ButtonType>,
+      type: String as PropType<import('./type').ButtonType>,
       default: 'default'
     },
     size: {
-      type: String as PropType<ButtonSize>,
+      type: String as PropType<import('./type').ButtonSize>,
       default: 'normal'
     },
     block: {

+ 3 - 7
src/packages/__VUE/button/index.vue

@@ -20,10 +20,6 @@ import { PropType, CSSProperties, toRefs, computed } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 import Icon from '../icon/index.vue';
 const { componentName, create } = createComponent('button');
-
-export type ButtonType = 'default' | 'primary' | 'info' | 'success' | 'warning' | 'danger';
-export type ButtonSize = 'large' | 'normal' | 'small' | 'mini';
-export type ButtonShape = 'square' | 'round';
 export default create({
   components: {
     [Icon.name]: Icon
@@ -31,7 +27,7 @@ export default create({
   props: {
     color: String,
     shape: {
-      type: String as PropType<ButtonShape>,
+      type: String as PropType<import('./type').ButtonShape>,
       default: 'round'
     },
     plain: {
@@ -47,11 +43,11 @@ export default create({
       default: false
     },
     type: {
-      type: String as PropType<ButtonType>,
+      type: String as PropType<import('./type').ButtonType>,
       default: 'default'
     },
     size: {
-      type: String as PropType<ButtonSize>,
+      type: String as PropType<import('./type').ButtonSize>,
       default: 'normal'
     },
     block: {

+ 3 - 0
src/packages/__VUE/button/type.ts

@@ -0,0 +1,3 @@
+export type ButtonType = 'default' | 'primary' | 'info' | 'success' | 'warning' | 'danger';
+export type ButtonSize = 'large' | 'normal' | 'small' | 'mini';
+export type ButtonShape = 'square' | 'round';

+ 4 - 8
src/packages/__VUE/datepicker/index.taro.vue

@@ -18,14 +18,10 @@ import { toRefs, watch, computed, reactive, onBeforeMount } from 'vue';
 import type { PropType } from 'vue';
 import nutPicker from '../picker/index.taro.vue';
 import { popupProps } from '../popup/index.vue';
-import { PickerOption } from '../picker/types';
 import { createComponent } from '@/packages/utils/create';
 import { padZero } from './utils';
 const { componentName, create } = createComponent('datepicker');
 
-type Formatter = (type: string, option: PickerOption) => PickerOption;
-type Filter = (columnType: string, options: PickerOption[]) => PickerOption[];
-
 const currentYear = new Date().getFullYear();
 function isDate(val: Date): val is Date {
   return Object.prototype.toString.call(val) === '[object Date]' && !isNaN(val.getTime());
@@ -83,10 +79,10 @@ export default create({
       validator: isDate
     },
     formatter: {
-      type: Function as PropType<Formatter>,
+      type: Function as PropType<import('./type').Formatter>,
       default: null
     },
-    filter: Function as PropType<Filter>
+    filter: Function as PropType<import('./type').Filter>
   },
   emits: ['click', 'update:visible', 'change', 'confirm', 'update:moduleValue'],
 
@@ -217,7 +213,7 @@ export default create({
     }: {
       columnIndex: number;
       selectedValue: (string | number)[];
-      selectedOptions: PickerOption[];
+      selectedOptions: import('../picker/types').PickerOption[];
     }) => {
       if (['date', 'datetime', 'datehour', 'month-day'].includes(props.type)) {
         let formatDate: (number | string)[] = [];
@@ -260,7 +256,7 @@ export default create({
 
     const generateValue = (min: number, max: number, val: number | string, type: string, columnIndex: number) => {
       // if (!(max > min)) return;
-      const arr: Array<PickerOption> = [];
+      const arr: Array<import('../picker/types').PickerOption> = [];
       let index = 0;
       while (min <= max) {
         arr.push(formatterOption(type, min));

+ 4 - 8
src/packages/__VUE/datepicker/index.vue

@@ -19,14 +19,10 @@ import { toRefs, watch, computed, reactive, onBeforeMount } from 'vue';
 import type { PropType } from 'vue';
 import Picker from '../picker/index.vue';
 import { popupProps } from '../popup/index.vue';
-import { PickerOption } from '../picker/types';
 import { createComponent } from '@/packages/utils/create';
 import { padZero } from './utils';
 const { componentName, create } = createComponent('datepicker');
 
-type Formatter = (type: string, option: PickerOption) => PickerOption;
-type Filter = (columnType: string, options: PickerOption[]) => PickerOption[];
-
 const currentYear = new Date().getFullYear();
 function isDate(val: Date): val is Date {
   return Object.prototype.toString.call(val) === '[object Date]' && !isNaN(val.getTime());
@@ -84,10 +80,10 @@ export default create({
       validator: isDate
     },
     formatter: {
-      type: Function as PropType<Formatter>,
+      type: Function as PropType<import('./type').Formatter>,
       default: null
     },
-    filter: Function as PropType<Filter>
+    filter: Function as PropType<import('./type').Filter>
   },
   emits: ['click', 'update:visible', 'change', 'confirm', 'update:moduleValue'],
 
@@ -229,7 +225,7 @@ export default create({
     }: {
       columnIndex: number;
       selectedValue: (string | number)[];
-      selectedOptions: PickerOption[];
+      selectedOptions: import('../picker/types').PickerOption[];
     }) => {
       if (['date', 'datetime', 'datehour', 'month-day'].includes(props.type)) {
         let formatDate: (number | string)[] = [];
@@ -273,7 +269,7 @@ export default create({
 
     // min 最小值  max 最大值  val  当前显示的值   type 类型(year、month、day、time)
     const generateValue = (min: number, max: number, val: number | string, type: string, columnIndex: number) => {
-      const arr: Array<PickerOption> = [];
+      const arr: Array<import('../picker/types').PickerOption> = [];
       let index = 0;
       while (min <= max) {
         arr.push(formatterOption(type, min));

+ 8 - 0
src/packages/__VUE/datepicker/type.ts

@@ -0,0 +1,8 @@
+export type Formatter = (
+  type: string,
+  option: import('../picker/types').PickerOption
+) => import('../picker/types').PickerOption;
+export type Filter = (
+  columnType: string,
+  options: import('../picker/types').PickerOption[]
+) => import('../picker/types').PickerOption[];

+ 1 - 2
src/packages/__VUE/formitem/index.vue

@@ -22,7 +22,6 @@ import { pxCheck } from '@/packages/utils/pxCheck';
 import { computed, inject, provide, PropType, ref } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('form-item');
-import { FormItemRule } from './types';
 export default create({
   inheritAttrs: false,
   props: {
@@ -35,7 +34,7 @@ export default create({
       default: ''
     },
     rules: {
-      type: Array as PropType<FormItemRule[]>,
+      type: Array as PropType<import('./types').FormItemRule[]>,
       default: () => {
         return [];
       }

+ 6 - 43
src/packages/__VUE/input/index.taro.vue

@@ -91,43 +91,6 @@ import { createComponent } from '@/packages/utils/create';
 import { formatNumber } from './util';
 
 const { componentName, create, translate } = createComponent('input');
-interface Events {
-  eventName: 'focus' | 'blur' | 'clear' | 'change' | 'update:modelValue';
-  params: (string | number | Event)[];
-}
-export type InputAlignType = 'left' | 'center' | 'right'; // text-align
-export type InputFormatTrigger = 'onChange' | 'onBlur'; // onChange: 在输入时执行格式化 ; onBlur: 在失焦时执行格式化
-export type InputType =
-  | 'tel'
-  | 'url'
-  | 'date'
-  | 'file'
-  | 'text'
-  | 'time'
-  | 'week'
-  | 'color'
-  | 'digit'
-  | 'email'
-  | 'image'
-  | 'month'
-  | 'radio'
-  | 'range'
-  | 'reset'
-  | 'button'
-  | 'hidden'
-  | 'number'
-  | 'search'
-  | 'submit'
-  | 'checkbox'
-  | 'password'
-  | 'textarea'
-  | 'datetime-local';
-
-export type InputRule = {
-  pattern?: RegExp;
-  message?: string;
-  required?: boolean;
-};
 
 export default create({
   props: {
@@ -136,7 +99,7 @@ export default create({
       default: ''
     },
     type: {
-      type: String as PropType<InputType>,
+      type: String as PropType<import('./type').InputType>,
       default: 'text'
     },
     modelValue: {
@@ -160,7 +123,7 @@ export default create({
       default: '80'
     },
     labelAlign: {
-      type: String as PropType<InputAlignType>,
+      type: String as PropType<import('./type').InputAlignType>,
       default: 'left'
     },
     colon: {
@@ -228,7 +191,7 @@ export default create({
       default: true
     },
     formatTrigger: {
-      type: String as PropType<InputFormatTrigger>,
+      type: String as PropType<import('./type').InputFormatTrigger>,
       default: 'onChange'
     },
     formatter: {
@@ -236,7 +199,7 @@ export default create({
       default: null
     },
     rules: {
-      type: Array as PropType<InputRule>,
+      type: Array as PropType<import('./type').InputRule>,
       default: []
     },
     errorMessage: {
@@ -244,7 +207,7 @@ export default create({
       default: ''
     },
     errorMessageAlign: {
-      type: String as PropType<InputAlignType>,
+      type: String as PropType<import('./type').InputAlignType>,
       default: ''
     },
     rows: {
@@ -338,7 +301,7 @@ export default create({
     const blur = () => inputRef.value?.blur();
     const focus = () => inputRef.value?.focus();
 
-    const updateValue = (value: string, trigger: InputFormatTrigger = 'onChange') => {
+    const updateValue = (value: string, trigger: import('./type').InputFormatTrigger = 'onChange') => {
       if (props.type === 'digit') {
         value = formatNumber(value, false, false);
       }

+ 6 - 43
src/packages/__VUE/input/index.vue

@@ -88,43 +88,6 @@ import { createComponent } from '@/packages/utils/create';
 import { formatNumber } from './util';
 
 const { componentName, create, translate } = createComponent('input');
-interface Events {
-  eventName: 'focus' | 'blur' | 'clear' | 'change' | 'update:modelValue';
-  params: (string | number | Event)[];
-}
-export type InputAlignType = 'left' | 'center' | 'right'; // text-align
-export type InputFormatTrigger = 'onChange' | 'onBlur'; // onChange: 在输入时执行格式化 ; onBlur: 在失焦时执行格式化
-export type InputType =
-  | 'tel'
-  | 'url'
-  | 'date'
-  | 'file'
-  | 'text'
-  | 'time'
-  | 'week'
-  | 'color'
-  | 'digit'
-  | 'email'
-  | 'image'
-  | 'month'
-  | 'radio'
-  | 'range'
-  | 'reset'
-  | 'button'
-  | 'hidden'
-  | 'number'
-  | 'search'
-  | 'submit'
-  | 'checkbox'
-  | 'password'
-  | 'textarea'
-  | 'datetime-local';
-
-export type InputRule = {
-  pattern?: RegExp;
-  message?: string;
-  required?: boolean;
-};
 
 export default create({
   props: {
@@ -133,7 +96,7 @@ export default create({
       default: ''
     },
     type: {
-      type: String as PropType<InputType>,
+      type: String as PropType<import('./type').InputType>,
       default: 'text'
     },
     modelValue: {
@@ -157,7 +120,7 @@ export default create({
       default: '80'
     },
     labelAlign: {
-      type: String as PropType<InputAlignType>,
+      type: String as PropType<import('./type').InputAlignType>,
       default: 'left'
     },
     colon: {
@@ -225,7 +188,7 @@ export default create({
       default: true
     },
     formatTrigger: {
-      type: String as PropType<InputFormatTrigger>,
+      type: String as PropType<import('./type').InputFormatTrigger>,
       default: 'onChange'
     },
     formatter: {
@@ -233,7 +196,7 @@ export default create({
       default: null
     },
     rules: {
-      type: Array as PropType<InputRule>,
+      type: Array as PropType<import('./type').InputRule>,
       default: []
     },
     errorMessage: {
@@ -241,7 +204,7 @@ export default create({
       default: ''
     },
     errorMessageAlign: {
-      type: String as PropType<InputAlignType>,
+      type: String as PropType<import('./type').InputAlignType>,
       default: ''
     },
     rows: {
@@ -335,7 +298,7 @@ export default create({
     const blur = () => inputRef.value?.blur();
     const focus = () => inputRef.value?.focus();
 
-    const updateValue = (value: string, trigger: InputFormatTrigger = 'onChange') => {
+    const updateValue = (value: string, trigger: import('./type').InputFormatTrigger = 'onChange') => {
       if (props.type === 'digit') {
         value = formatNumber(value, false, false);
       }

+ 33 - 0
src/packages/__VUE/input/type.ts

@@ -0,0 +1,33 @@
+export type InputAlignType = 'left' | 'center' | 'right'; // text-align
+export type InputFormatTrigger = 'onChange' | 'onBlur'; // onChange: 在输入时执行格式化 ; onBlur: 在失焦时执行格式化
+export type InputType =
+  | 'tel'
+  | 'url'
+  | 'date'
+  | 'file'
+  | 'text'
+  | 'time'
+  | 'week'
+  | 'color'
+  | 'digit'
+  | 'email'
+  | 'image'
+  | 'month'
+  | 'radio'
+  | 'range'
+  | 'reset'
+  | 'button'
+  | 'hidden'
+  | 'number'
+  | 'search'
+  | 'submit'
+  | 'checkbox'
+  | 'password'
+  | 'textarea'
+  | 'datetime-local';
+
+export type InputRule = {
+  pattern?: RegExp;
+  message?: string;
+  required?: boolean;
+};

+ 16 - 15
src/packages/__VUE/picker/index.taro.vue

@@ -45,7 +45,6 @@ import { ref, onMounted, onBeforeUnmount, reactive, watch, computed, toRaw, toRe
 import { createComponent } from '@/packages/utils/create';
 import { popupProps } from '../popup/index.taro.vue';
 import column from './ColumnTaro.vue';
-import { PickerOption } from './types';
 const { componentName, create, translate } = createComponent('picker');
 export default create({
   components: {
@@ -84,7 +83,7 @@ export default create({
   setup(props, { emit }) {
     const state = reactive({
       show: false,
-      formattedColumns: props.columns as PickerOption[]
+      formattedColumns: props.columns as import('./types').PickerOption[]
     });
 
     // 选中项
@@ -98,18 +97,20 @@ export default create({
     });
 
     const selectedOptions = computed(() => {
-      let optins: PickerOption[] = [];
-      (columnsList.value as PickerOption[][]).map((column: PickerOption[], index: number) => {
-        let currOptions = [];
-        currOptions = column.filter((item) => item.value == defaultValues.value[index]);
-        optins.push(currOptions[0]);
-      });
+      let optins: import('./types').PickerOption[] = [];
+      (columnsList.value as import('./types').PickerOption[][]).map(
+        (column: import('./types').PickerOption[], index: number) => {
+          let currOptions = [];
+          currOptions = column.filter((item) => item.value == defaultValues.value[index]);
+          optins.push(currOptions[0]);
+        }
+      );
 
       return optins;
     });
     // 当前类型
     const columnsType = computed(() => {
-      const firstColumn: PickerOption = state.formattedColumns[0];
+      const firstColumn: import('./types').PickerOption = state.formattedColumns[0];
       if (firstColumn) {
         if (Array.isArray(firstColumn)) {
           return 'multiple';
@@ -133,9 +134,9 @@ export default create({
       }
     });
 
-    const formatCascade = (columns: PickerOption[], defaultValues: (number | string)[]) => {
-      const formatted: PickerOption[][] = [];
-      let cursor: PickerOption = {
+    const formatCascade = (columns: import('./types').PickerOption[], defaultValues: (number | string)[]) => {
+      const formatted: import('./types').PickerOption[][] = [];
+      let cursor: import('./types').PickerOption = {
         text: '',
         value: '',
         children: columns
@@ -144,7 +145,7 @@ export default create({
       let columnIndex = 0;
 
       while (cursor && cursor.children) {
-        const options: PickerOption[] = cursor.children;
+        const options: import('./types').PickerOption[] = cursor.children;
         const value = defaultValues[columnIndex];
         let index = options.findIndex((columnItem) => columnItem.value == value);
         if (index == -1) index = 0;
@@ -162,7 +163,7 @@ export default create({
       emit('update:visible', false);
     };
 
-    const changeHandler = (columnIndex: number, option: PickerOption) => {
+    const changeHandler = (columnIndex: number, option: import('./types').PickerOption) => {
       if (option && Object.keys(option).length) {
         if (columnsType.value === 'cascade') {
           defaultValues.value[columnIndex] = option.value ? option.value : '';
@@ -233,7 +234,7 @@ export default create({
     watch(
       () => props.columns,
       (val) => {
-        if (val.length) state.formattedColumns = val as PickerOption[];
+        if (val.length) state.formattedColumns = val as import('./types').PickerOption[];
       }
     );
 

+ 16 - 15
src/packages/__VUE/picker/index.vue

@@ -49,7 +49,6 @@ import { ref, onMounted, onBeforeUnmount, reactive, watch, computed, toRaw, toRe
 import { createComponent } from '@/packages/utils/create';
 import popup, { popupProps } from '../popup/index.vue';
 import column from './Column.vue';
-import { PickerOption } from './types';
 const { componentName, create, translate } = createComponent('picker');
 export default create({
   components: {
@@ -89,7 +88,7 @@ export default create({
   setup(props, { emit }) {
     const state = reactive({
       show: false,
-      formattedColumns: props.columns as PickerOption[]
+      formattedColumns: props.columns as import('./types').PickerOption[]
     });
 
     // 选中项
@@ -103,18 +102,20 @@ export default create({
     });
 
     const selectedOptions = computed(() => {
-      let optins: PickerOption[] = [];
-      (columnsList.value as PickerOption[][]).map((column: PickerOption[], index: number) => {
-        let currOptions = [];
-        currOptions = column.filter((item) => item.value == defaultValues.value[index]);
-        optins.push(currOptions[0]);
-      });
+      let optins: import('./types').PickerOption[] = [];
+      (columnsList.value as import('./types').PickerOption[][]).map(
+        (column: import('./types').PickerOption[], index: number) => {
+          let currOptions = [];
+          currOptions = column.filter((item) => item.value == defaultValues.value[index]);
+          optins.push(currOptions[0]);
+        }
+      );
 
       return optins;
     });
     // 当前类型
     const columnsType = computed(() => {
-      const firstColumn: PickerOption = state.formattedColumns[0];
+      const firstColumn: import('./types').PickerOption = state.formattedColumns[0];
       if (firstColumn) {
         if (Array.isArray(firstColumn)) {
           return 'multiple';
@@ -138,9 +139,9 @@ export default create({
       }
     });
 
-    const formatCascade = (columns: PickerOption[], defaultValues: (number | string)[]) => {
-      const formatted: PickerOption[][] = [];
-      let cursor: PickerOption = {
+    const formatCascade = (columns: import('./types').PickerOption[], defaultValues: (number | string)[]) => {
+      const formatted: import('./types').PickerOption[][] = [];
+      let cursor: import('./types').PickerOption = {
         text: '',
         value: '',
         children: columns
@@ -149,7 +150,7 @@ export default create({
       let columnIndex = 0;
 
       while (cursor && cursor.children) {
-        const options: PickerOption[] = cursor.children;
+        const options: import('./types').PickerOption[] = cursor.children;
         const value = defaultValues[columnIndex];
         let index = options.findIndex((columnItem) => columnItem.value == value);
         if (index == -1) index = 0;
@@ -167,7 +168,7 @@ export default create({
       emit('update:visible', false);
     };
 
-    const changeHandler = (columnIndex: number, option: PickerOption) => {
+    const changeHandler = (columnIndex: number, option: import('./types').PickerOption) => {
       if (option && Object.keys(option).length) {
         if (columnsType.value === 'cascade') {
           defaultValues.value[columnIndex] = option.value ? option.value : '';
@@ -238,7 +239,7 @@ export default create({
     watch(
       () => props.columns,
       (val) => {
-        if (val.length) state.formattedColumns = val as PickerOption[];
+        if (val.length) state.formattedColumns = val as import('./types').PickerOption[];
       }
     );
 

+ 3 - 6
src/packages/__VUE/popover/index.taro.vue

@@ -29,9 +29,6 @@ import Popup, { popupProps } from '../popup/index.vue';
 import Button from '../button/index.vue';
 import { useTaroRect } from '@/packages/utils/useTaroRect';
 import Taro from '@tarojs/taro';
-export type PopoverTheme = 'light' | 'dark';
-
-export type PopoverLocation = 'bottom' | 'top' | 'left' | 'right';
 
 export default create({
   inheritAttrs: false,
@@ -47,16 +44,16 @@ export default create({
     },
 
     theme: {
-      type: String as PropType<PopoverTheme>,
+      type: String as PropType<import('./type').PopoverTheme>,
       default: 'light'
     },
 
     location: {
-      type: String as PropType<PopoverLocation>,
+      type: String as PropType<import('./type').PopoverLocation>,
       default: 'bottom'
     }
   },
-  emits: ['update', 'update:visible', 'close', 'choose', 'openPopover'],
+  emits: ['update', 'update:visible', 'close', 'choose', 'openPopover', 'open'],
   setup(props, { emit }) {
     const reference = ref<HTMLElement>();
     const state = reactive({

+ 3 - 8
src/packages/__VUE/popover/index.vue

@@ -27,11 +27,6 @@ import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('popover');
 import Popup, { popupProps } from '../popup/index.vue';
 import Button from '../button/index.vue';
-
-export type PopoverTheme = 'light' | 'dark';
-
-export type PopoverLocation = 'bottom' | 'top' | 'left' | 'right';
-
 export default create({
   inheritAttrs: false,
   components: {
@@ -46,16 +41,16 @@ export default create({
     },
 
     theme: {
-      type: String as PropType<PopoverTheme>,
+      type: String as PropType<import('./type').PopoverTheme>,
       default: 'light'
     },
 
     location: {
-      type: String as PropType<PopoverLocation>,
+      type: String as PropType<import('./type').PopoverLocation>,
       default: 'bottom'
     }
   },
-  emits: ['update', 'update:visible', 'close', 'choose', 'openPopover'],
+  emits: ['update', 'update:visible', 'close', 'choose', 'openPopover', 'open'],
   setup(props, { emit }) {
     const reference = ref();
     const state = reactive({

+ 3 - 0
src/packages/__VUE/popover/type.ts

@@ -0,0 +1,3 @@
+export type PopoverTheme = 'light' | 'dark';
+
+export type PopoverLocation = 'bottom' | 'top' | 'left' | 'right';

+ 5 - 7
src/packages/__VUE/range/index.taro.vue

@@ -83,8 +83,6 @@ import { useTouch } from '@/packages/utils/useTouch';
 import { useTaroRect } from '@/packages/utils/useTaroRect';
 const { componentName, create } = createComponent('range');
 
-type SliderValue = number | number[];
-
 export default create({
   props: {
     range: {
@@ -124,7 +122,7 @@ export default create({
       default: 1
     },
     modelValue: {
-      type: [Number, Array] as PropType<SliderValue>,
+      type: [Number, Array] as PropType<import('./type').SliderValue>,
       default: 0
     }
   },
@@ -133,8 +131,8 @@ export default create({
 
   setup(props, { emit, slots }) {
     const buttonIndex = ref(0);
-    let startValue: SliderValue;
-    let currentValue: SliderValue;
+    let startValue: import('./type').SliderValue;
+    let currentValue: import('./type').SliderValue;
 
     const root = ref<HTMLElement>();
     const dragStatus = ref<'start' | 'draging' | ''>();
@@ -267,7 +265,7 @@ export default create({
       return Math.round(value / +step) * +step;
     };
 
-    const isSameValue = (newValue: SliderValue, oldValue: SliderValue) =>
+    const isSameValue = (newValue: import('./type').SliderValue, oldValue: import('./type').SliderValue) =>
       JSON.stringify(newValue) === JSON.stringify(oldValue);
 
     const handleOverlap = (value: number[]) => {
@@ -277,7 +275,7 @@ export default create({
       return value;
     };
 
-    const updateValue = (value: SliderValue, end?: boolean) => {
+    const updateValue = (value: import('./type').SliderValue, end?: boolean) => {
       if (isRange(value)) {
         value = handleOverlap(value).map(format);
       } else {

+ 5 - 7
src/packages/__VUE/range/index.vue

@@ -80,8 +80,6 @@ import { useTouch } from '@/packages/utils/useTouch';
 import { useRect } from '@/packages/utils/useRect';
 const { componentName, create } = createComponent('range');
 
-type SliderValue = number | number[];
-
 export default create({
   props: {
     range: {
@@ -122,7 +120,7 @@ export default create({
       default: 1
     },
     modelValue: {
-      type: [Number, Array] as PropType<SliderValue>,
+      type: [Number, Array] as PropType<import('./type').SliderValue>,
       default: 0
     }
   },
@@ -131,8 +129,8 @@ export default create({
 
   setup(props, { emit, slots }) {
     const buttonIndex = ref(0);
-    let startValue: SliderValue;
-    let currentValue: SliderValue;
+    let startValue: import('./type').SliderValue;
+    let currentValue: import('./type').SliderValue;
 
     const root = ref<HTMLElement>();
     const dragStatus = ref<'start' | 'draging' | ''>();
@@ -265,7 +263,7 @@ export default create({
       return Math.round(value / +step) * +step;
     };
 
-    const isSameValue = (newValue: SliderValue, oldValue: SliderValue) =>
+    const isSameValue = (newValue: import('./type').SliderValue, oldValue: import('./type').SliderValue) =>
       JSON.stringify(newValue) === JSON.stringify(oldValue);
 
     const handleOverlap = (value: number[]) => {
@@ -275,7 +273,7 @@ export default create({
       return value;
     };
 
-    const updateValue = (value: SliderValue, end?: boolean) => {
+    const updateValue = (value: import('./type').SliderValue, end?: boolean) => {
       if (isRange(value)) {
         value = handleOverlap(value).map(format);
       } else {

+ 1 - 0
src/packages/__VUE/range/type.ts

@@ -0,0 +1 @@
+export type SliderValue = number | number[];

+ 1 - 2
src/packages/__VUE/tag/index.vue

@@ -9,14 +9,13 @@
 import { PropType, CSSProperties, computed, toRefs } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('tag');
-export type TagType = 'primary' | 'success' | 'danger' | 'warning';
 
 export default create({
   props: {
     color: { type: String, default: '' },
     textColor: { type: String, default: '' },
     type: {
-      type: String as PropType<TagType>,
+      type: String as PropType<import('./type').TagType>,
       default: 'default'
     },
     plain: {

+ 1 - 0
src/packages/__VUE/tag/type.ts

@@ -0,0 +1 @@
+export type TagType = 'primary' | 'success' | 'danger' | 'warning';

+ 8 - 21
src/packages/__VUE/uploader/index.taro.vue

@@ -71,32 +71,19 @@
 import { computed, PropType, reactive } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 import { Uploader, UploadOptions } from './uploader';
+import { FileItem } from './type';
 const { componentName, create, translate } = createComponent('uploader');
 import Taro from '@tarojs/taro';
-export type FileItemStatus = 'ready' | 'uploading' | 'success' | 'error';
-export class FileItem {
-  status: FileItemStatus = 'ready';
-  message: string = translate('ready');
-  uid: string = new Date().getTime().toString();
-  url?: string;
-  path?: string;
-  name?: string;
-  type?: string;
-  percentage: string | number = 0;
-  formData: any = {};
-}
-export type SizeType = 'original' | 'compressed';
-export type SourceType = 'album' | 'camera' | 'user' | 'environment';
 export default create({
   props: {
     name: { type: String, default: 'file' },
     url: { type: String, default: '' },
     sizeType: {
-      type: Array as PropType<SizeType[]>,
+      type: Array as PropType<import('./type').SizeType[]>,
       default: () => ['original', 'compressed']
     },
     sourceType: {
-      type: Array as PropType<SourceType[]>,
+      type: Array as PropType<import('./type').SourceType[]>,
       default: () => ['album', 'camera']
     },
     timeout: { type: [Number, String], default: 1000 * 30 },
@@ -125,7 +112,7 @@ export default create({
     },
     beforeDelete: {
       type: Function,
-      default: (file: FileItem, files: FileItem[]) => {
+      default: (file: import('./type').FileItem, files: import('./type').FileItem[]) => {
         return true;
       }
     },
@@ -143,7 +130,7 @@ export default create({
     'file-item-click'
   ],
   setup(props, { emit }) {
-    const fileList = reactive(props.fileList) as Array<FileItem>;
+    const fileList = reactive(props.fileList) as Array<import('./type').FileItem>;
     let uploadQueue: Promise<Uploader>[] = [];
 
     const classes = computed(() => {
@@ -167,11 +154,11 @@ export default create({
       });
     };
 
-    const fileItemClick = (fileItem: FileItem) => {
+    const fileItemClick = (fileItem: import('./type').FileItem) => {
       emit('file-item-click', { fileItem });
     };
 
-    const executeUpload = (fileItem: FileItem, index: number) => {
+    const executeUpload = (fileItem: import('./type').FileItem, index: number) => {
       const uploadOption = new UploadOptions();
       uploadOption.name = props.name;
       uploadOption.url = props.url;
@@ -296,7 +283,7 @@ export default create({
       }
       return files;
     };
-    const onDelete = (file: FileItem, index: number) => {
+    const onDelete = (file: import('./type').FileItem, index: number) => {
       clearUploadQueue(index);
       if (props.beforeDelete(file, fileList)) {
         fileList.splice(index, 1);

+ 6 - 16
src/packages/__VUE/uploader/index.vue

@@ -111,18 +111,8 @@
 import { computed, reactive } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 import { Uploader, UploadOptions } from './uploader';
+import { FileItem } from './type';
 const { componentName, create, translate } = createComponent('uploader');
-export type FileItemStatus = 'ready' | 'uploading' | 'success' | 'error';
-export class FileItem {
-  status: FileItemStatus = 'ready';
-  message: string = translate('ready');
-  uid: string = new Date().getTime().toString();
-  name?: string;
-  url?: string;
-  type?: string;
-  percentage: string | number = 0;
-  formData: FormData = new FormData();
-}
 export default create({
   props: {
     name: { type: String, default: 'file' },
@@ -155,7 +145,7 @@ export default create({
     },
     beforeDelete: {
       type: Function,
-      default: (file: FileItem, files: FileItem[]) => {
+      default: (file: import('./type').FileItem, files: import('./type').FileItem[]) => {
         return true;
       }
     },
@@ -174,7 +164,7 @@ export default create({
     'file-item-click'
   ],
   setup(props, { emit }) {
-    const fileList = reactive(props.fileList) as Array<FileItem>;
+    const fileList: import('./type').FileItem[] = reactive(props.fileList) as Array<import('./type').FileItem>;
     let uploadQueue: Promise<Uploader>[] = [];
 
     const classes = computed(() => {
@@ -188,11 +178,11 @@ export default create({
       el.value = '';
     };
 
-    const fileItemClick = (fileItem: FileItem) => {
+    const fileItemClick = (fileItem: import('./type').FileItem) => {
       emit('file-item-click', { fileItem });
     };
 
-    const executeUpload = (fileItem: FileItem, index: number) => {
+    const executeUpload = (fileItem: import('./type').FileItem, index: number) => {
       const uploadOption = new UploadOptions();
       uploadOption.url = props.url;
       uploadOption.formData = fileItem.formData;
@@ -307,7 +297,7 @@ export default create({
       }
       return files;
     };
-    const onDelete = (file: FileItem, index: number) => {
+    const onDelete = (file: import('./type').FileItem, index: number) => {
       clearUploadQueue(index);
       if (props.beforeDelete(file, fileList)) {
         fileList.splice(index, 1);

+ 15 - 0
src/packages/__VUE/uploader/type.ts

@@ -0,0 +1,15 @@
+import { createComponent } from '@/packages/utils/create';
+const { translate } = createComponent('uploader');
+export type SizeType = 'original' | 'compressed';
+export type SourceType = 'album' | 'camera' | 'user' | 'environment';
+export type FileItemStatus = 'ready' | 'uploading' | 'success' | 'error';
+export class FileItem {
+  status: FileItemStatus = 'ready';
+  message: string = translate('ready');
+  uid: string = new Date().getTime().toString();
+  name?: string;
+  url?: string;
+  type?: string;
+  percentage: string | number = 0;
+  formData: FormData = new FormData();
+}

+ 3 - 3
vite.config.build.disperse.ts

@@ -40,12 +40,12 @@ declare type Install<T> = T & {
 `;
         const start = 'declare const _sfc_main:';
         const end = ';\nexport default _sfc_main;\n';
+        let name = Object.keys(input).find((item: string) => item.toLowerCase() === filePath.split('/').slice(-2)[0]);
+        name = name ? name.toLowerCase() : ' ';
         const remain = `
 declare module 'vue' {
   interface GlobalComponents {
-      Nut${Object.keys(input).find(
-        (item: string) => item.toLowerCase() === filePath.split('/').slice(-2)[0]
-      )}: typeof _sfc_main;
+      Nut${name[0].toUpperCase() + name.substr(1)}: typeof _sfc_main;
   }
 }     
       `;

+ 3 - 3
vite.config.build.taro.vue.disperse.ts

@@ -42,12 +42,12 @@ declare type Install<T> = T & {
 `;
         const start = 'declare const _sfc_main:';
         const end = ';\nexport default _sfc_main;\n';
+        let name = Object.keys(input).find((item: string) => item.toLowerCase() === filePath.split('/').slice(-2)[0]);
+        name = name ? name.toLowerCase() : ' ';
         const remain = `
 declare module 'vue' {
   interface GlobalComponents {
-      Nut${Object.keys(input).find(
-        (item: string) => item.toLowerCase() === filePath.split('/').slice(-2)[0]
-      )}: typeof _sfc_main;
+      Nut${name[0].toUpperCase() + name.substr(1)}: typeof _sfc_main;
   }
 }     
       `;