2022-11-23 13:59:13 +08:00
|
|
|
<template>
|
|
|
|
<ContentWrap>
|
|
|
|
<!-- 列表 -->
|
|
|
|
<vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
|
|
|
|
<template #toolbar_buttons>
|
|
|
|
<XButton
|
|
|
|
type="primary"
|
|
|
|
preIcon="ep:zoom-in"
|
|
|
|
:title="t('action.import')"
|
|
|
|
v-hasPermi="['infra:codegen:create']"
|
|
|
|
@click="openImportTable()"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<template #actionbtns_default="{ row }">
|
|
|
|
<XTextButton
|
|
|
|
preIcon="ep:view"
|
|
|
|
:title="t('action.preview')"
|
|
|
|
v-hasPermi="['infra:codegen:query']"
|
|
|
|
@click="handlePreview(row.id)"
|
|
|
|
/>
|
|
|
|
<XTextButton
|
|
|
|
preIcon="ep:edit"
|
|
|
|
:title="t('action.edit')"
|
|
|
|
v-hasPermi="['infra:codegen:update']"
|
|
|
|
@click="handleUpdate(row.id)"
|
|
|
|
/>
|
|
|
|
<XTextButton
|
|
|
|
preIcon="ep:delete"
|
|
|
|
:title="t('action.del')"
|
|
|
|
v-hasPermi="['infra:codegen:delete']"
|
|
|
|
@click="handleDelete(row.id)"
|
|
|
|
/>
|
|
|
|
<XTextButton
|
|
|
|
preIcon="ep:refresh"
|
|
|
|
:title="t('action.sync')"
|
|
|
|
v-hasPermi="['infra:codegen:update']"
|
|
|
|
@click="handleSynchDb(row.id)"
|
|
|
|
/>
|
|
|
|
<XTextButton
|
|
|
|
preIcon="ep:download"
|
|
|
|
:title="t('action.generate')"
|
|
|
|
v-hasPermi="['infra:codegen:download']"
|
|
|
|
@click="handleGenTable(row.id)"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</vxe-grid>
|
|
|
|
</ContentWrap>
|
|
|
|
<ImportTable ref="importRef" @ok="handleQuery()" />
|
|
|
|
<Preview ref="previewRef" />
|
|
|
|
</template>
|
2022-07-18 19:06:37 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { ref } from 'vue'
|
2022-11-23 13:59:13 +08:00
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
import { VxeGridInstance } from 'vxe-table'
|
|
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
|
|
import { useMessage } from '@/hooks/web/useMessage'
|
|
|
|
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
|
|
|
|
import download from '@/utils/download'
|
2022-07-18 19:06:37 +08:00
|
|
|
import * as CodegenApi from '@/api/infra/codegen'
|
|
|
|
import { CodegenTableVO } from '@/api/infra/codegen/types'
|
|
|
|
import { allSchemas } from './codegen.data'
|
2022-07-25 16:53:36 +08:00
|
|
|
import { ImportTable, Preview } from './components'
|
2022-11-23 13:59:13 +08:00
|
|
|
|
2022-07-18 19:06:37 +08:00
|
|
|
const { t } = useI18n() // 国际化
|
2022-11-23 13:59:13 +08:00
|
|
|
const message = useMessage() // 消息弹窗
|
2022-07-18 19:06:37 +08:00
|
|
|
const { push } = useRouter()
|
2022-11-23 13:59:13 +08:00
|
|
|
// 列表相关的变量
|
|
|
|
const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
|
|
|
|
const { gridOptions, getList, deleteData } = useVxeGrid<CodegenTableVO>({
|
|
|
|
allSchemas: allSchemas,
|
2022-07-18 19:06:37 +08:00
|
|
|
getListApi: CodegenApi.getCodegenTablePageApi,
|
2022-11-23 13:59:13 +08:00
|
|
|
deleteApi: CodegenApi.deleteCodegenTableApi
|
2022-07-18 19:06:37 +08:00
|
|
|
})
|
2022-11-23 13:59:13 +08:00
|
|
|
|
2022-07-18 19:06:37 +08:00
|
|
|
// 导入操作
|
|
|
|
const importRef = ref()
|
|
|
|
const openImportTable = () => {
|
|
|
|
importRef.value.show()
|
|
|
|
}
|
|
|
|
// 预览操作
|
|
|
|
const previewRef = ref()
|
|
|
|
const handlePreview = (row: CodegenTableVO) => {
|
|
|
|
previewRef.value.show(row)
|
|
|
|
}
|
|
|
|
// 编辑操作
|
2022-11-23 13:59:13 +08:00
|
|
|
const handleUpdate = (rowId: number) => {
|
|
|
|
push('/codegen/edit?id=' + rowId)
|
2022-07-18 19:06:37 +08:00
|
|
|
}
|
|
|
|
// 同步操作
|
|
|
|
const handleSynchDb = (row: CodegenTableVO) => {
|
|
|
|
// 基于 DB 同步
|
|
|
|
const tableName = row.tableName
|
2022-07-21 17:42:25 +08:00
|
|
|
message
|
|
|
|
.confirm('确认要强制同步' + tableName + '表结构吗?', t('common.reminder'))
|
|
|
|
.then(async () => {
|
|
|
|
await CodegenApi.syncCodegenFromDBApi(row.id)
|
|
|
|
message.success('同步成功')
|
|
|
|
})
|
2022-07-18 19:06:37 +08:00
|
|
|
}
|
|
|
|
// 生成代码操作
|
2022-07-25 21:03:14 +08:00
|
|
|
const handleGenTable = async (row: CodegenTableVO) => {
|
|
|
|
const res = await CodegenApi.downloadCodegenApi(row.id)
|
2022-07-18 19:06:37 +08:00
|
|
|
download.zip(res, 'codegen-' + row.className + '.zip')
|
|
|
|
}
|
2022-11-23 13:59:13 +08:00
|
|
|
// 删除操作
|
|
|
|
const handleDelete = async (rowId: number) => {
|
|
|
|
await deleteData(xGrid, rowId)
|
|
|
|
}
|
2022-07-18 19:06:37 +08:00
|
|
|
// 查询操作
|
2022-11-23 13:59:13 +08:00
|
|
|
const handleQuery = async () => {
|
|
|
|
await getList(xGrid)
|
2022-07-18 19:06:37 +08:00
|
|
|
}
|
|
|
|
</script>
|