update
parent
b9ca3ba3cb
commit
cb65ad215a
File diff suppressed because one or more lines are too long
|
|
@ -13,6 +13,10 @@ export function setToken(token:string) {
|
||||||
}
|
}
|
||||||
export function removeToken() {
|
export function removeToken() {
|
||||||
sessionStorage.removeItem(tokenKey);
|
sessionStorage.removeItem(tokenKey);
|
||||||
|
global.user = {
|
||||||
|
authorities: [],
|
||||||
|
info: {},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 菜单信息
|
// 菜单信息
|
||||||
|
|
@ -77,7 +81,11 @@ export async function getUserInfo() {
|
||||||
method: 'get'
|
method: 'get'
|
||||||
}).then((res:any) => {
|
}).then((res:any) => {
|
||||||
if(res.data.result){
|
if(res.data.result){
|
||||||
global.user.info = res.data.result
|
// 用户信息
|
||||||
|
let user = res.data.result
|
||||||
|
global.user.info = user
|
||||||
|
// 权限信息
|
||||||
|
global.user.authorities = user.authorities
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ import * as ElIcons from '@element-plus/icons-vue'
|
||||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||||
import 'uno.css'
|
import 'uno.css'
|
||||||
import globalProperties from './utils/globalProperties'
|
import globalProperties from './utils/globalProperties'
|
||||||
|
import hasPermission from './utils/hasPermission'
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
app.use(globalProperties)
|
app.use(globalProperties)
|
||||||
|
|
@ -19,4 +20,5 @@ app.use(ElementPlus,{
|
||||||
for (const icon in ElIcons) {
|
for (const icon in ElIcons) {
|
||||||
app.component(icon, (ElIcons as any)[icon])
|
app.component(icon, (ElIcons as any)[icon])
|
||||||
}
|
}
|
||||||
|
app.use(hasPermission)
|
||||||
app.mount('#app');
|
app.mount('#app');
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ export default {
|
||||||
baseApi: import.meta.env.VITE_BASE_API,
|
baseApi: import.meta.env.VITE_BASE_API,
|
||||||
cardShadow: 'never',
|
cardShadow: 'never',
|
||||||
user: {
|
user: {
|
||||||
info: {}
|
info: {},
|
||||||
|
authorities: [],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
// 权限
|
||||||
|
const hasPermission = {
|
||||||
|
install(app:any) {
|
||||||
|
app.directive('permission', {
|
||||||
|
mounted(el:any, binding:any) {
|
||||||
|
if (binding.value) {
|
||||||
|
const permissionList = app.config.globalProperties.$global.user.authorities
|
||||||
|
if (permissionList && permissionList.length && !permissionList.includes(binding.value)) {
|
||||||
|
el.remove()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default hasPermission
|
||||||
|
|
@ -221,14 +221,14 @@
|
||||||
<Table :data="table.tableData" :column="table.tableTitle" :operation="table.operation" :page="table.page" :loading="table.loading"
|
<Table :data="table.tableData" :column="table.tableTitle" :operation="table.operation" :page="table.page" :loading="table.loading"
|
||||||
@onSizeChange="onSizeChange" @onCurrentChange="onCurrentChange" @onSwitchChange="onSwitchChange">
|
@onSizeChange="onSizeChange" @onCurrentChange="onCurrentChange" @onSwitchChange="onSwitchChange">
|
||||||
<template #search>
|
<template #search>
|
||||||
<div><el-button type="primary" @click="onAddRole">添加</el-button></div>
|
<div><el-button v-permission="'user:save'" type="primary" @click="onAddRole">添加</el-button></div>
|
||||||
<div><el-input v-model="searchForm.username" placeholder="请输入名称"></el-input></div>
|
<div><el-input v-model="searchForm.username" placeholder="请输入名称"></el-input></div>
|
||||||
<div><el-button @click="onRefresh" icon="RefreshRight" circle></el-button></div>
|
<div><el-button @click="onRefresh" icon="RefreshRight" circle></el-button></div>
|
||||||
<div><el-button @click="onSearch" type="primary" icon="Search">查询</el-button></div>
|
<div><el-button @click="onSearch" type="primary" icon="Search">查询</el-button></div>
|
||||||
</template>
|
</template>
|
||||||
<template #column="scope">
|
<template #column="scope">
|
||||||
<el-button @click="onEdit(scope)" type='primary' text='primary' style="color:var(--edit); padding:0;">编辑</el-button>
|
<el-button @click="onEdit(scope)" v-permission="'user:update'" type='primary' link style="color:var(--edit); padding:0;">编辑</el-button>
|
||||||
<el-button @click="onDelete(scope)" type='primary' text='primary' style="color:var(--delete); padding:0;">删除</el-button>
|
<el-button @click="onDelete(scope)" v-permission="'user:delete'" type='primary' link style="color:var(--delete); padding:0;">删除</el-button>
|
||||||
</template>
|
</template>
|
||||||
</Table>
|
</Table>
|
||||||
<el-dialog title="用户信息" v-model="form.userVisible" :show-close="false" width="50%">
|
<el-dialog title="用户信息" v-model="form.userVisible" :show-close="false" width="50%">
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName: UserAuthVo.java
|
* @ClassName: UserAuthVo.java
|
||||||
* @ClassPath: com.tansci.domain.vo.UserAuthVo.java
|
* @ClassPath: com.tansci.domain.vo.UserAuthVo.java
|
||||||
|
|
@ -39,4 +41,7 @@ public class UserAuthVo {
|
||||||
@ApiModelProperty(value = "邮箱")
|
@ApiModelProperty(value = "邮箱")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "权限code")
|
||||||
|
private List<String> authorities;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ package com.tansci.mapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.tansci.domain.SysUser;
|
import com.tansci.domain.SysUser;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName: SysUserMapper.java
|
* @ClassName: SysUserMapper.java
|
||||||
|
|
@ -13,4 +17,15 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
**/
|
**/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SysUserMapper extends BaseMapper<SysUser> {
|
public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||||
|
|
||||||
|
@Select("SELECT DISTINCT sm.permission\n" +
|
||||||
|
"FROM sys_menu sm\n" +
|
||||||
|
"right JOIN sys_role_menu srm ON sm.id = srm.menu_id\n" +
|
||||||
|
"right JOIN sys_user_role sur ON sur.role_id = srm.role_id\n" +
|
||||||
|
"right JOIN sys_user su ON su.id = sur.user_id AND su.id = #{userId} AND su.is_del = 0\n" +
|
||||||
|
"WHERE sm.is_del = 0\n" +
|
||||||
|
"AND sm.permission != ''\n" +
|
||||||
|
"AND sm.permission IS NOT NULL")
|
||||||
|
List<String> authorities(@Param("userId") String userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,12 +80,15 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||||
@Override
|
@Override
|
||||||
public UserAuthVo info() {
|
public UserAuthVo info() {
|
||||||
SysUser user = this.baseMapper.selectById(String.valueOf(StpUtil.getLoginId()));
|
SysUser user = this.baseMapper.selectById(String.valueOf(StpUtil.getLoginId()));
|
||||||
|
// 获取当前用户权限code
|
||||||
|
List<String> authorities = this.baseMapper.authorities(String.valueOf(StpUtil.getLoginId()));
|
||||||
return UserAuthVo.builder()
|
return UserAuthVo.builder()
|
||||||
.username(user.getUsername())
|
.username(user.getUsername())
|
||||||
.nickname(user.getNickname())
|
.nickname(user.getNickname())
|
||||||
.type(user.getType())
|
.type(user.getType())
|
||||||
.phone(user.getPhone())
|
.phone(user.getPhone())
|
||||||
.email(user.getEmail())
|
.email(user.getEmail())
|
||||||
|
.authorities(authorities)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue