Commit f4f243b0 by 梁建民

登录

parent 4b0dd2ff
...@@ -58,16 +58,34 @@ App({ ...@@ -58,16 +58,34 @@ App({
}, },
onLaunch() { onLaunch() {
let me = this; let me = this;
// 查看是否授权
wx.getSetting({
success(res) {
console.log(res)
if (res.authSetting['scope.userInfo']) {
// 已经授权
wx.switchTab({
url: '/pages/tab/home/home'
})
}
}
})
wx.setStorage({ wx.setStorage({
key: "myUsername", key: "myUsername",
data: '18271408717' data: '18271408717'
}); });
this.conn.open({ this.conn.open({
apiUrl: WebIM.config.apiURL, apiUrl: WebIM.config.apiURL,
user: '18271408717', user: '18271408717',
pwd: '123456', pwd: '123456',
appKey: WebIM.config.appkey appKey: WebIM.config.appkey
}); });
WebIM.conn.listen({ WebIM.conn.listen({
onOpened(message) { onOpened(message) {
......
{ {
"pages": [ "pages": [
"pages/person/login/index",
"pages/person/auth/index", "pages/person/auth/index",
"pages/person/getphone/index", "pages/person/getphone/index",
"pages/person/login/index",
"pages/person/agreement/index", "pages/person/agreement/index",
"pages/person/successfully/index", "pages/person/successfully/index",
"pages/person/register/index", "pages/person/register/index",
......
var http = require('../../../utils/util.js'); const http = require('../../../utils/util.js');
var service = require('../../../utils/api.js'); import { apis } from '../../../utils/api.js';
Page({ Page({
...@@ -7,6 +7,7 @@ Page({ ...@@ -7,6 +7,7 @@ Page({
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
canIUse: wx.canIUse('button.open-type.getUserInfo'),
userinfo: [] userinfo: []
}, },
...@@ -15,16 +16,7 @@ Page({ ...@@ -15,16 +16,7 @@ Page({
*/ */
onLoad: function(options) { onLoad: function(options) {
// 查看是否授权
wx.getSetting({
success(res) {
console.log(res)
if (res.authSetting['scope.userInfo']) {
// 已经授权
}
}
})
}, },
/** /**
...@@ -81,42 +73,63 @@ Page({ ...@@ -81,42 +73,63 @@ Page({
bindGetUserInfo(e) { bindGetUserInfo(e) {
let self = this; let self = this;
this.setData({ if (e.detail.errMsg == 'getUserInfo:ok'){
userinfo: e.detail.userInfo wx.login({
}); success(res) {
if (res.code) {
wx.login({
success(res) { //存储用户资料
wx.showLoading(); self.setData({
if (res.code) { userinfo: e.detail.userInfo
//发起网络请求 });
http.getData(service.apis.getOpenId, {
code: res.code, //获取openId
'userinfo[avatarUrl]': self.data.userinfo.avatarUrl, http.getData(apis.getOpenId, {
'userinfo[nickName]': self.data.userinfo.nickName code: res.code,
}, function(res) { 'userinfo[avatarUrl]': self.data.userinfo.avatarUrl,
if (res.err_code === 0) { 'userinfo[nickName]': self.data.userinfo.nickName
wx.setStorage({ }, function (res) {
key: "openid",
data: res.data.openid if (res.err_code === 0) {
});
wx.setStorage({ wx.setStorage({
key: "session_key", key: "openid",
data: res.data.session_key data: res.data.openid
}); });
//授权成功跳转一键获取手机号 wx.setStorage({
wx.navigateTo({ key: "session_key",
url: '/pages/person/getphone/index' data: res.data.session_key
}) });
} //授权成功跳转一键获取手机号
}); wx.navigateTo({
} else { url: '/pages/person/getphone/index'
console.log('登录失败!' + res.errMsg) });
}
}, true);
} else {
console.log('登录失败!' + res.errMsg);
}
},
fail(res) {
wx.showLoading({
title: '网络不通,请重试'
})
} }
} })
}) }else{
//用户拒绝获取资料
wx.navigateTo({
url: '/pages/person/login/index'
});
}
}, },
/** /**
* 暂不注册 * 暂不注册
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
<!-- 授权 --> <!-- 授权 -->
<view class="auth"> <view class="auth">
<view> <view>
<button class="btn-com btn-com-b" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">一键授权(微信用户资料)</button> <button wx:if="{{canIUse}}" class="btn-com btn-com-b" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">一键授权</button>
<view wx:else>请升级微信版本</view>
<view class="btn-com btn-com-c" bindtap="toUrl">暂不注册,先看看</view> <view class="btn-com btn-com-c" bindtap="toUrl">暂不注册,先看看</view>
</view> </view>
<view class="text-wrap row"> <view class="text-wrap row">
......
var http = require('../../../utils/util.js'); const http = require('../../../utils/util.js');
var service = require('../../../utils/api.js'); import { apis } from '../../../utils/api.js';
Page({ Page({
...@@ -69,21 +69,38 @@ Page({ ...@@ -69,21 +69,38 @@ Page({
* 一键获取手机号 * 一键获取手机号
*/ */
getPhoneNumber(e) { getPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok'){
http.getData(service.apis.getwxUserInfo, {
openid: wx.getStorageSync('openid'),
session_key: wx.getStorageSync('session_key'),
encryptedData: e.detail.encryptedData,
iv: e.detail.iv
}, function(res) {
if (res.err_code === 0) {
http.getData(apis.getwxUserInfo, {
openid: wx.getStorageSync('openid'),
session_key: wx.getStorageSync('session_key'),
encryptedData: e.detail.encryptedData,
iv: e.detail.iv
}, function (res) {
} if (res.err_code === 0) {
});
//注入token
wx.setStorage({
key: "token",
data: res.data.access_token
});
wx.switchTab({
url: '/pages/tab/home/home'
});
}
},true);
}else{
//用户拒绝获取手机
wx.navigateTo({
url: '/pages/person/login/index'
});
}
} }
}) })
\ No newline at end of file
// pages/person/login/index.js const http = require('../../../utils/util.js');
import { apis } from '../../../utils/api.js';
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
error:false,
visible_pwd:false,
passwordType: true
}, },
/** /**
...@@ -20,17 +25,7 @@ Page({ ...@@ -20,17 +25,7 @@ Page({
*/ */
onReady: function() { onReady: function() {
wx.login({
success(res) {
console.log(res)
if (res.code) {
//发起网络请求
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
}, },
/** /**
...@@ -74,9 +69,54 @@ Page({ ...@@ -74,9 +69,54 @@ Page({
onShareAppMessage: function() { onShareAppMessage: function() {
}, },
getPhoneNumber(e) { /**
console.log(e.detail.errMsg) * 登录
console.log(e.detail.iv) */
console.log(e.detail.encryptedData) formSubmit: function (e) {
http.postData(apis.authlogin, e.detail.value,function(res){
if (res.err_code === 0){
//注入token
wx.setStorage({
key: "access_token",
data: res.data.access_token
});
wx.switchTab({
url: '/pages/tab/home/home'
})
}else{
wx.showToast({
title: res.err_msg,
icon: 'none',
duration: 2000
});
}
},true);
},
/**
* 密码是否可见
*/
toggleFn:function(e){
if (this.data['visible_pwd']) {
this.setData({
visible_pwd: false,
passwordType:true
});
} else {
this.setData({
visible_pwd: true,
passwordType:false
});
}
} }
}) })
\ No newline at end of file
{ {
"usingComponents": {} "usingComponents": {},
"navigationBarTitleText": "",
"navigationBarBackgroundColor": "white",
"navigationBarTextStyle": "black",
"backgroundColor": "white"
} }
\ No newline at end of file
<!-- 密码登录 --> <!-- 密码登录 -->
<view class="person"> <view class="person">
<view class="column tit"> <view class="column tit">
<text class="t1">Hi,上午好</text> <text class="t1">Hi,上午好</text>
<text class="t1">欢迎使用IC业务助手!</text> <text class="t1">欢迎使用IC业务助手!</text>
</view> </view>
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">212</button>
<form bindsubmit="formSubmit">
<view class="inp-wrap row verCenter">
<text class="icon iconfont iconiconxiantiaoshouji21"></text> <view class="inp-wrap row verCenter">
<view class="form-item-right row verCenter bothSide"> <text class="icon iconfont iconiconxiantiaoshouji21"></text>
<input placeholder="请输入手机号" placeholder-class="placeholderClass"></input> <view class="form-item-right row verCenter bothSide">
<view class="areacode" bindtap="switchPrice"> <input placeholder="请输入手机号" placeholder-class="placeholderClass" name="mobile" type="number"></input>
<text class="tel-value">中国 + 86</text> <view class="areacode" bindtap="switchPrice">
<text class="icon iconfont iconbianzu1"></text> <text class="tel-value">中国 + 86</text>
</view> <text class="icon iconfont iconbianzu1"></text>
</view> </view>
</view> </view>
</view>
<view class="inp-wrap row verCenter">
<text class="icon iconfont iconiconxiantiaoshouji2"></text> <view class="inp-wrap row verCenter">
<view class="form-item-right row verCenter bothSide"> <text class="icon iconfont iconiconxiantiaoshouji2"></text>
<input placeholder="请输入密码" placeholder-class="placeholderClass" class="pwd"></input> <view class="form-item-right row verCenter bothSide">
<text class="icon iconfont iconiconxiantiaoshouji4 pwd-ico"></text> <input placeholder="请输入密码" placeholder-class="placeholderClass" class="pwd" name="password" password='{{passwordType}}'></input>
</view> <block wx:if="{{visible_pwd}}">
</view> <text class="icon iconfont iconiconxiantiaoshouji3 pwd-ico" bindtap="toggleFn"></text>
</block>
<view class="error-wrap row bothSide verCenter"> <block wx:else>
<view class="error"> <text class="icon iconfont iconiconxiantiaoshouji4 pwd-ico" bindtap="toggleFn"></text>
<text class="icon iconfont iconiconxiantiaoshouji1"></text> </block>
<text class="txt">密码错误,请重新输入</text> </view>
</view> </view>
<navigator class="forget" url="pages/person/verifycode/index">忘记密码?</navigator>
</view> <view class="error-wrap row bothSide verCenter">
<button class="login-button">登录</button> <view class="error">
<block wx:if="{{error}}">
<view class="bottom row bothSide"> <text class="icon iconfont iconiconxiantiaoshouji1"></text>
<navigator class="txt" url="/pages/person/verifycode/index">验证码登录</navigator> <text class="txt">密码错误,请重新输入</text>
<navigator class="txt" url="/pages/person/verifycode/index">注册账户</navigator> </block>
</view> </view>
</view> <navigator class="forget" url="pages/person/verifycode/index">忘记密码?</navigator>
</view>
<button class="login-button" form-type="submit">登录</button>
</form>
<view class="bottom row bothSide">
<navigator class="txt" url="/pages/person/verifycode/index">验证码登录</navigator>
<navigator class="txt" url="/pages/person/verifycode/index">注册账户</navigator>
</view>
</view>
\ No newline at end of file
...@@ -5,7 +5,8 @@ const user_url = 'http://userapi.icsales.cc'; ...@@ -5,7 +5,8 @@ const user_url = 'http://userapi.icsales.cc';
const goods_url = 'http://goodsapi.icsales.cc'; const goods_url = 'http://goodsapi.icsales.cc';
const inquiry_url = 'http://inquiryapi.icsales.cc'; const inquiry_url = 'http://inquiryapi.icsales.cc';
const index_url = 'http://www.icsales.cc'; const index_url = 'http://www.icsales.cc';
const apis = {
const apis = {
/** /**
* 授权接口 * 授权接口
*/ */
...@@ -173,6 +174,7 @@ const apis = { ...@@ -173,6 +174,7 @@ const apis = {
userMarkmsg: user_url + '/user/markmsg' userMarkmsg: user_url + '/user/markmsg'
} }
module.exports = { module.exports = {
apis: apis apis: apis
} }
\ No newline at end of file
//数据请求(get) //数据请求(get)
const getData = (url, params, callBack) => { const getData = (url, params, callBack,loading) => {
wx.showNavigationBarLoading(); //顶部显示loading效果 wx.showNavigationBarLoading();
if(loading){
wx.showLoading();
}
wx.request({ wx.request({
url: url, url: url,
data: params, data: params,
...@@ -8,38 +13,66 @@ const getData = (url, params, callBack) => { ...@@ -8,38 +13,66 @@ const getData = (url, params, callBack) => {
"Content-Type": "applciation/json" "Content-Type": "applciation/json"
}, },
success: (res) => { success: (res) => {
typeof callBack == "function" && callBack(res.data, ""); typeof callBack == "function" && callBack(res.data, "");
wx.hideNavigationBarLoading(); wx.hideNavigationBarLoading();
wx.hideLoading();
}, },
fail: (err) => { fail: (err) => {
typeof callBack == "function" && callBack(null, err.errMsg); typeof callBack == "function" && callBack(null, err.errMsg);
console.log(err)
console.log(err);
wx.hideNavigationBarLoading(); wx.hideNavigationBarLoading();
wx.hideLoading();
} }
}) })
}; };
//数据请求(post) //数据请求(post)
const postData = (url, data, callBack) => { const postData = (url, params, callBack, loading) => {
showLoading("加载中", true)
var Url = getApp().globalUrl.baseUrl + url; wx.showNavigationBarLoading();
if (loading) {
wx.showLoading();
}
wx.request({ wx.request({
url: Url, url: url,
data: data, data: params,
header: { header: {
"Content-Type": "applciation/json" "Content-Type": "applciation/json"
}, },
method: "POST", method: "POST",
success: (res) => { success: (res) => {
wx.hideLoading() typeof callBack == "function" && callBack(res.data, "");
callBack(true, res.data)
wx.hideNavigationBarLoading();
wx.hideLoading();
}, },
fail: (err) => { fail: (err) => {
wx.hideLoading()
callBack(false, err) typeof callBack == "function" && callBack(null, err.errMsg);
console.log(err);
wx.hideNavigationBarLoading();
wx.hideLoading();
} }
}) })
}; };
//上传文件 //上传文件
const uploadFile = (paths, callBack) => { const uploadFile = (paths, callBack) => {
let gUrl = getApp().globalUrl; let gUrl = getApp().globalUrl;
...@@ -84,6 +117,8 @@ const chooseImg = (num, callback) => { ...@@ -84,6 +117,8 @@ const chooseImg = (num, callback) => {
} }
}) })
}; };
module.exports = { module.exports = {
getData: getData, getData: getData,
postData: postData, postData: postData,
......
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 sign in to comment