| 137 | |
| 138 | // 对data的dataList去重 |
| 139 | function uniqueData(liveList) { |
| 140 | |
| 141 | const allItems = [] |
| 142 | // 提取全部dataList |
| 143 | liveList.forEach(category => { |
| 144 | category.dataList.forEach(program => { |
| 145 | |
| 146 | allItems.push({ |
| 147 | ...program, |
| 148 | categoryName: category.name |
| 149 | }) |
| 150 | }) |
| 151 | |
| 152 | }) |
| 153 | |
| 154 | // 使用set确保唯一 |
| 155 | const set = new Set() |
| 156 | // 保存唯一的数据 |
| 157 | const uniqueItem = [] |
| 158 | |
| 159 | allItems.forEach(item => { |
| 160 | // set用来确定已经出现过 |
| 161 | if (!set.has(item.name)) { |
| 162 | set.add(item.name) |
| 163 | uniqueItem.push(item) |
| 164 | } |
| 165 | }) |
| 166 | |
| 167 | const categoryMap = [] |
| 168 | |
| 169 | // 清空原dataList内容 |
| 170 | liveList.forEach(live => { |
| 171 | live.dataList = [] |
| 172 | categoryMap[live.name] = [] |
| 173 | }) |
| 174 | |
| 175 | // 去除添加字段,根据分类填充内容 |
| 176 | uniqueItem.forEach(item => { |
| 177 | const { categoryName, ...program } = item |
| 178 | categoryMap[categoryName].push(program) |
| 179 | }) |
| 180 | |
| 181 | // liveList赋值 |
| 182 | liveList.forEach(live => { |
| 183 | live.dataList = categoryMap[live.name] |
| 184 | }) |
| 185 | |
| 186 | return liveList |
| 187 | } |
| 188 | |
| 189 | export { cateList, dataList, delay } |