瀏覽代碼

调整创建表格和菜单的请求顺序/删除表格时同时删除路由

lph 1 年之前
父節點
當前提交
723fa2b1e3

+ 24 - 8
ruoyi-ui/src/utils/index.js

@@ -12,12 +12,12 @@ import { parseTime } from './ruoyi'
  */
 export function formatDate(cellValue) {
   if (cellValue == null || cellValue == "") return "";
-  var date = new Date(cellValue) 
+  var date = new Date(cellValue)
   var year = date.getFullYear()
   var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
-  var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() 
-  var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours() 
-  var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes() 
+  var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
+  var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
+  var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
   var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
   return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
 }
@@ -225,7 +225,7 @@ export function getTime(type) {
 export function debounce(func, wait, immediate) {
   let timeout, args, context, timestamp, result
 
-  const later = function() {
+  const later = function () {
     // 据上一次触发时间间隔
     const last = +new Date() - timestamp
 
@@ -242,7 +242,7 @@ export function debounce(func, wait, immediate) {
     }
   }
 
-  return function(...args) {
+  return function (...args) {
     context = this
     timestamp = +new Date()
     const callNow = immediate && !timeout
@@ -256,6 +256,22 @@ export function debounce(func, wait, immediate) {
     return result
   }
 }
+/**
+ * 
+ */
+export function throttle(fn, delay) {
+  let timer = null;
+  return function () {
+    let context = this;
+    let args = arguments;
+    if (!timer) {
+      timer = setTimeout(function () {
+        fn.apply(context, args);
+        timer = null;
+      }, delay);
+    }
+  }
+}
 
 /**
  * This is just a simple version of deep copy
@@ -337,7 +353,7 @@ export function makeMap(str, expectsLowerCase) {
     ? val => map[val.toLowerCase()]
     : val => map[val]
 }
- 
+
 export const exportDefault = 'export default '
 
 export const beautifierConf = {
@@ -394,7 +410,7 @@ export function camelCase(str) {
 export function isNumberStr(str) {
   return /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(str)
 }
- 
+
 
 
 export const $ = name => document.querySelector(name)

+ 7 - 0
ruoyi-ui/src/utils/request.js

@@ -6,11 +6,13 @@ import errorCode from '@/utils/errorCode'
 import { tansParams, blobValidate } from "@/utils/ruoyi";
 import cache from '@/plugins/cache'
 import { saveAs } from 'file-saver'
+import { throttle } from '@/utils/index'
 
 let downloadLoadingInstance;
 // 是否显示重新登录
 export let isRelogin = { show: false };
 
+
 axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
 // 创建axios实例
 const service = axios.create({
@@ -95,6 +97,10 @@ service.interceptors.response.use(res => {
     Message({ message: msg, type: 'warning' })
     return Promise.reject('error')
   } else if (code !== 200) {
+    // throttle(function () {
+    //   console.log(msg);
+    //   Notification.error({ title: msg })
+    // }, 1000)
     Notification.error({ title: msg })
     return Promise.reject('error')
   } else {
@@ -111,6 +117,7 @@ service.interceptors.response.use(res => {
     } else if (message.includes("Request failed with status code")) {
       message = "系统接口" + message.substr(message.length - 3) + "异常";
     }
+
     Message({ message: message, type: 'error', duration: 5 * 1000 })
     return Promise.reject(error)
   }

+ 35 - 3
ruoyi-ui/src/views/dragform/tableList.vue

@@ -223,6 +223,7 @@
 </template>
 <script>
 import { listTable, removeTableList } from "@/api/dragform/tableList";
+import { delMenu } from "@/api/system/menu";
 import { mapGetters } from "vuex";
 import DictData from "@/components/DictData";
 
@@ -235,6 +236,7 @@ export default {
       // 选中数组
       ids: [],
       Keys: [],
+      menuIds: [],
       // 非单个禁用
       single: true,
       // 非多个禁用
@@ -330,6 +332,7 @@ export default {
     handleSelectionChange(selection) {
       this.ids = selection.map((item) => item.tId);
       this.Keys = selection.map((item) => item.sqlKey);
+      this.menuIds = selection.map((item) => item.menuId);
       this.single = selection.length !== 1;
       this.multiple = !selection.length;
     },
@@ -386,29 +389,58 @@ export default {
     },
     /** 删除按钮操作 */
     handleDelete(row) {
-      let data = {};
+      let data = {},
+        menuIdList = [];
       if (row.tId && row.sqlKey) {
         data.tIds = [row.tId];
         data.sqlKeys = [row.sqlKey];
+        menuIdList.push(row.menuId);
       } else {
         data.tIds = this.ids;
         data.sqlKeys = this.Keys;
+        menuIdList = this.menuIds;
       }
       // console.log(data);
       this.$modal
         .confirm(
-          '是否确认删除动态格编号为"' + data.tIds.join(",") + '"的数据项?'
+          '是否确认删除动态格编号为"' +
+            data.tIds.join(",") +
+            '"的数据项?删除后菜单中相关数据也将删除!'
         )
         .then(async function () {
           const res = await removeTableList(data);
-          // console.log(res);
+          await delMenu(row.menuId);
+          // let promiseArr = [];
+          // for (let i = 0; i < menuIdList.length; i++) {
+          //   console.log(menuIdList[i]);
+          //   promiseArr.push(
+          //     new Promise((resolve, reject) => {
+          //       delMenu(menuIdList[i]).then(
+          //         (val) => {
+          //           resolve(val);
+          //         },
+          //         (res) => {
+          //           reject(res);
+          //         }
+          //       );
+          //     })
+          //   );
+          // }
+          // let result = await Promise.all(promiseArr);
         })
         .then(() => {
           this.getList();
+          this.reloadRouter();
           this.$modal.msgSuccess("删除成功");
         })
         .catch(() => {});
     },
+    // 更新路由
+    reloadRouter() {
+      this.$store.dispatch("GenerateRoutes").then((accessRoutes) => {
+        this.$router.addRoutes(accessRoutes); // 动态添加可访问路由表
+      });
+    },
     /** 导出按钮操作 */
     handleExport() {
       this.download(

+ 121 - 108
ruoyi-ui/src/views/tableMange/index.vue

@@ -767,11 +767,14 @@ export default {
       };
       let res = await getFormName(data);
 
-      const baseTable = await this.getDicts('base_table')
+      const baseTable = await this.getDicts("base_table");
 
-      this.tableList = res.data.filter(item => {
-        return !baseTable.data.some(value => value.dictValue.toLowerCase() == item.tableName.toLowerCase())
-      })
+      this.tableList = res.data.filter((item) => {
+        return !baseTable.data.some(
+          (value) =>
+            value.dictValue.toLowerCase() == item.tableName.toLowerCase()
+        );
+      });
     },
     //处理表格行拖拽
     initDragTable() {
@@ -1091,21 +1094,6 @@ export default {
             this.$message.error(validRes.msg);
             return;
           }
-          // let validateParams = {
-          //   isFieldDescrib: false,
-          //   isRelationFieldAll: false,
-          // };
-          // this.validateField(this.tableFieldList, validateParams);
-          // console.log(validateParams);
-          // if (validateParams.isFieldDescrib) {
-          //   this.$message.error("需要显示的字段描述不能为空");
-          //   return;
-          // }
-          // if (validateParams.isRelationFieldAll) {
-          //   this.$message.error("请补全关联条件");
-          //   return;
-          // }
-          let uuid = uuidv4();
           let columns = [],
             searchFieldList = [],
             tableExportField = {};
@@ -1121,110 +1109,135 @@ export default {
             tableFieldData: this.tableFieldList,
             formData: this.formData,
           };
-          // let isAsc = this.formData.isAsc == "ASC" ? 0 : 1;
-          let data = {
-            tId: this.tId,
-            dtName: this.formData.menuName,
-            // menuId: this.formData.routePath,
-            // tableKey: this.formData.routePath, //  暂定
-            dtTableName: this.tableName,
-            primaryKey: this.formData.primaryKey,
-            orderByColumn: this.formData.orderByColumn,
-            sortOrder: this.formData.isAsc,
-            sqlKey: uuid,
-            dtColumnName: columns, //列字段标题名称(存储显示字段信息
-            // dtColumnName: JSON.stringify(columns).replace(/"/g, "'"), //列字段标题名称(存储显示字段信息
-            timeFormat: this.formData.timeFormate,
-            searchFieldList: searchFieldList, //搜索字段数组
-            tableSql: this.getSQLStr(), //  暂定
-            tableExportField: tableExportField, //导出字段名及列名
-            echoData: JSON.stringify(echoData),
-          };
-          // this.tableFieldList.forEach((item) => {
-          //   if (item.isShow) {
-          //     let tempObj = {};
-          //     tempObj[item.fieldName] = item.fieldDescription;
-          //     data.dtColumnName.push(tempObj);
-          //     if (item.children.length) {
-          //       item.children.map((child) => {
-          //         let tempObj = {};
-          //         tempObj[child.fieldName] = child.fieldDescription;
-          //         data.dtColumnName.push(tempObj);
-          //       });
-          //     }
-          //   }
-          //   if (item.isSearch) {
-          //     data.searchFieldList.push(item.fieldName);
-          //   }
-          //   if (item.isExport) {
-          //     data.tableExportField[item.fieldName] = item.fieldDescription;
-          //   }
-          // });
-          if (!data.searchFieldList.length) {
+          if (!searchFieldList.length) {
             this.$message.warning("请至少选择一个包含查询字段");
             return false;
           }
-          let res;
+          // let validateParams = {
+          //   isFieldDescrib: false,
+          //   isRelationFieldAll: false,
+          // };
+          // this.validateField(this.tableFieldList, validateParams);
+          // console.log(validateParams);
+          // if (validateParams.isFieldDescrib) {
+          //   this.$message.error("需要显示的字段描述不能为空");
+          //   return;
+          // }
+          // if (validateParams.isRelationFieldAll) {
+          //   this.$message.error("请补全关联条件");
+          //   return;
+          // }
+          let uuid = uuidv4();
+
+          // 表单
+          let result;
           if (this.tId) {
-            data.sqlKey = this.editData.sqlKey;
-            res = await editTable(data);
+            let payLoad = {
+              menuId: this.menuId,
+              menuName: this.formData.menuName,
+              parentId: this.formData.routePath,
+              component: "tablelist/commonTable/listInfo",
+              icon: "",
+              isCache: "0",
+              isFrame: "1",
+              menuType: "C",
+              orderNum: "0",
+              status: "0",
+              visible: "0",
+            };
+            result = await updateMenu(payLoad);
           } else {
-            res = await addDragTable(data);
+            let sqlKeyObj = {
+              sqlkey: uuid,
+            };
+            let payLoad = {
+              component: "tablelist/commonTable/listInfo",
+              icon: "",
+              isCache: "0",
+              isFrame: "1",
+              menuName: this.formData.menuName,
+              menuType: "C",
+              orderNum: "0",
+              parentId: this.formData.routePath,
+              path: uuid,
+              query: JSON.stringify(sqlKeyObj),
+              status: "0",
+              visible: "0",
+            };
+            result = await addMenu(payLoad);
           }
-          if (res.code == 200) {
+
+          if (result.code == 200) {
+            // 更新路由
+            this.reloadRouter();
+
+            // let isAsc = this.formData.isAsc == "ASC" ? 0 : 1;
+            let data = {
+              tId: this.tId,
+              dtName: this.formData.menuName,
+              // menuId: this.formData.routePath,
+              // tableKey: this.formData.routePath, //  暂定
+              dtTableName: this.tableName,
+              primaryKey: this.formData.primaryKey,
+              orderByColumn: this.formData.orderByColumn,
+              sortOrder: this.formData.isAsc,
+              sqlKey: uuid,
+              dtColumnName: columns, //列字段标题名称(存储显示字段信息
+              // dtColumnName: JSON.stringify(columns).replace(/"/g, "'"), //列字段标题名称(存储显示字段信息
+              timeFormat: this.formData.timeFormate,
+              searchFieldList: searchFieldList, //搜索字段数组
+              tableSql: this.getSQLStr(), //  暂定
+              tableExportField: tableExportField, //导出字段名及列名
+              echoData: JSON.stringify(echoData),
+            };
+            // this.tableFieldList.forEach((item) => {
+            //   if (item.isShow) {
+            //     let tempObj = {};
+            //     tempObj[item.fieldName] = item.fieldDescription;
+            //     data.dtColumnName.push(tempObj);
+            //     if (item.children.length) {
+            //       item.children.map((child) => {
+            //         let tempObj = {};
+            //         tempObj[child.fieldName] = child.fieldDescription;
+            //         data.dtColumnName.push(tempObj);
+            //       });
+            //     }
+            //   }
+            //   if (item.isSearch) {
+            //     data.searchFieldList.push(item.fieldName);
+            //   }
+            //   if (item.isExport) {
+            //     data.tableExportField[item.fieldName] = item.fieldDescription;
+            //   }
+            // });
+
+            let res;
             if (this.tId) {
-              let payLoad = {
-                menuId: this.menuId,
-                menuName: this.formData.menuName,
-                parentId: this.formData.routePath,
-                component: "tablelist/commonTable/listInfo",
-                icon: "",
-                isCache: "0",
-                isFrame: "1",
-                menuType: "C",
-                orderNum: "0",
-                status: "0",
-                visible: "0",
-              };
-              let result = await updateMenu(payLoad);
-              if (result.code == 200) {
-                this.$message.success("更新成功");
-                this.reloadRouter();
-              } else {
-                this.$message.warning("更新失败");
-              }
+              data.menuId = this.menuId;
+              data.sqlKey = this.editData.sqlKey;
+              res = await editTable(data);
             } else {
-              let sqlKeyObj = {
-                sqlkey: uuid,
-              };
-              let payLoad = {
-                component: "tablelist/commonTable/listInfo",
-                icon: "",
-                isCache: "0",
-                isFrame: "1",
-                menuName: this.formData.menuName,
-                menuType: "C",
-                orderNum: "0",
-                parentId: this.formData.routePath,
-                path: uuid,
-                query: JSON.stringify(sqlKeyObj),
-                status: "0",
-                visible: "0",
-              };
-              let result = await addMenu(payLoad);
-              if (result.code == 200) {
-                this.$message.success("创建成功");
-                this.reloadRouter();
-              } else {
-                this.$message.warning("创建失败");
-              }
+              data.menuId = result.data;
+              res = await addDragTable(data);
             }
+
             // 关闭当前页面
             if (this.tId) {
+              if (res.code == 200) {
+                this.$message.success("修改成功");
+              } else {
+                this.$message.warning("修改失败");
+              }
               this.$tab.closePage();
               this.$router.push({
                 path: "/system/fromModel/index/tablelist",
               });
+              return;
+            }
+            if (res.code == 200) {
+              this.$message.success("创建成功");
+            } else {
+              this.$message.warning("创建失败");
             }
             this.isShowPreview = false;
           }