Browse Source

不用权限用户,显示不同菜单,当前登录账号不能删除自己。

soft5566 2 years ago
parent
commit
f1d8a2299a

+ 83 - 51
src/layout/components/Sidebar/index.vue

@@ -1,56 +1,88 @@
 <template>
 <template>
-  <div :class="{'has-logo':showLogo}">
-    <logo v-if="showLogo" :collapse="isCollapse" />
-    <el-scrollbar wrap-class="scrollbar-wrapper">
-      <el-menu
-        :default-active="activeMenu"
-        :collapse="isCollapse"
-        :background-color="variables.menuBg"
-        :text-color="variables.menuText"
-        :unique-opened="false"
-        :active-text-color="variables.menuActiveText"
-        :collapse-transition="false"
-        mode="vertical"
-      >
-        <sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" />
-      </el-menu>
-    </el-scrollbar>
-  </div>
+	<div :class="{'has-logo':showLogo}">
+		<logo v-if="showLogo" :collapse="isCollapse" />
+		<el-scrollbar wrap-class="scrollbar-wrapper">
+			<el-menu :default-openeds="['/systemset']" :default-active="activeMenu" :collapse="isCollapse" :background-color="variables.menuBg"
+				:text-color="variables.menuText" :unique-opened="false" :active-text-color="variables.menuActiveText" :collapse-transition="false"
+				mode="vertical">
+				<sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" />
+			</el-menu>
+		</el-scrollbar>
+	</div>
 </template>
 </template>
 
 
 <script>
 <script>
-import { mapGetters } from 'vuex'
-import Logo from './Logo'
-import SidebarItem from './SidebarItem'
-import variables from '@/styles/variables.scss'
+	import {
+		mapGetters
+	} from 'vuex'
+	import Logo from './Logo'
+	import SidebarItem from './SidebarItem'
+	import variables from '@/styles/variables.scss'
 
 
-export default {
-  components: { SidebarItem, Logo },
-  computed: {
-    ...mapGetters([
-      'sidebar'
-    ]),
-    routes() {
-      return this.$router.options.routes
-    },
-    activeMenu() {
-      const route = this.$route
-      const { meta, path } = route
-      // if set path, the sidebar will highlight the path you set
-      if (meta.activeMenu) {
-        return meta.activeMenu
-      }
-      return path
-    },
-    showLogo() {
-      return this.$store.state.settings.sidebarLogo
-    },
-    variables() {
-      return variables
-    },
-    isCollapse() {
-      return !this.sidebar.opened
-    }
-  }
-}
-</script>
+	export default {
+		components: {
+			SidebarItem,
+			Logo
+		},
+		computed: {
+			...mapGetters([
+				'sidebar'
+			]),
+			routes() {
+				// 查看权限: 1 管理员 admin, 2 超级管理员 superAdmin
+				// console.log(this.$store.state.user.level)
+				// console.log(this.$router.options.routes);
+				var p = this.$store.state.user.level;
+				var returnRoutes = [];
+				const r = this.$router.options.routes;
+				for (var i = 0; i < r.length; i++) {
+					if (p == 2) {
+						if (typeof r[i].meta !== 'undefined' && typeof r[i].meta.roles !== 'undefined') {
+							if (r[i].meta.roles.includes('superAdmin')) {
+								returnRoutes.push(r[i]);
+							}
+						} else if (typeof r[i].children !== 'undefined' && typeof r[i].children[0].meta.roles !== 'undefined') {
+							if (r[i].children[0].meta.roles.includes('superAdmin')) {
+								returnRoutes.push(r[i]);
+							}
+						}
+					} else {
+						if (typeof r[i].meta !== 'undefined' && typeof r[i].meta.roles !== 'undefined') {
+							if (r[i].meta.roles.includes('admin')) {
+								returnRoutes.push(r[i]);
+							}
+						} else if (typeof r[i].children !== 'undefined' && typeof r[i].children[0].meta.roles !== 'undefined') {
+							if (r[i].children[0].meta.roles.includes('admin')) {
+								returnRoutes.push(r[i]);
+							}
+						}
+					}
+				}
+
+				// 返回过滤的路由
+				return returnRoutes;
+			},
+			activeMenu() {
+				const route = this.$route
+				const {
+					meta,
+					path
+				} = route
+				// if set path, the sidebar will highlight the path you set
+				if (meta.activeMenu) {
+					return meta.activeMenu
+				}
+				return path
+			},
+			showLogo() {
+				return this.$store.state.settings.sidebarLogo
+			},
+			variables() {
+				return variables
+			},
+			isCollapse() {
+				return !this.sidebar.opened
+			}
+		}
+	}
+</script>

+ 3 - 2
src/router/index.js

@@ -51,6 +51,7 @@ export const constantRoutes = [{
 			name: 'Data',
 			name: 'Data',
 			component: () => import('@/views/data/index'),
 			component: () => import('@/views/data/index'),
 			meta: {
 			meta: {
+				roles: ['admin', 'superAdmin'],
 				title: '数据中台',
 				title: '数据中台',
 				icon: 'order'
 				icon: 'order'
 			}
 			}
@@ -66,6 +67,7 @@ export const constantRoutes = [{
 			name: 'StdbookMgr',
 			name: 'StdbookMgr',
 			component: () => import('@/views/stdbookMgr/index'),
 			component: () => import('@/views/stdbookMgr/index'),
 			meta: {
 			meta: {
+				roles: ['superAdmin'],
 				title: '台账管理',
 				title: '台账管理',
 				icon: 'order'
 				icon: 'order'
 			}
 			}
@@ -75,13 +77,12 @@ export const constantRoutes = [{
 	{
 	{
 		path: '/systemset',
 		path: '/systemset',
 		component: Layout,
 		component: Layout,
-		// redirect: '/systemset',
 		name: 'Systemset',
 		name: 'Systemset',
 		meta: {
 		meta: {
+			roles: ['superAdmin'],
 			title: '系统设置',
 			title: '系统设置',
 			icon: 'systemSet'
 			icon: 'systemSet'
 		},
 		},
-		// component: () => import('@/views/systemSet/index'),
 		children: [{
 		children: [{
 			path: 'accountMgr',
 			path: 'accountMgr',
 			name: 'AccountMgr',
 			name: 'AccountMgr',

+ 8 - 8
src/store/modules/user.js

@@ -147,14 +147,14 @@ const actions = {
 		})
 		})
 		// 修改:下面被注释了
 		// 修改:下面被注释了
 		// return new Promise((resolve, reject) => {
 		// return new Promise((resolve, reject) => {
-		//   logout(state.token).then(() => {
-		//     removeToken() // must remove  token  first
-		//     resetRouter()
-		//     commit('RESET_STATE')
-		//     resolve()
-		//   }).catch(error => {
-		//     reject(error)
-		//   })
+		// 	logout(state.token).then(() => {
+		// 		removeToken() // must remove  token  first
+		// 		resetRouter()
+		// 		commit('RESET_STATE')
+		// 		resolve()
+		// 	}).catch(error => {
+		// 		reject(error)
+		// 	})
 		// })
 		// })
 	},
 	},
 
 

+ 16 - 2
src/views/accountMgr/index.vue

@@ -69,7 +69,11 @@
 									<div class="action-btns">
 									<div class="action-btns">
 										<el-link class="bg-btn" @click="reset_amount(scope.$index, scope.row)">密码重置</el-link>
 										<el-link class="bg-btn" @click="reset_amount(scope.$index, scope.row)">密码重置</el-link>
 										<el-link class="bg-btn" @click="edit_amount(scope.$index, scope.row)">修改</el-link>
 										<el-link class="bg-btn" @click="edit_amount(scope.$index, scope.row)">修改</el-link>
-										<el-link type="danger" @click="delete_amount(scope.$index, scope.row)">删除</el-link>
+										<el-link v-if="currentUserName !== scope.row.adminName" type="danger"
+											@click="delete_amount(scope.$index, scope.row)">删除</el-link>
+										<el-tooltip v-else class="item" effect="dark" content="当前登录账号,不能删除!" placement="top-end">
+											<span style="cursor: not-allowed;">删除</span>
+										</el-tooltip>
 									</div>
 									</div>
 								</template>
 								</template>
 							</el-table-column>
 							</el-table-column>
@@ -428,6 +432,11 @@
 			 * 条件
 			 * 条件
 			 */
 			 */
 			get_condtion() {
 			get_condtion() {
+				if (this.currentUserLevel !== 2) {
+					this.$message.error('请用【超级管理员】账号登录!')
+					return
+				}
+
 				let data = {
 				let data = {
 					page: this.pagination.currentPage,
 					page: this.pagination.currentPage,
 					rows: this.pagination.pageSize
 					rows: this.pagination.pageSize
@@ -490,8 +499,13 @@
 			 */
 			 */
 			delete_amount(index, row) {
 			delete_amount(index, row) {
 				// console.log(index, row);
 				// console.log(index, row);
+				if (this.currentUserName === row.adminName) {
+					this.$message.error('当前登录账号,不能删除!');
+					return;
+				}
 				this.deleteAccountData.id = row.id;
 				this.deleteAccountData.id = row.id;
 				this.deleteAccountData.delete_account = row.adminName;
 				this.deleteAccountData.delete_account = row.adminName;
+				// 显示删除确认对话框
 				this.dialog_delete_account = true;
 				this.dialog_delete_account = true;
 			},
 			},
 			/**
 			/**
@@ -502,7 +516,7 @@
 			reset_amount(index, row) {
 			reset_amount(index, row) {
 				this.resetAccountData.id = row.id
 				this.resetAccountData.id = row.id
 				this.resetAccountData.reset_account = row.adminName
 				this.resetAccountData.reset_account = row.adminName
-				
+
 				this.dialog_reset_account = true
 				this.dialog_reset_account = true
 			},
 			},
 			/**
 			/**

+ 0 - 182
src/views/systemSet/index.vue

@@ -1,182 +0,0 @@
-<template>
-  <div class="app-container">
-    <el-row>
-      <el-col :span="24">
-        <div class="cell">
-          <div class="cell-title">
-            <div class="title-left">
-              <div class="title">系统设置</div>
-            </div>
-          </div>
-          <div class="cell-body">
-            <div class="label-date-range">免费取消时间设置:</div>
-            <el-date-picker v-model="valueDateRange" type="daterange" :editable="false" :clearable="false" unlink-panels range-separator="至"
-              start-placeholder="开始日期" end-placeholder="结束日期" link :picker-options="pickerOptions" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
-              style="width: 280px;">
-            </el-date-picker>
-            <div class="label-date">系统暂停时间设置:</div>
-            <el-date-picker v-model="valueDate" type="date" placeholder="选择日期" :editable="false" :clearable="false" value-format="yyyy-MM-dd"
-              format="yyyy-MM-dd" style="width: 150px;">
-            </el-date-picker>
-            <div class="submit-ok">
-              <el-button type="primary" class="ok" @click="submit_handler">确定</el-button>
-            </div>
-          </div>
-        </div>
-      </el-col>
-    </el-row>
-  </div>
-</template>
-
-<script>
-  import {
-    updateSet,
-    getSet
-  } from '@/api/systemSet';
-
-  export default {
-    data() {
-      return {
-        id: '',
-        valueDateRange: '',
-        valueDate: '',
-        pickerOptions: {
-          shortcuts: [{
-            text: '最近一周',
-            onClick(picker) {
-              const end = new Date();
-              const start = new Date();
-              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
-              picker.$emit('pick', [start, end]);
-            }
-          }, {
-            text: '最近一个月',
-            onClick(picker) {
-              const end = new Date();
-              const start = new Date();
-              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
-              picker.$emit('pick', [start, end]);
-            }
-          }, {
-            text: '最近三个月',
-            onClick(picker) {
-              const end = new Date();
-              const start = new Date();
-              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
-              picker.$emit('pick', [start, end]);
-            }
-          }]
-        }
-      }
-    },
-    mounted() {
-      this.get_data();
-    },
-    methods: {
-      /**
-       * 获取配置数据
-       */
-      get_data() {
-        // 开始发送请求,获取配置数据
-        getSet().then((res) => {
-          // console.log('getSet', res);
-          if (res.code === 200) {
-            this.id = res.data.id;
-            this.valueDateRange = res.data.free_cancel.split('~');
-            this.valueDate = res.data.stop_book;
-          } else {
-            this.$message.error(res.message);
-          }
-        }).catch((err) => {
-          // console.log(err);
-          this.$message.error(err.message);
-        });
-      },
-      /**
-       * 提交修改后的配置
-       */
-      submit_handler() {
-        //form表单校验通过,可以进行下一步操作
-        const params = {
-          id: this.id,
-          free_cancel: this.valueDateRange[0] + '~' + this.valueDateRange[1],
-          stop_book: this.valueDate
-        };
-        // console.log(params);
-        // 开始发送更新配置请求
-        updateSet(params).then((res) => {
-          // console.log(res);
-          if (res.code === 200) {
-            this.$message.success(res.message);
-          } else {
-            this.$message.error(res.message);
-          }
-        }).catch((err) => {
-          // console.log(err);
-          this.$message.error(err.message);
-        });
-      }
-    }
-  }
-</script>
-
-<style lang="scss" scoped>
-  .app-container {
-    background-color: #EFF2F7;
-    padding: 10px;
-
-    .el-row {
-
-      .el-col {
-        padding: 10px;
-
-        .cell {
-          padding: 30px;
-          border-radius: 10px;
-          background-color: #FFFFFF;
-          // box-shadow: 5px 5px 15px #979797;
-          box-shadow: 0px 3px 21px 0px rgba(60, 108, 254, 0.16);
-
-          .cell-title {
-            display: flex;
-            justify-content: space-between;
-            align-items: center;
-            margin-bottom: 30px;
-            padding-bottom: 30px;
-            border-bottom: 1px solid #CCCCCC;
-
-            .title {
-              font-size: 22px;
-              font-family: Microsoft YaHei-3970(82674968);
-              font-weight: bold;
-              color: #1A202B;
-            }
-          }
-
-          .cell-body {
-            height: 630px;
-            padding-left: 30px;
-
-            .label-date-range {
-              margin-bottom: 12px;
-              font-size: 18px;
-            }
-
-            .label-date {
-              margin: 28px 0 12px;
-            }
-
-            .submit-ok {
-              margin: 28px 0 12px;
-
-              .ok {
-                background-color: #3762FE;
-                border-color: #3762FE;
-              }
-            }
-          }
-        }
-      }
-    }
-  }
-</style>