Pre Merge pull request !791 from 刘英杰/master
commit
daf4d4fb78
|
|
@ -110,3 +110,13 @@ export const deleteCodegenTable = (id: number) => {
|
||||||
export const deleteCodegenTableList = (ids: number[]) => {
|
export const deleteCodegenTableList = (ids: number[]) => {
|
||||||
return request.delete({ url: '/infra/codegen/delete-list', params: { tableIds: ids.join(',') } })
|
return request.delete({ url: '/infra/codegen/delete-list', params: { tableIds: ids.join(',') } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 快速生成代码到指定路径
|
||||||
|
export const generateCodeToPath = (data: {
|
||||||
|
tableId: number
|
||||||
|
backendPath: string
|
||||||
|
frontendPath: string
|
||||||
|
overwrite: boolean
|
||||||
|
}) => {
|
||||||
|
return request.post({ url: '/infra/codegen/generate-to-path', data })
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,14 @@
|
||||||
>
|
>
|
||||||
生成代码
|
生成代码
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
v-hasPermi="['infra:codegen:download']"
|
||||||
|
link
|
||||||
|
type="success"
|
||||||
|
@click="handleQuickGenTable(scope.row)"
|
||||||
|
>
|
||||||
|
快速生成代码
|
||||||
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
|
|
@ -160,6 +168,47 @@
|
||||||
<ImportTable ref="importRef" @success="getList" />
|
<ImportTable ref="importRef" @success="getList" />
|
||||||
<!-- 弹窗:预览代码 -->
|
<!-- 弹窗:预览代码 -->
|
||||||
<PreviewCode ref="previewRef" />
|
<PreviewCode ref="previewRef" />
|
||||||
|
|
||||||
|
<!-- 弹窗:快速生成代码 -->
|
||||||
|
<Dialog title="快速生成代码到指定路径" v-model="quickGenDialogVisible" width="600px">
|
||||||
|
<el-form
|
||||||
|
ref="quickGenFormRef"
|
||||||
|
:model="quickGenForm"
|
||||||
|
:rules="quickGenRules"
|
||||||
|
label-width="120px"
|
||||||
|
v-loading="quickGenLoading"
|
||||||
|
>
|
||||||
|
<el-form-item label="前端路径" prop="frontendPath">
|
||||||
|
<el-input
|
||||||
|
v-model="quickGenForm.frontendPath"
|
||||||
|
placeholder="请输入前端代码生成路径,如:D:\workspace\frontend\src"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="后端路径" prop="backendPath">
|
||||||
|
<el-input
|
||||||
|
v-model="quickGenForm.backendPath"
|
||||||
|
placeholder="请输入后端代码生成路径,如:D:\workspace\backend\src"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="覆盖选项" prop="overwrite">
|
||||||
|
<el-checkbox v-model="quickGenForm.overwrite">
|
||||||
|
覆盖已存在的文件
|
||||||
|
</el-checkbox>
|
||||||
|
<div class="form-item-tip">
|
||||||
|
勾选后将覆盖目标路径中已存在的同名文件,请谨慎操作
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="submitQuickGen" type="primary" :disabled="quickGenLoading">
|
||||||
|
确 定
|
||||||
|
</el-button>
|
||||||
|
<el-button @click="quickGenDialogVisible = false">取 消</el-button>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { dateFormatter } from '@/utils/formatTime'
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
|
|
@ -188,6 +237,61 @@ const queryParams = reactive({
|
||||||
const queryFormRef = ref() // 搜索的表单
|
const queryFormRef = ref() // 搜索的表单
|
||||||
const dataSourceConfigList = ref<DataSourceConfigApi.DataSourceConfigVO[]>([]) // 数据源列表
|
const dataSourceConfigList = ref<DataSourceConfigApi.DataSourceConfigVO[]>([]) // 数据源列表
|
||||||
|
|
||||||
|
// 快速生成代码相关
|
||||||
|
const quickGenDialogVisible = ref(false) // 快速生成代码弹窗显示状态
|
||||||
|
const quickGenLoading = ref(false) // 快速生成代码加载状态
|
||||||
|
const quickGenFormRef = ref() // 快速生成代码表单引用
|
||||||
|
const currentTableRow = ref<CodegenApi.CodegenTableVO>() // 当前选中的表行数据
|
||||||
|
|
||||||
|
// 快速生成代码表单数据
|
||||||
|
const quickGenForm = reactive({
|
||||||
|
frontendPath: '',
|
||||||
|
backendPath: '',
|
||||||
|
overwrite: false
|
||||||
|
})
|
||||||
|
|
||||||
|
// 快速生成代码表单验证规则
|
||||||
|
const quickGenRules = reactive({
|
||||||
|
frontendPath: [
|
||||||
|
{ required: true, message: '请输入前端代码生成路径', trigger: 'blur' },
|
||||||
|
{
|
||||||
|
validator: (rule: any, value: string, callback: any) => {
|
||||||
|
if (!value) {
|
||||||
|
callback()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 简单的路径格式验证
|
||||||
|
const isValidPath = /^[a-zA-Z]:\\|^\/|^\./.test(value) || value.includes('/')
|
||||||
|
if (!isValidPath) {
|
||||||
|
callback(new Error('请输入有效的路径格式'))
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
trigger: 'blur'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
backendPath: [
|
||||||
|
{ required: true, message: '请输入后端代码生成路径', trigger: 'blur' },
|
||||||
|
{
|
||||||
|
validator: (rule: any, value: string, callback: any) => {
|
||||||
|
if (!value) {
|
||||||
|
callback()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 简单的路径格式验证
|
||||||
|
const isValidPath = /^[a-zA-Z]:\\|^\/|^\./.test(value) || value.includes('/')
|
||||||
|
if (!isValidPath) {
|
||||||
|
callback(new Error('请输入有效的路径格式'))
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
trigger: 'blur'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
/** 查询列表 */
|
/** 查询列表 */
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
@ -278,6 +382,60 @@ const handleGenTable = async (row: CodegenApi.CodegenTableVO) => {
|
||||||
download.zip(res, 'codegen-' + row.className + '.zip')
|
download.zip(res, 'codegen-' + row.className + '.zip')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 快速生成代码操作 */
|
||||||
|
const handleQuickGenTable = (row: CodegenApi.CodegenTableVO) => {
|
||||||
|
currentTableRow.value = row
|
||||||
|
quickGenDialogVisible.value = true
|
||||||
|
resetQuickGenForm()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** 提交快速生成代码表单 */
|
||||||
|
const submitQuickGen = async () => {
|
||||||
|
// 校验表单
|
||||||
|
if (!quickGenFormRef.value) return
|
||||||
|
await quickGenFormRef.value.validate()
|
||||||
|
|
||||||
|
// 确认操作
|
||||||
|
try {
|
||||||
|
const confirmMessage = quickGenForm.overwrite
|
||||||
|
? '确认生成代码到指定路径?这将覆盖已存在的文件!'
|
||||||
|
: '确认生成代码到指定路径?'
|
||||||
|
await message.confirm(confirmMessage, '确认操作')
|
||||||
|
} catch {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提交请求
|
||||||
|
quickGenLoading.value = true
|
||||||
|
try {
|
||||||
|
await CodegenApi.generateCodeToPath({
|
||||||
|
tableId: currentTableRow.value!.id,
|
||||||
|
backendPath: quickGenForm.backendPath,
|
||||||
|
frontendPath: quickGenForm.frontendPath,
|
||||||
|
overwrite: quickGenForm.overwrite
|
||||||
|
})
|
||||||
|
message.success('代码生成成功!')
|
||||||
|
quickGenDialogVisible.value = false
|
||||||
|
} catch (error) {
|
||||||
|
console.error('代码生成失败:', error)
|
||||||
|
message.error('代码生成失败,请检查路径是否正确')
|
||||||
|
} finally {
|
||||||
|
quickGenLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置快速生成代码表单 */
|
||||||
|
const resetQuickGenForm = () => {
|
||||||
|
quickGenForm.frontendPath = ''
|
||||||
|
quickGenForm.backendPath = ''
|
||||||
|
quickGenForm.overwrite = false
|
||||||
|
quickGenFormRef.value?.resetFields()
|
||||||
|
}
|
||||||
|
|
||||||
/** 初始化 **/
|
/** 初始化 **/
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await getList()
|
await getList()
|
||||||
|
|
@ -285,3 +443,26 @@ onMounted(async () => {
|
||||||
dataSourceConfigList.value = await DataSourceConfigApi.getDataSourceConfigList()
|
dataSourceConfigList.value = await DataSourceConfigApi.getDataSourceConfigList()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.preset-paths {
|
||||||
|
margin-top: 8px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preset-label {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #606266;
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-item-tip {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
margin-top: 4px;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue