acs用户管理更新
This commit is contained in:
@@ -6,12 +6,16 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.annotation.TransactionManagementConfigurer;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DataBaseConfig {
|
public class DataBaseConfig implements TransactionManagementConfigurer {
|
||||||
|
|
||||||
@Primary
|
@Primary
|
||||||
@Bean(name = "dataSource")
|
@Bean(name = "dataSource")
|
||||||
@@ -20,4 +24,20 @@ public class DataBaseConfig {
|
|||||||
return new DruidDataSource();
|
return new DruidDataSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Resource(name="transactionManager")
|
||||||
|
private PlatformTransactionManager transactionManager;
|
||||||
|
|
||||||
|
// 创建事务管理器
|
||||||
|
@Bean(name = "transactionManager")
|
||||||
|
public PlatformTransactionManager transactionManager(DataSource dataSource) {
|
||||||
|
return new DataSourceTransactionManager(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 实现接口 TransactionManagementConfigurer 方法,其返回值代表在拥有多个事务管理器的情况下默认使用的事务管理器
|
||||||
|
@Override
|
||||||
|
public PlatformTransactionManager annotationDrivenTransactionManager() {
|
||||||
|
return transactionManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,6 +92,9 @@ public class AuthorizationController {
|
|||||||
throw new BadRequestException("账号或密码错误");
|
throw new BadRequestException("账号或密码错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断是否被锁
|
||||||
|
if (!userDto.getEnabled()) throw new BadRequestException("账号未激活");
|
||||||
|
|
||||||
// 获取权限列表 - 登录查找权限
|
// 获取权限列表 - 登录查找权限
|
||||||
List<String> permissionList = roleService.getPermissionList(userDto);
|
List<String> permissionList = roleService.getPermissionList(userDto);
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
|
|||||||
import cn.dev33.satoken.secure.SaSecureUtil;
|
import cn.dev33.satoken.secure.SaSecureUtil;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -109,7 +110,10 @@ public class UserController {
|
|||||||
public ResponseEntity<Object> create(@Validated @RequestBody User resources){
|
public ResponseEntity<Object> create(@Validated @RequestBody User resources){
|
||||||
checkLevel(resources);
|
checkLevel(resources);
|
||||||
// 默认密码 123456
|
// 默认密码 123456
|
||||||
resources.setPassword(SaSecureUtil.md5BySalt("123456", "salt"));
|
if (ObjectUtil.isEmpty(resources.getPassword()))
|
||||||
|
resources.setPassword(SaSecureUtil.md5BySalt("123456", "salt"));
|
||||||
|
else
|
||||||
|
resources.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt"));
|
||||||
userService.create(resources);
|
userService.create(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.nl.modules.system.service.impl;
|
package org.nl.modules.system.service.impl;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.secure.SaSecureUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.nl.modules.common.config.FileProperties;
|
import org.nl.modules.common.config.FileProperties;
|
||||||
@@ -89,9 +91,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
if (userRepository.findByUsername(resources.getUsername()) != null) {
|
if (userRepository.findByUsername(resources.getUsername()) != null) {
|
||||||
throw new EntityExistException(User.class, "username", resources.getUsername());
|
throw new EntityExistException(User.class, "username", resources.getUsername());
|
||||||
}
|
}
|
||||||
if (userRepository.findByEmail(resources.getEmail()) != null) {
|
|
||||||
throw new EntityExistException(User.class, "email", resources.getEmail());
|
|
||||||
}
|
|
||||||
resources.setCreateBy(SecurityUtils.getCurrentUsername());
|
resources.setCreateBy(SecurityUtils.getCurrentUsername());
|
||||||
userRepository.save(resources);
|
userRepository.save(resources);
|
||||||
}
|
}
|
||||||
@@ -102,45 +101,36 @@ public class UserServiceImpl implements UserService {
|
|||||||
User user = userRepository.findById(resources.getId()).orElseGet(User::new);
|
User user = userRepository.findById(resources.getId()).orElseGet(User::new);
|
||||||
ValidationUtil.isNull(user.getId(), "User", "id", resources.getId());
|
ValidationUtil.isNull(user.getId(), "User", "id", resources.getId());
|
||||||
User user1 = userRepository.findByUsername(resources.getUsername());
|
User user1 = userRepository.findByUsername(resources.getUsername());
|
||||||
User user2 = userRepository.findByEmail(resources.getEmail());
|
|
||||||
|
|
||||||
if (user1 != null && !user.getId().equals(user1.getId())) {
|
if (user1 != null && !user.getId().equals(user1.getId())) {
|
||||||
throw new EntityExistException(User.class, "username", resources.getUsername());
|
throw new EntityExistException(User.class, "username", resources.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user2 != null && !user.getId().equals(user2.getId())) {
|
|
||||||
throw new EntityExistException(User.class, "email", resources.getEmail());
|
|
||||||
}
|
|
||||||
// 如果用户的角色改变
|
// 如果用户的角色改变
|
||||||
if (!resources.getRoles().equals(user.getRoles())) {
|
if (!resources.getRoles().equals(user.getRoles())) {
|
||||||
redisUtils.del(CacheKey.DATA_USER + resources.getId());
|
redisUtils.del(CacheKey.DATA_USER + resources.getId());
|
||||||
redisUtils.del(CacheKey.MENU_USER + resources.getId());
|
redisUtils.del(CacheKey.MENU_USER + resources.getId());
|
||||||
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId());
|
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId());
|
||||||
}
|
}
|
||||||
// 如果用户名称修改
|
redisUtils.del("user::username:" + user.getUsername());
|
||||||
if(!resources.getUsername().equals(user.getUsername())){
|
|
||||||
redisUtils.del("user::username:" + user.getUsername());
|
|
||||||
}
|
|
||||||
// 如果用户被禁用,则清除用户登录信息
|
// 如果用户被禁用,则清除用户登录信息
|
||||||
if(!resources.getEnabled()){
|
if(!resources.getEnabled()){
|
||||||
onlineUserService.kickOutForUsername(resources.getUsername());
|
onlineUserService.kickOutForUsername(resources.getUsername());
|
||||||
}
|
}
|
||||||
User clone = new User(); // jpa 多表问题,需要用新的类来进行修改
|
user.setId(resources.getId());
|
||||||
clone.setId(resources.getId());
|
user.setUsername(resources.getUsername());
|
||||||
clone.setUsername(resources.getUsername());
|
user.setEmail(resources.getEmail());
|
||||||
clone.setEmail(resources.getEmail());
|
user.setEnabled(resources.getEnabled());
|
||||||
clone.setEnabled(resources.getEnabled());
|
user.setRoles(resources.getRoles());
|
||||||
clone.setRoles(resources.getRoles());
|
user.setDept(resources.getDept());
|
||||||
clone.setDept(resources.getDept());
|
user.setPhone(resources.getPhone());
|
||||||
clone.setPhone(resources.getPhone());
|
user.setNickName(resources.getNickName());
|
||||||
clone.setNickName(resources.getNickName());
|
user.setGender(resources.getGender());
|
||||||
clone.setGender(resources.getGender());
|
if (ObjectUtil.isNotEmpty(resources.getPassword()))
|
||||||
|
user.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt"));
|
||||||
|
|
||||||
userRepository.save(clone);
|
userRepository.save(user);
|
||||||
// 清除缓存
|
// 清除缓存
|
||||||
delCaches(user.getId(), user.getUsername());
|
delCaches(user.getId(), user.getUsername());
|
||||||
// 修改session
|
|
||||||
// flushSession(user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -153,8 +143,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
delCaches(user.getId(), user.getUsername());
|
delCaches(user.getId(), user.getUsername());
|
||||||
// 修改session
|
|
||||||
// flushSession(user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -184,7 +172,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
public void updatePass(String username, String pass) {
|
public void updatePass(String username, String pass) {
|
||||||
userRepository.updatePass(username, pass, new Date());
|
userRepository.updatePass(username, pass, new Date());
|
||||||
redisUtils.del("user::username:" + username);
|
redisUtils.del("user::username:" + username);
|
||||||
// flushSession(userRepository.findByUsername(username));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -200,7 +187,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
FileUtil.del(oldPath);
|
FileUtil.del(oldPath);
|
||||||
}
|
}
|
||||||
@NotBlank String username = user.getUsername();
|
@NotBlank String username = user.getUsername();
|
||||||
// flushSession(user);
|
|
||||||
return new HashMap<String, String>(1) {{
|
return new HashMap<String, String>(1) {{
|
||||||
put("avatar", file.getName());
|
put("avatar", file.getName());
|
||||||
}};
|
}};
|
||||||
@@ -210,7 +196,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateEmail(String username, String email) {
|
public void updateEmail(String username, String email) {
|
||||||
userRepository.updateEmail(username, email);
|
userRepository.updateEmail(username, email);
|
||||||
// flushSession(userRepository.findByUsername(username));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -239,17 +224,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
*/
|
*/
|
||||||
public void delCaches(Long id, String username) {
|
public void delCaches(Long id, String username) {
|
||||||
redisUtils.del(CacheKey.USER_ID + id);
|
redisUtils.del(CacheKey.USER_ID + id);
|
||||||
// flushCache(username);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 清理 登陆时 用户缓存信息
|
|
||||||
*
|
|
||||||
* @param user /
|
|
||||||
*/
|
|
||||||
// private void flushSession(User user) {
|
|
||||||
// UserDto userDto = this.findByName(user.getUsername());
|
|
||||||
// List<String> permissionList = roleService.getPermissionList(userDto.getId().toString());
|
|
||||||
// flushSessionUtil.flushSessionInfo(userDto, permissionList);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="password">
|
<el-form-item prop="password">
|
||||||
<el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码" @keyup.enter.native="handleLogin">
|
<el-input v-model="loginForm.password" type="password" auto-complete="new-password" placeholder="密码" @keyup.enter.native="handleLogin">
|
||||||
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@@ -120,14 +120,12 @@ export default {
|
|||||||
code: this.loginForm.code,
|
code: this.loginForm.code,
|
||||||
uuid: this.loginForm.uuid
|
uuid: this.loginForm.uuid
|
||||||
}
|
}
|
||||||
if (user.password !== this.cookiePass) {
|
user.password = encrypt(user.password)
|
||||||
user.password = encrypt(user.password)
|
|
||||||
}
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
if (user.rememberMe) {
|
if (user.rememberMe) {
|
||||||
Cookies.set('username', user.username, { expires: Config.passCookieExpires })
|
Cookies.set('username', user.username, { expires: Config.passCookieExpires })
|
||||||
Cookies.set('password', user.password, { expires: Config.passCookieExpires })
|
Cookies.set('password', this.loginForm.password, { expires: Config.passCookieExpires })
|
||||||
Cookies.set('rememberMe', user.rememberMe, { expires: Config.passCookieExpires })
|
Cookies.set('rememberMe', user.rememberMe, { expires: Config.passCookieExpires })
|
||||||
} else {
|
} else {
|
||||||
Cookies.remove('username')
|
Cookies.remove('username')
|
||||||
|
|||||||
@@ -80,7 +80,7 @@
|
|||||||
<el-form-item label="邮箱" prop="email">
|
<el-form-item label="邮箱" prop="email">
|
||||||
<el-input v-model="form.email" style="width: 200px;" />
|
<el-input v-model="form.email" style="width: 200px;" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="部门" prop="dept.id">
|
<el-form-item label="部门" prop="dept.id" :rules="[{ required: true, message: '请选择部门', trigger: 'change' }]">
|
||||||
<treeselect
|
<treeselect
|
||||||
v-model="form.dept.id"
|
v-model="form.dept.id"
|
||||||
:options="depts"
|
:options="depts"
|
||||||
@@ -89,7 +89,10 @@
|
|||||||
placeholder="选择部门"
|
placeholder="选择部门"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<br v-if="!crud.status.add">
|
||||||
|
<el-form-item label="密码" prop="password" v-if="crud.status.add">
|
||||||
|
<el-input v-model="form.password" style="width: 200px;" show-password auto-complete="new-password"/>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="性别">
|
<el-form-item label="性别">
|
||||||
<el-radio-group v-model="form.gender" style="width: 178px">
|
<el-radio-group v-model="form.gender" style="width: 178px">
|
||||||
<el-radio label="男">男</el-radio>
|
<el-radio label="男">男</el-radio>
|
||||||
@@ -168,16 +171,25 @@
|
|||||||
<el-table-column
|
<el-table-column
|
||||||
v-permission="['admin','user:edit','user:del']"
|
v-permission="['admin','user:edit','user:del']"
|
||||||
label="操作"
|
label="操作"
|
||||||
width="115"
|
width="200"
|
||||||
align="center"
|
align="center"
|
||||||
fixed="right"
|
fixed="right"
|
||||||
>
|
>
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<udOperation
|
<udOperation
|
||||||
|
style="display: inline"
|
||||||
:data="scope.row"
|
:data="scope.row"
|
||||||
:permission="permission"
|
:permission="permission"
|
||||||
:disabled-dle="scope.row.id === user.id"
|
:disabled-dle="scope.row.id === user.id"
|
||||||
/>
|
/>
|
||||||
|
<el-button
|
||||||
|
type="text"
|
||||||
|
slot="left"
|
||||||
|
icon="el-icon-refresh-left"
|
||||||
|
v-permission="permission.edit"
|
||||||
|
@click="resetPassword(scope.row)">
|
||||||
|
重置密码
|
||||||
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@@ -189,260 +201,284 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import crudUser from '@/api/system/user'
|
import crudUser from '@/api/system/user'
|
||||||
import { getDepts, getDeptSuperior } from '@/api/system/dept'
|
import { getDepts, getDeptSuperior } from '@/api/system/dept'
|
||||||
import { getAll, getLevel } from '@/api/system/role'
|
import { getAll, getLevel } from '@/api/system/role'
|
||||||
import CRUD, { crud, form, header, presenter } from '@crud/crud'
|
import CRUD, { crud, form, header, presenter } from '@crud/crud'
|
||||||
import rrOperation from '@crud/RR.operation'
|
import rrOperation from '@crud/RR.operation'
|
||||||
import crudOperation from '@crud/CRUD.operation'
|
import crudOperation from '@crud/CRUD.operation'
|
||||||
import udOperation from '@crud/UD.operation'
|
import udOperation from '@crud/UD.operation'
|
||||||
import pagination from '@crud/Pagination'
|
import pagination from '@crud/Pagination'
|
||||||
import DateRangePicker from '@/components/DateRangePicker'
|
import DateRangePicker from '@/components/DateRangePicker'
|
||||||
import Treeselect, { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
|
import Treeselect, { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
|
||||||
import { mapGetters } from 'vuex'
|
import { mapGetters } from 'vuex'
|
||||||
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
|
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
|
||||||
|
|
||||||
let userRoles = []
|
let userRoles = []
|
||||||
const defaultForm = {
|
const defaultForm = {
|
||||||
id: null,
|
id: null,
|
||||||
username: null,
|
username: null,
|
||||||
nickName: null,
|
nickName: null,
|
||||||
gender: '男',
|
gender: '男',
|
||||||
email: null,
|
email: null,
|
||||||
enabled: 'true',
|
enabled: 'true',
|
||||||
roles: [],
|
roles: [],
|
||||||
dept: { id: null },
|
dept: { id: null },
|
||||||
phone: null
|
phone: null,
|
||||||
}
|
password: null
|
||||||
export default {
|
}
|
||||||
name: 'User',
|
export default {
|
||||||
components: { Treeselect, crudOperation, rrOperation, udOperation, pagination, DateRangePicker },
|
name: 'User',
|
||||||
cruds() {
|
components: { Treeselect, crudOperation, rrOperation, udOperation, pagination, DateRangePicker },
|
||||||
return CRUD({ title: '用户', url: 'api/users', crudMethod: { ...crudUser }})
|
cruds() {
|
||||||
},
|
return CRUD({ title: '用户', url: 'api/users', crudMethod: { ...crudUser }})
|
||||||
mixins: [presenter(), header(), form(defaultForm), crud()],
|
},
|
||||||
// 数据字典
|
mixins: [presenter(), header(), form(defaultForm), crud()],
|
||||||
dicts: ['user_status'],
|
// 数据字典
|
||||||
data() {
|
dicts: ['user_status'],
|
||||||
return {
|
data() {
|
||||||
height: document.documentElement.clientHeight - 180 + 'px;',
|
return {
|
||||||
deptName: '', depts: [], deptDatas: [], level: 3, roles: [],
|
height: document.documentElement.clientHeight - 180 + 'px;',
|
||||||
roleDatas: [], // 多选时使用
|
deptName: '', depts: [], deptDatas: [], level: 3, roles: [],
|
||||||
defaultProps: { children: 'children', label: 'name', isLeaf: 'leaf' },
|
roleDatas: [], // 多选时使用
|
||||||
permission: {
|
defaultProps: { children: 'children', label: 'name', isLeaf: 'leaf' },
|
||||||
add: ['admin', 'user:add'],
|
permission: {
|
||||||
edit: ['admin', 'user:edit'],
|
add: ['admin', 'user:add'],
|
||||||
del: ['admin', 'user:del']
|
edit: ['admin', 'user:edit'],
|
||||||
},
|
del: ['admin', 'user:del']
|
||||||
enabledTypeOptions: [
|
},
|
||||||
{ key: 'true', display_name: '激活' },
|
enabledTypeOptions: [
|
||||||
{ key: 'false', display_name: '锁定' }
|
{ key: 'true', display_name: '激活' },
|
||||||
],
|
{ key: 'false', display_name: '锁定' }
|
||||||
rules: {
|
|
||||||
username: [
|
|
||||||
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
|
||||||
{ min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
|
|
||||||
],
|
],
|
||||||
nickName: [
|
rules: {
|
||||||
{ required: true, message: '请输入用户姓名', trigger: 'blur' },
|
username: [
|
||||||
{ min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
|
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||||||
]
|
{ min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
|
||||||
}
|
],
|
||||||
}
|
nickName: [
|
||||||
},
|
{ required: true, message: '请输入用户姓名', trigger: 'blur' },
|
||||||
computed: {
|
{ min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
|
||||||
...mapGetters([
|
]
|
||||||
'user'
|
|
||||||
])
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
this.crud.msg.add = '新增成功,默认密码:123456'
|
|
||||||
},
|
|
||||||
mounted: function() {
|
|
||||||
const that = this
|
|
||||||
window.onresize = function temp() {
|
|
||||||
that.height = document.documentElement.clientHeight - 180 + 'px;'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
changeRole(value) {
|
|
||||||
userRoles = []
|
|
||||||
value.forEach(function(data, index) {
|
|
||||||
const role = { id: data }
|
|
||||||
userRoles.push(role)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
deleteTag(value) {
|
|
||||||
userRoles.forEach(function(data, index) {
|
|
||||||
if (data.id === value) {
|
|
||||||
userRoles.splice(index, value)
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
},
|
|
||||||
// 新增与编辑前做的操作
|
|
||||||
[CRUD.HOOK.afterToCU](crud, form) {
|
|
||||||
this.getRoles()
|
|
||||||
if (form.id == null) {
|
|
||||||
this.getDepts()
|
|
||||||
} else {
|
|
||||||
this.getSupDepts(form.dept.id)
|
|
||||||
}
|
}
|
||||||
this.getRoleLevel()
|
|
||||||
form.enabled = form.enabled.toString()
|
|
||||||
},
|
},
|
||||||
// 新增前将多选的值设置为空
|
computed: {
|
||||||
[CRUD.HOOK.beforeToAdd]() {
|
...mapGetters([
|
||||||
this.roleDatas = []
|
'user'
|
||||||
|
])
|
||||||
},
|
},
|
||||||
// 初始化编辑时候的角色与岗位
|
created() {
|
||||||
[CRUD.HOOK.beforeToEdit](crud, form) {
|
this.crud.msg.add = '新增成功'
|
||||||
this.roleDatas = []
|
|
||||||
userRoles = []
|
|
||||||
const _this = this
|
|
||||||
form.roles.forEach(function(role, index) {
|
|
||||||
_this.roleDatas.push(role.id)
|
|
||||||
const rol = { id: role.id }
|
|
||||||
userRoles.push(rol)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
// 提交前做的操作
|
mounted: function() {
|
||||||
[CRUD.HOOK.afterValidateCU](crud) {
|
const that = this
|
||||||
if (!crud.form.dept.id) {
|
window.onresize = function temp() {
|
||||||
this.$message({
|
that.height = document.documentElement.clientHeight - 180 + 'px;'
|
||||||
message: '部门不能为空',
|
}
|
||||||
type: 'warning'
|
},
|
||||||
|
methods: {
|
||||||
|
changeRole(value) {
|
||||||
|
userRoles = []
|
||||||
|
value.forEach(function(data, index) {
|
||||||
|
const role = { id: data }
|
||||||
|
userRoles.push(role)
|
||||||
})
|
})
|
||||||
return false
|
},
|
||||||
} else if (this.roleDatas.length === 0) {
|
deleteTag(value) {
|
||||||
this.$message({
|
userRoles.forEach(function(data, index) {
|
||||||
message: '角色不能为空',
|
if (data.id === value) {
|
||||||
type: 'warning'
|
userRoles.splice(index, value)
|
||||||
})
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
crud.form.roles = userRoles
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
// 获取左侧部门数据
|
|
||||||
getDeptDatas(node, resolve) {
|
|
||||||
console.log('node', node)
|
|
||||||
console.log('resolve', resolve)
|
|
||||||
const sort = 'id,desc'
|
|
||||||
const params = { sort: sort }
|
|
||||||
if (typeof node !== 'object') {
|
|
||||||
if (node) {
|
|
||||||
params['name'] = node
|
|
||||||
}
|
|
||||||
} else if (node.level !== 0) {
|
|
||||||
params['pid'] = node.data.id
|
|
||||||
}
|
|
||||||
console.log('params', params)
|
|
||||||
setTimeout(() => {
|
|
||||||
getDepts(params).then(res => {
|
|
||||||
console.log('res', res)
|
|
||||||
if (resolve) {
|
|
||||||
resolve(res.content)
|
|
||||||
} else {
|
|
||||||
this.deptDatas = res.content
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, 100)
|
},
|
||||||
},
|
// 新增与编辑前做的操作
|
||||||
getDepts() {
|
[CRUD.HOOK.afterToCU](crud, form) {
|
||||||
console.log('获取部门')
|
this.getRoles()
|
||||||
getDepts({ enabled: true }).then(res => {
|
if (form.id == null) {
|
||||||
console.log('获取的部门信息', res)
|
this.getDepts()
|
||||||
this.depts = res.content.map(function(obj) {
|
} else {
|
||||||
if (obj.hasChildren) {
|
this.getSupDepts(form.dept.id)
|
||||||
obj.children = null
|
}
|
||||||
}
|
this.getRoleLevel()
|
||||||
return obj
|
form.enabled = form.enabled.toString()
|
||||||
|
},
|
||||||
|
// 新增前将多选的值设置为空
|
||||||
|
[CRUD.HOOK.beforeToAdd]() {
|
||||||
|
this.form.password = '123456'
|
||||||
|
this.roleDatas = []
|
||||||
|
},
|
||||||
|
// 初始化编辑时候的角色与岗位
|
||||||
|
[CRUD.HOOK.beforeToEdit](crud, form) {
|
||||||
|
this.roleDatas = []
|
||||||
|
userRoles = []
|
||||||
|
const _this = this
|
||||||
|
form.roles.forEach(function(role, index) {
|
||||||
|
_this.roleDatas.push(role.id)
|
||||||
|
const rol = { id: role.id }
|
||||||
|
userRoles.push(rol)
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
},
|
// 提交前做的操作
|
||||||
getSupDepts(deptId) {
|
[CRUD.HOOK.afterValidateCU](crud) {
|
||||||
getDeptSuperior(deptId).then(res => {
|
if (!crud.form.dept.id) {
|
||||||
console.log('父部门', res)
|
this.$message({
|
||||||
const date = res.content
|
message: '部门不能为空',
|
||||||
this.buildDepts(date)
|
type: 'warning'
|
||||||
this.depts = date
|
})
|
||||||
})
|
return false
|
||||||
},
|
} else if (this.roleDatas.length === 0) {
|
||||||
buildDepts(depts) {
|
this.$message({
|
||||||
depts.forEach(data => {
|
message: '角色不能为空',
|
||||||
if (data.children) {
|
type: 'warning'
|
||||||
this.buildDepts(data.children)
|
})
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
if (data.hasChildren && !data.children) {
|
crud.form.roles = userRoles
|
||||||
data.children = null
|
return true
|
||||||
|
},
|
||||||
|
// 获取左侧部门数据
|
||||||
|
getDeptDatas(node, resolve) {
|
||||||
|
console.log('node', node)
|
||||||
|
console.log('resolve', resolve)
|
||||||
|
const sort = 'id,desc'
|
||||||
|
const params = { sort: sort }
|
||||||
|
if (typeof node !== 'object') {
|
||||||
|
if (node) {
|
||||||
|
params['name'] = node
|
||||||
|
}
|
||||||
|
} else if (node.level !== 0) {
|
||||||
|
params['pid'] = node.data.id
|
||||||
}
|
}
|
||||||
})
|
console.log('params', params)
|
||||||
},
|
setTimeout(() => {
|
||||||
// 获取弹窗内部门数据
|
getDepts(params).then(res => {
|
||||||
loadDepts({ action, parentNode, callback }) {
|
console.log('res', res)
|
||||||
if (action === LOAD_CHILDREN_OPTIONS) {
|
if (resolve) {
|
||||||
getDepts({ enabled: true, pid: parentNode.id }).then(res => {
|
resolve(res.content)
|
||||||
parentNode.children = res.content.map(function(obj) {
|
} else {
|
||||||
|
this.deptDatas = res.content
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, 100)
|
||||||
|
},
|
||||||
|
getDepts() {
|
||||||
|
console.log('获取部门')
|
||||||
|
getDepts({ enabled: true }).then(res => {
|
||||||
|
console.log('获取的部门信息', res)
|
||||||
|
this.depts = res.content.map(function(obj) {
|
||||||
if (obj.hasChildren) {
|
if (obj.hasChildren) {
|
||||||
obj.children = null
|
obj.children = null
|
||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
})
|
})
|
||||||
setTimeout(() => {
|
|
||||||
callback()
|
|
||||||
}, 200)
|
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
},
|
getSupDepts(deptId) {
|
||||||
// 切换部门
|
getDeptSuperior(deptId).then(res => {
|
||||||
handleNodeClick(data) {
|
console.log('父部门', res)
|
||||||
if (data.pid === 0) {
|
const date = res.content
|
||||||
this.query.deptId = null
|
this.buildDepts(date)
|
||||||
} else {
|
this.depts = date
|
||||||
this.query.deptId = data.id
|
})
|
||||||
}
|
},
|
||||||
this.crud.toQuery()
|
buildDepts(depts) {
|
||||||
},
|
depts.forEach(data => {
|
||||||
// 改变状态
|
if (data.children) {
|
||||||
changeEnabled(data, val) {
|
this.buildDepts(data.children)
|
||||||
this.$confirm('此操作将 "' + this.dict.label.user_status[val] + '" ' + data.username + ', 是否继续?', '提示', {
|
}
|
||||||
confirmButtonText: '确定',
|
if (data.hasChildren && !data.children) {
|
||||||
cancelButtonText: '取消',
|
data.children = null
|
||||||
type: 'warning'
|
}
|
||||||
}).then(() => {
|
})
|
||||||
crudUser.edit(data).then(res => {
|
},
|
||||||
this.crud.notify(this.dict.label.user_status[val] + '成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
// 获取弹窗内部门数据
|
||||||
|
loadDepts({ action, parentNode, callback }) {
|
||||||
|
if (action === LOAD_CHILDREN_OPTIONS) {
|
||||||
|
getDepts({ enabled: true, pid: parentNode.id }).then(res => {
|
||||||
|
parentNode.children = res.content.map(function(obj) {
|
||||||
|
if (obj.hasChildren) {
|
||||||
|
obj.children = null
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
})
|
||||||
|
setTimeout(() => {
|
||||||
|
callback()
|
||||||
|
}, 200)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 切换部门
|
||||||
|
handleNodeClick(data) {
|
||||||
|
if (data.pid === 0) {
|
||||||
|
this.query.deptId = null
|
||||||
|
} else {
|
||||||
|
this.query.deptId = data.id
|
||||||
|
}
|
||||||
|
this.crud.toQuery()
|
||||||
|
},
|
||||||
|
// 改变状态
|
||||||
|
changeEnabled(data, val) {
|
||||||
|
this.$confirm('此操作将 "' + this.dict.label.user_status[val] + '" ' + data.username + ', 是否继续?', '提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
crudUser.edit(data).then(res => {
|
||||||
|
this.crud.notify(this.dict.label.user_status[val] + '成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
||||||
|
}).catch(() => {
|
||||||
|
data.enabled = !data.enabled
|
||||||
|
})
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
data.enabled = !data.enabled
|
data.enabled = !data.enabled
|
||||||
})
|
})
|
||||||
}).catch(() => {
|
},
|
||||||
data.enabled = !data.enabled
|
// 获取弹窗内角色数据
|
||||||
})
|
getRoles() {
|
||||||
},
|
getAll().then(res => {
|
||||||
// 获取弹窗内角色数据
|
this.roles = res
|
||||||
getRoles() {
|
}).catch(() => {
|
||||||
getAll().then(res => {
|
})
|
||||||
this.roles = res
|
},
|
||||||
}).catch(() => {
|
// 获取权限级别
|
||||||
})
|
getRoleLevel() {
|
||||||
},
|
getLevel().then(res => {
|
||||||
// 获取权限级别
|
this.level = res.level
|
||||||
getRoleLevel() {
|
}).catch(() => {
|
||||||
getLevel().then(res => {
|
})
|
||||||
this.level = res.level
|
},
|
||||||
}).catch(() => {
|
checkboxT(row, rowIndex) {
|
||||||
})
|
return row.id !== this.user.id
|
||||||
},
|
},
|
||||||
checkboxT(row, rowIndex) {
|
resetPassword(row) {
|
||||||
return row.id !== this.user.id
|
row.password = null
|
||||||
|
this.$prompt('', '重置密码', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
inputPlaceholder: '请输入新的密码',
|
||||||
|
inputPattern: /^[A-Z|a-z|0-9|(._~!@#$^&*)]{6,20}$/,
|
||||||
|
inputErrorMessage: '密码格式不正确,只能是6-20位密码',
|
||||||
|
closeOnClickModal: false
|
||||||
|
}).then(({ value }) => {
|
||||||
|
row.password = value
|
||||||
|
crudUser.edit(row).then(res => {
|
||||||
|
this.crud.toQuery()
|
||||||
|
this.crud.notify('密码重置成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
||||||
|
})
|
||||||
|
}).catch(() => {
|
||||||
|
this.$message({
|
||||||
|
type: 'info',
|
||||||
|
message: '取消输入'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style rel="stylesheet/scss" lang="scss" scoped>
|
<style rel="stylesheet/scss" lang="scss" scoped>
|
||||||
::v-deep .vue-treeselect__control, ::v-deep .vue-treeselect__placeholder, ::v-deep .vue-treeselect__single-value {
|
::v-deep .vue-treeselect__control, ::v-deep .vue-treeselect__placeholder, ::v-deep .vue-treeselect__single-value {
|
||||||
height: 30px;
|
height: 30px;
|
||||||
line-height: 30px;
|
line-height: 30px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user