Commit 290d5b90 by 李伟康

增加30天免登

1 parent 7f0c6598
......@@ -54,7 +54,7 @@ class UsersApi {
} else Promise.reject()
}
/**账号密码登录 */
accountLogin(data = {}) {
async accountLogin(data = {}) {
return api.post({
method: 'scrm.api.sso.wechat.applets.password.login',
...data,
......
......@@ -9,7 +9,15 @@ Component({
properties: {
show: Boolean,
text: String,
value: Boolean
value: {
type: Boolean,
value: false,
observer(n) {
this.setData({
agree: n
})
}
}
},
/**
......@@ -24,7 +32,8 @@ Component({
*/
methods: {
agree() {
let {agree} = this.data
this.triggerEvent('change', !agree)
},
}
})
\ No newline at end of file
......@@ -2,7 +2,8 @@
import USERAPI from '~/api/usersApi/index'
import {
selectAccountLogin,
setLoginInfo
setLoginInfo,
loginModal
} from '~/login/lib/index'
let thisPage
Component({
......@@ -154,7 +155,6 @@ Component({
password: formData.password
}
this.setBtnLoading()
console.log(target)
USERAPI[target](obj).then(({
code,
data,
......@@ -165,8 +165,19 @@ Component({
if (loginType == 1) this.checkLoginUserInfo(data)
else {
const {
sessionId
} = data
autoLogin
} = thisPage.data, {
sessionId
} = data,
validTime = 3600 * 24 * 30 * 1e3,
autoLoginFailureTime = Date.now() + validTime
if (autoLogin) {
wx.$storage.set('auto_login_object', {
failureTime: autoLoginFailureTime,
userName: formData.account,
password: formData.password
})
} else wx.$storage.rm('auto_login_object')
setLoginInfo(data, sessionId)
}
} else {
......@@ -250,16 +261,11 @@ Component({
}
},
/**获取loginToken */
reLogin(message) {
wx.showModal({
content: message || '获取loginToken失败',
confirmText: '重试',
confirmColor: '#3666FE'
}).then(({
confirm
}) => {
if (confirm) this.init()
async reLogin(message) {
const reload = await loginModal({
message: message || '获取loginToken失败'
})
if (reload) this.init()
}
},
lifetimes: {
......
......@@ -6,11 +6,11 @@ Page({
*/
data: {
/**0:微信 1:手机号 2:账号密码 */
loginType: 2,
loginType: 0,
/**按钮disabled */
disabled: true,
/**同意免登 */
agree: true
/**免登 */
autoLogin: false
},
onRoute(options) {},
/**
......@@ -61,6 +61,12 @@ Page({
* 用户点击右上角分享
*/
// onShareAppMessage() {},
/**30天免登 */
changeAgree(e){
this.setData({
autoLogin:e.detail
})
},
checkLoginBtn(disabled = false) {
const {
loginType
......
......@@ -3,5 +3,5 @@
<navigation-bar navStyle="background-color: rgba(0,0,0,0)">生意助手</navigation-bar>
<box loginType="{{loginType}}" disabled="{{disabled}}" id="box" />
<type-list loginType="{{loginType}}" />
<agree show="{{loginType == 2}}" text="30天内免登陆" value="{{agree}}" />
<agree show="{{loginType == 2}}" text="30天内免登陆" value="{{autoLogin}}" bindchange="changeAgree" />
</view>
\ No newline at end of file
......@@ -56,9 +56,26 @@ const loginSuccess = () => {
wx.$router.reLaunch(url, obj)
} else wx.$router.go('pages.index')
}
const loginModal = async ({
message,
confirmText
}) => {
return new Promise((resolve, reject) => {
wx.showModal({
content: message || '网络异常',
confirmText: confirmText || '重试',
confirmColor: '#3666FE',
success(res) {
if (res.confirm) resolve(res.confirm)
if (res.cancel) reject(false)
}
})
})
}
module.exports = {
selectAccountLogin,
loginSuccess,
setRouteData,
setLoginInfo
setLoginInfo,
loginModal
}
\ No newline at end of file
import {
setRouteData
setRouteData,
setLoginInfo,
loginModal
} from '../lib/index'
import {
getSessionId,
......@@ -37,7 +39,8 @@ Page({
{
url,
targetPath = url ? decodeURIComponent(url) : ''
} = this.options
} = this.options,
autoLoginObject = wx.$storage.get('auto_login_object')
wx.nextTick(() => {
let path = 'pages.index',
obj = {}
......@@ -52,7 +55,31 @@ Page({
obj = setRouteData(targetPath).obj
}
wx.$router.reLaunch(path, obj)
} else wx.$router.reLaunch('login.index', obj)
} else {
if (autoLoginObject) {
const {
failureTime,
userName,
password
} = autoLoginObject
if (Date.now() < failureTime) {
USERAPI.accountLogin({
userName,
password
}).then(async res => {
if (res.code == '0') {
const {data} = res
setLoginInfo(data, data.sessionId)
} else {
const reload = await loginModal({
message: '登录失败请重试'
})
if(reload) this.onShow()
}
})
} else wx.$router.reLaunch('login.index', obj)
} else wx.$router.reLaunch('login.index', obj)
}
})
} else wx.$router.reLaunch('login.index', obj)
})
......
......@@ -9,5 +9,6 @@ export const STORAGE_OBJECTkEY = {
sessionId: 'sessionId',
userInfo: 'userInfo',
system_info: 'systemInfo',
app_title: 'appTitle'
}
app_title: 'appTitle',
auto_login_object: 'auto_login_object'
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!