refactor: 优化代码生成相关页面

This commit is contained in:
2024-04-19 22:17:39 +08:00
parent 6321de7cac
commit 124674c530
9 changed files with 144 additions and 120 deletions

View File

@@ -18,6 +18,7 @@
"@codemirror/lang-javascript": "^6.2.1", "@codemirror/lang-javascript": "^6.2.1",
"@codemirror/lang-vue": "^0.1.2", "@codemirror/lang-vue": "^0.1.2",
"@codemirror/theme-one-dark": "^6.1.2", "@codemirror/theme-one-dark": "^6.1.2",
"@ddietr/codemirror-themes": "^1.4.2",
"@vueuse/components": "^10.5.0", "@vueuse/components": "^10.5.0",
"@vueuse/core": "^10.5.0", "@vueuse/core": "^10.5.0",
"@wangeditor/editor": "^5.1.1", "@wangeditor/editor": "^5.1.1",

14
pnpm-lock.yaml generated
View File

@@ -23,6 +23,9 @@ dependencies:
'@codemirror/theme-one-dark': '@codemirror/theme-one-dark':
specifier: ^6.1.2 specifier: ^6.1.2
version: 6.1.2 version: 6.1.2
'@ddietr/codemirror-themes':
specifier: ^1.4.2
version: 1.4.2
'@vueuse/components': '@vueuse/components':
specifier: ^10.5.0 specifier: ^10.5.0
version: 10.9.0(vue@3.4.21) version: 10.9.0(vue@3.4.21)
@@ -855,6 +858,15 @@ packages:
w3c-keyname: 2.2.8 w3c-keyname: 2.2.8
dev: false dev: false
/@ddietr/codemirror-themes@1.4.2:
resolution: {integrity: sha512-8U3H3lmtmSWLD5VRlt7jf2HW62URnwgPxjZZDYjBX5EtMpgZ2QnqiIYrNzdQPPjJngT9D43gls3+JlekCBmrfw==}
dependencies:
'@codemirror/language': 6.10.1
'@codemirror/state': 6.4.1
'@codemirror/view': 6.26.0
'@lezer/highlight': 1.2.0
dev: false
/@esbuild/aix-ppc64@0.19.12: /@esbuild/aix-ppc64@0.19.12:
resolution: {integrity: sha512-bmoCYyWdEL3wDQIVbcyzRyeKLgk2WtWLTWz1ZIAZF/EGbNOwSA6ew3PftJ1PqMiOOGu0OyFMzG53L0zqIpPeNA==} resolution: {integrity: sha512-bmoCYyWdEL3wDQIVbcyzRyeKLgk2WtWLTWz1ZIAZF/EGbNOwSA6ew3PftJ1PqMiOOGu0OyFMzG53L0zqIpPeNA==}
engines: {node: '>=12'} engines: {node: '>=12'}
@@ -6354,4 +6366,4 @@ packages:
resolution: {integrity: sha512-O3MilSi/9mwoovx77m6ROZM7sXShR/O/JIanvzTwjN3FORfLSr81PsUGd7jlaYOeds9d8tw82oP44+3YucVo+w==} resolution: {integrity: sha512-O3MilSi/9mwoovx77m6ROZM7sXShR/O/JIanvzTwjN3FORfLSr81PsUGd7jlaYOeds9d8tw82oP44+3YucVo+w==}
dependencies: dependencies:
tslib: 2.3.0 tslib: 2.3.0
dev: false dev: false

View File

@@ -13,24 +13,22 @@
import CodeMirror from 'vue-codemirror6' import CodeMirror from 'vue-codemirror6'
import { javascript } from '@codemirror/lang-javascript' import { javascript } from '@codemirror/lang-javascript'
import { vue } from '@codemirror/lang-vue' import { vue } from '@codemirror/lang-vue'
import { githubLight } from '@ddietr/codemirror-themes/github-light'
import { oneDark } from '@codemirror/theme-one-dark' import { oneDark } from '@codemirror/theme-one-dark'
import { useAppStore } from '@/stores'
const appStore = useAppStore()
const isDark = computed(() => appStore.theme === 'dark')
interface Props { interface Props {
type?: 'javascript' | 'vue' type?: 'javascript' | 'vue'
codeJson: string codeJson: string
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
type: 'javascript', type: 'javascript',
codeJson: '' codeJson: ''
}) })
const visible = ref(false)
const open = () => {
visible.value = true
}
defineExpose({ open })
const defaultConfig = { const defaultConfig = {
tabSize: 2, tabSize: 2,
basic: true, basic: true,
@@ -40,8 +38,14 @@ const defaultConfig = {
const config = defaultConfig const config = defaultConfig
const codeValue = computed(() => props.codeJson) const codeValue = computed(() => props.codeJson)
const visible = ref(false)
// 打开
const open = () => {
visible.value = true
}
const extensions = computed(() => { const extensions = computed(() => {
const arr = [oneDark] const arr = [isDark.value ? oneDark : githubLight]
if (props.type === 'javascript') { if (props.type === 'javascript') {
arr.push(javascript()) arr.push(javascript())
} }
@@ -50,6 +54,8 @@ const extensions = computed(() => {
} }
return arr return arr
}) })
defineExpose({ open })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -6,7 +6,7 @@
> >
<div class="gi-option-item__wrapper"> <div class="gi-option-item__wrapper">
<span class="gi-option-item__icon"> <span class="gi-option-item__icon">
<slot name="icon"> <slot v-if="props.icon" name="icon">
<GiSvgIcon :name="props.icon"></GiSvgIcon> <GiSvgIcon :name="props.icon"></GiSvgIcon>
</slot> </slot>
</span> </span>

View File

@@ -1,9 +1,9 @@
<template> <template>
<GiOption :class="{ shadow: props.shadow }"> <GiOption :class="{ shadow: props.shadow }">
<GiOptionItem label="重命名" icon="menu-edit" @click="onClickItem('rename')"> </GiOptionItem> <GiOptionItem label="重命名" @click="onClickItem('rename')"> </GiOptionItem>
<GiOptionItem label="详情" icon="menu-detail" @click="onClickItem('detail')"> </GiOptionItem> <GiOptionItem label="详情" @click="onClickItem('detail')"> </GiOptionItem>
<GiOptionItem label="下载" icon="menu-download" @click="onClickItem('download')"></GiOptionItem> <GiOptionItem label="下载" @click="onClickItem('download')"></GiOptionItem>
<GiOptionItem label="删除" icon="menu-delete" @click="onClickItem('delete')"> </GiOptionItem> <GiOptionItem label="删除" @click="onClickItem('delete')"> </GiOptionItem>
</GiOption> </GiOption>
</template> </template>

View File

@@ -104,7 +104,7 @@ const columns: TableInstanceColumns[] = [
title: '操作', title: '操作',
slotName: 'action', slotName: 'action',
width: 130, width: 130,
show: has.hasPermOr(['system:storage:update', 'system:storage:delete']), 3
align: 'center', align: 'center',
fixed: !isMobile() ? 'right' : undefined fixed: !isMobile() ? 'right' : undefined
} }

View File

@@ -4,107 +4,109 @@
:title="title" :title="title"
:mask-closable="false" :mask-closable="false"
:esc-to-close="false" :esc-to-close="false"
:width="width >= 1000 ? 1000 : '100%'" :width="width >= 1050 ? 1050 : '100%'"
@before-ok="save" @before-ok="save"
@close="reset" @close="reset"
> >
<a-card title="字段配置" class="field-config"> <a-tabs>
<template #extra> <a-tab-pane key="1" title="生成配置">
<a-popconfirm <a-form ref="formRef" :model="form" :rules="rules" class="gen-config" size="large">
content="是否确定同步最新数据表结构?同步后只要不点击确定保存,则不影响原有配置数据。" <a-form-item label="作者名称" field="author">
type="warning" <a-input v-model="form.author" placeholder="请输入作者名称" />
@ok="handleRefresh(form.tableName)" </a-form-item>
<a-form-item label="业务名称" field="businessName">
<a-input v-model="form.businessName" placeholder="自定义业务名称,例如:用户" />
</a-form-item>
<a-form-item label="所属模块" field="moduleName">
<a-input v-model="form.moduleName" placeholder="项目模块名称例如continew-admin-system" />
</a-form-item>
<a-form-item label="模块包名" field="packageName">
<a-input v-model="form.packageName" placeholder="项目模块包名例如top.charles7c.continew.admin.system" />
</a-form-item>
<a-form-item label="去表前缀" field="tablePrefix">
<a-input v-model="form.tablePrefix" placeholder="数据库表前缀例如sys_" />
</a-form-item>
<a-form-item label="是否覆盖" field="isOverride">
<a-radio-group v-model="form.isOverride" type="button">
<a-radio :value="true"></a-radio>
<a-radio :value="false"></a-radio>
</a-radio-group>
</a-form-item>
</a-form>
</a-tab-pane>
<a-tab-pane key="2" title="字段配置">
<GiTable
row-key="tableName"
:data="dataList"
:columns="columns"
:loading="loading"
:scroll="{ x: '100%', y: 800, minWidth: 900 }"
:pagination="false"
:disabledTools="['setting', 'refresh']"
:disabledColumnKeys="['tableName']"
> >
<a-tooltip content="同步最新数据表结构"> <template #custom-left>
<a-button <a-popconfirm
type="primary" content="是否确定同步最新数据表结构?同步后只要不点击确定保存,则不影响原有配置数据。"
status="success" type="warning"
size="small" @ok="handleRefresh(form.tableName)"
title="同步"
:disabled="dataList.length !== 0 && dataList[0].createTime === null"
> >
<template #icon><icon-sync /></template>同步 <a-tooltip content="同步最新数据表结构">
</a-button> <a-button
</a-tooltip> type="primary"
</a-popconfirm> status="success"
</template> size="small"
<GiTable title="同步"
row-key="id" :disabled="dataList.length !== 0 && dataList[0].createTime === null"
:data="dataList" >
:columns="columns" <template #icon><icon-sync /></template>同步
:loading="loading" </a-button>
:scroll="{ y: 400 }" </a-tooltip>
:pagination="false" </a-popconfirm>
:disabledTools="['setting', 'refresh']" </template>
:disabledColumnKeys="['tableName']" <template #fieldType="{ record }">
> <span v-if="record.fieldType">{{ record.fieldType }}</span>
<template #fieldType="{ record }"> <a-tooltip v-else content="请检查 generator.properties 配置">
<span v-if="record.fieldType">{{ record.fieldType }}</span> <icon-exclamation-circle-fill size="large" style="color: #f53f3f" />
<a-tooltip v-else content="请检查 generator.properties 配置"> </a-tooltip>
<icon-exclamation-circle-fill size="large" style="color: #f53f3f" /> </template>
</a-tooltip> <template #comment="{ record }">
</template> <a-input v-model="record.comment" />
<template #comment="{ record }"> </template>
<a-input v-model="record.comment" /> <template #showInList="{ record }">
</template> <a-checkbox v-model="record.showInList" value="true" />
<template #showInList="{ record }"> </template>
<a-checkbox v-model="record.showInList" value="true" /> <template #showInForm="{ record }">
</template> <a-checkbox v-model="record.showInForm" value="true" />
<template #showInForm="{ record }"> </template>
<a-checkbox v-model="record.showInForm" value="true" /> <template #isRequired="{ record }">
</template> <a-checkbox v-if="record.showInForm" v-model="record.isRequired" value="true" />
<template #isRequired="{ record }"> <a-checkbox v-else disabled />
<a-checkbox v-if="record.showInForm" v-model="record.isRequired" value="true" /> </template>
<a-checkbox v-else disabled /> <template #showInQuery="{ record }">
</template> <a-checkbox v-model="record.showInQuery" value="true" />
<template #showInQuery="{ record }"> </template>
<a-checkbox v-model="record.showInQuery" value="true" /> <template #formType="{ record }">
</template> <a-select
<template #formType="{ record }"> v-if="record.showInForm || record.showInQuery"
<a-select v-model="record.formType"
v-if="record.showInForm || record.showInQuery" :options="form_type_enum"
v-model="record.formType" placeholder="请选择表单类型"
:options="form_type_enum" />
placeholder="请选择表单类型" <span v-else>无需设置</span>
/> </template>
<span v-else>无需设置</span> <template #queryType="{ record }">
</template> <a-select
<template #queryType="{ record }"> v-if="record.showInQuery"
<a-select v-model="record.queryType"
v-if="record.showInQuery" :options="query_type_enum"
v-model="record.queryType" placeholder="请选择查询方式"
:options="query_type_enum" />
placeholder="请选择查询方式" <span v-else>无需设置</span>
/> </template>
<span v-else>无需设置</span> </GiTable>
</template> </a-tab-pane>
</GiTable> </a-tabs>
</a-card>
<a-card title="生成配置" style="margin-top: 10px">
<a-form ref="formRef" :model="form" :rules="rules" class="gen-config" size="large">
<a-form-item label="作者名称" field="author">
<a-input v-model="form.author" placeholder="请输入作者名称" />
</a-form-item>
<a-form-item label="业务名称" field="businessName">
<a-input v-model="form.businessName" placeholder="自定义业务名称,例如:用户" />
</a-form-item>
<a-form-item label="所属模块" field="moduleName">
<a-input v-model="form.moduleName" placeholder="项目模块名称例如continew-admin-system" />
</a-form-item>
<a-form-item label="模块包名" field="packageName">
<a-input v-model="form.packageName" placeholder="项目模块包名例如top.charles7c.continew.admin.system" />
</a-form-item>
<a-form-item label="去表前缀" field="tablePrefix">
<a-input v-model="form.tablePrefix" placeholder="数据库表前缀例如sys_" />
</a-form-item>
<a-form-item label="是否覆盖" field="isOverride">
<a-radio-group v-model="form.isOverride" type="button">
<a-radio :value="true"></a-radio>
<a-radio :value="false"></a-radio>
</a-radio-group>
</a-form-item>
</a-form>
</a-card>
</a-drawer> </a-drawer>
</template> </template>
@@ -213,11 +215,7 @@ const emit = defineEmits<{
defineExpose({ onConfig }) defineExpose({ onConfig })
</script> </script>
<style scoped lang="less"> <style lang="scss" scoped>
.field-config :deep(.arco-card-body) {
padding: 0;
}
:deep(.gen-config.arco-form) { :deep(.gen-config.arco-form) {
width: 50%; width: 50%;
} }

View File

@@ -1,5 +1,12 @@
<template> <template>
<a-modal v-model:visible="visible" title="生成预览" :mask-closable="false" :esc-to-close="false" width="90%"> <a-modal
v-model:visible="visible"
title="生成预览"
:mask-closable="false"
:esc-to-close="false"
width="90%"
:footer="false"
>
<div> <div>
<a-scrollbar style="height: 700px; overflow: auto"> <a-scrollbar style="height: 700px; overflow: auto">
<a-link style="position: absolute; right: 20px; top: 50px; z-index: 999" @click="onCopy"> <a-link style="position: absolute; right: 20px; top: 50px; z-index: 999" @click="onCopy">
@@ -13,7 +20,7 @@
<GiCodeView <GiCodeView
:type="'vue' === item.fileName.split('.')[1] ? 'vue' : 'javascript'" :type="'vue' === item.fileName.split('.')[1] ? 'vue' : 'javascript'"
:code-json="item.content" :code-json="item.content"
></GiCodeView> />
</a-tab-pane> </a-tab-pane>
</a-tabs> </a-tabs>
</a-scrollbar> </a-scrollbar>

View File

@@ -2,7 +2,7 @@
<div class="gi_page"> <div class="gi_page">
<a-card title="代码生成" class="general-card"> <a-card title="代码生成" class="general-card">
<GiTable <GiTable
row-key="id" row-key="tableName"
:data="dataList" :data="dataList"
:columns="columns" :columns="columns"
:loading="loading" :loading="loading"
@@ -64,7 +64,7 @@ const columns: TableInstanceColumns[] = [
{ title: '描述', dataIndex: 'comment', tooltip: true }, { title: '描述', dataIndex: 'comment', tooltip: true },
{ title: '存储引擎', dataIndex: 'engine', align: 'center' }, { title: '存储引擎', dataIndex: 'engine', align: 'center' },
{ title: '字符集', dataIndex: 'charset' }, { title: '字符集', dataIndex: 'charset' },
{ title: '创建时间', dataIndex: 'createTime' }, { title: '创建时间', dataIndex: 'createTime', width: 180 },
{ title: '操作', slotName: 'action', width: 180, align: 'center', fixed: !isMobile() ? 'right' : undefined } { title: '操作', slotName: 'action', width: 180, align: 'center', fixed: !isMobile() ? 'right' : undefined }
] ]