Commit f4dc5257 authored by xwq's avatar xwq

新登录授权弹窗

parent e19bf6f9
{"pages": [
"pages/photo/photo",
"pages/takePhoto/takePhoto",
"pages/login/login",
"pages/displayAnswers/displayAnswers"
],
......
......@@ -2,7 +2,7 @@
// pages/displayAnswers/displayAnswers.js
import UploadFileManager from "../../jade/UploadFileManager";
import {hosts} from "../../utils/index"
const log =require("../../utils/log.js")
Page({
/**
......@@ -41,6 +41,7 @@ Page({
},
detectAnswer: (tempPath) => {
// tempPath -> url
log.info("detectAnswer----",tempPath)
// console.log("detectAnswer", tempPath);
const ufm = UploadFileManager.getInstance();
return ufm
......@@ -52,6 +53,7 @@ Page({
true
)
.then((res) => {
log.info("detectAnswer", res,"=============",wx.getStorageSync("result"))
// console.log("detectAnswer", res,"=============",wx.getStorageSync("result"));
// const ret = JSON.parse(wx.getStorageSync("result"));
const baby = wx.getStorageSync("baby");
......@@ -76,8 +78,8 @@ Page({
reject(e);
},
});
}).catch(()=>{
}).catch((e)=>{
log.error("=======",e)
})
)
.then(
......@@ -109,7 +111,9 @@ Page({
reject(e);
},
});
}).catch(()=>{})
}).catch(()=>{
log.error("===0000====",e)
})
);
},
/**
......@@ -242,6 +246,7 @@ Page({
.catch(reject);
},
fail: (e) => {
log.error(e,"-------- 245-cancel")
// console.log(e);
reject(e);
},
......
// pages/login/login.js
Page({
/**
* 页面的初始数据
*/
data: {
},
bindGetUserInfo: function(e){
console.log(e);
wx.navigateBack({
delta: 1
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<!--pages/login/login.wxml-->
<view class="login-back" style="height: 100vh; width: 100%">
<view class="login-button">
<button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授权登录</button>
</view>
</view>
/* pages/login/login.wxss */
.login-back{
width: 100%;
height: 100%;
background-color: #FFB12C;
min-height: calc(100%vh - 0px);
position: relative;
}
.login-button{
position: absolute;
left: 50%;
transform: translateX(-50%);
bottom: 50px;
color: #FFB12C;
}
\ No newline at end of file
// pages/photo/photo.js
import { Jade } from "../../jade/index"
const log =require("../../utils/log.js")
// import {Log} from "../../utils/log"
Page({
/**
......@@ -20,15 +22,17 @@ Page({
wx.showModal({
title: '登录弹窗',
content: '使用小程序前,请登录并授权小程序获取您的信息',
success (res) {
if (res.confirm) {
success (res1) {
if (res1.confirm) {
wx.login({
success: res => {
success: res2 => {
log.info(res2,"---------登录")
// console.log(res,"---------登录");
var code = res.code
var code = res2.code
wx.getUserInfo({
withCredentials: true,
success: res => {
log.info(res,"---------getUserInfo")
// console.log('getUserInfo')
wx.request({
url: Jade.getUrl("users/sign_in.json"),
......@@ -39,10 +43,11 @@ Page({
encrypted_data: res.encryptedData,
iv: res.iv
},
success: res => {
const data = res.data;
success: res4 => {
const data = res4.data;
wx.setStorageSync('user', data)
wx.setStorageSync('user_token', data.token)
log.info(res4,"---------getUserInfo=success")
// Jade.UserManager.setUser(data)
// Jade.UserManager.setToken(data.token)
Jade.UserManager.authRequest({
......@@ -53,6 +58,7 @@ Page({
} else {
wx.setStorageSync('baby', null)
}
log.info(result,"---------authRequest=success")
wx.redirectTo({
url: '/pages/takePhoto/takePhoto',
})
......@@ -61,6 +67,11 @@ Page({
// }
},
fail: err => {
wx.showToast({
title: '获取信息失败',
icon: 'none',
duration:2000
})
// if (options && options.success) {
// options.success(result)
// }
......@@ -70,18 +81,38 @@ Page({
})
},
fail: err => {
wx.redirectTo({
url: '/pages/photo/photo',
log.error(err,"---------登录-fail")
wx.showToast({
title: '登录失败',
icon: 'none',
duration:2000,
complete:function(){
wx.redirectTo({
url: '/pages/photo/photo',
})
}
})
// wx.redirectTo({
// url: '/pages/photo/photo',
// })
// wx.onLoad()
}
})
}
})
} else if (res.cancel) {
wx.redirectTo({
url: '/pages/photo/photo',
} else if (res1.cancel) {
log.error(res1,"---------登录-cancel")
wx.showToast({
title: '您已拒绝授权',
icon: 'none',
duration:10000,
complete:function(){
wx.redirectTo({
url: '/pages/photo/photo',
})
}
})
}
}
})
......
const Jade = require("../jade/index").Jade
const Log = require("./log")
const getUrl = Jade.getUrl
const getCurrentPage = () => {
......@@ -151,6 +151,7 @@ module.exports = {
getUrl,
getCurrentPage,
Jade,
Log,
calculateTrainingStar,
promisedCanIUseAPI,
getSingle,
......
var log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null
module.exports = {
info() {
if (!log) return
log.info.apply(log, arguments)
},
warn() {
if (!log) return
log.warn.apply(log, arguments)
},
error() {
if (!log) return
log.error.apply(log, arguments)
},
setFilterMsg(msg) {
if (!log || !log.setFilterMsg) return
if (typeof msg !== 'string') return
log.setFilterMsg(msg)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment