ImageUploadCo.ts 603 B

1234567891011121314151617181920
  1. import CommonContent from "@/api/CommonContent";
  2. import type { UploaderAction } from "@/components/form/Uploader";
  3. export function useImageSimpleUploadCo(additionData?: Record<string, any>) {
  4. return (action: UploaderAction) => {
  5. action.onStart('正在上传');
  6. CommonContent.uploadFile(action.item.filePath, 'image', 'file', additionData)
  7. .then((res) => {
  8. action.onProgress(100);
  9. action.onFinish({
  10. uploadedUrl: res.fullurl,
  11. previewUrl: res.fullurl,
  12. }, '上传成功');
  13. }).catch((err) => {
  14. action.onError?.(err);
  15. })
  16. }
  17. }