Skip to content

Commit

Permalink
feat(projects): add quartz and optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
paynezhuang committed Jun 2, 2024
1 parent 5b3c20c commit 94e600c
Show file tree
Hide file tree
Showing 28 changed files with 1,414 additions and 28 deletions.
34 changes: 34 additions & 0 deletions src/constants/business.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,37 @@ export const logsLoginStatusTag: Record<Api.Monitor.LogsLoginStatus, NaiveUI.The
};

export const logsLoginStatusOptions = transformRecordToOption(logsLoginStatusRecord);

/** monitor logs scheduler status */
export const logsSchedulerStatusRecord: Record<Api.Monitor.SchedulerExecuteStatus, App.I18n.I18nKey> = {
FAIL: 'page.monitor.logs.scheduler.executeStatus.fail',
SUCCESS: 'page.monitor.logs.scheduler.executeStatus.success'
};

export const logsSchedulerStatusTag: Record<Api.Monitor.SchedulerExecuteStatus, NaiveUI.ThemeColor> = {
FAIL: 'error',
SUCCESS: 'success'
};

export const logsSchedulerStatusOptions = transformRecordToOption(logsSchedulerStatusRecord);

/** monitor scheduler trigger state */
export const schedulerTriggerStateRecord: Record<Api.Monitor.SchedulerTriggerState, App.I18n.I18nKey> = {
WAITING: 'page.monitor.scheduler.triggerStates.waiting',
ACQUIRED: 'page.monitor.scheduler.triggerStates.acquired',
EXECUTING: 'page.monitor.scheduler.triggerStates.executing',
PAUSED: 'page.monitor.scheduler.triggerStates.paused',
BLOCKED: 'page.monitor.scheduler.triggerStates.blocked',
ERROR: 'page.monitor.scheduler.triggerStates.error'
};

export const schedulerTriggerStateTag: Record<Api.Monitor.SchedulerTriggerState, NaiveUI.ThemeColor> = {
WAITING: 'success',
ACQUIRED: 'success',
EXECUTING: 'success',
PAUSED: 'error',
BLOCKED: 'error',
ERROR: 'error'
};

export const schedulerTriggerStateOptions = transformRecordToOption(schedulerTriggerStateRecord);
62 changes: 54 additions & 8 deletions src/hooks/common/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { computed, effectScope, onScopeDispose, reactive, ref, watch } from 'vue
import type { Ref } from 'vue';
import { type PaginationProps } from 'naive-ui';
import { useBoolean, useHookTable } from '@sa/hooks';
import { cloneDeep } from 'lodash-es';
import { useAppStore } from '@/store/modules/app';
import { $t } from '@/locales';
type TableData = NaiveUI.TableData;
Expand Down Expand Up @@ -192,25 +193,56 @@ export function useTableOperate<T extends TableData = TableData>(data: Ref<T[]>,
/** the editing row data */
const editingData: Ref<T | null> = ref(null);

/** the checked row key of table */
const checkedRowKey: Ref<string> = ref('0');

/** the checked row keys of table */
const checkedRowKeys: Ref<string[]> = ref([]);

/** the checked row data of table */
const checkedRowData: Ref<T | null> = ref(null);

/** the checked row datas of table */
const checkedRowDatas: Ref<T[]> = ref([]);

/** Get data by id */
function handleEdit(id: T['id']) {
operateType.value = 'edit';
editingData.value = data.value.find(item => item.id === id) || null;

editingId.value = id;

const findItem = data.value.find(item => item.id === id) || null;
editingData.value = cloneDeep(findItem);
openDrawer();
}

/** set row data id */
function handleId(id: T['id']) {
editingId.value = id;
function handleId(id?: T['id']) {
editingId.value = getTargetId(id);
}

/** set checked row data */
function handleCheckedRow() {
checkedRowKey.value = checkedRowKeys.value.length > 0 ? checkedRowKeys.value[0] : '0';
checkedRowData.value = data.value.find(item => item.id === checkedRowKey.value) || null;
checkedRowDatas.value = data.value.filter(item => checkedRowKeys.value.includes(item.id));
}

/** set row data */
function handleData(id: T['id']) {
editingData.value = data.value.find(item => item.id === id) || null;
function handleData(id?: T['id']) {
const targetId = getTargetId(id);
if (targetId === '0') {
editingData.value = null;
return;
}
const findItem = data.value.find(item => item.id === targetId) || null;
editingData.value = cloneDeep(findItem);
}

/** the checked row keys of table */
const checkedRowKeys = ref<string[]>([]);
/** get the target id , If no ID is entered, retrieve the row key; otherwise, it is 0 */
function getTargetId(id?: string) {
return id ?? (checkedRowKeys.value.length > 0 ? checkedRowKeys.value[0] : '0');
}

/** the hook after the batch delete operation is completed */
async function onBatchDeleted() {
Expand All @@ -228,6 +260,15 @@ export function useTableOperate<T extends TableData = TableData>(data: Ref<T[]>,
await getData();
}

/** Remote operation is complete, displaying the message action. */
async function onMessage(message?: string, immediate: boolean = true) {
window.$message?.success(message || $t('common.actionSuccess'));

checkedRowKeys.value = [];

if (immediate) await getData();
}

return {
drawerVisible,
openDrawer,
Expand All @@ -239,9 +280,14 @@ export function useTableOperate<T extends TableData = TableData>(data: Ref<T[]>,
handleEdit,
handleId,
handleData,
checkedRowKey,
checkedRowKeys,
checkedRowData,
checkedRowDatas,
handleCheckedRow,
onBatchDeleted,
onDeleted
onDeleted,
onMessage
};
}

Expand Down
75 changes: 74 additions & 1 deletion src/locales/langs/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const local: App.I18n.Schema = {
},
common: {
action: 'Action',
actionSuccess: 'Action Success',
add: 'Add',
addSuccess: 'Add Success',
backToHome: 'Back to home',
Expand Down Expand Up @@ -44,7 +45,11 @@ const local: App.I18n.Schema = {
yesOrNo: {
yes: 'Yes',
no: 'No'
}
},
createUser: 'Create User',
createTime: 'Create Time',
updateUser: 'Update User',
updateTime: 'Update Time'
},
request: {
logout: 'Logout user after request failed',
Expand Down Expand Up @@ -178,6 +183,8 @@ const local: App.I18n.Schema = {
monitor_logs_login: 'Login Logs',
monitor_logs_operation: 'Operation Logs',
monitor_logs_error: 'Error Logs',
monitor_logs_scheduler: 'Scheduler Logs',
monitor_scheduler: 'Scheduler',
'multi-menu': 'Multi Menu',
'multi-menu_first': 'Menu One',
'multi-menu_first_child': 'Menu One Child',
Expand Down Expand Up @@ -601,6 +608,72 @@ const local: App.I18n.Schema = {
form: {
createUser: 'Please enter operation User'
}
},
scheduler: {
jobName: 'Job Name',
jobGroup: 'Job Group',
useTime: 'Use Time(ms)',
status: 'Status',
createTime: 'Execute Time',
exceptionMessage: 'Exception Message',
exceptionClass: 'Exception Class',
line: 'Exceptioin Line',
stackTrace: 'Stack Trace',
executeStatus: {
success: 'Success',
fail: 'Fail'
},
form: {
jobName: 'Please select job name'
}
}
},
scheduler: {
jobName: 'Job Name',
jobGroup: 'Job Group',
jobClassName: 'Job Class Name',
description: 'Job Description',
cronExpression: 'Cron Expression',
jobData: 'Job Params',
triggerName: 'Trigger Name',
triggerGroup: 'Trigger Group',
triggerDescription: 'Trigger Description',
triggerData: 'Trigger Params',
triggerState: 'State',
form: {
jobName: 'Please enter job name',
jobGroup: 'Please enter job group',
jobClassName: 'Please enter job class name',
description: 'Please enter job description',
cronExpression: 'Please enter cron expression',
jobDataKey: 'Please enter job params key',
jobDataValue: 'Please enter job params value',
triggerName: 'Please enter trigger name',
triggerGroup: 'Please enter trigger group',
triggerDescription: 'Please enter trigger description',
triggerDataKey: 'Please enter trigger params key',
triggerDataValue: 'Please enter trigger params value'
},
addJob: 'Add Job',
editJob: 'Edit Job',
ImmediateJob: 'Immediate Job',
ImmediateSuccess: 'Immediate Success',
pauseJob: 'Pause Job',
pauseJobGroup: 'Pause Group Job',
pauseSuccess: 'Pause Success',
pauseFail: 'Pause Fail',
resumeJob: 'Resume Job',
resumeJobGroup: 'Resume Group Job',
resumeSuccess: 'Resume Success',
resumeFail: 'Resume Fail',
confirmOperate: 'Are You Confirm {operation} : {name} ?',
triggerStates: {
waiting: 'Waiting',
acquired: 'Acquired',
executing: 'Executing',
paused: 'Paused',
blocked: 'Blocked',
error: 'Error'
}
}
}
Expand Down
75 changes: 74 additions & 1 deletion src/locales/langs/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const local: App.I18n.Schema = {
},
common: {
action: '操作',
actionSuccess: '操作成功',
add: '新增',
addSuccess: '添加成功',
backToHome: '返回首页',
Expand Down Expand Up @@ -44,7 +45,11 @@ const local: App.I18n.Schema = {
yesOrNo: {
yes: '是',
no: '否'
}
},
createUser: '创建用户',
createTime: '创建时间',
updateUser: '更新用户',
updateTime: '更新时间'
},
request: {
logout: '请求失败后登出用户',
Expand Down Expand Up @@ -178,6 +183,8 @@ const local: App.I18n.Schema = {
monitor_logs_login: '登录日志',
monitor_logs_operation: '操作日志',
monitor_logs_error: '错误日志',
monitor_logs_scheduler: '调度日志',
monitor_scheduler: '调度任务',
'multi-menu': '多级菜单',
'multi-menu_first': '菜单一',
'multi-menu_first_child': '菜单一子菜单',
Expand Down Expand Up @@ -601,6 +608,72 @@ const local: App.I18n.Schema = {
form: {
createUser: '请填写操作用户'
}
},
scheduler: {
jobName: '任务名称',
jobGroup: '任务组名',
useTime: '耗时(ms)',
status: '执行状态',
createTime: '执行时间',
exceptionMessage: '异常信息',
exceptionClass: '异常类名',
line: '异常行号',
stackTrace: '异常堆栈',
executeStatus: {
success: '执行成功',
fail: '执行失败'
},
form: {
jobName: '请选择任务名称'
}
}
},
scheduler: {
jobName: '任务名称',
jobGroup: '任务组名',
jobClassName: '任务类名',
description: '任务描述',
cronExpression: 'cron 表达式',
jobData: '任务参数',
triggerName: '触发器名称',
triggerGroup: '触发器组名',
triggerDescription: '触发器描述',
triggerData: '触发器参数',
triggerState: '状态',
form: {
jobName: '请输入任务名称',
jobGroup: '请输入任务组名',
jobClassName: '请输入任务类名',
description: '请输入任务描述',
cronExpression: '请输入 cron 表达式',
jobDataKey: '请输入任务参数Key',
jobDataValue: '请输入任务参数Value',
triggerName: '请输入触发器名称',
triggerGroup: '请输入触发器组名',
triggerDescription: '请输入触发器描述',
triggerDataKey: '请输入触发器参数Key',
triggerDataValue: '请输入触发器参数Value'
},
addJob: '新增任务',
editJob: '编辑任务',
ImmediateJob: '立即执行',
ImmediateSuccess: '执行成功',
pauseJob: '暂停任务',
pauseJobGroup: '暂停任务组',
pauseSuccess: '暂停成功',
pauseFail: '暂停失败',
resumeJob: '恢复任务',
resumeJobGroup: '恢复任务组',
resumeSuccess: '恢复成功',
resumeFail: '恢复失败',
confirmOperate: '您确认{operation} : {name} ?',
triggerStates: {
waiting: '等待执行',
acquired: '准备执行',
executing: '执行中',
paused: '暂停',
blocked: '阻塞',
error: '错误'
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/router/elegant/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const views: Record<LastLevelRouteKey, RouteComponent | (() => Promise<Ro
monitor_logs_error: () => import("@/views/monitor/logs_error/index.vue"),
monitor_logs_login: () => import("@/views/monitor/logs_login/index.vue"),
monitor_logs_operation: () => import("@/views/monitor/logs_operation/index.vue"),
monitor_logs_scheduler: () => import("@/views/monitor/logs_scheduler/index.vue"),
monitor_scheduler: () => import("@/views/monitor/scheduler/index.vue"),
monitor_system: () => import("@/views/monitor/system/index.vue"),
"multi-menu_first_child": () => import("@/views/multi-menu/first_child/index.vue"),
"multi-menu_second_child_home": () => import("@/views/multi-menu/second_child_home/index.vue"),
Expand Down
18 changes: 18 additions & 0 deletions src/router/elegant/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,27 @@ export const generatedRoutes: GeneratedRoute[] = [
title: 'monitor_logs_operation',
i18nKey: 'route.monitor_logs_operation'
}
},
{
name: 'monitor_logs_scheduler',
path: '/monitor/logs/scheduler',
component: 'view.monitor_logs_scheduler',
meta: {
title: 'monitor_logs_scheduler',
i18nKey: 'route.monitor_logs_scheduler'
}
}
]
},
{
name: 'monitor_scheduler',
path: '/monitor/scheduler',
component: 'view.monitor_scheduler',
meta: {
title: 'monitor_scheduler',
i18nKey: 'route.monitor_scheduler'
}
},
{
name: 'monitor_system',
path: '/monitor/system',
Expand Down
2 changes: 2 additions & 0 deletions src/router/elegant/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ const routeMap: RouteMap = {
"monitor_logs_error": "/monitor/logs/error",
"monitor_logs_login": "/monitor/logs/login",
"monitor_logs_operation": "/monitor/logs/operation",
"monitor_logs_scheduler": "/monitor/logs/scheduler",
"monitor_scheduler": "/monitor/scheduler",
"monitor_system": "/monitor/system",
"multi-menu": "/multi-menu",
"multi-menu_first": "/multi-menu/first",
Expand Down
Loading

0 comments on commit 94e600c

Please sign in to comment.