{"version":3,"file":"fileservice.js","sources":["../../../../src/service/fileservice.js"],"sourcesContent":["import { httpUploadFile } from \"@/utils/http\";\n\n// 选择并上传图片\nexport const chooseImage = () => {\n return new Promise((resolve, reject) => {\n uni.chooseImage({\n count: 1,\n success: async (res) => {\n try {\n const filePath = res.tempFilePaths[0]; // 获取第一张图片路径\n const uploadedUrl = await uploadImage(filePath); // 异步上传图片\n resolve(uploadedUrl); // 成功上传后返回 URL\n } catch (error) {\n reject(error); // 上传失败时返回错误\n }\n },\n fail: () => {\n uni.showToast({ title: '图片选择失败', icon: 'none' });\n reject(new Error('图片选择失败'));\n },\n })\n })\n}\n\n// 上传图片到服务器\nexport const uploadImage = async (filePath) => {\n try {\n const uploadResult = await httpUploadFile('/file/upload', filePath)\n if (uploadResult && uploadResult.data && uploadResult.data.url) {\n return uploadResult.data.url\n } else {\n uni.showToast({ title: '图片上传失败', icon: 'none' })\n return ''\n }\n } catch (error) {\n console.error(error)\n uni.showToast({ title: '图片上传失败', icon: 'none' })\n return ''\n }\n}\n"],"names":["uni","httpUploadFile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGY,MAAC,cAAc,MAAM;AAC/B,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtCA,kBAAAA,MAAI,YAAY;AAAA,MACd,OAAO;AAAA,MACP,SAAS,CAAO,QAAQ;AACtB,YAAI;AACF,gBAAM,WAAW,IAAI,cAAc,CAAC;AACpC,gBAAM,cAAc,MAAM,YAAY,QAAQ;AAC9C,kBAAQ,WAAW;AAAA,QACpB,SAAQ,OAAO;AACd,iBAAO,KAAK;AAAA,QACb;AAAA,MACF;AAAA,MACD,MAAM,MAAM;AACVA,sBAAG,MAAC,UAAU,EAAE,OAAO,UAAU,MAAM,OAAM,CAAE;AAC/C,eAAO,IAAI,MAAM,QAAQ,CAAC;AAAA,MAC3B;AAAA,IACP,CAAK;AAAA,EACL,CAAG;AACH;AAGO,MAAM,cAAc,CAAO,aAAa;AAC7C,MAAI;AACF,UAAM,eAAe,MAAMC,0BAAe,gBAAgB,QAAQ;AAClE,QAAI,gBAAgB,aAAa,QAAQ,aAAa,KAAK,KAAK;AAC9D,aAAO,aAAa,KAAK;AAAA,IAC/B,OAAW;AACLD,oBAAG,MAAC,UAAU,EAAE,OAAO,UAAU,MAAM,QAAQ;AAC/C,aAAO;AAAA,IACR;AAAA,EACF,SAAQ,OAAO;AACd,YAAQ,MAAM,KAAK;AACnBA,kBAAG,MAAC,UAAU,EAAE,OAAO,UAAU,MAAM,QAAQ;AAC/C,WAAO;AAAA,EACR;AACH;;"}