From fa6b42e1dae90f2569b8052e9bbaeffc266947c9 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Thu, 4 Aug 2022 12:04:42 +0800 Subject: [PATCH] refactor: plugin settings page form Signed-off-by: Ryan Wang --- packages/shared/src/composables/index.ts | 1 + .../src}/composables/use-setting-form.ts | 9 +- packages/shared/src/index.ts | 1 + packages/shared/src/layouts/PluginLayout.vue | 132 ++++++++++------- src/modules/interface/themes/ThemeSetting.vue | 2 +- .../interface/themes/layouts/ThemeLayout.vue | 3 +- src/modules/system/plugins/PluginSetting.vue | 133 ++++-------------- 7 files changed, 114 insertions(+), 167 deletions(-) create mode 100644 packages/shared/src/composables/index.ts rename {src => packages/shared/src}/composables/use-setting-form.ts (94%) diff --git a/packages/shared/src/composables/index.ts b/packages/shared/src/composables/index.ts new file mode 100644 index 00000000..dccb74e7 --- /dev/null +++ b/packages/shared/src/composables/index.ts @@ -0,0 +1 @@ +export { useSettingForm } from "./use-setting-form"; diff --git a/src/composables/use-setting-form.ts b/packages/shared/src/composables/use-setting-form.ts similarity index 94% rename from src/composables/use-setting-form.ts rename to packages/shared/src/composables/use-setting-form.ts index 4f8c51aa..2768ed34 100644 --- a/src/composables/use-setting-form.ts +++ b/packages/shared/src/composables/use-setting-form.ts @@ -1,16 +1,13 @@ // core libs import { ref } from "vue"; -import { apiClient } from "@halo-dev/admin-shared"; +import { apiClient } from "../utils/api-client"; // libs import cloneDeep from "lodash.clonedeep"; // types import type { Ref } from "vue"; -import type { - FormKitSetting, - FormKitSettingSpec, -} from "@halo-dev/admin-shared"; +import type { FormKitSetting, FormKitSettingSpec } from "../types/formkit"; import type { ConfigMap } from "@halo-dev/api-client"; const initialConfigMap: ConfigMap = { @@ -64,6 +61,7 @@ export function useSettingForm( if (data) { configMapFormData.value = Object.keys(data).reduce((acc, key) => { + // @ts-ignore acc[key] = JSON.parse(data[key]); return acc; }, {}); @@ -73,6 +71,7 @@ export function useSettingForm( } finally { if (!configMapFormData.value) { configMapFormData.value = settings.value?.spec.reduce((acc, item) => { + // @ts-ignore acc[item.group] = {}; return acc; }, {}); diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 65c7a8b1..d5477e4b 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -6,3 +6,4 @@ export * from "./states/pages"; export * from "./layouts"; export * from "./utils/api-client"; +export * from "./composables"; diff --git a/packages/shared/src/layouts/PluginLayout.vue b/packages/shared/src/layouts/PluginLayout.vue index a1f46a92..98347c0e 100644 --- a/packages/shared/src/layouts/PluginLayout.vue +++ b/packages/shared/src/layouts/PluginLayout.vue @@ -1,25 +1,34 @@ diff --git a/src/modules/interface/themes/ThemeSetting.vue b/src/modules/interface/themes/ThemeSetting.vue index fd3024c5..bdebdfe6 100644 --- a/src/modules/interface/themes/ThemeSetting.vue +++ b/src/modules/interface/themes/ThemeSetting.vue @@ -10,7 +10,7 @@ import type { Ref } from "vue"; import type { Theme } from "@halo-dev/api-client"; // hooks -import { useSettingForm } from "@/composables/use-setting-form"; +import { useSettingForm } from "@halo-dev/admin-shared"; const selectedTheme = inject>("selectedTheme", ref({} as Theme)); const group = inject>("activeTab"); diff --git a/src/modules/interface/themes/layouts/ThemeLayout.vue b/src/modules/interface/themes/layouts/ThemeLayout.vue index bcdaeddc..eb766a7f 100644 --- a/src/modules/interface/themes/layouts/ThemeLayout.vue +++ b/src/modules/interface/themes/layouts/ThemeLayout.vue @@ -8,7 +8,7 @@ import cloneDeep from "lodash.clonedeep"; // hooks import { useThemeLifeCycle } from "../composables/use-theme"; -import { useSettingForm } from "@/composables/use-setting-form"; +import { useSettingForm } from "@halo-dev/admin-shared"; // components import { @@ -122,7 +122,6 @@ const onTabChange = (routeName: string) => { return; } - // @ts-ignore const tab = tabs.value.find((tab) => tab.route.name === route.name); activeTab.value = tab ? tab.id : tabs.value[0].id; }; diff --git a/src/modules/system/plugins/PluginSetting.vue b/src/modules/system/plugins/PluginSetting.vue index c274d1d6..54a0e902 100644 --- a/src/modules/system/plugins/PluginSetting.vue +++ b/src/modules/system/plugins/PluginSetting.vue @@ -1,131 +1,54 @@