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,7 +154,7 @@ export const customRequest = async (request: RequestConfigType) => { | ||
154 | * 修改后代码 requestHttpType === RequestHttpEnum.GET.toUpperCase() ? requestUrl: `${requestUrl}?${objConvertQuery(Params)} | 154 | * 修改后代码 requestHttpType === RequestHttpEnum.GET.toUpperCase() ? requestUrl: `${requestUrl}?${objConvertQuery(Params)} |
155 | */ | 155 | */ |
156 | Params = handleParams(Params) | 156 | Params = handleParams(Params) |
157 | - console.log(Params) | 157 | + |
158 | return customHttp.request<any>({ | 158 | return customHttp.request<any>({ |
159 | url: requestHttpType === RequestHttpEnum.GET.toUpperCase() ? requestUrl : `${requestUrl}?${objConvertQuery(Params)}`, | 159 | url: requestHttpType === RequestHttpEnum.GET.toUpperCase() ? requestUrl : `${requestUrl}?${objConvertQuery(Params)}`, |
160 | baseURL: getOriginUrl(requestOriginUrl!), | 160 | baseURL: getOriginUrl(requestOriginUrl!), |
@@ -97,7 +97,7 @@ | @@ -97,7 +97,7 @@ | ||
97 | </template> | 97 | </template> |
98 | 98 | ||
99 | <script lang="ts" setup> | 99 | <script lang="ts" setup> |
100 | -import { ref, computed, watch } from 'vue' | 100 | +import { ref, computed, watch, unref } from 'vue' |
101 | import { MonacoEditor } from '@/components/Pages/MonacoEditor' | 101 | import { MonacoEditor } from '@/components/Pages/MonacoEditor' |
102 | import { icon } from '@/plugins' | 102 | import { icon } from '@/plugins' |
103 | import { goDialog, toString } from '@/utils' | 103 | import { goDialog, toString } from '@/utils' |
@@ -105,6 +105,7 @@ import { useTargetData } from '../../../../hooks/useTargetData.hook' | @@ -105,6 +105,7 @@ import { useTargetData } from '../../../../hooks/useTargetData.hook' | ||
105 | import { NButton, NCard, NCode, NDivider, NIcon, NModal, NScrollbar, NSpace, NTag, NText } from 'naive-ui' | 105 | import { NButton, NCard, NCode, NDivider, NIcon, NModal, NScrollbar, NSpace, NTag, NText } from 'naive-ui' |
106 | import { useFilterFn } from '@/hooks/external/useFilterFn' | 106 | import { useFilterFn } from '@/hooks/external/useFilterFn' |
107 | import { useFetchTargetData } from '@/hooks/external/useFetchTargetData' | 107 | import { useFetchTargetData } from '@/hooks/external/useFetchTargetData' |
108 | +import { RequestContentTypeEnum } from '@/enums/external/httpEnum' | ||
108 | 109 | ||
109 | const { DocumentTextIcon } = icon.ionicons5 | 110 | const { DocumentTextIcon } = icon.ionicons5 |
110 | const { FilterIcon, FilterEditIcon } = icon.carbon | 111 | const { FilterIcon, FilterEditIcon } = icon.carbon |
@@ -122,9 +123,15 @@ const sourceData = ref<any>('') | @@ -122,9 +123,15 @@ const sourceData = ref<any>('') | ||
122 | const { fetchTargetData: fetchHandle } = useFetchTargetData() | 123 | const { fetchTargetData: fetchHandle } = useFetchTargetData() |
123 | // 动态获取数据 | 124 | // 动态获取数据 |
124 | const fetchTargetData = async () => { | 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,7 +141,6 @@ const filterRes = computed(() => { | ||
134 | // eslint-disable-next-line vue/no-side-effects-in-computed-properties | 141 | // eslint-disable-next-line vue/no-side-effects-in-computed-properties |
135 | errorFlag.value = !flag | 142 | errorFlag.value = !flag |
136 | return toString(flag ? value : `过滤函数错误,日志:${reason}`) | 143 | return toString(flag ? value : `过滤函数错误,日志:${reason}`) |
137 | - | ||
138 | }) | 144 | }) |
139 | 145 | ||
140 | // 新增过滤器 | 146 | // 新增过滤器 |
@@ -170,7 +176,7 @@ const saveFilter = () => { | @@ -170,7 +176,7 @@ const saveFilter = () => { | ||
170 | watch( | 176 | watch( |
171 | () => showModal.value, | 177 | () => showModal.value, |
172 | (newData: boolean) => { | 178 | (newData: boolean) => { |
173 | - if (newData) { | 179 | + if (newData) { |
174 | fetchTargetData() | 180 | fetchTargetData() |
175 | filter.value = targetData.value.filter || `return res` | 181 | filter.value = targetData.value.filter || `return res` |
176 | } | 182 | } |