/*
|
* @Author: Liuyi candymxq888@outlook.com
|
* @Date: 2024-08-06 14:47:41
|
* @LastEditors: Liuyi candymxq888@outlook.com
|
* @LastEditTime: 2024-08-15 11:15:57
|
* @FilePath: \water-qinghe-web\src\utils\methods.js
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
*/
|
//将没有层级的对象列表传为树形,树形节点标识为parentId
|
export const listToTree = (data) => {
|
const tree = {};
|
|
// 遍历数据数组
|
data.forEach((item) => {
|
const { id, parentId } = item;
|
|
if (!tree[id]) {
|
tree[id] = { ...item, children: [] }; // 创建节点
|
} else {
|
tree[id] = { ...tree[id], ...item }; // 更新节点
|
}
|
|
if (parentId !== id) {
|
if (!tree[parentId]) {
|
tree[parentId] = { children: [] }; // 创建父节点
|
}
|
tree[parentId].children.push(tree[id]); // 将子节点添加到父节点的 children 中
|
}
|
});
|
// 找到根节点
|
const rootIds = Object.keys(tree).filter(idx => tree[idx].parentId === 0 || tree[idx].parentId === 40);
|
const root = rootIds.map(idx => tree[idx]);
|
console.log('tree', tree, rootIds, root)
|
return root;
|
}
|
//设置图片路径
|
import { PREURL } from '@/config/index'
|
export const getImage = (imgList) =>{
|
if(imgList != null){
|
return imgList.split(',').map((image) => {
|
if(image.indexOf('http') == -1 && image != ''){
|
return PREURL + image
|
}else {
|
return image
|
}
|
})
|
}
|
}
|
export const setImage = (imgList) =>{
|
return imgList.map((image) => {
|
if(image.indexOf(PREURL) != -1){
|
return image.replace(PREURL,'')
|
}else {
|
return image
|
}
|
})
|
}
|