master
夜良king 2022-03-04 02:31:56 +08:00
commit 87f6b81e37
15 changed files with 10400 additions and 8826 deletions

View File

@ -9,9 +9,9 @@ var BASE = {
manager: "https://admin-api.pickmall.cn"
},
API_PROD: {
common: "https://common-api.pickmall.cn",
buyer: "https://buyer-api.pickmall.cn",
seller: "https://store-api.pickmall.cn",
manager: "https://admin-api.pickmall.cn"
common: "http://192.168.2.110:8890",
buyer: "http://192.168.2.110:8888",
seller: "http://192.168.2.110:8889",
manager: "http://192.168.2.110:8887"
},
};

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@
/>
</Form-item>
<Form-item label="联系方式">
<Input
<Inputuser-manage
type="text"
v-model="searchForm.mobile"
placeholder="请输入联系方式"

View File

@ -3,10 +3,21 @@ var BASE = {
* @description api请求基础路径
*/
API_DEV: {
<<<<<<< HEAD
common: "http://192.168.0.102:8890",
buyer: "https://buyer-api.pickmall.cn",
seller: "http://192.168.0.102:8889",
manager: "https://admin-api.pickmall.cn"
=======
// common: "http://localhost:8890",
// buyer: "http://localhost:8888",
// seller: "http://localhost:8889",
// manager: "http://localhost:8887"
common:"http://192.168.0.113:8890",
buyer:"http://192.168.0.113:8888",
manager:"http://192.168.0.113:8887",
seller:"http://192.168.0.113:8889"
>>>>>>> 32336decc6e9e0ae8a0e67033f8ca66a89bbd372
},
API_PROD: {
common: "https://common-api.pickmall.cn",

View File

@ -6,6 +6,9 @@ import {
deleteRequest,
getRequestWithNoToken,
postRequestWithNoTokenData,
putRequestWithNoForm,
postRequestWithNoToken,
postRequestWithNoForm,
commonUrl,
} from "@/libs/axios";
@ -14,13 +17,16 @@ export const getAllCity = (params) => {
return getRequest(commonUrl+'/common/common/region/allCity', params)
}
// 获取全部权限数据
export const getCurrentPermissionList = (params) => {
return getRequest("/menu/memberMenu", params);
};
// 登陆
export const getHomeNotice = params => {
return getRequest("/other/article/getByPage?type=STORE_ARTICLE&pageSize=15");
};
// 登陆
export const getSellerHomeData = params => {
return getRequest("/statistics/index", params);
@ -128,7 +134,7 @@ export const getRelatedListData = params => {
// 获取用户数据 多条件
export const getUserListData = params => {
return getRequest("/user/getByCondition", params);
return getRequest("/clerk", params);
};
// 通过用户名搜索
export const searchUserByName = (username, params) => {
@ -141,7 +147,7 @@ export const getAllUserData = params => {
// 添加用户
export const addUser = params => {
return postRequest("/user/admin/add", params);
return postRequest("/clerk", params);
};
// 编辑用户
export const editUser = params => {
@ -268,4 +274,100 @@ export const handleRefreshToken = (token) => {
return getRequestWithNoToken(`/login/refresh/${token}`);
};
// 获取一级部门
export const initDepartment = (params) => {
return getRequest("/department", params);
};
// 添加部门
export const addDepartment = (params) => {
return postRequest("/department", params);
};
// 删除部门
export const deleteDepartment = (ids, params) => {
return deleteRequest(`/department/${ids}`, params);
};
// 编辑部门
export const editDepartment = (ids, params) => {
return putRequest(`/department/${ids} `, params);
};
// 加载部门子级数据
export const loadDepartment = (id) => {
return getRequest(`/department/${id}`);
};
// 通过部门获取全部角色数据
export const getUserByDepartmentId = (id, params) => {
return getRequest(`/departmentRole/${id}`, params);
};
// 分页获取角色数据
export const getRoleList = (params) => {
return getRequest("/role", params);
};
// 通过部门修改绑定角色
export const updateDepartmentRole = (id, params) => {
return putRequestWithNoForm(`/departmentRole/${id}`, params);
};
// 获取全部权限数据
export const getAllPermissionList = (params) => {
return getRequest("/menu/tree", params);
};
// 添加角色
export const addRole = (params) => {
return postRequest("/role", params);
};
// 删除角色
export const deleteRole = (ids, params) => {
return deleteRequest(`/role/${ids}`, params);
};
// 编辑角色
export const editRole = (params) => {
return putRequest(`/role/${params.roleId}`, params);
};
// 分配角色权限
export const editRolePerm = (params) => {
return postRequest("/role/editRolePerm", params);
};
// 查看某角色拥有的菜单
export const selectRoleMenu = (params) => {
return getRequest(`/roleMenu/${params}`);
};
// 保存角色菜单
export const saveRoleMenu = (id, params) => {
return postRequestWithNoForm(`/roleMenu/${id}`, params);
};
// 获取全部角色数据
export const getAllRoleList = (params) => {
return getRequest("/role", params);
};
export const checkClerk = (mobile) => {
return postRequest(`/clerk/${mobile}/check`);
};
// 重置用户密码
export const resetPassword = (params) => {
return postRequest(`/clerk/resetPassword/${params}`);
};
// 删除用户
export const deleteClerk = (ids) => {
return deleteRequest(`/clerk/delByIds/${ids}`);
};
// 禁 启用用户
export const enableClerk = (id, params) => {
return putRequest(`/clerk/enable/${id}`, params);
};
// 获取店员详细
export const getClerk = (id) => {
return getRequest(`/clerk/${id}`);
};
export const editOtherUser = (id, params) => {
return putRequest(`/clerk/${id}`,params);
};

View File

@ -26,11 +26,11 @@ export const result = [{
children: null,
},
{
name: "goods",
name: "goods1",
level: 2,
type: 0,
title: "商品列表",
path: "goods",
path: "goods12",
component: "goods/goods-seller/goods",
children: null,
},
@ -388,6 +388,42 @@ export const result = [{
component: "sys/user-manage/userManage",
children: []
},
{
name: "clerk",
level: 1,
type: 0,
title: "店员设置",
path: "",
component: "Main",
children: [
{
name: "clerkManage",
level: 2,
type: 0,
title: "店员管理",
path: "clerkManage",
component: "shop/system/clerk/clerkManage",
children: null
},{
name: "storeDepartmentManage",
level: 2,
type: 0,
title: "部门管理",
path: "storeDepartmentManage",
component: "shop/system/department/storeDepartmentManage",
children: null
},
{
name: "storeRole",
level: 2,
type: 0,
title: "角色权限",
path: "storeRole",
component: "shop/system/role/storeRoleManage",
children: null
}
]
},
{
name: "ship",
level: 1,
@ -396,14 +432,14 @@ export const result = [{
path: "",
component: "Main",
children: [{
name: "shipTemplate",
level: 2,
type: 0,
title: "配送模板",
path: "shipTemplate",
component: "shop/ship/shipTemplate",
children: null
},
name: "shipTemplate",
level: 2,
type: 0,
title: "配送模板",
path: "shipTemplate",
component: "shop/ship/shipTemplate",
children: null
},
{
name: "logistics",
level: 2,

View File

@ -1,6 +1,7 @@
import lazyLoading from './lazyLoading.js';
import Cookies from "js-cookie";
import { result } from './routerJson.js';
import { getCurrentPermissionList } from "@/api/index";
const config = require('@/config/index')
@ -326,43 +327,40 @@ util.initRouter = function (vm) { // 初始化路由
return;
}
if (!vm.$store.state.app.added) {
// 加载菜单
let menuData = result;
// 格式化数据,设置 空children 为 null
for(let i =0;i<menuData.length;i++){
let t = menuData[i].children
for(let k = 0;k<t.length;k++){
let tt = t[k].children;
for(let z = 0;z<tt.length;z++){
tt[z].children = null
// 给所有三级路由添加字段显示一级菜单name方便点击页签时的选中筛选
tt[z].firstRouterName = menuData[i].name
getCurrentPermissionList().then(res => {
if (!res.success) return false;
let menuData = res.result;
// 格式化数据,设置 空children 为 null
for (let i = 0; i < menuData.length; i++) {
let t = menuData[i].children
for (let k = 0; k < t.length; k++) {
let tt = t[k].children;
for (let z = 0; z < tt.length; z++) {
tt[z].children = null
// 给所有三级路由添加字段显示一级菜单name方便点击页签时的选中筛选
tt[z].firstRouterName = menuData[i].name
}
}
}
}
util.initAllMenuData(constRoutes, menuData);
util.initRouterNode(otherRoutes, otherRouter);
// 添加所有主界面路由
vm.$store.commit('updateAppRouter', constRoutes.filter(item => item.children.length > 0));
// 添加全局路由
vm.$store.commit('updateDefaultRouter', otherRoutes);
// 添加菜单路由
util.initMenuData(vm, menuData);
// 缓存数据 修改加载标识
window.localStorage.setItem('menuData', JSON.stringify(menuData));
vm.$store.commit('setAdded', true);
} else {
// 读取缓存数据
let data = window.localStorage.getItem('menuData');
if (!data) {
vm.$store.commit('setAdded', false);
return;
}
let menuData = JSON.parse(data);
// 添加菜单路由
util.initMenuData(vm, menuData);
}
if (!menuData) {
return;
}
util.initAllMenuData(constRoutes, menuData);
util.initRouterNode(otherRoutes, otherRouter);
// 添加所有主界面路由
vm.$store.commit('updateAppRouter', constRoutes.filter(item => item.children.length > 0));
// 添加全局路由
vm.$store.commit('updateDefaultRouter', otherRoutes);
// 添加菜单路由
util.initMenuData(vm, menuData);
// 缓存数据 修改加载标识
window.localStorage.setItem('menuData', JSON.stringify(menuData));
vm.$store.commit('setAdded', true);
})
};
// 添加所有顶部导航栏下的菜单路由
@ -370,7 +368,7 @@ util.initAllMenuData = function (constRoutes, data) {
let allMenuData = [];
data.forEach(e => {
if (e.type == -1) {
if (e.level == 0) {
e.children.forEach(item => {
allMenuData.push(item);
})
@ -439,16 +437,15 @@ util.initRouterNode = function (routers, data) { // data为所有子菜单数
for (var item of data) {
let menu = Object.assign({}, item);
menu.component = lazyLoading(menu.component);
menu.component = lazyLoading(menu.frontRoute);
if (item.children && item.children.length > 0) {
menu.children = [];
util.initRouterNode(menu.children, item.children);
}
let meta = {};
// 给页面添加标题
meta.title = menu.title ? menu.title + " - "+config.title+"商家后台" : null;
meta.firstRouterName = menu.firstRouterName
meta.title = menu.title ? menu.title + " - " + config.title + "商家后台" : null;
meta.firstRouterName = item.firstRouterName
meta.keepAlive = menu.keepAlive ? true : false
menu.meta = meta;

View File

@ -1,6 +1,7 @@
<template>
<div class="search">
<Card>
<Row @keydown.enter.native="handleSearch">
<Form
ref="searchForm"

View File

@ -2,38 +2,66 @@
<div class="login" @click="$refs.verify.show = false">
<Row type="flex" @keydown.enter.native="submitLogin">
<Col style="width: 368px">
<Header />
<Row style="flex-direction: column;">
<Form ref="usernameLoginForm" :model="form" :rules="rules" class="form">
<FormItem prop="username">
<Input v-model="form.username" prefix="ios-contact" size="large" clearable placeholder="请输入用户名"
autocomplete="off" />
</FormItem>
<FormItem prop="password">
<Input type="password" v-model="form.password" prefix="ios-lock" size="large" password placeholder="请输入密码"
autocomplete="off" />
</FormItem>
</Form>
<Header />
<Row style="flex-direction: column">
<Form
ref="usernameLoginForm"
:model="form"
:rules="rules"
class="form"
>
<FormItem prop="username">
<Input
v-model="form.username"
prefix="ios-contact"
size="large"
clearable
placeholder="请输入用户名"
autocomplete="off"
/>
</FormItem>
<FormItem prop="password">
<Input
type="password"
v-model="form.password"
prefix="ios-lock"
size="large"
password
placeholder="请输入密码"
autocomplete="off"
/>
</FormItem>
</Form>
<Row>
<div class="login-btn" type="primary" size="large" :loading="loading" @click="submitLogin" long>
<span v-if="!loading"></span>
<span v-else></span>
</div>
<Row>
<div
class="login-btn"
type="primary"
size="large"
:loading="loading"
@click="submitLogin"
long
>
<span v-if="!loading"></span>
<span v-else></span>
</div>
</Row>
</Row>
</Row>
<Footer />
<!-- 拼图验证码 -->
<verify ref="verify" class="verify-con" verifyType="LOGIN" @change="verifyChange"></verify>
<Footer />
<!-- 拼图验证码 -->
<verify
ref="verify"
class="verify-con"
verifyType="LOGIN"
@change="verifyChange"
></verify>
</Col>
</Row>
</div>
</template>
<script>
import { getCurrentPermissionList } from "@/api/index";
import { login, userMsg } from "@/api/index";
import { validateMobile } from "@/libs/validate";
import Cookies from "js-cookie";
@ -95,6 +123,10 @@ export default {
},
};
},
created() {
window.localStorage.setItem("menuData", "");
},
methods: {
afterLogin(res) {
let accessToken = res.result.accessToken;
@ -104,6 +136,10 @@ export default {
//
userMsg().then((res) => {
if (res.success) {
// location.reload();
// this.$router.go(0);
console.log("Huoqu ");
this.setStore("saveLogin", this.saveLogin);
if (this.saveLogin) {
// 7
@ -113,9 +149,10 @@ export default {
} else {
Cookies.set("userInfoSeller", JSON.stringify(res.result));
}
util.initRouter(this);
this.$store.commit("setAvatarPath", res.result.storeLogo);
//
util.initRouter(this);
this.$router.push({
name: "home_index",
});
@ -139,8 +176,8 @@ export default {
this.loading = true;
let fd = new FormData();
fd.append('username',this.form.username)
fd.append('password',this.md5(this.form.password))
fd.append("username", this.form.username);
fd.append("password", this.md5(this.form.password));
login(fd)
.then((res) => {
this.loading = false;
@ -157,7 +194,6 @@ export default {
};
</script>
<style lang="scss" scoped>
.login {
height: 100%;
background: url("../assets/background.png") no-repeat;
@ -167,7 +203,6 @@ export default {
display: flex;
align-items: center;
justify-content: center;
.verify-con {
position: absolute;
@ -194,9 +229,8 @@ export default {
transition: 0.35s;
}
.login-btn:hover {
opacity: .9;
opacity: 0.9;
border-radius: 10px;
}
}
</style>

View File

@ -0,0 +1,72 @@
<template>
<div>
<Cascader
v-model="selectDep"
:data="department"
@on-change="handleChangeDep"
change-on-select
filterable
clearable
placeholder="请选择"
></Cascader>
</div>
</template>
<script>
import { initDepartment } from "@/api/index";
export default {
name: "departmentChoose",
props: {
},
data() {
return {
selectDep: [], //
department: [] //
};
},
methods: {
//
initDepartmentData() {
initDepartment().then(res => {
if (res.success) {
const arr = res.result;
this.filterData(arr)
this.department = arr
}
});
},
handleChangeDep(value, selectedData) {
let departmentId = "";
//
if (value && value.length > 0) {
departmentId = value[value.length - 1];
}
this.$emit("on-change", departmentId);
},
//
clearSelect() {
this.selectDep = [];
},
//
filterData (data) {
data.forEach(e => {
e.value = e.id;
e.label = e.title;
if (e.children) {
this.filterData(e.children)
} else {
return
}
})
}
},
created() {
this.initDepartmentData();
}
};
</script>
<style lang="scss">
</style>

View File

@ -0,0 +1,159 @@
<template>
<div>
<div style="display:flex;">
<Input
v-model="departmentTitle"
readonly
style="margin-right:10px;"
:placeholder="placeholder"
:clearable="clearable"
@on-clear="clearSelect"
/>
<Poptip transfer trigger="click" placement="right" title="选择部门" width="250">
<Button icon="md-list">选择部门</Button>
<div slot="content">
<Input
v-model="searchKey"
suffix="ios-search"
@on-change="searchDep"
placeholder="输入部门名搜索"
clearable
/>
<div class="dep-tree-bar">
<Tree
:data="dataDep"
@on-select-change="selectTree"
></Tree>
<Spin size="large" fix v-if="depLoading"></Spin>
</div>
</div>
</Poptip>
</div>
</div>
</template>
<script>
import {initDepartment, searchDepartment} from "@/api/index";
export default {
name: "departmentTreeChoose",
props: {
multiple: {
type: Boolean,
default: false
},
clearable: {
type: Boolean,
default: true
},
placeholder: {
type: String,
default: "点击选择部门"
}
},
data() {
return {
depLoading: false, //
departmentTitle: "", // modal
searchKey: "", //
dataDep: [], //
selectDep: [], //
departmentId: [] // id
};
},
methods: {
//
initDepartmentData() {
initDepartment().then(res => {
if (res.success) {
this.dataDep = res.result;
}
});
},
searchDep() {
//
if (this.searchKey) {
this.depLoading = true;
searchDepartment({title: this.searchKey}).then(res => {
this.depLoading = false;
if (res.success) {
res.result.forEach(function (e) {
if (e.status == -1) {
e.title = "[已禁用] " + e.title;
e.disabled = true;
}
});
this.dataDep = res.result;
}
});
} else {
this.initDepartmentData();
}
},
//
selectTree(v) {
if (v.length === 0) {
this.$emit("on-change", null);
this.departmentId = "";
this.departmentTitle = "";
return
}
this.departmentId = v[0].id;
this.departmentTitle = v[0].title;
let department = {
departmentId: this.departmentId,
departmentTitle: this.departmentTitle
}
this.$emit("on-change", department);
},
//
clearSelect() {
this.departmentId = [];
this.departmentTitle = "";
this.initDepartmentData();
if (this.multiple) {
this.$emit("on-change", []);
} else {
this.$emit("on-change", "");
}
this.$emit("on-clear");
},
//
setData(ids, title) {
this.departmentTitle = title;
if (this.multiple) {
this.departmentId = ids;
} else {
this.departmentId = [];
this.departmentId.push(ids);
}
}
},
created() {
this.initDepartmentData();
}
};
</script>
<style lang="scss" scoped>
.dep-tree-bar {
position: relative;
min-height: 80px;
max-height: 500px;
overflow: auto;
margin-top: 5px;
}
.dep-tree-bar::-webkit-scrollbar {
width: 6px;
height: 6px;
}
.dep-tree-bar::-webkit-scrollbar-thumb {
border-radius: 4px;
-webkit-box-shadow: inset 0 0 2px #d1d1d1;
background: #e4e4e4;
}
</style>

View File

@ -263,7 +263,6 @@
this.loading = false;
if (res.success) {
this.data = res.result.records;
this.total = res.result.total;
}
});

View File

@ -0,0 +1,782 @@
<template>
<div class="search">
<Card>
<Form ref="searchForm" :model="searchForm" inline :label-width="70" class="search-form">
<Form-item label="店员名称">
<Input
type="text"
v-model="searchForm.clerkName"
placeholder="请输入店员名称"
clearable
style="width: 200px"
/>
</Form-item>
<Form-item label="联系方式">
<Input
type="text"
v-model="searchForm.mobile"
placeholder="请输入联系方式"
clearable
style="width: 200px"
/>
</Form-item>
<Form-item label="部门">
<department-choose @on-change="handleSelectDep" style="width: 150px;" ref="dep"></department-choose>
</Form-item>
<Button @click="handleSearch" type="primary" icon="ios-search" class="search-btn">搜索</Button>
</Form>
<Row class="operation padding-row">
<Button @click="add" type="primary">添加</Button>
<Button @click="delAll"></Button>
<Button @click="resetPass"></Button>
</Row>
<br>
<Table
:loading="loading"
border
:columns="columns"
:data="data"
sortable="custom"
@on-sort-change="changeSort"
@on-selection-change="showSelect"
ref="table"
></Table>
<Row type="flex" justify="end" class="mt_10">
<Page
:current="searchForm.pageNumber"
:total="total"
:page-size="searchForm.pageSize"
@on-change="changePage"
@on-page-size-change="changePageSize"
:page-size-opts="[10,20,50]"
size="small"
show-total
show-elevator
show-sizer
></Page>
</Row>
</Card>
<Modal
:title="modalTitle"
v-model="userEditModalVisible"
:mask-closable="false"
:width="500"
:styles="{top: '30px'}"
>
<Form ref="form" :model="editForm" :label-width="80" :rules="formValidate">
<FormItem label="手机号">
<Input v-model="mobile" disabled/>
</FormItem>
<FormItem label="店员名称">
<Input v-model="clerkName" disabled/>
</FormItem>
<FormItem label="超级管理员" prop="isSuper">
<RadioGroup type="button" button-style="solid" v-model="editForm.isSuper">
<Radio :label="1">
<span></span>
</Radio>
<Radio :label="0">
<span></span>
</Radio>
</RadioGroup>
</FormItem>
<FormItem label="角色" prop="roles" v-if="editForm.isSuper == 0">
<Select v-model="editForm.roles" multiple>
<Option v-for="item in roleList" :value="item.id" :key="item.id" :label="item.name">
</Option>
</Select>
</FormItem>
<Form-item label="所属部门">
<department-tree-choose @on-change="handleEditSelectDepTree" ref="depTree"></department-tree-choose>
</Form-item>
</Form>
<div slot="footer">
<Button type="text" @click="userEditModalVisible = false">取消</Button>
<Button type="primary" :loading="submitLoading" @click="updateSubmit"></Button>
</div>
</Modal>
<Modal
:title="modalTitle"
v-model="userModalVisible"
:mask-closable="false"
:width="500"
:styles="{top: '30px'}"
>
<Form ref="form" :model="form" :label-width="80" :rules="formValidate">
<FormItem label="手机号" prop="mobile">
<Input placeholder="请输入要添加的会员手机号码" maxlength="11" style="width: 75%" v-model="form.mobile"
autocomplete="off" @on-change="checkClerks"/>
&nbsp;<Button v-if="!memberCheck" @click="checkClerk"></Button>
<Button v-if="memberCheck" @click="checkAgainClerk"></Button>
</FormItem>
<FormItem v-if="newMember" label="用户名" prop="username">
<Input v-model="form.username" autocomplete="off"/>
</FormItem>
<FormItem v-if="oldMember" label="用户名" prop="username">
<Input v-model="form.username" autocomplete="off" disabled/>
</FormItem>
<FormItem label="密码" prop="password" v-if="newMember" :error="errorPass">
<Input type="password" password v-model="form.password" autocomplete="off"/>
</FormItem>
<FormItem label="超级管理员" prop="isSuper" v-if="newMember || oldMember">
<RadioGroup type="button" button-style="solid" v-model="form.isSuper">
<Radio :label="1">
<span></span>
</Radio>
<Radio :label="0">
<span></span>
</Radio>
</RadioGroup>
</FormItem>
<FormItem label="角色" prop="roles" v-if="(oldMember || newMember) && form.isSuper == 0">
<Select v-model="form.roles" multiple>
<Option v-for="item in roleList" :value="item.id" :key="item.id" :label="item.name">
</Option>
</Select>
</FormItem>
<Form-item label="所属部门" v-if="oldMember || newMember">
<department-tree-choose @on-change="handleSelectDepTree" ref="depTree"></department-tree-choose>
</Form-item>
</Form>
<div slot="footer">
<Button type="text" @click="userModalVisible = false">取消</Button>
<Button type="primary" :loading="submitLoading" @click="submitUser"></Button>
</div>
</Modal>
</div>
</template>
<script>
import {
checkClerk,
getUserListData,
getAllRoleList,
addUser,
editOtherUser,
enableClerk,
deleteClerk,
resetPassword,
getClerk
} from "@/api/index";
import {validateMobile} from "@/libs/validate";
import departmentChoose from "@/views/my-components/lili/department-choose";
import departmentTreeChoose from "@/views/my-components/lili/department-tree-choose";
import uploadPicInput from "@/views/my-components/lili/upload-pic-input";
export default {
name: "clerk-manage",
components: {
departmentChoose,
departmentTreeChoose,
uploadPicInput,
},
data() {
return {
open:0,
loading: true, //
selectCount: 0, //
selectList: [], //
searchForm: { //
clerkName: "",
departmentId: "",
pageNumber: 1,
pageSize: 10,
sort: "createTime",
order: "desc"
},
modalType: 0, //
userModalVisible: false, // modal
userEditModalVisible:false,
modalTitle: "", // modal
form: { //
username: "",
mobile: 0,
sex: "",
isSuper: 0,
roles: [],
departmentId: "",
departmentTitle: ""
},
editForm: { //
isSuper: 0,
roles: [],
departmentId: "",
departmentTitle: ""
},
mobile: "",
clerkName: "",
newMember: false,
oldMember: false,
memberCheck: false,
roleList: [], //
errorPass: "", //
formValidate: { //
username: [
{required: true, message: "用户名不能为空", trigger: "blur"}
],
password: [
{required: true, message: "密码不能为空", trigger: "blur"}
],
mobile: [
{required: true, message: "手机号不能为空", trigger: "blur"},
{validator: validateMobile, trigger: "blur"}
]
},
submitLoading: false, //
columns: [ //
{
type: "selection",
width: 60,
align: "center",
fixed: "left"
},
{
title: "店员名称",
key: "clerkName",
minWidth: 100,
sortable: true,
fixed: "left"
},
{
title: "手机号码",
key: "mobile",
minWidth: 100,
fixed: "left"
},
{
title: "店主",
key: "status",
align: "center",
width: 130,
render: (h, params) => {
if (params.row.shopkeeper == true) {
return h("div", [
h("Badge", {
props: {
status: "success",
text: "是"
}
})
]);
} else if (params.row.shopkeeper == false) {
return h("div", [
h("Badge", {
props: {
status: "error",
text: "否"
}
})
]);
}
},
},
{
title: "超级管理员",
key: "status",
align: "center",
width: 130,
render: (h, params) => {
if (params.row.isSuper == true) {
return h("div", [
h("Badge", {
props: {
status: "success",
text: "是"
}
})
]);
} else if (params.row.isSuper == false) {
return h("div", [
h("Badge", {
props: {
status: "error",
text: "否"
}
})
]);
}
},
},
{
title: "状态",
key: "status",
align: "center",
width: 130,
render: (h, params) => {
if (params.row.status == true) {
return h("div", [
h("Badge", {
props: {
status: "success",
text: "启用"
}
})
]);
} else if (params.row.status == false) {
return h("div", [
h("Badge", {
props: {
status: "error",
text: "禁用"
}
})
]);
}
},
filters: [
{
label: "启用",
value: true
},
{
label: "禁用",
value: false
}
],
filterMultiple: false,
filterMethod(value, row) {
return row.status == value;
}
},
{
title: "创建时间",
key: "createTime",
sortable: true,
sortType: "desc",
width: 180
},
{
title: "操作",
key: "action",
width: 200,
align: "center",
fixed: "right",
render: (h, params) => {
let enableOrDisable = "";
if (params.row.status == true) {
enableOrDisable = h(
"Button",
{
props: {
size: "small"
},
style: {
marginRight: "5px"
},
on: {
click: () => {
this.disable(params.row);
}
}
},
"禁用"
);
} else {
enableOrDisable = h(
"Button",
{
props: {
type: "success",
size: "small"
},
style: {
marginRight: "5px"
},
on: {
click: () => {
this.enable(params.row);
}
}
},
"启用"
);
}
return h("div", [
h(
"Button",
{
props: {
type: "info",
size: "small"
},
style: {
marginRight: "5px"
},
on: {
click: () => {
this.edit(params.row);
}
}
},
"编辑"
),
enableOrDisable,
h(
"Button",
{
props: {
type: "error",
size: "small"
},
on: {
click: () => {
this.remove(params.row);
}
}
},
"删除"
)
]);
}
}
],
data: [], //
total: 0, //
};
},
methods: {
//
init() {
this.getUserList();
},
checkClerks() {
this.open = this.form.mobile.length;
console.log(this.open)
if(this.open == 11 ){
this.checkClerk();
}
if(this.open < 11){
this.checkAgainClerk()
}
},
//
handleSelectDepTree(v) {
if (v) {
this.form.departmentId = v.departmentId;
this.form.departmentTitle = v.departmentTitle;
} else {
this.form.departmentId = "";
this.form.departmentTitle = "";
}
},
//
handleEditSelectDepTree(v) {
if (v) {
this.editForm.departmentId = v.departmentId;
this.editForm.departmentTitle = v.departmentTitle;
} else {
this.editForm.departmentId = "";
this.editForm.departmentTitle = "";
}
},
//
checkAgainClerk() {
this.memberCheck = false
this.newMember = false
this.oldMember = false
},
//
checkClerk() {
if (this.form.mobile) {
this.newMember = false
this.oldMember = false
checkClerk(this.form.mobile).then(res => {
if (!res.result.id) {
this.newMember = true
} else {
this.oldMember = true
this.form.username = res.result.username
this.form.password = res.result.password
}
this.form.isSuper = 1
this.memberCheck = true;
});
}
},
//
handleSelectDep(v) {
this.searchForm.departmentId = v;
},
//
changePage(v) {
this.searchForm.pageNumber = v;
this.getUserList();
this.clearSelectAll();
},
//
changePageSize(v) {
this.searchForm.pageSize = v;
this.searchForm.pageNumber = 1;
this.getUserList();
},
getUserList() {
//
this.loading = true;
getUserListData(this.searchForm).then(res => {
this.loading = false;
if (res.success) {
this.data = res.result.records;
this.total = res.result.total;
}
});
},
//
handleSearch() {
this.searchForm.pageNumber = 1;
this.searchForm.pageSize = 10;
this.getUserList();
},
//
changeSort(e) {
this.searchForm.sort = e.key;
this.searchForm.order = e.order;
if (e.order == "normal") {
this.searchForm.order = "";
}
this.getUserList();
},
//
getRoleList() {
let params = {
pageSize: 100
}
getAllRoleList(params).then(res => {
if (res.success) {
this.roleList = res.result.records;
}
});
},
//
resetPass() {
if (this.selectCount == 0) {
this.$Message.warning('请选中数据后重试!');
return
}
this.$Modal.confirm({
title: "确认重置",
content:
"您确认要重置所选的 " +
this.selectCount +
" 条用户数据密码为【123456】?",
loading: true,
onOk: () => {
let ids = "";
this.selectList.forEach(function (e) {
ids += e.id + ",";
});
ids = ids.substring(0, ids.length - 1);
console.warn(ids)
resetPassword(ids).then(res => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("操作成功");
this.clearSelectAll();
this.getUserList();
}
});
}
});
},
updateSubmit(){
this.submitLoading = true;
console.warn(this.editForm)
editOtherUser(this.editForm.id,this.editForm).then(res => {
this.submitLoading = false;
if (res.success) {
this.$Message.success("操作成功");
this.getUserList();
this.userEditModalVisible = false;
}
});
},
//
submitUser() {
this.$refs.form.validate(valid => {
if (valid) {
// id
const params = JSON.parse(JSON.stringify(this.form))
console.warn(params)
delete params.id;
delete params.status;
if (this.newMember) {
if (params.password == "" || params.password == undefined) {
this.errorPass = "密码不能为空";
return;
}
if (params.password.length < 6) {
this.errorPass = "密码长度不得少于6位";
return;
}
//todo
params.password = this.md5(params.password)
} else {
params.password = this.form.password
}
this.submitLoading = true;
addUser(params).then(res => {
this.submitLoading = false;
if (res.success) {
this.$Message.success("操作成功");
this.getUserList();
this.userModalVisible = false;
}
});
}
});
},
//
add() {
// this.checkClerks();
this.modalType = 0;
this.modalTitle = "添加店员";
this.$refs.form.resetFields();
this.form = { //
username: "",
mobile: "",
isSuper: 0,
roles: [],
departmentId: "",
departmentTitle: ""
},
this.oldMember = false
this.newMember = false
this.userModalVisible = true;
},
//
edit(v) {
console.warn(v)
getClerk(v.id).then(res => {
console.warn(res)
this.mobile = res.result.mobile
this.clerkName = res.result.clerkName
this.editForm.isSuper = 0
this.editForm.id = res.result.id
if(res.result.isSuper){
this.editForm.isSuper = 1
}
this.editForm.departmentId = res.result.departmentId
this.$refs.depTree.setData(res.result.departmentId, res.result.departmentTitle);
let selectRolesId = [];
if (res.result.roles) {
res.result.roles.forEach(function (e) {
selectRolesId.push(e.id);
});
}
this.editForm.roles = selectRolesId;
this.modalTitle = "修改店员";
this.userEditModalVisible = true;
})
},
//
enable(v) {
let params = {
status: true
}
this.$Modal.confirm({
title: "确认启用",
content: "您确认要启用用户 " + v.clerkName + " ?",
loading: true,
onOk: () => {
enableClerk(v.id, params).then(res => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("操作成功");
this.getUserList();
}
});
}
});
},
//
disable(v) {
let params = {
status: false
}
this.$Modal.confirm({
title: "确认禁用",
content: "您确认要禁用用户 " + v.clerkName + " ?",
loading: true,
onOk: () => {
enableClerk(v.id, params).then(res => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("操作成功");
this.getUserList();
}
});
}
});
},
//
remove(v) {
this.$Modal.confirm({
title: "确认删除",
content: "您确认要删除用户 " + v.clerkName + " ?",
loading: true,
onOk: () => {
deleteClerk(v.id).then(res => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("删除成功");
this.getUserList();
}
});
}
});
},
//
showSelect(e) {
this.selectList = e;
this.selectCount = e.length;
},
//
clearSelectAll() {
this.$refs.table.selectAll(false);
},
//
delAll() {
if (this.selectCount <= 0) {
this.$Message.warning("您还未选择要删除的数据");
return;
}
this.$Modal.confirm({
title: "确认删除",
content: "您确认要删除所选的 " + this.selectCount + " 条店员?",
loading: true,
onOk: () => {
let ids = "";
this.selectList.forEach(function (e) {
ids += e.id + ",";
});
ids = ids.substring(0, ids.length - 1);
deleteClerk(ids).then(res => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("删除成功");
this.clearSelectAll();
this.getUserList();
}
});
}
});
}
},
mounted() {
this.init();
this.getRoleList();
}
};
</script>

View File

@ -0,0 +1,408 @@
<template>
<div class="search">
<Card>
<Row class="operation">
<i-switch v-model="strict" size="large" style="margin-right: 5px">
<span slot="open">级联</span>
<span slot="close">单选</span>
</i-switch>
<Button @click="addRoot"></Button>
<Button @click="add" type="primary">添加子部门</Button>
<Button @click="delAll"></Button>
<Button @click="getParentList"></Button>
</Row>
<Row type="flex" justify="start">
<Col :md="8" :lg="8" :xl="6">
<Alert show-icon>
当前选择编辑
<span class="select-title">{{ editTitle }}</span>
<a class="select-clear" v-if="form.id" @click="cancelSelect"
>取消选择</a
>
</Alert>
<div class="tree-bar" :style="{ maxHeight: maxHeight }">
<Tree
ref="tree"
:data="data"
:load-data="loadData"
show-checkbox
@on-check-change="changeSelect"
@on-select-change="selectTree"
:check-strictly="!strict"
></Tree>
<Spin size="large" fix v-if="loading"></Spin>
</div>
</Col>
<Col :md="15" :lg="13" :xl="9" style="margin-left: 10px">
<Form
ref="form"
:model="form"
:label-width="100"
:rules="formValidate"
>
<FormItem label="部门名称" prop="title">
<Input v-model="form.title" />
</FormItem>
<FormItem label="选择角色">
<Select
:loading="userLoading"
not-found-text="暂无角色"
v-model="selectedRole"
multiple
>
<Option v-for="item in users" :value="item.id" :key="item.id">{{
item.name
}}</Option>
</Select>
</FormItem>
<FormItem label="排序值" prop="sortOrder">
<Tooltip
trigger="hover"
placement="right"
content="值越小越靠前,支持小数"
>
<InputNumber
:max="1000"
:min="0"
v-model="form.sortOrder"
></InputNumber>
</Tooltip>
</FormItem>
<Form-item>
<Button
style="margin-right: 5px"
@click="submitEdit"
:loading="submitLoading"
type="primary"
>修改并保存</Button
>
<Button @click="handleReset"></Button>
</Form-item>
</Form>
</Col>
</Row>
</Card>
<Modal
:title="modalTitle"
v-model="modalVisible"
:mask-closable="false"
:width="500"
>
<Form
ref="formAdd"
:model="formAdd"
:label-width="85"
:rules="formValidate"
>
<div v-if="showParent">
<FormItem label="上级部门:">{{ form.title }}</FormItem>
</div>
<FormItem label="部门名称" prop="title">
<Input v-model="formAdd.title" />
</FormItem>
<FormItem label="排序值" prop="sortOrder">
<Tooltip
trigger="hover"
placement="right"
content="值越小越靠前,支持小数"
>
<InputNumber
:max="1000"
:min="0"
v-model="formAdd.sortOrder"
></InputNumber>
</Tooltip>
</FormItem>
</Form>
<div slot="footer">
<Button type="text" @click="cancelAdd"></Button>
<Button type="primary" :loading="submitLoading" @click="submitAdd"
>提交</Button
>
</div>
</Modal>
</div>
</template>
<script>
import {
initDepartment,
loadDepartment,
addDepartment,
editDepartment,
deleteDepartment,
getUserByDepartmentId,
getRoleList,
updateDepartmentRole,
} from "@/api/index";
export default {
name: "store-department-manage",
data() {
return {
loading: true, //
maxHeight: "500px", //
strict: true, //
userLoading: false, //
loadingEdit: false, //
modalVisible: false, // modal
selectList: [], //
selectCount: 0, //
showParent: false, //
modalTitle: "", // modal
editTitle: "", //
selectedRole: [], //
searchKey: "", //
form: { //
id: "",
title: "",
parentId: "",
parentTitle: "",
sortOrder: 0,
status: 0,
},
formAdd: {}, //
formValidate: { //
title: [{ required: true, message: "名称不能为空", trigger: "blur" }],
sortOrder: [
{
required: true,
type: "number",
message: "排序值不能为空",
trigger: "blur",
},
],
},
submitLoading: false, // loading
data: [], //
dataEdit: [], //
users: [], //
};
},
methods: {
init() {
this.getParentList();
},
//
getParentList() {
this.loading = true;
initDepartment().then((res) => {
this.loading = false;
if (res.success) {
this.data = res.result;
}
});
},
//
loadData(item, callback) {
loadDepartment(item.id).then((res) => {
this.loadingEdit = false;
if (res.success) {
console.log(res.result);
callback(res.result);
}
});
},
//
selectTree(v) {
if (v.length > 0) {
// null""
for (let attr in v[0]) {
if (v[0][attr] == null) {
v[0][attr] = "";
}
}
let str = JSON.stringify(v[0]);
let data = JSON.parse(str);
this.editTitle = data.title;
//
this.userLoading = true;
getUserByDepartmentId(data.id).then((res) => {
let way =[]
res.result && res.result.forEach((item) => {
way.push(item.roleId)
})
this.$set(this,'selectedRole',way)
});
getRoleList({
pageNumber: 1,
pageSize: 10000,
}).then((res) => {
this.userLoading = false;
if (res.success) {
this.users = res.result.records;
//
this.form = data;
}
});
} else {
this.cancelSelect();
}
},
//
cancelSelect() {
let data = this.$refs.tree.getSelectedNodes()[0];
if (data) {
data.selected = false;
}
this.$refs.form.resetFields();
delete this.form.id;
this.editTitle = "";
},
//
selectTreeEdit(v) {
if (v.length > 0) {
// null""
for (let attr in v[0]) {
if (v[0][attr] == null) {
v[0][attr] = "";
}
}
let str = JSON.stringify(v[0]);
let data = JSON.parse(str);
this.form.parentId = data.id;
this.form.parentTitle = data.title;
}
},
//
cancelAdd() {
this.modalVisible = false;
},
//
handleReset() {
this.$refs.form.resetFields();
this.form.status = 0;
},
//
submitEdit() {
this.$refs.form.validate((valid) => {
if (valid) {
if (!this.form.id) {
this.$Message.warning("请先点击选择要修改的部门");
return;
}
let roleWay = [];
this.selectedRole.forEach((item) => {
let role = {
departmentId: this.form.id,
roleId: item,
};
roleWay.push(role);
});
Promise.all([
editDepartment(this.form.id, this.form),
updateDepartmentRole(this.form.id, roleWay)
]).then((res) => {
console.warn(res)
this.submitLoading = false;
if (res[0].success) {
this.$Message.success("编辑成功");
this.init();
this.modalVisible = false;
}
});
}
});
},
//
submitAdd() {
this.$refs.formAdd.validate((valid) => {
if (valid) {
this.submitLoading = true;
addDepartment(this.formAdd).then((res) => {
this.submitLoading = false;
if (res.success) {
this.$Message.success("添加成功");
this.init();
this.modalVisible = false;
}
});
}
});
},
//
add() {
if (this.form.id == "" || this.form.id == null) {
this.$Message.warning("请先点击选择一个部门");
return;
}
this.modalTitle = "添加子部门";
this.showParent = true;
this.formAdd = {
parentId: this.form.id,
sortOrder: 0,
status: 0,
};
this.modalVisible = true;
},
//
addRoot() {
this.modalTitle = "添加一级部门";
this.showParent = false;
this.formAdd = {
parentId: 0,
sortOrder: 0,
status: 0,
};
this.modalVisible = true;
},
//
changeSelect(v) {
console.log(v);
this.selectCount = v.length;
this.selectList = v;
},
//
delAll() {
if (this.selectCount <= 0) {
this.$Message.warning("您还未勾选要删除的数据");
return;
}
this.$Modal.confirm({
title: "确认删除",
content:
"您确认要删除所选的 " + this.selectCount + " 条数据及其下级所有数据?",
loading: true,
onOk: () => {
let ids = "";
this.selectList.forEach(function (e) {
ids += e.id + ",";
});
ids = ids.substring(0, ids.length - 1);
deleteDepartment(ids).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("删除成功");
this.selectList = [];
this.selectCount = 0;
this.cancelSelect();
this.init();
}
});
},
});
},
},
mounted() {
//
let height = document.documentElement.clientHeight;
this.maxHeight = Number(height - 287) + "px";
this.init();
},
};
</script>
<style lang="scss" scoped>
@import "@/styles/tree-common.scss";
</style>

View File

@ -0,0 +1,768 @@
<template>
<div class="search">
<Card>
<Row class="operation">
<Button @click="addRole" type="primary">添加角色</Button>
<Button @click="delAll"></Button>
</Row>
<br>
<Table :loading="loading" border :columns="columns" :data="data" ref="table" sortable="custom" @on-sort-change="changeSort" @on-selection-change="changeSelect"></Table>
<Row type="flex" justify="end" class="mt_10">
<Page :current="pageNumber" :total="total" :page-size="pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10, 20, 50]" size="small" show-total
show-elevator show-sizer></Page>
</Row>
</Card>
<!-- 编辑 -->
<Modal :title="modalTitle" v-model="roleModalVisible" :mask-closable="false" :width="500">
<Form ref="roleForm" :model="roleForm" :label-width="80" :rules="roleFormValidate">
<FormItem label="角色名称" prop="name">
<Input v-model="roleForm.name" />
</FormItem>
<FormItem label="备注" prop="description">
<Input v-model="roleForm.description" />
</FormItem>
</Form>
<div slot="footer">
<Button type="text" @click="roleModalVisible = false">取消</Button>
<Button type="primary" :loading="submitLoading" @click="submitRole">
</Button>
</div>
</Modal>
<!-- 菜单权限 -->
<Modal :title="modalTitle" v-model="permModalVisible" :mask-closable="false" :width="500" :styles="{ top: '30px' }" class="permModal">
<div style="position: relative">
<Tree ref="tree" :data="permData" show-checkbox :render="renderContent">
</Tree>
<Spin size="large" fix v-if="treeLoading"></Spin>
</div>
<div slot="footer">
<Button type="text" @click="permModalVisible = false">取消</Button>
<Select v-model="openLevel" @on-change="changeOpen" style="width: 110px; text-align: left; margin-right: 10px">
<Option value="0">展开所有</Option>
<Option value="1">收合所有</Option>
<Option value="2">仅展开一级</Option>
<Option value="3">仅展开两级</Option>
</Select>
<Button type="primary" :loading="submitPermLoading" @click="submitPermEdit()">
</Button>
</div>
</Modal>
<!-- 保存权限弹出选择权限 -->
<Modal width="800" v-model="selectIsSuperModel" title="选择菜单权限" :loading="superModelLoading" @on-ok="saveRole">
<div class="btns">
<Button type="primary" @click="setRole()" class="btn-item">一键选中·数据权限</Button>
<Button class="btn-item" @click="setRole('onlyView')">·</Button>
</div>
<div class="role-list">
<div class="role-item" v-for="(item, index) in saveRoleWay" :key="index">
<div class="title">{{ item.title }}</div>
<div class="content">
<RadioGroup type="button" button-style="solid" v-model="item.isSuper">
<Radio :label="1">
<span>操作数据权限</span>
</Radio>
<Radio :label="0">
<span>查看权限</span>
</Radio>
</RadioGroup>
</div>
</div>
</div>
</Modal>
</div>
</template>
<script>
import {
getRoleList,
getAllPermissionList,
addRole,
editRole,
deleteRole,
loadDepartment,
selectRoleMenu,
saveRoleMenu,
} from "@/api/index";
import util from "@/libs/util.js";
export default {
name: "role-manage",
data() {
return {
superModelLoading: false, //
selectIsSuperModel: false, //
rolePermsWay: [], //
openLevel: "0", //
loading: true, //
treeLoading: true, //
depTreeLoading: true, //
submitPermLoading: false, //
submitDepLoading: false, //
sortColumn: "", //
sortType: "desc", //
modalType: 0, // 0 1
roleModalVisible: false, // modal
permModalVisible: false, // modal
depModalVisible: false, // modal
modalTitle: "", // modal
roleForm: {
//
name: "",
description: "",
},
roleFormValidate: {
//
name: [
{ required: true, message: "角色名称不能为空", trigger: "blur" },
],
},
submitLoading: false, // loading
selectList: [], //
selectCount: 0, //
columns: [
//
{
type: "selection",
width: 60,
align: "center",
},
{
title: "角色名称",
key: "name",
minWidth: 150,
},
{
title: "备注",
key: "description",
minWidth: 150,
tooltip: true,
},
{
title: "创建时间",
key: "createTime",
width: 170,
sortable: true,
sortType: "desc",
},
{
title: "更新时间",
key: "updateTime",
width: 170,
sortable: true,
},
{
title: "最后操作人",
key: "createBy",
width: 150,
},
{
title: "操作",
key: "action",
align: "center",
fixed: "right",
width: 230,
render: (h, params) => {
return h("div", [
h(
"Button",
{
props: {
type: "warning",
size: "small",
},
style: {
marginRight: "5px",
},
on: {
click: () => {
this.editPerm(params.row);
},
},
},
"菜单权限"
),
h(
"Button",
{
props: {
size: "small",
type: "info",
},
style: {
marginRight: "5px",
},
on: {
click: () => {
this.edit(params.row);
},
},
},
"编辑"
),
h(
"Button",
{
props: {
type: "error",
size: "small",
},
on: {
click: () => {
this.remove(params.row);
},
},
},
"删除"
),
]);
},
},
],
data: [], //
pageNumber: 1, //
pageSize: 10, //
total: 0, //
permData: [], //
editRolePermId: "", // id
selectAllFlag: false, //
depData: [], //
dataType: 0, //
editDepartments: [], //
saveRoleWay: [], //
};
},
methods: {
//
init() {
this.getRoleList();
//
this.getPermList();
},
// icon
renderContent(h, { root, node, data }) {
let icon = "";
if (data.level == 0) {
icon = "ios-navigate";
} else if (data.level == 1) {
icon = "md-list-box";
} else if (data.level == 2) {
icon = "md-list";
} else if (data.level == 3) {
icon = "md-radio-button-on";
} else {
icon = "md-radio-button-off";
}
return h(
"span",
{
style: {
display: "inline-block",
cursor: "pointer",
},
},
[
h("span", [
h("Icon", {
props: {
type: icon,
size: "16",
},
style: {
"margin-right": "8px",
"margin-bottom": "3px",
},
}),
h("span", data.title),
h(
"Tag",
{
props: {
color:
data.isSuper == 1
? "red"
: data.isSuper == 0
? "default"
: "default",
},
style: {
"margin-left": "10px",
display:
data.isSuper == 1 || data.isSuper == 0
? "inline-block"
: "none",
},
},
data.isSuper == 1
? "操作权限"
: data.isSuper == 0
? "查看权限"
: ""
),
]),
]
);
},
//
changePage(v) {
this.pageNumber = v;
this.getRoleList();
this.clearSelectAll();
},
//
changePageSize(v) {
this.pageNumber = 1;
this.pageSize = v;
this.getRoleList();
},
//
changeSort(e) {
this.sortColumn = e.key;
this.sortType = e.order;
if (e.order == "normal") {
this.sortType = "";
}
this.getRoleList();
},
/**
* 设置权限
*/
setRole(val) {
let enable;
val == "onlyView" ? (enable = 0) : (enable = 1);
this.saveRoleWay.map((item) => {
item.isSuper = enable;
});
},
/**
* 查询所有角色
*/
getRoleList() {
this.loading = true;
let params = {
pageNumber: this.pageNumber,
pageSize: this.pageSize,
sort: this.sortColumn,
order: this.sort,
};
getRoleList(params).then((res) => {
this.loading = false;
if (res.success) {
this.data = res.result.records;
this.total = res.result.total;
}
});
},
/**
* 查询菜单
*/
getPermList() {
this.treeLoading = true;
getAllPermissionList().then((res) => {
if (res.success) {
this.deleteDisableNode(res.result);
this.permData = res.result;
this.treeLoading = false;
}
this.treeLoading = false;
});
},
//
deleteDisableNode(permData) {
let that = this;
permData.forEach(function (e) {
if (e.status == -1) {
e.title = "[已禁用] " + e.title;
e.disabled = true;
}
if (e.children && e.children.length > 0) {
that.deleteDisableNode(e.children);
}
});
},
//
submitRole() {
this.$refs.roleForm.validate((valid) => {
if (valid) {
if (this.modalType == 0) {
//
this.submitLoading = true;
addRole(this.roleForm).then((res) => {
this.submitLoading = false;
if (res.success) {
this.$Message.success("操作成功");
this.getRoleList();
this.roleModalVisible = false;
}
});
} else {
this.submitLoading = true;
this.roleForm.roleId = this.roleForm.id;
editRole(this.roleForm).then((res) => {
this.submitLoading = false;
if (res.success) {
this.$Message.success("操作成功");
this.getRoleList();
this.roleModalVisible = false;
}
});
}
}
});
},
/**
* 点击添加按钮
*/
addRole() {
this.modalType = 0;
this.modalTitle = "添加角色";
this.$refs.roleForm.resetFields();
delete this.roleForm.id;
this.roleModalVisible = true;
},
//
edit(v) {
this.modalType = 1;
this.modalTitle = "编辑角色";
this.$refs.roleForm.resetFields();
// null""
for (let attr in v) {
if (v[attr] == null) {
v[attr] = "";
}
}
let str = JSON.stringify(v);
let roleInfo = JSON.parse(str);
this.roleForm = roleInfo;
this.roleModalVisible = true;
},
//
remove(v) {
this.$Modal.confirm({
title: "确认删除",
content: "您确认要删除角色 " + v.name + " ?",
loading: true,
onOk: () => {
deleteRole(v.id).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("删除成功");
this.getRoleList();
}
});
},
});
},
//
clearSelectAll() {
this.$refs.table.selectAll(false);
},
//
changeSelect(e) {
this.selectList = e;
this.selectCount = e.length;
},
//
delAll() {
if (this.selectCount <= 0) {
this.$Message.warning("您还未选择要删除的数据");
return;
}
this.$Modal.confirm({
title: "确认删除",
content: "您确认要删除所选的 " + this.selectCount + " 条数据?",
loading: true,
onOk: () => {
let ids = "";
this.selectList.forEach(function (e) {
ids += e.id + ",";
});
ids = ids.substring(0, ids.length - 1);
deleteRole(ids).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("删除成功");
this.clearSelectAll();
this.getRoleList();
}
});
},
});
},
//
async editPerm(v) {
/**
* 点击菜单权限每次将赋值的isSuper数据给清空掉
*/
this.permData.map((item) => {
item.children.length != 0
? item.children.map((child) => {
child.children.length != 0
? child.children.map((kid) => {
delete kid.isSuper;
})
: "";
delete child.isSuper;
})
: "";
delete item.isSuper;
});
if (this.treeLoading) {
this.$Message.warning("菜单权限数据加载中,请稍后点击查看");
return;
}
this.editRolePermId = v.id;
this.modalTitle = "分配 " + v.name + " 的菜单权限";
//
let rolePerms;
//
let res = await selectRoleMenu(v.id);
if (res.result) {
rolePerms = res.result;
this.rolePermsWay = res.result;
}
//
this.checkPermTree(this.permData, rolePerms);
this.permModalVisible = true;
},
//
checkPermTree(permData, rolePerms) {
let that = this;
permData.forEach((p) => {
if (that.hasPerm(p, rolePerms) && p.status != -1) {
if (p.children && p.children.length === 0) {
this.$set(p, "checked", true);
}
} else {
this.$set(p, "checked", false);
}
if (p.children && p.children.length > 0) {
that.checkPermTree(p.children, rolePerms);
}
});
},
//
hasPerm(p, rolePerms) {
if (!rolePerms) return false;
let flag = false;
for (let i = 0; i < rolePerms.length; i++) {
if (p.id == rolePerms[i].menuId) {
this.$set(p, "isSuper", rolePerms[i].isSuper);
flag = true;
break;
}
}
if (flag) {
return true;
}
return false;
},
//
selectedTreeAll(permData, select) {
let that = this;
permData.forEach(function (e) {
e.checked = select;
if (e.children && e.children.length > 0) {
that.selectedTreeAll(e.children, select);
}
});
},
/**分配菜单权限 */
submitPermEdit() {
this.saveRoleWay = [];
this.selectIsSuperModel = true; //
let selectedNodes = this.$refs.tree.getCheckedAndIndeterminateNodes();
let way = [];
selectedNodes.forEach((e) => {
console.log(e)
let perm = {
title: e.title,
isSuper: e.isSuper ? e.isSuper = 1 : e.isSuper = 0 || 0,
menuId: e.id,
roleId: this.editRolePermId,
};
way.push(perm);
this.$set(this,'saveRoleWay',way)
});
console.log(this.saveRoleWay)
},
/**保存权限 */
saveRole() {
this.superModelLoading = true;
saveRoleMenu(this.editRolePermId, this.saveRoleWay).then((res) => {
this.superModelLoading = false;
if (res.success) {
this.$Message.success("操作成功");
//
this.$store.commit("setAdded", false);
util.initRouter(this);
this.getRoleList();
this.permModalVisible = false;
}
});
},
//
loadData(item, callback) {
loadDepartment(item.id, { openDataFilter: false }).then((res) => {
if (res.success) {
res.result.forEach(function (e) {
e.checked = false;
if (e.isParent) {
e.loading = false;
e.children = [];
}
if (e.status == -1) {
e.title = "[已禁用] " + e.title;
e.disabled = true;
}
});
callback(res.result);
}
});
},
//
expandCheckDep(v) {
this.checkDepTree(v.children, this.editDepartments);
},
//
checkDepTree(depData, roleDepIds) {
let that = this;
depData.forEach(function (p) {
if (that.hasDepPerm(p, roleDepIds)) {
p.checked = true;
} else {
p.checked = false;
}
});
},
//
changeOpen(v) {
if (v == "0") {
this.permData.forEach((e) => {
e.expand = true;
if (e.children && e.children.length > 0) {
e.children.forEach((c) => {
c.expand = true;
if (c.children && c.children.length > 0) {
c.children.forEach(function (b) {
b.expand = true;
});
}
});
}
});
} else if (v == "1") {
this.permData.forEach((e) => {
e.expand = false;
if (e.children && e.children.length > 0) {
e.children.forEach((c) => {
c.expand = false;
if (c.children && c.children.length > 0) {
c.children.forEach(function (b) {
b.expand = false;
});
}
});
}
});
} else if (v == "2") {
this.permData.forEach((e) => {
e.expand = true;
if (e.children && e.children.length > 0) {
e.children.forEach((c) => {
c.expand = false;
if (c.children && c.children.length > 0) {
c.children.forEach(function (b) {
b.expand = false;
});
}
});
}
});
} else if (v == "3") {
this.permData.forEach((e) => {
e.expand = true;
if (e.children && e.children.length > 0) {
e.children.forEach((c) => {
c.expand = true;
if (c.children && c.children.length > 0) {
c.children.forEach(function (b) {
b.expand = false;
});
}
});
}
});
}
},
},
mounted() {
this.init();
},
};
</script>
<style lang="scss" scoped>
.role-list {
height: 500px;
overflow-y: auto;
display: flex;
flex-wrap: wrap;
}
.role-item {
width: 50%;
display: flex;
padding: 20px 0;
align-items: center;
> .title {
flex: 2;
text-align: right;
}
> .content {
flex: 10;
}
}
.btns {
display: flex;
align-items: center;
justify-content: center;
}
.btn-item {
margin-right: 20px;
}
.permModal {
.ivu-modal-body {
max-height: 560px;
overflow: auto;
}
}
.depModal {
.ivu-modal-body {
max-height: 500px;
overflow: auto;
}
}
.tips {
font-size: 12px;
color: #999;
margin-left: 8px;
}
.title {
font-weight: bold;
margin-right: 20px;
}
</style>