修复BUG: 系统配置中,radio保存的值错误
parent
7f503e27b7
commit
e61e0c152a
|
@ -6,9 +6,11 @@
|
||||||
@Remark: 部门管理
|
@Remark: 部门管理
|
||||||
"""
|
"""
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from rest_framework.decorators import action
|
||||||
|
|
||||||
from dvadmin.system.models import Dept
|
from dvadmin.system.models import Dept
|
||||||
from dvadmin.utils.json_response import DetailResponse, SuccessResponse
|
from dvadmin.utils.json_response import DetailResponse, SuccessResponse
|
||||||
|
from dvadmin.utils.permission import AnonymousUserPermission
|
||||||
from dvadmin.utils.serializers import CustomModelSerializer
|
from dvadmin.utils.serializers import CustomModelSerializer
|
||||||
from dvadmin.utils.viewset import CustomModelViewSet
|
from dvadmin.utils.viewset import CustomModelViewSet
|
||||||
|
|
||||||
|
@ -18,18 +20,17 @@ class DeptSerializer(CustomModelSerializer):
|
||||||
部门-序列化器
|
部门-序列化器
|
||||||
"""
|
"""
|
||||||
parent_name = serializers.CharField(read_only=True, source='parent.name')
|
parent_name = serializers.CharField(read_only=True, source='parent.name')
|
||||||
has_children = serializers.SerializerMethodField()
|
|
||||||
status_label = serializers.SerializerMethodField()
|
status_label = serializers.SerializerMethodField()
|
||||||
|
has_children = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
def get_status_label(self, obj: Dept):
|
||||||
|
if obj.status:
|
||||||
|
return "启用"
|
||||||
|
return "禁用"
|
||||||
|
|
||||||
def get_has_children(self, obj: Dept):
|
def get_has_children(self, obj: Dept):
|
||||||
return Dept.objects.filter(parent_id=obj.id).count()
|
return Dept.objects.filter(parent_id=obj.id).count()
|
||||||
|
|
||||||
def get_status_label(self, instance):
|
|
||||||
status = instance.status
|
|
||||||
if status:
|
|
||||||
return "启用"
|
|
||||||
return "禁用"
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Dept
|
model = Dept
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
@ -59,7 +60,7 @@ class DeptInitSerializer(CustomModelSerializer):
|
||||||
filter_data = {
|
filter_data = {
|
||||||
"name": menu_data['name'],
|
"name": menu_data['name'],
|
||||||
"parent": menu_data['parent'],
|
"parent": menu_data['parent'],
|
||||||
"key":menu_data['key']
|
"key": menu_data['key']
|
||||||
}
|
}
|
||||||
instance_obj = Dept.objects.filter(**filter_data).first()
|
instance_obj = Dept.objects.filter(**filter_data).first()
|
||||||
if instance_obj and not self.initial_data.get('reset'):
|
if instance_obj and not self.initial_data.get('reset'):
|
||||||
|
@ -73,7 +74,7 @@ class DeptInitSerializer(CustomModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Dept
|
model = Dept
|
||||||
fields = ['name', 'sort', 'owner', 'phone', 'email', 'status', 'parent', 'creator', 'dept_belong_id',
|
fields = ['name', 'sort', 'owner', 'phone', 'email', 'status', 'parent', 'creator', 'dept_belong_id',
|
||||||
'children','key']
|
'children', 'key']
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
'creator': {'write_only': True},
|
'creator': {'write_only': True},
|
||||||
'dept_belong_id': {'write_only': True}
|
'dept_belong_id': {'write_only': True}
|
||||||
|
@ -123,7 +124,13 @@ class DeptViewSet(CustomModelViewSet):
|
||||||
if lazy:
|
if lazy:
|
||||||
# 如果懒加载模式,返回全部
|
# 如果懒加载模式,返回全部
|
||||||
if not parent:
|
if not parent:
|
||||||
if self.request.user.is_superuser:
|
role_list = request.user.role.filter(status=1).values("admin", "data_range")
|
||||||
|
is_admin = False
|
||||||
|
for ele in role_list:
|
||||||
|
if 3 == ele.get("data_range") or ele.get("admin") == True:
|
||||||
|
is_admin = True
|
||||||
|
break
|
||||||
|
if self.request.user.is_superuser or is_admin:
|
||||||
queryset = queryset.filter(parent__isnull=True)
|
queryset = queryset.filter(parent__isnull=True)
|
||||||
else:
|
else:
|
||||||
queryset = queryset.filter(id=self.request.user.dept_id)
|
queryset = queryset.filter(id=self.request.user.dept_id)
|
||||||
|
@ -147,3 +154,10 @@ class DeptViewSet(CustomModelViewSet):
|
||||||
queryset = queryset.filter(id=self.request.user.dept_id)
|
queryset = queryset.filter(id=self.request.user.dept_id)
|
||||||
data = queryset.filter(status=True).order_by('sort').values('name', 'id', 'parent')
|
data = queryset.filter(status=True).order_by('sort').values('name', 'id', 'parent')
|
||||||
return DetailResponse(data=data, msg="获取成功")
|
return DetailResponse(data=data, msg="获取成功")
|
||||||
|
|
||||||
|
@action(methods=["GET"], detail=False, permission_classes=[AnonymousUserPermission])
|
||||||
|
def all_dept(self, request, *args, **kwargs):
|
||||||
|
self.extra_filter_backends = []
|
||||||
|
queryset = self.filter_queryset(self.get_queryset())
|
||||||
|
data = queryset.filter(status=True).order_by('sort').values('name', 'id', 'parent')
|
||||||
|
return DetailResponse(data=data, msg="获取成功")
|
||||||
|
|
|
@ -3,7 +3,7 @@ import hashlib
|
||||||
from django.contrib.auth.hashers import make_password
|
from django.contrib.auth.hashers import make_password
|
||||||
from django_restql.fields import DynamicSerializerMethodField
|
from django_restql.fields import DynamicSerializerMethodField
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action, permission_classes
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
|
||||||
from application import dispatch
|
from application import dispatch
|
||||||
|
@ -21,6 +21,7 @@ class UserSerializer(CustomModelSerializer):
|
||||||
"""
|
"""
|
||||||
dept_name = serializers.CharField(source='dept.name', read_only=True)
|
dept_name = serializers.CharField(source='dept.name', read_only=True)
|
||||||
role_info = DynamicSerializerMethodField()
|
role_info = DynamicSerializerMethodField()
|
||||||
|
factory_name = serializers.CharField(source='factory_info.name', read_only=True, help_text="工厂名称")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Users
|
model = Users
|
||||||
|
@ -46,16 +47,6 @@ class UsersInitSerializer(CustomModelSerializer):
|
||||||
"""
|
"""
|
||||||
初始化获取数信息(用于生成初始化json文件)
|
初始化获取数信息(用于生成初始化json文件)
|
||||||
"""
|
"""
|
||||||
def save(self, **kwargs):
|
|
||||||
instance = super().save(**kwargs)
|
|
||||||
role_key = self.initial_data.get('role_key',[])
|
|
||||||
role_ids = Role.objects.filter(key__in=role_key).values_list('id',flat=True)
|
|
||||||
instance.role.set(role_ids)
|
|
||||||
dept_key = self.initial_data.get('dept_key',None)
|
|
||||||
dept_id = Dept.objects.filter(key=dept_key).first()
|
|
||||||
instance.dept = dept_id
|
|
||||||
instance.save()
|
|
||||||
return instance
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Users
|
model = Users
|
||||||
|
@ -223,17 +214,17 @@ class UserViewSet(CustomModelViewSet):
|
||||||
}
|
}
|
||||||
search_fields = ["username", "name", "gender", "dept__name", "role__name"]
|
search_fields = ["username", "name", "gender", "dept__name", "role__name"]
|
||||||
# 导出
|
# 导出
|
||||||
export_field_label = {
|
export_field_label = [
|
||||||
"username":"用户账号",
|
"用户账号",
|
||||||
"name":"用户名称",
|
"用户名称",
|
||||||
"email":"用户邮箱",
|
"用户邮箱",
|
||||||
"mobile":"手机号码",
|
"手机号码",
|
||||||
"gender":"用户性别",
|
"用户性别",
|
||||||
"is_active":"帐号状态",
|
"帐号状态",
|
||||||
"last_login":"最后登录时间",
|
"最后登录时间",
|
||||||
"dept_name":"部门名称",
|
"部门名称",
|
||||||
"dept_owner":"部门负责人",
|
"部门负责人",
|
||||||
}
|
]
|
||||||
export_serializer_class = ExportUserProfileSerializer
|
export_serializer_class = ExportUserProfileSerializer
|
||||||
# 导入
|
# 导入
|
||||||
import_serializer_class = UserProfileImportSerializer
|
import_serializer_class = UserProfileImportSerializer
|
||||||
|
@ -262,14 +253,31 @@ class UserViewSet(CustomModelViewSet):
|
||||||
@action(methods=["GET"], detail=False, permission_classes=[IsAuthenticated])
|
@action(methods=["GET"], detail=False, permission_classes=[IsAuthenticated])
|
||||||
def user_info(self, request):
|
def user_info(self, request):
|
||||||
"""获取当前用户信息"""
|
"""获取当前用户信息"""
|
||||||
user = request.user
|
user = self.request.user
|
||||||
result = {
|
result = {
|
||||||
|
"id": user.id,
|
||||||
"name": user.name,
|
"name": user.name,
|
||||||
"mobile": user.mobile,
|
"mobile": user.mobile,
|
||||||
|
"user_type": user.user_type,
|
||||||
"gender": user.gender,
|
"gender": user.gender,
|
||||||
"email": user.email,
|
"email": user.email,
|
||||||
"avatar": user.avatar,
|
"avatar": user.avatar,
|
||||||
|
"dept": user.dept.id,
|
||||||
|
"is_superuser": user.is_superuser,
|
||||||
|
"role": user.role.values_list('id', flat=True),
|
||||||
}
|
}
|
||||||
|
if user.user_type == 3:
|
||||||
|
result["distributor_info"] = user.distributor_info_user.all().values_list('name', flat=True)
|
||||||
|
dept = getattr(user, 'dept', None)
|
||||||
|
if dept:
|
||||||
|
result['dept_info'] = {
|
||||||
|
'dept_id': dept.id,
|
||||||
|
'dept_name': dept.name
|
||||||
|
}
|
||||||
|
role = getattr(user, 'role', None)
|
||||||
|
if role:
|
||||||
|
result['role_info'] = role.values('id', 'name', 'key')
|
||||||
|
|
||||||
return DetailResponse(data=result, msg="获取成功")
|
return DetailResponse(data=result, msg="获取成功")
|
||||||
|
|
||||||
@action(methods=["PUT"], detail=False, permission_classes=[IsAuthenticated])
|
@action(methods=["PUT"], detail=False, permission_classes=[IsAuthenticated])
|
||||||
|
@ -286,7 +294,7 @@ class UserViewSet(CustomModelViewSet):
|
||||||
old_pwd = data.get("oldPassword")
|
old_pwd = data.get("oldPassword")
|
||||||
new_pwd = data.get("newPassword")
|
new_pwd = data.get("newPassword")
|
||||||
new_pwd2 = data.get("newPassword2")
|
new_pwd2 = data.get("newPassword2")
|
||||||
if old_pwd or new_pwd or new_pwd2:
|
if old_pwd is None or new_pwd is None or new_pwd2 is None:
|
||||||
return ErrorResponse(msg="参数不能为空")
|
return ErrorResponse(msg="参数不能为空")
|
||||||
if new_pwd != new_pwd2:
|
if new_pwd != new_pwd2:
|
||||||
return ErrorResponse(msg="两次密码不匹配")
|
return ErrorResponse(msg="两次密码不匹配")
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
function install (Vue) {
|
||||||
|
Vue.component('dept-format', () => import('./lib/dept-format'))
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
install
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
{{$store.state.d2admin.dept.data[currentValue] || ''}}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
// 行展示组件进阶版
|
||||||
|
// 本示例演示要对传入的值做一些改变,然后再展示
|
||||||
|
export default {
|
||||||
|
name: 'dept-format',
|
||||||
|
props: {
|
||||||
|
// 接收row.xxx的值
|
||||||
|
value: {
|
||||||
|
type: Number || String,
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
require: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
currentValue: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
value (value) {
|
||||||
|
// this.$emit('change', value)
|
||||||
|
if (this.currentValue === value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.setValue(value)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
this.setValue(this.value)
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
setValue (value) {
|
||||||
|
// 在这里对 传入的value值做处理
|
||||||
|
this.currentValue = String(this.value)
|
||||||
|
// 根据值的key 递归获取对应的名称
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
Footer
|
|
@ -9,3 +9,4 @@ Vue.component('d2-icon-svg', () => import('./d2-icon-svg/index.vue'))
|
||||||
Vue.component('importExcel', () => import('./importExcel/index.vue'))
|
Vue.component('importExcel', () => import('./importExcel/index.vue'))
|
||||||
Vue.component('foreignKey', () => import('./foreign-key/index.vue'))
|
Vue.component('foreignKey', () => import('./foreign-key/index.vue'))
|
||||||
Vue.component('manyToMany', () => import('./many-to-many/index.vue'))
|
Vue.component('manyToMany', () => import('./many-to-many/index.vue'))
|
||||||
|
Vue.component('dept-format', () => import('./dept-format/lib/dept-format.vue'))
|
||||||
|
|
|
@ -16,7 +16,6 @@ import { request } from '@/api/service'
|
||||||
import util from '@/libs/util'
|
import util from '@/libs/util'
|
||||||
import XEUtils from 'xe-utils'
|
import XEUtils from 'xe-utils'
|
||||||
import store from '@/store/index'
|
import store from '@/store/index'
|
||||||
import { urlPrefix as deptPrefix } from '@/views/system/dept/api'
|
|
||||||
import types from '@/config/d2p-extends/types'
|
import types from '@/config/d2p-extends/types'
|
||||||
import { checkPlugins, plugins } from '@/views/plugins'
|
import { checkPlugins, plugins } from '@/views/plugins'
|
||||||
|
|
||||||
|
@ -243,7 +242,8 @@ Vue.prototype.commonEndColumns = function (param = {}) {
|
||||||
},
|
},
|
||||||
dept_belong_id: {
|
dept_belong_id: {
|
||||||
showForm: (param.dept_belong_id && param.dept_belong_id.showForm) !== undefined ? param.dept_belong_id.showForm : false,
|
showForm: (param.dept_belong_id && param.dept_belong_id.showForm) !== undefined ? param.dept_belong_id.showForm : false,
|
||||||
showTable: (param.dept_belong_id && param.dept_belong_id.showTable) !== undefined ? param.dept_belong_id.showTable : false
|
showTable: (param.dept_belong_id && param.dept_belong_id.showTable) !== undefined ? param.dept_belong_id.showTable : false,
|
||||||
|
showSearch: (param.dept_belong_id && param.dept_belong_id.showSearch) !== undefined ? param.dept_belong_id.showSearch : false
|
||||||
},
|
},
|
||||||
modifier_name: {
|
modifier_name: {
|
||||||
showForm: (param.modifier_name && param.modifier_name.showForm) !== undefined ? param.modifier_name.showForm : false,
|
showForm: (param.modifier_name && param.modifier_name.showForm) !== undefined ? param.modifier_name.showForm : false,
|
||||||
|
@ -293,61 +293,41 @@ Vue.prototype.commonEndColumns = function (param = {}) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '数据归属部门',
|
title: '所属部门',
|
||||||
key: 'dept_belong_id',
|
key: 'dept_belong_id',
|
||||||
show: showData.dept_belong_id.showTable,
|
show: showData.dept_belong_id.showTable,
|
||||||
width: 150,
|
width: 150,
|
||||||
search: {
|
search: {
|
||||||
disabled: true
|
disabled: !showData.dept_belong_id.showSearch
|
||||||
},
|
},
|
||||||
type: 'table-selector',
|
type: 'tree-selector',
|
||||||
dict: {
|
dict: {
|
||||||
cache: true,
|
cache: false,
|
||||||
url: deptPrefix,
|
url: '/api/system/dept/all_dept/',
|
||||||
isTree: true,
|
// isTree: true,
|
||||||
|
// dept: true,
|
||||||
value: 'id', // 数据字典中value字段的属性名
|
value: 'id', // 数据字典中value字段的属性名
|
||||||
label: 'name', // 数据字典中label字段的属性名
|
label: 'name', // 数据字典中label字段的属性名
|
||||||
children: 'children', // 数据字典中children字段的属性名
|
children: 'children' // 数据字典中children字段的属性名
|
||||||
getData: (url, dict, {
|
// getData: (url, dict, {
|
||||||
_,
|
// _,
|
||||||
component
|
// component
|
||||||
}) => {
|
// }) => {
|
||||||
return request({
|
// return request({
|
||||||
url: url,
|
// url: url
|
||||||
params: { limit: 999, status: 1 }
|
// }).then(ret => {
|
||||||
}).then(ret => {
|
// return XEUtils.toArrayTree(ret.data, { parentKey: 'parent', strict: false })
|
||||||
return ret.data.data
|
// })
|
||||||
})
|
// }
|
||||||
}
|
},
|
||||||
|
component: {
|
||||||
|
name: 'dept-format',
|
||||||
|
props: { multiple: false, clearable: true }
|
||||||
},
|
},
|
||||||
form: {
|
form: {
|
||||||
disabled: !showData.dept_belong_id.showForm,
|
disabled: !showData.dept_belong_id.showForm,
|
||||||
component: {
|
component: {
|
||||||
props: {
|
props: { multiple: false, clearable: true }
|
||||||
elProps: {
|
|
||||||
treeConfig: {
|
|
||||||
transform: true,
|
|
||||||
rowField: 'id',
|
|
||||||
parentField: 'parent',
|
|
||||||
expandAll: true
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
field: 'name',
|
|
||||||
title: '部门名称',
|
|
||||||
treeNode: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'status',
|
|
||||||
title: '状态'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'parent_name',
|
|
||||||
title: '父级部门'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
helper: {
|
helper: {
|
||||||
render (h) {
|
render (h) {
|
||||||
|
@ -355,6 +335,12 @@ Vue.prototype.commonEndColumns = function (param = {}) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// 接收时,处理数据
|
||||||
|
valueBuilder (row, col) {
|
||||||
|
if (row[col.key]) {
|
||||||
|
row[col.key] = Number(row[col.key])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -1 +1,9 @@
|
||||||
module.exports = file => () => import('@great-dream/' + file)
|
module.exports = file => {
|
||||||
|
var result
|
||||||
|
try {
|
||||||
|
result = require('@great-dream/' + file).default
|
||||||
|
} catch (error) {
|
||||||
|
result = require('@/views/plugins/' + file).default
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
|
@ -79,4 +79,30 @@ util.randomString = function (e) {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util.ArrayToTree = function (rootList, parentValue, parentName, list) {
|
||||||
|
for (const item of rootList) {
|
||||||
|
if (item.parent === parentValue) {
|
||||||
|
if (parentName) {
|
||||||
|
item.name = parentName + '/' + item.name
|
||||||
|
}
|
||||||
|
list.push(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const i of list) {
|
||||||
|
// 如果子元素里面存在children就直接递归,不存在就生成一个children
|
||||||
|
if (i.children) {
|
||||||
|
util.ArrayToTree(rootList, i.id, i.name, i.children)
|
||||||
|
} else {
|
||||||
|
i.children = []
|
||||||
|
util.ArrayToTree(rootList, i.id, i.name, i.children)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i.children.length === 0) {
|
||||||
|
delete i.children
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
export default util
|
export default util
|
||||||
|
|
|
@ -17,6 +17,7 @@ import util from '@/libs/util.js'
|
||||||
// 路由数据
|
// 路由数据
|
||||||
import routes from './routes'
|
import routes from './routes'
|
||||||
import { getMenu, handleAsideMenu, handleRouter, checkRouter } from '@/menu'
|
import { getMenu, handleAsideMenu, handleRouter, checkRouter } from '@/menu'
|
||||||
|
import { request } from '@/api/service'
|
||||||
|
|
||||||
// fix vue-router NavigationDuplicated
|
// fix vue-router NavigationDuplicated
|
||||||
const VueRouterPush = VueRouter.prototype.push
|
const VueRouterPush = VueRouter.prototype.push
|
||||||
|
@ -55,6 +56,24 @@ router.beforeEach(async (to, from, next) => {
|
||||||
// 请根据自身业务需要修改
|
// 请根据自身业务需要修改
|
||||||
const token = util.cookies.get('token')
|
const token = util.cookies.get('token')
|
||||||
if (token && token !== 'undefined') {
|
if (token && token !== 'undefined') {
|
||||||
|
if (!store.state.d2admin.user.info.name) {
|
||||||
|
var res = await request({
|
||||||
|
url: '/api/system/user/user_info/',
|
||||||
|
method: 'get',
|
||||||
|
params: {}
|
||||||
|
})
|
||||||
|
await store.dispatch('d2admin/user/set', {
|
||||||
|
name: res.data.name,
|
||||||
|
user_id: res.data.id,
|
||||||
|
avatar: res.data.avatar,
|
||||||
|
role_info: res.data.role_info,
|
||||||
|
dept_info: res.data.dept_info,
|
||||||
|
is_superuser: res.data.is_superuser
|
||||||
|
}, { root: true })
|
||||||
|
await store.dispatch('d2admin/account/load')
|
||||||
|
store.dispatch('d2admin/dept/load')
|
||||||
|
store.dispatch('d2admin/settings/init')
|
||||||
|
}
|
||||||
if (!store.state.d2admin.menu || store.state.d2admin.menu.aside.length === 0) {
|
if (!store.state.d2admin.menu || store.state.d2admin.menu.aside.length === 0) {
|
||||||
// 动态添加路由
|
// 动态添加路由
|
||||||
getMenu().then(ret => {
|
getMenu().then(ret => {
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
import { request } from '@/api/service'
|
||||||
|
import util from '@/libs/util'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
namespaced: true,
|
||||||
|
state: {
|
||||||
|
// 用户信息
|
||||||
|
data: undefined
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
/**
|
||||||
|
* @description 初始化部门数据
|
||||||
|
* @param {Object} context
|
||||||
|
* @param {*} info info
|
||||||
|
*/
|
||||||
|
async getDeptName ({ state, dispatch }, { data }) {
|
||||||
|
const nameDict = {}
|
||||||
|
for (const items of data) {
|
||||||
|
if (items.children) {
|
||||||
|
const filterData = await dispatch('getDeptName', { data: items.children })
|
||||||
|
for (var key in filterData) {
|
||||||
|
nameDict[key] = filterData[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nameDict[items.id] = items.name
|
||||||
|
}
|
||||||
|
return nameDict
|
||||||
|
},
|
||||||
|
async load ({ state, dispatch }, info) {
|
||||||
|
// 持久化
|
||||||
|
const ret = await request({
|
||||||
|
url: '/api/system/dept/all_dept/'
|
||||||
|
})
|
||||||
|
const data = util.ArrayToTree(ret.data.data || ret.data, null, null, [])
|
||||||
|
state.data = await dispatch('getDeptName', { data: data })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,12 +14,12 @@ export default {
|
||||||
// store 赋值
|
// store 赋值
|
||||||
state.info = info
|
state.info = info
|
||||||
// 持久化
|
// 持久化
|
||||||
await dispatch('d2admin/db/set', {
|
// await dispatch('d2admin/db/set', {
|
||||||
dbName: 'sys',
|
// dbName: 'sys',
|
||||||
path: 'user.info',
|
// path: 'user.info',
|
||||||
value: info,
|
// value: info,
|
||||||
user: true
|
// user: true
|
||||||
}, { root: true })
|
// }, { root: true })
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @description 从数据库取用户数据
|
* @description 从数据库取用户数据
|
||||||
|
@ -27,12 +27,12 @@ export default {
|
||||||
*/
|
*/
|
||||||
async load ({ state, dispatch }) {
|
async load ({ state, dispatch }) {
|
||||||
// store 赋值
|
// store 赋值
|
||||||
state.info = await dispatch('d2admin/db/get', {
|
// state.info = await dispatch('d2admin/db/get', {
|
||||||
dbName: 'sys',
|
// dbName: 'sys',
|
||||||
path: 'user.info',
|
// path: 'user.info',
|
||||||
defaultValue: {},
|
// defaultValue: {},
|
||||||
user: true
|
// user: true
|
||||||
}, { root: true })
|
// }, { root: true })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,13 +49,17 @@ export default {
|
||||||
},
|
},
|
||||||
addRequest (row) {
|
addRequest (row) {
|
||||||
d2CrudPlus.util.dict.clear()
|
d2CrudPlus.util.dict.clear()
|
||||||
|
this.$store.dispatch('d2admin/dept/load')
|
||||||
return api.createObj(row)
|
return api.createObj(row)
|
||||||
},
|
},
|
||||||
updateRequest (row) {
|
updateRequest (row) {
|
||||||
d2CrudPlus.util.dict.clear()
|
d2CrudPlus.util.dict.clear()
|
||||||
|
this.$store.dispatch('d2admin/dept/load')
|
||||||
return api.UpdateObj(row)
|
return api.UpdateObj(row)
|
||||||
},
|
},
|
||||||
delRequest (row) {
|
delRequest (row) {
|
||||||
|
d2CrudPlus.util.dict.clear()
|
||||||
|
this.$store.dispatch('d2admin/dept/load')
|
||||||
return api.DelObj(row.id)
|
return api.DelObj(row.id)
|
||||||
},
|
},
|
||||||
// 授权
|
// 授权
|
||||||
|
|
Loading…
Reference in New Issue