2023-01-06 04:21:27 -05:00
|
|
|
import { isReactive, isRef, toRaw, unref } from 'vue'
|
|
|
|
|
2021-04-05 05:47:06 -04:00
|
|
|
const isDevelopment = process.env.NODE_ENV !== 'production'
|
|
|
|
/* eslint-disable camelcase */
|
2021-04-10 09:01:55 -04:00
|
|
|
export const handleTalkingDataEvent = (data: ITalkingDataOptions) => {
|
|
|
|
const { EventId, Label = '', MapKv = {} } = data
|
|
|
|
MapKv.from = window.location.href
|
|
|
|
window.TDAPP.onEvent(EventId, Label, MapKv)
|
2021-04-05 05:47:06 -04:00
|
|
|
if (isDevelopment) {
|
2021-04-10 09:01:55 -04:00
|
|
|
console.log('talkingData', data)
|
2021-04-05 05:47:06 -04:00
|
|
|
}
|
|
|
|
}
|
2022-06-12 08:20:08 -04:00
|
|
|
|
|
|
|
export const trimValues = (obj: IStringKeyMap) => {
|
|
|
|
const newObj = {} as IStringKeyMap
|
|
|
|
Object.keys(obj).forEach(key => {
|
|
|
|
newObj[key] = typeof obj[key] === 'string' ? obj[key].trim() : obj[key]
|
|
|
|
})
|
|
|
|
return newObj
|
|
|
|
}
|
2023-01-06 04:21:27 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get raw data from reactive or ref
|
|
|
|
*/
|
|
|
|
export const getRawData = (args: any) => {
|
|
|
|
if (Array.isArray(args)) {
|
|
|
|
const data = args.map((item: any) => {
|
|
|
|
if (isRef(item)) {
|
|
|
|
return unref(item)
|
|
|
|
}
|
|
|
|
if (isReactive(item)) {
|
|
|
|
return toRaw(item)
|
|
|
|
}
|
|
|
|
return item
|
|
|
|
})
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
if (typeof args === 'object') {
|
|
|
|
const data = {} as IStringKeyMap
|
|
|
|
Object.keys(args).forEach(key => {
|
|
|
|
const item = args[key]
|
|
|
|
if (isRef(item)) {
|
|
|
|
data[key] = unref(item)
|
|
|
|
} else if (isReactive(item)) {
|
|
|
|
data[key] = toRaw(item)
|
|
|
|
} else {
|
|
|
|
data[key] = getRawData(item)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
return args
|
|
|
|
}
|