Files
nl-mall-view/apps/web-antd/src/views/code-generation/components/fileds.vue
2025-05-13 16:53:36 +08:00

186 lines
4.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, Input, Select, Switch, Table } from 'ant-design-vue';
import filedType from '#/util/json/filedType.json';
import formType from '#/util/json/formType.json';
interface RowType {
name: string;
type: string;
type_length: string;
default: string;
comment: string;
not_null: boolean;
formShow: boolean;
tableShow: boolean;
formType: string;
search: boolean;
searchValue: string;
}
const createEmptyRow = (): RowType => ({
name: '',
type: 'varchar',
type_length: '',
default: '',
comment: '',
not_null: true,
formShow: true,
tableShow: true,
formType: 'VbenInput',
search: true,
searchValue: '=',
});
const tableData = ref<RowType[]>([createEmptyRow()]);
// 暴露常量
defineExpose({
tableData,
});
// 添加行
const addRow = () => tableData.value.push(createEmptyRow());
// 删除行
const deleteRow = (index: number) => {
if (tableData.value.length > 1) {
tableData.value.splice(index, 1);
}
};
// 表格列配置
const columns = computed(() => [
{ title: '字段名', dataIndex: 'name', width: 150 },
{ title: '类型', dataIndex: 'type', width: 120 },
{ title: '字段长度', dataIndex: 'type_length', width: 120 },
{ title: '默认值', dataIndex: 'default', width: 120 },
{ title: '注释', dataIndex: 'comment', width: 200 },
{ title: '基础配置', dataIndex: 'base', width: 100 },
{ title: '搜索配置', dataIndex: 'search', width: 120 },
{
title: '操作',
dataIndex: 'action',
width: 100,
fixed: 'right',
},
]);
</script>
<template>
<Page auto-content-height>
{{ tableData }}
<Table
:columns="columns"
:data-source="tableData"
:pagination="false"
bordered
row-key="index"
>
<template #bodyCell="{ column, record, index }">
<!-- 操作列 -->
<template v-if="column.dataIndex === 'action'">
<div class="flex gap-2">
<Button danger @click="deleteRow(index)">删除</Button>
<Button type="primary" @click="addRow"> 添加行 </Button>
</div>
</template>
<!-- 字段名编辑 -->
<template v-if="column.dataIndex === 'name'">
<Input v-model:value="record.name" autofocus />
</template>
<!-- 类型选择 -->
<template v-if="column.dataIndex === 'type'">
<Select
v-model:value="record.type"
:options="filedType"
show-search
style="width: 100%"
autofocus
/>
</template>
<!-- 默认值编辑 -->
<template v-if="column.dataIndex === 'type_length'">
<Input v-model:value="record.type_length" autofocus />
</template>
<!-- 默认值编辑 -->
<template v-if="column.dataIndex === 'default'">
<Input v-model:value="record.default" autofocus />
</template>
<!-- 注释编辑 -->
<template v-if="column.dataIndex === 'comment'">
<Input v-model:value="record.comment" autofocus />
</template>
<!-- 基础配置 -->
<template v-if="column.dataIndex === 'base'">
<!-- 开关控件 -->
<div>可以为空 <Switch v-model:checked="record.null" /></div>
<div class="mt-2">
表单显示 <Switch v-model:checked="record.formShow" />
</div>
<div class="mt-2">
表格显示 <Switch v-model:checked="record.tableShow" />
</div>
<div class="mt-2">
开启查询 <Switch v-model:checked="record.search" />
</div>
</template>
<!-- 搜索配置 -->
<template v-if="column.dataIndex === 'search'">
<!-- 开关控件 -->
<div class="mt-2">
表单类型
<Select
v-model:value="record.formType"
:options="formType"
show-search
style="width: 100%"
:disabled="!record.formShow"
autofocus
/>
</div>
<div class="mt-2">
查询类型
<Select
v-model:value="record.searchValue"
:options="[
{
label: '绝对查询',
value: '=',
},
{
label: '模糊查询',
value: 'like',
},
]"
style="width: 100%"
:disabled="!record.search"
autofocus
/>
</div>
</template>
<!-- 搜索配置 -->
<template v-if="column.dataIndex === 'formType'">
<!-- 开关控件 -->
</template>
</template>
</Table>
</Page>
</template>
<style scoped>
.ant-table-cell {
min-height: 45px;
padding: 8px 16px !important;
cursor: pointer;
}
</style>