Commit 878554991ee238921c8b83ed1fd21fbd36075c4c
Merge branch 'dev-ww' into 'main_dev'
fix: 修复teambition bug See merge request yunteng/thingskit-view!45
Showing
5 changed files
with
67 additions
and
10 deletions
@@ -26,7 +26,7 @@ export const useFetchTargetData = () => { | @@ -26,7 +26,7 @@ export const useFetchTargetData = () => { | ||
26 | } catch (error) { | 26 | } catch (error) { |
27 | loading.value = false | 27 | loading.value = false |
28 | console.error(error); | 28 | console.error(error); |
29 | - window['$message'].warning('数据异常,请检查参数!') | 29 | + // window['$message'].warning('数据异常,请检查参数!') |
30 | } | 30 | } |
31 | } | 31 | } |
32 | return { fetchTargetData, loading } | 32 | return { fetchTargetData, loading } |
src/utils/external/utils.ts
0 → 100644
1 | +import { excludeParseEventKeyList, excludeParseEventValueList } from "@/enums/eventEnum" | ||
2 | + | ||
3 | +const tryRunFunction = (v: string) => { | ||
4 | + try { | ||
5 | + return eval(`(function(){return ${v}})()`) | ||
6 | + } catch (error) { | ||
7 | + return v | ||
8 | + } | ||
9 | +} | ||
10 | + | ||
11 | +export const JSONParse = (data: string) => { | ||
12 | + return JSON.parse(data, (k, v) => { | ||
13 | + // 过滤函数字符串 | ||
14 | + if (excludeParseEventKeyList.includes(k)) return v | ||
15 | + // 过滤函数值表达式 | ||
16 | + if (typeof v === 'string') { | ||
17 | + const someValue = excludeParseEventValueList.some(excludeValue => v.indexOf(excludeValue) > -1) | ||
18 | + if (someValue) return v | ||
19 | + } | ||
20 | + // 还原函数值 | ||
21 | + if (typeof v === 'string' && v.indexOf && (v.indexOf('function') > -1 || v.indexOf('=>') > -1)) { | ||
22 | + return tryRunFunction(v) | ||
23 | + } else if (typeof v === 'string' && v.indexOf && v.indexOf('return ') > -1) { | ||
24 | + const baseLeftIndex = v.indexOf('(') | ||
25 | + if (baseLeftIndex > -1) { | ||
26 | + const newFn = `function ${v.substring(baseLeftIndex)}` | ||
27 | + return tryRunFunction(newFn) | ||
28 | + } | ||
29 | + } | ||
30 | + return v | ||
31 | + }) | ||
32 | +} |
@@ -12,6 +12,9 @@ import { RequestHttpIntervalEnum, RequestParamsObjType } from '@/enums/httpEnum' | @@ -12,6 +12,9 @@ import { RequestHttpIntervalEnum, RequestParamsObjType } from '@/enums/httpEnum' | ||
12 | import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d' | 12 | import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d' |
13 | import { excludeParseEventKeyList, excludeParseEventValueList } from '@/enums/eventEnum' | 13 | import { excludeParseEventKeyList, excludeParseEventValueList } from '@/enums/eventEnum' |
14 | 14 | ||
15 | +/// THINGS_KIT 替换JSONParse解析 | ||
16 | +export { JSONParse } from './external/utils' | ||
17 | + | ||
15 | /** | 18 | /** |
16 | * * 判断是否是开发环境 | 19 | * * 判断是否是开发环境 |
17 | * @return { Boolean } | 20 | * @return { Boolean } |
@@ -127,11 +130,11 @@ export const fileToUrl = (file: File): string => { | @@ -127,11 +130,11 @@ export const fileToUrl = (file: File): string => { | ||
127 | * * file转base64 | 130 | * * file转base64 |
128 | */ | 131 | */ |
129 | export const fileTobase64 = (file: File, callback: Function) => { | 132 | export const fileTobase64 = (file: File, callback: Function) => { |
130 | - let reader = new FileReader() | 133 | + const reader = new FileReader() |
131 | reader.readAsDataURL(file) | 134 | reader.readAsDataURL(file) |
132 | reader.onload = function (e: ProgressEvent<FileReader>) { | 135 | reader.onload = function (e: ProgressEvent<FileReader>) { |
133 | if (e.target) { | 136 | if (e.target) { |
134 | - let base64 = e.target.result | 137 | + const base64 = e.target.result |
135 | callback(base64) | 138 | callback(base64) |
136 | } | 139 | } |
137 | } | 140 | } |
@@ -318,7 +321,8 @@ export const JSONStringify = <T>(data: T) => { | @@ -318,7 +321,8 @@ export const JSONStringify = <T>(data: T) => { | ||
318 | * * JSON反序列化,支持函数和 undefined | 321 | * * JSON反序列化,支持函数和 undefined |
319 | * @param data | 322 | * @param data |
320 | */ | 323 | */ |
321 | -export const JSONParse = (data: string) => { | 324 | +/// THINGS_KIT 重命名 JSONParse 为 JSONParseOriginal |
325 | +export const JSONParseOriginal = (data: string) => { | ||
322 | return JSON.parse(data, (k, v) => { | 326 | return JSON.parse(data, (k, v) => { |
323 | // 过滤函数字符串 | 327 | // 过滤函数字符串 |
324 | if (excludeParseEventKeyList.includes(k)) return v | 328 | if (excludeParseEventKeyList.includes(k)) return v |
@@ -347,4 +351,4 @@ export const JSONParse = (data: string) => { | @@ -347,4 +351,4 @@ export const JSONParse = (data: string) => { | ||
347 | */ | 351 | */ |
348 | export const setTitle = (title?: string) => { | 352 | export const setTitle = (title?: string) => { |
349 | title && (document.title = title) | 353 | title && (document.title = title) |
350 | -} | ||
354 | +} |
@@ -29,10 +29,7 @@ const designStore = useDesignStore() | @@ -29,10 +29,7 @@ const designStore = useDesignStore() | ||
29 | * 修改后的代码 const selectedRequestType = ref(targetData.value.request.requestDataType || RequestDataTypeEnum.Pond) | 29 | * 修改后的代码 const selectedRequestType = ref(targetData.value.request.requestDataType || RequestDataTypeEnum.Pond) |
30 | * 修改后代码在//ft之间 | 30 | * 修改后代码在//ft之间 |
31 | */ | 31 | */ |
32 | - | ||
33 | const selectedRequestType = ref(targetData.value.request.requestDataType || RequestDataTypeEnum.Pond) | 32 | const selectedRequestType = ref(targetData.value.request.requestDataType || RequestDataTypeEnum.Pond) |
34 | -console.log(targetData.value.request.requestDataType) | ||
35 | -//ft | ||
36 | 33 | ||
37 | const getApiRequestType: SelectOption[] = [ | 34 | const getApiRequestType: SelectOption[] = [ |
38 | { label: '自定义请求', value: RequestDataTypeEnum.AJAX }, | 35 | { label: '自定义请求', value: RequestDataTypeEnum.AJAX }, |
@@ -50,7 +47,10 @@ const { fetchTargetData, } = useFetchTargetData() | @@ -50,7 +47,10 @@ const { fetchTargetData, } = useFetchTargetData() | ||
50 | 47 | ||
51 | // 发送请求 | 48 | // 发送请求 |
52 | const sendHandle = async () => { | 49 | const sendHandle = async () => { |
53 | - if (!targetData.value?.request) return | 50 | + if (!targetData.value?.request || !targetData.value.request.requestUrl) { |
51 | + window['$message'].warning('请先配置请求') | ||
52 | + return | ||
53 | + } | ||
54 | loading.value = true | 54 | loading.value = true |
55 | try { | 55 | try { |
56 | const res = await fetchTargetData() | 56 | const res = await fetchTargetData() |
@@ -11,6 +11,9 @@ import { PublicInterfaceForm } from '../PublicInterfaceForm'; | @@ -11,6 +11,9 @@ import { PublicInterfaceForm } from '../PublicInterfaceForm'; | ||
11 | import ComponentConfiguration from './ComponentConfiguration.vue'; | 11 | import ComponentConfiguration from './ComponentConfiguration.vue'; |
12 | import GlobalPublicConfiguration from './GlobalPublicConfiguration.vue'; | 12 | import GlobalPublicConfiguration from './GlobalPublicConfiguration.vue'; |
13 | import { createRequestModalContext } from './useRequestModalContext'; | 13 | import { createRequestModalContext } from './useRequestModalContext'; |
14 | +import { useTargetData } from '../../../../hooks/useTargetData.hook'; | ||
15 | +import { useFetchTargetData } from '@/hooks/external/useFetchTargetData'; | ||
16 | +import { useFilterFn } from '@/hooks/external/useFilterFn'; | ||
14 | 17 | ||
15 | 18 | ||
16 | const requestDataType = ref<RequestDataTypeEnum>(RequestDataTypeEnum.AJAX) | 19 | const requestDataType = ref<RequestDataTypeEnum>(RequestDataTypeEnum.AJAX) |
@@ -67,9 +70,26 @@ const getResult = () => { | @@ -67,9 +70,26 @@ const getResult = () => { | ||
67 | return {} as unknown as RequestConfigType | 70 | return {} as unknown as RequestConfigType |
68 | } | 71 | } |
69 | 72 | ||
73 | +const { targetData } = useTargetData() | ||
74 | +const { fetchTargetData } = useFetchTargetData() | ||
75 | +// 发送请求 | ||
76 | +const sendHandle = async () => { | ||
77 | + if (!targetData.value?.request || !targetData.value.request.requestUrl) { | ||
78 | + window['$message'].warning('请先配置请求') | ||
79 | + return | ||
80 | + } | ||
81 | + const res = await fetchTargetData() | ||
82 | + if (res) { | ||
83 | + const { value } = useFilterFn(targetData.value.filter, res) | ||
84 | + targetData.value.option.dataset = value | ||
85 | + return | ||
86 | + } | ||
87 | + | ||
88 | +} | ||
89 | + | ||
70 | const handleSaveAction = async () => { | 90 | const handleSaveAction = async () => { |
71 | if (!(await validate())) return | 91 | if (!(await validate())) return |
72 | - const value = getResult() | 92 | + const value = getResult() |
73 | if (unref(selectTarget)) { | 93 | if (unref(selectTarget)) { |
74 | chartEditStore.updateComponentList(chartEditStore.fetchTargetIndex(), { | 94 | chartEditStore.updateComponentList(chartEditStore.fetchTargetIndex(), { |
75 | ...unref(selectTarget)!, | 95 | ...unref(selectTarget)!, |
@@ -77,6 +97,7 @@ const handleSaveAction = async () => { | @@ -77,6 +97,7 @@ const handleSaveAction = async () => { | ||
77 | }) | 97 | }) |
78 | } | 98 | } |
79 | showModal.value = false | 99 | showModal.value = false |
100 | + sendHandle() | ||
80 | } | 101 | } |
81 | 102 | ||
82 | createRequestModalContext({ | 103 | createRequestModalContext({ |