fix: type error

This commit is contained in:
vben
2020-11-12 22:20:15 +08:00
parent 21e0548e34
commit ecfb702b09
37 changed files with 83 additions and 73 deletions

View File

@@ -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

View File

@@ -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:
*/

View File

@@ -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);

View File

@@ -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';

View File

@@ -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[];
}
//

View File

@@ -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);

View File

@@ -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;

View File

@@ -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',)

View File

@@ -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];
}