|
@@ -0,0 +1,117 @@
|
|
|
+<template>
|
|
|
+ <div class="dsion-step2">
|
|
|
+ <BasicTable @register="registerTable">
|
|
|
+ <template #toolbar>
|
|
|
+ <a-button type="primary">导入</a-button>
|
|
|
+ <a-button type="primary" @click="handelAdd">添加</a-button>
|
|
|
+ </template>
|
|
|
+ <template #action="{ record, column }">
|
|
|
+ <TableAction :actions="createActions(record, column)" />
|
|
|
+ </template>
|
|
|
+ </BasicTable>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+ import { ref } from 'vue';
|
|
|
+ import {
|
|
|
+ BasicTable,
|
|
|
+ useTable,
|
|
|
+ TableAction,
|
|
|
+ EditRecordRow,
|
|
|
+ ActionItem,
|
|
|
+ BasicColumn,
|
|
|
+ } from '/@/components/Table';
|
|
|
+ import { table2Columns } from '../data.config';
|
|
|
+ import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
+ import { buildUUID } from '/@/utils/uuid';
|
|
|
+
|
|
|
+ const [registerTable, { insertTableDataRecord, deleteTableDataRecord }] = useTable({
|
|
|
+ // api: getEvaluateTemplatePage,
|
|
|
+ title: '班级列表',
|
|
|
+ rowKey: 'uid',
|
|
|
+ columns: table2Columns,
|
|
|
+ useSearchForm: false,
|
|
|
+ showTableSetting: true,
|
|
|
+ bordered: true,
|
|
|
+ immediate: true,
|
|
|
+ canResize: true,
|
|
|
+ pagination: false,
|
|
|
+ actionColumn: {
|
|
|
+ width: 120,
|
|
|
+ title: '操作',
|
|
|
+ dataIndex: 'action',
|
|
|
+ slots: { customRender: 'action' },
|
|
|
+ fixed: 'right',
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ const currentEditKeyRef = ref('');
|
|
|
+ const { createMessage } = useMessage();
|
|
|
+
|
|
|
+ const handelAdd = () => {
|
|
|
+ insertTableDataRecord({ uid: buildUUID() });
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleEdit = (record: EditRecordRow) => {
|
|
|
+ currentEditKeyRef.value = record.uid;
|
|
|
+ record.onEdit?.(true);
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleCancel = (record: EditRecordRow) => {
|
|
|
+ currentEditKeyRef.value = '';
|
|
|
+ record.onEdit?.(false, false);
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleDelete = (record: EditRecordRow) => {
|
|
|
+ deleteTableDataRecord(record.uid);
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleSave = async (record: EditRecordRow) => {
|
|
|
+ const valid = await record.onValid?.();
|
|
|
+ if (valid) {
|
|
|
+ await record.onEdit?.(false, true);
|
|
|
+ currentEditKeyRef.value = '';
|
|
|
+ } else {
|
|
|
+ createMessage.error({ content: '请填写正确的数据', key: 'saving' });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const createActions = (record: EditRecordRow, column: BasicColumn): ActionItem[] => {
|
|
|
+ if (!record.editable) {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ label: '编辑',
|
|
|
+ disabled: currentEditKeyRef.value ? currentEditKeyRef.value !== record.uid : false,
|
|
|
+ onClick: handleEdit.bind(null, record),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '删除',
|
|
|
+ popConfirm: {
|
|
|
+ title: '是否删除',
|
|
|
+ confirm: handleDelete.bind(null, record, column),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ label: '确定',
|
|
|
+ onClick: handleSave.bind(null, record, column),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '取消',
|
|
|
+ popConfirm: {
|
|
|
+ title: '是否取消编辑',
|
|
|
+ confirm: handleCancel.bind(null, record, column),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ };
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped>
|
|
|
+ .dsion-step2 {
|
|
|
+ margin: 24px 0;
|
|
|
+ }
|
|
|
+</style>
|