提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<!-- 搜索 --> |
|
3 |
<ContentWrap> |
|
4 |
<el-form |
|
5 |
ref="queryFormRef" |
|
6 |
:inline="true" |
|
7 |
:model="queryParams" |
|
8 |
class="-mb-15px" |
|
9 |
label-width="68px" |
|
10 |
> |
|
11 |
<el-form-item label="表名称" prop="tableName"> |
|
12 |
<el-input |
|
13 |
v-model="queryParams.tableName" |
|
14 |
class="!w-240px" |
|
15 |
clearable |
|
16 |
placeholder="请输入表名称" |
|
17 |
@keyup.enter="handleQuery" |
|
18 |
/> |
|
19 |
</el-form-item> |
|
20 |
<el-form-item label="表描述" prop="tableComment"> |
|
21 |
<el-input |
|
22 |
v-model="queryParams.tableComment" |
|
23 |
class="!w-240px" |
|
24 |
clearable |
|
25 |
placeholder="请输入表描述" |
|
26 |
@keyup.enter="handleQuery" |
|
27 |
/> |
|
28 |
</el-form-item> |
|
29 |
<el-form-item label="创建时间" prop="createTime"> |
|
30 |
<el-date-picker |
|
31 |
v-model="queryParams.createTime" |
|
32 |
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" |
|
33 |
class="!w-240px" |
|
34 |
end-placeholder="结束日期" |
|
35 |
start-placeholder="开始日期" |
|
36 |
type="daterange" |
|
37 |
value-format="YYYY-MM-DD HH:mm:ss" |
|
38 |
/> |
|
39 |
</el-form-item> |
|
40 |
<el-form-item> |
|
41 |
<el-button @click="handleQuery"> |
|
42 |
<Icon class="mr-5px" icon="ep:search" /> |
|
43 |
搜索 |
|
44 |
</el-button> |
|
45 |
<el-button @click="resetQuery"> |
|
46 |
<Icon class="mr-5px" icon="ep:refresh" /> |
|
47 |
重置 |
|
48 |
</el-button> |
|
49 |
<el-button v-hasPermi="['infra:codegen:create']" type="primary" @click="openImportTable()"> |
|
50 |
<Icon class="mr-5px" icon="ep:zoom-in" /> |
|
51 |
导入 |
|
52 |
</el-button> |
|
53 |
</el-form-item> |
|
54 |
</el-form> |
|
55 |
</ContentWrap> |
|
56 |
|
|
57 |
<!-- 列表 --> |
|
58 |
<ContentWrap> |
|
59 |
<el-table v-loading="loading" :data="list"> |
|
60 |
<el-table-column align="center" label="数据源"> |
|
61 |
<template #default="scope"> |
|
62 |
{{ |
|
63 |
dataSourceConfigList.find((config) => config.id === scope.row.dataSourceConfigId)?.name |
|
64 |
}} |
|
65 |
</template> |
|
66 |
</el-table-column> |
|
67 |
<el-table-column align="center" label="表名称" prop="tableName" width="200" /> |
|
68 |
<el-table-column |
|
69 |
:show-overflow-tooltip="true" |
|
70 |
align="center" |
|
71 |
label="表描述" |
|
72 |
prop="tableComment" |
|
73 |
width="200" |
|
74 |
/> |
|
75 |
<el-table-column align="center" label="实体" prop="className" width="200" /> |
|
76 |
<el-table-column |
|
77 |
:formatter="dateFormatter" |
|
78 |
align="center" |
|
79 |
label="创建时间" |
|
80 |
prop="createTime" |
|
81 |
width="180" |
|
82 |
/> |
|
83 |
<el-table-column |
|
84 |
:formatter="dateFormatter" |
|
85 |
align="center" |
|
86 |
label="更新时间" |
|
87 |
prop="createTime" |
|
88 |
width="180" |
|
89 |
/> |
|
90 |
<el-table-column align="center" fixed="right" label="操作" width="300px"> |
|
91 |
<template #default="scope"> |
|
92 |
<el-button |
|
93 |
v-hasPermi="['infra:codegen:preview']" |
|
94 |
link |
|
95 |
type="primary" |
|
96 |
@click="handlePreview(scope.row)" |
|
97 |
> |
|
98 |
预览 |
|
99 |
</el-button> |
|
100 |
<el-button |
|
101 |
v-hasPermi="['infra:codegen:update']" |
|
102 |
link |
|
103 |
type="primary" |
|
104 |
@click="handleUpdate(scope.row.id)" |
|
105 |
> |
|
106 |
编辑 |
|
107 |
</el-button> |
|
108 |
<el-button |
|
109 |
v-hasPermi="['infra:codegen:delete']" |
|
110 |
link |
|
111 |
type="danger" |
|
112 |
@click="handleDelete(scope.row.id)" |
|
113 |
> |
|
114 |
删除 |
|
115 |
</el-button> |
|
116 |
<el-button |
|
117 |
v-hasPermi="['infra:codegen:update']" |
|
118 |
link |
|
119 |
type="primary" |
|
120 |
@click="handleSyncDB(scope.row)" |
|
121 |
> |
|
122 |
同步 |
|
123 |
</el-button> |
|
124 |
<el-button |
|
125 |
v-hasPermi="['infra:codegen:download']" |
|
126 |
link |
|
127 |
type="primary" |
|
128 |
@click="handleGenTable(scope.row)" |
|
129 |
> |
|
130 |
生成代码 |
|
131 |
</el-button> |
|
132 |
</template> |
|
133 |
</el-table-column> |
|
134 |
</el-table> |
|
135 |
<!-- 分页 --> |
|
136 |
<Pagination |
|
137 |
v-model:limit="queryParams.pageSize" |
|
138 |
v-model:page="queryParams.pageNo" |
|
139 |
:total="total" |
|
140 |
@pagination="getList" |
|
141 |
/> |
|
142 |
</ContentWrap> |
|
143 |
|
|
144 |
<!-- 弹窗:导入表 --> |
|
145 |
<ImportTable ref="importRef" @success="getList" /> |
|
146 |
<!-- 弹窗:预览代码 --> |
|
147 |
<PreviewCode ref="previewRef" /> |
|
148 |
</template> |
|
149 |
<script lang="ts" setup> |
|
150 |
import { dateFormatter } from '@/utils/formatTime' |
|
151 |
import download from '@/utils/download' |
|
152 |
import * as CodegenApi from '@/api/infra/codegen' |
|
153 |
import * as DataSourceConfigApi from '@/api/infra/dataSourceConfig' |
|
154 |
import ImportTable from './ImportTable.vue' |
|
155 |
import PreviewCode from './PreviewCode.vue' |
|
156 |
|
|
157 |
defineOptions({ name: 'InfraCodegen' }) |
|
158 |
|
|
159 |
const message = useMessage() // 消息弹窗 |
|
160 |
const { t } = useI18n() // 国际化 |
|
161 |
const { push } = useRouter() // 路由跳转 |
|
162 |
|
|
163 |
const loading = ref(true) // 列表的加载中 |
|
164 |
const total = ref(0) // 列表的总页数 |
|
165 |
const list = ref([]) // 列表的数据 |
|
166 |
const queryParams = reactive({ |
|
167 |
pageNo: 1, |
|
168 |
pageSize: 10, |
|
169 |
tableName: undefined, |
|
170 |
tableComment: undefined, |
|
171 |
createTime: [] |
|
172 |
}) |
|
173 |
const queryFormRef = ref() // 搜索的表单 |
|
174 |
const dataSourceConfigList = ref<DataSourceConfigApi.DataSourceConfigVO[]>([]) // 数据源列表 |
|
175 |
|
|
176 |
/** 查询列表 */ |
|
177 |
const getList = async () => { |
|
178 |
loading.value = true |
|
179 |
try { |
|
180 |
const data = await CodegenApi.getCodegenTablePage(queryParams) |
|
181 |
list.value = data.list |
|
182 |
total.value = data.total |
|
183 |
} finally { |
|
184 |
loading.value = false |
|
185 |
} |
|
186 |
} |
|
187 |
|
|
188 |
/** 搜索按钮操作 */ |
|
189 |
const handleQuery = () => { |
|
190 |
queryParams.pageNo = 1 |
|
191 |
getList() |
|
192 |
} |
|
193 |
|
|
194 |
/** 重置按钮操作 */ |
|
195 |
const resetQuery = () => { |
|
196 |
queryFormRef.value.resetFields() |
|
197 |
handleQuery() |
|
198 |
} |
|
199 |
|
|
200 |
/** 导入操作 */ |
|
201 |
const importRef = ref() |
|
202 |
const openImportTable = () => { |
|
203 |
importRef.value.open() |
|
204 |
} |
|
205 |
|
|
206 |
/** 编辑操作 */ |
|
207 |
const handleUpdate = (id: number) => { |
|
208 |
push('/codegen/edit?id=' + id) |
|
209 |
} |
|
210 |
|
|
211 |
/** 预览操作 */ |
|
212 |
const previewRef = ref() |
|
213 |
const handlePreview = (row: CodegenApi.CodegenTableVO) => { |
|
214 |
previewRef.value.open(row.id) |
|
215 |
} |
|
216 |
|
|
217 |
/** 删除按钮操作 */ |
|
218 |
const handleDelete = async (id: number) => { |
|
219 |
try { |
|
220 |
// 删除的二次确认 |
|
221 |
await message.delConfirm() |
|
222 |
// 发起删除 |
|
223 |
await CodegenApi.deleteCodegenTable(id) |
|
224 |
message.success(t('common.delSuccess')) |
|
225 |
// 刷新列表 |
|
226 |
await getList() |
|
227 |
} catch {} |
|
228 |
} |
|
229 |
|
|
230 |
/** 同步操作 */ |
|
231 |
const handleSyncDB = async (row: CodegenApi.CodegenTableVO) => { |
|
232 |
// 基于 DB 同步 |
|
233 |
const tableName = row.tableName |
|
234 |
try { |
|
235 |
await message.confirm('确认要强制同步' + tableName + '表结构吗?', t('common.reminder')) |
|
236 |
await CodegenApi.syncCodegenFromDB(row.id) |
|
237 |
message.success('同步成功') |
|
238 |
} catch {} |
|
239 |
} |
|
240 |
|
|
241 |
/** 生成代码操作 */ |
|
242 |
const handleGenTable = async (row: CodegenApi.CodegenTableVO) => { |
|
243 |
const res = await CodegenApi.downloadCodegen(row.id) |
|
244 |
download.zip(res, 'codegen-' + row.className + '.zip') |
|
245 |
} |
|
246 |
|
|
247 |
/** 初始化 **/ |
|
248 |
onMounted(async () => { |
|
249 |
await getList() |
|
250 |
// 加载数据源列表 |
|
251 |
dataSourceConfigList.value = await DataSourceConfigApi.getDataSourceConfigList() |
|
252 |
}) |
|
253 |
</script> |