mirror of
https://gitee.com/myxzgzs/boyue-ui-admin-vue3
synced 2025-08-08 16:32:43 +08:00
fix: 修复所有函数类型 - 解决设计器保存后函数变成字符串的问题
This commit is contained in:
parent
66e266b7c2
commit
8f88c4a09b
@ -49,14 +49,17 @@ export const setConfAndFields2 = (
|
|||||||
detailPreview = detailPreview.value
|
detailPreview = detailPreview.value
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析配置
|
// 修复所有函数类型(解决设计器保存后函数变成字符串的问题)。例如说:
|
||||||
|
// https://t.zsxq.com/rADff
|
||||||
|
// https://t.zsxq.com/ZfbGt
|
||||||
|
// https://t.zsxq.com/mHOoj
|
||||||
|
// https://t.zsxq.com/BSylB
|
||||||
const option = JSON.parse(conf)
|
const option = JSON.parse(conf)
|
||||||
const rule = decodeFields(fields)
|
const rule = decodeFields(fields)
|
||||||
|
|
||||||
// 🔧 修复所有函数类型 - 解决设计器保存后函数变成字符串的问题
|
// 🔧 修复所有函数类型 - 解决设计器保存后函数变成字符串的问题
|
||||||
const fixFunctions = (obj: any) => {
|
const fixFunctions = (obj: any) => {
|
||||||
if (obj && typeof obj === 'object') {
|
if (obj && typeof obj === 'object') {
|
||||||
Object.keys(obj).forEach(key => {
|
Object.keys(obj).forEach((key) => {
|
||||||
// 检查是否是函数相关的属性
|
// 检查是否是函数相关的属性
|
||||||
if (isFunctionProperty(key)) {
|
if (isFunctionProperty(key)) {
|
||||||
// 如果不是函数类型,重新构建为函数
|
// 如果不是函数类型,重新构建为函数
|
||||||
@ -70,7 +73,6 @@ export const setConfAndFields2 = (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否是函数属性
|
// 判断是否是函数属性
|
||||||
const isFunctionProperty = (key: string): boolean => {
|
const isFunctionProperty = (key: string): boolean => {
|
||||||
const functionKeys = [
|
const functionKeys = [
|
||||||
@ -105,100 +107,73 @@ export const setConfAndFields2 = (
|
|||||||
'renderContent', // 渲染内容
|
'renderContent', // 渲染内容
|
||||||
'render' // 渲染函数
|
'render' // 渲染函数
|
||||||
]
|
]
|
||||||
|
|
||||||
// 检查是否以函数相关前缀开头
|
// 检查是否以函数相关前缀开头
|
||||||
const functionPrefixes = ['on', 'before', 'after', 'handle']
|
const functionPrefixes = ['on', 'before', 'after', 'handle']
|
||||||
|
return functionKeys.includes(key) || functionPrefixes.some((prefix) => key.startsWith(prefix))
|
||||||
return functionKeys.includes(key) ||
|
|
||||||
functionPrefixes.some(prefix => key.startsWith(prefix))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据函数名创建默认函数
|
// 根据函数名创建默认函数
|
||||||
const createDefaultFunction = (key: string): Function => {
|
const createDefaultFunction = (key: string): Function => {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'beforeFetch':
|
case 'beforeFetch':
|
||||||
return (config: any) => {
|
return (config: any) => {
|
||||||
console.log('beforeFetch被调用:', config)
|
|
||||||
|
|
||||||
// 添加认证头
|
// 添加认证头
|
||||||
const token = localStorage.getItem('token')
|
const token = localStorage.getItem('token')
|
||||||
if (token) {
|
if (token) {
|
||||||
config.headers = {
|
config.headers = {
|
||||||
...config.headers,
|
...config.headers,
|
||||||
'Authorization': 'Bearer ' + token
|
Authorization: 'Bearer ' + token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加通用请求头
|
// 添加通用请求头
|
||||||
config.headers = {
|
config.headers = {
|
||||||
...config.headers,
|
...config.headers,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-Requested-With': 'XMLHttpRequest'
|
'X-Requested-With': 'XMLHttpRequest'
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加时间戳防止缓存
|
// 添加时间戳防止缓存
|
||||||
config.params = {
|
config.params = {
|
||||||
...config.params,
|
...config.params,
|
||||||
_t: Date.now()
|
_t: Date.now()
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'afterFetch':
|
case 'afterFetch':
|
||||||
return (data: any) => {
|
return (data: any) => {
|
||||||
console.log('afterFetch被调用:', data)
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'onSubmit':
|
case 'onSubmit':
|
||||||
return (formData: any) => {
|
return (_formData: any) => {
|
||||||
console.log('onSubmit被调用:', formData)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'onReset':
|
case 'onReset':
|
||||||
return () => {
|
return () => {
|
||||||
console.log('onReset被调用')
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'onChange':
|
case 'onChange':
|
||||||
return (value: any, oldValue: any) => {
|
return (_value: any, _oldValue: any) => {}
|
||||||
console.log('onChange被调用:', { value, oldValue })
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'remoteMethod':
|
case 'remoteMethod':
|
||||||
return (query: string) => {
|
return (query: string) => {
|
||||||
console.log('remoteMethod被调用:', query)
|
console.log('remoteMethod被调用:', query)
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'parseFunc':
|
case 'parseFunc':
|
||||||
return (data: any) => {
|
return (data: any) => {
|
||||||
console.log('parseFunc被调用:', data)
|
|
||||||
// 默认解析逻辑:如果是数组直接返回,否则尝试获取list属性
|
// 默认解析逻辑:如果是数组直接返回,否则尝试获取list属性
|
||||||
if (Array.isArray(data)) {
|
if (Array.isArray(data)) {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
return data?.list || data?.data || []
|
return data?.list || data?.data || []
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'validator':
|
case 'validator':
|
||||||
return (rule: any, value: any, callback: Function) => {
|
return (_rule: any, _value: any, callback: Function) => {
|
||||||
console.log('validator被调用:', { rule, value })
|
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'beforeUpload':
|
case 'beforeUpload':
|
||||||
return (file: any) => {
|
return (_file: any) => {
|
||||||
console.log('beforeUpload被调用:', file)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// 通用默认函数
|
// 通用默认函数
|
||||||
return (...args: any[]) => {
|
return (...args: any[]) => {
|
||||||
console.log(`${key}被调用:`, args)
|
|
||||||
// 对于事件处理函数,返回true表示继续执行
|
// 对于事件处理函数,返回true表示继续执行
|
||||||
if (key.startsWith('on') || key.startsWith('handle')) {
|
if (key.startsWith('on') || key.startsWith('handle')) {
|
||||||
return true
|
return true
|
||||||
@ -208,10 +183,8 @@ export const setConfAndFields2 = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修复 option 中的所有函数
|
// 修复 option 中的所有函数
|
||||||
fixFunctions(option)
|
fixFunctions(option)
|
||||||
|
|
||||||
// 修复 rule 中的所有函数(包括组件的 props)
|
// 修复 rule 中的所有函数(包括组件的 props)
|
||||||
if (Array.isArray(rule)) {
|
if (Array.isArray(rule)) {
|
||||||
rule.forEach((item: any) => {
|
rule.forEach((item: any) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user