Commit 0321957c by 莫晓莉

mxl登录

parent 77807522
......@@ -5,12 +5,14 @@
"style": {
"navigationBarTitleText": "登录模板"
}
}, {
},
{
"path": "pages/login/login",
"style": {
"navigationBarTitleText": "登录"
}
}, {
},
{
"path": "pages/reg/reg",
"style": {
"navigationBarTitleText": "注册"
......
......@@ -27,85 +27,119 @@
mapMutations
} from 'vuex'
export default {
computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
onLoad() {
const loginType = uni.getStorageSync('login_type')
if (loginType === 'local') {
this.login(uni.getStorageSync('username'))
return
}
let uniIdToken = uni.getStorageSync('uniIdToken')
if (uniIdToken) {
this.login(uni.getStorageSync('username'))
uniCloud.callFunction({
name: 'user-center',
data: {
action: 'checkToken',
},
success: (e) => {
console.log('checkToken success', e);
if (e.result.code > 0) {
//token过期或token不合法,重新登录
if (this.forcedLogin) {
uni.reLaunch({
url: '../login/login'
});
} else {
uni.navigateTo({
url: '../login/login'
});
}
}
},
fail(e) {
uni.showModal({
content: JSON.stringify(e),
showCancel: false
})
}
import {
getUserByToken
} from "@/api/login"
export default {
onLoad: function() {
const token=uni.getStorageSync('token')
console.log(token);
if(token){
uni.switchTab({
url:'/pages/login/login'
})
} else {
this.guideToLogin()
}
},
methods: {
...mapMutations(['login']),
guideToLogin() {
uni.showModal({
title: '未登录',
content: '您未登录,需要登录后才能继续',
/**
* 如果需要强制登录,不显示取消按钮
*/
showCancel: !this.forcedLogin,
success: (res) => {
if (res.confirm) {
/**
* 如果需要强制登录,使用reLaunch方式
*/
if (this.forcedLogin) {
uni.reLaunch({
url: '../login/login'
});
} else {
uni.navigateTo({
url: '../login/login'
});
}
}
}
});
}
// getUserByToken().then(res=>{
// if (res.code == 200) {
// uni.setStorageSync('token', res.data.data);
// uni.switchTab({
// url:'/pages/login/login'
// })
// }else{
// uni.switchTab({
// url:'/pages/reg/reg'
// })
// }
// })
// const token=uni.getStorageSync('token')
// if(token){
// uni.switchTab({
// url:'/pages/index/index'
// })
// }
}
// computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
// onLoad() {
// const loginType = uni.getStorageSync('login_type')
// if (loginType === 'local') {
// this.login(uni.getStorageSync('username'))
// return
// }
// let uniIdToken = uni.getStorageSync('uniIdToken')
// if (uniIdToken) {
// this.login(uni.getStorageSync('username'))
// uniCloud.callFunction({
// name: 'user-center',
// data: {
// action: 'checkToken',
// },
// success: (e) => {
// console.log('checkToken success', e);
// if (e.result.code > 0) {
// //token过期或token不合法,重新登录
// if (this.forcedLogin) {
// uni.reLaunch({
// url: '../login/login'
// });
// } else {
// uni.navigateTo({
// url: '../login/login'
// });
// }
// }
// },
// fail(e) {
// uni.showModal({
// content: JSON.stringify(e),
// showCancel: false
// })
// }
// })
// } else {
// this.guideToLogin()
// }
// },
// methods: {
// ...mapMutations(['login']),
// guideToLogin() {
// uni.showModal({
// title: '未登录',
// content: '您未登录,需要登录后才能继续',
// /**
// * 如果需要强制登录,不显示取消按钮
// */
// showCancel: !this.forcedLogin,
// success: (res) => {
// if (res.confirm) {
// /**
// * 如果需要强制登录,使用reLaunch方式
// */
// if (this.forcedLogin) {
// uni.reLaunch({
// url: '../login/login'
// });
// } else {
// uni.navigateTo({
// url: '../login/login'
// });
// }
// }
// }
// });
// }
// }
}
</script>
<style>
.hello {
/* .hello {
display: flex;
flex: 1;
flex-direction: column;
......@@ -124,5 +158,5 @@
.ul>view {
line-height: 25px;
}
} */
</style>
<template>
<view class="content">
<!-- <view class="input-group">
<view class="input-row border">
<text class="title">账号:</text>
<m-input type="text" focus clearable v-model="username" placeholder="请输入账号"></m-input>
</view>
<view class="input-row border">
<text class="title">密码:</text>
<m-input type="password" displayable v-model="password" placeholder="请输入密码"></m-input>
</view>
<view class="input-row">
<text class="title">确认密码:</text>
<m-input type="password" displayable v-model="confirmPassword" placeholder="请确认密码"></m-input>
</view>
</view> -->
<!-- 登录新样式start -->
<view style="text-align: center;color:#CA0000;font-size:45upx;padding:50upx;">
<!-- <image class="head-icon" style="" src="../../static/login/personal.png"></image> -->
欢迎注册!
</view>
<view class="login-area">
<view class="login-item">
<image class="login-icon" src="../../static/login/mine.png"></image>
<input class="login-item-input" placeholder="请输入姓名" v-model="addForm.name" />
......@@ -49,7 +32,7 @@
<view class="login-item mt25">
<image class="login-icon" src="../../static/login/code.png"></image>
<input class="login-item-input" placeholder="请输入手机号码" v-model="addForm.phone" />
<input name="phone" type="number" class="login-item-input" placeholder="请输入手机号码" v-model="addForm.phone" />
<view class="code-btn" style="" @click="codeInfo.clickType ? getCode() : ''">{{codeInfo.msg}}</view>
</view>
<view class="login-item mt25">
......@@ -177,70 +160,70 @@
})
},
register() {
/**
* 客户端对账号信息进行一些必要的校验。
* 实际开发中,根据业务需要进行处理,这里仅做示例。
*/
if (this.username.length < 3) {
uni.showToast({
icon: 'none',
title: '账号最短为 3 个字符'
});
return;
}
if (this.password.length < 6) {
uni.showToast({
icon: 'none',
title: '密码最短为 6 个字符'
});
return;
}
if (this.password !== this.confirmPassword) {
uni.showToast({
icon: 'none',
title: '两次密码输入不一致'
});
return;
}
// register() {
// /**
// * 客户端对账号信息进行一些必要的校验。
// * 实际开发中,根据业务需要进行处理,这里仅做示例。
// */
// if (this.username.length < 3) {
// uni.showToast({
// icon: 'none',
// title: '账号最短为 3 个字符'
// });
// return;
// }
// if (this.password.length < 6) {
// uni.showToast({
// icon: 'none',
// title: '密码最短为 6 个字符'
// });
// return;
// }
// if (this.password !== this.confirmPassword) {
// uni.showToast({
// icon: 'none',
// title: '两次密码输入不一致'
// });
// return;
// }
const data = {
username: this.username,
password: this.password
}
uniCloud.callFunction({
name: 'user-center',
data: {
action: 'register',
params: data
},
success(e) {
console.log("注册成功", e);
// const data = {
// username: this.username,
// password: this.password
// }
// uniCloud.callFunction({
// name: 'user-center',
// data: {
// action: 'register',
// params: data
// },
// success(e) {
// console.log("注册成功", e);
if (e.result.code === 0) {
uni.showToast({
title: '注册成功'
});
uni.setStorageSync('uniIdToken', e.result.token)
uni.setStorageSync('username', e.result.username)
uni.reLaunch({
url: '../main/main',
});
} else {
uni.showModal({
content: JSON.stringify(e.result),
showCancel: false
})
}
},
fail(e) {
uni.showModal({
content: JSON.stringify(e),
showCancel: false
})
}
})
}
// if (e.result.code === 0) {
// uni.showToast({
// title: '注册成功'
// });
// uni.setStorageSync('uniIdToken', e.result.token)
// uni.setStorageSync('username', e.result.username)
// uni.reLaunch({
// url: '../main/main',
// });
// } else {
// uni.showModal({
// content: JSON.stringify(e.result),
// showCancel: false
// })
// }
// },
// fail(e) {
// uni.showModal({
// content: JSON.stringify(e),
// showCancel: false
// })
// }
// })
// }
}
}
</script>
......
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