import type { SpecialTag, Track, ColorMap } from "@/types"; export default function useTrack() { function addTrackColorAttr(tList: Track[]): Track[] { let markerIds: (number | undefined)[] = tList .map((v) => v.userId) .filter((x) => !!x); markerIds = Array.from(new Set(markerIds)); // markerIds.sort(); const colorMap: ColorMap = {}; for (let i = 0; i < markerIds.length; i++) { const mId: any = markerIds[i]; if (i == 0) { colorMap[mId + ""] = "red"; } else if (i == 1) { colorMap[mId + ""] = "blue"; } else if (i > 1) { colorMap[mId + ""] = "gray"; } } if (Object.keys(colorMap).length > 1) { emit("getIsMultComments", true); } tList = tList.map((item: Track) => { item.color = colorMap[item.userId + ""] || "red"; item.isByMultMark = markerIds.length > 1; return item; }); return tList; } function addTagColorAttr(tList: SpecialTag[]): SpecialTag[] { let markerIds: (number | undefined)[] = tList .map((v) => v.userId) .filter((x) => !!x); markerIds = Array.from(new Set(markerIds)); // markerIds.sort(); const colorMap: ColorMap = {}; for (let i = 0; i < markerIds.length; i++) { const mId: any = markerIds[i]; if (i == 0) { colorMap[mId + ""] = "red"; } else if (i == 1) { colorMap[mId + ""] = "blue"; } else if (i > 1) { colorMap[mId + ""] = "gray"; } } tList = tList.map((item: SpecialTag) => { item.color = colorMap[item.userId + ""] || "red"; item.isByMultMark = markerIds.length > 1; return item; }); return tList; } function addHeaderTrackColorAttr(headerTrackList: Track[]): Track[] { return headerTrackList.map((item: Track) => { item.color = "green"; return item; }); } return { addTrackColorAttr, addTagColorAttr, addHeaderTrackColorAttr, }; }