aqsc-mobile-com
Version:
基于uni-ui实现的二次封装
59 lines (54 loc) • 1.48 kB
JavaScript
import { useUserStore } from '@/store/modules/user'
import { getFilePath } from '@/utils/index'
export const openFile = ({ url, filename }) => {
// 添加 token 请求头标识
const userStore = useUserStore()
const token = userStore.token
let filePath = url
if (!filePath.startsWith('http') && !filePath.includes('/fileservice')) {
filePath = import.meta.env.VITE_APP_API_BASEURL + filePath + '&id_token=Bearer ' + token
}
if (
!filePath.includes('/weworkCompany') &&
!filePath.includes('/jtgs') &&
import.meta.env.MODE !== 'development' &&
uni.getStorageSync('werks')
) {
filePath = '/' + uni.getStorageSync('werks') + filePath
}
uni.openDocument({
filePath: filePath,
showMenu: true,
header: {
Authorization: 'Bearer ' + token, // 这里是要添加的请求头
},
success: function (res) {
console.info(res)
console.log('打开文档成功')
},
fail: function (res) {
uni.showToast({
title: '下载失败',
icon: 'none',
})
},
})
}
export const downloadFile = ({ uuid, filename }) => {
if (!filename) {
filename = 'temp'
}
uni.openDocument({
filePath: getFilePath(uuid),
showMenu: true,
success: function (res) {
console.info(res)
},
fail: function (res) {
uni.showToast({
title: '下载失败',
icon: 'none',
})
},
})
}