index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <div class="sys-codeGen-container">
  3. <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
  4. <el-form :model="state.queryParams" ref="queryForm" :inline="true">
  5. <el-form-item label="业务名">
  6. <el-input placeholder="业务名" clearable @keyup.enter="handleQuery" v-model="state.queryParams.busName" />
  7. </el-form-item>
  8. <el-form-item label="数据库表名">
  9. <el-input placeholder="数据库表名" clearable @keyup.enter="handleQuery" v-model="state.queryParams.tableName" />
  10. </el-form-item>
  11. <el-form-item>
  12. <el-button-group>
  13. <el-button type="primary" icon="ele-Search" @click="handleQuery" v-auth="'sysMenu:list'"> 查询 </el-button>
  14. <el-button icon="ele-Refresh" @click="resetQuery"> 重置 </el-button>
  15. </el-button-group>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button type="primary" icon="ele-Plus" @click="openAddDialog"> 增加 </el-button>
  19. </el-form-item>
  20. </el-form>
  21. </el-card>
  22. <el-card class="full-table" shadow="hover" style="margin-top: 5px">
  23. <el-table :data="state.tableData" style="width: 100%" v-loading="state.loading" border>
  24. <el-table-column type="index" label="序号" width="55" align="center" />
  25. <el-table-column prop="configId" label="库定位器" align="center" show-overflow-tooltip />
  26. <el-table-column prop="dbNickName" label="库名" align="center" show-overflow-tooltip />
  27. <el-table-column prop="tableName" label="表名称" align="center" show-overflow-tooltip />
  28. <el-table-column prop="busName" label="业务名" align="center" show-overflow-tooltip />
  29. <el-table-column prop="nameSpace" label="命名空间" align="center" show-overflow-tooltip />
  30. <el-table-column prop="authorName" label="作者姓名" align="center" show-overflow-tooltip />
  31. <el-table-column prop="generateType" label="生成方式" align="center" show-overflow-tooltip>
  32. <template #default="scope">
  33. <g-sys-dict v-model="scope.row.generateType" code="code_gen_create_type" />
  34. </template>
  35. </el-table-column>
  36. <el-table-column label="操作" width="280" fixed="right" align="center" show-overflow-tooltip>
  37. <template #default="scope">
  38. <el-button icon="ele-Delete" size="small" text type="danger" title="删除" @click="deleConfig(scope.row)" />
  39. <el-button icon="ele-Edit" size="small" text type="primary" title="编辑" @click="openEditDialog(scope.row)" />
  40. <el-button icon="ele-CopyDocument" size="small" text type="primary" title="复制" @click="openCopyDialog(scope.row)" />
  41. <el-button icon="ele-View" size="small" text type="primary" title="预览" @click="handlePreview(scope.row)" />
  42. <el-button icon="ele-Setting" size="small" text type="primary" title="配置" @click="openConfigDialog(scope.row)" />
  43. <el-button icon="ele-Refresh" size="small" text type="primary" title="同步" @click="syncCodeGen(scope.row)" />
  44. <el-button icon="ele-Position" size="small" text type="primary" @click="handleGenerate(scope.row)">生成</el-button>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. <el-pagination
  49. v-model:currentPage="state.tableParams.page"
  50. v-model:page-size="state.tableParams.pageSize"
  51. :total="state.tableParams.total"
  52. :page-sizes="[10, 20, 50, 100]"
  53. size="small"
  54. background
  55. @size-change="handleSizeChange"
  56. @current-change="handleCurrentChange"
  57. layout="total, sizes, prev, pager, next, jumper"
  58. />
  59. </el-card>
  60. <EditCodeGenDialog :title="state.editTitle" ref="EditCodeGenRef" @handleQuery="handleQuery" :application-namespaces="state.applicationNamespaces" />
  61. <CodeConfigDialog ref="CodeConfigRef" @handleQuery="handleQuery" />
  62. <PreviewDialog :title="state.editTitle" ref="PreviewRef" />
  63. </div>
  64. </template>
  65. <script lang="ts" setup name="sysCodeGen">
  66. import { onMounted, reactive, ref, defineAsyncComponent } from 'vue';
  67. import { ElMessageBox, ElMessage } from 'element-plus';
  68. import EditCodeGenDialog from './component/editCodeGenDialog.vue';
  69. import CodeConfigDialog from './component/genConfigDialog.vue';
  70. import { downloadByUrl } from '/@/utils/download';
  71. import { getAPI } from '/@/utils/axios-utils';
  72. import { SysCodeGenApi } from '/@/api-services/api';
  73. import { SysCodeGen } from '/@/api-services/models';
  74. const PreviewDialog = defineAsyncComponent(() => import('./component/previewDialog.vue'));
  75. const EditCodeGenRef = ref<InstanceType<typeof EditCodeGenDialog>>();
  76. const CodeConfigRef = ref<InstanceType<typeof CodeConfigDialog>>();
  77. const PreviewRef = ref<InstanceType<typeof PreviewDialog>>();
  78. const state = reactive({
  79. loading: false,
  80. loading1: false,
  81. dbData: [] as any,
  82. configId: '',
  83. tableData: [] as Array<SysCodeGen>,
  84. tableName: '',
  85. queryParams: {
  86. name: undefined,
  87. code: undefined,
  88. tableName: undefined,
  89. busName: undefined,
  90. },
  91. tableParams: {
  92. page: 1,
  93. pageSize: 50,
  94. total: 0 as any,
  95. },
  96. editTitle: '',
  97. applicationNamespaces: [] as Array<string>,
  98. });
  99. onMounted(async () => {
  100. handleQuery();
  101. let res = await getAPI(SysCodeGenApi).apiSysCodeGenApplicationNamespacesGet();
  102. state.applicationNamespaces = res.data.result as Array<string>;
  103. });
  104. const openConfigDialog = (row: any) => {
  105. CodeConfigRef.value?.openDialog(row);
  106. };
  107. // 表查询操作
  108. const handleQuery = async () => {
  109. state.loading = true;
  110. let params = Object.assign(state.queryParams, state.tableParams);
  111. let res = await getAPI(SysCodeGenApi).apiSysCodeGenPagePost(params);
  112. state.tableData = res.data.result?.items ?? [];
  113. state.tableParams.total = res.data.result?.total;
  114. state.loading = false;
  115. };
  116. // 重置操作
  117. const resetQuery = () => {
  118. state.queryParams.busName = undefined;
  119. state.queryParams.tableName = undefined;
  120. handleQuery();
  121. };
  122. // 改变页面容量
  123. const handleSizeChange = (val: number) => {
  124. state.tableParams.pageSize = val;
  125. handleQuery();
  126. };
  127. // 改变页码序号
  128. const handleCurrentChange = (val: number) => {
  129. state.tableParams.page = val;
  130. handleQuery();
  131. };
  132. // 打开表增加页面
  133. const openAddDialog = () => {
  134. state.editTitle = '增加';
  135. EditCodeGenRef.value?.openDialog({
  136. authorName: 'Admin.NET',
  137. generateType: '200',
  138. printType: 'off',
  139. menuIcon: 'ele-Menu',
  140. pagePath: 'main',
  141. nameSpace: state.applicationNamespaces[0],
  142. generateMenu: true,
  143. });
  144. };
  145. // 打开表编辑页面
  146. const openEditDialog = (row: any) => {
  147. state.editTitle = '编辑';
  148. EditCodeGenRef.value?.openDialog(row);
  149. };
  150. // 打开复制页面
  151. const openCopyDialog = (row: any) => {
  152. state.editTitle = '复制';
  153. var copyRow = JSON.parse(JSON.stringify(row));
  154. copyRow.id = 0;
  155. copyRow.busName = '';
  156. copyRow.tableName = '';
  157. copyRow.tableUniqueList = undefined;
  158. EditCodeGenRef.value?.openDialog(copyRow);
  159. };
  160. // 删除表
  161. const deleConfig = (row: any) => {
  162. ElMessageBox.confirm(`确定删除吗?`, '提示', {
  163. confirmButtonText: '确定',
  164. cancelButtonText: '取消',
  165. type: 'warning',
  166. }).then(async () => {
  167. await getAPI(SysCodeGenApi).apiSysCodeGenDeletePost([{ id: row.id }]);
  168. handleQuery();
  169. ElMessage.success('操作成功');
  170. }).catch(() => {});
  171. };
  172. // 同步生成
  173. const syncCodeGen = async (row: any) => {
  174. ElMessageBox.confirm(`确定要同步吗?`, '提示', {
  175. confirmButtonText: '确定',
  176. cancelButtonText: '取消',
  177. type: 'warning',
  178. }).then(async () => {
  179. await getAPI(SysCodeGenApi).apiSysCodeGenUpdatePost(row);
  180. handleQuery();
  181. ElMessage.success('同步成功');
  182. }).catch(() => {});
  183. }
  184. // 开始生成代码
  185. const handleGenerate = (row: any) => {
  186. ElMessageBox.confirm(`确定要生成吗?`, '提示', {
  187. confirmButtonText: '确定',
  188. cancelButtonText: '取消',
  189. type: 'warning',
  190. })
  191. .then(async () => {
  192. var res = await getAPI(SysCodeGenApi).apiSysCodeGenRunLocalPost(row);
  193. if (res.data.result != null && res.data.result.url != null) downloadByUrl({ url: res.data.result.url });
  194. handleQuery();
  195. ElMessage.success('操作成功');
  196. })
  197. .catch(() => {});
  198. };
  199. // 预览代码
  200. const handlePreview = (row: any) => {
  201. state.editTitle = '预览代码';
  202. PreviewRef.value?.openDialog(row);
  203. };
  204. </script>