111 lines
2.7 KiB
JavaScript
111 lines
2.7 KiB
JavaScript
import request from '@/api/request'
|
|
import {
|
|
get_base_url
|
|
} from '@/api/request.js'
|
|
|
|
const app_url = '/traapp'
|
|
|
|
|
|
/**
|
|
* 查询吉祥物列表
|
|
* 出参:
|
|
mascotId 吉祥物ID String
|
|
mascotName 吉祥物名称 String
|
|
mascotNameEn 吉祥物英文名称 String
|
|
mascotDesc 吉祥物简介 String
|
|
mascotNo 吉祥物编号 String
|
|
imgAddr 吉祥物图片 String
|
|
imgThumbAddr 吉祥物缩略图 String
|
|
showOrder 显示顺序 int
|
|
*/
|
|
export const queryValidTraMascotInfo = (data) => {
|
|
return request({
|
|
url: app_url + '/traMascotInfo/queryValidTraMascotInfo',
|
|
method: 'post',
|
|
toastErrors: true,
|
|
data
|
|
});
|
|
};
|
|
|
|
/**
|
|
* 设置吉祥物
|
|
* 入参:
|
|
mascotId 必输项:true 类型:String
|
|
*/
|
|
export const setTraMascotInfo = (data) => {
|
|
return request({
|
|
url: app_url + '/traMascotInfo/setTraMascotInfo',
|
|
method: 'post',
|
|
toastErrors: true,
|
|
data
|
|
});
|
|
};
|
|
|
|
// 查询当前已经选择的吉祥物
|
|
// 检查文件是否存在
|
|
const checkFileExists = (filePath) => {
|
|
return new Promise((resolve) => {
|
|
uni.getFileInfo({
|
|
filePath,
|
|
success: () => resolve(true),
|
|
fail: () => resolve(false)
|
|
})
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 查询当前已经选择的吉祥物
|
|
* 出参:
|
|
mascotId 吉祥物ID String
|
|
mascotName 吉祥物名称 String
|
|
mascotNameEn 吉祥物英文名称 String
|
|
mascotDesc 吉祥物简介 String
|
|
mascotNo 吉祥物编号 String
|
|
imgAddr 吉祥物图片 String
|
|
imgThumbAddr 吉祥物缩略图 String
|
|
showOrder 显示顺序 int
|
|
*/
|
|
export const queryCurrentValidMascotInfo = (data) => {
|
|
return request({
|
|
url: app_url + '/traMascotInfo/queryCurrentValidMascotInfo',
|
|
method: 'post',
|
|
toastErrors: true,
|
|
data
|
|
}).then(({
|
|
body
|
|
}) => {
|
|
if (body.imgAddr) {
|
|
console.log('body.imgAddrmascotNo');
|
|
const base_url = get_base_url()
|
|
const pathName = body.imgAddr
|
|
const fileUrl = base_url + pathName
|
|
const localFilePath = '_doc/mascot/' + body.mascotNo + '.png'
|
|
console.log('fileUrl', fileUrl);
|
|
// 将 Promise 回调函数声明为 async
|
|
return new Promise(async (resolve, reject) => {
|
|
// 现在可以在这里使用 await 了
|
|
const exists = await checkFileExists(localFilePath)
|
|
if (exists) {
|
|
console.log('已存在,无需下载')
|
|
resolve({...body, imgAddr:localFilePath})
|
|
} else {
|
|
console.log('开始下载吉祥物:', fileUrl)
|
|
const dtask = plus.downloader.createDownload(fileUrl, {
|
|
filename: localFilePath
|
|
}, (d, status) => {
|
|
if (status === 200) {
|
|
console.log("保存路径:", d.filename)
|
|
resolve({...body, imgAddr:d.filename})
|
|
} else {
|
|
console.error("文件下载失败:", status)
|
|
reject(new Error(`下载失败,状态码: ${status}`))
|
|
}
|
|
})
|
|
|
|
dtask.start()
|
|
}
|
|
})
|
|
}
|
|
return body
|
|
})
|
|
}; |