liuyu
21 小时以前 8534025c45b4736975730678b9ccf23570a75f95
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<script lang="ts" setup>
import type { ActionItem, BasicColumn } from '@jnpf/ui/vxeTable';
 
import type { PaperEntity } from './types';
 
import { computed, onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
 
import { useMessage } from '@jnpf/hooks';
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { getPaperList, invalidatePaper, setPaperStatus } from '#/api/x/tms/paper';
import { TMS_DIC_FIELD_NAMES } from '#/views/x/tms/shared/dic';
 
import { STATUS_OPTIONS, labelOfSortMode, labelOfStatus, loadPaperDics } from './constants';
 
defineOptions({ name: 'TmsPaperList' });
 
const router = useRouter();
const { createMessage } = useMessage();
const invalidMode = ref(false);
 
const activeStatusOptions = computed(() =>
  STATUS_OPTIONS.value.filter((x) => (x.enCode || x.id) !== 'invalid'),
);
 
const columns: BasicColumn[] = [
  { title: '试卷编号', dataIndex: 'paperNo', width: 120 },
  { title: '试卷名称', dataIndex: 'paperName', minWidth: 200 },
  {
    title: '状态',
    dataIndex: 'bizStatus',
    width: 100,
    align: 'center',
    slots: { default: 'bizStatus' },
  },
  {
    title: '时长(分钟)',
    dataIndex: 'durationMin',
    width: 100,
    align: 'center',
  },
  {
    title: '总分',
    dataIndex: 'totalScore',
    width: 90,
    align: 'center',
  },
  {
    title: '合格分',
    dataIndex: 'passScore',
    width: 90,
    align: 'center',
  },
  {
    title: '题量',
    dataIndex: 'questionCount',
    width: 80,
    align: 'center',
  },
  {
    title: '试题排序',
    dataIndex: 'sortMode',
    width: 110,
    customRender: ({ record }) => labelOfSortMode((record as PaperEntity).sortMode),
  },
  { title: '创建时间', dataIndex: 'creatorTime', width: 170 },
];
 
const [registerTable, { reload, getForm }] = useVxeTable({
  api: fetchList,
  columns,
  immediate: false,
  rowKey: 'id',
  useSearchForm: true,
  formConfig: {
    baseColProps: { span: 6 },
    compact: true,
    schemas: [
      {
        field: 'keyword',
        label: '关键词',
        component: 'Input',
        componentProps: { placeholder: '编号/名称', submitOnPressEnter: true },
      },
      {
        field: 'bizStatus',
        label: '状态',
        component: 'Select',
        componentProps: {
          allowClear: true,
          placeholder: '请选择',
          options: STATUS_OPTIONS.value,
          fieldNames: TMS_DIC_FIELD_NAMES,
        },
      },
    ],
  },
  actionColumn: {
    width: 180,
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
  },
});
 
onMounted(async () => {
  await loadPaperDics();
  getForm()?.updateSchema?.([
    {
      field: 'bizStatus',
      componentProps: {
        allowClear: true,
        placeholder: '请选择',
        options: activeStatusOptions.value,
        fieldNames: TMS_DIC_FIELD_NAMES,
      },
    },
  ]);
  reload();
});
 
async function fetchList(params: Record<string, any>) {
  const query = { ...params };
  if (invalidMode.value) {
    query.bizStatus = 'invalid';
  }
  const page = await getPaperList(query);
  return {
    data: {
      list: Array.isArray(page?.list) ? page.list : [],
      pagination: page?.pagination || { total: 0 },
    },
  };
}
 
function openInvalidList() {
  invalidMode.value = true;
  getForm()?.setFieldsValue?.({ bizStatus: undefined });
  getForm()?.updateSchema?.([{ field: 'bizStatus', ifShow: false }]);
  reload();
}
 
function backToNormal() {
  invalidMode.value = false;
  getForm()?.updateSchema?.([{ field: 'bizStatus', ifShow: true }]);
  reload();
}
 
function statusColor(status?: string) {
  if (status === 'open') return '#52c41a';
  if (status === 'closed') return '#ff4d4f';
  if (status === 'invalid') return '#999';
  return undefined;
}
 
function handleCreate() {
  router.push('/tms/paper/create');
}
 
function handleEdit(record: PaperEntity) {
  if (record.bizStatus === 'open') {
    createMessage.warning('请先停用后再编辑');
    return;
  }
  if (record.bizStatus === 'invalid') {
    createMessage.warning('已废弃试卷不可编辑');
    return;
  }
  router.push(`/tms/paper/edit/${record.id}`);
}
 
function handleDetail(record: PaperEntity) {
  router.push(`/tms/paper/detail/${record.id}`);
}
 
async function handleInvalidate(record: PaperEntity) {
  await invalidatePaper(record.id!);
  createMessage.success('废弃成功');
  reload();
}
 
async function handleEnable(record: PaperEntity) {
  await setPaperStatus(record.id!, 'open');
  createMessage.success('已启用');
  reload();
}
 
async function handleDisable(record: PaperEntity) {
  await setPaperStatus(record.id!, 'closed');
  createMessage.success('已停用');
  reload();
}
 
function getTableActions(record: PaperEntity): ActionItem[] {
  if (record.bizStatus === 'open') {
    return [
      {
        label: '停用',
        modelConfirm: {
          content: `确定停用试卷「${record.paperName}」吗?停用后不可用于培训任务在线考试。`,
          onOk: handleDisable.bind(null, record),
        },
      },
      { label: '详情', onClick: handleDetail.bind(null, record) },
    ];
  }
  if (record.bizStatus === 'closed') {
    return [
      {
        label: '启用',
        modelConfirm: {
          content: `确定启用试卷「${record.paperName}」吗?启用后可用于培训任务在线考试。`,
          onOk: handleEnable.bind(null, record),
        },
      },
      { label: '编辑', onClick: handleEdit.bind(null, record) },
      {
        label: '废弃',
        color: 'error',
        modelConfirm: {
          content: `确定废弃试卷「${record.paperName}」吗?废弃后不可再启用,且不可用于培训任务在线考试。`,
          onOk: handleInvalidate.bind(null, record),
        },
      },
    ];
  }
  return [{ label: '详情', onClick: handleDetail.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-space>
              <template v-if="!invalidMode">
                <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="handleCreate">新增</a-button>
                <a-button @click="openInvalidList">废弃列表</a-button>
              </template>
              <a-button v-else @click="backToNormal">返回</a-button>
            </a-space>
          </template>
          <template #bizStatus="{ record }">
            <span :style="{ color: statusColor(record.bizStatus) }">{{ labelOfStatus(record.bizStatus) }}</span>
          </template>
          <template #action="{ record }">
            <TableAction :actions="getTableActions(record)" />
          </template>
        </BasicVxeTable>
      </div>
    </div>
  </div>
</template>