From 7f006d13593104eb41d372d8b77f08b2a89f95f1 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Wed, 16 Sep 2026 00:15:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor(plugin):=20=E8=BF=81=E7=A7=BB=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=8F=92=E4=BB=B6=E9=80=BB=E8=BE=91=E5=88=B0=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=BB=84=E4=BB=B6=E5=B9=B6=E4=BC=98=E5=8C=96=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=96=87=E4=BC=A0=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 将plugin crud组件中的syncOnlinePlugins方法迁移到index.vue中 2. 把syncLoading和syncOnlinePlugins加入页面上下文传递给crud组件 3. 移除crud组件中冗余的syncLoading声明 4. 调整页面初始化调用顺序 --- .../src/views/sys/plugin/crud.tsx | 22 ++------------- .../src/views/sys/plugin/index.vue | 28 +++++++++++++++++-- packages/ui/certd-server/.env | 2 +- packages/ui/certd-server/src/configuration.ts | 1 + 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/packages/ui/certd-client/src/views/sys/plugin/crud.tsx b/packages/ui/certd-client/src/views/sys/plugin/crud.tsx index 2866d3fbd..07e023f34 100644 --- a/packages/ui/certd-client/src/views/sys/plugin/crud.tsx +++ b/packages/ui/certd-client/src/views/sys/plugin/crud.tsx @@ -19,6 +19,8 @@ import dayjs from "dayjs"; export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet { const { t } = useI18n(); const lastSyncTime = context.lastSyncTime; + const syncLoading = context.syncLoading; + const syncOnlinePlugins = context.syncOnlinePlugins; let lastType = ""; const pageRequest = async (query: UserPageQuery): Promise => { if (lastType && lastType != query?.query?.type) { @@ -66,7 +68,6 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat const settingStore = useSettingStore(); const pluginStore = usePluginStore(); - const syncLoading = ref(false); const upgradeAllLoading = ref(false); const syncButtonTitle = computed(() => { @@ -86,25 +87,6 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat return row.editable === true; } - async function syncOnlinePlugins(options?: { showSuccess?: boolean }) { - if (syncLoading.value) { - return; - } - syncLoading.value = true; - try { - await api.OnlinePluginSync(); - const setting = await api.OnlinePluginSetting(); - lastSyncTime.value = setting.lastSyncTime || Date.now(); - await pluginStore.reload(); - crudExpose.doRefresh(); - if (options?.showSuccess !== false) { - notification.success({ message: t("certd.onlinePluginSyncSuccess") }); - } - } finally { - syncLoading.value = false; - } - } - async function upgradeAllOnlinePlugins() { if (upgradeAllLoading.value) { return; diff --git a/packages/ui/certd-client/src/views/sys/plugin/index.vue b/packages/ui/certd-client/src/views/sys/plugin/index.vue index 5a9429ee0..ce386ec3a 100644 --- a/packages/ui/certd-client/src/views/sys/plugin/index.vue +++ b/packages/ui/certd-client/src/views/sys/plugin/index.vue @@ -25,16 +25,38 @@ import { useMounted } from "/@/use/use-mounted"; import { computed, onBeforeUnmount, onMounted, ref } from "vue"; import { usePluginStore } from "/@/store/plugin"; import { useFormDialog } from "/@/use/use-dialog"; +import { notification } from "ant-design-vue"; import * as api from "./api"; const { t } = useI18n(); const pluginStore = usePluginStore(); const { openFormDialog } = useFormDialog(); const lastSyncTime = ref(0); +const syncLoading = ref(false); const autoSyncInterval = 3 * 24 * 60 * 60 * 1000; defineOptions({ name: "SysPlugin", }); -const context = { lastSyncTime }; + +async function syncOnlinePlugins(options?: { showSuccess?: boolean }) { + if (syncLoading.value) { + return; + } + syncLoading.value = true; + try { + await api.OnlinePluginSync(); + const setting = await api.OnlinePluginSetting(); + lastSyncTime.value = setting.lastSyncTime || Date.now(); + await pluginStore.clear(); + crudExpose.doRefresh(); + if (options?.showSuccess !== false) { + notification.success({ message: t("certd.onlinePluginSyncSuccess") }); + } + } finally { + syncLoading.value = false; + } +} + +const context = { lastSyncTime, syncLoading, syncOnlinePlugins }; const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context }); const pluginList = computed(() => { return crudBinding.value?.data || []; @@ -96,8 +118,8 @@ async function autoSyncOnlinePlugins() { // 页面打开后获取列表数据 useMounted(async () => { - await autoSyncOnlinePlugins(); - await crudExpose.doRefresh(); + autoSyncOnlinePlugins(); + crudExpose.doRefresh(); }); onMounted(() => { diff --git a/packages/ui/certd-server/.env b/packages/ui/certd-server/.env index 9d4509b8a..253a849b1 100644 --- a/packages/ui/certd-server/.env +++ b/packages/ui/certd-server/.env @@ -4,4 +4,4 @@ certd_plugin_loadmode=dev # certd_koa_port=7004 # certd_https_port=7005 -certd_release_mode=stable +#certd_release_mode=stable diff --git a/packages/ui/certd-server/src/configuration.ts b/packages/ui/certd-server/src/configuration.ts index 23d2b0a7f..362cf788e 100644 --- a/packages/ui/certd-server/src/configuration.ts +++ b/packages/ui/certd-server/src/configuration.ts @@ -121,6 +121,7 @@ export class MainConfiguration { ResetPasswdMiddleware, ]); + this.app.getMiddleware().insertFirst(async (ctx: IMidwayKoaContext, next: NextFunction) => { await next(); const path = ctx.path;