2024-04-12 17:57:52 +08:00
|
|
|
import {
|
2024-04-22 22:31:50 +08:00
|
|
|
request,
|
|
|
|
|
transformRepalceString
|
2024-04-12 17:57:52 +08:00
|
|
|
} from '@/untils/AxiosUtils.js';
|
|
|
|
|
import {
|
|
|
|
|
baseUrl
|
|
|
|
|
} from '@/config/env.js'
|
|
|
|
|
import {
|
|
|
|
|
getStore
|
|
|
|
|
} from '@/untils/store.js'
|
|
|
|
|
import {
|
|
|
|
|
Base64
|
|
|
|
|
} from 'js-base64'
|
|
|
|
|
import website from "@/config/website.js"
|
|
|
|
|
|
|
|
|
|
export async function uploadFile(file) {
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: '上传中'
|
|
|
|
|
})
|
|
|
|
|
var token = getStore({
|
|
|
|
|
name: 'token'
|
|
|
|
|
})
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const header = {
|
|
|
|
|
'Authorization': `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}`,
|
|
|
|
|
}
|
|
|
|
|
header[website.tokenName] = "bearer " + token
|
|
|
|
|
uni.uploadFile({
|
2024-04-22 15:59:25 +08:00
|
|
|
url: `${baseUrl}/api/jobslink-api/resource/file/save?bussinessType=5`,
|
2024-04-12 17:57:52 +08:00
|
|
|
header,
|
|
|
|
|
filePath: file.url,
|
|
|
|
|
// formData: formdata,
|
|
|
|
|
name: 'file',
|
|
|
|
|
success: ({
|
|
|
|
|
statusCode,
|
|
|
|
|
data
|
|
|
|
|
}) => {
|
2024-04-22 22:31:50 +08:00
|
|
|
const resp = transformRepalceString(JSON.parse(data))
|
2024-04-12 17:57:52 +08:00
|
|
|
if (statusCode === 200 && resp.code === 200) {
|
2024-04-22 15:59:25 +08:00
|
|
|
resolve(resp.msg)
|
2024-04-12 17:57:52 +08:00
|
|
|
} else {
|
|
|
|
|
reject(new Error('数据异常'))
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
fail: (uploadFileRes) => {
|
|
|
|
|
reject(uploadFileRes)
|
|
|
|
|
},
|
|
|
|
|
complete: () => {
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
}
|