浏览代码

fix: type error

vben 4 年之前
父节点
当前提交
ecfb702b09
共有 37 个文件被更改,包括 83 次插入73 次删除
  1. 1 1
      build/script/preserve.ts
  2. 1 2
      build/vite/plugin/dynamicImport/index.ts
  3. 1 1
      src/App.vue
  4. 5 5
      src/components/ContextMenu/index.ts
  5. 1 0
      src/components/Dropdown/Dropdown.tsx
  6. 1 1
      src/components/Excel/src/ImportExcel.vue
  7. 2 2
      src/components/Form/src/FormItem.tsx
  8. 1 1
      src/components/Form/src/props.ts
  9. 2 2
      src/components/Menu/src/BasicMenu.tsx
  10. 1 0
      src/components/Scrollbar/src/util.ts
  11. 9 2
      src/components/Table/src/components/TableAction.tsx
  12. 1 1
      src/components/Table/src/const.ts
  13. 1 1
      src/components/Table/src/props.ts
  14. 2 2
      src/components/Table/src/types/table.ts
  15. 1 1
      src/hooks/event/useEvent.ts
  16. 0 2
      src/hooks/event/useWindowSize.ts
  17. 1 1
      src/hooks/web/useLocalStorage.ts
  18. 1 1
      src/hooks/web/useMessage.tsx
  19. 1 1
      src/hooks/web/usePermission.ts
  20. 1 1
      src/hooks/web/useSessionStorage.ts
  21. 1 1
      src/layouts/default/header/LayoutHeader.tsx
  22. 1 1
      src/layouts/default/header/LockActionItem.tsx
  23. 2 2
      src/main.ts
  24. 1 3
      src/router/menus/index.ts
  25. 5 3
      src/router/types.d.ts
  26. 1 1
      src/setup/directives/permission.ts
  27. 1 1
      src/store/modules/permission.ts
  28. 5 4
      src/useApp.ts
  29. 3 3
      src/utils/color.ts
  30. 0 4
      src/utils/env.ts
  31. 2 2
      src/utils/helper/menuHelper.ts
  32. 1 1
      src/utils/helper/persistent.ts
  33. 22 16
      src/utils/helper/routeHelper.ts
  34. 1 0
      src/utils/helper/tsxHelper.tsx
  35. 1 1
      src/utils/http/axios/Axios.ts
  36. 1 1
      src/utils/storage/Storage.ts
  37. 1 1
      src/utils/uuid.ts

+ 1 - 1
build/script/preserve.ts

@@ -25,7 +25,7 @@ export async function runPreserve() {
     process.exit(1);
   }
 
-  fs.mkdirp(resolve('build/.cache'));
+  await fs.mkdirp(resolve('build/.cache'));
   function checkPkgUpdate() {
     const pkg = require('../../package.json');
     const { dependencies, devDependencies } = pkg;

+ 1 - 2
build/vite/plugin/dynamicImport/index.ts

@@ -33,7 +33,7 @@ const dynamicImportTransform = function (env: any = {}): Transform {
       try {
         const files = glob.sync('src/views/**/**.{vue,tsx}', { cwd: process.cwd() });
 
-        const _code = `
+        return `
         export default function (id) {
            switch (id) {
           ${files
@@ -47,7 +47,6 @@ const dynamicImportTransform = function (env: any = {}): Transform {
            }
     }\n\n
     `;
-        return _code;
       } catch (error) {
         console.error(error);
         return code;

+ 1 - 1
src/App.vue

@@ -1,5 +1,5 @@
 <template>
-  <ConfigProvider :locale="zhCN" :transformCellText="transformCellText" v-bind="lockOn">
+  <ConfigProvider :locale="zhCN" :transform-cell-text="transformCellText" v-bind="lockOn">
     <router-view />
   </ConfigProvider>
 </template>

+ 5 - 5
src/components/ContextMenu/index.ts

@@ -3,10 +3,10 @@ import { isClient } from '/@/utils/is';
 import { Options, Props } from './src/types';
 import { createVNode, render } from 'vue';
 const menuManager: {
-  doms: Element[];
+  domList: Element[];
   resolve: Fn;
 } = {
-  doms: [],
+  domList: [],
   resolve: () => {},
 };
 export const createContextMenu = function (options: Options) {
@@ -32,9 +32,9 @@ export const createContextMenu = function (options: Options) {
     const bodyClick = function () {
       menuManager.resolve('');
     };
-    menuManager.doms.push(container);
+    menuManager.domList.push(container);
     const remove = function () {
-      menuManager.doms.forEach((dom: Element) => {
+      menuManager.domList.forEach((dom: Element) => {
         try {
           document.body.removeChild(dom);
         } catch (error) {}
@@ -55,7 +55,7 @@ export const createContextMenu = function (options: Options) {
 export const unMountedContextMenu = function () {
   if (menuManager) {
     menuManager.resolve('');
-    menuManager.doms = [];
+    menuManager.domList = [];
   }
 };
 

+ 1 - 0
src/components/Dropdown/Dropdown.tsx

@@ -34,6 +34,7 @@ export default defineComponent({
                       </>
                     )}
                   </Menu.Item>,
+                  // @ts-ignore
                   divider && <Menu.Divider key={`d-${index}`} />,
                 ];
               })}

+ 1 - 1
src/components/Excel/src/ImportExcel.vue

@@ -96,7 +96,7 @@
           // fix can't select the same excel
           inputRefDom.value = '';
         }
-        readerData(rawFile);
+        await readerData(rawFile);
       }
 
       /**

+ 2 - 2
src/components/Form/src/FormItem.tsx

@@ -2,7 +2,7 @@ import type { PropType } from 'vue';
 import type { FormProps } from './types/form';
 import type { FormSchema } from './types/form';
 import type { ValidationRule } from 'ant-design-vue/lib/form/Form';
-import type { TableActionType } from '../../Table/src/types/table';
+import type { TableActionType } from '/@/components/Table';
 
 import { defineComponent, computed, unref, toRef } from 'vue';
 import { Form, Col } from 'ant-design-vue';
@@ -16,7 +16,7 @@ import { upperFirst, cloneDeep } from 'lodash-es';
 
 import { useItemLabelWidth } from './hooks/useLabelWidth';
 import { ComponentType } from './types';
-import { isNumber } from '../../../utils/is';
+import { isNumber } from '/@/utils/is';
 
 export default defineComponent({
   name: 'BasicFormItem',

+ 1 - 1
src/components/Form/src/props.ts

@@ -1,7 +1,7 @@
 import type { FieldMapToTime, FormSchema } from './types/form';
 import type { PropType } from 'vue';
 import type { ColEx } from './types';
-import { TableActionType } from '../../Table/src/types/table';
+import { TableActionType } from '/@/components/Table';
 
 export const basicProps = {
   model: {

+ 2 - 2
src/components/Menu/src/BasicMenu.tsx

@@ -6,7 +6,7 @@ import { Menu } from 'ant-design-vue';
 import SearchInput from './SearchInput.vue';
 import MenuContent from './MenuContent';
 
-import { MenuModeEnum, MenuTypeEnum } from '/@/enums/menuEnum';
+import { MenuModeEnum, MenuThemeEnum, MenuTypeEnum } from '/@/enums/menuEnum';
 
 import { menuStore } from '/@/store/modules/menu';
 import { appStore } from '/@/store/modules/app';
@@ -255,7 +255,7 @@ export default defineComponent({
           {getSlot(slots, 'header')}
           <SearchInput
             class={!props.search ? 'hidden' : ''}
-            theme={props.theme}
+            theme={props.theme as MenuThemeEnum}
             onChange={handleInputChange}
             onClick={handleInputClick}
             collapsed={getCollapsedState}

+ 1 - 0
src/components/Scrollbar/src/util.ts

@@ -22,6 +22,7 @@ export const BAR_MAP: BarMap = {
   },
 };
 
+// @ts-ignore
 export function renderThumbStyle({ move, size, bar }) {
   const style = {} as any;
   const translate = `translate${bar.axis}(${move}%)`;

+ 9 - 2
src/components/Table/src/components/TableAction.tsx

@@ -2,7 +2,7 @@ import { defineComponent, PropType } from 'vue';
 import { Dropdown, Menu, Popconfirm } from 'ant-design-vue';
 import Icon from '/@/components/Icon/index';
 import { DownOutlined } from '@ant-design/icons-vue';
-import { ActionItem } from '../types/tableAction';
+import { ActionItem } from '/@/components/Table';
 import Button from '/@/components/Button/index.vue';
 const prefixCls = 'basic-table-action';
 export default defineComponent({
@@ -26,7 +26,14 @@ export default defineComponent({
     function renderButton(action: ActionItem, index: number) {
       const { disabled = false, label, icon, color = '', type = 'link' } = action;
       const button = (
-        <Button type={type} size="small" disabled={disabled} color={color} {...action} key={index}>
+        <Button
+          type={type as any}
+          size="small"
+          disabled={disabled}
+          color={color}
+          {...action}
+          key={index}
+        >
           {() => (
             <>
               {label}

+ 1 - 1
src/components/Table/src/const.ts

@@ -22,7 +22,7 @@ export const FETCH_SETTING = {
 };
 
 // 配置通用排序函数
-export function DEFAULT_SORT_FN(sortInfo: SorterResult<any>) {
+export function DEFAULT_SORT_FN(sortInfo: SorterResult) {
   const { field, order } = sortInfo;
   return {
     // 传给后台的排序字段你

+ 1 - 1
src/components/Table/src/props.ts

@@ -8,7 +8,7 @@ import type {
   TableCustomRecord,
   TableRowSelection,
 } from './types/table';
-import type { FormProps } from '/@/components/Form/index';
+import type { FormProps } from '/@/components/Form';
 import { DEFAULT_SORT_FN, FETCH_SETTING } from './const';
 
 // 注释看 types/table

+ 2 - 2
src/components/Table/src/types/table.ts

@@ -1,6 +1,6 @@
 import type { VNodeChild } from 'vue';
 import type { PaginationProps } from './pagination';
-import type { FormProps } from '/@/components/Form/index';
+import type { FormProps } from '/@/components/Form';
 import type {
   ColumnProps,
   TableRowSelection as ITableRowSelection,
@@ -125,7 +125,7 @@ export interface TableSetting {
 
 export interface BasicTableProps<T = any> {
   // 自定义排序方法
-  sortFn?: (sortInfo: SorterResult<any>) => any;
+  sortFn?: (sortInfo: SorterResult) => any;
   // 显示表格设置
   showTableSetting?: boolean;
   tableSetting?: TableSetting;

+ 1 - 1
src/hooks/event/useEvent.ts

@@ -41,7 +41,7 @@ export function useEvent({
 
     const removeWatch = watch(
       element,
-      (v, ov, cleanUp) => {
+      (v, _ov, cleanUp) => {
         if (v) {
           !unref(isAddRef) && addEventListener(v);
           cleanUp(() => {

+ 0 - 2
src/hooks/event/useWindowSize.ts

@@ -1,5 +1,3 @@
-import type { Fn } from './types';
-
 import { tryOnMounted, tryOnUnmounted } from '/@/utils/helper/vueHelper';
 import { ref } from 'vue';
 

+ 1 - 1
src/hooks/web/useLocalStorage.ts

@@ -1,4 +1,4 @@
-import { createStorage } from '/@/utils/storage/index';
+import { createStorage } from '/@/utils/storage';
 
 export function useLocalStorage() {
   return createStorage(localStorage);

+ 1 - 1
src/hooks/web/useMessage.tsx

@@ -1,5 +1,5 @@
 import type { ModalFunc, ModalFuncProps } from 'ant-design-vue/lib/modal/Modal';
-import type { MessageApi } from 'ant-design-vue/lib/message/index';
+import type { MessageApi } from 'ant-design-vue/lib/message';
 import type { VNodeTypes, CSSProperties } from 'vue';
 
 import { Modal, message as Message, notification } from 'ant-design-vue';

+ 1 - 1
src/hooks/web/usePermission.ts

@@ -1,4 +1,4 @@
-import { appStore } from './../../store/modules/app';
+import { appStore } from '/@/store/modules/app';
 import { permissionStore } from '/@/store/modules/permission';
 import { useTabs } from './useTabs';
 import { RoleEnum } from '/@/enums/roleEnum';

+ 1 - 1
src/hooks/web/useSessionStorage.ts

@@ -1,4 +1,4 @@
-import { createStorage } from '/@/utils/storage/index';
+import { createStorage } from '/@/utils/storage';
 
 export function useSessionStorage() {
   return createStorage(sessionStorage);

+ 1 - 1
src/layouts/default/header/LayoutHeader.tsx

@@ -21,7 +21,7 @@ import { useFullscreen } from '/@/hooks/web/useFullScreen';
 import { useTabs } from '/@/hooks/web/useTabs';
 import { useWindowSizeFn } from '/@/hooks/event/useWindowSize';
 import { useRouter } from 'vue-router';
-import { useModal } from '/@/components/Modal/index';
+import { useModal } from '/@/components/Modal';
 
 import { appStore } from '/@/store/modules/app';
 import { errorStore } from '/@/store/modules/error';

+ 1 - 1
src/layouts/default/header/LockActionItem.tsx

@@ -54,7 +54,7 @@ export default defineComponent({
           isLock: true,
           pwd: password,
         });
-        resetFields();
+        await resetFields();
       } catch (error) {}
     }
     // 账号密码登录

+ 2 - 2
src/main.ts

@@ -3,8 +3,8 @@ import { createApp } from 'vue';
 import router, { setupRouter } from '/@/router';
 import { setupStore } from '/@/store';
 import { setupAntd } from '/@/setup/ant-design-vue';
-import { setupErrorHandle } from '/@/setup/error-handle/index';
-import { setupDirectives } from '/@/setup/directives/index';
+import { setupErrorHandle } from '/@/setup/error-handle';
+import { setupDirectives } from '/@/setup/directives';
 
 import { isDevMode, isProdMode, isUseMock } from '/@/utils/env';
 import { setupProdMockServer } from '../mock/_createProductionServer';

+ 1 - 3
src/router/menus/index.ts

@@ -91,9 +91,7 @@ function basicFilter(routes: RouteRecordNormalized[]) {
         if (route.meta.carryParam) {
           return pathToRegexp(route.path).test(menu.path);
         }
-        if (route.meta.ignoreAuth) {
-          return false;
-        }
+        if (route.meta.ignoreAuth) return false;
       }
       return route.path === menu.path;
     });

+ 5 - 3
src/router/types.d.ts

@@ -73,9 +73,11 @@ export interface MenuModule {
   menu: Menu;
 }
 
-export interface AppRouteModule {
-  layout?: AppRouteRecordRaw;
-  routes?: AppRouteRecordRaw[];
+interface RouteModule {
+  layout: AppRouteRecordRaw;
+  routes: AppRouteRecordRaw[];
   children?: AppRouteRecordRaw[];
   component?: any;
 }
+
+export type AppRouteModule = RouteModule | AppRouteRecordRaw;

+ 1 - 1
src/setup/directives/permission.ts

@@ -1,4 +1,4 @@
-import { appStore } from './../../store/modules/app';
+import { appStore } from '/@/store/modules/app';
 import type { App } from 'vue';
 import { usePermission } from '/@/hooks/web/usePermission';
 import { PermissionModeEnum } from '/@/enums/appEnum';

+ 1 - 1
src/store/modules/permission.ts

@@ -10,7 +10,7 @@ import { PermissionModeEnum } from '/@/enums/appEnum';
 import { appStore } from '/@/store/modules/app';
 import { userStore } from '/@/store/modules/user';
 
-import { asyncRoutes } from '/@/router/routes/index';
+import { asyncRoutes } from '/@/router/routes';
 import { filter } from '/@/utils/helper/treeHelper';
 import { toRaw } from 'vue';
 import { getMenuListById } from '/@/api/sys/menu';

+ 5 - 4
src/useApp.ts

@@ -93,10 +93,11 @@ export function useListenerNetWork() {
   // Check network status
   useNetWork({
     onLineFn: () => {
-      replace(PageEnum.BASE_HOME);
-      useTimeout(() => {
-        appStore.commitPageLoadingState(false);
-      }, 300);
+      replace(PageEnum.BASE_HOME).then(() => {
+        useTimeout(() => {
+          appStore.commitPageLoadingState(false);
+        }, 200);
+      });
     },
     offLineFn: () => {
       replace({

+ 3 - 3
src/utils/color.ts

@@ -14,10 +14,10 @@ export const isHexColor = function (color: string) {
  * RGB 颜色值转换为 十六进制颜色值.
  * r, g, 和 b 需要在 [0, 255] 范围内
  *
- * @param   Number  r       红色色值
- * @param   Number  g       绿色色值
- * @param   Number  b       蓝色色值
  * @return  String          类似#ff00ff
+ * @param r
+ * @param g
+ * @param b
  */
 export const rgbToHex = function (r: number, g: number, b: number) {
   // tslint:disable-next-line:no-bitwise

+ 0 - 4
src/utils/env.ts

@@ -17,7 +17,6 @@ export const prodMode = 'production';
 
 /**
  * @description: 获取环境变量
- * @param {type}
  * @returns:
  * @example:
  */
@@ -25,7 +24,6 @@ export const getEnv = (): string => import.meta.env.MODE;
 
 /**
  * @description: 是否是开发模式
- * @param {type}
  * @returns:
  * @example:
  */
@@ -33,7 +31,6 @@ export const isDevMode = (): boolean => import.meta.env.DEV;
 
 /**
  * @description: 是否是生产模式模式
- * @param {type}
  * @returns:
  * @example:
  */
@@ -41,7 +38,6 @@ export const isProdMode = (): boolean => import.meta.env.PROD;
 
 /**
  * @description: 是否开启mock
- * @param {type}
  * @returns:
  * @example:
  */

+ 2 - 2
src/utils/helper/menuHelper.ts

@@ -1,4 +1,4 @@
-import { AppRouteModule } from '/@/router/types.d';
+import { AppRouteModule, RouteModule } from '/@/router/types.d';
 import type { MenuModule, Menu, AppRouteRecordRaw } from '/@/router/types';
 
 import { findPath, forEach, treeMap, treeToList } from './treeHelper';
@@ -48,7 +48,7 @@ export function transformRouteToMenu(routeModList: AppRouteModule[]) {
   const cloneRouteModList = cloneDeep(routeModList);
   const routeList: AppRouteRecordRaw[] = [];
   cloneRouteModList.forEach((item) => {
-    const { layout, routes, children } = item;
+    const { layout, routes, children } = item as RouteModule;
     if (layout) {
       layout.children = routes || children;
       routeList.push(layout);

+ 1 - 1
src/utils/helper/persistent.ts

@@ -1,4 +1,4 @@
-import { createStorage } from '/@/utils/storage/index';
+import { createStorage } from '/@/utils/storage';
 import { isIeFn } from '/@/utils/browser';
 
 import { BASE_LOCAL_CACHE_KEY, BASE_SESSION_CACHE_KEY } from '/@/enums/cacheEnum';

+ 22 - 16
src/utils/helper/routeHelper.ts

@@ -1,9 +1,9 @@
-import type { AppRouteModule, AppRouteRecordRaw } from '/@/router/types';
+import type { AppRouteModule, AppRouteRecordRaw, RouteModule } from '/@/router/types';
 import type { RouteLocationNormalized, RouteRecordRaw } from 'vue-router';
+import { createRouter, createWebHashHistory } from 'vue-router';
 
 import { appStore } from '/@/store/modules/app';
 import { tabStore } from '/@/store/modules/tab';
-import { createRouter, createWebHashHistory } from 'vue-router';
 import { toRaw } from 'vue';
 import { PAGE_LAYOUT_COMPONENT } from '/@/router/constant';
 // import { isDevMode } from '/@/utils/env';
@@ -21,17 +21,17 @@ export function setCurrentTo(to: RouteLocationNormalized) {
 }
 // 转化路由模块
 // 将多级转成2层。keepAlive问题
-export function genRouteModule(moduleList: AppRouteModule[]) {
+export function genRouteModule(moduleList: AppRouteModule[] | AppRouteRecordRaw[]) {
   const ret: AppRouteRecordRaw[] = [];
   for (const routeMod of moduleList) {
-    let routes = [];
+    let routes: RouteRecordRaw[] = [];
     let layout: AppRouteRecordRaw | undefined;
     if (Reflect.has(routeMod, 'routes')) {
-      routes = routeMod.routes as any;
-      layout = routeMod.layout;
+      routes = (routeMod as RouteModule).routes as any;
+      layout = (routeMod as RouteModule).layout;
     } else if (Reflect.has(routeMod, 'path')) {
       layout = omit(routeMod, 'children') as any;
-      routes = routeMod.children || [];
+      routes = (routeMod.children as RouteRecordRaw[]) || ([] as RouteRecordRaw[]);
     }
 
     const router = createRouter({ routes, history: createWebHashHistory() });
@@ -66,20 +66,26 @@ function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) {
   });
 }
 
+function getLayoutComp(comp: string) {
+  return comp === 'PAGE_LAYOUT' ? PAGE_LAYOUT_COMPONENT : '';
+}
+
 // 将后台对象转成路由对象
-export function transformObjToRoute(routeList: AppRouteModule[]) {
+export function transformObjToRoute<T = any>(routeList: AppRouteModule[]): T[] {
   routeList.forEach((route) => {
-    asyncImportRoute(Reflect.has(route, 'routes') ? route.routes : route.children || []);
-    if (route.layout) {
-      route.layout.component =
-        route.layout.component === 'PAGE_LAYOUT' ? PAGE_LAYOUT_COMPONENT : '';
+    asyncImportRoute(
+      Reflect.has(route, 'routes') ? (route as RouteModule).routes : route.children || []
+    );
+    if ((route as RouteModule).layout) {
+      (route as RouteModule).layout.component = getLayoutComp(
+        (route as RouteModule).layout.component
+      );
     } else {
-      route.component = route.component === 'PAGE_LAYOUT' ? PAGE_LAYOUT_COMPONENT : '';
-      const _layout = omit(route, 'children') as any;
-      route.layout = _layout;
+      route.component = getLayoutComp(route.component);
+      (route as RouteModule).layout = omit(route, 'children') as any;
     }
   });
-  return routeList;
+  return (routeList as unknown) as T[];
 }
 
 //

+ 1 - 0
src/utils/helper/tsxHelper.tsx

@@ -20,6 +20,7 @@ export function getSlot(slots: Slots, slot = 'default', data?: any) {
 /**
  * extends slots
  * @param slots
+ * @param excludeKeys
  */
 export function extendSlots(slots: Slots, excludeKeys: string[] = []) {
   const slotKeys = Object.keys(slots);

+ 1 - 1
src/utils/http/axios/Axios.ts

@@ -17,7 +17,7 @@ export * from './axiosTransform';
  */
 export class VAxios {
   private axiosInstance: AxiosInstance;
-  private options: CreateAxiosOptions;
+  private readonly options: CreateAxiosOptions;
 
   constructor(options: CreateAxiosOptions) {
     this.options = options;

+ 1 - 1
src/utils/storage/Storage.ts

@@ -92,7 +92,7 @@ export const createStorage = ({ prefixKey = '', storage = sessionStorage } = {})
      * 添加cookie
      * @param name cookie名字
      * @param value cookie内容
-     * @param day 过期时间
+     * @param expire
      * 如果过期时间未设置,默认管理浏览器自动删除
      * 例子:
      *  cookieData.set('name','value',)

+ 1 - 1
src/utils/uuid.ts

@@ -10,7 +10,7 @@ export function buildUUID(): string {
     } else if (i === 15) {
       uuid += 4;
     } else if (i === 20) {
-      uuid += hexList[(Math.random() * 4) | (0 + 8)];
+      uuid += hexList[(Math.random() * 4) | 8];
     } else {
       uuid += hexList[(Math.random() * 16) | 0];
     }