feat: 新增解析SQL
This commit is contained in:
parent
9dfe5d6b3e
commit
1503e91bc6
|
@ -2,7 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<link href="/favicon.png" rel="icon" type="image/svg+xml"/>
|
||||
<link href="/favicon.ico" rel="icon" type="image/svg+xml"/>
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
|
||||
<title>%VITE_APP_TITLE%</title>
|
||||
</head>
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
Binary file not shown.
Before Width: | Height: | Size: 34 KiB |
|
@ -34,12 +34,12 @@ service.interceptors.response.use(
|
|||
if (response.config.responseType === 'blob' || response.config.responseType === 'arraybuffer') {
|
||||
return response;
|
||||
}
|
||||
// const { code, data, msg } = response.data;
|
||||
// if (code === ResultEnum.SUCCESS) {
|
||||
// return data;
|
||||
// }
|
||||
|
||||
if (response.status === 200) {
|
||||
const { code, message } = response.data;
|
||||
if (code !== 200) {
|
||||
(window as any).$message.error(message);
|
||||
}
|
||||
return response.data;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
import request from '@/api/server/request';
|
||||
import type { BaseResult } from '@/types/request';
|
||||
|
||||
/* 当前数据库信息 */
|
||||
export const fetchTableInfo = (params: any) => {
|
||||
return request<any, BaseResult<any>>({
|
||||
url: '/sqlParser/tableInfo',
|
||||
method: 'POST',
|
||||
params,
|
||||
});
|
||||
};
|
||||
/* 当前数据库信息 */
|
||||
export const fetchColumnMetaData = (params: any) => {
|
||||
return request<any, BaseResult<any>>({
|
||||
url: '/sqlParser/columnMetaData',
|
||||
method: 'POST',
|
||||
params,
|
||||
});
|
||||
};
|
|
@ -3,17 +3,17 @@ import type { BaseResult } from '@/types/request';
|
|||
|
||||
/* 当前数据库信息 */
|
||||
export const getDatabaseInfoMetaData = () => {
|
||||
return request<any, any>({ url: '/table/databaseInfoMetaData', method: 'GET' });
|
||||
return request<any, BaseResult<any>>({ url: '/table/databaseInfoMetaData', method: 'GET' });
|
||||
};
|
||||
|
||||
/* 当前配置的数据库 */
|
||||
export const getCurrentDatabaseName = () => {
|
||||
return request<any, any>({ url: '/table/currentDatabaseName', method: 'GET' });
|
||||
return request<any, BaseResult<any>>({ url: '/table/currentDatabaseName', method: 'GET' });
|
||||
};
|
||||
|
||||
/* 所有的数据库 */
|
||||
export const getDatabaseList = () => {
|
||||
return request<any, any>({ url: '/table/databaseList', method: 'GET' });
|
||||
return request<any, BaseResult<any>>({ url: '/table/databaseList', method: 'GET' });
|
||||
};
|
||||
|
||||
/* 数据库所有的表 */
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 232 KiB |
|
@ -1 +0,0 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
Before Width: | Height: | Size: 496 B |
|
@ -35,7 +35,6 @@ export const useTableStore = defineStore('tableStore', {
|
|||
const result = await getDatabaseList();
|
||||
|
||||
if (result.code !== 200) {
|
||||
(window as any).$message.error(result.message);
|
||||
this.tableListLoading = false;
|
||||
return;
|
||||
}
|
||||
|
@ -59,10 +58,6 @@ export const useTableStore = defineStore('tableStore', {
|
|||
const data = { dbName: this.currentDatabaseName };
|
||||
const result = await getDatabaseTableList(data);
|
||||
|
||||
if (result.code !== 200) {
|
||||
(window as any).$message.error(result.message);
|
||||
}
|
||||
|
||||
this.tableList = result.data;
|
||||
},
|
||||
|
||||
|
@ -70,7 +65,6 @@ export const useTableStore = defineStore('tableStore', {
|
|||
async getTableMetaData(tableName: string) {
|
||||
const result = await getTableMetaData({ tableName });
|
||||
if (result.code !== 200) {
|
||||
(window as any).$message.error(result.message);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -81,7 +75,6 @@ export const useTableStore = defineStore('tableStore', {
|
|||
async getTableColumnInfo(tableName: string) {
|
||||
const result = await getTableColumnInfo({ tableName });
|
||||
if (result.code !== 200) {
|
||||
(window as any).$message.error(result.message);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -42,9 +42,6 @@ export const useVmsStore = defineStore('vmsStore', {
|
|||
async generator(data: any) {
|
||||
const result = await generator(data);
|
||||
// 需要确保已经在 setup 中执行了 window.$message = message
|
||||
if (result.code !== 200) {
|
||||
(window as any).$message.error(result.message);
|
||||
}
|
||||
|
||||
this.generators = result.data.map((i: any) => ({ ...i, path: i.path.replace('.vm', '') }));
|
||||
(window as any).$message.success(`生成成功,共 ${this.generators.length} 数据`);
|
||||
|
@ -55,7 +52,6 @@ export const useVmsStore = defineStore('vmsStore', {
|
|||
const result = await getVmsResourcePathList();
|
||||
// 需要确保已经在 setup 中执行了 window.$message = message
|
||||
if (result.code !== 200) {
|
||||
(window as any).$message.error(result.message);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -12,10 +12,16 @@ const tableStore = useTableStore();
|
|||
// 数据库中当前表的列信息
|
||||
const datalist = ref([]);
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
/* 数据库列信息 */
|
||||
const getColumnInfo = async () => {
|
||||
loading.value = true;
|
||||
|
||||
const tableName: any = route.query.tableName;
|
||||
datalist.value = await tableStore.getTableColumnInfo(tableName);
|
||||
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
|
@ -25,5 +31,5 @@ onMounted(() => {
|
|||
|
||||
<template>
|
||||
<!-- 当前表的列字段 -->
|
||||
<n-data-table :bordered="true" :columns="columns" :data="datalist" />
|
||||
<n-data-table :bordered="true" :columns="columns" :data="datalist" :loading="loading" />
|
||||
</template>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
<script lang="ts" setup>
|
||||
import { NGradientText } from 'naive-ui';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { onMounted } from 'vue';
|
||||
|
||||
import { useTableStore } from '@/store/modules/table';
|
||||
|
||||
const tableStore = useTableStore();
|
||||
const { databaseInfoMeta } = storeToRefs(tableStore);
|
||||
|
||||
onMounted(() => {
|
||||
tableStore.getDatabaseInfoMeta();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="database-info">
|
||||
<p>
|
||||
数据库产品名称:
|
||||
<n-gradient-text type="primary">{{ databaseInfoMeta?.databaseProductName }}</n-gradient-text>
|
||||
</p>
|
||||
<p>
|
||||
数据库产品版本:
|
||||
<n-gradient-text type="primary">
|
||||
{{ databaseInfoMeta?.databaseProductVersion }}
|
||||
</n-gradient-text>
|
||||
</p>
|
||||
<p>
|
||||
驱动名称:
|
||||
<n-gradient-text type="primary">{{ databaseInfoMeta?.driverName }}</n-gradient-text>
|
||||
</p>
|
||||
<p>
|
||||
数据库驱动版本:
|
||||
<n-gradient-text type="primary">{{ databaseInfoMeta?.driverVersion }}</n-gradient-text>
|
||||
</p>
|
||||
<p>
|
||||
数据库用户:
|
||||
<n-gradient-text type="primary">{{ databaseInfoMeta?.username }}</n-gradient-text>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.database-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
flex-direction: column;
|
||||
|
||||
p {
|
||||
margin: 5px 0 0 0;
|
||||
}
|
||||
}
|
||||
</style>
|
|
@ -16,6 +16,7 @@ import { onMounted, ref } from 'vue';
|
|||
import { computed } from 'vue-demi';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
import { fetchTableInfo } from '@/api/sqlParser';
|
||||
import { downloadByZip } from '@/api/vms';
|
||||
import SelectButtonGroup from '@/components/select-button-group.vue';
|
||||
import { useVmsStore } from '@/store/modules/vms';
|
||||
|
@ -40,6 +41,9 @@ const hasDownloadZip = computed(
|
|||
() => !(formOption.value.generatorWeb.length > 0 || formOption.value.generatorServer.length > 0)
|
||||
);
|
||||
|
||||
// 解析 Sql 语句
|
||||
const sql = ref();
|
||||
|
||||
/* 提交表单 */
|
||||
const onSubmit = (e: MouseEvent) => {
|
||||
e.preventDefault();
|
||||
|
@ -83,6 +87,17 @@ const downloadZipFile = async () => {
|
|||
downloadBlob(result);
|
||||
};
|
||||
|
||||
/* 解析 SQL 语句信息 */
|
||||
const sqlParser = async () => {
|
||||
const params = { sql: sql.value };
|
||||
const { data } = await fetchTableInfo(params);
|
||||
|
||||
// 设置要生成的sql表中的内容
|
||||
formValue.value.comment = data.comment;
|
||||
formValue.value.tableName = data.tableName;
|
||||
formValueInit(data.tableName);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
// 初始化表名称
|
||||
const tableName: any = route.query.tableName;
|
||||
|
@ -94,6 +109,26 @@ onMounted(() => {
|
|||
|
||||
<template>
|
||||
<n-form ref="formRef" :label-width="80" :model="formValue" :rules="rules">
|
||||
<n-grid cols="24" item-responsive responsive="screen">
|
||||
<n-form-item-gi
|
||||
label="如果有sql会生成sql中的信息,点击【解析SQL】会替换【表名称】和【注释名称】"
|
||||
path="sql"
|
||||
span="24"
|
||||
>
|
||||
<div class="flex flex-wrap flex-col w-full">
|
||||
<n-input
|
||||
v-model:value="sql"
|
||||
:autosize="{ minRows: 3 }"
|
||||
class="w-full"
|
||||
placeholder="SQL语句"
|
||||
type="textarea"
|
||||
/>
|
||||
|
||||
<n-button class="w-full mt-2" type="primary" @click="sqlParser">解析SQL</n-button>
|
||||
</div>
|
||||
</n-form-item-gi>
|
||||
</n-grid>
|
||||
|
||||
<!-- 需要提交的生成表单 -->
|
||||
<n-grid :cols="24" :x-gap="5" item-responsive responsive="screen">
|
||||
<n-form-item-gi label="作者名称" path="author" span="12 m:8 l:6">
|
||||
|
@ -104,19 +139,19 @@ onMounted(() => {
|
|||
<n-input v-model:value="formValue.requestMapping" placeholder="requestMapping名称" />
|
||||
</n-form-item-gi>
|
||||
|
||||
<n-form-item-gi label="表名称" path="tableName" span="12 m:8 l:6">
|
||||
<n-form-item-gi label="表名称" path="tableName" span="24 m:8 l:6">
|
||||
<n-input v-model:value="formValue.tableName" placeholder="表名称" />
|
||||
</n-form-item-gi>
|
||||
|
||||
<n-form-item-gi label="类名称" path="className" span="12 m:8 l:6">
|
||||
<n-form-item-gi label="类名称" path="className" span="24 m:8 l:6">
|
||||
<n-input v-model:value="formValue.className" placeholder="类名称" />
|
||||
</n-form-item-gi>
|
||||
|
||||
<n-form-item-gi label="包名称" path="packageName" span="12 m:8 l:6">
|
||||
<n-form-item-gi label="包名称" path="packageName" span="24 m:8 l:6">
|
||||
<n-input v-model:value="formValue.packageName" placeholder="包名称" />
|
||||
</n-form-item-gi>
|
||||
|
||||
<n-form-item-gi label="时间格式" path="simpleDateFormat" span="12 m:8 l:6">
|
||||
<n-form-item-gi label="时间格式" path="simpleDateFormat" span="24 m:8 l:6">
|
||||
<n-input v-model:value="formValue.simpleDateFormat" placeholder="时间格式" />
|
||||
</n-form-item-gi>
|
||||
|
||||
|
@ -124,7 +159,7 @@ onMounted(() => {
|
|||
<n-input v-model:value="formValue.tablePrefixes" placeholder="去除开头前缀" />
|
||||
</n-form-item-gi>
|
||||
|
||||
<n-form-item-gi label="修改注释名称" path="comment" span="12 m:8 l:6">
|
||||
<n-form-item-gi label="注释名称" path="comment" span="12 m:8 l:6">
|
||||
<n-input v-model:value="formValue.comment" placeholder="修改注释名称" />
|
||||
</n-form-item-gi>
|
||||
</n-grid>
|
||||
|
@ -176,13 +211,13 @@ onMounted(() => {
|
|||
|
||||
<!-- 操作选项按钮 -->
|
||||
<n-grid cols="24" item-responsive responsive="screen">
|
||||
<n-grid-item class="flex-center mt-2" span="24 m:12 l:8">
|
||||
<n-grid-item class="mt-2" span="24 m:12 l:8">
|
||||
<n-button attr-type="button" type="success" @click="selectAll">全部选择</n-button>
|
||||
<n-button attr-type="button" type="warning" @click="selectAllInvert">全部反选</n-button>
|
||||
<n-button attr-type="button" type="error" @click="selectCancelAll">全选取消</n-button>
|
||||
</n-grid-item>
|
||||
|
||||
<n-grid-item class="flex-center mt-2" span="24 m:12 l:8">
|
||||
<n-grid-item class="mt-2" span="24 m:12 l:8">
|
||||
<n-button attr-type="button" type="success" @click="onSubmit">开始生成</n-button>
|
||||
<n-button attr-type="button" type="error" @click="clearGeneratorCode">清空已生成</n-button>
|
||||
<n-button
|
||||
|
@ -195,7 +230,7 @@ onMounted(() => {
|
|||
</n-button>
|
||||
</n-grid-item>
|
||||
|
||||
<n-grid-item class="flex-center mt-2" span="24 m:12 l:8">
|
||||
<n-grid-item class="mt-2" span="24 m:12 l:8">
|
||||
<n-button
|
||||
:disabled="hasDownloadZip"
|
||||
attr-type="button"
|
||||
|
|
|
@ -6,14 +6,15 @@ import { useRoute, useRouter } from 'vue-router';
|
|||
|
||||
import { useTableStore } from '@/store/modules/table';
|
||||
import { useVmsStore } from '@/store/modules/vms';
|
||||
import Index from '@/views/generator-code/column-field/index.vue';
|
||||
import ColumnField from '@/views/generator-code/column-field/index.vue';
|
||||
import ConnectInfo from '@/views/generator-code/connect-info/index.vue';
|
||||
import GeneratorForm from '@/views/generator-code/generator/index.vue';
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const tableStore = useTableStore();
|
||||
const vmsStore = useVmsStore();
|
||||
const { formValue, formOption } = storeToRefs(vmsStore);
|
||||
const { formValue } = storeToRefs(vmsStore);
|
||||
|
||||
// 数据库表信息
|
||||
const tableInfo = reactive({
|
||||
|
@ -60,8 +61,12 @@ onMounted(() => {
|
|||
<generator-form />
|
||||
</n-tab-pane>
|
||||
|
||||
<n-tab-pane name="connect-info" tab="连接信息">
|
||||
<connect-info />
|
||||
</n-tab-pane>
|
||||
|
||||
<n-tab-pane name="columns-info" tab="列字段">
|
||||
<index />
|
||||
<column-field />
|
||||
</n-tab-pane>
|
||||
</n-tabs>
|
||||
</n-card>
|
||||
|
|
|
@ -8,8 +8,7 @@ import { useTableStore } from '@/store/modules/table';
|
|||
import { columns, renderOptions } from '@/views/home/columns';
|
||||
|
||||
const tableStore = useTableStore();
|
||||
const { databaseInfoMeta, tableList, dbList, tableListLoading, currentDatabaseName } =
|
||||
storeToRefs(tableStore);
|
||||
const { tableList, dbList, tableListLoading, currentDatabaseName } = storeToRefs(tableStore);
|
||||
|
||||
/* 更新数据库名称 */
|
||||
const onUpdateCurrentDatabaseName = (databaseName: string) => {
|
||||
|
@ -28,8 +27,6 @@ const initDatabaseTables = async () => {
|
|||
|
||||
onMounted(() => {
|
||||
initDatabaseTables();
|
||||
|
||||
tableStore.getDatabaseInfoMeta();
|
||||
tableStore.getDatabaseList();
|
||||
});
|
||||
</script>
|
||||
|
@ -43,28 +40,6 @@ onMounted(() => {
|
|||
<n-tag>注释内容</n-tag>
|
||||
跳转
|
||||
</p>
|
||||
|
||||
<p>
|
||||
数据库产品名称:
|
||||
<n-tag type="primary">{{ databaseInfoMeta.databaseProductName }}</n-tag>
|
||||
</p>
|
||||
<p>
|
||||
数据库产品版本:
|
||||
<n-tag type="primary">{{ databaseInfoMeta.databaseProductVersion }}</n-tag>
|
||||
</p>
|
||||
<p>
|
||||
驱动名称:
|
||||
<n-tag type="primary">{{ databaseInfoMeta.driverName }}</n-tag>
|
||||
</p>
|
||||
<p>
|
||||
数据库驱动版本:
|
||||
<n-tag type="primary">{{ databaseInfoMeta.driverVersion }}</n-tag>
|
||||
</p>
|
||||
<p>
|
||||
数据库用户:
|
||||
<n-tag type="primary">{{ databaseInfoMeta.username }}</n-tag>
|
||||
</p>
|
||||
|
||||
<p class="mt-2">
|
||||
数据库共
|
||||
<n-tag type="info">{{ tableList.length }}</n-tag>
|
||||
|
|
Loading…
Reference in New Issue