From 34cf4d6215cb6891f6158b09e0b71b29bf4c2a0e Mon Sep 17 00:00:00 2001 From: Kirk Lin Date: Wed, 3 Jul 2024 15:58:11 +0800 Subject: [PATCH] chore: fix hooks, styles, directives deps --- apps/admin/autoResolver/auto-imports.d.ts | 3 -- .../dashboard/components/DataOverview.vue | 8 ++-- .../dashboard/components/UserAnalysisItem.vue | 6 ++- .../AuthForm/components/ForgotPassword.vue | 6 +-- .../src/store/modules/design/themeUtils.ts | 2 +- .../admin/src/store/modules/design/types.ts | 0 .../vite/src/plugins/unpluginAutoImport.ts | 1 - packages/web/CAComponents/package.json | 21 ++++++++-- packages/web/CAComponents/tsconfig.json | 23 ++++++++++ packages/web/CAComponents/tsup.config.ts | 10 +++++ packages/web/components/index.ts | 4 +- packages/web/components/package.json | 4 +- .../components/{ => src}/Application/index.ts | 0 .../{ => src}/Application/src/AppLogo.vue | 0 .../Application/src/AppNaiveUIProvider.vue | 0 .../web/components/{ => src}/Charts/index.ts | 0 .../{ => src}/Charts/src/Charts.vue | 0 .../{ => src}/Charts/src/vueEchartsChunk.ts | 0 .../{ => src}/Charts/types/echarts.ts | 0 .../web/components/{ => src}/Icon/index.ts | 0 .../components/{ => src}/Icon/src/Icon.vue | 0 .../components/{ => src}/Icon/src/utils.ts | 0 packages/web/components/src/index.ts | 3 ++ packages/web/constants/package.json | 18 ++++++-- .../constants/src/utils/defineConstants.ts | 3 +- packages/web/constants/tsconfig.json | 22 ++++++++++ packages/web/constants/tsup.config.ts | 9 ++++ packages/web/directives/tsup.config.ts | 2 +- packages/web/hooks/src/index.ts | 1 - packages/web/hooks/src/types.ts | 2 + packages/web/hooks/src/useLoading.ts | 13 ------ packages/web/hooks/src/useState.ts | 26 +++++++++--- packages/web/hooks/tsup.config.ts | 2 +- packages/web/locale/package.json | 15 ++++++- packages/web/locale/tsconfig.json | 23 ++++++++++ packages/web/locale/tsup.config.ts | 10 +++++ packages/web/types/src/config.ts | 3 +- packages/web/types/src/index.ts | 1 - packages/web/utils/src/cipher.ts | 42 ++++++++----------- packages/web/utils/tsup.config.ts | 2 +- pnpm-lock.yaml | 3 -- 41 files changed, 206 insertions(+), 82 deletions(-) rename packages/web/types/src/theme.ts => apps/admin/src/store/modules/design/types.ts (100%) create mode 100644 packages/web/CAComponents/tsconfig.json create mode 100644 packages/web/CAComponents/tsup.config.ts rename packages/web/components/{ => src}/Application/index.ts (100%) rename packages/web/components/{ => src}/Application/src/AppLogo.vue (100%) rename packages/web/components/{ => src}/Application/src/AppNaiveUIProvider.vue (100%) rename packages/web/components/{ => src}/Charts/index.ts (100%) rename packages/web/components/{ => src}/Charts/src/Charts.vue (100%) rename packages/web/components/{ => src}/Charts/src/vueEchartsChunk.ts (100%) rename packages/web/components/{ => src}/Charts/types/echarts.ts (100%) rename packages/web/components/{ => src}/Icon/index.ts (100%) rename packages/web/components/{ => src}/Icon/src/Icon.vue (100%) rename packages/web/components/{ => src}/Icon/src/utils.ts (100%) create mode 100644 packages/web/components/src/index.ts create mode 100644 packages/web/constants/tsconfig.json create mode 100644 packages/web/constants/tsup.config.ts create mode 100644 packages/web/hooks/src/types.ts delete mode 100644 packages/web/hooks/src/useLoading.ts create mode 100644 packages/web/locale/tsconfig.json create mode 100644 packages/web/locale/tsup.config.ts diff --git a/apps/admin/autoResolver/auto-imports.d.ts b/apps/admin/autoResolver/auto-imports.d.ts index e0e66b3b..04390b38 100644 --- a/apps/admin/autoResolver/auto-imports.d.ts +++ b/apps/admin/autoResolver/auto-imports.d.ts @@ -197,7 +197,6 @@ declare global { const useKeyModifier: typeof import('@vueuse/core')['useKeyModifier'] const useLastChanged: typeof import('@vueuse/core')['useLastChanged'] const useLink: typeof import('vue-router')['useLink'] - const useLoading: typeof import('@celeris/hooks')['useLoading'] const useLoadingBar: typeof import('@celeris/ca-components')['useLoadingBar'] const useLocalStorage: typeof import('@vueuse/core')['useLocalStorage'] const useMagicKeys: typeof import('@vueuse/core')['useMagicKeys'] @@ -510,7 +509,6 @@ declare module 'vue' { readonly useKeyModifier: UnwrapRef readonly useLastChanged: UnwrapRef readonly useLink: UnwrapRef - readonly useLoading: UnwrapRef readonly useLoadingBar: UnwrapRef readonly useLocalStorage: UnwrapRef readonly useMagicKeys: UnwrapRef @@ -816,7 +814,6 @@ declare module '@vue/runtime-core' { readonly useKeyModifier: UnwrapRef readonly useLastChanged: UnwrapRef readonly useLink: UnwrapRef - readonly useLoading: UnwrapRef readonly useLoadingBar: UnwrapRef readonly useLocalStorage: UnwrapRef readonly useMagicKeys: UnwrapRef diff --git a/apps/admin/src/pages/dashboard/components/DataOverview.vue b/apps/admin/src/pages/dashboard/components/DataOverview.vue index 370da557..0312e83f 100644 --- a/apps/admin/src/pages/dashboard/components/DataOverview.vue +++ b/apps/admin/src/pages/dashboard/components/DataOverview.vue @@ -50,7 +50,7 @@ function generateSeries(name: string, lineColor: string, itemBorderColor: string }, }; } -const { loading, setLoading } = useLoading(true); +const loading = ref(true); const { getDarkMode } = useThemeSetting(); const renderData = computed(() => [ { @@ -222,7 +222,7 @@ const { chartOption } = useChartOption((isDark: boolean) => { }; }); async function fetchData() { - setLoading(true); + loading.value = true; try { const data = await queryDataOverview(); xAxis.value = data.xAxis; @@ -237,9 +237,9 @@ async function fetchData() { likedResponsesData.value = el.value; }); } catch (err) { - setLoading(false); + loading.value = false; } finally { - setLoading(false); + loading.value = false; } } fetchData(); diff --git a/apps/admin/src/pages/dashboard/components/UserAnalysisItem.vue b/apps/admin/src/pages/dashboard/components/UserAnalysisItem.vue index 9bc86578..0e9a578c 100644 --- a/apps/admin/src/pages/dashboard/components/UserAnalysisItem.vue +++ b/apps/admin/src/pages/dashboard/components/UserAnalysisItem.vue @@ -25,7 +25,7 @@ const props = defineProps({ }, }); -const { loading, setLoading } = useLoading(true); +const loading = ref(true); const count = ref(); const growth = ref(100); const chartData = ref([]); @@ -83,6 +83,7 @@ const { chartOption } = useChartOption(() => { }; }); async function fetchData(params: { quota: string }) { + loading.value = true; try { const data = await queryUserAnalysisData(params); const { chartData: resChartData } = data; @@ -102,8 +103,9 @@ async function fetchData(params: { quota: string }) { }); } catch (err) { // you can report use errorHandler or other + loading.value = false; } finally { - setLoading(false); + loading.value = false; } } fetchData({ quota: props.quota }); diff --git a/apps/admin/src/pages/login/components/AuthForm/components/ForgotPassword.vue b/apps/admin/src/pages/login/components/AuthForm/components/ForgotPassword.vue index 8100e42c..c654b715 100644 --- a/apps/admin/src/pages/login/components/AuthForm/components/ForgotPassword.vue +++ b/apps/admin/src/pages/login/components/AuthForm/components/ForgotPassword.vue @@ -16,7 +16,7 @@ import type { ForgotPasswordFromType } from "~/pages/login/types"; const { t } = useI18n(); const formRef = ref(null); const message = useMessage(); -const { loading, setLoading } = useLoading(false); +const loading = ref(true); const model = ref({ phoneNumber: "", }); @@ -37,9 +37,9 @@ const rules: FormRules = { function forgotPassword(e: Event) { e.preventDefault(); - setLoading(true); + loading.value = true; formRef.value?.validate((errors: Array | undefined) => { - setLoading(false); + loading.value = false; if (!errors) { message.success(t("page.login.form.resetLinkSentMessage")); } diff --git a/apps/admin/src/store/modules/design/themeUtils.ts b/apps/admin/src/store/modules/design/themeUtils.ts index 9b0b3cb9..1c15a2f4 100644 --- a/apps/admin/src/store/modules/design/themeUtils.ts +++ b/apps/admin/src/store/modules/design/themeUtils.ts @@ -1,6 +1,6 @@ -import type { ButtonColorScene, ColorAction, ColorType, ColorTypeCase, ThemeColor, ThemeConfig } from "@celeris/types"; import { deepMerge, generateColorPalettes } from "@celeris/utils"; import { type GlobalThemeOverrides, commonDark, commonLight } from "naive-ui"; +import type { ButtonColorScene, ColorAction, ColorType, ColorTypeCase, ThemeColor, ThemeConfig } from "./types"; /** * 将字符串的第一个字符大写 diff --git a/packages/web/types/src/theme.ts b/apps/admin/src/store/modules/design/types.ts similarity index 100% rename from packages/web/types/src/theme.ts rename to apps/admin/src/store/modules/design/types.ts diff --git a/packages/shared/vite/src/plugins/unpluginAutoImport.ts b/packages/shared/vite/src/plugins/unpluginAutoImport.ts index 8e3f7f3a..aadac75b 100644 --- a/packages/shared/vite/src/plugins/unpluginAutoImport.ts +++ b/packages/shared/vite/src/plugins/unpluginAutoImport.ts @@ -20,7 +20,6 @@ export function createAutoImportPluginConfig(): PluginOption { { "@celeris/hooks": [ "useComponentRef", - "useLoading", "useMergeState", "useScreen", "useState", diff --git a/packages/web/CAComponents/package.json b/packages/web/CAComponents/package.json index e0a0baaa..e12a0ea2 100644 --- a/packages/web/CAComponents/package.json +++ b/packages/web/CAComponents/package.json @@ -6,13 +6,26 @@ "author": "Kirk Lin (https://github.com/kirklin)", "license": "MIT", "homepage": "https://github.com/kirklin/celeris-web", - "main": "index.ts", - "module": "index.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.cjs" + } + }, + "main": "./index.ts", + "module": "./index.ts", + "types": "./dist/index.d.ts", "scripts": { - "clean": "pnpm rimraf node_modules && pnpm rimraf dist" + "build": "tsup", + "dev": "tsup --stub", + "clean": "pnpm rimraf node_modules && pnpm rimraf dist", + "prepublishOnly": "npm run build", + "postinstall": "npm run build" }, "peerDependencies": { - "vue": "^3.3.4" + "naive-ui": ">=2.38.2", + "vue": ">=3.3.4" }, "dependencies": {}, "devDependencies": { diff --git a/packages/web/CAComponents/tsconfig.json b/packages/web/CAComponents/tsconfig.json new file mode 100644 index 00000000..c347ae3e --- /dev/null +++ b/packages/web/CAComponents/tsconfig.json @@ -0,0 +1,23 @@ +{ + "extends": "@celeris/tsconfig/tsconfig.base.json", + "compilerOptions": { + "target": "esnext", + "lib": [ + "esnext", + "dom" + ], + "baseUrl": ".", + "module": "esnext", + "moduleResolution": "Node", + "strict": true, + "sourceMap": false, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true + }, + "include": [ + "index.ts" + ], + "exclude": [ + "node_modules" + ] +} diff --git a/packages/web/CAComponents/tsup.config.ts b/packages/web/CAComponents/tsup.config.ts new file mode 100644 index 00000000..241bbe3e --- /dev/null +++ b/packages/web/CAComponents/tsup.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: ["./index.ts"], + clean: true, + format: ["esm", "cjs"], + external: ["vue"], + dts: true, + minify: true, +}); diff --git a/packages/web/components/index.ts b/packages/web/components/index.ts index d19f7ea8..3bd16e17 100644 --- a/packages/web/components/index.ts +++ b/packages/web/components/index.ts @@ -1,3 +1 @@ -export * from "./Application"; -export * from "./Icon"; -export * from "./Charts"; +export * from "./src"; diff --git a/packages/web/components/package.json b/packages/web/components/package.json index ff62461b..9a4614b2 100644 --- a/packages/web/components/package.json +++ b/packages/web/components/package.json @@ -6,8 +6,8 @@ "author": "Kirk Lin (https://github.com/kirklin)", "license": "MIT", "homepage": "https://github.com/kirklin/celeris-web", - "main": "index.ts", - "module": "index.ts", + "main": "./index.ts", + "module": "./index.ts", "scripts": { "clean": "pnpm rimraf node_modules && pnpm rimraf dist" }, diff --git a/packages/web/components/Application/index.ts b/packages/web/components/src/Application/index.ts similarity index 100% rename from packages/web/components/Application/index.ts rename to packages/web/components/src/Application/index.ts diff --git a/packages/web/components/Application/src/AppLogo.vue b/packages/web/components/src/Application/src/AppLogo.vue similarity index 100% rename from packages/web/components/Application/src/AppLogo.vue rename to packages/web/components/src/Application/src/AppLogo.vue diff --git a/packages/web/components/Application/src/AppNaiveUIProvider.vue b/packages/web/components/src/Application/src/AppNaiveUIProvider.vue similarity index 100% rename from packages/web/components/Application/src/AppNaiveUIProvider.vue rename to packages/web/components/src/Application/src/AppNaiveUIProvider.vue diff --git a/packages/web/components/Charts/index.ts b/packages/web/components/src/Charts/index.ts similarity index 100% rename from packages/web/components/Charts/index.ts rename to packages/web/components/src/Charts/index.ts diff --git a/packages/web/components/Charts/src/Charts.vue b/packages/web/components/src/Charts/src/Charts.vue similarity index 100% rename from packages/web/components/Charts/src/Charts.vue rename to packages/web/components/src/Charts/src/Charts.vue diff --git a/packages/web/components/Charts/src/vueEchartsChunk.ts b/packages/web/components/src/Charts/src/vueEchartsChunk.ts similarity index 100% rename from packages/web/components/Charts/src/vueEchartsChunk.ts rename to packages/web/components/src/Charts/src/vueEchartsChunk.ts diff --git a/packages/web/components/Charts/types/echarts.ts b/packages/web/components/src/Charts/types/echarts.ts similarity index 100% rename from packages/web/components/Charts/types/echarts.ts rename to packages/web/components/src/Charts/types/echarts.ts diff --git a/packages/web/components/Icon/index.ts b/packages/web/components/src/Icon/index.ts similarity index 100% rename from packages/web/components/Icon/index.ts rename to packages/web/components/src/Icon/index.ts diff --git a/packages/web/components/Icon/src/Icon.vue b/packages/web/components/src/Icon/src/Icon.vue similarity index 100% rename from packages/web/components/Icon/src/Icon.vue rename to packages/web/components/src/Icon/src/Icon.vue diff --git a/packages/web/components/Icon/src/utils.ts b/packages/web/components/src/Icon/src/utils.ts similarity index 100% rename from packages/web/components/Icon/src/utils.ts rename to packages/web/components/src/Icon/src/utils.ts diff --git a/packages/web/components/src/index.ts b/packages/web/components/src/index.ts new file mode 100644 index 00000000..d19f7ea8 --- /dev/null +++ b/packages/web/components/src/index.ts @@ -0,0 +1,3 @@ +export * from "./Application"; +export * from "./Icon"; +export * from "./Charts"; diff --git a/packages/web/constants/package.json b/packages/web/constants/package.json index 07f91577..967cabc6 100644 --- a/packages/web/constants/package.json +++ b/packages/web/constants/package.json @@ -6,10 +6,22 @@ "author": "Kirk Lin (https://github.com/kirklin)", "license": "MIT", "homepage": "https://github.com/kirklin/celeris-web", - "main": "index.ts", - "module": "index.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.cjs" + } + }, + "main": "./index.ts", + "module": "./index.ts", + "types": "./dist/index.d.ts", "scripts": { - "clean": "pnpm rimraf node_modules && pnpm rimraf dist" + "build": "tsup", + "dev": "tsup --stub", + "clean": "pnpm rimraf node_modules && pnpm rimraf dist", + "prepublishOnly": "npm run build", + "postinstall": "npm run build" }, "dependencies": { "lodash.pick": "4.4.0" diff --git a/packages/web/constants/src/utils/defineConstants.ts b/packages/web/constants/src/utils/defineConstants.ts index ba5ef524..6398e0df 100644 --- a/packages/web/constants/src/utils/defineConstants.ts +++ b/packages/web/constants/src/utils/defineConstants.ts @@ -1,4 +1,5 @@ -import pick from "lodash/pick"; +// eslint-disable-next-line ts/no-require-imports,ts/no-var-requires +const pick = require("lodash/pick.js"); /** * Utility function to determine the raw type of a value. diff --git a/packages/web/constants/tsconfig.json b/packages/web/constants/tsconfig.json new file mode 100644 index 00000000..02a42abd --- /dev/null +++ b/packages/web/constants/tsconfig.json @@ -0,0 +1,22 @@ +{ + "extends": "@celeris/tsconfig/tsconfig.base.json", + "compilerOptions": { + "target": "esnext", + "lib": [ + "esnext", + "dom" + ], + "baseUrl": ".", + "module": "esnext", + "strict": true, + "sourceMap": false, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true + }, + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules" + ] +} diff --git a/packages/web/constants/tsup.config.ts b/packages/web/constants/tsup.config.ts new file mode 100644 index 00000000..4a2534c9 --- /dev/null +++ b/packages/web/constants/tsup.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: ["./index.ts"], + clean: true, + format: ["esm", "cjs"], + dts: true, + minify: true, +}); diff --git a/packages/web/directives/tsup.config.ts b/packages/web/directives/tsup.config.ts index d41731d6..241bbe3e 100644 --- a/packages/web/directives/tsup.config.ts +++ b/packages/web/directives/tsup.config.ts @@ -3,7 +3,7 @@ import { defineConfig } from "tsup"; export default defineConfig({ entry: ["./index.ts"], clean: true, - format: ["esm", "cjs", "iife"], + format: ["esm", "cjs"], external: ["vue"], dts: true, minify: true, diff --git a/packages/web/hooks/src/index.ts b/packages/web/hooks/src/index.ts index 78a9c666..1022984e 100644 --- a/packages/web/hooks/src/index.ts +++ b/packages/web/hooks/src/index.ts @@ -1,5 +1,4 @@ export * from "./useComponentRef"; -export * from "./useLoading"; export * from "./useMergeState"; export * from "./useScreen"; export * from "./useState"; diff --git a/packages/web/hooks/src/types.ts b/packages/web/hooks/src/types.ts new file mode 100644 index 00000000..362157e5 --- /dev/null +++ b/packages/web/hooks/src/types.ts @@ -0,0 +1,2 @@ +export type BasicStateAction = ((state: S) => S) | S; +export type Dispatch = (action: A) => void; diff --git a/packages/web/hooks/src/useLoading.ts b/packages/web/hooks/src/useLoading.ts deleted file mode 100644 index 7b107771..00000000 --- a/packages/web/hooks/src/useLoading.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { Ref } from "vue"; -import { ref } from "vue"; - -export function useLoading(initValue = false): { loading: Ref; setLoading: (loadingValue: boolean) => void } { - const loading = ref(initValue); - const setLoading = (loadingValue: boolean) => { - loading.value = loadingValue; - }; - return { - loading, - setLoading, - }; -} diff --git a/packages/web/hooks/src/useState.ts b/packages/web/hooks/src/useState.ts index a7d3f53d..f6b6bbba 100644 --- a/packages/web/hooks/src/useState.ts +++ b/packages/web/hooks/src/useState.ts @@ -1,11 +1,27 @@ import type { Ref } from "vue"; import { ref } from "vue"; +import { isFunction } from "@celeris/utils"; +import type { BasicStateAction, Dispatch } from "./types"; -export function useState(defaultValue?: T): [Ref, (newValue: T) => void] { - const value = ref(defaultValue) as Ref; - const setValue = (newValue: T) => { - value.value = newValue; +export function useState( + initialState?: (() => S) | S, +): [Ref, Dispatch>] { + // "vue useState is use customRef to simulation.; + + let state = initialState; + if (isFunction(initialState)) { + state = initialState(); + } + + const reactiveState = ref(state) as Ref; + + const dispatchAction = (actionOrState: ((prevState: S) => S) | S) => { + if (isFunction(actionOrState)) { + reactiveState.value = actionOrState(reactiveState.value); + } else { + reactiveState.value = actionOrState; + } }; - return [value, setValue]; + return [reactiveState, dispatchAction]; } diff --git a/packages/web/hooks/tsup.config.ts b/packages/web/hooks/tsup.config.ts index d41731d6..241bbe3e 100644 --- a/packages/web/hooks/tsup.config.ts +++ b/packages/web/hooks/tsup.config.ts @@ -3,7 +3,7 @@ import { defineConfig } from "tsup"; export default defineConfig({ entry: ["./index.ts"], clean: true, - format: ["esm", "cjs", "iife"], + format: ["esm", "cjs"], external: ["vue"], dts: true, minify: true, diff --git a/packages/web/locale/package.json b/packages/web/locale/package.json index 103f958f..8c6d5893 100644 --- a/packages/web/locale/package.json +++ b/packages/web/locale/package.json @@ -6,15 +6,26 @@ "author": "Kirk Lin (https://github.com/kirklin)", "license": "MIT", "homepage": "https://github.com/kirklin/celeris-web", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.cjs" + } + }, "main": "./index.ts", "module": "./index.ts", + "types": "./dist/index.d.ts", "scripts": { - "clean": "pnpm rimraf node_modules && pnpm rimraf dist" + "build": "tsup", + "dev": "tsup --stub", + "clean": "pnpm rimraf node_modules && pnpm rimraf dist", + "prepublishOnly": "npm run build", + "postinstall": "npm run build" }, "dependencies": { "@celeris/constants": "workspace:*", "@celeris/hooks": "workspace:*", - "@celeris/types": "workspace:*", "@celeris/utils": "workspace:*", "iso-639-1": "^3.1.2", "vue": "^3.4.30", diff --git a/packages/web/locale/tsconfig.json b/packages/web/locale/tsconfig.json new file mode 100644 index 00000000..33d54879 --- /dev/null +++ b/packages/web/locale/tsconfig.json @@ -0,0 +1,23 @@ +{ + "extends": "@celeris/tsconfig/tsconfig.base.json", + "compilerOptions": { + "target": "esnext", + "lib": [ + "esnext", + "dom" + ], + "baseUrl": ".", + "module": "esnext", + "moduleResolution": "Node", + "strict": true, + "sourceMap": false, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true + }, + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules" + ] +} diff --git a/packages/web/locale/tsup.config.ts b/packages/web/locale/tsup.config.ts new file mode 100644 index 00000000..241bbe3e --- /dev/null +++ b/packages/web/locale/tsup.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: ["./index.ts"], + clean: true, + format: ["esm", "cjs"], + external: ["vue"], + dts: true, + minify: true, +}); diff --git a/packages/web/types/src/config.ts b/packages/web/types/src/config.ts index becc5f1f..8e4cf03b 100644 --- a/packages/web/types/src/config.ts +++ b/packages/web/types/src/config.ts @@ -5,7 +5,6 @@ import type { SessionTimeoutProcessingConstants, SettingButtonPositionConstants, } from "@celeris/constants"; -import type { ThemeConfig } from "./theme"; export interface MenuSetting { collapsed: boolean; @@ -67,7 +66,7 @@ export interface ThemeSetting { // 其他主题颜色 // Other theme colors - otherColor: ThemeConfig; + otherColor: Record; } /** diff --git a/packages/web/types/src/index.ts b/packages/web/types/src/index.ts index 9c939b9e..d037b998 100644 --- a/packages/web/types/src/index.ts +++ b/packages/web/types/src/index.ts @@ -1,5 +1,4 @@ export * from "./config"; export * from "./global"; export * from "./menu"; -export * from "./theme"; export * from "./user"; diff --git a/packages/web/utils/src/cipher.ts b/packages/web/utils/src/cipher.ts index e108e12a..0910ef9f 100644 --- a/packages/web/utils/src/cipher.ts +++ b/packages/web/utils/src/cipher.ts @@ -1,11 +1,6 @@ -import { decrypt as aesDecrypt, encrypt as aesEncrypt } from "crypto-js/aes"; -import UTF8, { parse } from "crypto-js/enc-utf8"; -import pkcs7 from "crypto-js/pad-pkcs7"; -import CTR from "crypto-js/mode-ctr"; -import Base64 from "crypto-js/enc-base64"; -import MD5 from "crypto-js/md5"; -import SHA256 from "crypto-js/sha256"; -import SHA512 from "crypto-js/sha512"; +import CryptoJS from "crypto-js"; + +const { AES, enc, pad, mode, MD5, SHA256, SHA512 } = CryptoJS; // Define an interface for encryption // 定义一个加密器的接口 @@ -13,6 +8,7 @@ export interface Encryption { encrypt: (plainText: string) => string; decrypt: (cipherText: string) => string; } + // Define an interface for Hashing // 定义一个哈希算法的接口 export interface Hashing { @@ -29,24 +25,24 @@ class AesEncryption implements Encryption { private readonly iv; constructor({ key, iv }: EncryptionParams) { - this.key = parse(key); - this.iv = parse(iv); + this.key = enc.Utf8.parse(key); + this.iv = enc.Utf8.parse(iv); } get getOptions() { return { - mode: CTR, - padding: pkcs7, + mode: mode.CTR, + padding: pad.Pkcs7, iv: this.iv, }; } encrypt(plainText: string) { - return aesEncrypt(plainText, this.key, this.getOptions).toString(); + return AES.encrypt(plainText, this.key, this.getOptions).toString(); } decrypt(cipherText: string) { - return aesDecrypt(cipherText, this.key, this.getOptions).toString(UTF8); + return AES.decrypt(cipherText, this.key, this.getOptions).toString(enc.Utf8); } } @@ -54,8 +50,7 @@ class AesEncryption implements Encryption { class Base64Encryption implements Encryption { private static instance: Base64Encryption; - private constructor() { - } + private constructor() {} // Get the singleton instance // 获取单例实例 @@ -67,11 +62,11 @@ class Base64Encryption implements Encryption { } encrypt(plainText: string) { - return UTF8.parse(plainText).toString(Base64); + return enc.Utf8.parse(plainText).toString(enc.Base64); } decrypt(cipherText: string) { - return Base64.parse(cipherText).toString(UTF8); + return enc.Base64.parse(cipherText).toString(enc.Utf8); } } @@ -79,8 +74,7 @@ class Base64Encryption implements Encryption { class MD5Hashing implements Hashing { private static instance: MD5Hashing; - private constructor() { - } + private constructor() {} // Get the singleton instance // 获取单例实例 @@ -100,8 +94,7 @@ class MD5Hashing implements Hashing { class SHA256Hashing implements Hashing { private static instance: SHA256Hashing; - private constructor() { - } + private constructor() {} // Get the singleton instance // 获取单例实例 @@ -121,12 +114,11 @@ class SHA256Hashing implements Hashing { class SHA512Hashing implements Hashing { private static instance: SHA512Hashing; - private constructor() { - } + private constructor() {} // Get the singleton instance // 获取单例实例 - public static getInstance(): SHA256Hashing { + public static getInstance(): SHA512Hashing { if (!SHA512Hashing.instance) { SHA512Hashing.instance = new SHA512Hashing(); } diff --git a/packages/web/utils/tsup.config.ts b/packages/web/utils/tsup.config.ts index 61130f0d..1e0a958e 100644 --- a/packages/web/utils/tsup.config.ts +++ b/packages/web/utils/tsup.config.ts @@ -3,7 +3,7 @@ import { defineConfig } from "tsup"; export default defineConfig({ entry: ["src/index.ts"], clean: true, - format: ["esm", "cjs", "iife"], + format: ["esm", "cjs"], external: ["vue"], dts: true, minify: true, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 75cc8270..941ad2df 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -408,9 +408,6 @@ importers: '@celeris/hooks': specifier: workspace:* version: link:../hooks - '@celeris/types': - specifier: workspace:* - version: link:../types '@celeris/utils': specifier: workspace:* version: link:../utils