liuyu
3 小时以前 82a74ba0402ab546ba524d23ce62198c4d00d2f7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<script lang="ts" setup>
import type { ActionItem, BasicColumn } from '@jnpf/ui/vxeTable';
 
import type { EvalModeItem } from './types';
 
import { useMessage } from '@jnpf/hooks';
import { useModal } from '@jnpf/ui/modal';
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { deleteEvalMode, getEvalModeList, setEvalModeEnabled } from '#/api/x/tms/evalMode';
 
import Form from './Form.vue';
import { ENABLE_OPTIONS, labelOfEnabled, labelOfYesNo } from './constants';
 
defineOptions({ name: 'TmsEvalMode' });
 
const { createMessage } = useMessage();
const [registerForm, { openModal: openFormModal }] = useModal();
 
const columns: BasicColumn[] = [
  { title: '方式编码', dataIndex: 'modeCode', width: 120 },
  { title: '方式名称', dataIndex: 'modeName', width: 140 },
  {
    title: '需要试卷',
    dataIndex: 'needPaper',
    width: 100,
    align: 'center',
    customRender: ({ record }) => labelOfYesNo((record as EvalModeItem).needPaper),
  },
  {
    title: '需要提问预设',
    dataIndex: 'needQuiz',
    width: 120,
    align: 'center',
    customRender: ({ record }) => labelOfYesNo((record as EvalModeItem).needQuiz),
  },
  {
    title: '需要实操评分',
    dataIndex: 'needPractice',
    width: 120,
    align: 'center',
    customRender: ({ record }) => labelOfYesNo((record as EvalModeItem).needPractice),
  },
  {
    title: '状态',
    dataIndex: 'enabled',
    width: 90,
    align: 'center',
    slots: { default: 'enabled' },
  },
  { title: '备注', dataIndex: 'remark', minWidth: 200 },
];
 
const [registerTable, { reload }] = useVxeTable({
  api: fetchList,
  columns,
  immediate: true,
  rowKey: 'id',
  useSearchForm: true,
  formConfig: {
    baseColProps: { span: 6 },
    compact: true,
    schemas: [
      {
        field: 'keyword',
        label: '关键词',
        component: 'Input',
        componentProps: { placeholder: '编码/名称', submitOnPressEnter: true },
      },
      {
        field: 'enabled',
        label: '状态',
        component: 'Select',
        componentProps: { allowClear: true, placeholder: '请选择', options: ENABLE_OPTIONS },
      },
    ],
  },
  actionColumn: {
    width: 180,
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
  },
});
 
async function fetchList(params: Record<string, any>) {
  return { data: await getEvalModeList(params) };
}
 
function handleAdd() {
  openFormModal(true, {});
}
 
function handleEdit(record: EvalModeItem) {
  openFormModal(true, { id: record.id });
}
 
async function handleToggleEnabled(record: EvalModeItem) {
  const next = record.enabled === '1' ? '0' : '1';
  const action = next === '1' ? '启用' : '停用';
  try {
    await setEvalModeEnabled(record.id, next);
    createMessage.success(`已${action}`);
    reload();
  } catch (e: any) {
    createMessage.error(e?.message || `${action}失败`);
  }
}
 
async function handleDelete(record: EvalModeItem) {
  try {
    await deleteEvalMode(record.id);
    createMessage.success('删除成功');
    reload();
  } catch (e: any) {
    createMessage.error(e?.message || '删除失败');
  }
}
 
function getTableActions(record: EvalModeItem): ActionItem[] {
  const enableLabel = record.enabled === '1' ? '停用' : '启用';
  return [
    { label: '编辑', onClick: handleEdit.bind(null, record) },
    {
      label: enableLabel,
      modelConfirm: {
        content: `确定${enableLabel}考核方式「${record.modeName}」吗?`,
        onOk: handleToggleEnabled.bind(null, record),
      },
    },
    {
      label: '删除',
      color: 'error',
      modelConfirm: {
        content: `确定删除考核方式「${record.modeName}」吗?`,
        onOk: handleDelete.bind(null, record),
      },
    },
  ];
}
</script>
 
<template>
  <div class="jnpf-content-wrapper">
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-content">
        <BasicVxeTable @register="registerTable">
          <template #tableTitle>
            <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="handleAdd">新增</a-button>
          </template>
          <template #enabled="{ record }">
            <a-tag :color="record.enabled === '1' ? 'success' : 'default'">
              {{ labelOfEnabled(record.enabled) }}
            </a-tag>
          </template>
          <template #action="{ record }">
            <TableAction :actions="getTableActions(record)" />
          </template>
        </BasicVxeTable>
      </div>
    </div>
    <Form @register="registerForm" @reload="reload" />
  </div>
</template>