liuyu
4 小时以前 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
<script lang="ts" setup>
import type { ActionItem, BasicColumn } from '@jnpf/ui/vxeTable';
 
import type { MyPaperListItem } from './types';
 
import { ref } from 'vue';
import { useRouter } from 'vue-router';
 
import { useMessage } from '@jnpf/hooks';
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { getMyPaperList, startOnlineExam } from '#/api/x/tms/onlineExam';
 
import { MY_PAPER_STATUS_OPTIONS, colorOfMyPaperStatus, labelOfMyPaperStatus } from './constants';
 
defineOptions({ name: 'TmsOnlineExam' });
 
const router = useRouter();
const { createMessage } = useMessage();
const starting = ref(false);
 
const columns: BasicColumn[] = [
  { title: '试卷名称', dataIndex: 'paperName', minWidth: 260 },
  {
    title: '状态',
    dataIndex: 'status',
    width: 100,
    align: 'center',
    slots: { default: 'status' },
  },
  {
    title: '考试时间',
    dataIndex: 'examTimeText',
    minWidth: 280,
    customRender: ({ record }) => (record as MyPaperListItem).examTimeText || '-',
  },
  {
    title: '卷面总分',
    dataIndex: 'totalScore',
    width: 100,
    align: 'center',
  },
];
 
const [registerTable] = 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: 'status',
        label: '状态',
        component: 'Select',
        componentProps: {
          allowClear: true,
          placeholder: '请选择状态',
          options: MY_PAPER_STATUS_OPTIONS,
        },
      },
    ],
  },
  actionColumn: {
    width: 160,
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
  },
});
 
async function fetchList(params: Record<string, any>) {
  return { data: await getMyPaperList(params) };
}
 
function handleDetail(record: MyPaperListItem) {
  router.push(`/tms/onlineExam/detail/${record.id}`);
}
 
async function handleStart(record: MyPaperListItem) {
  if (starting.value) return;
  starting.value = true;
  try {
    const paper = await startOnlineExam(record.id);
    sessionStorage.setItem('tms_online_exam_paper', JSON.stringify(paper));
    sessionStorage.setItem('tms_online_exam_myPaperId', record.id);
    router.push('/tms/onlineExam/exam');
  } catch (e: any) {
    createMessage.error(e?.message || '开始考试失败');
  } finally {
    starting.value = false;
  }
}
 
function getTableActions(record: MyPaperListItem): ActionItem[] {
  const actions: ActionItem[] = [];
  if (record.status === 'notStarted') {
    actions.push({ label: '开始考试', onClick: handleStart.bind(null, record) });
  } else if (record.status === 'doing') {
    actions.push({ label: '继续考试', onClick: handleStart.bind(null, record) });
  }
  actions.push({ label: '查看详情', onClick: handleDetail.bind(null, record) });
  return actions;
}
</script>
 
<template>
  <div class="jnpf-content-wrapper">
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-content">
        <BasicVxeTable @register="registerTable">
          <template #tableTitle>
            <div>
              <div class="text-base font-medium">我的试卷</div>
              <div class="mt-1 text-gray-400 text-sm">我的试卷,选择试卷参加考试,或者查看考试详情。</div>
            </div>
          </template>
          <template #status="{ record }">
            <span :style="{ color: colorOfMyPaperStatus(record.status) }">
              {{ labelOfMyPaperStatus(record.status) }}
            </span>
          </template>
          <template #action="{ record }">
            <TableAction :actions="getTableActions(record)" />
          </template>
        </BasicVxeTable>
      </div>
    </div>
  </div>
</template>