通用图片预览组件调整
This commit is contained in:
+30
-2
@@ -40,8 +40,8 @@ export const uploadFile = (file, data) => {
|
||||
};
|
||||
|
||||
|
||||
// 对象存储预览 /traoss/tras3/show/{文件ID}
|
||||
export function previewFile(id,responseType = 'arraybuffer') {
|
||||
// 对象存储预览 /traoss/tras3/show/{文件ID}
|
||||
export function previewFile(id, responseType = 'arraybuffer') {
|
||||
const token = getToken();
|
||||
const header = {
|
||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
@@ -67,4 +67,32 @@ export function previewFile(id,responseType = 'arraybuffer') {
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// 缩略图预览 /traoss/tras3/getCacheThumbImage/{fileId}/{width}/{height}
|
||||
export function previewCacheThumbImage(id, width = 30, height = 30) {
|
||||
const token = getToken();
|
||||
const header = {
|
||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
};
|
||||
if (token)
|
||||
header['summary'] = token
|
||||
let baseUrl = get_base_url();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: `${baseUrl}/traoss/tras3/getCacheThumbImage/${id}/${width}/${height}`,
|
||||
header,
|
||||
responseType,
|
||||
success(result) {
|
||||
console.log(result)
|
||||
let _header = result.header['content-type'].split(';')[0]
|
||||
// let base64 = new Blob([result.data],{type:result.header['content-type'].split(';')[0]})
|
||||
let base64 = `data:${_header};base64,` + uni.arrayBufferToBase64(result.data)
|
||||
resolve(base64)
|
||||
},
|
||||
fail(error) {
|
||||
reject(new Error('Upload failed'));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user