123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- // pages/login/login.ts;
- const app = getApp();
- const {
- login,
- register
- } = require('./../../utils/api.js')
- Page({
- data: {
- nvabarData: {
- showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
- title: '', //导航栏 中间的标题
- },
- isYs: false,
- isAgree: false,
- },
- egree() {
- this.setData({
- isAgree: !this.data.isAgree
- })
- },
- goabout(e) {
- wx.navigateTo({
- url: './../aboutInfo/aboutInfo?type=' + e.currentTarget.dataset.index,
- })
- },
- getPhoneNumber(e) {
- if (e.detail.errMsg != "getPhoneNumber:ok") {
- wx.showToast({
- title: "获取手机号失败",
- icon: 'fail',
- duration: 2000
- });
- return;
- }
- var phoneCode = e.detail.code;
- if (phoneCode) {
- wx.login({
- success: res1 => {
- wx.showLoading({
- title: '加载中',
- });
- // {"openid":"oZHPJ5JcNem2och3ToaocggmUENw","unionid":null,"userId":null,"deviceUid":null,"accessToken":null,"phone":null,"headUrl":"","nickname":"","isNewUser":true}
- login({
- code: res1.code,
- unShowLoad: true,
- }).then((res2) => {
- register({
- openid: res2.openid,
- code: phoneCode,
- unShowLoad: true,
- }).then((res3) => {
- // {"openid":"oZHPJ5JcNem2och3ToaocggmUENw","userId":933625,"deviceUid":1,"accessToken":"PUK8WVnLbIFsWYjSteitmg3OhllpbUMvIPKUtfJgwhRtpl1jx4Fm1NkHQIiZYhHz","phone":"15915390284","headUrl":"https://music-play.oss-cn-shenzhen.aliyuncs.com/user/headurl/20220316194115703366576.png","nickname":"儿子的爸爸叫啥"}
- wx.login({
- success: res4 => {
- // {"openid":"oZHPJ5JcNem2och3ToaocggmUENw","unionid":null,"userId":933625,"deviceUid":1,"accessToken":"kaKdNAb9eO0iUGKsaLP18UE0wRwrvoCr4opjNC3AieaigH4Fu1IspQKi2zTPgLNG","phone":"15915390284","headUrl":"https://music-play.oss-cn-shenzhen.aliyuncs.com/user/headurl/20220316194115703366576.png","nickname":"儿子的爸爸叫啥","isNewUser":false}
- login({
- code: res4.code,
- phone: res3.phone,
- }).then((res5) => {
- wx.showToast({
- title: "登录成功",
- icon: 'success',
- duration: 2000
- });
- app.globalData.userInfo = res5;
- wx.setStorageSync("userInfo", res5);
- wx.setStorageSync("token", JSON.stringify({
- id: res5.userId,
- token: res5.accessToken,
- }));
- getCurrentPages()[0].onUserInfoLoad();
- setTimeout(() => {
- wx.redirectTo({
- url: './../deviceList/deviceList'
- });
- }, 2000);
- // 需要用授权登录
- // if ((res.isNewUser && res.isNewUser === true) || !phone) {
- // return;
- // };
- });
- },
- fail(fail4) {
- wx.hideLoading();
- },
- });
- });
- });
- },
- fail(fail1) {
- wx.hideLoading();
- },
- });
- }
- },
- notlogin() {
- wx.showToast({
- title: '请同意协议',
- icon: "none"
- })
- }
- })
|