Merge remote-tracking branch 'origin/v2.x' into v2.x

pull/71/head
猿小天 2022-08-28 14:35:46 +08:00
commit 5f7799733d
5 changed files with 49 additions and 26 deletions

View File

@ -40,7 +40,7 @@ def _get_all_system_config():
from dvadmin.system.models import SystemConfig from dvadmin.system.models import SystemConfig
system_config_obj = ( system_config_obj = (
SystemConfig.objects.filter(status=True, parent_id__isnull=False) SystemConfig.objects.filter(parent_id__isnull=False)
.values("parent__key", "key", "value", "form_item_type") .values("parent__key", "key", "value", "form_item_type")
.order_by("sort") .order_by("sort")
) )
@ -131,6 +131,8 @@ def get_dictionary_config(schema_name=None):
:param schema_name: 对应字典配置的租户schema_name值 :param schema_name: 对应字典配置的租户schema_name值
:return: :return:
""" """
if not settings.DICTIONARY_CONFIG:
refresh_dictionary()
if is_tenants_mode(): if is_tenants_mode():
dictionary_config = settings.DICTIONARY_CONFIG[schema_name or connection.tenant.schema_name] dictionary_config = settings.DICTIONARY_CONFIG[schema_name or connection.tenant.schema_name]
else: else:
@ -175,6 +177,8 @@ def get_system_config(schema_name=None):
:param schema_name: 对应字典配置的租户schema_name值 :param schema_name: 对应字典配置的租户schema_name值
:return: :return:
""" """
if not settings.SYSTEM_CONFIG:
refresh_system_config()
if is_tenants_mode(): if is_tenants_mode():
dictionary_config = settings.SYSTEM_CONFIG[schema_name or connection.tenant.schema_name] dictionary_config = settings.SYSTEM_CONFIG[schema_name or connection.tenant.schema_name]
else: else:

View File

@ -259,7 +259,7 @@ def media_file_name(instance, filename):
class FileList(CoreModel): class FileList(CoreModel):
name = models.CharField(max_length=50, null=True, blank=True, verbose_name="名称", help_text="名称") name = models.CharField(max_length=200, null=True, blank=True, verbose_name="名称", help_text="名称")
url = models.FileField(upload_to=media_file_name) url = models.FileField(upload_to=media_file_name)
md5sum = models.CharField(max_length=36, blank=True, verbose_name="文件md5", help_text="文件md5") md5sum = models.CharField(max_length=36, blank=True, verbose_name="文件md5", help_text="文件md5")
@ -427,4 +427,4 @@ class MessageCenter(CoreModel):
db_table = table_prefix + "message_center" db_table = table_prefix + "message_center"
verbose_name = "消息中心" verbose_name = "消息中心"
verbose_name_plural = verbose_name verbose_name_plural = verbose_name
ordering = ("-create_datetime",) ordering = ("-create_datetime",)

View File

@ -250,9 +250,29 @@ class InitSettingsViewSet(APIView):
authentication_classes = [] authentication_classes = []
permission_classes = [] permission_classes = []
def filter_system_config_values(self, data: dict):
"""
过滤系统初始化配置
:param data:
:return:
"""
if not self.request.query_params.get('key', ''):
return data
new_data = {}
for key in self.request.query_params.get('key', '').split('|'):
if key:
new_data.update(**dict(filter(lambda x: x[0].startswith(key), data.items())))
return new_data
def get(self, request): def get(self, request):
data = dispatch.get_system_config() data = dispatch.get_system_config()
if not data: if not data:
dispatch.refresh_system_config() dispatch.refresh_system_config()
data = dispatch.get_system_config() data = dispatch.get_system_config()
# 不返回后端专用配置
backend_config = [f"{ele.get('parent__key')}.{ele.get('key')}" for ele in
SystemConfig.objects.filter(status=False, parent_id__isnull=False).values('parent__key',
'key')]
data = dict(filter(lambda x: x[0] not in backend_config, data.items()))
data = self.filter_system_config_values(data=data)
return DetailResponse(data=data) return DetailResponse(data=data)

View File

@ -272,22 +272,23 @@ class UserViewSet(CustomModelViewSet):
@action(methods=["PUT"], detail=True, permission_classes=[IsAuthenticated]) @action(methods=["PUT"], detail=True, permission_classes=[IsAuthenticated])
def change_password(self, request, *args, **kwargs): def change_password(self, request, *args, **kwargs):
"""密码修改""" """密码修改"""
instance = Users.objects.filter(id=kwargs.get("pk")).first()
data = request.data data = request.data
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 instance: if old_pwd or new_pwd or new_pwd2:
if new_pwd != new_pwd2: return ErrorResponse(msg="参数不能为空")
return ErrorResponse(msg="两次密码不匹配") if new_pwd != new_pwd2:
elif instance.check_password(old_pwd): return ErrorResponse(msg="两次密码不匹配")
instance.password = make_password(new_pwd) check_password = request.user.check_password(old_pwd)
instance.save() if not check_password:
return DetailResponse(data=None, msg="修改成功") check_password = request.user.check_password(hashlib.md5(old_pwd.encode(encoding='UTF-8')).hexdigest())
else: if check_password:
return ErrorResponse(msg="旧密码不正确") request.user.password = make_password(new_pwd)
request.user.save()
return DetailResponse(data=None, msg="修改成功")
else: else:
return ErrorResponse(msg="未获取到用户") return ErrorResponse(msg="旧密码不正确")
@action(methods=["PUT"], detail=True, permission_classes=[IsAuthenticated]) @action(methods=["PUT"], detail=True, permission_classes=[IsAuthenticated])
def reset_to_default_password(self, request, *args, **kwargs): def reset_to_default_password(self, request, *args, **kwargs):

View File

@ -2,10 +2,10 @@
<div> <div>
<el-row :gutter="10"> <el-row :gutter="10">
<el-col :span="4">变量标题</el-col> <el-col :span="4">变量标题</el-col>
<el-col :span="8">变量值</el-col> <el-col :span="10">变量值</el-col>
<el-col :span="4" >变量名</el-col> <el-col :span="4" >变量名</el-col>
<el-col :span="4" >状态</el-col> <el-col :span="2">是否前端配置</el-col>
<el-col :span="4" >操作</el-col> <el-col :span="3" :offset="1">操作</el-col>
</el-row> </el-row>
<el-form ref="form" :model="form" label-width="240px" label-position="left" style="margin-top: 20px"> <el-form ref="form" :model="form" label-width="240px" label-position="left" style="margin-top: 20px">
<el-form-item :label="item.title" :prop="['array'].indexOf(item.form_item_type_label) >-1?'':item.key" <el-form-item :label="item.title" :prop="['array'].indexOf(item.form_item_type_label) >-1?'':item.key"
@ -17,7 +17,7 @@
<el-input v-if="item.edit" v-model="item.title" style="display: inline-block;width: 200px;" placeholder="请输入标题"></el-input> <el-input v-if="item.edit" v-model="item.title" style="display: inline-block;width: 200px;" placeholder="请输入标题"></el-input>
<span v-else>{{item.title}}</span> <span v-else>{{item.title}}</span>
</template> </template>
<el-col :span="6" > <el-col :span="11" >
<!-- 文本 --> <!-- 文本 -->
<el-input :key="index" v-if="['text','textarea'].indexOf(item.form_item_type_label) >-1" <el-input :key="index" v-if="['text','textarea'].indexOf(item.form_item_type_label) >-1"
:type="item.form_item_type_label" :type="item.form_item_type_label"
@ -74,7 +74,7 @@
<el-radio <el-radio
v-for="item in dictionary(item.setting) || []" v-for="item in dictionary(item.setting) || []"
:key="item.value" :key="item.value"
:label="item.label" :label="item.value"
:value="item.value"> :value="item.value">
{{ item.label }} {{ item.label }}
</el-radio> </el-radio>
@ -201,7 +201,7 @@
</div> </div>
</div> </div>
</el-col> </el-col>
<el-col :span="6" :offset="2"> <el-col :span="4" :offset="1">
<el-input v-if="item.edit" v-model="item.new_key" style="width: 200px;" placeholder="请输入变量key"> <el-input v-if="item.edit" v-model="item.new_key" style="width: 200px;" placeholder="请输入变量key">
<template slot="prepend"> <template slot="prepend">
<span style="padding: 0px 5px">{{ editableTabsItem.key }}</span> <span style="padding: 0px 5px">{{ editableTabsItem.key }}</span>
@ -209,16 +209,14 @@
</el-input> </el-input>
<span v-else>{{ editableTabsItem.key }}.{{ item.key }}</span> <span v-else>{{ editableTabsItem.key }}.{{ item.key }}</span>
</el-col> </el-col>
<el-col :span="4" > <el-col :span="3" :offset="1">
<el-switch <el-switch
v-model="item.status" v-model="item.status"
active-color="#13ce66" active-color="#13ce66"
inactive-color="#ff4949" inactive-color="#ff4949">
active-text="启用"
inactive-text="禁用">
</el-switch> </el-switch>
</el-col> </el-col>
<el-col :span="4" :offset="1"> <el-col :span="2">
<el-button v-if="item.edit" size="mini" type="primary" icon="el-icon-success" @click="onEditSave(item)"></el-button> <el-button v-if="item.edit" size="mini" type="primary" icon="el-icon-success" @click="onEditSave(item)"></el-button>
<el-button v-else size="mini" type="primary" icon="el-icon-edit" @click="onEdit(index)"></el-button> <el-button v-else size="mini" type="primary" icon="el-icon-edit" @click="onEdit(index)"></el-button>
<el-popconfirm <el-popconfirm
@ -305,7 +303,7 @@ export default {
// //
getInit () { getInit () {
const that = this const that = this
api.GetList({ parent: this.options.id }).then(res => { api.GetList({ parent: this.options.id, limit: 999 }).then(res => {
const { data } = res.data const { data } = res.data
this.formList = data this.formList = data
const form = {} const form = {}