import{request as e}from"@cqsjjb/jjb-common-lib/http.js";import{useState as o}from"react";import{UPLOAD_FILE_TYPE_ENUM as r}from"../../enum/uploadFile/gwj/index.js";import{addingPrefixToFile as i}from"../../utils/index.js";function n(n="object"){const[t,l]=o(!1);let s=0;const a=o=>{if(o)return s++,s>0&&l(!0),new Promise((n,t)=>{const{eqType:a,eqForeignKey:c,single:p=!0,foreignKey:f,dataSource:g}=o;if(!a)return void console.error("【getFile】 缺少 options.eqType 参数");if(!Object.values(r).includes(a))return void console.error(`【getFile】 传入的 eqType 不在 UPLOAD_FILE_TYPE_ENUM 中，当前传入的 eqType 是 ${a}`);if(p){if(null==c||""===c)return void console.error("【getFile】 缺少 options.eqForeignKey 参数")}else{if(null==f||""===f)return void console.error("【getFile】 缺少 options.foreignKey 参数");if(null==g||""===g)return void console.error("【getFile】 缺少 options.dataSource 参数");if(0===g.length)return l(!1),void n(g)}const u=p?{eqType:a,eqForeignKey:c}:{eqType:a,inForeignKey:g.map(e=>e[f]).join(",")};e("/basicInfo/imgFiles/listAll","get",u).then(e=>{if(p)n(i(e.data).map(e=>({...e,type:void 0})));else{const o=new Map;e.data.forEach(e=>{o.has(e.foreignKey)||o.set(e.foreignKey,[]),o.get(e.foreignKey).push({...e,type:void 0})});const r=g.map(e=>{const r=e[f],n=o.has(r)?i(o.get(r)):[];return{...e,files:n}});n(r)}}).catch(e=>{t(e)}).finally(()=>{s--,s<=0&&l(!1)})});console.error("【getFile】 缺少 options 参数")};return"array"===n?[t,a]:{loading:t,getFile:a}}export{n as default};
