Commit 9057437e authored by peco's avatar peco

feat:部分登录功能

parent 0f427422
...@@ -5,15 +5,21 @@ const install = (Vue, vm) => { ...@@ -5,15 +5,21 @@ const install = (Vue, vm) => {
/*************** 认证 API *****************/ /*************** 认证 API *****************/
// 登录 // 登录
let quickLogin = params => vm.$u.post(`${baseUrl}/report/user/quickLogin`, params) let quickLogin = params => vm.$u.post(`${baseUrl}/report/user/quickLogin`, params)
// 注册
let register = params => vm.$u.post(`${baseUrl}/report/user/register`, params)
// 报表列表 // 报表列表
const getReportList = params => vm.$u.get(`${reportUrl}/report/chart/getList`, params) const getReportList = params => vm.$u.get(`${reportUrl}/report/chart/getList`, params)
// 数据集 // 数据集
const dataSetPreview = params => vm.$u.post(`${reportUrl}/report/dataset/preview`, params) const dataSetPreview = params => vm.$u.post(`${reportUrl}/report/dataset/preview`, params)
// 检查授权状态
const getAuthorized = params => vm.$u.get(`${baseUrl}/report/user/getAuthorized`, params)
vm.$u.api = { vm.$u.api = {
quickLogin, quickLogin,
register,
getReportList, getReportList,
dataSetPreview dataSetPreview,
getAuthorized
} }
} }
......
...@@ -23,6 +23,15 @@ ...@@ -23,6 +23,15 @@
} }
} }
,{
"path" : "pages/login/authorized",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}
], ],
"globalStyle": { "globalStyle": {
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",
......
<template> <template>
<view> <view>
个人中心 <u-button
class="my-u-block u-m-t-80"
type="warning"
shape="square"
:ripple="true"
@click="logout()"
>退出</u-button>
</view> </view>
</template> </template>
...@@ -15,6 +21,20 @@ ...@@ -15,6 +21,20 @@
}, },
methods: { methods: {
// 退出登录
logout() {
uni.removeStorageSync('userId');
uni.removeStorageSync('username');
uni.removeStorageSync('appId');
uni.removeStorageSync('authorized');
uni.removeStorageSync('admin');
uni.removeStorageSync('show');
uni.clearStorage();
uni.reLaunch({
url: '/pages/index/index'
})
}
} }
} }
......
...@@ -34,9 +34,47 @@ ...@@ -34,9 +34,47 @@
async onLoad() { async onLoad() {
this.getReportList() this.getReportList()
}, },
onShow() {
this.userAuthCheck()
},
methods: { methods: {
//检查是否登录
userAuthCheck() {
var userId = uni.getStorageSync('userId')
this.getNewestAuthFromServer()
var authorized = uni.getStorageSync('authorized')
if (userId) {
if (authorized) {
} else {
uni.reLaunch({
url:'../login/authorized'
})
}
} else {
uni.reLaunch({
url: '../login/login'
})
}
},
//获取最新的授权信息
getNewestAuthFromServer() {
var param = {
id: uni.getStorageSync('usaerId')
}
this.$u.api.getAuthorized({param}).then(res=>{
const { Status, Result } = res.data
if (Status === 'true') {
uni.setStorageSync('authorized', Result.authorized)
}
})
},
async getReportList() { async getReportList() {
let res = await this.$u.api.getReportList({id: '61c424a4c06bff0ce05d9a53'}) let res = await this.$u.api.getReportList({id: '61d697eec06bffb97312afeb'})
console.log() console.log()
const { Status, Result } = res.data const { Status, Result } = res.data
if (Status === 'true') { if (Status === 'true') {
......
<template>
<view>
授权中心
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
...@@ -10,12 +10,14 @@ ...@@ -10,12 +10,14 @@
<u-form-item label="用户名" prop="userName"> <u-form-item label="用户名" prop="userName">
<u-input <u-input
v-model="params.userName" v-model="params.userName"
placeholder="请输入用户名"
type="text" type="text"
/> />
</u-form-item> </u-form-item>
<u-form-item label="密码" prop="password"> <u-form-item label="密码" prop="password">
<u-input <u-input
v-model="params.password" v-model="params.password"
placeholder="请输入密码"
type="password" type="password"
:password-icon="true" :password-icon="true"
/> />
...@@ -26,9 +28,19 @@ ...@@ -26,9 +28,19 @@
type="warning" type="warning"
shape="square" shape="square"
:ripple="true" :ripple="true"
@click="submit" @click="submit('login')"
:disabled="!submitDisabled" :disabled="!submitDisabled"
>登入</u-button> >登入</u-button>
<u-button
class="my-u-block u-m-t-80"
type="warning"
shape="square"
:ripple="true"
@click="submit('register')"
:disabled="!submitDisabled"
>注册</u-button>
<text class="tips-text">使用须知:仅限企业内部人员使用,使用前需要认证用户</text>
</view> </view>
</view> </view>
</template> </template>
...@@ -58,12 +70,27 @@ export default { ...@@ -58,12 +70,27 @@ export default {
} }
}, },
methods: { methods: {
submit() { // 登录
submit(type) {
this.$refs.uForm.validate(async valid => { this.$refs.uForm.validate(async valid => {
if (valid) { if (valid) {
let res = await this.$u.api.quickLogin(this.params) var info = {
url: this.$u.api.quickLogin(this.params),
msg: '登录成功'
}
if ('register' == type) {
info = {
url: this.$u.api.register(this.params),
msg: '注册成功'
}
}
let res = await info.url
this.$u.vuex('vuex_token', `${res.token_type} ${res.access_token}`) this.$u.vuex('vuex_token', `${res.token_type} ${res.access_token}`)
this.$u.toast('登录成功') this.$u.toast(info.msg)
this.removeUserStorage()
this.saveUserStorage(res.data.Result)
// 登录成功后返回来源页面 // 登录成功后返回来源页面
let timer = setTimeout(() => { let timer = setTimeout(() => {
const backUrl = uni.getStorageSync('back_url') || '/pages/index/index' const backUrl = uni.getStorageSync('back_url') || '/pages/index/index'
...@@ -77,7 +104,27 @@ export default { ...@@ -77,7 +104,27 @@ export default {
console.log('验证失败'); console.log('验证失败');
} }
}) })
},
// 清除用户信息
removeUserStorage() {
uni.removeStorageSync('userId');
uni.removeStorageSync('username');
uni.removeStorageSync('appId');
uni.removeStorageSync('authorized');
uni.removeStorageSync('admin');
uni.removeStorageSync('show');
},
// 存储用户信息
saveUserStorage(info) {
uni.setStorageSync('userId', info.id);
uni.setStorageSync('username', info.userName);
uni.setStorageSync('appId', info.appId);
uni.setStorageSync('authorized', info.authorized);
uni.setStorageSync('admin', info.admin);
uni.setStorageSync('show', info.show);
} }
}, },
onReady() { onReady() {
this.$refs.uForm.setRules(this.rules) this.$refs.uForm.setRules(this.rules)
...@@ -86,4 +133,9 @@ export default { ...@@ -86,4 +133,9 @@ export default {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.tips-text {
color: black;
size: 20rpx;
padding-top: 50rpx;
}
</style> </style>
\ No newline at end of file
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