lrf402788946 преди 4 години
родител
ревизия
1c98f2479f
променени са 8 файла, в които са добавени 223 реда и са изтрити 13 реда
  1. 2 2
      config/menu-config.js
  2. 39 3
      layout/admin/admin-menu.vue
  3. 14 7
      layout/admin/menu/menu-item.vue
  4. 0 1
      layout/admin/navBar/default-select.vue
  5. 43 0
      store/auth/menu.js
  6. 43 0
      store/auth/role.js
  7. 39 0
      store/auth/user.js
  8. 43 0
      store/auth/userMenu.js

+ 2 - 2
config/menu-config.js

@@ -203,8 +203,8 @@ export const menu = [
         children: [
           { path: '/questionnaire/index', name: '问卷管理' },
           { path: '/itembank/index', name: '问卷题库' },
-          { path: '/questionstate/index', name: '问卷进度' },
-          { path: '/questionnaire/export/setting', name: '问卷导出设置' },
+          // { path: '/questionstate/index', name: '问卷进度' },
+          // { path: '/questionnaire/export/setting', name: '问卷导出设置' },
         ],
       },
       {

+ 39 - 3
layout/admin/admin-menu.vue

@@ -19,7 +19,7 @@
             :default-active="defualtActive"
           >
             <scroll-bar>
-              <menu-item :menus="menu"></menu-item>
+              <menu-item :menus="menu" :level="0"></menu-item>
             </scroll-bar>
           </el-menu>
         </template>
@@ -33,6 +33,8 @@ import menuItem from './menu/menu-item.vue';
 import * as menus from '@frame/config/menu-config';
 import scrollBar from './scrollBar.vue';
 import _ from 'lodash';
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: userMenu } = createNamespacedHelpers('userMenu');
 export default {
   name: 'admin-menu',
   props: {},
@@ -42,9 +44,11 @@ export default {
   },
   data: () => ({
     menu: [],
+    project: 'center',
   }),
   created() {},
   computed: {
+    ...mapState(['user', 'defaultOption']),
     project_modules() {
       return process.env.VUE_APP_MODULE;
     },
@@ -54,10 +58,11 @@ export default {
   },
   mounted() {
     let arr = _.get(menus, 'menu', []); //this.project_modules
-    let r = this.filterMenu(_.cloneDeep(arr), this.project_modules);
-    this.$set(this, `menu`, r);
+    // let r = this.filterMenu(_.cloneDeep(arr), this.project_modules);
+    // this.$set(this, `menu`, r);
   },
   methods: {
+    ...userMenu(['getMenu']),
     selectMenu(path, modules) {
       if (this.project_modules === modules) this.$router.push({ path: path });
     },
@@ -76,6 +81,37 @@ export default {
       });
       return _.compact(nm);
     },
+
+    async getUserMenu() {
+      const sessionMenu = sessionStorage.getItem('userMenu');
+      if (sessionMenu) {
+        this.$set(this, `menu`, JSON.parse(sessionMenu));
+      } else {
+        this.requestMenu();
+      }
+    },
+    async requestMenu() {
+      const { type, id: userid } = this.user;
+      const condition = { project: 'center', type, userid };
+      const res = await this.getMenu(condition);
+      if (this.$checkRes(res)) {
+        this.$set(this, `menu`, res.data);
+        sessionStorage.setItem('userMenu', JSON.stringify(res.data));
+      }
+    },
+  },
+  watch: {
+    user: {
+      deep: true,
+      immediate: true,
+      handler(val) {
+        if (this.menu.length > 0) return;
+        if (val) {
+          const { type, id } = val;
+          if (type && id) this.getUserMenu();
+        }
+      },
+    },
   },
 };
 </script>

+ 14 - 7
layout/admin/menu/menu-item.vue

@@ -2,19 +2,25 @@
   <div id="menu-item">
     <template v-for="(item, index) in menus">
       <!-- 没有子菜单情况 -->
-      <template v-if="!item.children">
-        <el-menu-item :index="item.path" @click="selectMenu(item.path, item.module)" :key="index">
+      <template v-if="item && item.children && item.children <= 0">
+        <el-menu-item :index="item.route" @click="selectMenu(item.route, item.module)" :key="index">
           <i v-if="item.icon" :class="item.icon"></i>
-          <span v-if="item.name" slot="title">{{ item.name }}</span>
+          <span v-if="item.title" slot="title">
+            <!-- <span :style="{ paddingLeft: `${level * 1}px` }">{{ item.title }}</span> -->
+            {{ item.title }}
+          </span>
         </el-menu-item>
       </template>
       <template v-else>
-        <el-submenu :index="item.name || item.path" :key="item.name">
+        <el-submenu :index="item.title || item.route" :key="item.title">
           <template slot="title">
             <i v-if="item && item.icon" :class="item.icon"></i>
-            <span v-if="item && item.name">{{ item.name }}</span>
+            <span v-if="item && item.title">
+              <!-- <span :style="{ paddingLeft: `${level * 1}px` }">{{ item.title }}</span> -->
+              {{ item.title }}
+            </span>
           </template>
-          <menu-item :menus="item.children"></menu-item>
+          <menu-item :menus="item.children" :level="level + 1"></menu-item>
         </el-submenu>
       </template>
     </template>
@@ -26,6 +32,7 @@ import { mapState, createNamespacedHelpers } from 'vuex';
 export default {
   name: 'menu-item',
   props: {
+    level: { type: Number, default: 0 },
     menus: { type: Array, require: true },
   },
   components: {},
@@ -47,7 +54,7 @@ export default {
 <style lang="less" scoped>
 .el-submenu .el-menu-item {
   min-width: 16rem !important;
-  padding-left: 3rem !important;
+  // padding-left: 3rem !important;
   background-color: #000c17 !important;
   &:hover {
     color: #fff !important;

+ 0 - 1
layout/admin/navBar/default-select.vue

@@ -177,7 +177,6 @@ export default {
     topOptions: {
       deep: true,
       handler(val, oval) {
-        console.log(val, oval);
         this.changeOpt(val);
       },
     },

+ 43 - 0
store/auth/menu.js

@@ -0,0 +1,43 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import axios from 'axios';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  interface: `/api/auth/menu`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.interface}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.interface}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.interface}/${payload}`);
+    return res;
+  },
+  async findProject({ commit }, { project, ...payload }) {
+    const res = await this.$axios.$get(`${api.interface}/project/${project}`, payload);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 43 - 0
store/auth/role.js

@@ -0,0 +1,43 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import axios from 'axios';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  interface: `/api/auth/role`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.interface}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.interface}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.interface}/${payload}`);
+    return res;
+  },
+  async roleMenu({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.interface}/menu/tree`, payload);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 39 - 0
store/auth/user.js

@@ -0,0 +1,39 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import axios from 'axios';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  interface: `/api/train/user`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.interface}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.interface}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.interface}/${payload}`);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 43 - 0
store/auth/userMenu.js

@@ -0,0 +1,43 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import axios from 'axios';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  interface: `/api/auth/usermenu`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.interface}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.interface}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.interface}/${payload}`);
+    return res;
+  },
+  async getMenu({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.interface}/menu`, payload);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};