Commit d684c0f0 by 张天炜

小程序登录功能更新

parent f4f8bf07
......@@ -2,112 +2,126 @@
import Wx from '../../utils/Wx.js'
import api from '../../utils/Api.js'
const {
$Toast
$Toast
} = require('../../iview/base/index');
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
/**
* 页面的初始数据
*/
data: {
},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
},
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
},
handleWxAuth: function(event) {
Wx.login().then(res => {
api.login({
code: res.code,
signature: event.detail.signature,
rawData: event.detail.rawData,
encryptedData: event.detail.encryptedData,
iv: event.detail.iv,
scene: app.options.query && app.options.query.scene ? decodeURIComponent(app.options.query.scene) : ''
}).then(res => {
if (!res.code) {
app.globalData.userInfo = res.user
wx.setStorageSync('token', res.token)
$Toast({
content: '授权登录成功',
type: 'success'
});
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 1000);
} else {
$Toast({
content: '微信授权失败,请重试',
type: 'error'
});
}
})
})
},
handleWxAuth: function() {
var _this = this
Wx.login().then(res => {
//获取登录的临时凭证
_this.wxLoginCode = res.code
})
handlePhoneAuth: function(event) {
Wx.login().then(res => {
let encryptedData = event.detail.encryptedData
let iv = event.detail.iv
this.decodePhoneData(res.code, encryptedData, iv)
})
},
wx.getUserProfile({
desc: '用于完善个人资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中
success: (e) => {
api.login({
code: _this.wxLoginCode,
signature: e.signature,
rawData: e.rawData,
encryptedData: e.encryptedData,
iv: e.iv,
scene: app.options.query && app.options.query.scene ? decodeURIComponent(app.options.query.scene) : ''
}).then(res => {
console.log(res)
if (!_this.wxLoginCode) {
app.globalData.userInfo = res.user
wx.setStorageSync('token', res.token)
$Toast({
content: '授权登录成功',
type: 'success'
});
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 1000);
} else {
$Toast({
content: '微信授权失败,请重试',
type: 'error'
});
}
})
},
fail: (e) => {
console.log(e)
}
})
// 返回首页
gotoHome: function() {
wx.switchTab({
url: '../index/index',
})
},
/**
* 解密手机号数据
*/
decodePhoneData: function(code, encryptedData, iv) {
let that = this
api.getPhoneNumber({
code: code,
encryptedData: encryptedData,
iv: iv
}).then(res => {
if (!res.code) {
$Toast({
content: '手机号授权成功',
type: 'success'
});
let userInfo = app.globalData.userInfo
app.globalData.userInfo = {
...userInfo,
...res.data
}
} else {
$Toast({
content: '手机号授权失败',
type: 'error'
});
}
})
}
})
\ No newline at end of file
},
handlePhoneAuth: function(event) {
Wx.login().then(res => {
let encryptedData = event.detail.encryptedData
let iv = event.detail.iv
this.decodePhoneData(res.code, encryptedData, iv)
})
},
// 返回首页
gotoHome: function() {
wx.switchTab({
url: '../index/index',
})
},
/**
* 解密手机号数据
*/
decodePhoneData: function(code, encryptedData, iv) {
let that = this
api.getPhoneNumber({
code: code,
encryptedData: encryptedData,
iv: iv
}).then(res => {
if (!res.code) {
$Toast({
content: '手机号授权成功',
type: 'success'
});
let userInfo = app.globalData.userInfo
app.globalData.userInfo = {
...userInfo,
...res.data
}
} else {
$Toast({
content: '手机号授权失败',
type: 'error'
});
}
})
}
})
......@@ -8,7 +8,8 @@
<view>美好的教育,行走在路上</view>
</view>
<view class='action-wrapper'>
<i-button bindgetuserinfo="handleWxAuth" type="success" shape="circle" open-type='getUserInfo'>微信授权</i-button>
<!-- <i-button bindgetuserinfo="handleWxAuth" type="success" shape="circle" open-type='getUserInfo'>微信授权</i-button> -->
<i-button bindtap="handleWxAuth" type="success" shape="circle">微信授权</i-button>
<!-- <i-button bindgetphonenumber="handlePhoneAuth" type="info" shape="circle" open-type="getPhoneNumber">手机号授权</i-button> -->
<!-- <view class="text-small text-hint tip">请完成微信授权</view> -->
<i-button bindtap="gotoHome" type="default" shape="circle">暂不登录</i-button>
......
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": false,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true,
"nodeModules": false,
"autoAudits": false
},
"compileType": "miniprogram",
"libVersion": "2.10.2",
"appid": "wx1b834552a7d49bb3",
"projectname": "%E7%BE%8E%E8%A1%8C%E8%80%85%E4%BA%B2%E5%AD%90%E6%B8%B8",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"plugin": {
"current": -1,
"list": []
},
"game": {
"list": []
},
"gamePlugin": {
"current": -1,
"list": []
},
"miniprogram": {
"current": 16,
"list": [
{
"id": 16,
"name": "活动详情(水梨)",
"pathName": "pages/detail/index",
"query": "id=662",
"scene": null
},
{
"id": -1,
"name": "直播页面",
"pathName": "pages/live/live",
"query": "",
"scene": null
},
{
"id": -1,
"name": "个人中心",
"pathName": "pages/me/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "我的地址",
"pathName": "pages/address/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "添加地址",
"pathName": "pages/address/create",
"query": "",
"scene": null
},
{
"id": -1,
"name": "活动-下单购买",
"pathName": "pages/detail/enroll/index",
"query": "id=662",
"scene": null
},
{
"id": -1,
"name": "我的订单",
"pathName": "pages/me/order/index",
"scene": null
}
]
}
}
"description": "项目配置文件,详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"packOptions": {
"ignore": [],
"include": []
},
"setting": {
"urlCheck": false,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true,
"nodeModules": false,
"autoAudits": false,
"coverView": true,
"lazyloadPlaceholderEnable": false,
"preloadBackgroundData": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"enhance": true,
"useMultiFrameRuntime": true,
"showShadowRootInWxmlPanel": true,
"packNpmManually": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"useStaticServer": true,
"showES6CompileOption": false,
"checkInvalidKey": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"disableUseStrict": false,
"useCompilerPlugins": false,
"minifyWXML": true
},
"compileType": "miniprogram",
"libVersion": "2.10.2",
"appid": "wx1b834552a7d49bb3",
"projectname": "%E7%BE%8E%E8%A1%8C%E8%80%85%E4%BA%B2%E5%AD%90%E6%B8%B8",
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"miniprogram": {
"list": [
{
"name": "活动详情(水梨)",
"pathName": "pages/detail/index",
"query": "id=662",
"scene": null
},
{
"name": "直播页面",
"pathName": "pages/live/live",
"query": "",
"scene": null
},
{
"name": "个人中心",
"pathName": "pages/me/index",
"query": "",
"scene": null
},
{
"name": "我的地址",
"pathName": "pages/address/index",
"query": "",
"scene": null
},
{
"name": "添加地址",
"pathName": "pages/address/create",
"query": "",
"scene": null
},
{
"name": "活动-下单购买",
"pathName": "pages/detail/enroll/index",
"query": "id=662",
"scene": null
},
{
"name": "我的订单",
"pathName": "pages/me/order/index",
"query": "",
"scene": null
}
]
}
},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
}
}
\ No newline at end of file
{
"projectname": "%E7%BE%8E%E8%A1%8C%E8%80%85%E4%BA%B2%E5%AD%90%E6%B8%B8",
"setting": {
"compileHotReLoad": true
},
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"libVersion": "2.24.7"
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ export default {
login: obj => f(wx.login, obj),
checkSession: obj => f(wx.checkSession, obj),
authorize: obj => f(wx.authorize, obj),
getUserInfo: obj => f(wx.getUserInfo, obj),
// getUserInfo: obj => f(wx.getUserInfo, obj),
// 支付
requestPayment: obj => f(wx.requestPayment, obj),
......@@ -72,7 +72,8 @@ export default {
removeStorage: obj => f(wx.removeStorage, obj),
// 位置
getLocation: obj => f(wx.getLocation, obj),
//getLocation已注释,暂无具体业务调用该功能
// getLocation: obj => f(wx.getLocation, obj),
chooseLocation: obj => f(wx.chooseLocation, obj),
openLocation: obj => f(wx.openLocation, obj),
......
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