Переглянути джерело

规范优化代码(主要是类型声明),使之符合ts规范要求

夜鹰 7 місяців тому
батько
коміт
e5b8b1f11e

+ 3 - 0
Web/src/types/axios.d.ts

@@ -10,4 +10,7 @@ declare module 'axios' {
 		type?: string;
 		[key: string]: T;
 	}
+	export interface AxiosRequestConfig {
+		customCatch?: boolean;
+	}
 }

+ 7 - 5
Web/src/types/global.d.ts

@@ -1,12 +1,14 @@
 // 申明外部 npm 插件模块
 declare module 'vue-grid-layout';
+declare module 'vue-signature-pad';
+declare module 'vform3-builds';
 declare module 'qrcodejs2-fixes';
 declare module 'splitpanes';
 declare module 'js-cookie';
-declare module '@wangeditor/editor-for-vue';
-declare module 'js-table2excel';
-declare module 'qs';
-declare module 'sortablejs';
+//declare module '@wangeditor/editor-for-vue';
+//declare module 'js-table2excel';
+//declare module 'qs';
+//declare module 'sortablejs';
 declare module 'vue-plugin-hiprint';
 declare module 'vcrontab-3';
 
@@ -117,7 +119,7 @@ declare interface TableType<T = any> {
 }
 
 // 字典数据结构
-export interface DictItem {
+declare interface DictItem {
 	typeCode: string;
 	label: string;
 	value: string;

+ 30 - 2
Web/src/utils/arrayOperation.ts

@@ -23,7 +23,7 @@ export function judgementSameArr(newArr: unknown[] | string[], oldArr: string[])
  * @param b 要比较的对象二
  * @returns 相同返回 true,反之则反
  */
-export function isObjectValueEqual<T>(a: T, b: T): boolean {
+export function isObjectValueEqual<T extends Record<string, any>>(a: T, b: T): boolean {
 	if (!a || !b) return false;
 	let aProps = Object.getOwnPropertyNames(a);
 	let bProps = Object.getOwnPropertyNames(b);
@@ -43,11 +43,12 @@ export function isObjectValueEqual<T>(a: T, b: T): boolean {
 }
 
 /**
- * 数组、数组对象去重
+ * 原始实现:数组、数组对象去重
  * @param arr 数组内容
  * @param attr 需要去重的键值(数组对象)
  * @returns
  */
+/*
 export function removeDuplicate(arr: EmptyArrayType, attr?: string) {
 	if (!Object.keys(arr).length) {
 		return arr;
@@ -63,6 +64,33 @@ export function removeDuplicate(arr: EmptyArrayType, attr?: string) {
 		}
 	}
 }
+*/
+/**
+ * 优化后实现:数组、数组对象去重
+ * 支持普通数组和对象数组去重,类型安全,且兼容原有所有调用方式
+ * @param arr 数组内容
+ * @param attr 需要去重的键值(数组对象)
+ * @returns
+ */
+export function removeDuplicate<T>(arr: T[], attr?: string): T[] {
+	if (!arr.length) {
+		return arr;
+	} else {
+		if (attr) {
+			const obj: Record<string, boolean> = {};
+			return arr.reduce((cur: T[], item: T) => {
+				const key = (item as any)[attr];
+				if (key && !obj[key]) {
+					obj[key] = true;
+					cur.push(item);
+				}
+				return cur;
+			}, []);
+		} else {
+			return [...new Set(arr)];
+		}
+	}
+}
 
 /* 数组、对象深拷贝
  * @param value 需要拷贝内容

+ 1 - 1
Web/src/utils/authFunction.ts

@@ -1,6 +1,6 @@
 import { useUserInfo } from '/@/stores/userInfo';
 import { judgementSameArr } from '/@/utils/arrayOperation';
-import { resolveDirective, withDirectives } from 'vue';
+import { resolveDirective, withDirectives, VNode } from 'vue';
 
 /**
  * 单个权限验证

+ 2 - 2
Web/src/utils/getStyleSheets.ts

@@ -1,8 +1,8 @@
 import { nextTick } from 'vue';
 import * as svg from '@element-plus/icons-vue';
 // import 本地样式类名数组
-import { iconfonntClassList } from '/@/theme/iconfont/font_2298093_rnp72ifj3ba.ts';
-import { fontAwesomeClassList } from '/@/theme/font-awesome/font-awesome.ts';
+import { iconfonntClassList } from '/@/theme/iconfont/font_2298093_rnp72ifj3ba';
+import { fontAwesomeClassList } from '/@/theme/font-awesome/font-awesome';
 
 // 获取阿里字体图标
 const getAlicdnIconfont = () => {

+ 1 - 1
Web/src/utils/other.ts

@@ -6,7 +6,7 @@ import pinia from '/@/stores/index';
 import { storeToRefs } from 'pinia';
 import { useThemeConfig } from '/@/stores/themeConfig';
 import { i18n } from '/@/i18n/index';
-import { Local } from '/@/utils/storage';
+//import { Local } from '/@/utils/storage';
 import { verifyUrl } from '/@/utils/toolsValidate';
 
 // 引入组件

+ 1 - 1
Web/src/views/system/pos/index.vue

@@ -30,7 +30,7 @@
 				<el-table-column type="index" label="序号" width="55" align="center" />
 				<el-table-column prop="name" label="职位名称" align="center" show-overflow-tooltip />
 				<el-table-column prop="code" label="职位编码" align="center" show-overflow-tooltip />
-				<el-table-column prop="userList" label="在职人数" width="70" align="center" show-overflow-tooltip >
+				<el-table-column prop="userList" label="在职人数" width="100" align="center" show-overflow-tooltip >
 					<template #default="scope">{{ scope.row.userList?.length}}</template>
 				</el-table-column>
 				<el-table-column prop="userList" label="人员明细" width="120" align="center" show-overflow-tooltip >