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
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<script lang="ts" setup>
import type { ActionItem, BasicColumn } from '@jnpf/ui/vxeTable';
 
import type { RecordListMode, TmsRecordListItem } from './types';
 
import { computed, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
 
import { useMessage } from '@jnpf/hooks';
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { Modal } from 'ant-design-vue';
 
import { archiveTmsRecords, deleteTmsRecords, getTmsRecordList } from '#/api/x/tms/record';
 
import { LIST_MODE_LABEL, RECORD_LIST_PATH } from './constants';
 
defineOptions({ name: 'TmsRecord' });
 
const route = useRoute();
const router = useRouter();
const { createMessage } = useMessage();
 
function modeFromPath(path: string): RecordListMode {
  if (path.includes('/archived')) return 'archived';
  if (path.includes('/ready')) return 'ready';
  return 'main';
}
 
const listMode = computed(() => modeFromPath(route.path));
const listModeTitle = computed(() => LIST_MODE_LABEL[listMode.value]);
const isMainView = computed(() => listMode.value === 'main');
const isReadyView = computed(() => listMode.value === 'ready');
const isArchivedView = computed(() => listMode.value === 'archived');
 
const columns: BasicColumn[] = [
  { title: '编号', dataIndex: 'recordNo', width: 140 },
  { title: '培训分类', dataIndex: 'category', width: 120 },
  {
    title: '培训主题',
    dataIndex: 'subject',
    minWidth: 280,
    slots: { default: 'subject' },
  },
  { title: '培训师', dataIndex: 'trainerName', width: 100 },
  { title: '培训类型', dataIndex: 'trainType', width: 110 },
  { title: '培训开始时间', dataIndex: 'startTime', width: 160 },
  { title: '考核方式', dataIndex: 'evalMode', width: 110 },
];
 
const [registerTable, { reload, getSelectRows }] = useVxeTable({
  api: fetchList,
  columns,
  immediate: true,
  rowKey: 'id',
  rowSelection: { type: 'checkbox' },
  useSearchForm: true,
  formConfig: {
    baseColProps: { span: 6 },
    compact: true,
    showAdvancedButton: true,
    autoAdvancedLine: 1,
    schemas: [
      {
        field: 'keyword',
        label: '关键词',
        component: 'Input',
        componentProps: { placeholder: '编号/主题/培训师', submitOnPressEnter: true },
      },
      {
        field: 'recordNo',
        label: '编号',
        component: 'Input',
        componentProps: { placeholder: '请输入编号', submitOnPressEnter: true },
      },
      {
        field: 'category',
        label: '培训分类',
        component: 'Input',
        componentProps: { placeholder: '请输入培训分类', submitOnPressEnter: true },
      },
      {
        field: 'trainerName',
        label: '培训师',
        component: 'Input',
        componentProps: { placeholder: '请输入培训师', submitOnPressEnter: true },
      },
    ],
  },
  actionColumn: {
    width: 100,
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
  },
});
 
watch(
  () => listMode.value,
  () => reload(),
);
 
async function fetchList(params: Record<string, any>) {
  return {
    data: await getTmsRecordList({
      ...params,
      listMode: listMode.value,
    }),
  };
}
 
function getSelectedRows(): TmsRecordListItem[] {
  return (getSelectRows?.() || []) as TmsRecordListItem[];
}
 
function requireOneRow(): TmsRecordListItem | null {
  const rows = getSelectedRows();
  if (!rows.length) {
    createMessage.warning('请先勾选一条记录');
    return null;
  }
  if (rows.length > 1) {
    createMessage.warning('请只勾选一条记录');
    return null;
  }
  return rows[0];
}
 
function requireRows(): TmsRecordListItem[] | null {
  const rows = getSelectedRows();
  if (!rows.length) {
    createMessage.warning('请先勾选记录');
    return null;
  }
  return rows;
}
 
function goList(mode: RecordListMode) {
  router.push(RECORD_LIST_PATH[mode]);
}
 
function handleQrcode() {
  const row = requireOneRow();
  if (!row) return;
  createMessage.success(`已生成「${row.recordNo}」签到二维码(接口联调后生效)`);
}
 
function handleAdd() {
  createMessage.info('新增培训记录(联调任务发布后由系统自动生成,手工新增待后端接口)');
}
 
function handleEdit() {
  const row = requireOneRow();
  if (!row) return;
  router.push(`/tms/record/edit/${row.id}`);
}
 
function handleView(record?: TmsRecordListItem) {
  const row = record || requireOneRow();
  if (!row) return;
  router.push({
    path: `/tms/record/detail/${row.id}`,
    query: { from: listMode.value },
  });
}
 
function handleSign() {
  const row = requireOneRow();
  if (!row) return;
  router.push(`/tms/record/sign/${row.id}`);
}
 
function handleDelete() {
  const rows = requireRows();
  if (!rows) return;
  Modal.confirm({
    title: '确认删除',
    content: `确定删除选中的 ${rows.length} 条培训记录吗?`,
    onOk: async () => {
      try {
        await deleteTmsRecords(rows.map((x) => x.id));
        createMessage.success('删除成功');
        reload();
      } catch (e: any) {
        createMessage.error(e?.message || '删除失败');
      }
    },
  });
}
 
function handleArchive() {
  const rows = requireRows();
  if (!rows) return;
  Modal.confirm({
    title: '确认归档',
    content: `确定将选中的 ${rows.length} 条记录归档吗?`,
    onOk: async () => {
      try {
        const count = await archiveTmsRecords(rows.map((x) => x.id));
        createMessage.success(`已归档 ${count} 条`);
        reload();
      } catch (e: any) {
        createMessage.error(e?.message || '归档失败');
      }
    },
  });
}
 
function getTableActions(record: TmsRecordListItem): ActionItem[] {
  const actions: ActionItem[] = [{ label: '查看', onClick: handleView.bind(null, record) }];
  if (isMainView.value) {
    actions.push({
      label: '签到',
      onClick: () => router.push(`/tms/record/sign/${record.id}`),
    });
  }
  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>
            <!-- 1. 培训记录 -->
            <a-space v-if="isMainView" wrap>
              <a-button pre-icon="icon-ym icon-ym-generator-qrcode" @click="handleQrcode">生成二维码</a-button>
              <a-button pre-icon="icon-ym icon-ym-btn-edit" @click="handleEdit">修改</a-button>
              <a-button pre-icon="icon-ym icon-ym-btn-preview" @click="handleView()">查看</a-button>
              <a-button pre-icon="icon-ym icon-ym-extend-form" @click="handleSign">签到</a-button>
              <a-button pre-icon="icon-ym icon-ym-file-text" @click="goList('ready')">可归档列表</a-button>
              <a-button pre-icon="icon-ym icon-ym-extend-folder" @click="goList('archived')">已归档列表</a-button>
              <span class="text-gray-400 text-sm">当前:{{ listModeTitle }}</span>
            </a-space>
 
            <!-- 2. 可归档列表 -->
            <a-space v-else-if="isReadyView" wrap>
              <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="handleAdd">新增</a-button>
              <a-button pre-icon="icon-ym icon-ym-btn-edit" @click="handleEdit">修改</a-button>
              <a-button danger pre-icon="icon-ym icon-ym-btn-clearn" @click="handleDelete">删除</a-button>
              <a-button pre-icon="icon-ym icon-ym-extend-folder" @click="handleArchive">归档</a-button>
              <a-button @click="goList('main')">返回</a-button>
              <a-button pre-icon="icon-ym icon-ym-file-text" @click="goList('archived')">已归档列表</a-button>
              <span class="text-gray-400 text-sm">当前:{{ listModeTitle }}</span>
            </a-space>
 
            <!-- 3. 已归档列表 -->
            <a-space v-else wrap>
              <a-button @click="handleView()">查看</a-button>
              <a-button @click="handleEdit">修改</a-button>
              <a-button @click="goList('main')">返回</a-button>
              <a-button type="primary" @click="goList('ready')">可归档列表</a-button>
              <span class="text-gray-400 text-sm">当前:{{ listModeTitle }}</span>
            </a-space>
          </template>
          <template #subject="{ record }">
            <div class="subject-cell">{{ record.subject }}</div>
          </template>
          <template #action="{ record }">
            <TableAction :actions="getTableActions(record)" />
          </template>
        </BasicVxeTable>
      </div>
    </div>
  </div>
</template>
 
<style scoped>
.subject-cell {
  white-space: pre-wrap;
  line-height: 1.45;
  word-break: break-word;
}
</style>