办学质量监测教学评价系统
康鲁杰
2 小时以前 38a626b58763f903f5580d49854a420681925092
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
<script setup lang="ts">
import type { Ref } from 'vue';
 
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { GenInfo } from '#/api/tool/gen/model';
 
import { inject } from 'vue';
 
import { useVbenVxeGrid } from '#/adapter/vxe-table';
 
import { validRules, vxeTableColumns } from './gen-data';
 
/**
 * 从父组件注入
 */
const genInfoData = inject('genInfoData') as Ref<GenInfo['info']>;
 
const gridOptions: VxeGridProps = {
  columns: vxeTableColumns,
  keepSource: true,
  editConfig: { trigger: 'click', mode: 'cell', showStatus: true },
  editRules: validRules,
  rowConfig: {
    keyField: 'id',
    isCurrent: true, // 高亮当前行
  },
  columnConfig: {
    resizable: true,
  },
  proxyConfig: {
    enabled: true,
  },
  toolbarConfig: {
    enabled: false,
  },
  height: 'auto',
  pagerConfig: {
    enabled: false,
  },
  data: genInfoData.value.columns,
};
 
const [BasicTable, tableApi] = useVbenVxeGrid({ gridOptions });
 
/**
 * 校验表格数据
 */
async function validateTable() {
  const hasError = await tableApi.grid.validate();
  return !hasError;
}
 
/**
 * 获取表格数据
 */
function getTableRecords() {
  return tableApi?.grid?.getData?.() ?? [];
}
 
defineExpose({
  validateTable,
  getTableRecords,
});
</script>
 
<template>
  <div class="flex flex-col gap-[16px]">
    <div class="h-[calc(100vh-200px)] overflow-y-hidden">
      <BasicTable />
    </div>
  </div>
</template>