修改测试问题
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="组件图标" prop="icon">
|
||||
<el-form-item label="组件图标">
|
||||
<IconSelector v-model="form.icon" placeholder="请选择图标" />
|
||||
</el-form-item>
|
||||
<el-form-item class="top" label="组件标识" prop="code">
|
||||
@@ -42,17 +42,7 @@
|
||||
<el-checkbox-button value="5">日</el-checkbox-button>
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
<el-form-item class="top" label="组件绑定系统" prop="systemIds">
|
||||
<el-select
|
||||
v-model="form.systemIds"
|
||||
multiple
|
||||
collapse-tags
|
||||
collapse-tags-tooltip
|
||||
placeholder="请选择组件绑定系统"
|
||||
>
|
||||
<el-option v-for="item in systemList" :key="item.id" :label="item.name" :value="item.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item class="top" label="组件排序" prop="sort">
|
||||
<el-input v-model.number="form.sort" placeholder="请输入组件排序"></el-input>
|
||||
</el-form-item>
|
||||
@@ -103,7 +93,6 @@ const form = ref<anyObj>({
|
||||
system: [],
|
||||
timeKeys: ['1', '2', '3', '4', '5'],
|
||||
code: '',
|
||||
systemIds: [],
|
||||
path: ''
|
||||
})
|
||||
const props = { label: 'name', value: 'id', multiple: true }
|
||||
@@ -114,36 +103,48 @@ const rules = {
|
||||
icon: [{ required: true, message: '请先择组件图标', trigger: 'change' }],
|
||||
path: [{ required: true, message: '请输入组件路径', trigger: 'blur' }],
|
||||
sort: [{ required: true, message: '请输入排序', trigger: 'blur' }],
|
||||
timeKeys: [{ required: true, message: '请选择组件查询时间', trigger: 'change' }],
|
||||
systemIds: [{ required: true, message: '请选择组件绑定系统', trigger: 'change' }]
|
||||
timeKeys: [{ required: true, message: '请选择组件查询时间', trigger: 'change' }]
|
||||
}
|
||||
const customDeptOption: any = ref([])
|
||||
const systemList = dictData.getBasicData('System_Type')
|
||||
onMounted(() => {
|
||||
customDeptOption.value = dictData.getBasicData('Component_Type')
|
||||
onMounted(() => {})
|
||||
const getSystem = async () => {
|
||||
// customDeptOption.value = dictData.getBasicData('System_Type')
|
||||
// await customDeptOption.value.forEach((item: any) => {
|
||||
// getFatherComponent({ systemType: item.id }).then(res => {
|
||||
// item.children = res.data.filter(item => item.name != '无')
|
||||
// })
|
||||
// })
|
||||
customDeptOption.value = dictData.getBasicData('System_Type')
|
||||
|
||||
customDeptOption.value.forEach((item: any) => {
|
||||
getFatherComponent({ systemType: item.id }).then(res => {
|
||||
item.children = res.data.filter(item => item.name != '无')
|
||||
})
|
||||
// 创建所有异步请求的 Promise 数组
|
||||
const promises = customDeptOption.value.map(async (item: any) => {
|
||||
try {
|
||||
const res = await getFatherComponent({ systemType: item.id })
|
||||
item.children = res.data.sort((a, b) => a.sort - b.sort)
|
||||
} catch (error) {
|
||||
console.error('加载组件失败:', error)
|
||||
item.children = []
|
||||
}
|
||||
})
|
||||
})
|
||||
// 等待所有请求完成
|
||||
await Promise.all(promises)
|
||||
// 所有 children 数据都已加载完成
|
||||
return customDeptOption.value
|
||||
}
|
||||
|
||||
const open = (text: string, data?: anyObj) => {
|
||||
console.log(data)
|
||||
const open = async (text: string, data?: anyObj) => {
|
||||
title.value = text
|
||||
dialogVisible.value = true
|
||||
await getSystem()
|
||||
if (data) {
|
||||
let Data = JSON.parse(JSON.stringify(data))
|
||||
form.value = Data
|
||||
form.value.system = [Data.systemType, Data.pid]
|
||||
// form.value.timeKeys = Data.timeKeys.split(',').map(Number)
|
||||
form.value.system = getSystemComponentPairs(customDeptOption.value, Data.componentType)
|
||||
|
||||
form.value.timeKeys = Data.timeKeys || []
|
||||
}
|
||||
}
|
||||
const submit = () => {
|
||||
console.log('🚀 ~ submit ~ form.value:', form.value)
|
||||
|
||||
formRef.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
let url = ''
|
||||
@@ -168,11 +169,9 @@ const submit = () => {
|
||||
if (title.value == '新增组件') {
|
||||
await componentAdd({
|
||||
...form.value,
|
||||
systemType: form.value.system
|
||||
.map(subArr => (subArr.length > 1 ? subArr.at(-1) : null))
|
||||
.filter(item => item !== null),
|
||||
// systemType: form.value.system[0],
|
||||
pid: form.value.system[1],
|
||||
systemType: formatFirstIdToString(form.value.system, 0),
|
||||
componentType: formatFirstIdToString(form.value.system, 1),
|
||||
pid: '123',
|
||||
image: url
|
||||
}).then(res => {
|
||||
ElMessage.success('新增成功!')
|
||||
@@ -182,11 +181,9 @@ const submit = () => {
|
||||
} else {
|
||||
await componentEdit({
|
||||
...form.value,
|
||||
// systemType: form.value.system[0],
|
||||
systemType: form.value.system
|
||||
.map(subArr => (subArr.length > 1 ? subArr.at(-1) : null))
|
||||
.filter(item => item !== null),
|
||||
pid: form.value.system[1],
|
||||
systemType: formatFirstIdToString(form.value.system, 0),
|
||||
componentType: formatFirstIdToString(form.value.system, 1),
|
||||
pid: '123',
|
||||
image: url
|
||||
}).then(res => {
|
||||
ElMessage.success('修改成功!')
|
||||
@@ -199,6 +196,41 @@ const submit = () => {
|
||||
}
|
||||
})
|
||||
}
|
||||
// 处理函数:提取子数组第一个元素 + 去重 + 拼接
|
||||
const formatFirstIdToString = (data: any, num: number) => {
|
||||
// 1. 提取每个子数组的第一个元素
|
||||
const firstIds = data.map(item => item[num])
|
||||
// 2. 去重(利用Set特性)
|
||||
const uniqueFirstIds = [...new Set(firstIds)]
|
||||
// 3. 拼接成逗号分隔的字符串
|
||||
return uniqueFirstIds.join(',')
|
||||
}
|
||||
// 根据id 找二位数组回显
|
||||
function getSystemComponentPairs(data: any, idsStr: string) {
|
||||
const targetIds = idsStr.split(',')
|
||||
const result: any[] = []
|
||||
|
||||
// 遍历所有数据
|
||||
data.forEach(system => {
|
||||
const systemId = system.id
|
||||
const children = system.children || []
|
||||
|
||||
// 在children中查找匹配的ID
|
||||
children.forEach(child => {
|
||||
if (targetIds.includes(child.id)) {
|
||||
result.push([systemId, child.id])
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// 按照提供的ID顺序排序
|
||||
return result.sort((a, b) => {
|
||||
const indexA = targetIds.indexOf(a[1])
|
||||
const indexB = targetIds.indexOf(b[1])
|
||||
return indexA - indexB
|
||||
})
|
||||
}
|
||||
|
||||
// 组件映射
|
||||
const componentMap = reactive(new Map<string, Component | string>())
|
||||
// 动态注册组件
|
||||
|
||||
Reference in New Issue
Block a user