Showing
5 changed files
with
23 additions
and
16 deletions
... | ... | @@ -8,7 +8,7 @@ export enum ParamsType { |
8 | 8 | OPTIONAL |
9 | 9 | } |
10 | 10 | |
11 | -const getOriginUrl = (originUrl: string) => { | |
11 | +export const getOriginUrl = (originUrl: string) => { | |
12 | 12 | const locationUrl = 'localhost' |
13 | 13 | return originUrl === locationUrl ? location.origin : originUrl |
14 | 14 | } | ... | ... |
... | ... | @@ -6,7 +6,7 @@ import { useChartEditStore } from "@/store/modules/chartEditStore/chartEditStore |
6 | 6 | import { getJwtToken } from "@/utils/external/auth"; |
7 | 7 | import { useWebSocket, WebSocketResult } from "@vueuse/core"; |
8 | 8 | import { onMounted, unref } from "vue"; |
9 | -import { useFilterFn } from "./useFilterFn"; | |
9 | +import { ExtraRequestConfigType } from "@/store/external/modules/extraComponentInfo.d"; | |
10 | 10 | |
11 | 11 | |
12 | 12 | interface SocketConnectionPoolType { |
... | ... | @@ -24,14 +24,22 @@ const parse = (value: string) => { |
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
27 | -const getSocketInstance = (requestUrl: string) => { | |
27 | +const getOriginUrl = (url: string) => { | |
28 | + const { host, protocol } = location | |
29 | + const isLocationUrl = url === 'localhost' | |
30 | + const isContentSafetyProtocol = protocol === 'https' | |
31 | + return isLocationUrl ? `${isContentSafetyProtocol ? 'wss' : 'ws'}://${host}` : host | |
32 | +} | |
33 | + | |
34 | +const getSocketInstance = (request: ExtraRequestConfigType) => { | |
35 | + const { requestUrl, requestOriginUrl } = request | |
28 | 36 | const socketStore = useSocketStore() |
29 | 37 | const index = socketConnectionPool.findIndex(item => item.url === requestUrl) |
30 | 38 | if (~index) { |
31 | 39 | return socketConnectionPool[index].ws |
32 | 40 | } |
33 | 41 | const token = getJwtToken() |
34 | - const socketUrl = `${requestUrl}?token=${token}` | |
42 | + const socketUrl = `${getOriginUrl(requestOriginUrl || '')}${requestUrl}?token=${token}` | |
35 | 43 | |
36 | 44 | const instance = useWebSocket(socketUrl.replace('undefined', ''), { |
37 | 45 | onMessage() { |
... | ... | @@ -44,7 +52,7 @@ const getSocketInstance = (requestUrl: string) => { |
44 | 52 | } |
45 | 53 | }) |
46 | 54 | |
47 | - socketConnectionPool.push({ url: requestUrl, ws: instance }) | |
55 | + socketConnectionPool.push({ url: requestUrl!, ws: instance }) | |
48 | 56 | |
49 | 57 | return instance |
50 | 58 | } |
... | ... | @@ -62,7 +70,7 @@ export const useChartDataSocket = () => { |
62 | 70 | |
63 | 71 | if ((requestContentType as RequestContentTypeEnum) !== RequestContentTypeEnum.WEB_SOCKET) return |
64 | 72 | |
65 | - const { send } = getSocketInstance(requestUrl!) | |
73 | + const { send } = getSocketInstance(request!) | |
66 | 74 | |
67 | 75 | onMounted(() => { |
68 | 76 | const message = socketStore.subscribe(targetComponent) |
... | ... | @@ -72,9 +80,8 @@ export const useChartDataSocket = () => { |
72 | 80 | |
73 | 81 | const sendMessage = async (targetComponent: CreateComponentType) => { |
74 | 82 | const { request } = unref(targetComponent) |
75 | - const { requestUrl } = request | |
76 | 83 | const message = socketStore.subscribe(unref(targetComponent)) |
77 | - const { send, data } = getSocketInstance(requestUrl!) | |
84 | + const { send, data } = getSocketInstance(request) | |
78 | 85 | message && send(JSON.stringify(message)) |
79 | 86 | return socketStore.getComponentValueByKeys(targetComponent, parse(unref(data))) |
80 | 87 | } | ... | ... |
src/views/chart/ContentConfigurations/components/ChartData/external/components/DynamicForm/index.vue
... | ... | @@ -16,7 +16,7 @@ const componentMap: { [key in ComponentType]?: any } = { |
16 | 16 | [ComponentType.DATE_PICKER]: NDatePicker |
17 | 17 | } |
18 | 18 | |
19 | -const getParamsItemList = computed(() => { | |
19 | +const getParamsItemList = computed(() => { | |
20 | 20 | return props.paramsItemList |
21 | 21 | }) |
22 | 22 | |
... | ... | @@ -35,7 +35,7 @@ const validate = async () => { |
35 | 35 | return unref(validFlag) |
36 | 36 | } |
37 | 37 | const setConfigurationData = async (params: Recordable) => { |
38 | - await nextTick() | |
38 | + await nextTick() | |
39 | 39 | setDynamicFormValue(params) |
40 | 40 | } |
41 | 41 | ... | ... |
... | ... | @@ -324,8 +324,7 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { |
324 | 324 | getDeviceOption() |
325 | 325 | } |
326 | 326 | |
327 | - const setParams = (Params: Recordable) => { | |
328 | - | |
327 | + const setParams = (Params: Recordable = {}) => { | |
329 | 328 | for (const { key, value } of unref(getParams)) { |
330 | 329 | const splitKeys = value ? value.split(GROUP_SEPARATOR) : key.split(GROUP_SEPARATOR) |
331 | 330 | if (isDateComponent(key as BuiltInVariable)) { |
... | ... | @@ -350,7 +349,7 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { |
350 | 349 | } |
351 | 350 | |
352 | 351 | const setDynamicFormValue = (params: Recordable) => { |
353 | - setParams(params) | |
352 | + setParams(params) | |
354 | 353 | getOrgOption() |
355 | 354 | getDeviceProfileOption() |
356 | 355 | getDeviceOption() | ... | ... |
... | ... | @@ -72,12 +72,14 @@ const paramsDynamicFormEl = ref<Nullable<InstanceType<typeof DynamicForm>>>(null |
72 | 72 | const bodyContentEl = ref<Nullable<InstanceType<typeof BodyContent>>>(null) |
73 | 73 | const socketDynamicFormEl = ref<Nullable<InstanceType<typeof DynamicForm>>>(null) |
74 | 74 | |
75 | -const handleSelectedInterfaceChange = (_value: string, option: PublicInterfaceRecord) => { | |
75 | +const handleSelectedInterfaceChange = async (_value: string, option: PublicInterfaceRecord) => { | |
76 | 76 | requestContentTypeRef.value = option.requestContentType as RequestContentTypeEnum |
77 | 77 | requestHttpTypeRef.value = option.requestHttpType as RequestHttpEnum |
78 | 78 | const { Header = [], Body } = JSON.parse(option.requestParams) as PublicInterfaceRequestParams |
79 | 79 | headerRef.value = isArray(Header) ? (Header as ParamsItemType[]).reduce((prev, next) => ({ ...prev, [next.key]: next.value }), {}) : {} |
80 | - unref(bodyContentEl)?.setConfigurationData(Body) | |
80 | + unref(bodyContentEl)?.setConfigurationData(unref(getSelectedInterfaceBody), Body) | |
81 | + await nextTick() | |
82 | + setDynamicFormValue(option as unknown as ExtraRequestConfigType) | |
81 | 83 | } |
82 | 84 | |
83 | 85 | const getGetRequestTypeName = (key: RequestContentTypeEnum) => { |
... | ... | @@ -124,7 +126,6 @@ const setConfigurationData = async (request: ExtraRequestConfigType) => { |
124 | 126 | requestParamsBodyTypeRef.value = requestParamsBodyType |
125 | 127 | requestBodyRef.value = requestParams |
126 | 128 | await nextTick() |
127 | - console.log(request) | |
128 | 129 | setDynamicFormValue(request) |
129 | 130 | } |
130 | 131 | ... | ... |