Commit 878554991ee238921c8b83ed1fd21fbd36075c4c

Authored by xp.Huang
2 parents 3ef920cb 554ed39b

Merge branch 'dev-ww' into 'main_dev'

fix: 修复teambition bug

See merge request yunteng/thingskit-view!45
... ... @@ -26,7 +26,7 @@ export const useFetchTargetData = () => {
26 26 } catch (error) {
27 27 loading.value = false
28 28 console.error(error);
29   - window['$message'].warning('数据异常,请检查参数!')
  29 + // window['$message'].warning('数据异常,请检查参数!')
30 30 }
31 31 }
32 32 return { fetchTargetData, loading }
... ...
  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 12 import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d'
13 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 20 * @return { Boolean }
... ... @@ -127,11 +130,11 @@ export const fileToUrl = (file: File): string => {
127 130 * * file转base64
128 131 */
129 132 export const fileTobase64 = (file: File, callback: Function) => {
130   - let reader = new FileReader()
  133 + const reader = new FileReader()
131 134 reader.readAsDataURL(file)
132 135 reader.onload = function (e: ProgressEvent<FileReader>) {
133 136 if (e.target) {
134   - let base64 = e.target.result
  137 + const base64 = e.target.result
135 138 callback(base64)
136 139 }
137 140 }
... ... @@ -318,7 +321,8 @@ export const JSONStringify = <T>(data: T) => {
318 321 * * JSON反序列化,支持函数和 undefined
319 322 * @param data
320 323 */
321   -export const JSONParse = (data: string) => {
  324 +/// THINGS_KIT 重命名 JSONParse 为 JSONParseOriginal
  325 +export const JSONParseOriginal = (data: string) => {
322 326 return JSON.parse(data, (k, v) => {
323 327 // 过滤函数字符串
324 328 if (excludeParseEventKeyList.includes(k)) return v
... ... @@ -347,4 +351,4 @@ export const JSONParse = (data: string) => {
347 351 */
348 352 export const setTitle = (title?: string) => {
349 353 title && (document.title = title)
350   -}
\ No newline at end of file
  354 +}
... ...
... ... @@ -29,10 +29,7 @@ const designStore = useDesignStore()
29 29 * 修改后的代码 const selectedRequestType = ref(targetData.value.request.requestDataType || RequestDataTypeEnum.Pond)
30 30 * 修改后代码在//ft之间
31 31 */
32   -
33 32 const selectedRequestType = ref(targetData.value.request.requestDataType || RequestDataTypeEnum.Pond)
34   -console.log(targetData.value.request.requestDataType)
35   -//ft
36 33
37 34 const getApiRequestType: SelectOption[] = [
38 35 { label: '自定义请求', value: RequestDataTypeEnum.AJAX },
... ... @@ -50,7 +47,10 @@ const { fetchTargetData, } = useFetchTargetData()
50 47
51 48 // 发送请求
52 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 54 loading.value = true
55 55 try {
56 56 const res = await fetchTargetData()
... ...
... ... @@ -11,6 +11,9 @@ import { PublicInterfaceForm } from '../PublicInterfaceForm';
11 11 import ComponentConfiguration from './ComponentConfiguration.vue';
12 12 import GlobalPublicConfiguration from './GlobalPublicConfiguration.vue';
13 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 19 const requestDataType = ref<RequestDataTypeEnum>(RequestDataTypeEnum.AJAX)
... ... @@ -67,9 +70,26 @@ const getResult = () => {
67 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 90 const handleSaveAction = async () => {
71 91 if (!(await validate())) return
72   - const value = getResult()
  92 + const value = getResult()
73 93 if (unref(selectTarget)) {
74 94 chartEditStore.updateComponentList(chartEditStore.fetchTargetIndex(), {
75 95 ...unref(selectTarget)!,
... ... @@ -77,6 +97,7 @@ const handleSaveAction = async () => {
77 97 })
78 98 }
79 99 showModal.value = false
  100 + sendHandle()
80 101 }
81 102
82 103 createRequestModalContext({
... ...