feat: 新增SQL数据造数功能,方便为数据库填充数据
parent
2ab8ea45da
commit
756fc1038c
|
|
@ -57,6 +57,16 @@ export type CodegenPreviewVO = {
|
||||||
code: string
|
code: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type CodegenFakeDataVO = {
|
||||||
|
tableId: string
|
||||||
|
num: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CodegenMockTypeRespVO = {
|
||||||
|
type: number
|
||||||
|
lable: string
|
||||||
|
}
|
||||||
|
|
||||||
export type CodegenUpdateReqVO = {
|
export type CodegenUpdateReqVO = {
|
||||||
table: CodegenTableVO | any
|
table: CodegenTableVO | any
|
||||||
columns: CodegenColumnVO[]
|
columns: CodegenColumnVO[]
|
||||||
|
|
@ -102,6 +112,21 @@ export const previewCodegen = (id: number) => {
|
||||||
return request.get({ url: '/infra/codegen/preview?tableId=' + id })
|
return request.get({ url: '/infra/codegen/preview?tableId=' + id })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SQL造数生成代码
|
||||||
|
export const fakeDataCodegen = (params) => {
|
||||||
|
return request.get({ url: '/infra/codegen/fake-data', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取SQL字段模拟类型列表
|
||||||
|
export const fakeDataMockTypeList = () => {
|
||||||
|
return request.get({ url: '/infra/codegen/fake-data/types' })
|
||||||
|
}
|
||||||
|
|
||||||
|
//通过模拟类型获取响应的列表参数
|
||||||
|
export const getMockParamsByMockType = (type: number) => {
|
||||||
|
return request.get({ url: '/infra/codegen/fake-data/params?mockType=' + type })
|
||||||
|
}
|
||||||
|
|
||||||
// 下载生成代码
|
// 下载生成代码
|
||||||
export const downloadCodegen = (id: number) => {
|
export const downloadCodegen = (id: number) => {
|
||||||
return request.download({ url: '/infra/codegen/download?tableId=' + id })
|
return request.download({ url: '/infra/codegen/download?tableId=' + id })
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,152 @@
|
||||||
|
<template>
|
||||||
|
<Dialog v-model="dialogVisible" title="代码预览" width="80%">
|
||||||
|
<div class="common-layout">
|
||||||
|
<el-container v-if="active == 1">
|
||||||
|
<el-header>请配置模拟类型、模拟参数以及模拟参数默认值</el-header>
|
||||||
|
<el-main>
|
||||||
|
<fake-data-colum-info-form ref="fakeDataColumInfoFormRef" :columns="formData.columns" />
|
||||||
|
</el-main>
|
||||||
|
<el-footer>
|
||||||
|
<div class="slider-demo-block">
|
||||||
|
<span class="demonstration">数据生成量</span>
|
||||||
|
<el-slider v-model="queryParams.num" :step="10" show-stops />
|
||||||
|
</div>
|
||||||
|
</el-footer>
|
||||||
|
</el-container>
|
||||||
|
<el-container v-if="active == 2">
|
||||||
|
<el-header>请配置模拟类型、模拟参数以及模拟参数默认值</el-header>
|
||||||
|
<el-main>
|
||||||
|
<div v-loading="loading" :gutter="12" element-loading-text="加载代码中..." shadow="hover">
|
||||||
|
<div>
|
||||||
|
<pre><code class="hljs" v-html="highlightedCode(previewResult)"></code></pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-main>
|
||||||
|
<el-footer
|
||||||
|
><el-button class="float-right" text type="primary" @click="copy()">
|
||||||
|
{{ t('common.copy') }}
|
||||||
|
</el-button></el-footer
|
||||||
|
>
|
||||||
|
</el-container>
|
||||||
|
</div>
|
||||||
|
<el-steps :active="active" finish-status="success">
|
||||||
|
<el-step description="请配置模拟类型、模拟参数以及模拟参数默认值" title="步骤 1" />
|
||||||
|
<el-step description="SQL" title="步骤 2" />
|
||||||
|
</el-steps>
|
||||||
|
<el-button style="margin-top: 12px" @click="next">下一步(循环)</el-button>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
|
<script lang="ts" name="InfraCodegenFakeData" setup>
|
||||||
|
import { FakeDataColumInfoForm } from './components'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import * as CodegenApi from '@/api/infra/codegen'
|
||||||
|
|
||||||
|
import 'highlight.js/styles/github.css' // 导入代码高亮样式
|
||||||
|
import hljs from 'highlight.js' // 导入代码高亮文件
|
||||||
|
import sql from 'highlight.js/lib/languages/sql'
|
||||||
|
import { useClipboard } from '@vueuse/core'
|
||||||
|
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||||
|
const loading = ref(false) // 加载中的状态
|
||||||
|
const fakeDataColumInfoFormRef = ref<ComponentRef<typeof FakeDataColumInfoForm>>()
|
||||||
|
|
||||||
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
|
const formData = ref<CodegenApi.CodegenUpdateReqVO>({
|
||||||
|
table: {},
|
||||||
|
columns: []
|
||||||
|
})
|
||||||
|
/** 获得详情 */
|
||||||
|
const getDetail = async (id: number) => {
|
||||||
|
if (!id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
formData.value = await CodegenApi.getCodegenTable(id)
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 加载sql造数代码*/
|
||||||
|
const previewResult = ref('')
|
||||||
|
const queryParams = reactive({
|
||||||
|
tableId: undefined,
|
||||||
|
num: 1
|
||||||
|
})
|
||||||
|
const getFakeData = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
previewResult.value = await CodegenApi.fakeDataCodegen(queryParams)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const active = ref(1)
|
||||||
|
|
||||||
|
const next = () => {
|
||||||
|
if (active.value == 1) {
|
||||||
|
submitForm()
|
||||||
|
getFakeData()
|
||||||
|
}
|
||||||
|
if (active.value++ > 1) active.value = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 提交按钮 */
|
||||||
|
const submitForm = async () => {
|
||||||
|
// 参数校验
|
||||||
|
if (!unref(formData)) return
|
||||||
|
try {
|
||||||
|
// 提交请求
|
||||||
|
await CodegenApi.updateCodegenTable(formData.value)
|
||||||
|
message.success(t('common.updateSuccess'))
|
||||||
|
close()
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 打开弹窗 */
|
||||||
|
const open = async (id: number) => {
|
||||||
|
//回到第一个步骤
|
||||||
|
active.value = 1
|
||||||
|
//清空上次的结果
|
||||||
|
previewResult.value = ''
|
||||||
|
//记录表单id
|
||||||
|
queryParams.tableId = id
|
||||||
|
getDetail(id)
|
||||||
|
dialogVisible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||||
|
|
||||||
|
/** 代码高亮 **/
|
||||||
|
const highlightedCode = (item) => {
|
||||||
|
const result = hljs.highlight('sql', item || '', true)
|
||||||
|
return result.value || ' '
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 复制 **/
|
||||||
|
const copy = async () => {
|
||||||
|
const { copy, copied, isSupported } = useClipboard({ source: previewResult.value })
|
||||||
|
if (!isSupported) {
|
||||||
|
message.error(t('common.copyError'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await copy()
|
||||||
|
if (unref(copied)) {
|
||||||
|
message.success(t('common.copySuccess'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onMounted) {
|
||||||
|
/** 初始化 **/
|
||||||
|
onMounted(async () => {
|
||||||
|
// 注册代码高亮的各种语言
|
||||||
|
hljs.registerLanguage('sql', sql)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<style lang="scss"></style>
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
<template>
|
||||||
|
<el-table ref="dragTable" :data="formData" :max-height="tableHeight" row-key="columnId">
|
||||||
|
<el-table-column
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
label="字段列名"
|
||||||
|
min-width="10%"
|
||||||
|
prop="columnName"
|
||||||
|
/>
|
||||||
|
<el-table-column label="字段描述" min-width="10%" prop="columnComment" />
|
||||||
|
<el-table-column
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
label="物理类型"
|
||||||
|
min-width="10%"
|
||||||
|
prop="dataType"
|
||||||
|
/>
|
||||||
|
<el-table-column label="Java类型" min-width="11%" prop="javaType" />
|
||||||
|
<el-table-column label="java属性" min-width="10%" prop="javaField" />
|
||||||
|
<el-table-column label="插入" min-width="4%" prop="createOperation" />
|
||||||
|
<el-table-column label="编辑" min-width="4%" prop="updateOperation" />
|
||||||
|
<el-table-column label="允许空" min-width="5%" prop="nullable" />
|
||||||
|
<el-table-column label="示例" min-width="10%" prop="example" />
|
||||||
|
<el-table-column label="模拟类型" min-width="11%">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-select v-model="scope.row.mockType" clearable filterable placeholder="请选择">
|
||||||
|
<el-option
|
||||||
|
v-for="dict in dictOptions"
|
||||||
|
:key="dict.label"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.type"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="模拟参数" min-width="10%">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-select
|
||||||
|
v-if="scope.row.mockType == 4"
|
||||||
|
v-model="scope.row.mockParams"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
placeholder="请选择"
|
||||||
|
>
|
||||||
|
<el-option v-for="dict in mockParamOptions" :key="dict" :label="dict" :value="dict" />
|
||||||
|
</el-select>
|
||||||
|
<el-input v-else v-model="scope.row.mockParams" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="模拟参数默认值" min-width="10%">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-input v-model="scope.row.defaultValue" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</template>
|
||||||
|
<script lang="ts" name="InfraCodegenFakeDataColumInfoForm" setup>
|
||||||
|
import { PropType } from 'vue'
|
||||||
|
import * as CodegenApi from '@/api/infra/codegen'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
columns: {
|
||||||
|
type: Array as unknown as PropType<CodegenApi.CodegenColumnVO[]>,
|
||||||
|
default: () => null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const formData = ref<CodegenApi.CodegenColumnVO[]>([])
|
||||||
|
const tableHeight = document.documentElement.scrollHeight - 350 + 'px'
|
||||||
|
|
||||||
|
/** 查询模拟类型下拉列表 */
|
||||||
|
const dictOptions = ref<CodegenApi.CodegenMockTypeRespVO[]>([])
|
||||||
|
const getDictOptions = async () => {
|
||||||
|
dictOptions.value = await CodegenApi.fakeDataMockTypeList()
|
||||||
|
}
|
||||||
|
|
||||||
|
const mockParamOptions = ref<string[]>([]) // 用户组列表
|
||||||
|
const getMockParmOptions = async () => {
|
||||||
|
mockParamOptions.value = await CodegenApi.getMockParamsByMockType(4)
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.columns,
|
||||||
|
(columns) => {
|
||||||
|
if (!columns) return
|
||||||
|
formData.value = columns
|
||||||
|
},
|
||||||
|
{
|
||||||
|
deep: true,
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await getDictOptions()
|
||||||
|
await getMockParmOptions()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import BasicInfoForm from './BasicInfoForm.vue'
|
import BasicInfoForm from './BasicInfoForm.vue'
|
||||||
import ColumInfoForm from './ColumInfoForm.vue'
|
import ColumInfoForm from './ColumInfoForm.vue'
|
||||||
import GenerateInfoForm from './GenerateInfoForm.vue'
|
import GenerateInfoForm from './GenerateInfoForm.vue'
|
||||||
export { BasicInfoForm, ColumInfoForm, GenerateInfoForm }
|
import FakeDataColumInfoForm from './FakeDataColumInfoForm.vue'
|
||||||
|
export { BasicInfoForm, ColumInfoForm, GenerateInfoForm, FakeDataColumInfoForm }
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,14 @@
|
||||||
>
|
>
|
||||||
预览
|
预览
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
v-hasPermi="['infra:codegen:preview']"
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
@click="fakeData(scope.row)"
|
||||||
|
>
|
||||||
|
造数
|
||||||
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
v-hasPermi="['infra:codegen:update']"
|
v-hasPermi="['infra:codegen:update']"
|
||||||
link
|
link
|
||||||
|
|
@ -148,6 +156,8 @@
|
||||||
<ImportTable ref="importRef" @success="getList" />
|
<ImportTable ref="importRef" @success="getList" />
|
||||||
<!-- 弹窗:预览代码 -->
|
<!-- 弹窗:预览代码 -->
|
||||||
<PreviewCode ref="previewRef" />
|
<PreviewCode ref="previewRef" />
|
||||||
|
<!-- 弹窗:造数 -->
|
||||||
|
<FakeData ref="fakeDataRef" />
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" name="InfraCodegen" setup>
|
<script lang="ts" name="InfraCodegen" setup>
|
||||||
import { dateFormatter } from '@/utils/formatTime'
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
|
|
@ -156,6 +166,7 @@ import * as CodegenApi from '@/api/infra/codegen'
|
||||||
import * as DataSourceConfigApi from '@/api/infra/dataSourceConfig'
|
import * as DataSourceConfigApi from '@/api/infra/dataSourceConfig'
|
||||||
import ImportTable from './ImportTable.vue'
|
import ImportTable from './ImportTable.vue'
|
||||||
import PreviewCode from './PreviewCode.vue'
|
import PreviewCode from './PreviewCode.vue'
|
||||||
|
import FakeData from './FakeData.vue'
|
||||||
|
|
||||||
const message = useMessage() // 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
|
|
@ -215,6 +226,12 @@ const handlePreview = (row: CodegenApi.CodegenTableVO) => {
|
||||||
previewRef.value.open(row.id)
|
previewRef.value.open(row.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 造数操作 */
|
||||||
|
const fakeDataRef = ref()
|
||||||
|
const fakeData = (row: CodegenApi.CodegenTableVO) => {
|
||||||
|
fakeDataRef.value.open(row.id)
|
||||||
|
}
|
||||||
|
|
||||||
/** 删除按钮操作 */
|
/** 删除按钮操作 */
|
||||||
const handleDelete = async (id: number) => {
|
const handleDelete = async (id: number) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue