Commit 290d5b90 by 李伟康

增加30天免登

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