| | |
| | | }); |
| | | const list = Array.isArray(resp) ? resp : resp?.records || []; |
| | | const names = list |
| | | .map((item: any) => item?.realname || item?.username || item?.nickName || '') |
| | | .map((item: any) => item?.username || item?.realname || item?.nickName || '') |
| | | .filter((name: string) => typeof name === 'string' && name.trim() !== ''); |
| | | return Array.from(new Set(names)); |
| | | } catch (error) { |
| | |
| | | const collectFromArray = (arr: any[]): string[] => { |
| | | const names: string[] = []; |
| | | arr.forEach((item) => { |
| | | if (!item) return; |
| | | if (item === null || item === undefined) return; |
| | | if (typeof item === 'string') { |
| | | names.push(item.trim()); |
| | | } else if (typeof item === 'number') { |
| | | // 数字也转换为字符串显示 |
| | | names.push(String(item)); |
| | | } else if (Array.isArray(item)) { |
| | | names.push(...collectFromArray(item)); |
| | | } else if (typeof item === 'object') { |
| | |
| | | if (typeof name === 'string' && name.trim() !== '') { |
| | | names.push(name.trim()); |
| | | } |
| | | } else { |
| | | // 其他类型也转换为字符串 |
| | | names.push(String(item)); |
| | | } |
| | | }); |
| | | return names; |
| | |
| | | try { |
| | | const parsed = JSON.parse(trimmed); |
| | | if (Array.isArray(parsed)) { |
| | | return collectFromArray(parsed); |
| | | // 不过滤,接口返回什么就展示什么,将所有值转换为字符串 |
| | | return parsed.map((item) => String(item)).filter((item) => item.trim() !== ''); |
| | | } |
| | | } catch (e) { |
| | | // 不是标准 JSON,再按逗号分割 |
| | |
| | | .slice(1, -1) |
| | | .split(',') |
| | | .map((token) => token.trim().replace(/^['"]|['"]$/g, '')); |
| | | return tokens.filter((token) => token && isNaN(Number(token))); |
| | | // 不过滤,返回所有token |
| | | return tokens.filter((token) => token !== ''); |
| | | } |
| | | return []; |
| | | }; |
| | |
| | | }, |
| | | { isTransformResponse: false, errorMessageMode: 'none' } |
| | | ); |
| | | const namesSource = |
| | | (Array.isArray(resp) && resp) || |
| | | (Array.isArray(resp?.records) && resp.records) || |
| | | (Array.isArray(resp?.result?.records) && resp.result.records) || |
| | | (Array.isArray(resp?.result) && resp.result) || |
| | | resp?.result || |
| | | resp?.message || |
| | | []; |
| | | const names = Array.from(new Set(normalizeCustomerNames(namesSource))).filter((name) => name && name.trim() !== ''); |
| | | // 优先处理 result 字段,如果 result 是字符串格式的数组,需要解析 |
| | | let namesSource: any = null; |
| | | if (Array.isArray(resp)) { |
| | | namesSource = resp; |
| | | } else if (Array.isArray(resp?.records)) { |
| | | namesSource = resp.records; |
| | | } else if (Array.isArray(resp?.result?.records)) { |
| | | namesSource = resp.result.records; |
| | | } else if (Array.isArray(resp?.result)) { |
| | | namesSource = resp.result; |
| | | } else if (resp?.result) { |
| | | namesSource = resp.result; |
| | | } else if (resp?.message) { |
| | | namesSource = resp.message; |
| | | } else { |
| | | namesSource = []; |
| | | } |
| | | const names = normalizeCustomerNames(namesSource); |
| | | customers.value = names.map((n) => ({ value: n as string, label: n as string })); |
| | | selectedCustomer.value = null; |
| | | // 清空下游 |
| | |
| | | if (isAgent) { |
| | | const resp = await contractList({ |
| | | // 代理客户模式下,根据选中的代理商 + 客户名称筛选合同 |
| | | agentsName: selectedAgent.value, |
| | | customerName: selectedCustomer.value, |
| | | // customerName, |
| | | // agentSales: currentCreateBy.value, |
| | | pageNo: 1, |