ysy 2 lat temu
rodzic
commit
4ed7115dbd

+ 176 - 205
src/views/system/menu/components/menu-edit.vue

@@ -1,85 +1,54 @@
 <!-- 编辑弹窗 -->
 <template>
-  <ele-modal
-    width="720px"
-    :visible="visible"
-    :close-on-click-modal="false"
-    custom-class="ele-dialog-form"
-    :title="isUpdate ? '修改菜单' : '添加菜单'"
-    @update:visible="updateVisible"
-  >
+  <ele-modal width="720px" :visible="visible" :close-on-click-modal="false" custom-class="ele-dialog-form"
+    :title="isUpdate ? '修改菜单' : '添加菜单'" @update:visible="updateVisible">
     <el-form ref="form" :model="form" :rules="rules" label-width="100px">
       <el-row>
+
+
         <el-col :span="12">
           <el-form-item label="上级菜单:">
-            <ele-tree-select
-              clearable
-              v-model="form.parentId"
-              :data="menuList"
-              label-key="name"
-              value-key="id"
-              default-expand-all
-              placeholder="请选择上级菜单"
-            />
+            <ele-tree-select clearable v-model="form.parentId" :data="menuList" label-key="name" value-key="id"
+              default-expand-all placeholder="请选择上级菜单" />
           </el-form-item>
         </el-col>
         <el-col :span="12">
           <el-form-item label="菜单名称:" prop="name">
-            <el-input
-              clearable
-              v-model="form.name"
-              placeholder="请输入菜单名称"
-            />
+            <el-input clearable v-model="form.name" placeholder="请输入菜单名称" />
           </el-form-item>
         </el-col>
         <el-col :span="12">
           <el-form-item label="路由地址:" prop="url">
-            <el-input
-              clearable
-              v-model="form.url"
-              placeholder="请输入路由地址"
-            />
+            <el-input clearable v-model="form.url" placeholder="请输入路由地址" />
           </el-form-item>
         </el-col>
         <el-col :span="12">
           <el-form-item label="组件地址:" prop="component">
-            <el-input
-              clearable
-              v-model="form.component"
-              placeholder="请输入路由地址"
-            />
+            <el-input clearable v-model="form.component" placeholder="请输入路由地址" />
           </el-form-item>
         </el-col>
 
         <el-col :span="12">
           <el-form-item label="权限编码:" prop="permissionCode">
-            <el-input
-              clearable
-              v-model="form.permissionCode"
-              placeholder="请输入路由地址"
-            />
+            <el-input clearable v-model="form.permissionCode" placeholder="请输入路由地址" />
           </el-form-item>
         </el-col>
 
 
         <el-col :span="12">
-          <el-form-item label="菜单图标:">
-            <ele-icon-picker
-              v-model="form.icon"
-              placeholder="请选择菜单图标"
-              :disabled="form.type === 2"
-            />
+          <el-form-item v-if="form.rootId != -1" label="菜单图标:">
+            <ele-icon-picker v-model="form.icon" placeholder="请选择菜单图标" :disabled="form.type === 2" />
+          </el-form-item>
+
+          <el-form-item v-if="form.rootId == -1" label="菜单图标:">
+            <el-input clearable v-model="form.icon" placeholder="请输入pda图标" />
           </el-form-item>
+
         </el-col>
         <el-col :span="12">
           <el-form-item label="排序号:" prop="sort">
-            <el-input-number
-              :min="0"
-              v-model="form.sort"
-              placeholder="请输入排序号"
-              controls-position="right"
-              class="ele-fluid ele-text-left"
-            />
+            <el-input-number :min="0" v-model="form.sort" placeholder="请输入排序号" controls-position="right"
+              class="ele-fluid ele-text-left" />
           </el-form-item>
         </el-col>
         <el-col :span="12">
@@ -105,169 +74,171 @@
 </template>
 
 <script>
-  import { EleIconPicker } from 'ele-admin';
-  import { saveOrUpdate } from '@/api/system/menu';
+import { EleIconPicker } from 'ele-admin';
+import { saveOrUpdate } from '@/api/system/menu';
 
-  export default {
-    components: { EleIconPicker },
-    props: {
-      // 弹窗是否打开
-      visible: Boolean,
-      // 修改回显的数据
-      data: Object,
-      // 上级菜单id
-      parentId: [Number, String],
-      // 全部菜单数据
-      menuList: Array
+export default {
+  components: { EleIconPicker },
+  props: {
+    // 弹窗是否打开
+    visible: Boolean,
+    // 修改回显的数据
+    data: Object,
+    // 上级菜单id
+    parentId: [Number, String],
+    // 全部菜单数据
+    menuList: Array
+  },
+  data() {
+    const defaultForm = {
+      id: null,
+      parentId: '',
+      name: '',
+      type: 1,
+      icon: '',
+      url: '/',
+      component: '',
+      sort: null,
+      rootId: null,
+      permissionCode: 1
+    };
+    return {
+      defaultForm,
+      // 表单数据
+      form: { ...defaultForm },
+      // 表单验证规则
+      rules: {
+        name: [
+          { required: true, message: '请输入菜单名称', trigger: 'blur' }
+        ],
+        sort: [{ required: true, message: '请输入排序号', trigger: 'blur' }],
+        url: [{ required: true, message: '请输入菜单路由', trigger: 'blur' }],
+        type: [{ required: true, message: '请选择菜单类型', trigger: 'blur' }]
+      },
+      // 提交状态
+      loading: false,
+      // 是否是修改
+      isUpdate: false
+    };
+  },
+  computed: {
+    // pathPlaceholder() {
+    //   return this.form.openType === 2 ? '请输入外链地址' : '请输入路由地址';
+    // },
+    // componentPlaceholder() {
+    //   return this.form.openType === 1 ? '请输入内链地址' : '请输入组件路径';
+    // },
+    // // 是否开启响应式布局
+    // styleResponsive() {
+    //   return this.$store.state.theme.styleResponsive;
+    // }
+  },
+  methods: {
+    /* 保存编辑 */
+    save() {
+      this.$refs.form.validate((valid) => {
+        if (!valid) {
+          return false;
+        }
+        this.loading = true;
+        const data = {
+          ...this.form,
+          // menuType 对应的值与后端不一致在前端处理
+          // type: this.form.type === 2 ? 1 : 0,
+          parentId: this.form.parentId || 0
+        };
+        // const saveOrUpdate = this.isUpdate ? updateMenu : addMenu;
+        if (!this.isUpdate) {
+          delete data.id;
+        }
+        saveOrUpdate(data)
+          .then((res) => {
+            this.loading = false;
+            if (this.isUpdate) {
+              this.$message.success('菜单编辑成功');
+            } else {
+              this.$message.success('菜单新增成功');
+            }
+            this.updateVisible(false);
+            this.$emit('done');
+          })
+          .catch((e) => {
+            this.loading = false;
+            // this.$message.error(e.message);
+          });
+      });
     },
-    data () {
-      const defaultForm = {
-        id: null,
-        parentId: '',
-        name: '',
-        type: 1,
-        icon: '',
-        url: '',
-        component: '',
-        sort: null,
-        permissionCode: 1
-      };
-      return {
-        defaultForm,
-        // 表单数据
-        form: { ...defaultForm },
-        // 表单验证规则
-        rules: {
-          name: [
-            { required: true, message: '请输入菜单名称', trigger: 'blur' }
-          ],
-          sort: [{ required: true, message: '请输入排序号', trigger: 'blur' }],
-          url: [{ required: true, message: '请输入菜单路由', trigger: 'blur' }],
-          type: [{ required: true, message: '请选择菜单类型', trigger: 'blur' }]
-        },
-        // 提交状态
-        loading: false,
-        // 是否是修改
-        isUpdate: false
-      };
+    /* 更新visible */
+    updateVisible(value) {
+      this.$emit('update:visible', value);
     },
-    computed: {
-      // pathPlaceholder() {
-      //   return this.form.openType === 2 ? '请输入外链地址' : '请输入路由地址';
-      // },
-      // componentPlaceholder() {
-      //   return this.form.openType === 1 ? '请输入内链地址' : '请输入组件路径';
-      // },
-      // // 是否开启响应式布局
-      // styleResponsive() {
-      //   return this.$store.state.theme.styleResponsive;
+    /* menuType选择改变 */
+    onMenuTypeChange() {
+      // if (this.form.menuType === 0) {
+      //   this.form.authority = null;
+      //   this.form.openType = 0;
+      //   this.form.component = null;
+      // } else if (this.form.menuType === 1) {
+      //   if (this.form.openType === 2) {
+      //     this.form.authority = null;
+      //   }
+      // } else {
+      //   this.form.openType = 0;
+      //   this.form.icon = null;
+      //   this.form.path = null;
+      //   this.form.component = null;
+      //   this.form.hide = 0;
       // }
     },
-    methods: {
-      /* 保存编辑 */
-      save () {
-        this.$refs.form.validate((valid) => {
-          if (!valid) {
-            return false;
-          }
-          this.loading = true;
-          const data = {
-            ...this.form,
-            // menuType 对应的值与后端不一致在前端处理
-            // type: this.form.type === 2 ? 1 : 0,
-            parentId: this.form.parentId || 0
-          };
-          // const saveOrUpdate = this.isUpdate ? updateMenu : addMenu;
-          if (!this.isUpdate) {
-            delete data.id;
-          }
-          saveOrUpdate(data)
-            .then((res) => {
-              this.loading = false;
-              if (this.isUpdate) {
-                this.$message.success('菜单编辑成功');
-              } else {
-                this.$message.success('菜单新增成功');
-              }
-              this.updateVisible(false);
-              this.$emit('done');
-            })
-            .catch((e) => {
-              this.loading = false;
-              // this.$message.error(e.message);
-            });
-        });
-      },
-      /* 更新visible */
-      updateVisible (value) {
-        this.$emit('update:visible', value);
-      },
-      /* menuType选择改变 */
-      onMenuTypeChange () {
-        // if (this.form.menuType === 0) {
-        //   this.form.authority = null;
-        //   this.form.openType = 0;
-        //   this.form.component = null;
-        // } else if (this.form.menuType === 1) {
-        //   if (this.form.openType === 2) {
-        //     this.form.authority = null;
-        //   }
-        // } else {
-        //   this.form.openType = 0;
-        //   this.form.icon = null;
-        //   this.form.path = null;
-        //   this.form.component = null;
-        //   this.form.hide = 0;
-        // }
-      },
-      /* openType选择改变 */
-      onOpenTypeChange () {
-        if (this.form.openType === 2) {
-          this.form.component = null;
-          this.form.authority = null;
-        }
+    /* openType选择改变 */
+    onOpenTypeChange() {
+      if (this.form.openType === 2) {
+        this.form.component = null;
+        this.form.authority = null;
       }
-      /* 判断是否是外链 */
-      // isUrl(url) {
-      //   return !!(
-      //     url &&
-      //     (url.startsWith('http://') ||
-      //       url.startsWith('https://') ||
-      //       url.startsWith('//'))
-      //   );
-      // },
-      /* 判断是否是目录 */
-      // isDirectory(d) {
-      //   return !!d.children?.length && !d.component;
-      // }
-    },
-    watch: {
-      visible (visible) {
-        if (visible) {
-          if (this.data) {
-            // const isInnerLink = this.isUrl(this.data.component) ? 1 : 0;
-            // menuType 对应的值与后端不一致在前端处理
-            // const menuType =
-            //   this.data.type === 1
-            //     ? 2
-            //     : this.isDirectory(this.data)
-            //     ? 0
-            //     : 1;
-            this.$util.assignObject(this.form, {
-              ...this.data,
-              // openType: this.isUrl(this.data.path) ? 2 : isInnerLink,
-              parentId: this.data.parentId == 0 ? '' : this.data.parentId ?? ''
-            });
-            this.isUpdate = true;
-          } else {
-            this.form.parentId = this.parentId ?? '';
-            this.isUpdate = false;
-          }
+    }
+    /* 判断是否是外链 */
+    // isUrl(url) {
+    //   return !!(
+    //     url &&
+    //     (url.startsWith('http://') ||
+    //       url.startsWith('https://') ||
+    //       url.startsWith('//'))
+    //   );
+    // },
+    /* 判断是否是目录 */
+    // isDirectory(d) {
+    //   return !!d.children?.length && !d.component;
+    // }
+  },
+  watch: {
+    visible(visible) {
+      if (visible) {
+        if (this.data) {
+          // const isInnerLink = this.isUrl(this.data.component) ? 1 : 0;
+          // menuType 对应的值与后端不一致在前端处理
+          // const menuType =
+          //   this.data.type === 1
+          //     ? 2
+          //     : this.isDirectory(this.data)
+          //     ? 0
+          //     : 1;
+
+          this.$util.assignObject(this.form, {
+            ...this.data,
+            // openType: this.isUrl(this.data.path) ? 2 : isInnerLink,
+            parentId: this.data.parentId == 0 ? '' : this.data.parentId ?? ''
+          });
+          this.isUpdate = true;
         } else {
-          this.$refs.form.clearValidate();
-          this.form = { ...this.defaultForm };
+          this.form.parentId = this.parentId ?? '';
+          this.isUpdate = false;
         }
+      } else {
+        this.$refs.form.clearValidate();
+        this.form = { ...this.defaultForm };
       }
     }
-  };
+  }
+};
 </script>

+ 1 - 0
src/views/system/menu/index.vue

@@ -79,6 +79,7 @@
             class="ele-action"
             title="确定要删除吗?"
             @confirm="remove(row)"
+            v-if="row.id != -1"
           >
             <template v-slot:reference>
               <el-link type="danger" :underline="false" icon="el-icon-delete">

+ 1 - 1
vue.config.js

@@ -33,7 +33,7 @@ module.exports = {
       // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
       '/api': {
         // target: 'http://124.71.68.31:50001',
-        target: 'http://192.168.1.139:18086',
+        target: 'http://192.168.1.125:18086',
         // target: 'http://192.168.1.132:18086',
         // target: 'http://192.168.1.147:18087',
         changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域