update
This commit is contained in:
BIN
merchant.zip
BIN
merchant.zip
Binary file not shown.
@@ -1,5 +1,6 @@
|
|||||||
import request from "../utils/request.js";
|
import request from "../utils/request.js";
|
||||||
import Method from "./Method.js";
|
import Method from "./Method.js";
|
||||||
|
import Qiniu from "../utils/Qiniu.js";
|
||||||
|
|
||||||
const system = {
|
const system = {
|
||||||
getData: async (params) => {
|
getData: async (params) => {
|
||||||
@@ -31,31 +32,26 @@ const system = {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
uploadFile: async (file) => {
|
getUploadToken: async () => {
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('file', file);
|
|
||||||
return request({
|
return request({
|
||||||
UN_AES: true,
|
UN_AES: true,
|
||||||
url: '/admin/upload/upload',
|
url: `/${import.meta.env.VITE_BUILD_MODE === 'admin' ? 'admin' : 'index'}/Upload/webToken`,
|
||||||
method: Method.POST,
|
method: Method.GET,
|
||||||
data: formData,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'multipart/form-data; boundary=--------------------------611824495457697861278283'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
uploadFile: async (file) => {
|
||||||
|
const qiniu = await Qiniu.getInstance();
|
||||||
|
const path = await qiniu.uploadFile(file);
|
||||||
|
return {
|
||||||
|
data: path,
|
||||||
|
}
|
||||||
|
},
|
||||||
uploadFile2: async (file) => {
|
uploadFile2: async (file) => {
|
||||||
const formData = new FormData();
|
const qiniu = await Qiniu.getInstance();
|
||||||
formData.append('file', file);
|
const path = await qiniu.uploadFile(file);
|
||||||
return request({
|
return {
|
||||||
UN_AES: true,
|
data: path,
|
||||||
url: '/index/upload/upload',
|
}
|
||||||
method: Method.POST,
|
|
||||||
data: formData,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'multipart/form-data; boundary=--------------------------611824495457697861278283'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
79
src/utils/Qiniu.js
Normal file
79
src/utils/Qiniu.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import Api from "../api/index.js";
|
||||||
|
import Method from "../api/Method.js";
|
||||||
|
import axios from "axios";
|
||||||
|
import {Message} from "@arco-design/web-vue";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: 如果后面频繁出现七牛的异常,记得后面做一下异常处理
|
||||||
|
*/
|
||||||
|
class Qiniu {
|
||||||
|
static instance;
|
||||||
|
domain;
|
||||||
|
path;
|
||||||
|
token;
|
||||||
|
|
||||||
|
constructor(callback) {
|
||||||
|
this.getToken().then(() => {
|
||||||
|
if (callback) callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Promise<Qiniu>}
|
||||||
|
*/
|
||||||
|
static async getInstance() {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (!Qiniu.instance) {
|
||||||
|
Qiniu.instance = new Qiniu(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve(Qiniu.instance);
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(Qiniu.instance);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async getToken() {
|
||||||
|
const {data} = await Api.system.getUploadToken();
|
||||||
|
this.domain = data.domain;
|
||||||
|
this.path = data.path;
|
||||||
|
this.token = data.token;
|
||||||
|
}
|
||||||
|
|
||||||
|
async uploadFile(file) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('token', this.token);
|
||||||
|
formData.append('key', `${this.path}/${crypto.randomUUID()}.${this.getExt(file.name)}`);
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const {data: {key}} = await axios.request({
|
||||||
|
url: 'https://up-z2.qiniup.com',
|
||||||
|
method: Method.POST,
|
||||||
|
data: formData,
|
||||||
|
})
|
||||||
|
|
||||||
|
return `${this.domain}/${key}`;
|
||||||
|
} catch ({status, message}) {
|
||||||
|
if (status === 401) {
|
||||||
|
await this.getToken();
|
||||||
|
return await this.uploadFile(file);
|
||||||
|
} else {
|
||||||
|
Message.error(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param filename {string}
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
getExt(filename) {
|
||||||
|
const parts = filename.split('.');
|
||||||
|
return parts.length > 1 ? parts.pop() : '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Qiniu;
|
||||||
@@ -11,6 +11,10 @@ const excludeURL = [
|
|||||||
'/index/login/login',
|
'/index/login/login',
|
||||||
'/index/task/getCommonRefund',
|
'/index/task/getCommonRefund',
|
||||||
'/index/task/getDiyRefund',
|
'/index/task/getDiyRefund',
|
||||||
|
'/index/task/getDiyRefund',
|
||||||
|
'/index/login/sendSms',
|
||||||
|
'/index/Upload/webToken',
|
||||||
|
'/admin/Upload/webToken',
|
||||||
];
|
];
|
||||||
|
|
||||||
export const BASEURL = import.meta.env.MODE === 'development' ? '/baseApi' : import.meta.env.VITE_API_URL;
|
export const BASEURL = import.meta.env.MODE === 'development' ? '/baseApi' : import.meta.env.VITE_API_URL;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user