You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.2 KiB
84 lines
2.2 KiB
import { getWxId } from "../apis/api.js";
|
|
//登录获取、持久化 id token
|
|
export function wxLogin() {
|
|
return new Promise((resolve, reject) => {
|
|
uni.login({
|
|
success(res) {
|
|
if (res.code) {
|
|
getWxId({
|
|
code: res.code,
|
|
}).then((wxInfo: any) => {
|
|
if (wxInfo.success) {
|
|
uni.setStorageSync("token", wxInfo.token);
|
|
uni.setStorageSync("id", wxInfo.id);
|
|
resolve(wxInfo);
|
|
} else {
|
|
uni.showToast({
|
|
icon: "fail",
|
|
title: "用户信息获取失败!",
|
|
});
|
|
reject();
|
|
}
|
|
});
|
|
} else {
|
|
uni.showToast({
|
|
icon: "fail",
|
|
title: "登录失败!",
|
|
});
|
|
reject();
|
|
}
|
|
},
|
|
fail() {
|
|
uni.showToast({
|
|
icon: "fail",
|
|
title: "登录失败!",
|
|
});
|
|
reject();
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
//图片本地缓存处理 imgCache [{modelId:1,imgList:[url1,url2,...]},{modelId:2,imgList:[url1,url2,...]},...]
|
|
export function saveImgCache(modelId: any, imgList: any) {
|
|
Promise.all([
|
|
pro(imgList[0]),
|
|
pro(imgList[1]),
|
|
pro(imgList[2]),
|
|
pro(imgList[3]),
|
|
pro(imgList[4]),
|
|
]).then((res) => {
|
|
const imgCache = uni.getStorageSync("imgCache");
|
|
if (imgCache && imgCache.length > 0) {
|
|
imgCache.push({ modelId: modelId, imgList: res });
|
|
uni.setStorageSync("imgCache", imgCache);
|
|
} else {
|
|
uni.setStorageSync("imgCache", [{ modelId: modelId, imgList: res }]);
|
|
}
|
|
});
|
|
}
|
|
|
|
//转存本地路径
|
|
const pro = (url: string) => {
|
|
return new Promise((resolve) => {
|
|
uni.downloadFile({
|
|
url: url,
|
|
success: (res: any) => {
|
|
uni.getFileSystemManager().saveFile({
|
|
tempFilePath: res.tempFilePath,
|
|
success: (saveRes: any) => {
|
|
resolve(saveRes.savedFilePath);
|
|
},
|
|
});
|
|
},
|
|
});
|
|
});
|
|
};
|
|
|
|
//设置根字体大小
|
|
export function caleRootFontSize() {
|
|
const clientWidth = Math.min(uni.getSystemInfoSync().windowWidth, 1080);
|
|
const rootFontSize = (clientWidth / 1080) * 20;
|
|
uni.setStorageSync("rootFontSize", rootFontSize);
|
|
}
|