| | |
| | | |
| | | import type { CourseItem } from './types'; |
| | | |
| | | import { onMounted, ref } from 'vue'; |
| | | |
| | | import { useMessage } from '@jnpf/hooks'; |
| | | import { useModal } from '@jnpf/ui/modal'; |
| | | import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable'; |
| | | |
| | | import { deleteCourse, getCourseList, setCourseEnabled } from '#/api/x/tms/course'; |
| | | import { useBaseStore } from '#/store'; |
| | | import { |
| | | TMS_DIC, |
| | | TMS_DIC_FIELD_NAMES, |
| | | labelOfDic, |
| | | loadTmsDic, |
| | | type TmsDicOpt, |
| | | } from '#/views/x/tms/shared/dic'; |
| | | |
| | | import Form from './Form.vue'; |
| | | import { |
| | | CATEGORY_OPTIONS, |
| | | ENABLE_OPTIONS, |
| | | EVAL_MODE_OPTIONS, |
| | | TRAIN_MODE_OPTIONS, |
| | | labelOfCategory, |
| | | labelOfEnabled, |
| | | labelOfEvalMode, |
| | | labelOfTrainMode, |
| | | } from './constants'; |
| | | |
| | | defineOptions({ name: 'TmsCourse' }); |
| | | |
| | | const { createMessage } = useMessage(); |
| | | const baseStore = useBaseStore(); |
| | | const [registerForm, { openModal: openFormModal }] = useModal(); |
| | | |
| | | const categoryOpts = ref<TmsDicOpt[]>([]); |
| | | const trainModeOpts = ref<TmsDicOpt[]>([]); |
| | | const evalModeOpts = ref<TmsDicOpt[]>([]); |
| | | const enableOpts = ref<TmsDicOpt[]>([]); |
| | | |
| | | const columns: BasicColumn[] = [ |
| | | { title: '课程编号', dataIndex: 'courseNo', width: 140 }, |
| | |
| | | title: '课程分类', |
| | | dataIndex: 'category', |
| | | width: 100, |
| | | customRender: ({ record }) => labelOfCategory((record as CourseItem).category), |
| | | customRender: ({ record }) => labelOfDic(categoryOpts.value, (record as CourseItem).category), |
| | | }, |
| | | { |
| | | title: '培训方式', |
| | | dataIndex: 'trainMode', |
| | | width: 110, |
| | | customRender: ({ record }) => labelOfTrainMode((record as CourseItem).trainMode), |
| | | customRender: ({ record }) => labelOfDic(trainModeOpts.value, (record as CourseItem).trainMode), |
| | | }, |
| | | { |
| | | title: '考核方式', |
| | | dataIndex: 'evalMode', |
| | | width: 110, |
| | | customRender: ({ record }) => labelOfEvalMode((record as CourseItem).evalMode), |
| | | customRender: ({ record }) => labelOfDic(evalModeOpts.value, (record as CourseItem).evalMode), |
| | | }, |
| | | { |
| | | title: '关联考核试卷', |
| | |
| | | { title: '备注', dataIndex: 'remark', minWidth: 140 }, |
| | | ]; |
| | | |
| | | const [registerTable, { reload }] = useVxeTable({ |
| | | const [registerTable, { reload, getForm }] = useVxeTable({ |
| | | api: fetchList, |
| | | columns, |
| | | immediate: true, |
| | | immediate: false, |
| | | rowKey: 'id', |
| | | useSearchForm: true, |
| | | formConfig: { |
| | |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请选择', |
| | | options: CATEGORY_OPTIONS, |
| | | options: categoryOpts.value, |
| | | fieldNames: TMS_DIC_FIELD_NAMES, |
| | | }, |
| | | }, |
| | | { |
| | |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请选择', |
| | | options: TRAIN_MODE_OPTIONS, |
| | | options: trainModeOpts.value, |
| | | fieldNames: TMS_DIC_FIELD_NAMES, |
| | | }, |
| | | }, |
| | | { |
| | |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请选择', |
| | | options: EVAL_MODE_OPTIONS, |
| | | options: evalModeOpts.value, |
| | | fieldNames: TMS_DIC_FIELD_NAMES, |
| | | }, |
| | | }, |
| | | { |
| | |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请选择', |
| | | options: ENABLE_OPTIONS, |
| | | options: enableOpts.value, |
| | | fieldNames: TMS_DIC_FIELD_NAMES, |
| | | }, |
| | | }, |
| | | ], |
| | |
| | | dataIndex: 'action', |
| | | fixed: 'right', |
| | | }, |
| | | }); |
| | | |
| | | onMounted(async () => { |
| | | const [category, trainMode, evalMode, enable] = await Promise.all([ |
| | | loadTmsDic(baseStore, TMS_DIC.courseCategory), |
| | | loadTmsDic(baseStore, TMS_DIC.trainMode), |
| | | loadTmsDic(baseStore, TMS_DIC.evalMode), |
| | | loadTmsDic(baseStore, TMS_DIC.enableStatus), |
| | | ]); |
| | | categoryOpts.value = category; |
| | | trainModeOpts.value = trainMode; |
| | | evalModeOpts.value = evalMode; |
| | | enableOpts.value = enable; |
| | | getForm()?.updateSchema?.([ |
| | | { |
| | | field: 'category', |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请选择', |
| | | options: category, |
| | | fieldNames: TMS_DIC_FIELD_NAMES, |
| | | }, |
| | | }, |
| | | { |
| | | field: 'trainMode', |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请选择', |
| | | options: trainMode, |
| | | fieldNames: TMS_DIC_FIELD_NAMES, |
| | | }, |
| | | }, |
| | | { |
| | | field: 'evalMode', |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请选择', |
| | | options: evalMode, |
| | | fieldNames: TMS_DIC_FIELD_NAMES, |
| | | }, |
| | | }, |
| | | { |
| | | field: 'enabled', |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请选择', |
| | | options: enable, |
| | | fieldNames: TMS_DIC_FIELD_NAMES, |
| | | }, |
| | | }, |
| | | ]); |
| | | reload(); |
| | | }); |
| | | |
| | | async function fetchList(params: Record<string, any>) { |
| | |
| | | } |
| | | |
| | | async function handleDelete(record: CourseItem) { |
| | | if (record.enabled !== '0') { |
| | | createMessage.warning('请先停用后再删除'); |
| | | return; |
| | | } |
| | | try { |
| | | await deleteCourse(record.id); |
| | | createMessage.success('删除成功'); |
| | |
| | | |
| | | function getTableActions(record: CourseItem): ActionItem[] { |
| | | const enableLabel = record.enabled === '1' ? '停用' : '启用'; |
| | | return [ |
| | | const actions: ActionItem[] = [ |
| | | { label: '编辑', onClick: handleEdit.bind(null, record) }, |
| | | { |
| | | label: enableLabel, |
| | |
| | | onOk: handleToggleEnabled.bind(null, record), |
| | | }, |
| | | }, |
| | | { |
| | | ]; |
| | | if (record.enabled === '0') { |
| | | actions.push({ |
| | | label: '删除', |
| | | color: 'error', |
| | | modelConfirm: { |
| | | content: `确定删除培训课程「${record.courseName}」吗?`, |
| | | onOk: handleDelete.bind(null, record), |
| | | }, |
| | | }, |
| | | ]; |
| | | }); |
| | | } |
| | | return actions; |
| | | } |
| | | </script> |
| | | |
| | |
| | | </template> |
| | | <template #enabled="{ record }"> |
| | | <a-tag :color="record.enabled === '1' ? 'success' : 'default'"> |
| | | {{ labelOfEnabled(record.enabled) }} |
| | | {{ labelOfDic(enableOpts, record.enabled) }} |
| | | </a-tag> |
| | | </template> |
| | | <template #action="{ record }"> |