Commit 4f55b598b8309b93e78af356e554164cfd39b9c1
Merge branch 'fix/socket-filter' into 'main_dev'
fix: 修复websocket请求无法使用过滤器 See merge request yunteng/thingskit-view!207
Showing
3 changed files
with
14 additions
and
8 deletions
... | ... | @@ -154,7 +154,7 @@ export const customRequest = async (request: RequestConfigType) => { |
154 | 154 | * 修改后代码 requestHttpType === RequestHttpEnum.GET.toUpperCase() ? requestUrl: `${requestUrl}?${objConvertQuery(Params)} |
155 | 155 | */ |
156 | 156 | Params = handleParams(Params) |
157 | - console.log(Params) | |
157 | + | |
158 | 158 | return customHttp.request<any>({ |
159 | 159 | url: requestHttpType === RequestHttpEnum.GET.toUpperCase() ? requestUrl : `${requestUrl}?${objConvertQuery(Params)}`, |
160 | 160 | baseURL: getOriginUrl(requestOriginUrl!), | ... | ... |
... | ... | @@ -97,7 +97,7 @@ |
97 | 97 | </template> |
98 | 98 | |
99 | 99 | <script lang="ts" setup> |
100 | -import { ref, computed, watch } from 'vue' | |
100 | +import { ref, computed, watch, unref } from 'vue' | |
101 | 101 | import { MonacoEditor } from '@/components/Pages/MonacoEditor' |
102 | 102 | import { icon } from '@/plugins' |
103 | 103 | import { goDialog, toString } from '@/utils' |
... | ... | @@ -105,6 +105,7 @@ import { useTargetData } from '../../../../hooks/useTargetData.hook' |
105 | 105 | import { NButton, NCard, NCode, NDivider, NIcon, NModal, NScrollbar, NSpace, NTag, NText } from 'naive-ui' |
106 | 106 | import { useFilterFn } from '@/hooks/external/useFilterFn' |
107 | 107 | import { useFetchTargetData } from '@/hooks/external/useFetchTargetData' |
108 | +import { RequestContentTypeEnum } from '@/enums/external/httpEnum' | |
108 | 109 | |
109 | 110 | const { DocumentTextIcon } = icon.ionicons5 |
110 | 111 | const { FilterIcon, FilterEditIcon } = icon.carbon |
... | ... | @@ -122,9 +123,15 @@ const sourceData = ref<any>('') |
122 | 123 | const { fetchTargetData: fetchHandle } = useFetchTargetData() |
123 | 124 | // 动态获取数据 |
124 | 125 | const fetchTargetData = async () => { |
125 | - const res = await fetchHandle() | |
126 | - if (res) { | |
127 | - sourceData.value = res | |
126 | + if ((unref(targetData).request.requestContentType as RequestContentTypeEnum) === RequestContentTypeEnum.WEB_SOCKET) { | |
127 | + sourceData.value = { | |
128 | + data: unref(targetData).option.dataset | |
129 | + } | |
130 | + } else { | |
131 | + const res = await fetchHandle() | |
132 | + if (res) { | |
133 | + sourceData.value = res | |
134 | + } | |
128 | 135 | } |
129 | 136 | } |
130 | 137 | |
... | ... | @@ -134,7 +141,6 @@ const filterRes = computed(() => { |
134 | 141 | // eslint-disable-next-line vue/no-side-effects-in-computed-properties |
135 | 142 | errorFlag.value = !flag |
136 | 143 | return toString(flag ? value : `过滤函数错误,日志:${reason}`) |
137 | - | |
138 | 144 | }) |
139 | 145 | |
140 | 146 | // 新增过滤器 |
... | ... | @@ -170,7 +176,7 @@ const saveFilter = () => { |
170 | 176 | watch( |
171 | 177 | () => showModal.value, |
172 | 178 | (newData: boolean) => { |
173 | - if (newData) { | |
179 | + if (newData) { | |
174 | 180 | fetchTargetData() |
175 | 181 | filter.value = targetData.value.filter || `return res` |
176 | 182 | } | ... | ... |