Commit 44c5b7bb8bb357924648c465e0e6764162d84de1

Authored by 杨泽宇
1 parent 668ef9f8

修改菜单权限

src/layout/menu.vue
@@ -49,71 +49,14 @@ onMounted(() => { @@ -49,71 +49,14 @@ onMounted(() => {
49 > 49 >
50 <template #title> 50 <template #title>
51 <el-icon><location /></el-icon> 51 <el-icon><location /></el-icon>
52 - <span>{{ item.name }}假菜单</span> 52 + <span>{{ item.name }}</span>
53 </template> 53 </template>
54 <el-menu-item-group v-for="(ele, i) in item.menuList" :key="i"> 54 <el-menu-item-group v-for="(ele, i) in item.menuList" :key="i">
55 - <el-menu-item :index="ele.path ? ele.path : '/'">{{ 55 + <el-menu-item :index="ele.url ? ele.url : '/'">{{
56 ele.name 56 ele.name
57 }}</el-menu-item> 57 }}</el-menu-item>
58 </el-menu-item-group> 58 </el-menu-item-group>
59 </el-sub-menu> 59 </el-sub-menu>
60 -  
61 - <el-sub-menu index="11">  
62 - <template #title>  
63 - <el-icon><location /></el-icon>  
64 - <span>物业管理真菜单可点</span>  
65 - </template>  
66 - <el-menu-item-group>  
67 - <el-menu-item index="/property">物业列表</el-menu-item>  
68 - </el-menu-item-group>  
69 - </el-sub-menu>  
70 - <el-sub-menu index="12">  
71 - <template #title>  
72 - <el-icon><location /></el-icon>  
73 - <span>小区管理真菜单可点</span>  
74 - </template>  
75 - <el-menu-item-group>  
76 - <el-menu-item index="/community">小区管理</el-menu-item>  
77 - <el-menu-item index="/housekeeper">楼宇管理</el-menu-item>  
78 - <el-menu-item index="/houses">房屋管理</el-menu-item>  
79 - </el-menu-item-group>  
80 - </el-sub-menu>  
81 - <el-sub-menu index="13">  
82 - <template #title>  
83 - <el-icon><location /></el-icon>  
84 - <span>用户管理真菜单可点</span>  
85 - </template>  
86 - <el-menu-item-group>  
87 - <el-menu-item index="/user">用户列表</el-menu-item>  
88 - </el-menu-item-group>  
89 - </el-sub-menu>  
90 - <el-sub-menu index="14">  
91 - <template #title>  
92 - <el-icon><location /></el-icon>  
93 - <span>角色管理真菜单可点</span>  
94 - </template>  
95 - <el-menu-item-group>  
96 - <el-menu-item index="/role">角色列表</el-menu-item>  
97 - </el-menu-item-group>  
98 - </el-sub-menu>  
99 - <el-sub-menu index="15">  
100 - <template #title>  
101 - <el-icon><location /></el-icon>  
102 - <span>权限管理真菜单可点</span>  
103 - </template>  
104 - <el-menu-item-group>  
105 - <el-menu-item index="/permission">权限列表</el-menu-item>  
106 - </el-menu-item-group>  
107 - </el-sub-menu>  
108 - <el-sub-menu index="16">  
109 - <template #title>  
110 - <el-icon><location /></el-icon>  
111 - <span>系统管理真菜单可点</span>  
112 - </template>  
113 - <el-menu-item-group>  
114 - <el-menu-item index="/system">基本信息</el-menu-item>  
115 - </el-menu-item-group>  
116 - </el-sub-menu>  
117 </el-menu> 60 </el-menu>
118 </el-scrollbar> 61 </el-scrollbar>
119 </template> 62 </template>
src/pinia/modules/login.ts
@@ -4,27 +4,49 @@ interface LoginUser { @@ -4,27 +4,49 @@ interface LoginUser {
4 token: string, 4 token: string,
5 organizationId: number, 5 organizationId: number,
6 id: number, 6 id: number,
7 - userName: string 7 + userName: string,
  8 + organizationType: number | null,
  9 + organizationName: string,
  10 + organizationLogo: string
8 } 11 }
9 const id: string = 'login' 12 const id: string = 'login'
10 const state: Function = () => ({ 13 const state: Function = () => ({
11 token: '', 14 token: '',
12 organizationId: null, 15 organizationId: null,
13 id: null, 16 id: null,
14 - userName: '' 17 + userName: '',
  18 + organizationType: null,
  19 + organizationName: '',
  20 + organizationLogo: ''
15 }) 21 })
16 const getters = { 22 const getters = {
17 getToken() { 23 getToken() {
  24 + // 记录登录状态的标识
18 return this.token 25 return this.token
19 }, 26 },
20 getOid() { 27 getOid() {
  28 + // 当前登录人的组织id
21 return this.organizationId 29 return this.organizationId
22 }, 30 },
23 getId() { 31 getId() {
  32 + // 当前登录人的id
24 return this.id 33 return this.id
25 }, 34 },
26 getUserName() { 35 getUserName() {
  36 + // 当前登录人的用户名
27 return this.userName 37 return this.userName
  38 + },
  39 + getOtype () {
  40 + // 1 物业管理员,2 公益管理员
  41 + return this.organizationType
  42 + },
  43 + getOname () {
  44 + // 当前登录的组织名称
  45 + return this.organizationName
  46 + },
  47 + getOlogo () {
  48 + // 当前登陆的组织logo
  49 + return this.organizationLogo
28 } 50 }
29 } 51 }
30 const actions = { 52 const actions = {
@@ -33,9 +55,13 @@ const actions = { @@ -33,9 +55,13 @@ const actions = {
33 this.organizationId = obj.organizationId 55 this.organizationId = obj.organizationId
34 this.id = obj.id 56 this.id = obj.id
35 this.userName = obj.userName 57 this.userName = obj.userName
  58 + this.organizationName = obj.organizationName
  59 + this.organizationType = obj.organizationType
  60 + this.organizationLogo = obj.organizationLogo
36 }, 61 },
37 removeToken(msg: string | null) { 62 removeToken(msg: string | null) {
38 this.token = '' 63 this.token = ''
  64 + window.localStorage.removeItem('store-data')
39 ElMessage.success(msg || '已退出登录'); 65 ElMessage.success(msg || '已退出登录');
40 setTimeout(() => { 66 setTimeout(() => {
41 router.replace('/login') 67 router.replace('/login')
src/views/permission/index.vue
@@ -16,7 +16,7 @@ const getList = async () =&gt; { @@ -16,7 +16,7 @@ const getList = async () =&gt; {
16 data.loading = true; 16 data.loading = true;
17 try { 17 try {
18 const res = await permissionList(); 18 const res = await permissionList();
19 - data.list = res.data.data; 19 + data.list = res?.data?.data;
20 } catch (e) { 20 } catch (e) {
21 console.log(e); 21 console.log(e);
22 } finally { 22 } finally {
src/views/property/index.vue
@@ -42,8 +42,8 @@ const getList = async () =&gt; { @@ -42,8 +42,8 @@ const getList = async () =&gt; {
42 data.loading = true; 42 data.loading = true;
43 try { 43 try {
44 const res = await propertyList(data.params.query); 44 const res = await propertyList(data.params.query);
45 - data.list = res.data.data.list;  
46 - data.params.total = res.data.data.total; 45 + data.list = res?.data?.data?.list;
  46 + data.params.total = res?.data?.data?.total;
47 } catch (e) { 47 } catch (e) {
48 console.log(e); 48 console.log(e);
49 } finally { 49 } finally {
src/views/role/index.vue
@@ -182,8 +182,18 @@ onMounted(() =&gt; { @@ -182,8 +182,18 @@ onMounted(() =&gt; {
182 </template> 182 </template>
183 </el-table-column> 183 </el-table-column>
184 <el-table-column label="操作" align="center"> 184 <el-table-column label="操作" align="center">
  185 + <!-- 超级管理员、商务管理员、物业管理员、公益管理员这四个角色是系统角色,不可以编辑、删除。通过code字段判断 -->
185 <template #default="scope"> 186 <template #default="scope">
186 - <el-button type="text" 187 + <el-button
  188 + type="text"
  189 + v-show="
  190 + ![
  191 + 'SUPER_ADMIN',
  192 + 'BUSINESS_ADMIN',
  193 + 'PROPERTY_ADMIN',
  194 + 'PUBLIC_BENEFIT_ADMIN',
  195 + ].includes(scope.row.code)
  196 + "
187 ><router-link :to="{ path: '/role/edit', query: scope.row }" 197 ><router-link :to="{ path: '/role/edit', query: scope.row }"
188 >编辑</router-link 198 >编辑</router-link
189 ></el-button 199 ></el-button
@@ -206,7 +216,17 @@ onMounted(() =&gt; { @@ -206,7 +216,17 @@ onMounted(() =&gt; {
206 >权限</router-link 216 >权限</router-link
207 ></el-button 217 ></el-button
208 > 218 >
209 - <el-button type="text" @click="handleDelete(scope.row)" 219 + <el-button
  220 + type="text"
  221 + @click="handleDelete(scope.row)"
  222 + v-show="
  223 + ![
  224 + 'SUPER_ADMIN',
  225 + 'BUSINESS_ADMIN',
  226 + 'PROPERTY_ADMIN',
  227 + 'PUBLIC_BENEFIT_ADMIN',
  228 + ].includes(scope.row.code)
  229 + "
210 >删除</el-button 230 >删除</el-button
211 > 231 >
212 </template> 232 </template>
src/views/role/permission.vue
@@ -60,8 +60,8 @@ const submitForm = (formEl: InstanceType&lt;typeof ElForm&gt; | undefined) =&gt; { @@ -60,8 +60,8 @@ const submitForm = (formEl: InstanceType&lt;typeof ElForm&gt; | undefined) =&gt; {
60 const getPermissions = async (roleId = useRoute().query.roleId) => { 60 const getPermissions = async (roleId = useRoute().query.roleId) => {
61 try { 61 try {
62 let res = await rolePermission({ roleId: roleId }); 62 let res = await rolePermission({ roleId: roleId });
63 - form.permissions = res.data.data;  
64 - form.defaultPermissions = getCheckedPermissions(res.data.data) 63 + form.permissions = res?.data?.data;
  64 + form.defaultPermissions = getCheckedPermissions(res?.data?.data)
65 } catch (e) { 65 } catch (e) {
66 console.log(e); 66 console.log(e);
67 } 67 }
src/views/role/user.vue
@@ -43,8 +43,8 @@ const getList = async () =&gt; { @@ -43,8 +43,8 @@ const getList = async () =&gt; {
43 data.loading = true; 43 data.loading = true;
44 try { 44 try {
45 const res = await roleUser(data.params.query); 45 const res = await roleUser(data.params.query);
46 - data.list = res.data.data.list;  
47 - data.params.total = res.data.data.total; 46 + data.list = res?.data?.data?.list;
  47 + data.params.total = res?.data?.data?.total;
48 } catch (e) { 48 } catch (e) {
49 console.log(e); 49 console.log(e);
50 } finally { 50 } finally {
src/views/user/edit.vue
@@ -5,6 +5,7 @@ import { roleList } from &quot;@/api/user/role&quot;; @@ -5,6 +5,7 @@ import { roleList } from &quot;@/api/user/role&quot;;
5 import { getTableList } from "@/api/community/residence"; 5 import { getTableList } from "@/api/community/residence";
6 import { useRoute } from "vue-router"; 6 import { useRoute } from "vue-router";
7 import { validMobile } from "@/utils/validate"; 7 import { validMobile } from "@/utils/validate";
  8 +import * as store from '@/pinia';
8 import type { ElForm } from "element-plus"; 9 import type { ElForm } from "element-plus";
9 const { 10 const {
10 appContext: { 11 appContext: {
@@ -26,6 +27,9 @@ let form = reactive({ @@ -26,6 +27,9 @@ let form = reactive({
26 checkList: [], 27 checkList: [],
27 communityList: [], 28 communityList: [],
28 }); 29 });
  30 +let asyncData = reactive({
  31 + userInfo: null
  32 +})
29 const ruleFormRef = ref<InstanceType<typeof ElForm>>(); 33 const ruleFormRef = ref<InstanceType<typeof ElForm>>();
30 /** 34 /**
31 * 校验手机号格式 35 * 校验手机号格式
@@ -129,9 +133,9 @@ const getRoleList = async (pageSize: number = 20) =&gt; { @@ -129,9 +133,9 @@ const getRoleList = async (pageSize: number = 20) =&gt; {
129 page: 1, 133 page: 1,
130 pageSize: pageSize, 134 pageSize: pageSize,
131 }); 135 });
132 - form.roles = res.data.data.list;  
133 - if (res.data.data.total > pageSize) {  
134 - getRoleList(res.data.data.total); 136 + form.roles = res?.data?.data?.list;
  137 + if (res?.data?.data?.total > pageSize) {
  138 + getRoleList(res?.data?.data?.total);
135 } 139 }
136 } catch (e) { 140 } catch (e) {
137 console.log(e); 141 console.log(e);
@@ -148,15 +152,17 @@ const getCommunityList = async (pageSize: number = 20) =&gt; { @@ -148,15 +152,17 @@ const getCommunityList = async (pageSize: number = 20) =&gt; {
148 type: 0, 152 type: 0,
149 pageSize: pageSize, 153 pageSize: pageSize,
150 }); 154 });
151 - form.communities = res.data.data.list;  
152 - if (res.data.data.total > pageSize) {  
153 - getCommunityList(res.data.data.total); 155 + form.communities = res?.data?.data?.list;
  156 + if (res?.data?.data?.total > pageSize) {
  157 + getCommunityList(res?.data?.data?.total);
154 } 158 }
155 } catch (e) { 159 } catch (e) {
156 console.log(e); 160 console.log(e);
157 } 161 }
158 }; 162 };
159 onMounted(() => { 163 onMounted(() => {
  164 + asyncData.userInfo = store.family.loginStore().id
  165 + asyncData.userType = store.family.loginStore().organizationType
160 getRoleList(); 166 getRoleList();
161 getCommunityList(); 167 getCommunityList();
162 form.data = useRoute().query; 168 form.data = useRoute().query;
@@ -218,11 +224,13 @@ onMounted(() =&gt; { @@ -218,11 +224,13 @@ onMounted(() =&gt; {
218 v-for="(item, index) in form.roles" 224 v-for="(item, index) in form.roles"
219 :key="index" 225 :key="index"
220 :label="item.id" 226 :label="item.id"
  227 + :disabled="asyncData.userInfo === 1 && item.code !== 'BUSINESS_ADMIN'"
221 >{{ item.roleName }}</el-checkbox 228 >{{ item.roleName }}</el-checkbox
222 > 229 >
223 </el-checkbox-group> 230 </el-checkbox-group>
224 </el-form-item> 231 </el-form-item>
225 - <el-form-item label="小区" style="width: 100%"> 232 + <!-- 当前登录的用户是物业管理员,表单里才有关联小区 -->
  233 + <el-form-item label="小区" style="width: 100%" v-show="asyncData.userType === '1'">
226 <el-checkbox-group 234 <el-checkbox-group
227 v-model="form.communityList" 235 v-model="form.communityList"
228 @change="(data) => (form.data.neighborhoodIds = data.join(','))" 236 @change="(data) => (form.data.neighborhoodIds = data.join(','))"
src/views/user/index.vue
@@ -39,8 +39,8 @@ const getList = async () =&gt; { @@ -39,8 +39,8 @@ const getList = async () =&gt; {
39 data.loading = true; 39 data.loading = true;
40 try { 40 try {
41 const res = await userList(data.params.query); 41 const res = await userList(data.params.query);
42 - data.list = res.data.data.list;  
43 - data.params.total = res.data.data.total; 42 + data.list = res?.data?.data?.list;
  43 + data.params.total = res?.data?.data?.total;
44 } catch (e) { 44 } catch (e) {
45 console.log(e); 45 console.log(e);
46 } finally { 46 } finally {
src/views/user/login.vue
@@ -36,7 +36,8 @@ const submitForm = (formEl: InstanceType&lt;typeof ElForm&gt; | undefined) =&gt; { @@ -36,7 +36,8 @@ const submitForm = (formEl: InstanceType&lt;typeof ElForm&gt; | undefined) =&gt; {
36 login(loginForm).then((res) => { 36 login(loginForm).then((res) => {
37 if (res?.data) { 37 if (res?.data) {
38 globalProperties.$message.success("登录成功"); 38 globalProperties.$message.success("登录成功");
39 - store.family.loginStore().setUserInfo(res.data.data); 39 + // 登录成功返回的参数含义,到pinia/modules/login.ts中查看
  40 + store.family.loginStore().setUserInfo(res?.data?.data);
40 getMenu().then((res) => { 41 getMenu().then((res) => {
41 setTimeout(() => { 42 setTimeout(() => {
42 router.push({ path: "/" }); 43 router.push({ path: "/" });
@@ -55,7 +56,7 @@ const submitForm = (formEl: InstanceType&lt;typeof ElForm&gt; | undefined) =&gt; { @@ -55,7 +56,7 @@ const submitForm = (formEl: InstanceType&lt;typeof ElForm&gt; | undefined) =&gt; {
55 const getMenu = async () => { 56 const getMenu = async () => {
56 try { 57 try {
57 let res = await menuData(); 58 let res = await menuData();
58 - store.family.menuStore().setMenuList(res.data.data); 59 + store.family.menuStore().setMenuList(res?.data?.data);
59 } catch (e) { 60 } catch (e) {
60 console.log(e); 61 console.log(e);
61 } 62 }