| 151 | |
| 152 | // 处理分组数据 |
| 153 | export const processGroupsData = (data, userGroup) => { |
| 154 | let groupOptions = Object.entries(data).map(([group, info]) => ({ |
| 155 | label: info.desc.length > 20 ? info.desc.substring(0, 20) + '...' : info.desc, |
| 156 | value: group, |
| 157 | ratio: info.ratio, |
| 158 | fullLabel: info.desc, |
| 159 | })); |
| 160 | |
| 161 | if (groupOptions.length === 0) { |
| 162 | groupOptions = [{ |
| 163 | label: '用户分组', |
| 164 | value: '', |
| 165 | ratio: 1, |
| 166 | }]; |
| 167 | } else if (userGroup) { |
| 168 | const userGroupIndex = groupOptions.findIndex(g => g.value === userGroup); |
| 169 | if (userGroupIndex > -1) { |
| 170 | const userGroupOption = groupOptions.splice(userGroupIndex, 1)[0]; |
| 171 | groupOptions.unshift(userGroupOption); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | return groupOptions; |
| 176 | }; |
| 177 | |
| 178 | // 原来components中的utils.js |
| 179 | |