refactor: 接入时增加query参数

This commit is contained in:
CaptainB 2024-09-13 15:40:13 +08:00 committed by 刘瑞斌
parent 88b6d8b9d8
commit b5e6f07ada
3 changed files with 24 additions and 5 deletions

View File

@ -204,7 +204,7 @@ class ApplicationSerializer(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 @@ class ApplicationSerializer(serializers.Serializer):
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 @@ class ApplicationSerializer(serializers.Serializer):
'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"))

View File

@ -25,9 +25,9 @@ const chatButtonHtml=
const getChatContainerHtml=(protocol,host,token)=>{
const getChatContainerHtml=(protocol,host,token,query)=>{
return `<div id="maxkb-chat-container">
<iframe id="maxkb-chat" src=${protocol}://${host}/ui/chat/${token}?mode=embed></iframe>
<iframe id="maxkb-chat" src=${protocol}://${host}/ui/chat/${token}?mode=embed${query}></iframe>
<div class="maxkb-operate"><div class="maxkb-closeviewport maxkb-viewportnone"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
<path d="M7.507 11.6645C7.73712 11.6645 7.94545 11.7578 8.09625 11.9086C8.24706 12.0594 8.34033 12.2677 8.34033 12.4978V16.7976C8.34033 17.0277 8.15378 17.2143 7.92366 17.2143H7.09033C6.86021 17.2143 6.67366 17.0277 6.67366 16.7976V14.5812L3.41075 17.843C3.24803 18.0057 2.98421 18.0057 2.82149 17.843L2.23224 17.2537C2.06952 17.091 2.06952 16.8272 2.23224 16.6645L5.56668 13.3311H3.19634C2.96622 13.3311 2.77967 13.1446 2.77967 12.9145V12.0811C2.77967 11.851 2.96622 11.6645 3.19634 11.6645H7.507ZM16.5991 2.1572C16.7619 1.99448 17.0257 1.99448 17.1884 2.1572L17.7777 2.74645C17.9404 2.90917 17.9404 3.17299 17.7777 3.33571L14.4432 6.66904H16.8136C17.0437 6.66904 17.2302 6.85559 17.2302 7.08571V7.91904C17.2302 8.14916 17.0437 8.33571 16.8136 8.33571H12.5029C12.2728 8.33571 12.0644 8.24243 11.9136 8.09163C11.7628 7.94082 11.6696 7.73249 11.6696 7.50237V3.20257C11.6696 2.97245 11.8561 2.7859 12.0862 2.7859H12.9196C13.1497 2.7859 13.3362 2.97245 13.3362 3.20257V5.419L16.5991 2.1572Z" fill="#646A73"/>
</svg></div>
@ -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')
// 对话框元素

View File

@ -167,7 +167,7 @@ class Application(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]