Browse Source

no message

feature/v1.0
xpz2018 5 years ago
parent
commit
5b3f8821f5
2 changed files with 82 additions and 29 deletions
  1. 70
      pages/login/index.js
  2. 41
      pages/login/index.wxml

70
pages/login/index.js

@ -1,6 +1,6 @@
//获取应用实例 //获取应用实例
import Dialog from '../../components/dialog/dialog' import Dialog from '../../components/dialog/dialog'
import { config, postCaptcha, loginCaptcha, loginPwd, verifyCode } from "../api/user"
import { config, wechatApplet, loginWechat, postCaptcha, loginCaptcha, loginPwd, verifyCode } from "../api/user"
import { sconfig, loginToken, getBaseInfo } from "../api/saas" import { sconfig, loginToken, getBaseInfo } from "../api/saas"
const util = require('../../utils/util') const util = require('../../utils/util')
const storage = require('../../utils/storage') const storage = require('../../utils/storage')
@ -20,6 +20,7 @@ Page({
captcha: null captcha: null
}, },
loging: false, loging: false,
regist: false,
qrPage: null, qrPage: null,
metaData: null, metaData: null,
code: null code: null
@ -37,6 +38,7 @@ Page({
let q = decodeURIComponent(options.q) let q = decodeURIComponent(options.q)
this.data.code = q.substring(q.indexOf('?')) this.data.code = q.substring(q.indexOf('?'))
} }
this.wxLogin()
}, },
onReady: function () { onReady: function () {
wx.getSystemInfo({ wx.getSystemInfo({
@ -91,20 +93,20 @@ Page({
config.header = { 'Authorization': 'QNT ' + authorization } config.header = { 'Authorization': 'QNT ' + authorization }
loginToken({loginToken: app.globalData.token}).then(result => { loginToken({loginToken: app.globalData.token}).then(result => {
sconfig.header = { 'Authorization': 'QNT ' + result.data } sconfig.header = { 'Authorization': 'QNT ' + result.data }
wx.redirectTo({ url: '/pages/index/index' })
// getBaseInfo().then(result => {
// this.setData({ loging: false})
// app.userInfo = result.data
// wx.hideLoading()
// wx.redirectTo({ url: '/pages/index/index' })
// }).catch(err => {
// wx.hideLoading()
// util.showToast(err)
// app.globalData.token = null
// storage.remove('Authorization')
// config.header = null
// this.setData({ loging: false})
// })
// wx.redirectTo({ url: '/pages/index/index' })
getBaseInfo().then(result => {
this.setData({ loging: false})
app.userInfo = result.data
wx.hideLoading()
wx.redirectTo({ url: '/pages/index/index' })
}).catch(err => {
wx.hideLoading()
util.showToast(err)
app.globalData.token = null
storage.remove('Authorization')
config.header = null
this.setData({ loging: false})
})
}).catch(err => { }).catch(err => {
wx.hideLoading() wx.hideLoading()
util.showToast(err) util.showToast(err)
@ -114,10 +116,47 @@ Page({
this.setData({ loging: false}) this.setData({ loging: false})
}) })
}, },
wxLogin: function(){
wx.login({
success: res => {
wechatApplet({ authCode: res.code }).then(result => {
storage.put('tmpAuthToken', result.data.tmpAuthToken, 98)
})
}
})
},
/************************************** 注册流程 ********************************************/ /************************************** 注册流程 ********************************************/
readAgreement: function () { readAgreement: function () {
wx.navigateTo({ url: '/pages/htmls/agreement/index' }) wx.navigateTo({ url: '/pages/htmls/agreement/index' })
}, },
onGotUserInfo: function (e) {
if(this.data.loging){
return
}
this.setData({ loging: true })
if(this.data.form.tmpAuthToken){
this.registAccount()
return
}
loginWechat({ encryptedData: e.detail.encryptedData, iv: e.detail.iv }).then(result => {
storage.put('Authorization', result.data.token)
app.globalData.token = result.data.token
this.data.form.tmpAuthToken = result.data.tmpAuthToken
if(e.currentTarget.id == 'btn-login'){
this.registAccount()
} else {
this.fetchUserInfo()
}
}).catch(error => {
if(error.data && error.data.tmpAuthToken){
this.data.form.tmpAuthToken = error.data.tmpAuthToken
this.setData({ regist: true, loging: false })
} else {
this.setData({ loging: false })
}
util.showToast(error.message)
})
},
inputFocus: function(e) { inputFocus: function(e) {
app.globalData.keyboardHeight = e.detail.height app.globalData.keyboardHeight = e.detail.height
}, },
@ -208,6 +247,7 @@ Page({
this.setData({ type: 1, ['form.password']: null, loginEnable: true }) this.setData({ type: 1, ['form.password']: null, loginEnable: true })
} }
}, },
/************************************** 二维码流程 ********************************************/ /************************************** 二维码流程 ********************************************/
fetchQrCode: function(code){ fetchQrCode: function(code){
wx.showLoading({ title: '处理中', mask: true }) wx.showLoading({ title: '处理中', mask: true })

41
pages/login/index.wxml

@ -3,47 +3,60 @@
<image style="width:192rpx;height:192rpx" src="/assets/image/icon_logo.png"></image> <image style="width:192rpx;height:192rpx" src="/assets/image/icon_logo.png"></image>
</view> </view>
<view style="padding: 30rpx 80rpx">
<view style="padding: 30rpx 80rpx" wx:if="{{ regist }}">
<view class="flex"> <view class="flex">
<image style="width:40rpx;height:40rpx" src="/assets/image/icon_phone.png"></image> <image style="width:40rpx;height:40rpx" src="/assets/image/icon_phone.png"></image>
<text class="label" style="margin-left:24rpx">手机号码</text> <text class="label" style="margin-left:24rpx">手机号码</text>
</view> </view>
<view class="cu-form-group" style="min-height:120rpx;border-bottom:1rpx solid #eee;padding:0rpx"> <view class="cu-form-group" style="min-height:120rpx;border-bottom:1rpx solid #eee;padding:0rpx">
<input id="account" type="number" placeholder-style="color:#aaa" maxlength="11" placeholder="请输入手机号" value="{{form.account}}" bindinput="bindInput" />
<input id="account" type="number" placeholder-style="color:#aaa" maxlength="11" placeholder="请输入手机号"
value="{{form.account}}" bindinput="bindInput" />
</view> </view>
<view class="flex" style="margin-top: 40rpx"> <view class="flex" style="margin-top: 40rpx">
<image style="width:40rpx;height:40rpx" src="{{type == 1 ? '/assets/image/icon_code.png' : '/assets/image/icon_pwd.png'}}"></image> <image style="width:40rpx;height:40rpx" src="{{type == 1 ? '/assets/image/icon_code.png' : '/assets/image/icon_pwd.png'}}"></image>
<text class="label" style="margin-left:12rpx">{{type == 1 ? '验证码' : '密码'}}</text> <text class="label" style="margin-left:12rpx">{{type == 1 ? '验证码' : '密码'}}</text>
</view> </view>
<view wx:if="{{type == 1}}" class="cu-form-group" style="min-height:120rpx;border-bottom:1rpx solid #eee;padding:0rpx;border-top:0rpx solid #eee;"> <view wx:if="{{type == 1}}" class="cu-form-group" style="min-height:120rpx;border-bottom:1rpx solid #eee;padding:0rpx;border-top:0rpx solid #eee;">
<input id="captcha" type="number" placeholder-style="color:#aaa" maxlength="6" placeholder="请输入{{type == 1 ? '验证码' : '密码'}}" bindinput="bindInput" />
<van-button size="small" plain type="info" custom-style="width:220rpx" disabled="{{!mobileEnable || !codeEnable}}" bind:click="fetchCaptcha">
<van-count-down class="count-down" time="{{ 60000 }}" use-slot auto-start="{{false}}" bind:change="onCountChange" bind:finish="onFinished">
<input id="captcha" type="number" placeholder-style="color:#aaa" maxlength="6"
placeholder="请输入{{type == 1 ? '验证码' : '密码'}}" bindinput="bindInput" />
<van-button size="small" plain type="info" custom-style="width:220rpx" disabled="{{!mobileEnable || !codeEnable}}"
bind:click="fetchCaptcha">
<van-count-down class="count-down" time="{{ 60000 }}" use-slot auto-start="{{false}}" bind:change="onCountChange"
bind:finish="onFinished">
<text class="text-sm">{{second}}</text> <text class="text-sm">{{second}}</text>
</van-count-down> </van-count-down>
</van-button> </van-button>
</view> </view>
<view wx:else class="cu-form-group" style="min-height:120rpx;border-bottom:1rpx solid #eee;padding:0rpx"> <view wx:else class="cu-form-group" style="min-height:120rpx;border-bottom:1rpx solid #eee;padding:0rpx">
<input id="password" placeholder-style="color:#aaa" type="{{pwdType}}" maxlength="20" placeholder="请输入验密码" bindinput="bindInput" bindfocus="inputFocus" />
<input id="password" placeholder-style="color:#aaa" type="{{pwdType}}" maxlength="20" placeholder="请输入验密码"
bindinput="bindInput" bindfocus="inputFocus" />
</view> </view>
<view style="margin-top:24rpx;text-align:end;"> <view style="margin-top:24rpx;text-align:end;">
<text class="label" style="font-size:30rpx;padding: 12rpx 0rpx 12rpx 24rpx" bindtap="changeType">{{type == 1 ? '密码登录' : '验证码登录'}}</text>
<text class="label" style="font-size:30rpx;padding: 12rpx 0rpx 12rpx 24rpx"
bindtap="changeType">{{type == 1 ? '密码登录' : '验证码登录'}}</text>
</view> </view>
</view> </view>
<view style="margin-top:20rpx;padding:40rpx 80rpx">
<van-button block type="info" loading="{{loging}}" loading-text="登录中..." disabled="{{loginEnable}}" bind:click="registAccount">登录</van-button>
<view wx:else style="margin-top:16rpx;padding:30rpx">
<view style="text-align: center" class="text-xl">服务协议和隐私政策</view>
<view class="text-df" style="padding:40rpx 30rpx">
<text class="text-df">请你务必审慎阅读、充分理解“服务协议”和“隐私政策”各条款,包括但不限于:为了向你提工厂经营管理、订单结算以及其他业务的相关服务,我们需要获你的个人微信信息,然后验证是你本人在操作。
你可阅读</text><text class="text-blue" bindtap="readAgreement">《纸通宝SAAS服务协议》</text>了解详细信息,如你同意,请点击“同意”开始接受我们的服务。
</view>
</view> </view>
<!-- <view style="margin-top:20rpx;padding:40rpx 80rpx">
<van-button block type="info" loading="{{loging}}" loading-text="登录中..." disabled="{{loginEnable}}" open-type="getUserInfo"
bind:getuserinfo="onGotUserInfo">登录</van-button>
</view> -->
<!-- <view style="margin-top:30rpx;padding:30rpx 60rpx;">
<view style="margin-top:20rpx;padding:40rpx 80rpx">
<van-button block type="info" loading="{{loging}}" loading-text="登录中..." disabled="{{loginEnable}}" <van-button block type="info" loading="{{loging}}" loading-text="登录中..." disabled="{{loginEnable}}"
wx:if="{{metaData && token}}" bind:click="bindAccount">提交</van-button>
bind:click="registAccount" wx:if="{{ regist }}">提交</van-button>
<van-button block type="info" loading="{{loging}}" loading-text="登录中..." open-type="getUserInfo" <van-button block type="info" loading="{{loging}}" loading-text="登录中..." open-type="getUserInfo"
bind:getuserinfo="onGotUserInfo" wx:else>同意</van-button> bind:getuserinfo="onGotUserInfo" wx:else>同意</van-button>
</view> -->
</view>
<view class="flex flex-center" style="margin-top:10rpx;font-size:24rpx;color:#008AFF;text-align: center"> <view class="flex flex-center" style="margin-top:10rpx;font-size:24rpx;color:#008AFF;text-align: center">
<text class="cuIcon-infofill md-icon">仅限纸通宝工厂户使用</text>
<text class="cuIcon-infofill md-icon">仅限纸通宝工厂户使用</text>
</view> </view>
<van-dialog id="van-dialog" /> <van-dialog id="van-dialog" />
Loading…
Cancel
Save