feat: 退出登录、获取用户信息
This commit is contained in:
parent
3fad6cecf8
commit
ac125a8d3c
16
api/api.js
16
api/api.js
|
|
@ -15,9 +15,21 @@ class Api {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 游客登录
|
// 游客登录
|
||||||
static guestLogin(data) {
|
static guestLogin() {
|
||||||
let url = `${config.host}/worker/worker/guestLogin`;
|
let url = `${config.host}/worker/worker/guestLogin`;
|
||||||
return fetch.request('postFrom', url, data, false)
|
return fetch.request('postFrom', url, {}, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 退出登录
|
||||||
|
static logout() {
|
||||||
|
let url = `${config.host}/worker/worker/logout`;
|
||||||
|
return fetch.request('postFrom', url, {}, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取用户信息
|
||||||
|
static userInfo() {
|
||||||
|
let url = `${config.host}/worker/worker/show`;
|
||||||
|
return fetch.request('postFrom', url, {}, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
16
pages.json
16
pages.json
|
|
@ -1,13 +1,5 @@
|
||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
{
|
|
||||||
"path" : "pages/user/login",
|
|
||||||
"style" :
|
|
||||||
{
|
|
||||||
"navigationBarTitleText" : "登录",
|
|
||||||
"disableScroll": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"path" : "pages/index/index",
|
"path" : "pages/index/index",
|
||||||
"style" :
|
"style" :
|
||||||
|
|
@ -16,6 +8,14 @@
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path" : "pages/user/login",
|
||||||
|
"style" :
|
||||||
|
{
|
||||||
|
"navigationBarTitleText" : "登录",
|
||||||
|
"disableScroll": true
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path" : "pages/user/user",
|
"path" : "pages/user/user",
|
||||||
"style" :
|
"style" :
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,10 @@ const toDetail = (id) => {
|
||||||
helpers.jumpToPage('order-info', `id=${id}`)
|
helpers.jumpToPage('order-info', `id=${id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onLoad(() => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ import api from "../../api/api";
|
||||||
import {throttle} from "../../utils/throttle";
|
import {throttle} from "../../utils/throttle";
|
||||||
|
|
||||||
const visitor = () => {
|
const visitor = () => {
|
||||||
api.guestLogin({}).then(res => {
|
api.guestLogin().then(res => {
|
||||||
storageUserInfo(res)
|
storageUserInfo(res)
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<view class="ctr">
|
<view class="ctr" v-if="userInfo.id !== undefined">
|
||||||
<view class="fixed-top">
|
<view class="fixed-top">
|
||||||
<me-top title="我的" :is-show-icon="false"></me-top>
|
<me-top title="我的" :is-show-icon="false"></me-top>
|
||||||
</view>
|
</view>
|
||||||
|
|
@ -8,14 +8,14 @@
|
||||||
<view class="header flex-l">
|
<view class="header flex-l">
|
||||||
<view class="avatar" :style="{background: 'var(--defaultUserAvatar)'}"></view>
|
<view class="avatar" :style="{background: 'var(--defaultUserAvatar)'}"></view>
|
||||||
<view class="info">
|
<view class="info">
|
||||||
<view class="name">刘强西</view>
|
<view class="name">{{ userInfo.name }}</view>
|
||||||
<view class="phone">18628195903</view>
|
<view class="phone">{{ userInfo.tel }}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="decorate"></view>
|
<view class="decorate"></view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="menus">
|
<view class="menus">
|
||||||
<view class="item flex-sb" hover-class="auto-mask-layer-radius8" hover-start-time="0" hover-stay-time="50">
|
<view class="item flex-sb" @click="logout()" hover-class="auto-mask-layer-radius8" hover-start-time="0" hover-stay-time="50">
|
||||||
<view class="icon flex-c">
|
<view class="icon flex-c">
|
||||||
<me-icon type="icon-logout" color="var(--descriptionColor)" size="56rpx"></me-icon>
|
<me-icon type="icon-logout" color="var(--descriptionColor)" size="56rpx"></me-icon>
|
||||||
</view>
|
</view>
|
||||||
|
|
@ -36,12 +36,41 @@
|
||||||
import {onLoad, onShow} from '@dcloudio/uni-app'
|
import {onLoad, onShow} from '@dcloudio/uni-app'
|
||||||
import {ref, reactive, computed, watch, inject} from 'vue'
|
import {ref, reactive, computed, watch, inject} from 'vue'
|
||||||
import MeIcon from "../../components/me-icon/me-icon";
|
import MeIcon from "../../components/me-icon/me-icon";
|
||||||
import MeButton from "../../components/me-button/me-button";
|
|
||||||
import MeEmptySpace from "../../components/me-empty-space/me-empty-space.vue";
|
import MeEmptySpace from "../../components/me-empty-space/me-empty-space.vue";
|
||||||
import MeTop from "../../components/me-top/me-top.vue";
|
import MeTop from "../../components/me-top/me-top.vue";
|
||||||
|
import api from "../../api/api";
|
||||||
|
import helpers from "../../utils/helpers";
|
||||||
const listMarginTop = computed(() => {
|
const listMarginTop = computed(() => {
|
||||||
return (inject('globalData').statusBarH + (inject('globalData').customBarH - inject('globalData').statusBarH)) * 2
|
return (inject('globalData').statusBarH + (inject('globalData').customBarH - inject('globalData').statusBarH)) * 2
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const userInfo = ref({})
|
||||||
|
|
||||||
|
onShow(() => {
|
||||||
|
updateUserInfo()
|
||||||
|
})
|
||||||
|
|
||||||
|
const updateUserInfo = () => {
|
||||||
|
api.userInfo().then((res) => {
|
||||||
|
uni.setStorageSync('user_info', res)
|
||||||
|
userInfo.value = res
|
||||||
|
}).catch(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
|
//退出登录
|
||||||
|
const logout = () => {
|
||||||
|
uni.showLoading({
|
||||||
|
title: '退出中…'
|
||||||
|
});
|
||||||
|
api.logout().then(() => {
|
||||||
|
uni.removeStorageSync('token')
|
||||||
|
uni.removeStorageSync('user_info')
|
||||||
|
|
||||||
|
helpers.jumpToPage('login', '', 'redirectTo')
|
||||||
|
}).catch(() => {}).finally(() => {
|
||||||
|
uni.hideLoading();
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user