Files
dianxiaorui-uniapp/common/js/user.js
PC-202306242200\Administrator 4d06351f6a no message
2026-03-28 23:00:29 +08:00

120 lines
2.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
loginApi,
loginCodeApi,
loginByZfbCode
} from "@/api/api.js"
import {
init
} from '@/utils/sok.js';
export const login = async (params, type = 1) => {
if (type == 1) {
var {
code: loginCode
} = await uni.login({
provider: 'weixin'
});
try {
let {
token,
userInfo
} = await loginCodeApi({
loginCode
})
uni.setStorageSync('token', token);
uni.setStorageSync('user', userInfo);
} catch (err) {
if (err.code == 10) {
uni.setStorageSync('token', false);
}
}
} else if (type == 2) {
var {
code: phoneCode
} = params.detail;
var {
code: loginCode
} = await uni.login({
provider: 'alipay'
});
try {
// #ifdef MP-WEIXIN
let {
token,
user
} = await loginApi({
phoneCode,
loginCode
});
// #endif
// #ifdef MP-ALIPAY
let {
token,
user
} = await loginByZfbCode({
phoneCode,
loginCode
});
// #endif
uni.setStorageSync('token', token);
uni.setStorageSync('user', user);
// uni.reLaunch({
// url: '/pages/home/home'
// });
// uni.navigateBack()
uni.navigateBack()
init()
} catch (err) {
console.log(err);
}
}
}
const download = (e, type) => {
const base64 = uni.arrayBufferToBase64(e.data);
const fs = wx.getFileSystemManager()
var imgPath = ''
if (type == 'video') {
imgPath = wx.env.USER_DATA_PATH + '/base64Video' + '.mp4' //自定义下载图片的名称
} else {
imgPath = wx.env.USER_DATA_PATH + '/base64img' + '.png' //自定义下载图片的名称
}
fs.writeFile({
filePath: imgPath, //设置下载图片的地址
data: base64, //slice(22)的目的是去掉data:image/png;base64,如果本身就不带的话就直接this.data.codeImg就好了
encoding: 'base64',
success: function(res) {
//读取文件
wx.getImageInfo({
src: imgPath,
success: function(ret) {
console.log("请求到了");
var path = ret.path;
wx.saveImageToPhotosAlbum({
filePath: imgPath, //设置下载图片的地址
success(result) {
console.log("保存成功"); //保存成功
}
})
}
})
// console.log(res);
// console.log("请求到了");
// wx.saveImageToPhotosAlbum({
// filePath: imgPath, //设置下载图片的地址
// success: function() {
// console.log("保存成功"); //保存成功
// }
// })
}
})
}