zhangwencui
8 天以前 4eaf74efba7ead917bf53155a9b9fa59c4743cf8
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
<script lang="ts" setup>
import type { InfraCodegenApi } from '#/api/infra/codegen';
import type { SystemDictTypeApi } from '#/api/system/dict/type';
 
import { nextTick, onMounted, ref, watch } from 'vue';
 
import { Checkbox, Input, Select } from 'ant-design-vue';
 
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getSimpleDictTypeList } from '#/api/system/dict/type';
 
import { useCodegenColumnTableColumns } from '../data';
 
const props = defineProps<{
  columns?: InfraCodegenApi.CodegenColumn[];
}>();
 
/** 表格配置 */
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    columns: useCodegenColumnTableColumns(),
    border: true,
    showOverflow: true,
    autoResize: true,
    keepSource: true,
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    pagerConfig: {
      enabled: false,
    },
    toolbarConfig: {
      enabled: false,
    },
  },
});
 
/** 监听外部传入的列数据 */
watch(
  () => props.columns,
  async (columns) => {
    if (!columns) {
      return;
    }
    await nextTick();
    gridApi.grid?.loadData(columns);
  },
  {
    immediate: true,
  },
);
 
/** 提供获取表格数据的方法供父组件调用 */
defineExpose({
  getData: (): InfraCodegenApi.CodegenColumn[] =>
    gridApi.grid.getData() as InfraCodegenApi.CodegenColumn[],
});
 
/** 初始化 */
const dictTypeOptions = ref<SystemDictTypeApi.DictType[]>([]); // 字典类型选项
onMounted(async () => {
  dictTypeOptions.value = await getSimpleDictTypeList();
});
 
/** 字典类型过滤:支持 type 或 name,忽略大小写 */
function filterDictTypeOption(input: string, option: any) {
  if (!option?.key) {
    return false;
  }
  const searchValue = input.toLowerCase();
  const dictType = dictTypeOptions.value.find(
    (item) => item.type === option.key,
  );
  if (!dictType) {
    return false;
  }
  return (
    dictType.type.toLowerCase().includes(searchValue) ||
    dictType.name.toLowerCase().includes(searchValue)
  );
}
</script>
 
<template>
  <Grid>
    <!-- 字段描述 -->
    <template #columnComment="{ row }">
      <Input v-model:value="row.columnComment" />
    </template>
 
    <!-- Java 类型 -->
    <template #javaType="{ row, column }">
      <Select v-model:value="row.javaType" style="width: 100%">
        <Select.Option
          v-for="option in column.params.options"
          :key="option.value"
          :value="option.value"
        >
          {{ option.label }}
        </Select.Option>
      </Select>
    </template>
    <!-- Java 属性 -->
    <template #javaField="{ row }">
      <Input v-model:value="row.javaField" />
    </template>
 
    <!-- 插入 -->
    <template #createOperation="{ row }">
      <Checkbox v-model:checked="row.createOperation" />
    </template>
    <!-- 编辑 -->
    <template #updateOperation="{ row }">
      <Checkbox v-model:checked="row.updateOperation" />
    </template>
    <!-- 列表 -->
    <template #listOperationResult="{ row }">
      <Checkbox v-model:checked="row.listOperationResult" />
    </template>
    <!-- 查询 -->
    <template #listOperation="{ row }">
      <Checkbox v-model:checked="row.listOperation" />
    </template>
 
    <!-- 查询方式 -->
    <template #listOperationCondition="{ row, column }">
      <Select v-model:value="row.listOperationCondition" class="w-full">
        <Select.Option
          v-for="option in column.params.options"
          :key="option.value"
          :value="option.value"
        >
          {{ option.label }}
        </Select.Option>
      </Select>
    </template>
 
    <!-- 允许空 -->
    <template #nullable="{ row }">
      <Checkbox v-model:checked="row.nullable" />
    </template>
 
    <!-- 显示类型 -->
    <template #htmlType="{ row, column }">
      <Select v-model:value="row.htmlType" class="w-full">
        <Select.Option
          v-for="option in column.params.options"
          :key="option.value"
          :value="option.value"
        >
          {{ option.label }}
        </Select.Option>
      </Select>
    </template>
 
    <!-- 字典类型 -->
    <template #dictType="{ row }">
      <Select
        v-model:value="row.dictType"
        class="w-full"
        allow-clear
        show-search
        :filter-option="filterDictTypeOption"
      >
        <Select.Option
          v-for="option in dictTypeOptions"
          :key="option.type"
          :value="option.type"
        >
          {{ option.name }}
        </Select.Option>
      </Select>
    </template>
 
    <!-- 示例 -->
    <template #example="{ row }">
      <Input v-model:value="row.example" />
    </template>
  </Grid>
</template>