Ver Fonte

feat: 新增文件上传

Tim_Walker há 1 ano atrás
pai
commit
389d7b0668
1 ficheiros alterados com 41 adições e 0 exclusões
  1. 41 0
      src/utils/request.js

+ 41 - 0
src/utils/request.js

@@ -74,3 +74,44 @@ export function request(options) {
     });
   });
 }
+
+/**
+ * 文件上传
+ * @param {string} filePath 文件路径
+ * @returns
+ */
+export async function uploadFile(filePath) {
+  const { deviceId, osName, osVersion } = await getSystemInfoAsync();
+  const access_token = store.getters.access_token;
+  uni.showLoading({
+    title: '正在上传,请稍后'
+  })
+  return new Promise((resolve, reject) => {
+    uni.uploadFile({
+      url: BASE_URL + '/maintain/file',
+      filePath: filePath,
+      name: 'file',
+      header: {
+        Authorization: `Bearer ${access_token}`,
+        'Content-Type': 'application/json; charset=utf-8',
+        client_id: 'chelvc_client',
+        client_secret: 'qWBe6jD%GCuPPTkP',
+        grant_type: 'wechat',
+        Device: deviceId,
+        Platform: osName.toUpperCase(),
+        Version: osVersion,
+        Terminal: 'APPLET',
+        Business: 'CUSTOMER',
+      },
+      success: res => {
+        resolve(res.data);
+      },
+      fail: err => {
+        reject(err);
+      },
+      complete:()=>{
+        uni.hideLoading()
+      }
+    });
+  });
+}