From 420f29a272aa66bbb8f16933d8633b52d657ca56 Mon Sep 17 00:00:00 2001 From: IchliebedichZhu <54796446@qq.com> Date: Mon, 26 Feb 2024 19:35:43 +0000 Subject: [PATCH] feat: support typescript in util files --- src/main.ts | 6 +++--- src/utils/index.ts | 3 ++- src/utils/utils.ts | 15 ++++++++++----- src/utils/widgets/elementConfig.ts | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1e92767..5ef707c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,8 +2,8 @@ * @Author: ShawnPhang * @Date: 2022-03-03 14:13:16 * @Description: - * @LastEditors: ShawnPhang - * @LastEditTime: 2023-06-29 15:11:46 + * @LastEditors: Jeremy Yu + * @LastEditTime: 2024-02-26 17:54:00 */ import { createApp } from 'vue' import App from './App.vue' @@ -20,7 +20,7 @@ elementConfig.components.forEach((component) => { app.component(component.name, component) }) -elementConfig.plugins.forEach((plugin: any) => { +elementConfig.plugins.forEach((plugin) => { app.use(plugin) }) diff --git a/src/utils/index.ts b/src/utils/index.ts index 1ac267f..c274639 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -11,12 +11,13 @@ import * as utils from './utils' import _config from '@/config' import modules from './plugins/modules' import cssLoader from './plugins/cssLoader' +import type {App} from 'vue' /** * 全局组件方法 */ export default { - install(myVue: Type.Object) { + install(myVue: App) { /** 全局组件注册 */ modules(myVue) /** iconfont 注入 */ diff --git a/src/utils/utils.ts b/src/utils/utils.ts index d320598..d2de8de 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,6 +1,8 @@ import app_config from '@/config' export const config = app_config +type TComObj = Record + /** * 星期换算 * @param {String} 'YYYY-MM-DD' @@ -47,21 +49,24 @@ export const isInArray = (arr: Type.Object[], value: any) => { } return false } + /** 删除多个对象元素 */ -export const deleteSome = (obj: Type.Object, arr: string[]) => { +export const deleteSome = (obj: T, arr: string[]) => { arr.forEach((key) => { delete obj[key] }) - return obj + return obj as R extends T ? R : Partial } + /** 拾取对象元素 */ -export const pickSome = (obj: Type.Object, arr: string[]) => { - const newObj: Type.Object = {} +export const pickSome = (obj: T, arr: string[]) => { + const newObj: Record = {} arr.forEach((key) => { newObj[key] = obj[key] }) - return newObj + return newObj as R extends T ? R : Partial } + /** String长度 */ // export const getBLen = (str: string | any) => { // if (str === null) { diff --git a/src/utils/widgets/elementConfig.ts b/src/utils/widgets/elementConfig.ts index 14dff5a..147a654 100644 --- a/src/utils/widgets/elementConfig.ts +++ b/src/utils/widgets/elementConfig.ts @@ -169,7 +169,7 @@ const components = [ // ElUpload, ] -const plugins: any = [ +const plugins = [ ElInfiniteScroll, ElLoading, // ElMessage,