新增:字典管理功能及获取初始化配置
parent
8faeed2ff7
commit
148a0dec3a
|
@ -31,6 +31,7 @@ from dvadmin.system.views.login import (
|
|||
LogoutView,
|
||||
)
|
||||
from dvadmin.system.views.system_config import InitSettingsViewSet
|
||||
from dvadmin.system.views.dictionary import InitDictionaryViewSet
|
||||
from dvadmin.utils.swagger import CustomOpenAPISchemaGenerator
|
||||
|
||||
schema_view = get_schema_view(
|
||||
|
@ -73,6 +74,7 @@ urlpatterns = (
|
|||
),
|
||||
path("api/captcha/", CaptchaView.as_view()),
|
||||
path("api/captcha/status/", CaptchaStatusView.as_view()),
|
||||
path("api/init/dictionary/", InitDictionaryViewSet.as_view()),
|
||||
path("api/init/settings/", InitSettingsViewSet.as_view()),
|
||||
path("apiLogin/", ApiLogin.as_view()),
|
||||
]
|
||||
|
|
|
@ -6,11 +6,13 @@
|
|||
@Created on: 2021/6/3 003 0:30
|
||||
@Remark: 字典管理
|
||||
"""
|
||||
from rest_framework import serializers
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from dvadmin.system.models import Dictionary
|
||||
from dvadmin.utils.json_response import SuccessResponse
|
||||
from dvadmin.utils.serializers import CustomModelSerializer
|
||||
from dvadmin.utils.viewset import CustomModelViewSet
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class DictionarySerializer(CustomModelSerializer):
|
||||
|
@ -67,7 +69,16 @@ class DictionaryViewSet(CustomModelViewSet):
|
|||
extra_filter_backends = []
|
||||
search_fields = ['label']
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
|
||||
class InitDictionaryViewSet(APIView):
|
||||
"""
|
||||
获取初始化配置
|
||||
"""
|
||||
authentication_classes = []
|
||||
permission_classes = []
|
||||
queryset = Dictionary.objects.all()
|
||||
|
||||
def get(self, request):
|
||||
dictionary_key = self.request.query_params.get('dictionary_key')
|
||||
if dictionary_key:
|
||||
if dictionary_key == 'all':
|
||||
|
@ -77,4 +88,4 @@ class DictionaryViewSet(CustomModelViewSet):
|
|||
else:
|
||||
data = self.queryset.filter(parent__value=dictionary_key, status=True).values('label', 'value', 'type')
|
||||
return SuccessResponse(data=data, msg="获取成功")
|
||||
return super().list(request, *args, **kwargs)
|
||||
return SuccessResponse(data=[], msg="获取成功")
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
import { request } from '@/api/service'
|
||||
import util from '@/libs/util'
|
||||
import XEUtils from 'xe-utils'
|
||||
import store from '@/store/index'
|
||||
import { urlPrefix as deptPrefix } from '@/views/system/dept/api'
|
||||
import types from '@/config/d2p-extends/types'
|
||||
const uploadUrl = util.baseURL() + 'api/system/file/'
|
||||
|
@ -183,7 +184,10 @@ d2CrudPlus.util.columnResolve.addTypes(types)
|
|||
// 修改官方字段类型
|
||||
const selectType = d2CrudPlus.util.columnResolve.getType('select')
|
||||
selectType.component.props.color = 'auto' // 修改官方的字段类型,设置为支持自动染色
|
||||
|
||||
// 获取字典配置
|
||||
Vue.prototype.dictionary = function (name) {
|
||||
return store.state.d2admin.dictionary.data[name]
|
||||
}
|
||||
// 默认Columns 结尾 showForm:显示在form中,showTable:显示在table中
|
||||
Vue.prototype.commonEndColumns = function (param = {}) {
|
||||
/**
|
||||
|
|
|
@ -42,6 +42,11 @@ new Vue({
|
|||
store,
|
||||
i18n,
|
||||
render: h => h(App),
|
||||
beforeCreate () {
|
||||
// 初始化配置
|
||||
this.$store.dispatch('d2admin/settings/load')
|
||||
this.$store.dispatch('d2admin/dictionary/load')
|
||||
},
|
||||
created () {
|
||||
|
||||
// 处理路由 得到每一级的路由设置
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { request } from '@/api/service'
|
||||
|
||||
export const urlPrefix = '/api/system/dictionary/'
|
||||
export const urlPrefix = '/api/init/dictionary/'
|
||||
|
||||
// 系统配置
|
||||
export default {
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
import { request } from '@/api/service'
|
||||
|
||||
export const urlPrefix = '/api/init/settings/'
|
||||
|
||||
// 系统配置
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
siteName: '', // 网站名称
|
||||
siteLogo: '', // 网站logo地址
|
||||
loginBackground: '', // 登录页背景图
|
||||
loginBanner: '', // 登录页Banner图
|
||||
copyright: '', // 版权
|
||||
keepRecord: '' // 备案
|
||||
},
|
||||
actions: {
|
||||
/**
|
||||
* @description 请求最新配置
|
||||
* @param {Object} context
|
||||
*/
|
||||
async init ({ state, dispatch, commit }) {
|
||||
// 请求配置
|
||||
request({
|
||||
url: urlPrefix,
|
||||
method: 'get'
|
||||
}).then(async res => {
|
||||
// 赋值
|
||||
await dispatch('d2admin/db/set', {
|
||||
dbName: 'sys',
|
||||
path: 'settings.init',
|
||||
value: res.data,
|
||||
user: true
|
||||
}, { root: true })
|
||||
dispatch('load')
|
||||
})
|
||||
},
|
||||
/**
|
||||
* @description 本地加载配置
|
||||
* @param {Object} context
|
||||
*/
|
||||
async load ({ state, dispatch, commit }) {
|
||||
const res = await dispatch('d2admin/db/get', {
|
||||
dbName: 'sys',
|
||||
path: 'settings.init',
|
||||
defaultValue: {},
|
||||
user: true
|
||||
}, { root: true })
|
||||
// store 赋值
|
||||
state.siteName = res.site_name
|
||||
state.siteLogo = res.site_logo
|
||||
state.loginBackground = res.login_background
|
||||
state.loginBanner = res.login_banner
|
||||
state.copyright = res.copyright
|
||||
state.keepRecord = res.keep_record
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
/**
|
||||
* @description 获取配置
|
||||
* @param {Object} state state
|
||||
* @param {String} key active
|
||||
* @param {Object} value active
|
||||
*/
|
||||
async get (state, key, value) {
|
||||
return state[key]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue