123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- import api from '../../js/api'
- Page({
-
- data: {
- userInfo: {}
- },
-
- onLoad(options) {
- },
-
- onReady() {
- },
-
- onShow() {
- },
-
- onHide() {
- },
-
- onUnload() {
- },
-
- onPullDownRefresh() {
- },
-
- onReachBottom() {
- },
-
- onShareAppMessage() {
- },
-
- handleAuthLogin(e) {
- console.log('一键授权登录按钮被点击');
- wx.showLoading({
- title: '正在登录中...',
- })
-
-
-
-
-
-
-
-
-
-
-
-
- const that = this;
- wx.getUserProfile({
- desc: '用于完善用户资料',
- success(res) {
- console.log('用户信息:', res.userInfo);
- var user = {
- UserName: res.userInfo.nickName,
- UserAvatarUrl: res.userInfo.avatarUrl,
- UserPhoneNumber: '',
- Address: ''
- };
- that.setData({
- userInfo:user
- })
- that.toLogin()
-
-
- },
- fail(err) {
- console.error('获取用户信息失败:', err);
- wx.hideLoading()
- },
- });
- },
- toLogin(){
-
- var that = this;
- wx.login({
- success(res) {
- if (res.code) {
- console.log('登录成功,code:', res.code);
- api.request_Wechatlogin(res.code)
- .then(res => {
- console.log("获取wid",res.data.data)
- wx.setStorageSync('WachatID', res.data.data)
- return api.request_AddMiniprogramUser(that.data.userInfo)
- }).then(res => {
- console.log("添加user",res)
- wx.hideLoading()
- wx.redirectTo({
- url: '../scan/scan',
- })
- }).catch(err => {
- console.log("报错",res)
- wx.hideLoading()
- });
- } else {
- wx.hideLoading()
- console.log('登录失败:', res.errMsg);
- }
- },
- fail(err) {
- wx.hideLoading()
- console.error('登录接口调用失败:', err);
- },
- });
- }
- })
|