| @ -5,7 +5,6 @@ import { AxiosPromise } from 'axios'; | |||||||
| // 查询生成表数据 | // 查询生成表数据 | ||||||
| export const listTable = (query: TableQuery): AxiosPromise<TableVO[]> => { | export const listTable = (query: TableQuery): AxiosPromise<TableVO[]> => { | ||||||
|   return request({ |   return request({ | ||||||
|     headers: { datasource: localStorage.getItem('dataName') }, |  | ||||||
|     url: '/tool/gen/list', |     url: '/tool/gen/list', | ||||||
|     method: 'get', |     method: 'get', | ||||||
|     params: query |     params: query | ||||||
| @ -14,7 +13,6 @@ export const listTable = (query: TableQuery): AxiosPromise<TableVO[]> => { | |||||||
| // 查询db数据库列表 | // 查询db数据库列表 | ||||||
| export const listDbTable = (query: DbTableQuery): AxiosPromise<DbTableVO[]> => { | export const listDbTable = (query: DbTableQuery): AxiosPromise<DbTableVO[]> => { | ||||||
|   return request({ |   return request({ | ||||||
|     headers: { datasource: localStorage.getItem('dataName') }, |  | ||||||
|     url: '/tool/gen/db/list', |     url: '/tool/gen/db/list', | ||||||
|     method: 'get', |     method: 'get', | ||||||
|     params: query |     params: query | ||||||
| @ -24,7 +22,6 @@ export const listDbTable = (query: DbTableQuery): AxiosPromise<DbTableVO[]> => { | |||||||
| // 查询表详细信息 | // 查询表详细信息 | ||||||
| export const getGenTable = (tableId: string | number): AxiosPromise<GenTableVO> => { | export const getGenTable = (tableId: string | number): AxiosPromise<GenTableVO> => { | ||||||
|   return request({ |   return request({ | ||||||
|     headers: { datasource: localStorage.getItem('dataName') }, |  | ||||||
|     url: '/tool/gen/' + tableId, |     url: '/tool/gen/' + tableId, | ||||||
|     method: 'get' |     method: 'get' | ||||||
|   }); |   }); | ||||||
| @ -33,7 +30,6 @@ export const getGenTable = (tableId: string | number): AxiosPromise<GenTableVO> | |||||||
| // 修改代码生成信息 | // 修改代码生成信息 | ||||||
| export const updateGenTable = (data: DbTableForm) => { | export const updateGenTable = (data: DbTableForm) => { | ||||||
|   return request({ |   return request({ | ||||||
|     headers: { datasource: localStorage.getItem('dataName') }, |  | ||||||
|     url: '/tool/gen', |     url: '/tool/gen', | ||||||
|     method: 'put', |     method: 'put', | ||||||
|     data: data |     data: data | ||||||
| @ -41,9 +37,8 @@ export const updateGenTable = (data: DbTableForm) => { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| // 导入表 | // 导入表 | ||||||
| export const importTable = (data: { tables: string }) => { | export const importTable = (data: { tables: string, dataName: string }) => { | ||||||
|   return request({ |   return request({ | ||||||
|     headers: { datasource: localStorage.getItem('dataName') }, |  | ||||||
|     url: '/tool/gen/importTable', |     url: '/tool/gen/importTable', | ||||||
|     method: 'post', |     method: 'post', | ||||||
|     params: data |     params: data | ||||||
| @ -53,7 +48,6 @@ export const importTable = (data: { tables: string }) => { | |||||||
| // 预览生成代码 | // 预览生成代码 | ||||||
| export const previewTable = (tableId: string | number) => { | export const previewTable = (tableId: string | number) => { | ||||||
|   return request({ |   return request({ | ||||||
|     headers: { datasource: localStorage.getItem('dataName') }, |  | ||||||
|     url: '/tool/gen/preview/' + tableId, |     url: '/tool/gen/preview/' + tableId, | ||||||
|     method: 'get' |     method: 'get' | ||||||
|   }); |   }); | ||||||
| @ -62,26 +56,31 @@ export const previewTable = (tableId: string | number) => { | |||||||
| // 删除表数据 | // 删除表数据 | ||||||
| export const delTable = (tableId: string | number | Array<string | number>) => { | export const delTable = (tableId: string | number | Array<string | number>) => { | ||||||
|   return request({ |   return request({ | ||||||
|     headers: { datasource: localStorage.getItem('dataName') }, |  | ||||||
|     url: '/tool/gen/' + tableId, |     url: '/tool/gen/' + tableId, | ||||||
|     method: 'delete' |     method: 'delete' | ||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| // 生成代码(自定义路径) | // 生成代码(自定义路径) | ||||||
| export const genCode = (tableName: string) => { | export const genCode = (tableId: string | number) => { | ||||||
|   return request({ |   return request({ | ||||||
|     headers: { datasource: localStorage.getItem('dataName') }, |     url: '/tool/gen/genCode/' + tableId, | ||||||
|     url: '/tool/gen/genCode/' + tableName, |  | ||||||
|     method: 'get' |     method: 'get' | ||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| // 同步数据库 | // 同步数据库 | ||||||
| export const synchDb = (tableName: string) => { | export const synchDb = (tableId: string | number) => { | ||||||
|   return request({ |   return request({ | ||||||
|     headers: { datasource: localStorage.getItem('dataName') }, |     url: '/tool/gen/synchDb/' + tableId, | ||||||
|     url: '/tool/gen/synchDb/' + tableName, |     method: 'get' | ||||||
|  |   }); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | // 获取数据源名称 | ||||||
|  | export const getDataNames = () => { | ||||||
|  |   return request({ | ||||||
|  |     url: '/tool/gen/getDataNames', | ||||||
|     method: 'get' |     method: 'get' | ||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
| @ -1,6 +1,7 @@ | |||||||
| export interface TableVO extends BaseEntity { | export interface TableVO extends BaseEntity { | ||||||
|   createDept: number | string; |   createDept: number | string; | ||||||
|   tableId: string | number; |   tableId: string | number; | ||||||
|  |   dataName: string; | ||||||
|   tableName: string; |   tableName: string; | ||||||
|   tableComment: string; |   tableComment: string; | ||||||
|   subTableName?: any; |   subTableName?: any; | ||||||
| @ -97,6 +98,7 @@ export interface DbTableVO { | |||||||
| } | } | ||||||
|  |  | ||||||
| export interface DbTableQuery extends PageQuery { | export interface DbTableQuery extends PageQuery { | ||||||
|  |   dataName: string; | ||||||
|   tableName: string; |   tableName: string; | ||||||
|   tableComment: string; |   tableComment: string; | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,7 +1,12 @@ | |||||||
| <template> | <template> | ||||||
|   <!-- 导入表 --> |   <!-- 导入表 --> | ||||||
|   <el-dialog title="导入表" v-model="visible" width="800px" top="5vh" append-to-body> |   <el-dialog title="导入表" v-model="visible" width="1100px" top="5vh" append-to-body> | ||||||
|     <el-form :model="queryParams" ref="queryFormRef" :inline="true"> |     <el-form :model="queryParams" ref="queryFormRef" :inline="true"> | ||||||
|  |       <el-form-item label="数据源" prop="dataName"> | ||||||
|  |             <el-select v-model="queryParams.dataName" filterable placeholder="请选择/输入数据源名称" style="width: 200px"> | ||||||
|  |               <el-option v-for="item in dataNameList" :key="item" :label="item" :value="item"> </el-option> | ||||||
|  |             </el-select> | ||||||
|  |           </el-form-item> | ||||||
|           <el-form-item label="表名称" prop="tableName"> |           <el-form-item label="表名称" prop="tableName"> | ||||||
|         <el-input v-model="queryParams.tableName" placeholder="请输入表名称" clearable @keyup.enter="handleQuery" /> |         <el-input v-model="queryParams.tableName" placeholder="请输入表名称" clearable @keyup.enter="handleQuery" /> | ||||||
|       </el-form-item> |       </el-form-item> | ||||||
| @ -33,7 +38,7 @@ | |||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script setup lang="ts"> | <script setup lang="ts"> | ||||||
| import { listDbTable, importTable } from '@/api/tool/gen'; | import { listDbTable, importTable, getDataNames } from '@/api/tool/gen'; | ||||||
| import { DbTableQuery, DbTableVO } from '@/api/tool/gen/types'; | import { DbTableQuery, DbTableVO } from '@/api/tool/gen/types'; | ||||||
| import { ComponentInternalInstance } from 'vue'; | import { ComponentInternalInstance } from 'vue'; | ||||||
| import { ElTable, ElForm } from 'element-plus'; | import { ElTable, ElForm } from 'element-plus'; | ||||||
| @ -50,14 +55,22 @@ const queryFormRef = ref(ElForm); | |||||||
| const queryParams = reactive<DbTableQuery>({ | const queryParams = reactive<DbTableQuery>({ | ||||||
|     pageNum: 1, |     pageNum: 1, | ||||||
|     pageSize: 10, |     pageSize: 10, | ||||||
|  |     dataName: '', | ||||||
|     tableName: '', |     tableName: '', | ||||||
|     tableComment: '' |     tableComment: '' | ||||||
| }); | }); | ||||||
|  | const dataNameList = ref<Array<string>>([]); | ||||||
|  |  | ||||||
| const emit = defineEmits(["ok"]); | const emit = defineEmits(["ok"]); | ||||||
|  |  | ||||||
| /** 查询参数列表 */ | /** 查询参数列表 */ | ||||||
| const show = () => { | const show = (dataName: string) => { | ||||||
|  |     getDataNameList(); | ||||||
|  |     if(dataName){ | ||||||
|  |       queryParams.dataName = dataName; | ||||||
|  |     } else { | ||||||
|  |       queryParams.dataName = 'master'; | ||||||
|  |     } | ||||||
|     getList(); |     getList(); | ||||||
|     visible.value = true; |     visible.value = true; | ||||||
| } | } | ||||||
| @ -92,13 +105,18 @@ const handleImportTable = async () => { | |||||||
|         proxy?.$modal.msgError("请选择要导入的表"); |         proxy?.$modal.msgError("请选择要导入的表"); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     const res = await importTable({ tables: tableNames }); |     const res = await importTable({ tables: tableNames, dataName: queryParams.dataName }); | ||||||
|     proxy?.$modal.msgSuccess(res.msg); |     proxy?.$modal.msgSuccess(res.msg); | ||||||
|     if (res.code === 200) { |     if (res.code === 200) { | ||||||
|         visible.value = false; |         visible.value = false; | ||||||
|         emit("ok"); |         emit("ok"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | /** 查询多数据源名称 */ | ||||||
|  | const getDataNameList = async () => { | ||||||
|  |   const res = await getDataNames() | ||||||
|  |   dataNameList.value = res.data; | ||||||
|  | } | ||||||
|  |  | ||||||
| defineExpose({ | defineExpose({ | ||||||
|     show, |     show, | ||||||
|  | |||||||
| @ -4,7 +4,10 @@ | |||||||
|       <div class="search" v-show="showSearch"> |       <div class="search" v-show="showSearch"> | ||||||
|         <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px"> |         <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px"> | ||||||
|           <el-form-item label="数据源" prop="dataName"> |           <el-form-item label="数据源" prop="dataName"> | ||||||
|             <el-input v-model="queryParams.dataName" placeholder="请输入数据源名称" clearable style="width: 200px" @keyup.enter="handleQuery" /> |             <el-select v-model="queryParams.dataName" filterable clearable placeholder="请选择/输入数据源名称" style="width: 200px"> | ||||||
|  |               <el-option key="" label="全部" value="" /> | ||||||
|  |               <el-option v-for="item in dataNameList" :key="item" :label="item" :value="item"> </el-option> | ||||||
|  |             </el-select> | ||||||
|           </el-form-item> |           </el-form-item> | ||||||
|           <el-form-item label="表名称" prop="tableName"> |           <el-form-item label="表名称" prop="tableName"> | ||||||
|             <el-input v-model="queryParams.tableName" placeholder="请输入表名称" clearable style="width: 200px" @keyup.enter="handleQuery" /> |             <el-input v-model="queryParams.tableName" placeholder="请输入表名称" clearable style="width: 200px" @keyup.enter="handleQuery" /> | ||||||
| @ -58,6 +61,7 @@ | |||||||
|             <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span> |             <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span> | ||||||
|           </template> |           </template> | ||||||
|         </el-table-column> |         </el-table-column> | ||||||
|  |         <el-table-column label="数据源" align="center" prop="dataName" :show-overflow-tooltip="true" /> | ||||||
|         <el-table-column label="表名称" align="center" prop="tableName" :show-overflow-tooltip="true" /> |         <el-table-column label="表名称" align="center" prop="tableName" :show-overflow-tooltip="true" /> | ||||||
|         <el-table-column label="表描述" align="center" prop="tableComment" :show-overflow-tooltip="true" /> |         <el-table-column label="表描述" align="center" prop="tableComment" :show-overflow-tooltip="true" /> | ||||||
|         <el-table-column label="实体" align="center" prop="className" :show-overflow-tooltip="true" /> |         <el-table-column label="实体" align="center" prop="className" :show-overflow-tooltip="true" /> | ||||||
| @ -107,7 +111,7 @@ | |||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script setup name="Gen" lang="ts"> | <script setup name="Gen" lang="ts"> | ||||||
| import { listTable, previewTable, delTable, genCode, synchDb } from '@/api/tool/gen'; | import { listTable, previewTable, delTable, genCode, synchDb, getDataNames } from '@/api/tool/gen'; | ||||||
| import { TableQuery, TableVO } from '@/api/tool/gen/types'; | import { TableQuery, TableVO } from '@/api/tool/gen/types'; | ||||||
| import router from '@/router'; | import router from '@/router'; | ||||||
| import importTable from './importTable.vue'; | import importTable from './importTable.vue'; | ||||||
| @ -124,9 +128,9 @@ const ids = ref<Array<string | number>>([]); | |||||||
| const single = ref(true); | const single = ref(true); | ||||||
| const multiple = ref(true); | const multiple = ref(true); | ||||||
| const total = ref(0); | const total = ref(0); | ||||||
| const tableNames = ref<Array<string>>([]); |  | ||||||
| const dateRange = ref<[DateModelType, DateModelType]>(['', '']); | const dateRange = ref<[DateModelType, DateModelType]>(['', '']); | ||||||
| const uniqueId = ref(""); | const uniqueId = ref(""); | ||||||
|  | const dataNameList = ref<Array<string>>([]); | ||||||
|  |  | ||||||
| const queryFormRef = ref(ElForm); | const queryFormRef = ref(ElForm); | ||||||
| const importRef = ref(importTable); | const importRef = ref(importTable); | ||||||
| @ -136,7 +140,7 @@ const queryParams = ref<TableQuery>({ | |||||||
|     pageSize: 10, |     pageSize: 10, | ||||||
|     tableName: '', |     tableName: '', | ||||||
|     tableComment: '', |     tableComment: '', | ||||||
|     dataName: "master" |     dataName: "" | ||||||
| }) | }) | ||||||
|  |  | ||||||
| const preview = ref <any>({ | const preview = ref <any>({ | ||||||
| @ -148,8 +152,6 @@ const dialog = reactive<DialogOption>({ | |||||||
|     title: '代码预览' |     title: '代码预览' | ||||||
| }); | }); | ||||||
|  |  | ||||||
| localStorage.setItem('dataName', queryParams.value.dataName); |  | ||||||
|  |  | ||||||
| onActivated(() => { | onActivated(() => { | ||||||
|     const time = route.query.t; |     const time = route.query.t; | ||||||
|     if (time != null && time != uniqueId.value) { |     if (time != null && time != uniqueId.value) { | ||||||
| @ -161,6 +163,12 @@ onActivated(() => { | |||||||
|     } |     } | ||||||
| }) | }) | ||||||
|  |  | ||||||
|  | /** 查询多数据源名称 */ | ||||||
|  | const getDataNameList = async () => { | ||||||
|  |   const res = await getDataNames() | ||||||
|  |   dataNameList.value = res.data; | ||||||
|  | } | ||||||
|  |  | ||||||
| /** 查询表集合 */ | /** 查询表集合 */ | ||||||
| const getList = async () => { | const getList = async () => { | ||||||
|     loading.value = true; |     loading.value = true; | ||||||
| @ -171,34 +179,33 @@ const getList = async () => { | |||||||
| } | } | ||||||
| /** 搜索按钮操作 */ | /** 搜索按钮操作 */ | ||||||
| const handleQuery = () => { | const handleQuery = () => { | ||||||
|     localStorage.setItem('dataName', queryParams.value.dataName); |  | ||||||
|     queryParams.value.pageNum = 1; |     queryParams.value.pageNum = 1; | ||||||
|     getList(); |     getList(); | ||||||
| } | } | ||||||
| /** 生成代码操作 */ | /** 生成代码操作 */ | ||||||
| const handleGenTable = async (row?: TableVO) => { | const handleGenTable = async (row?: TableVO) => { | ||||||
|     const tbNames = row?.tableName || tableNames.value; |     const tbIds = row?.tableId || ids.value; | ||||||
|     if (tbNames == "") { |     if (tbIds == "") { | ||||||
|         proxy?.$modal.msgError('请选择要生成的数据'); |         proxy?.$modal.msgError('请选择要生成的数据'); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     if (row?.genType === "1") { |     if (row?.genType === "1") { | ||||||
|         await genCode(row.tableName); |         await genCode(row.tableId); | ||||||
|         proxy?.$modal.msgSuccess('成功生成到自定义路径:' + row.genPath); |         proxy?.$modal.msgSuccess('成功生成到自定义路径:' + row.genPath); | ||||||
|     } else { |     } else { | ||||||
|         proxy?.$download.zip('/tool/gen/batchGenCode?tables=' + tbNames, 'ruoyi.zip'); |         proxy?.$download.zip('/tool/gen/batchGenCode?tableIdStr=' + tbIds, 'ruoyi.zip'); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| /** 同步数据库操作 */ | /** 同步数据库操作 */ | ||||||
| const handleSynchDb = async (row: TableVO) => { | const handleSynchDb = async (row: TableVO) => { | ||||||
|     const tableName = row.tableName; |     const tableId = row.tableId; | ||||||
|     await proxy?.$modal.confirm('确认要强制同步"' + tableName + '"表结构吗?'); |     await proxy?.$modal.confirm('确认要强制同步"' + row.tableName + '"表结构吗?'); | ||||||
|     await synchDb(tableName); |     await synchDb(tableId); | ||||||
|     proxy?.$modal.msgSuccess('同步成功'); |     proxy?.$modal.msgSuccess('同步成功'); | ||||||
| } | } | ||||||
| /** 打开导入表弹窗 */ | /** 打开导入表弹窗 */ | ||||||
| const openImportTable = () => { | const openImportTable = () => { | ||||||
|     importRef.value.show(); |     importRef.value.show(queryParams.value.dataName); | ||||||
| } | } | ||||||
| /** 重置按钮操作 */ | /** 重置按钮操作 */ | ||||||
| const resetQuery = () => { | const resetQuery = () => { | ||||||
| @ -220,7 +227,6 @@ const copyTextSuccess = () => { | |||||||
| // 多选框选中数据 | // 多选框选中数据 | ||||||
| const handleSelectionChange = (selection: TableVO[]) => { | const handleSelectionChange = (selection: TableVO[]) => { | ||||||
|     ids.value = selection.map(item => item.tableId); |     ids.value = selection.map(item => item.tableId); | ||||||
|     tableNames.value = selection.map(item => item.tableName); |  | ||||||
|     single.value = selection.length != 1; |     single.value = selection.length != 1; | ||||||
|     multiple.value = !selection.length; |     multiple.value = !selection.length; | ||||||
| } | } | ||||||
| @ -240,5 +246,6 @@ const handleDelete = async (row?: TableVO) => { | |||||||
|  |  | ||||||
| onMounted(() => { | onMounted(() => { | ||||||
|     getList(); |     getList(); | ||||||
|  |     getDataNameList(); | ||||||
| }) | }) | ||||||
| </script> | </script> | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 疯狂的狮子Li
					疯狂的狮子Li