Преглед изворни кода

代码生成新增创建表结构功能

RuoYi пре 8 месеци
родитељ
комит
69c189a0c9
3 измењених фајлова са 71 додато и 0 уклоњено
  1. 9 0
      src/api/tool/gen.js
  2. 46 0
      src/views/tool/gen/createTable.vue
  3. 16 0
      src/views/tool/gen/index.vue

+ 9 - 0
src/api/tool/gen.js

@@ -43,6 +43,15 @@ export function importTable(data) {
   })
 }
 
+// 创建表
+export function createTable(data) {
+  return request({
+    url: '/tool/gen/createTable',
+    method: 'post',
+    params: data
+  })
+}
+
 // 预览生成代码
 export function previewTable(tableId) {
   return request({

+ 46 - 0
src/views/tool/gen/createTable.vue

@@ -0,0 +1,46 @@
+<template>
+  <!-- 创建表 -->
+  <el-dialog title="创建表" v-model="visible" width="800px" top="5vh" append-to-body>
+    <span>创建表语句(支持多个建表语句):</span>
+    <el-input type="textarea" :rows="10" placeholder="请输入文本" v-model="content"></el-input>
+    <template #footer>
+      <div class="dialog-footer">
+        <el-button type="primary" @click="handleImportTable">确 定</el-button>
+        <el-button @click="visible = false">取 消</el-button>
+      </div>
+    </template>
+  </el-dialog>
+</template>
+
+<script setup>
+import { createTable } from "@/api/tool/gen";
+
+const visible = ref(false);
+const content = ref("");
+const { proxy } = getCurrentInstance();
+const emit = defineEmits(["ok"]);
+
+/** 显示弹框 */
+function show() {
+  visible.value = true;
+}
+
+/** 导入按钮操作 */
+function handleImportTable() {
+  if (content.value === "") {
+    proxy.$modal.msgError("请输入建表语句");
+    return;
+  }
+  createTable({ sql: content.value }).then(res => {
+    proxy.$modal.msgSuccess(res.msg);
+    if (res.code === 200) {
+      visible.value = false;
+      emit("ok");
+    }
+  });
+}
+
+defineExpose({
+  show,
+});
+</script>

+ 16 - 0
src/views/tool/gen/index.vue

@@ -41,10 +41,20 @@
           type="primary"
           plain
           icon="Download"
+          :disabled="multiple"
           @click="handleGenTable"
           v-hasPermi="['tool:gen:code']"
         >生成</el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="primary"
+          plain
+          icon="Plus"
+          @click="openCreateTable"
+          v-hasRole="['admin']"
+        >创建</el-button>
+      </el-col>
       <el-col :span="1.5">
         <el-button
           type="info"
@@ -146,6 +156,7 @@
       </el-tabs>
     </el-dialog>
     <import-table ref="importRef" @ok="handleQuery" />
+    <create-table ref="createRef" @ok="handleQuery" />
   </div>
 </template>
 
@@ -153,6 +164,7 @@
 import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/gen";
 import router from "@/router";
 import importTable from "./importTable";
+import createTable from "./createTable";
 
 const route = useRoute();
 const { proxy } = getCurrentInstance();
@@ -238,6 +250,10 @@ function handleSynchDb(row) {
 function openImportTable() {
   proxy.$refs["importRef"].show();
 }
+/** 打开创建表弹窗 */
+function openCreateTable() {
+  proxy.$refs["createRef"].show();
+}
 /** 重置按钮操作 */
 function resetQuery() {
   dateRange.value = [];