参数设置完成

pull/1/head
李强 2021-02-27 11:14:14 +08:00
parent 68c3e3fa92
commit a19c95bd42
13 changed files with 143 additions and 95 deletions

View File

@ -102,7 +102,7 @@ class DeptModelViewSet(CustomModelViewSet):
# update_extra_permission_classes = (IsManagerPermission,)
# destroy_extra_permission_classes = (IsManagerPermission,)
# create_extra_permission_classes = (IsManagerPermission,)
search_fields = ('name',)
search_fields = ('deptName',)
ordering = 'create_datetime' # 默认排序
def exclude_list(self, request: Request, *args, **kwargs):
@ -166,7 +166,7 @@ class PostModelViewSet(CustomModelViewSet):
# update_extra_permission_classes = (IsManagerPermission,)
# destroy_extra_permission_classes = (IsManagerPermission,)
# create_extra_permission_classes = (IsManagerPermission,)
search_fields = ('name',)
search_fields = ('postName',)
ordering = ['postSort', 'create_datetime'] # 默认排序
@ -182,5 +182,5 @@ class RoleModelViewSet(CustomModelViewSet):
# update_extra_permission_classes = (IsManagerPermission,)
# destroy_extra_permission_classes = (IsManagerPermission,)
# create_extra_permission_classes = (IsManagerPermission,)
search_fields = ('name',)
search_fields = ('roleName',)
ordering = 'create_datetime' # 默认排序

View File

@ -1,12 +1,13 @@
import django_filters
from apps.system.models import DictDetails, DictData
from apps.system.models import DictDetails, DictData, ConfigSettings
class DictDataFilter(django_filters.rest_framework.FilterSet):
"""
字典管理 简单过滤器
"""
class Meta:
model = DictData
fields = '__all__'
@ -17,6 +18,17 @@ class DictDetailsFilter(django_filters.rest_framework.FilterSet):
字典详情 简单过滤器
"""
dictType = django_filters.CharFilter(field_name='dict_data__dictType')
class Meta:
model = DictDetails
fields = '__all__'
class ConfigSettingsFilter(django_filters.rest_framework.FilterSet):
"""
参数设置 简单过滤器
"""
class Meta:
model = ConfigSettings
fields = '__all__'

View File

@ -4,13 +4,11 @@ from apps.op_drf.models import CoreModel
class ConfigSettings(CoreModel):
name = CharField(max_length=64, verbose_name="参数名称")
configName = CharField(max_length=64, verbose_name="参数名称")
configKey = CharField(max_length=256, verbose_name="参数键名")
configValue = CharField(max_length=256, verbose_name="参数键值")
configType = BooleanField(default=False,verbose_name="是否内置")
is_status = BooleanField(default=False, verbose_name="字典状态")
sort = CharField(max_length=256, verbose_name="字典排序")
dict_data = ForeignKey(to='DictData', on_delete=CASCADE, verbose_name="关联字典")
configType = CharField(max_length=8,verbose_name="是否内置")
status = CharField(max_length=8, verbose_name="参数状态")
remark = CharField(max_length=256, verbose_name="备注", null=True)
class Meta:
@ -18,4 +16,4 @@ class ConfigSettings(CoreModel):
verbose_name_plural = verbose_name
def __str__(self):
return f"{self.name}"
return f"{self.configName}"

View File

@ -4,7 +4,7 @@ from apps.op_drf.models import CoreModel
class DictData(CoreModel):
name = CharField(max_length=64, verbose_name="字典名称")
dictName = CharField(max_length=64, verbose_name="字典名称")
dictType = CharField(max_length=64, verbose_name="字典类型")
status = CharField(max_length=8, verbose_name="字典状态")
remark = CharField(max_length=256,verbose_name="备注", null=True)
@ -14,4 +14,4 @@ class DictData(CoreModel):
verbose_name_plural = verbose_name
def __str__(self):
return f"{self.name}"
return f"{self.dictName}"

View File

@ -1,14 +1,14 @@
from rest_framework import serializers
from apps.op_drf.serializers import CustomModelSerializer
from apps.system.models import DictData, DictDetails
from apps.system.models import DictData, DictDetails, ConfigSettings
# ================================================= #
# ************** 字典管理 序列化器 ************** #
# ================================================= #
class DictDataSerializer(serializers.ModelSerializer):
class DictDataSerializer(CustomModelSerializer):
"""
字典管理 简单序列化器
"""
@ -33,7 +33,7 @@ class DictDataCreateUpdateSerializer(CustomModelSerializer):
# ************** 字典详情 序列化器 ************** #
# ================================================= #
class DictDetailsSerializer(serializers.ModelSerializer):
class DictDetailsSerializer(CustomModelSerializer):
"""
字典详情 简单序列化器
"""
@ -43,7 +43,8 @@ class DictDetailsSerializer(serializers.ModelSerializer):
model = DictDetails
exclude = ('description', 'creator', 'modifier')
class DictDetailsListSerializer(serializers.ModelSerializer):
class DictDetailsListSerializer(CustomModelSerializer):
"""
字典详情List 简单序列化器
"""
@ -62,3 +63,29 @@ class DictDetailsCreateUpdateSerializer(CustomModelSerializer):
model = DictDetails
exclude = ('description', 'creator', 'modifier')
read_only_fields = ('update_datetime', 'create_datetime', 'creator', 'modifier')
# ================================================= #
# ************** 参数设置 序列化器 ************** #
# ================================================= #
class ConfigSettingsSerializer(CustomModelSerializer):
"""
字典详情 简单序列化器
"""
dictType = serializers.CharField(source='dict_data.dictType', default='', read_only=True)
class Meta:
model = ConfigSettings
exclude = ('description', 'creator', 'modifier')
class ConfigSettingsCreateUpdateSerializer(CustomModelSerializer):
"""
字典详情 创建/更新时的列化器
"""
class Meta:
model = ConfigSettings
exclude = ('description', 'creator', 'modifier')
read_only_fields = ('update_datetime', 'create_datetime', 'creator', 'modifier')

View File

@ -1,12 +1,14 @@
from django.urls import re_path
from rest_framework.routers import DefaultRouter
from apps.system.views import DictDataModelViewSet, DictDetailsModelViewSet, DictDetailsListModelViewSet
from apps.system.views import DictDataModelViewSet, DictDetailsModelViewSet, DictDetailsListModelViewSet, \
ConfigSettingsModelViewSet
router = DefaultRouter()
router.register(r'dict/type', DictDataModelViewSet)
router.register(r'dict/data', DictDetailsModelViewSet)
router.register(r'config', ConfigSettingsModelViewSet)
urlpatterns = [
re_path('dict/get/type/(?P<pk>.*)/', DictDetailsListModelViewSet.as_view({'get':'list'})),
re_path('dict/get/type/(?P<pk>.*)/', DictDetailsListModelViewSet.as_view({'get': 'list'})),
]
urlpatterns += router.urls

View File

@ -1,11 +1,11 @@
from rest_framework.request import Request
from apps.op_drf.viewsets import CustomModelViewSet
from apps.system.models import DictData
from apps.system.filters import DictDetailsFilter, DictDataFilter, ConfigSettingsFilter
from apps.system.models import DictData, DictDetails, ConfigSettings
from apps.system.serializers import DictDataSerializer, DictDataCreateUpdateSerializer, DictDetailsSerializer, \
DictDetailsCreateUpdateSerializer, DictDetailsListSerializer
from apps.system.models import DictDetails
from apps.system.filters import DictDetailsFilter, DictDataFilter
DictDetailsCreateUpdateSerializer, DictDetailsListSerializer, ConfigSettingsSerializer, \
ConfigSettingsCreateUpdateSerializer
from utils.response import SuccessResponse
@ -23,9 +23,10 @@ class DictDataModelViewSet(CustomModelViewSet):
# update_extra_permission_classes = (IsManagerPermission,)
# destroy_extra_permission_classes = (IsManagerPermission,)
# create_extra_permission_classes = (IsManagerPermission,)
search_fields = ('name',)
search_fields = ('dictName',)
ordering = 'id' # 默认排序
class DictDetailsModelViewSet(CustomModelViewSet):
"""
字典详情 模型的CRUD视图
@ -38,24 +39,9 @@ class DictDetailsModelViewSet(CustomModelViewSet):
# update_extra_permission_classes = (IsManagerPermission,)
# destroy_extra_permission_classes = (IsManagerPermission,)
# create_extra_permission_classes = (IsManagerPermission,)
search_fields = ('name',)
search_fields = ('dictLabel',)
ordering = 'sort' # 默认排序
def list(self, request: Request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
page = self.paginate_queryset(queryset)
print(1,page)
if hasattr(self, 'handle_logging'):
self.handle_logging(request, *args, **kwargs)
if page is not None:
if getattr(self, 'values_queryset', None):
return self.get_paginated_response(page)
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
if getattr(self, 'values_queryset', None):
return SuccessResponse(page)
serializer = self.get_serializer(queryset, many=True)
return SuccessResponse(serializer.data)
class DictDetailsListModelViewSet(CustomModelViewSet):
"""
@ -64,11 +50,28 @@ class DictDetailsListModelViewSet(CustomModelViewSet):
queryset = DictDetails.objects.filter(status=0)
serializer_class = DictDetailsListSerializer
filter_class = DictDetailsFilter
search_fields = ('name',)
search_fields = ('dictLabel',)
ordering = 'sort' # 默认排序
def list(self, request: Request, *args, **kwargs):
queryset = self.queryset.filter(dict_data__dictType=kwargs.get('pk')).order_by('sort')
if hasattr(self, 'handle_logging'):
self.handle_logging(request, *args, **kwargs)
serializer = self.get_serializer(queryset, many=True)
return SuccessResponse(serializer.data)
class ConfigSettingsModelViewSet(CustomModelViewSet):
"""
参数设置 模型的CRUD视图
"""
queryset = ConfigSettings.objects.all()
serializer_class = ConfigSettingsSerializer
create_serializer_class = ConfigSettingsCreateUpdateSerializer
update_serializer_class = ConfigSettingsCreateUpdateSerializer
filter_class = ConfigSettingsFilter
# update_extra_permission_classes = (IsManagerPermission,)
# destroy_extra_permission_classes = (IsManagerPermission,)
# create_extra_permission_classes = (IsManagerPermission,)
search_fields = ('name',)
ordering = 'id' # 默认排序

View File

@ -3,7 +3,7 @@ import request from '@/utils/request'
// 查询参数列表
export function listConfig(query) {
return request({
url: '/system/config/list',
url: '/system/config/',
method: 'get',
params: query
})
@ -12,7 +12,7 @@ export function listConfig(query) {
// 查询参数详细
export function getConfig(configId) {
return request({
url: '/system/config/' + configId,
url: '/system/config/' + configId + '/',
method: 'get'
})
}
@ -28,7 +28,7 @@ export function getConfigKey(configKey) {
// 新增参数配置
export function addConfig(data) {
return request({
url: '/system/config',
url: '/system/config/',
method: 'post',
data: data
})
@ -37,7 +37,7 @@ export function addConfig(data) {
// 修改参数配置
export function updateConfig(data) {
return request({
url: '/system/config',
url: '/system/config/' + data.id + '/',
method: 'put',
data: data
})
@ -46,7 +46,7 @@ export function updateConfig(data) {
// 删除参数配置
export function delConfig(configId) {
return request({
url: '/system/config/' + configId,
url: '/system/config/' + configId + '/',
method: 'delete'
})
}
@ -54,7 +54,7 @@ export function delConfig(configId) {
// 清理参数缓存
export function clearCache() {
return request({
url: '/system/config/clearCache',
url: '/system/config/clearCache/',
method: 'delete'
})
}
@ -66,4 +66,4 @@ export function exportConfig(query) {
method: 'get',
params: query
})
}
}

View File

@ -35,7 +35,7 @@ export default {
},
data() {
return {
title: '若依管理系统',
title: process.env.VUE_APP_TITLE || 'dvAdmin管理系统',
logo: logoImg
}
}

View File

@ -1,5 +1,5 @@
module.exports = {
title: '若依管理系统',
title: process.env.VUE_APP_TITLE || 'dvAdmin管理系统',
/**
* 侧边栏主题 深色主题theme-dark浅色主题theme-light

View File

@ -31,18 +31,6 @@
/>
</el-select>
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker
v-model="dateRange"
size="small"
style="width: 240px"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
></el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"></el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery"></el-button>
@ -107,11 +95,12 @@
<el-table v-loading="loading" :data="configList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="参数主键" align="center" prop="configId" />
<el-table-column label="参数主键" align="center" prop="id" />
<el-table-column label="参数名称" align="center" prop="configName" :show-overflow-tooltip="true" />
<el-table-column label="参数键名" align="center" prop="configKey" :show-overflow-tooltip="true" />
<el-table-column label="参数键值" align="center" prop="configValue" />
<el-table-column label="系统内置" align="center" prop="configType" :formatter="typeFormat" />
<el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
<el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
@ -167,6 +156,15 @@
>{{dict.dictLabel}}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio
v-for="dict in statusOptions"
:key="dict.dictValue"
:label="dict.dictValue"
>{{dict.dictLabel}}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</el-form-item>
@ -206,15 +204,16 @@ export default {
open: false,
//
typeOptions: [],
//
dateRange: [],
//
statusOptions: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
configName: undefined,
configKey: undefined,
configType: undefined
configType: undefined,
status: undefined
},
//
form: {},
@ -237,14 +236,17 @@ export default {
this.getDicts("sys_yes_no").then(response => {
this.typeOptions = response.data;
});
this.getDicts("sys_normal_disable").then(response => {
this.statusOptions = response.data;
});
},
methods: {
/** 查询参数列表 */
getList() {
this.loading = true;
listConfig(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.configList = response.rows;
this.total = response.total;
listConfig(this.addDateRange(this.queryParams)).then(response => {
this.configList = response.data.results;
this.total = response.data.count;
this.loading = false;
}
);
@ -253,6 +255,10 @@ export default {
typeFormat(row, column) {
return this.selectDictLabel(this.typeOptions, row.configType);
},
//
statusFormat(row, column) {
return this.selectDictLabel(this.statusOptions, row.status);
},
//
cancel() {
this.open = false;
@ -261,11 +267,12 @@ export default {
//
reset() {
this.form = {
configId: undefined,
id: undefined,
configName: undefined,
configKey: undefined,
configValue: undefined,
configType: "Y",
status: '0',
remark: undefined
};
this.resetForm("form");
@ -277,7 +284,6 @@ export default {
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm("queryForm");
this.handleQuery();
},
@ -289,15 +295,15 @@ export default {
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.configId)
this.ids = selection.map(item => item.id)
this.single = selection.length!=1
this.multiple = !selection.length
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const configId = row.configId || this.ids
getConfig(configId).then(response => {
const id = row.id || this.ids
getConfig(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改参数";
@ -307,7 +313,7 @@ export default {
submitForm: function() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.configId != undefined) {
if (this.form.id != undefined) {
updateConfig(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
@ -325,7 +331,7 @@ export default {
},
/** 删除按钮操作 */
handleDelete(row) {
const configIds = row.configId || this.ids;
const configIds = row.id || this.ids;
this.$confirm('是否确认删除参数编号为"' + configIds + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
@ -358,4 +364,4 @@ export default {
}
}
};
</script>
</script>

View File

@ -6,14 +6,14 @@
<el-option
v-for="item in typeOptions"
:key="item.dictId"
:label="item.name"
:label="item.dictName"
:value="item.dictType"
/>
</el-select>
</el-form-item>
<el-form-item label="字典标签" prop="name">
<el-form-item label="字典标签" prop="dictLabel">
<el-input
v-model="queryParams.name"
v-model="queryParams.dictLabel"
placeholder="请输入字典标签"
clearable
size="small"
@ -85,7 +85,7 @@
<el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="字典编码" align="center" prop="id" />
<el-table-column label="字典标签" align="center" prop="name" />
<el-table-column label="字典标签" align="center" prop="dictLabel" />
<el-table-column label="字典键值" align="center" prop="dictValue" />
<el-table-column label="字典排序" align="center" prop="sort" />
<el-table-column label="是否默认" align="center" prop="is_default" >
@ -137,8 +137,8 @@
<el-form-item label="字典类型">
<el-input v-model="form.dictType" :disabled="true" />
</el-form-item>
<el-form-item label="数据标签" prop="name">
<el-input v-model="form.name" placeholder="请输入数据标签" />
<el-form-item label="数据标签" prop="dictLabel">
<el-input v-model="form.dictLabel" placeholder="请输入数据标签" />
</el-form-item>
<el-form-item label="数据键值" prop="dictValue">
<el-input v-model="form.dictValue" placeholder="请输入数据键值" />
@ -203,7 +203,7 @@ export default {
//
open: false,
//
statusOptions: [{dictLabel: '正常', dictValue: '1',}, {dictLabel: '停用', dictValue: '0',}],
statusOptions: [],
//
typeOptions: [],
//
@ -235,9 +235,9 @@ export default {
console.log(11111,this.$route.params)
this.getType(dictId);
this.getTypeList();
// this.getDicts("sys_normal_disable").then(response => {
// this.statusOptions = response.data;
// });
this.getDicts("sys_normal_disable").then(response => {
this.statusOptions = response.data;
});
},
methods: {
/** 查询字典类型详细 */
@ -277,7 +277,7 @@ export default {
reset() {
this.form = {
id: undefined,
name: undefined,
dictLabel: undefined,
dictValue: undefined,
sort: 0,
status: "0",

View File

@ -1,9 +1,9 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="字典名称" prop="name">
<el-form-item label="字典名称" prop="dictName">
<el-input
v-model="queryParams.name"
v-model="queryParams.dictName"
placeholder="请输入字典名称"
clearable
size="small"
@ -114,7 +114,7 @@
<el-table v-loading="loading" :data="typeList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="字典编号" align="center" prop="id" />
<el-table-column label="字典名称" align="center" prop="name" :show-overflow-tooltip="true" />
<el-table-column label="字典名称" align="center" prop="dictName" :show-overflow-tooltip="true" />
<el-table-column label="字典类型" align="center" :show-overflow-tooltip="true">
<template slot-scope="scope">
<router-link :to="'/dict/type/data/' + scope.row.id" class="link-type">
@ -160,8 +160,8 @@
<!-- 添加或修改参数配置对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="字典名称" prop="name">
<el-input v-model="form.name" placeholder="请输入字典名称" />
<el-form-item label="字典名称" prop="dictName">
<el-input v-model="form.dictName" placeholder="请输入字典名称" />
</el-form-item>
<el-form-item label="字典类型" prop="dictType">
<el-input v-model="form.dictType" placeholder="请输入字典类型" />
@ -220,7 +220,7 @@ export default {
queryParams: {
pageNum: 1,
pageSize: 10,
name: undefined,
dictName: undefined,
dictType: undefined,
status: undefined
},
@ -228,7 +228,7 @@ export default {
form: {},
//
rules: {
name: [
dictName: [
{ required: true, message: "字典名称不能为空", trigger: "blur" }
],
dictType: [
@ -267,7 +267,7 @@ export default {
reset() {
this.form = {
id: undefined,
name: undefined,
dictName: undefined,
dictType: undefined,
status: "0",
remark: undefined