获取参数配置

pull/1/head
李强 2021-02-27 11:21:06 +08:00
parent a19c95bd42
commit d8ea729d2e
3 changed files with 27 additions and 17 deletions

View File

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

View File

@ -42,22 +42,18 @@ class DictDetailsModelViewSet(CustomModelViewSet):
search_fields = ('dictLabel',) search_fields = ('dictLabel',)
ordering = 'sort' # 默认排序 ordering = 'sort' # 默认排序
def dict_details_list(self, request: Request, *args, **kwargs):
class DictDetailsListModelViewSet(CustomModelViewSet): """
""" 根据字典类型查询字典数据信息
根据字典类型查询字典数据信息 模型的CRUD视图 :param request:
""" :param args:
queryset = DictDetails.objects.filter(status=0) :param kwargs:
serializer_class = DictDetailsListSerializer :return:
filter_class = DictDetailsFilter """
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') queryset = self.queryset.filter(dict_data__dictType=kwargs.get('pk')).order_by('sort')
if hasattr(self, 'handle_logging'): if hasattr(self, 'handle_logging'):
self.handle_logging(request, *args, **kwargs) self.handle_logging(request, *args, **kwargs)
serializer = self.get_serializer(queryset, many=True) serializer = DictDetailsListSerializer(queryset, many=True)
return SuccessResponse(serializer.data) return SuccessResponse(serializer.data)
@ -73,5 +69,18 @@ class ConfigSettingsModelViewSet(CustomModelViewSet):
# update_extra_permission_classes = (IsManagerPermission,) # update_extra_permission_classes = (IsManagerPermission,)
# destroy_extra_permission_classes = (IsManagerPermission,) # destroy_extra_permission_classes = (IsManagerPermission,)
# create_extra_permission_classes = (IsManagerPermission,) # create_extra_permission_classes = (IsManagerPermission,)
search_fields = ('name',) search_fields = ('configName',)
ordering = 'id' # 默认排序 ordering = 'id' # 默认排序
def get_config_key(self, request: Request, *args, **kwargs):
"""
根据 参数键名 查询参数数据信息
:param request:
:param args:
:param kwargs:
:return:
"""
queryset = self.queryset.filter(configKey=kwargs.get('pk')).first()
# if hasattr(self, 'handle_logging'):
# self.handle_logging(request, *args, **kwargs)
return SuccessResponse(msg=queryset.configValue if queryset else '')

View File

@ -20,7 +20,7 @@ export function getConfig(configId) {
// 根据参数键名查询参数值 // 根据参数键名查询参数值
export function getConfigKey(configKey) { export function getConfigKey(configKey) {
return request({ return request({
url: '/system/config/configKey/' + configKey, url: '/system/config/configKey/' + configKey + '/',
method: 'get' method: 'get'
}) })
} }