修改
This commit is contained in:
@ -125,6 +125,7 @@ const updateEvent = () => {
|
|||||||
TsApi.updateTsEvent(obj).then(res => {
|
TsApi.updateTsEvent(obj).then(res => {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
|
eventBus.emit('update-event', obj)
|
||||||
ElMessage({type: "success", message: "操作成功"})
|
ElMessage({type: "success", message: "操作成功"})
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -437,6 +437,9 @@ let getEventList = () => {
|
|||||||
})
|
})
|
||||||
newTS(params, events)
|
newTS(params, events)
|
||||||
}
|
}
|
||||||
|
eventBus.on('update-event', (task) => {
|
||||||
|
tsOBJ.value._Store._tasks = tsOBJ.value.replaceArrayItem(tsOBJ.value._Store._tasks, task)
|
||||||
|
})
|
||||||
eventBus.on('delete-event', (ids) => {
|
eventBus.on('delete-event', (ids) => {
|
||||||
tsOBJ.value._Store._tasks = tsOBJ.value._Store._tasks.filter(item => !ids.includes(item.id))
|
tsOBJ.value._Store._tasks = tsOBJ.value._Store._tasks.filter(item => !ids.includes(item.id))
|
||||||
|
|
||||||
|
|||||||
@ -80,4 +80,29 @@ export class TS extends Tools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 替换对象数组中指定的元素(通过id匹配)
|
||||||
|
* @param {Array} arr - 原始对象数组,元素结构需包含id属性
|
||||||
|
* @param {Object} newItem - 要替换的新对象(必须包含id属性)
|
||||||
|
* @param {string} [key='id'] - 匹配的唯一标识字段(默认使用id)
|
||||||
|
* @returns {Array} - 返回替换后的新数组(原数组不会被修改)
|
||||||
|
*/
|
||||||
|
replaceArrayItem(arr, newItem, key = 'id') {
|
||||||
|
// 边界校验
|
||||||
|
if (!Array.isArray(arr)) {
|
||||||
|
console.error('第一个参数必须是数组');
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
if (typeof newItem !== 'object' || newItem === null || !newItem[key]) {
|
||||||
|
console.error(`新元素必须是包含${key}属性的对象`);
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遍历数组并替换匹配的元素(返回新数组,避免修改原数组)
|
||||||
|
return arr.map(item => {
|
||||||
|
// 匹配到对应id的元素则替换,否则返回原元素
|
||||||
|
return item[key] === newItem[key] ? {...item, ...newItem} : item;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user