master
xy 3 years ago
parent 83168f823f
commit cdf984c4a8

@ -0,0 +1,34 @@
import request from "@/utils/request";
export function getList(params,isLoading=true){
return request({
method:'get',
url:'/api/admin/admin-area/get-list',
params,
isLoading
})
}
export function getForm(id,params){
return request({
method:'get',
url:`/api/admin/admin-area/get-form/${id}`,
params
})
}
export function save(data){
return request({
method:'post',
url:'/api/admin/admin-area/save',
data
})
}
export function destroy(id,data){
return request({
method:'post',
url:`/api/admin/admin-area/delete/${id}`,
data
})
}

@ -0,0 +1,34 @@
import request from "@/utils/request";
export function getList(params,isLoading=true){
return request({
method:'get',
url:'/api/admin/admin-product-type/get-list',
params,
isLoading
})
}
export function getForm(id,params){
return request({
method:'get',
url:`/api/admin/admin-product-type/get-form/${id}`,
params
})
}
export function save(data){
return request({
method:'post',
url:'/api/admin/admin-product-type/save',
data
})
}
export function destroy(id,data){
return request({
method:'post',
url:`/api/admin/admin-product-type/delete/${id}`,
data
})
}

@ -36,6 +36,9 @@ router.beforeEach(async(to, from, next) => {
// note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
const { roles } = await store.dispatch('user/getInfo')
await store.dispatch('user/getType')
await store.dispatch('user/getArea')
// generate accessible routes map based on roles
const accessRoutes = await store.dispatch('permission/generateRoutes', roles)

@ -8,6 +8,8 @@ import {
setToken,
removeToken
} from '@/utils/auth'
import { getList as areaList } from "@/api/system/adminArea"
import { getList as typeList } from "@/api/system/adminProductType"
import {
resetRouter
} from '@/router'
@ -16,8 +18,11 @@ const getDefaultState = () => {
return {
token: getToken(),
name: '',
user_id:'',
avatar: '',
roles: []
roles: [],
typeAuth: [],
areaAuth: []
}
}
@ -38,6 +43,15 @@ const mutations = {
},
SET_ROLES: (state, roles) => {
state.roles = roles
},
SET_TYPEAUTH:(state,arr) => {
state.typeAuth = arr
},
SET_AREAAUTH:(state,arr) => {
state.areaAuth = arr
},
SET_USERID:(state,id) => {
state.user_id = id
}
}
@ -84,14 +98,14 @@ const actions = {
const {
roles,
name,
avatar
avatar,
id
} = response
commit('SET_ROLES', roles)
commit('SET_NAME', name)
commit('SET_AVATAR', avatar)
commit('SET_USERID',id)
resolve(response)
}).catch(error => {
reject(error)
@ -125,6 +139,34 @@ const actions = {
commit('RESET_STATE')
resolve()
})
},
//获取用户板块权限
getType({commit,state}){
return new Promise((resolve,reject) => {
typeList({
admin_id:state.user_id
}).then(res => {
commit('SET_TYPEAUTH',res)
resolve(res)
}).catch(err => {
reject(err)
})
})
},
//获取用户地区权限
getArea({commit,state}){
return new Promise((resolve,reject) => {
areaList({
admin_id:state.user_id
}).then(res => {
commit('SET_AREAAUTH',res)
resolve(res)
}).catch(err => {
reject(err)
})
})
}
}
@ -133,4 +175,4 @@ export default {
state,
mutations,
actions
}
}

@ -13,3 +13,11 @@ export function setToken(token) {
export function removeToken() {
return Cookies.remove(TokenKey)
}
export function getAuthAreas(_this){
return _this.$store.state.user.areaAuth.map(item => item.area_detail)
}
export function getAuthTypes(_this){
return _this.$store.state.user.typeAuth.map(item => item.product_type)
}

@ -201,23 +201,6 @@
</div>
</template>
<template v-slot:product_type_id>
<div class="xy-table-item">
<div class="xy-table-item-label">
<span style="color: red;font-weight: 600;padding-right: 4px;">*</span>业务板块
</div>
<div class="xy-table-item-content">
<el-select
disabled
v-model="form1.product_type_id"
placeholder="请选择业务板块"
style="width: 300px">
<el-option v-for="item in types" :key="item.id" :label="item.name" :value="item.id"></el-option>
</el-select>
</div>
</div>
</template>
<template v-slot:date>
<div class="xy-table-item">
<div class="xy-table-item-label">
@ -254,20 +237,20 @@
</div>
</template>
<template v-slot:status>
<div class="xy-table-item">
<div class="xy-table-item-label">
<span style="color: red;font-weight: 600;padding-right: 4px;">*</span>状态
</div>
<div class="xy-table-item-content">
<div style="width: 300px;display: flex;">
<el-radio v-model="form1.status" :label="0"></el-radio>
<el-radio v-model="form1.status" :label="1"></el-radio>
<el-radio v-model="form1.status" :label="2"></el-radio>
</div>
</div>
</div>
</template>
<!-- <template v-slot:status>-->
<!-- <div class="xy-table-item">-->
<!-- <div class="xy-table-item-label">-->
<!-- <span style="color: red;font-weight: 600;padding-right: 4px;">*</span>状态-->
<!-- </div>-->
<!-- <div class="xy-table-item-content">-->
<!-- <div style="width: 300px;display: flex;">-->
<!-- <el-radio v-model="form1.status" :label="0"></el-radio>-->
<!-- <el-radio v-model="form1.status" :label="1"></el-radio>-->
<!-- <el-radio v-model="form1.status" :label="2"></el-radio>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!-- </template>-->
<template v-slot:extraFormBottom>
<div style="font-weight: 600;padding: 10px;">日志</div>

@ -141,6 +141,7 @@ import { getparameter } from "@/api/system/dictionary";
import { getList as getUnit } from "@/api/payUnit";
import { getList as getTypes } from "@/api/productType";
import { deepCopy } from "@/utils";
import {getAuthAreas, getAuthTypes} from "@/utils/auth"
import addCustomer from "@/views/customer/component/addCustomer";
import addOrder from "./component/addOrder";
@ -367,17 +368,12 @@ export default {
},
async getTypes() {
const res = await getTypes(
{
page: 1,
page_size: 9999,
},
false
);
this.types = res.data;
this.types = getAuthTypes(this);
this.select.product_type_id = this.types.map(item => item.id)
},
async getCity() {
let authAreaIds = getAuthAreas(this).map(item => item.id)
let city = await getparameter(
{
number: "city",
@ -391,7 +387,13 @@ export default {
},
false
);
city.detail[i].children = area.detail;
let resArea = []
area?.detail.forEach(item => {
if(authAreaIds.indexOf(item.id) !== -1){
resArea.push(item)
}
})
city.detail[i].children = resArea
for (let j = 0; j < area.detail.length; j++) {
let street = await getparameter(

@ -70,6 +70,7 @@ import { AMapManager,lazyAMapApiLoaderInstance } from 'vue-amap'
import { getList } from '@/api/customer'
import {getList as getTypes} from "@/api/productType";
import {deepCopy} from "@/utils";
import { getAuthAreas } from "@/utils/auth";
const amapManager = new AMapManager()
export default {
@ -112,6 +113,7 @@ export default {
},
async getAreas(){
let authAreaIds = getAuthAreas(this).map(item => item.id)
let city = await getparameter({
number: 'city'
}, false)
@ -119,7 +121,14 @@ export default {
let area = await getparameter({
pid: city.detail[i].id
}, false)
city.detail[i].children = area.detail
let resArea = []
area?.detail.forEach(item => {
if(authAreaIds.indexOf(item.id) !== -1){
resArea.push(item)
}
})
city.detail[i].children = resArea
}
this.areas = city.detail

@ -93,6 +93,7 @@ import {getList as nurseIndex} from '@/api/worker'
import {getparameter} from '@/api/system/dictionary'
import {getList as typeIndex} from '@/api/productType'
import {destroy} from '@/api/order'
import { getAuthAreas,getAuthTypes } from "@/utils/auth"
import addSchedule from "@/views/schedule/component/addSchedule";
@ -182,13 +183,13 @@ export default {
},
methods: {
async getAreas(){
const res = await getparameter({number : 'changzhou'},false)
this.areas = res.detail
this.areas = getAuthAreas(this)
this.select.area_id = this.areas[0]?.id
},
async getTypes(){
const res = await typeIndex({page_size:9999,page:1},false)
this.types = res.data
this.types = getAuthTypes(this)
this.select.product_type_id = this.types[0]?.id
},
async getProducts(){

@ -108,6 +108,7 @@ import {parseTime} from '@/utils'
import {scheduleHome} from '@/api/schedule'
import {getList as typeList} from '@/api/productType'
import {getparameter} from '@/api/system/dictionary'
import { getAuthAreas,getAuthTypes } from "@/utils/auth"
export default {
data() {
@ -164,14 +165,12 @@ export default {
},
async getTypes(){
const res = await typeList({page:1,page_size:999},false)
this.types = res.data
this.select.product_type_id = res.data[0].id
this.types = getAuthTypes(this)
this.select.product_type_id = this.types[0].id
},
async getAreas(){
const res = await getparameter({number:'serveArea'})
this.areas = res.detail
this.select.area_id = res.detail[0].id
this.areas = getAuthAreas(this)
this.select.area_id = this.areas[0].id
}
},
computed: {

@ -0,0 +1,303 @@
<template>
<div class="container">
<!-- 查询配置 -->
<div>
<div ref="lxHeader">
<LxHeader icon="md-apps" text="数据权限" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
<div slot="content"></div>
<slot>
</slot>
</LxHeader>
</div>
<el-row :gutter="20">
<el-col :span="3">
<Card class="box-card">
<div slot="title" class="clearfix" style="height: 32px;line-height: 32px;">
<span>用户列表</span>
</div>
<div style="overflow: auto;" :style="{height:height+'px'}">
<el-scrollbar style="flex: 1">
<el-tabs tab-position="left" v-model="activeUser" @tab-click="getAdminAreas(),getAdminTypes()">
<el-tab-pane v-for="item in users" :label="item.name" :name="String(item.id)"></el-tab-pane>
</el-tabs>
</el-scrollbar>
</div>
</Card>
</el-col>
<el-col :span="21">
<Card class="box-card">
<div slot="title" class="clearfix" style="height: 32px;line-height: 32px;">
<span>权限列表</span>
<Button style="float: right;" type="primary" @click="submit"></Button>
</div>
<div style="overflow: auto;" :style="{height:height+'px'}">
<el-scrollbar style="flex: 1">
<div>
<h4 style="padding: 10px 0;">板块权限</h4>
<el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAll"></el-checkbox>
<el-checkbox-group style="margin: 10px 0 0 10px;" v-model="checkedTypes" @change="handleChecked">
<el-checkbox v-for="item in productTypes" :label="item.id" :key="item.id">{{ item.name }}</el-checkbox>
</el-checkbox-group>
</div>
<div>
<h4 style="padding: 16px 0;">区域权限</h4>
<el-tree
ref="elTree"
node-key="id"
default-expand-all
:data="cities"
:props="{label:'value',children:'children'}"
show-checkbox>
</el-tree>
</div>
</el-scrollbar>
</div>
</Card>
</el-col>
</el-row>
</div>
</div>
</template>
<script>
import { listuser } from "@/api/system/user"
import { getList as getProductTypes } from "@/api/productType"
import { getparameter } from "@/api/system/dictionary"
import { getList as getAdminType,save as saveType,destroy as destroyType } from "@/api/system/adminProductType"
import { getList as getAdminArea,save as saveArea,destroy as destroyArea } from "@/api/system/adminArea"
import LxHeader from "@/components/LxHeader/index.vue";
export default {
components: {
LxHeader
},
mounted() {
},
data() {
return {
height: 0,
users:[],
productTypes:[],
cities:[],
activeUser:'',
checkAll: false,
checkedTypes:[],
isIndeterminate: true,
originalArea:[],
originalType:[],
}
},
methods: {
async getAdminTypes(){
const res = await getAdminType({
admin_id:Number(this.activeUser)
})
console.log('type',res)
this.originalType = res
this.checkedTypes = res.map(item => item.product_type_id)
},
async getAdminAreas(){
const res = await getAdminArea({
admin_id:Number(this.activeUser)
})
console.log('area',res)
this.originalArea = res
this.$refs['elTree'].setCheckedKeys(res.map(item => item.area_id))
},
handleCheckAll(val) {
this.checkedTypes = val ? this.productTypes.map(item => item.id) : [];
this.isIndeterminate = false;
},
handleChecked(value) {
let checkedCount = value.length;
this.checkAll = checkedCount === this.productTypes.length;
this.isIndeterminate = checkedCount > 0 && checkedCount < this.productTypes.length;
},
initLoad() {
var that = this;
var clientHeight = document.documentElement.clientHeight
var lxHeader_height = 67; //
var card_Height = 109; //
var topHeight = 50; //
let height = clientHeight - lxHeader_height - topHeight - card_Height;
that.height = height;
},
async getUsers(){
const res = await listuser()
this.users = res.data
this.activeUser = String(this.users[0].id)
await this.getAdminTypes()
await this.getAdminAreas()
},
async getProductTypes(){
const res = await getProductTypes({
page:1,
page_size:999
})
this.productTypes = res.data
},
async getCity() {
let city = await getparameter(
{
number: "city",
},
false
);
for (let i = 0; i < city.detail.length; i++) {
let area = await getparameter(
{
pid: city.detail[i].id,
},
false
);
city.detail[i].children = area.detail;
}
this.cities = city.detail;
},
getArrDifference(arr1, arr2){
return arr1.concat(arr2).filter((v, i, arr) => {
return arr.indexOf(v) === arr.lastIndexOf(v);
})
},
submit(){
let areaIds = this.$refs['elTree'].getCheckedNodes().map(item => item.id)
let oriAreaIds = this.originalArea.map(item => item.area_id)
let areaPromiseAll = [];
let areaDifArr = this.getArrDifference(areaIds,oriAreaIds)
areaDifArr.forEach(item => {
if(oriAreaIds.indexOf(item) === -1){
areaPromiseAll.push(saveArea({
area_id:item,
admin_id:Number(this.activeUser)
}))
}
if(areaIds.indexOf(item) === -1){
areaPromiseAll.push(destroyArea(this.originalArea[oriAreaIds.indexOf(item)]?.id))
}
})
let oriTypeIds = this.originalType.map(item => item.product_type_id)
let typePromiseAll = [];
let typeDifArr = this.getArrDifference(oriTypeIds,this.checkedTypes)
typeDifArr.forEach(item => {
if(oriTypeIds.indexOf(item) === -1){
typePromiseAll.push(saveType({
product_type_id:item,
admin_id:Number(this.activeUser)
}))
}
if(this.checkedTypes.indexOf(item) === -1){
typePromiseAll.push(destroyType(this.originalType[oriTypeIds.indexOf(item)]?.id))
}
})
Promise.all([...areaPromiseAll,...typePromiseAll]).then(res => {
this.getAdminTypes()
this.getAdminAreas()
this.$message({
type:'success',
message:'保存成功'
})
})
}
},
created(){
this.initLoad()
this.getCity()
this.getUsers()
this.getProductTypes()
},
};
</script>
<style lang="less" scoped>
.t-tree {
position: absolute;
width: 100%;
height: 100%;
display: flex;
padding: 12px;
background: #eee;
/* padding: 100px; */
}
.header {
background: #f9f8f8;
line-height: 40px;
border-bottom: 1px solid #eee;
position: relative;
font-size: 15px;
padding: 0 15px;
button {
position: absolute;
right: 15px;
top: 4px;
}
}
.action-container {
border-radius: 4px;
flex: 1;
margin-left: 15px;
background: white;
border-bottom: 1px solid #eee;
display: flex;
flex-direction: column;
}
.role-list {
width: 200px;
border: 1px solid #eee;
border-bottom: 0;
}
.actived {
color: #409efe !important;
background-color: #f3f7f9;
}
</style>
<style scoped>
.roleitem {
margin-bottom: 5px;
}
.action-group {
width: 100%;
display: flex;
}
.action-text {
font-size: 14px;
margin-right: 10px;
}
.action-item {
flex: 1;
}
.action-item>label {
width: 55px;
margin-left: 3px;
}
.action-container>>>.el-tree-node {
padding: 5px 0;
}
.action-container>>>.el-checkbox__label {
padding-left: 5px;
}
</style>

@ -67,9 +67,6 @@
export default {
components: {
LxHeader
},
created() {
},
mounted() {},
data() {

Loading…
Cancel
Save