mirror of
https://github.com/certd/certd.git
synced 2026-10-13 07:38:56 +08:00
refactor(plugin): 迁移同步插件逻辑到页面组件并优化上下文传递
1. 将plugin crud组件中的syncOnlinePlugins方法迁移到index.vue中 2. 把syncLoading和syncOnlinePlugins加入页面上下文传递给crud组件 3. 移除crud组件中冗余的syncLoading声明 4. 调整页面初始化调用顺序
This commit is contained in:
@@ -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<UserPageRes> => {
|
||||
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;
|
||||
|
||||
@@ -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<number>(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(() => {
|
||||
|
||||
@@ -4,4 +4,4 @@ certd_plugin_loadmode=dev
|
||||
|
||||
# certd_koa_port=7004
|
||||
# certd_https_port=7005
|
||||
certd_release_mode=stable
|
||||
#certd_release_mode=stable
|
||||
|
||||
@@ -121,6 +121,7 @@ export class MainConfiguration {
|
||||
ResetPasswdMiddleware,
|
||||
]);
|
||||
|
||||
|
||||
this.app.getMiddleware().insertFirst(async (ctx: IMidwayKoaContext, next: NextFunction) => {
|
||||
await next();
|
||||
const path = ctx.path;
|
||||
|
||||
Reference in New Issue
Block a user