202 lines
6.2 KiB
JavaScript
202 lines
6.2 KiB
JavaScript
// template/goLogin/goLogin.js
|
|
var app = getApp();
|
|
var miucms = require('../../utils/miucms.js');
|
|
import util from "../../utils/util"
|
|
|
|
Component({
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
islogin: Boolean
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
canIUseGetUserProfile: false,
|
|
isAgreement: false
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
pageLifetimes: {
|
|
show() {
|
|
const self = this
|
|
getApp().watch(self.watchBack.bind(self));
|
|
}
|
|
},
|
|
lifetimes: {
|
|
attached: function () {
|
|
this.attachedIn()
|
|
},
|
|
},
|
|
attached: function () {
|
|
this.attachedIn()
|
|
},
|
|
methods: {
|
|
watchBack(value) {
|
|
if (value) {
|
|
this.triggerEvent('userClickLogin', {
|
|
data: {
|
|
regdatastep: 'success'
|
|
}
|
|
})
|
|
this.bindIsAccredit()
|
|
}
|
|
},
|
|
|
|
attachedIn() {
|
|
let that = this;
|
|
this.setData({
|
|
canIUseGetUserProfile: app.globalData.canIUseGetUserProfile
|
|
})
|
|
},
|
|
hidealert() {
|
|
|
|
},
|
|
getuserInfo(e) {
|
|
if (!this.data.isAgreement) {
|
|
wx.showToast({
|
|
title: '请阅读并勾选同意',
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
|
|
let that = this;
|
|
if (this.data.canIUseGetUserProfile) {
|
|
wx.getUserProfile({
|
|
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
|
success: (res1) => {
|
|
app.globalData.getUserInfoData = res1
|
|
miucms.getUserInfo(res1).then(res => {
|
|
this.triggerEvent('userClickLogin', {
|
|
data: res.data
|
|
})
|
|
}).catch(res => {
|
|
console.log(res)
|
|
})
|
|
}
|
|
})
|
|
return false;
|
|
}
|
|
if (e.detail.errMsg == 'getUserInfo:ok') {
|
|
//用户同意授权
|
|
miucms.getUserInfo(e.detail).then(res => {
|
|
this.triggerEvent('userClickLogin', {
|
|
data: res.data
|
|
})
|
|
}).catch(res => {
|
|
console.log(res)
|
|
})
|
|
}
|
|
|
|
},
|
|
|
|
agreement() {
|
|
this.setData({
|
|
isAgreement: !this.data.isAgreement
|
|
})
|
|
},
|
|
|
|
godetail(e) {
|
|
let {
|
|
link
|
|
} = e.currentTarget.dataset
|
|
|
|
console.log("link", link);
|
|
wx.navigateTo({
|
|
url: '/pages/webview/webview?url=' + link,
|
|
})
|
|
},
|
|
|
|
bindIsAccredit() {
|
|
this.setData({
|
|
islogin: true
|
|
})
|
|
this.triggerEvent("popClose")
|
|
// this.triggerEvent('closeUserClickLogin', {})
|
|
},
|
|
|
|
handScroll() {
|
|
return
|
|
},
|
|
|
|
isloginState: false,
|
|
go() {
|
|
if (!this.data.isAgreement) {
|
|
wx.showToast({
|
|
title: '请阅读并勾选同意',
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
|
|
if (this.isloginState) return
|
|
wx.login({
|
|
success: res => {
|
|
miucms.request("https://passport.gter.net/api/user/authorityInit", {
|
|
code: res.code,
|
|
appid: "wxd7ebf76a0a87057d"
|
|
}).then(res => {
|
|
console.log("res", res);
|
|
|
|
if (res.code != 200) {
|
|
wx.showToast({
|
|
icon: "none",
|
|
title: res.message,
|
|
})
|
|
return
|
|
}
|
|
this.isloginState = false
|
|
let data = res.data
|
|
if (data.user) app.globalData.user = data.user
|
|
|
|
// if (data.step == "success") {
|
|
if (data.status == 3) {
|
|
app.globalData.setSate = true
|
|
this.triggerEvent('userClickLogin', {
|
|
data: res.data
|
|
})
|
|
this.setData({
|
|
isaccredit: !this.data.isaccredit
|
|
})
|
|
// } else if (data.step == "mobile") {
|
|
} else if (data.status == 1 || data.status == 2) {
|
|
let token = data.token
|
|
wx.navigateTo({
|
|
url: '/pagesSquare/pages/PCAuthorization/PCAuthorization?token=' + token + "&status=" + data.status,
|
|
})
|
|
} else if (data.status == 4) {
|
|
let token = data.token
|
|
wx.navigateTo({
|
|
url: "/pages/setAvatarNickname/setAvatarNickname?token=" + token
|
|
})
|
|
} else {
|
|
// 这个是所有情况的默认
|
|
app.globalData.user = data.user
|
|
this.triggerEvent('userClickLogin', {
|
|
data: res.data
|
|
})
|
|
this.setData({
|
|
isaccredit: !this.data.isaccredit
|
|
})
|
|
}
|
|
|
|
// util.bindingUser(data.user)
|
|
wx.xstat && wx.xstat.setUserid(data.user.uid); // 登录后手动设置用户id , 如果有
|
|
}).finally(() => {
|
|
this.isloginState = false
|
|
})
|
|
},
|
|
fail: err => {
|
|
this.isloginState = false
|
|
},
|
|
})
|
|
}
|
|
|
|
}
|
|
}) |