开发吉祥物界面
This commit is contained in:
+72
-37
@@ -1,5 +1,9 @@
|
||||
import request from '@/api/request'
|
||||
import common from "@/common/common";
|
||||
import {
|
||||
queryCurrentValidMascotInfo
|
||||
} from "@/api/mascot.js"
|
||||
|
||||
import {
|
||||
setToken,
|
||||
setUserInfo,
|
||||
@@ -21,7 +25,36 @@ export const useAccountLoginApp = (data) => request({
|
||||
if (rtnCode === '0000') {
|
||||
setToken(body)
|
||||
|
||||
// 获取科技鹿
|
||||
queryCurrentValidMascotInfo().then((res) => {
|
||||
const userInfo = getUserInfo()
|
||||
setUserInfo({
|
||||
...userInfo,
|
||||
'mascotInfo': res
|
||||
})
|
||||
console.log('科技', res);
|
||||
if (res.imgAddr) {
|
||||
setTimeout(() => {
|
||||
const img = new Image(); // 创建Image对象
|
||||
// 图片加载成功(缓存完成)
|
||||
img.onload = () => {
|
||||
console.log(`图片缓存成功: ${url}`);
|
||||
resolve(img); // 返回加载完成的Image对象
|
||||
};
|
||||
|
||||
// 图片加载失败
|
||||
img.onerror = () => {
|
||||
console.error(`图片缓存失败: ${url}`);
|
||||
reject(new Error(`Failed to load image: ${url}`));
|
||||
};
|
||||
|
||||
// 开始加载图片(设置src触发请求,浏览器会自动缓存)
|
||||
img.src = url;
|
||||
})
|
||||
}
|
||||
})
|
||||
const user_data = await queryCurrentUser()
|
||||
|
||||
return user_data
|
||||
|
||||
}
|
||||
@@ -76,46 +109,48 @@ export const queryCurrentUser = (data) => request({
|
||||
// 预加载头像
|
||||
// #ifdef APP-PLUS
|
||||
const updateUserAvatar = (imagePath) => {
|
||||
const userInfo = getUserInfo()
|
||||
setUserInfo({
|
||||
...userInfo,
|
||||
'imagePath': imagePath
|
||||
})
|
||||
const userInfo = getUserInfo()
|
||||
setUserInfo({
|
||||
...userInfo,
|
||||
'imagePath': imagePath
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const pathName = res.body.imageAddr
|
||||
const url = base_url + pathName
|
||||
// 生成唯一文件名,避免冲突
|
||||
const filename = pathName.split('/').pop()
|
||||
const localFilePath = '_downloads/' + filename
|
||||
|
||||
// 先检查是否存在
|
||||
uni.getFileInfo({
|
||||
filePath: localFilePath,
|
||||
success: () => {
|
||||
console.log('头像已存在,无需下载');
|
||||
updateUserAvatar(localFilePath)
|
||||
},
|
||||
fail: () => {
|
||||
console.log('开始下载头像:', url);
|
||||
const dtask = plus.downloader.createDownload(
|
||||
url, {
|
||||
method: 'GET',
|
||||
filename: '_downloads/' + filename
|
||||
},
|
||||
(download, status) => {
|
||||
if (status === 200) {
|
||||
console.log('头像下载成功:', download.filename);
|
||||
updateUserAvatar(download.filename)
|
||||
}
|
||||
}
|
||||
)
|
||||
dtask.start();
|
||||
}
|
||||
})
|
||||
const pathName = res.body.imageAddr
|
||||
const url = base_url + pathName
|
||||
// 生成唯一文件名,避免冲突
|
||||
const filename = pathName.split('/').pop()
|
||||
const localFilePath = '_downloads/' + filename
|
||||
|
||||
// 先检查是否存在
|
||||
uni.getFileInfo({
|
||||
filePath: localFilePath,
|
||||
success: () => {
|
||||
console.log('头像已存在,无需下载');
|
||||
updateUserAvatar(localFilePath)
|
||||
},
|
||||
fail: () => {
|
||||
console.log('开始下载头像:', url);
|
||||
const dtask = plus.downloader.createDownload(
|
||||
url, {
|
||||
method: 'GET',
|
||||
filename: '_downloads/' + filename
|
||||
},
|
||||
(download, status) => {
|
||||
if (status === 200) {
|
||||
console.log('头像下载成功:', download.filename);
|
||||
updateUserAvatar(download.filename)
|
||||
}
|
||||
}
|
||||
)
|
||||
dtask.start();
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error('头像预加载过程发生错误:', error);
|
||||
console.error('头像预加载过程发生错误:', error);
|
||||
}
|
||||
// #endif
|
||||
return res.body
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import request from '@/api/request'
|
||||
|
||||
const base_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: base_url + '/traMascotInfo/queryValidTraMascotInfo',
|
||||
method: 'post',
|
||||
toastErrors: true,
|
||||
data
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置吉祥物
|
||||
* 入参:
|
||||
mascotId 必输项:true 类型:String
|
||||
*/
|
||||
export const setTraMascotInfo = (data) => {
|
||||
return request({
|
||||
url: base_url + '/traMascotInfo/setTraMascotInfo',
|
||||
method: 'post',
|
||||
toastErrors: true,
|
||||
data
|
||||
});
|
||||
};
|
||||
|
||||
// 查询当前已经选择的吉祥物
|
||||
/**
|
||||
* 查询当前已经选择的吉祥物
|
||||
* 出参:
|
||||
mascotId 吉祥物ID String
|
||||
mascotName 吉祥物名称 String
|
||||
mascotNameEn 吉祥物英文名称 String
|
||||
mascotDesc 吉祥物简介 String
|
||||
mascotNo 吉祥物编号 String
|
||||
imgAddr 吉祥物图片 String
|
||||
imgThumbAddr 吉祥物缩略图 String
|
||||
showOrder 显示顺序 int
|
||||
*/
|
||||
export const queryCurrentValidMascotInfo = (data) => {
|
||||
return request({
|
||||
url: base_url + '/traMascotInfo/queryCurrentValidMascotInfo',
|
||||
method: 'post',
|
||||
toastErrors: true,
|
||||
data
|
||||
});
|
||||
};
|
||||
@@ -6,7 +6,9 @@ import common from '@/common/common.js'
|
||||
const ENV = import.meta.env
|
||||
|
||||
export const get_base_url = url => {
|
||||
|
||||
if (ENV.MODE === 'development') { // 开发环境
|
||||
return ENV.VITE_APP_BASE_API_Url
|
||||
// H5必须用非https,手机端必须用https
|
||||
// #ifdef H5
|
||||
const baseUrl = ENV.VITE_APP_BASE_API_Url
|
||||
|
||||
Reference in New Issue
Block a user