Commit 9057437e authored by peco's avatar peco

feat:部分登录功能

parent 0f427422
......@@ -5,15 +5,21 @@ const install = (Vue, vm) => {
/*************** 认证 API *****************/
// 登录
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 dataSetPreview = params => vm.$u.post(`${reportUrl}/report/dataset/preview`, params)
// 检查授权状态
const getAuthorized = params => vm.$u.get(`${baseUrl}/report/user/getAuthorized`, params)
vm.$u.api = {
quickLogin,
register,
getReportList,
dataSetPreview
dataSetPreview,
getAuthorized
}
}
......
......@@ -23,6 +23,15 @@
}
}
,{
"path" : "pages/login/authorized",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
......
<template>
<view>
个人中心
<u-button
class="my-u-block u-m-t-80"
type="warning"
shape="square"
:ripple="true"
@click="logout()"
>退出</u-button>
</view>
</template>
......@@ -15,6 +21,20 @@
},
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 @@
async onLoad() {
this.getReportList()
},
onShow() {
this.userAuthCheck()
},
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() {
let res = await this.$u.api.getReportList({id: '61c424a4c06bff0ce05d9a53'})
let res = await this.$u.api.getReportList({id: '61d697eec06bffb97312afeb'})
console.log()
const { Status, Result } = res.data
if (Status === 'true') {
......
<template>
<view>
授权中心
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
......@@ -10,12 +10,14 @@
<u-form-item label="用户名" prop="userName">
<u-input
v-model="params.userName"
placeholder="请输入用户名"
type="text"
/>
</u-form-item>
<u-form-item label="密码" prop="password">
<u-input
v-model="params.password"
placeholder="请输入密码"
type="password"
:password-icon="true"
/>
......@@ -26,9 +28,19 @@
type="warning"
shape="square"
:ripple="true"
@click="submit"
@click="submit('login')"
:disabled="!submitDisabled"
>登入</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>
</template>
......@@ -58,12 +70,27 @@ export default {
}
},
methods: {
submit() {
// 登录
submit(type) {
this.$refs.uForm.validate(async 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.toast('登录成功')
this.$u.toast(info.msg)
this.removeUserStorage()
this.saveUserStorage(res.data.Result)
// 登录成功后返回来源页面
let timer = setTimeout(() => {
const backUrl = uni.getStorageSync('back_url') || '/pages/index/index'
......@@ -77,7 +104,27 @@ export default {
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() {
this.$refs.uForm.setRules(this.rules)
......@@ -86,4 +133,9 @@ export default {
</script>
<style lang="scss" scoped>
.tips-text {
color: black;
size: 20rpx;
padding-top: 50rpx;
}
</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