我的页面

This commit is contained in:
haomingming
2025-09-25 10:28:27 +08:00
parent b884a8f6fc
commit 9e78b974a2
17 changed files with 897 additions and 104 deletions
+90 -30
View File
@@ -108,7 +108,11 @@
import checkImg from "@/static/login_new_unselect.png"
import checkOnImg from "@/static/login_new_select.png"
import api from "@/api/api.js"
import my_api from "@/api/my_api.js"
import BASE_URL from "@/utils/config.js"
import { createSignedPostData } from '@/utils/sign.js'
import navTo from "@/utils/navTo"
const customStyle = reactive({
height: "100rpx",
fontSize: "36rpx",
@@ -135,7 +139,7 @@
console.log('一键登录');
uni.showLoading({
title: '登录中...'
title: '登录中2...'
});
// 模拟登录过程
@@ -173,34 +177,90 @@
return;
}
console.log('微信登录');
wx.login({
success(res) {
if (res.code) {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
api.expertWxLogin(res.code).then((data) => {
console.log(data)
if (data.data.openid) {
if (process.env.NODE_ENV === 'development') {
uni.setStorageSync('DEV_APPID', data.data.openid);
} else {
uni.setStorageSync('AUTH_APPID', data.data.openid);
}
}
let openid = ""
if (process.env.NODE_ENV === 'development') {
openid = uni.getStorageSync('DEV_APPID');
} else {
openid = uni.getStorageSync('AUTH_APPID');
}
console.log("openid: ", openid)
})
} else {
console.log('登录失败!' + res.errMsg);
}
}
// #ifdef APP
uni.showToast({
title: '微信登录 11',
icon: 'none'
});
// #endif
uni.login({
provider: 'weixin',
success: function (loginRes) {
// 登录成功
uni.getUserInfo({
provider: 'weixin',
success: async function(info) {
// 获取用户信息成功, info.authResult保存用户信息
// #ifdef APP
uni.showToast({
title: info.userInfo.nickName,
icon: 'none'
});
// #endif
const wechat_user_info = {
openid:info.userInfo.openId,
unionid:info.userInfo.unionId,
nickname:info.userInfo.nickName,
}
const { postData, sign } = await createSignedPostData({
wechat_user_info: JSON.stringify(wechat_user_info),
current_spec: "uniapp"
})
// #ifdef APP
uni.showToast({
title: sign,
icon: 'none'
});
// #endif
my_api.expertWxLogin(postData,{
sign:sign
}).then(res=>{
uni.showToast({
title: '登录成功',
icon: 'success'
})
if (BASE_URL.indexOf('dev') == -1) {
uni.setStorageSync('AUTH_TOKEN_App',res.data.access_token);
uni.setStorageSync('AUTH_YX_ACCID_App', res.data.YX_accid);
uni.setStorageSync('AUTH_YX_TOKEN_App', res.data.YX_token);
uni.setStorageSync('userInfo', res.data);
} else {
uni.setStorageSync('DEV_AUTH_TOKEN_App', res.data.access_token);
uni.setStorageSync('DEV_AUTH_YX_ACCID_App', res.data.YX_accid);
uni.setStorageSync('DEV_AUTH_YX_TOKEN_App', res.data.YX_token);
uni.setStorageSync('userInfo', res.data);
}
// 跳转到首页
navTo({
url: '/pages/index/index'
})
}).catch(err=>{
console.log(err)
uni.showToast({
title: res.data.msg || '登录失败',
icon: 'none'
})
})
}
})
},
fail: function (err) {
// 登录授权失败
// err.code是错误码
console.log(err)
// #ifdef APP
uni.showToast({
title: err,
icon: 'none'
});
// #endif
}
});
};