From a8768699fab32b0f91077114198134c2b56818a4 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Fri, 13 Sep 2024 15:40:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8E=A5=E5=85=A5=E6=97=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0query=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serializers/application_serializers.py | 21 ++++++++++++++++++- apps/application/template/embed.js | 6 +++--- apps/application/views/application_views.py | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/application/serializers/application_serializers.py b/apps/application/serializers/application_serializers.py index a7e7f6423a..a04af8999e 100644 --- a/apps/application/serializers/application_serializers.py +++ b/apps/application/serializers/application_serializers.py @@ -204,7 +204,7 @@ class Embed(serializers.Serializer): protocol = serializers.CharField(required=True, error_messages=ErrMessage.char("协议")) token = serializers.CharField(required=True, error_messages=ErrMessage.char("token")) - def get_embed(self, with_valid=True): + def get_embed(self, with_valid=True, params={}): if with_valid: self.is_valid(raise_exception=True) index_path = os.path.join(PROJECT_DIR, 'apps', "application", 'template', 'embed.js') @@ -218,6 +218,9 @@ def get_embed(self, with_valid=True): float_icon = f"{self.data.get('protocol')}://{self.data.get('host')}/ui/favicon.ico" X_PACK_LICENSE_IS_VALID = (settings.XPACK_LICENSE_IS_VALID if hasattr(settings, 'XPACK_LICENSE_IS_VALID') else False) + # 获取接入的query参数 + query = self.get_query_api_input(application_access_token.application, params) + application_setting_model = DBModelManage.get_model('application_setting') if application_setting_model is not None and X_PACK_LICENSE_IS_VALID: application_setting = QuerySet(application_setting_model).filter( @@ -239,10 +242,26 @@ def get_embed(self, with_valid=True): 'white_active': 'true' if application_access_token.white_active else 'false', 'is_draggable': is_draggable, 'float_icon': float_icon, + 'query': query, 'show_guide': show_guide})) response = HttpResponse(s, status=200, headers={'Content-Type': 'text/javascript'}) return response + def get_query_api_input(self, application, params): + query = '' + if application.work_flow is not None: + work_flow = application.work_flow + if work_flow is not None: + for node in work_flow['nodes']: + if node['id'] == 'base-node': + input_field_list = node['properties']['input_field_list'] + if input_field_list is not None: + for field in input_field_list: + if field['assignment_method'] == 'api_input' and field['variable'] in params: + query += f"&{field['variable']}={params[field['variable']]}" + + return query + class AccessTokenSerializer(serializers.Serializer): application_id = serializers.UUIDField(required=True, error_messages=ErrMessage.boolean("应用id")) diff --git a/apps/application/template/embed.js b/apps/application/template/embed.js index 898f31644f..4928e50f93 100644 --- a/apps/application/template/embed.js +++ b/apps/application/template/embed.js @@ -25,9 +25,9 @@ const chatButtonHtml= -const getChatContainerHtml=(protocol,host,token)=>{ +const getChatContainerHtml=(protocol,host,token,query)=>{ return `
- +
@@ -61,7 +61,7 @@ const initChat=(root)=>{ // 添加对话icon root.insertAdjacentHTML("beforeend",chatButtonHtml) // 添加对话框 - root.insertAdjacentHTML('beforeend',getChatContainerHtml('{{protocol}}','{{host}}','{{token}}')) + root.insertAdjacentHTML('beforeend',getChatContainerHtml('{{protocol}}','{{host}}','{{token}}','{{query}}')) // 按钮元素 const chat_button=root.querySelector('.maxkb-chat-button') // 对话框元素 diff --git a/apps/application/views/application_views.py b/apps/application/views/application_views.py index 0c83335667..d9c9043e9a 100644 --- a/apps/application/views/application_views.py +++ b/apps/application/views/application_views.py @@ -167,7 +167,7 @@ class Embed(APIView): def get(self, request: Request): return ApplicationSerializer.Embed( data={'protocol': request.query_params.get('protocol'), 'token': request.query_params.get('token'), - 'host': request.query_params.get('host'), }).get_embed() + 'host': request.query_params.get('host'), }).get_embed(params=request.query_params) class Model(APIView): authentication_classes = [TokenAuth]