三阶段签到页面
This commit is contained in:
+107
-105
@@ -4,6 +4,10 @@ import {
|
||||
queryCurrentValidMascotInfo
|
||||
} from "@/api/mascot.js"
|
||||
|
||||
import {
|
||||
queryCurrentStatus
|
||||
} from '@/api/pointsAndRank.js';
|
||||
|
||||
import {
|
||||
setToken,
|
||||
setUserInfo,
|
||||
@@ -24,15 +28,26 @@ export const useAccountLoginApp = (data) => request({
|
||||
}) => {
|
||||
if (rtnCode === '0000') {
|
||||
setToken(body)
|
||||
const res = await Promise.all([queryCurrentUser(), queryCurrentValidMascotInfo()])
|
||||
const res = await Promise.all([queryCurrentUser(), queryCurrentValidMascotInfo()
|
||||
// queryCurrentStatus()
|
||||
])
|
||||
const userInfo = getUserInfo()
|
||||
const mascotInfo = res[1]
|
||||
setUserInfo({
|
||||
...userInfo,
|
||||
'mascotInfo': mascotInfo
|
||||
})
|
||||
// 积分状态
|
||||
// const pointsStatus = res[2].body
|
||||
|
||||
common.setValue('points_data', {
|
||||
badgeNum: pointsStatus['badgeNum'] ?? 0, // 徽章数
|
||||
currentPoints: pointsStatus['currentPoints'] ?? 0, // 当前积分
|
||||
currentRankAddr: pointsStatus['ossAddr'] ?? '', // 当前段位图片
|
||||
currentRankName: pointsStatus['currentRankName']?? '未知', // 当前段位名称
|
||||
})
|
||||
return {
|
||||
mascotState:!mascotInfo.mascotId
|
||||
mascotState: !mascotInfo.mascotId
|
||||
}
|
||||
}
|
||||
return Promise.reject({
|
||||
@@ -40,22 +55,6 @@ export const useAccountLoginApp = (data) => request({
|
||||
body
|
||||
})
|
||||
}).catch(res => {
|
||||
/**
|
||||
error: "Service Unavailable"
|
||||
path: "/traapp/access/userLogin"
|
||||
requestId: "74d60800-104"
|
||||
status: 503
|
||||
timestamp: "2025-06-24T00:53:35.293+00:00"
|
||||
*/
|
||||
/**
|
||||
body: null
|
||||
channelNo: "FF6944B69A99745C009F4D0B3C3B22B8E81B22F587D68455E354BABBABCCB6246C54ABD28F3C55AAD34224A16CE7E24E"
|
||||
head: null
|
||||
message: "系统异常"
|
||||
rtnCode: "9999"
|
||||
rtnTime: "2025-06-24 08:54:52"
|
||||
*/
|
||||
|
||||
return Promise.reject(res)
|
||||
})
|
||||
|
||||
@@ -72,7 +71,7 @@ export const queryCurrentUser = (data) => request({
|
||||
method: 'post',
|
||||
data
|
||||
}).then(res => {
|
||||
|
||||
|
||||
// deptId: ""
|
||||
// deptName: null
|
||||
// loginName: "ADMIN" // todo id
|
||||
@@ -92,107 +91,109 @@ export const queryCurrentUser = (data) => request({
|
||||
// #ifdef APP-PLUS
|
||||
// 更新用户信息中的头像路径
|
||||
const updateUserAvatar = (imagePath) => {
|
||||
const _userInfo = getUserInfo() ?? {}
|
||||
setUserInfo({
|
||||
..._userInfo,
|
||||
...res.body,
|
||||
'imagePath': imagePath
|
||||
})
|
||||
const _userInfo = getUserInfo() ?? {}
|
||||
setUserInfo({
|
||||
..._userInfo,
|
||||
...res.body,
|
||||
'imagePath': imagePath
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 确保目录存在
|
||||
const ensureDirectoryExists = (dirPath) => {
|
||||
return new Promise((resolve) => {
|
||||
plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fs) => {
|
||||
fs.root.getDirectory(dirPath, { create: true }, resolve, resolve)
|
||||
})
|
||||
})
|
||||
return new Promise((resolve) => {
|
||||
plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fs) => {
|
||||
fs.root.getDirectory(dirPath, {
|
||||
create: true
|
||||
}, resolve, resolve)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 生成唯一文件名
|
||||
const generateUniqueFilename = (pathName) => {
|
||||
if (!pathName || typeof pathName !== 'string') {
|
||||
throw new Error('无效的路径');
|
||||
}
|
||||
|
||||
// 直接使用原始文件名(带扩展名)
|
||||
const filename = pathName.split('/').pop();
|
||||
|
||||
if (!filename) {
|
||||
throw new Error('无法从路径中提取文件名');
|
||||
}
|
||||
|
||||
// 确保文件扩展名为.png (可选,根据实际需求)
|
||||
const ext = filename.split('.').pop().toLowerCase();
|
||||
if (ext === 'png' || ext === 'jpg' || ext === 'jpeg' || ext === 'webp') {
|
||||
return filename;
|
||||
}
|
||||
|
||||
// 如果没有有效扩展名,添加.png
|
||||
return `${filename}.png`;
|
||||
if (!pathName || typeof pathName !== 'string') {
|
||||
throw new Error('无效的路径');
|
||||
}
|
||||
|
||||
// 直接使用原始文件名(带扩展名)
|
||||
const filename = pathName.split('/').pop();
|
||||
|
||||
if (!filename) {
|
||||
throw new Error('无法从路径中提取文件名');
|
||||
}
|
||||
|
||||
// 确保文件扩展名为.png (可选,根据实际需求)
|
||||
const ext = filename.split('.').pop().toLowerCase();
|
||||
if (ext === 'png' || ext === 'jpg' || ext === 'jpeg' || ext === 'webp') {
|
||||
return filename;
|
||||
}
|
||||
|
||||
// 如果没有有效扩展名,添加.png
|
||||
return `${filename}.png`;
|
||||
};
|
||||
|
||||
|
||||
// 下载并保存头像
|
||||
const downloadAndSaveAvatar = async (fileUrl, localFilePath) => {
|
||||
try {
|
||||
await ensureDirectoryExists('avatar')
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log('开始下载头像:', fileUrl)
|
||||
const dtask = plus.downloader.createDownload(fileUrl, {
|
||||
filename: localFilePath
|
||||
}, (d, status) => {
|
||||
if (status === 200) {
|
||||
console.log("保存路径:", d.filename)
|
||||
resolve(d.filename)
|
||||
} else {
|
||||
console.error("文件下载失败:", status)
|
||||
reject(new Error(`下载失败,状态码: ${status}`))
|
||||
}
|
||||
})
|
||||
|
||||
dtask.start()
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('创建目录失败:', error)
|
||||
throw error
|
||||
}
|
||||
try {
|
||||
await ensureDirectoryExists('avatar')
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log('开始下载头像:', fileUrl)
|
||||
const dtask = plus.downloader.createDownload(fileUrl, {
|
||||
filename: localFilePath
|
||||
}, (d, status) => {
|
||||
if (status === 200) {
|
||||
console.log("保存路径:", d.filename)
|
||||
resolve(d.filename)
|
||||
} else {
|
||||
console.error("文件下载失败:", status)
|
||||
reject(new Error(`下载失败,状态码: ${status}`))
|
||||
}
|
||||
})
|
||||
|
||||
dtask.start()
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('创建目录失败:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 检查文件是否存在
|
||||
const checkFileExists = (filePath) => {
|
||||
return new Promise((resolve) => {
|
||||
uni.getFileInfo({
|
||||
filePath,
|
||||
success: () => resolve(true),
|
||||
fail: () => resolve(false)
|
||||
})
|
||||
})
|
||||
return new Promise((resolve) => {
|
||||
uni.getFileInfo({
|
||||
filePath,
|
||||
success: () => resolve(true),
|
||||
fail: () => resolve(false)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 主逻辑
|
||||
(async () => {
|
||||
try {
|
||||
const pathName = res.body.imageAddr
|
||||
const fileUrl = base_url + pathName
|
||||
|
||||
// 生成保存路径
|
||||
const filename = generateUniqueFilename(pathName)
|
||||
const localFilePath = '_doc/avatar/' + filename
|
||||
|
||||
// 检查文件是否存在
|
||||
const exists = await checkFileExists(localFilePath)
|
||||
|
||||
if (exists) {
|
||||
// console.log('头像已存在,无需下载')
|
||||
updateUserAvatar(localFilePath)
|
||||
} else {
|
||||
const savedPath = await downloadAndSaveAvatar(fileUrl, localFilePath)
|
||||
updateUserAvatar(savedPath)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('头像预加载过程发生错误:', error)
|
||||
}
|
||||
try {
|
||||
const pathName = res.body.imageAddr
|
||||
const fileUrl = base_url + pathName
|
||||
|
||||
// 生成保存路径
|
||||
const filename = generateUniqueFilename(pathName)
|
||||
const localFilePath = '_doc/avatar/' + filename
|
||||
|
||||
// 检查文件是否存在
|
||||
const exists = await checkFileExists(localFilePath)
|
||||
|
||||
if (exists) {
|
||||
// console.log('头像已存在,无需下载')
|
||||
updateUserAvatar(localFilePath)
|
||||
} else {
|
||||
const savedPath = await downloadAndSaveAvatar(fileUrl, localFilePath)
|
||||
updateUserAvatar(savedPath)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('头像预加载过程发生错误:', error)
|
||||
}
|
||||
})()
|
||||
// #endif
|
||||
|
||||
@@ -230,4 +231,5 @@ export const loginOut = (data) => request({
|
||||
setUserInfo(null)
|
||||
common.setValue('me_statistics_data', null) // 我的页统计数据缓存
|
||||
common.setValue('index_statistics_data', null) // 首页统计数据缓存
|
||||
common.setValue('points_data', null) // 首页统计数据缓存
|
||||
})
|
||||
@@ -108,4 +108,16 @@ export const queryCurrentStatus = (data) => {
|
||||
method: 'post',
|
||||
data
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 徽章墙
|
||||
*/
|
||||
export const queryRankWall = (data) => {
|
||||
return request({
|
||||
url: base_url + '/traPointsInfo/queryRankWall',
|
||||
method: 'post',
|
||||
data
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user