优化
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
const viewModules = import.meta.glob('../view/**/*.vue')
|
||||
const moduleViews = import.meta.glob('../modules/**/*.vue')
|
||||
const legacyModuleComponents = {
|
||||
'plugin/email/view/index.vue': 'modules/email/view/index.vue',
|
||||
'plugin/announcement/view/info.vue': 'modules/announcement/view/info.vue',
|
||||
'plugin/announcement/form/info.vue': 'modules/announcement/form/info.vue'
|
||||
}
|
||||
|
||||
export const asyncRouterHandle = (asyncRouter) => {
|
||||
asyncRouter.forEach((item) => {
|
||||
if (item.component && typeof item.component === 'string') {
|
||||
item.meta.path = '/src/' + item.component
|
||||
if (item.component.split('/')[0] === 'view') {
|
||||
item.component = dynamicImport(viewModules, item.component)
|
||||
} else if (item.component.split('/')[0] === 'modules') {
|
||||
item.component = dynamicImport(moduleViews, item.component)
|
||||
const component = legacyModuleComponents[item.component] || item.component
|
||||
item.meta.path = '/src/' + component
|
||||
if (component.split('/')[0] === 'view') {
|
||||
item.component = dynamicImport(viewModules, component)
|
||||
} else if (component.split('/')[0] === 'modules') {
|
||||
item.component = dynamicImport(moduleViews, component)
|
||||
}
|
||||
}
|
||||
if (item.children) {
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
if (response.code !== 0) return
|
||||
notices.value = (response.data?.list || []).map((item) => ({
|
||||
typeTitle: item.type === 2 ? '公告' : '通知',
|
||||
time: item.createdAt ? new Date(item.createdAt).toLocaleDateString('zh-CN') : '',
|
||||
time: item.CreatedAt ? new Date(item.CreatedAt).toLocaleDateString('zh-CN') : '',
|
||||
title: item.title,
|
||||
dotClass: 'bg-cyan-500',
|
||||
tagClass: 'bg-cyan-100 text-cyan-700 dark:bg-cyan-900/40 dark:text-cyan-200'
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
<el-option v-for="m in methodOptions" :key="m.name" :label="`${m.name} — ${m.description}`" :value="m.name" />
|
||||
</el-select>
|
||||
<div class="text-xs text-gray-400 mt-1 flex items-center flex-wrap">
|
||||
<span>没有想要的方法?需在后端 server/initialize/timer.go 的 Timer() 中注册,重启服务后即可选择</span>
|
||||
<span>没有想要的方法?需在后端 internal/worker/task_registry.go 的 registerTaskMethods() 中注册,重启服务后即可选择</span>
|
||||
<el-popover placement="top" :width="560" trigger="click">
|
||||
<template #reference>
|
||||
<el-button type="primary" link size="small">查看注册模板</el-button>
|
||||
@@ -299,16 +299,21 @@ const headerText = ref('')
|
||||
const methodOptions = ref([])
|
||||
const formTitle = computed(() => (form.value.ID ? '编辑定时任务' : '新增定时任务'))
|
||||
|
||||
// 扩展内置任务时需要同时登记名称并实现执行分支。
|
||||
const methodRegisterTemplate = `// 1. internal/biz/task.go: 在 RegisteredTaskMethods 中登记任务
|
||||
{Name: "MyTask", Description: "任务说明(展示在方法下拉中)"},
|
||||
|
||||
// 2. internal/service/task_execution.go: 在 TaskExecutorMethod 分支中实现
|
||||
case "MyTask":
|
||||
// params := v.Params // 面板「参数(JSON)」原文,可按需解析
|
||||
// 通过 biz usecase 执行业务逻辑,不要在 service 中直接访问数据库
|
||||
err = s.uc.RunMyTask(runCtx, v.Params)
|
||||
log.Output = "任务执行完成"`
|
||||
// 注册方法代码模板: 引导二开在 worker 的统一注册入口追加注册。
|
||||
const methodRegisterTemplate = `// 位置: internal/worker/task_registry.go -> registerTaskMethods()
|
||||
biz.RegisterTaskMethod("MyTask", "任务说明(展示在方法下拉中)", func(ctx context.Context, params json.RawMessage) error {
|
||||
// params 为面板「参数(JSON)」原文, 按需解析; 无参数可忽略
|
||||
// var p struct {
|
||||
// Days int \`json:"days"\`
|
||||
// }
|
||||
// if len(params) > 0 {
|
||||
// if err := json.Unmarshal(params, &p); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// TODO: 调用注入到 TaskExecutor 的 biz usecase 执行业务逻辑
|
||||
return nil
|
||||
})`
|
||||
|
||||
const copyRegisterTemplate = () => {
|
||||
const input = document.createElement('textarea')
|
||||
@@ -317,7 +322,7 @@ const copyRegisterTemplate = () => {
|
||||
input.select()
|
||||
document.execCommand('copy')
|
||||
document.body.removeChild(input)
|
||||
ElMessage.success('扩展说明已复制,请按注释修改后端并重启服务')
|
||||
ElMessage.success('已复制,请粘贴到 internal/worker/task_registry.go 的 registerTaskMethods() 中,重启后生效')
|
||||
}
|
||||
|
||||
const openForm = async (row) => {
|
||||
|
||||
Reference in New Issue
Block a user