2023-02-11 00:44:00 +08:00
|
|
|
|
<template>
|
2023-03-27 14:06:30 +08:00
|
|
|
|
<!-- 搜索 -->
|
|
|
|
|
<content-wrap>
|
2023-03-29 09:09:34 +08:00
|
|
|
|
<el-form
|
|
|
|
|
class="-mb-15px"
|
|
|
|
|
:model="queryParams"
|
|
|
|
|
ref="queryFormRef"
|
|
|
|
|
:inline="true"
|
|
|
|
|
label-width="68px"
|
|
|
|
|
>
|
2023-03-27 14:06:30 +08:00
|
|
|
|
<el-form-item label="表名称" prop="tableName">
|
|
|
|
|
<el-input
|
|
|
|
|
v-model="queryParams.tableName"
|
|
|
|
|
placeholder="请输入表名称"
|
|
|
|
|
clearable
|
|
|
|
|
@keyup.enter="handleQuery"
|
2023-03-29 09:09:34 +08:00
|
|
|
|
class="!w-240px"
|
2023-02-11 00:44:00 +08:00
|
|
|
|
/>
|
2023-03-27 14:06:30 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="表描述" prop="tableComment">
|
|
|
|
|
<el-input
|
|
|
|
|
v-model="queryParams.tableComment"
|
|
|
|
|
placeholder="请输入表描述"
|
|
|
|
|
clearable
|
|
|
|
|
@keyup.enter="handleQuery"
|
2023-03-29 09:09:34 +08:00
|
|
|
|
class="!w-240px"
|
2023-02-11 00:44:00 +08:00
|
|
|
|
/>
|
2023-03-27 14:06:30 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="创建时间" prop="createTime">
|
|
|
|
|
<el-date-picker
|
|
|
|
|
v-model="queryParams.createTime"
|
2023-03-29 09:09:34 +08:00
|
|
|
|
value-format="YYYY-MM-dd HH:mm:ss"
|
2023-03-27 14:06:30 +08:00
|
|
|
|
type="daterange"
|
|
|
|
|
start-placeholder="开始日期"
|
|
|
|
|
end-placeholder="结束日期"
|
|
|
|
|
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
|
2023-03-29 09:09:34 +08:00
|
|
|
|
class="!w-240px"
|
2023-02-11 00:44:00 +08:00
|
|
|
|
/>
|
2023-03-27 14:06:30 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item>
|
|
|
|
|
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" />搜索</el-button>
|
|
|
|
|
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" />重置</el-button>
|
|
|
|
|
<el-button type="primary" v-hasPermi="['infra:codegen:create']" @click="openImportTable()">
|
2023-03-29 09:09:34 +08:00
|
|
|
|
<Icon icon="ep:zoom-in" class="mr-5px" /> 导入
|
2023-03-27 14:06:30 +08:00
|
|
|
|
</el-button>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</content-wrap>
|
|
|
|
|
|
|
|
|
|
<!-- 列表 -->
|
|
|
|
|
<content-wrap>
|
|
|
|
|
<el-table v-loading="loading" :data="list">
|
2023-03-29 09:09:34 +08:00
|
|
|
|
<el-table-column label="数据源" align="center">
|
|
|
|
|
<template #default="scope">
|
|
|
|
|
{{
|
|
|
|
|
dataSourceConfigList.find((config) => config.id === scope.row.dataSourceConfigId)?.name
|
|
|
|
|
}}
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2023-03-27 14:06:30 +08:00
|
|
|
|
<el-table-column label="表名称" align="center" prop="tableName" width="200" />
|
|
|
|
|
<el-table-column
|
|
|
|
|
label="表描述"
|
|
|
|
|
align="center"
|
|
|
|
|
prop="tableComment"
|
|
|
|
|
:show-overflow-tooltip="true"
|
2023-03-29 09:09:34 +08:00
|
|
|
|
width="200"
|
2023-03-27 14:06:30 +08:00
|
|
|
|
/>
|
|
|
|
|
<el-table-column label="实体" align="center" prop="className" width="200" />
|
|
|
|
|
<el-table-column
|
|
|
|
|
label="创建时间"
|
|
|
|
|
align="center"
|
|
|
|
|
prop="createTime"
|
|
|
|
|
width="180"
|
|
|
|
|
:formatter="dateFormatter"
|
|
|
|
|
/>
|
|
|
|
|
<el-table-column
|
|
|
|
|
label="更新时间"
|
|
|
|
|
align="center"
|
|
|
|
|
prop="createTime"
|
|
|
|
|
width="180"
|
|
|
|
|
:formatter="dateFormatter"
|
|
|
|
|
/>
|
2023-03-29 09:09:34 +08:00
|
|
|
|
<el-table-column label="操作" align="center" width="300px" fixed="right">
|
2023-03-27 14:06:30 +08:00
|
|
|
|
<template #default="scope">
|
|
|
|
|
<el-button
|
|
|
|
|
link
|
|
|
|
|
type="primary"
|
|
|
|
|
@click="handlePreview(scope.row)"
|
|
|
|
|
v-hasPermi="['infra:codegen:preview']"
|
|
|
|
|
>
|
2023-03-29 09:09:34 +08:00
|
|
|
|
预览
|
|
|
|
|
</el-button>
|
2023-03-27 14:06:30 +08:00
|
|
|
|
<el-button
|
|
|
|
|
link
|
|
|
|
|
type="primary"
|
|
|
|
|
@click="handleUpdate(scope.row.id)"
|
|
|
|
|
v-hasPermi="['infra:codegen:update']"
|
|
|
|
|
>
|
2023-03-29 09:09:34 +08:00
|
|
|
|
编辑
|
|
|
|
|
</el-button>
|
2023-03-27 14:06:30 +08:00
|
|
|
|
<el-button
|
|
|
|
|
link
|
|
|
|
|
type="danger"
|
|
|
|
|
@click="handleDelete(scope.row.id)"
|
|
|
|
|
v-hasPermi="['infra:codegen:delete']"
|
|
|
|
|
>
|
2023-03-29 09:09:34 +08:00
|
|
|
|
删除
|
|
|
|
|
</el-button>
|
2023-03-27 14:06:30 +08:00
|
|
|
|
<el-button
|
|
|
|
|
link
|
|
|
|
|
type="primary"
|
2023-03-29 09:09:34 +08:00
|
|
|
|
@click="handleSyncDB(scope.row)"
|
2023-03-27 14:06:30 +08:00
|
|
|
|
v-hasPermi="['infra:codegen:update']"
|
|
|
|
|
>
|
2023-03-29 09:09:34 +08:00
|
|
|
|
同步
|
|
|
|
|
</el-button>
|
2023-03-27 14:06:30 +08:00
|
|
|
|
<el-button
|
|
|
|
|
link
|
|
|
|
|
type="primary"
|
|
|
|
|
@click="handleGenTable(scope.row)"
|
|
|
|
|
v-hasPermi="['infra:codegen:download']"
|
|
|
|
|
>
|
2023-03-29 09:09:34 +08:00
|
|
|
|
生成代码
|
|
|
|
|
</el-button>
|
2023-03-27 14:06:30 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
2023-03-29 09:09:34 +08:00
|
|
|
|
<!-- 分页 -->
|
|
|
|
|
<Pagination
|
2023-03-27 14:06:30 +08:00
|
|
|
|
:total="total"
|
|
|
|
|
v-model:page="queryParams.pageNo"
|
|
|
|
|
v-model:limit="queryParams.pageSize"
|
|
|
|
|
@pagination="getList"
|
|
|
|
|
/>
|
|
|
|
|
</content-wrap>
|
|
|
|
|
|
2023-02-11 00:44:00 +08:00
|
|
|
|
<!-- 弹窗:导入表 -->
|
2023-03-29 09:09:34 +08:00
|
|
|
|
<ImportTable ref="importRef" @ok="getList" />
|
2023-02-11 00:44:00 +08:00
|
|
|
|
<!-- 弹窗:预览代码 -->
|
|
|
|
|
<Preview ref="previewRef" />
|
|
|
|
|
</template>
|
|
|
|
|
<script setup lang="ts" name="Codegen">
|
2023-03-29 09:09:34 +08:00
|
|
|
|
import { dateFormatter } from '@/utils/formatTime'
|
2023-02-11 00:44:00 +08:00
|
|
|
|
import download from '@/utils/download'
|
|
|
|
|
import * as CodegenApi from '@/api/infra/codegen'
|
2023-03-27 14:06:30 +08:00
|
|
|
|
import * as DataSourceConfigApi from '@/api/infra/dataSourceConfig'
|
2023-02-11 00:44:00 +08:00
|
|
|
|
import { ImportTable, Preview } from './components'
|
|
|
|
|
const message = useMessage() // 消息弹窗
|
2023-03-27 14:06:30 +08:00
|
|
|
|
const { t } = useI18n() // 国际化
|
2023-02-11 00:44:00 +08:00
|
|
|
|
const { push } = useRouter() // 路由跳转
|
2023-03-27 14:06:30 +08:00
|
|
|
|
|
|
|
|
|
const loading = ref(true) // 列表的加载中
|
|
|
|
|
const total = ref(0) // 列表的总页数
|
|
|
|
|
const list = ref([]) // 列表的数据
|
|
|
|
|
const queryParams = reactive({
|
|
|
|
|
pageNo: 1,
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
tableName: undefined,
|
|
|
|
|
tableComment: undefined,
|
|
|
|
|
createTime: []
|
2023-02-11 00:44:00 +08:00
|
|
|
|
})
|
2023-03-27 14:06:30 +08:00
|
|
|
|
const queryFormRef = ref() // 搜索的表单
|
2023-03-29 09:09:34 +08:00
|
|
|
|
const dataSourceConfigList = ref<DataSourceConfigApi.DataSourceConfigVO[]>([]) // 数据源列表
|
2023-03-27 14:06:30 +08:00
|
|
|
|
|
|
|
|
|
/** 查询参数列表 */
|
|
|
|
|
const getList = async () => {
|
|
|
|
|
loading.value = true
|
|
|
|
|
try {
|
|
|
|
|
const data = await CodegenApi.getCodegenTablePage(queryParams)
|
|
|
|
|
list.value = data.list
|
|
|
|
|
total.value = data.total
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 搜索按钮操作 */
|
|
|
|
|
const handleQuery = () => {
|
|
|
|
|
queryParams.pageNo = 1
|
|
|
|
|
getList()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 重置按钮操作 */
|
|
|
|
|
const resetQuery = () => {
|
|
|
|
|
queryFormRef.value.resetFields()
|
|
|
|
|
handleQuery()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-11 00:44:00 +08:00
|
|
|
|
// 导入操作
|
|
|
|
|
const importRef = ref()
|
|
|
|
|
const openImportTable = () => {
|
|
|
|
|
importRef.value.show()
|
|
|
|
|
}
|
2023-03-29 09:09:34 +08:00
|
|
|
|
|
|
|
|
|
/** 编辑操作 */
|
|
|
|
|
const handleUpdate = (id: number) => {
|
|
|
|
|
push('/codegen/edit?id=' + id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 预览操作 */
|
2023-02-11 00:44:00 +08:00
|
|
|
|
const previewRef = ref()
|
2023-03-29 09:09:34 +08:00
|
|
|
|
const handlePreview = (row: CodegenApi.CodegenTableVO) => {
|
2023-03-27 14:06:30 +08:00
|
|
|
|
previewRef.value.openModal(row.id)
|
2023-02-11 00:44:00 +08:00
|
|
|
|
}
|
2023-03-27 14:06:30 +08:00
|
|
|
|
|
|
|
|
|
/** 删除按钮操作 */
|
|
|
|
|
const handleDelete = async (id: number) => {
|
|
|
|
|
try {
|
|
|
|
|
// 删除的二次确认
|
|
|
|
|
await message.delConfirm()
|
|
|
|
|
// 发起删除
|
|
|
|
|
await CodegenApi.deleteCodegenTable(id)
|
|
|
|
|
message.success(t('common.delSuccess'))
|
|
|
|
|
// 刷新列表
|
|
|
|
|
await getList()
|
|
|
|
|
} catch {}
|
|
|
|
|
}
|
2023-03-29 09:09:34 +08:00
|
|
|
|
|
|
|
|
|
/** 同步操作 */
|
|
|
|
|
const handleSyncDB = async (row: CodegenApi.CodegenTableVO) => {
|
2023-02-11 00:44:00 +08:00
|
|
|
|
// 基于 DB 同步
|
|
|
|
|
const tableName = row.tableName
|
2023-03-27 14:06:30 +08:00
|
|
|
|
try {
|
|
|
|
|
await message.confirm('确认要强制同步' + tableName + '表结构吗?', t('common.reminder'))
|
|
|
|
|
await CodegenApi.syncCodegenFromDB(row.id)
|
|
|
|
|
message.success('同步成功')
|
|
|
|
|
} catch {}
|
2023-02-11 00:44:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 09:09:34 +08:00
|
|
|
|
/** 生成代码操作 */
|
|
|
|
|
const handleGenTable = async (row: CodegenApi.CodegenTableVO) => {
|
2023-03-27 14:06:30 +08:00
|
|
|
|
const res = await CodegenApi.downloadCodegen(row.id)
|
2023-02-11 00:44:00 +08:00
|
|
|
|
download.zip(res, 'codegen-' + row.className + '.zip')
|
|
|
|
|
}
|
2023-03-29 09:09:34 +08:00
|
|
|
|
|
|
|
|
|
/** 初始化 **/
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await getList()
|
|
|
|
|
// 加载数据源列表
|
|
|
|
|
dataSourceConfigList.value = await DataSourceConfigApi.getDataSourceConfigList()
|
|
|
|
|
})
|
2023-02-11 00:44:00 +08:00
|
|
|
|
</script>
|