Browse Source

获取用户信息;退出登录;

sinea17 1 year ago
parent
commit
e309550e9b
3 changed files with 82 additions and 26 deletions
  1. 16 0
      api/user.js
  2. 17 14
      pages/self/index.vue
  3. 49 12
      pages/self/info.vue

+ 16 - 0
api/user.js

@@ -0,0 +1,16 @@
+import request from '@/api'
+
+const openid = uni.getStorageSync('openid')
+
+const userService = {
+	// 使用openid获取小程序用户信息
+	getUserInfo: () => request.getPath('/info/{openid}', {}, {
+		openid
+	}),
+	// 使用openid退出用户登录
+	logout: () => request.getPath('/logout/{openid}', {}, {
+		openid
+	})
+}
+
+export default userService

+ 17 - 14
pages/self/index.vue

@@ -4,11 +4,11 @@
 			<image v-if="userInfo && userInfo.avatar" class="avatar" :src="userInfo.avatar" mode="aspectFill"></image>
 			<image v-if="userInfo && userInfo.avatar" class="avatar" :src="userInfo.avatar" mode="aspectFill"></image>
 			<image v-else class="avatar" src="../../static/img_avatar.png" mode="aspectFill"></image>
 			<image v-else class="avatar" src="../../static/img_avatar.png" mode="aspectFill"></image>
 			<view v-if="userInfo" class="info">
 			<view v-if="userInfo" class="info">
-				<view class="name">{{ userInfo.name }}</view>
-				<view class="company">{{ userInfo.company }}</view>
+				<view class="name">{{ userInfo.phone }}</view>
+				<view class="company">{{ userInfo.phone }}</view>
 				<image class="arrow" src="../../static/icon_arrow.png"></image>
 				<image class="arrow" src="../../static/icon_arrow.png"></image>
 			</view>
 			</view>
-			<button type='primary' class="btn" v-show="!isAuth" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">立即登录</button>
+			<button type="primary" class="btn" v-show="!userInfo.sessionKey" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">立即登录</button>
 		</view>
 		</view>
 		<view class="menu-panel">
 		<view class="menu-panel">
 			<view class="item" v-for="(item, index) in menuList" :key="index" @click="handleMenu(item.value)">
 			<view class="item" v-for="(item, index) in menuList" :key="index" @click="handleMenu(item.value)">
@@ -36,13 +36,13 @@
 </template>
 </template>
 
 
 <script>
 <script>
+import userService from '@/api/user.js';
 import avatar from '@/static/taxation/poster.jpg';
 import avatar from '@/static/taxation/poster.jpg';
 export default {
 export default {
 	components: {},
 	components: {},
 	data() {
 	data() {
 		return {
 		return {
 			userInfo: '',
 			userInfo: '',
-			isAuth : false,
 			menuList: [
 			menuList: [
 				{
 				{
 					label: '我的订单',
 					label: '我的订单',
@@ -64,10 +64,11 @@ export default {
 			navList: [
 			navList: [
 				{
 				{
 					label: '我的企业',
 					label: '我的企业',
-					value: 1,
-				},{
+					value: 1
+				},
+				{
 					label: '我的合同',
 					label: '我的合同',
-					value: 2,
+					value: 2
 				},
 				},
 				// {
 				// {
 				// 	label: '企业资料',
 				// 	label: '企业资料',
@@ -148,14 +149,16 @@ export default {
 	},
 	},
 	onLoad() {},
 	onLoad() {},
 	onShow() {
 	onShow() {
-		this.isAuth = getApp().globalData.globalAuth;
+		this.getUserInfo();
 	},
 	},
 	methods: {
 	methods: {
-		getPhoneNumber(e){
+		getPhoneNumber(e) {
 			let res = getApp().getPhoneNumber(e);
 			let res = getApp().getPhoneNumber(e);
-			if (res){
-				
-			}
+			if (res) this.getUserInfo();
+		},
+		async getUserInfo() {
+			const { data } = await userService.getUserInfo();
+			this.userInfo = data;
 		},
 		},
 		handleOpenLogin() {
 		handleOpenLogin() {
 			// this.userInfo = {
 			// this.userInfo = {
@@ -173,7 +176,7 @@ export default {
 				url: 'info'
 				url: 'info'
 			});
 			});
 		},
 		},
-		handleMenu(val){
+		handleMenu(val) {
 			let url = '';
 			let url = '';
 			switch (val) {
 			switch (val) {
 				case 1:
 				case 1:
@@ -231,4 +234,4 @@ export default {
 
 
 <style lang="scss" scoped>
 <style lang="scss" scoped>
 @import 'index.scss';
 @import 'index.scss';
-</style>
+</style>

+ 49 - 12
pages/self/info.vue

@@ -6,37 +6,74 @@
 		</view>
 		</view>
 		<view class="row">
 		<view class="row">
 			<view class="label">姓名</view>
 			<view class="label">姓名</view>
-			<view class="text">Caocao</view>
+			<view class="text">--</view>
 		</view>
 		</view>
 		<view class="row">
 		<view class="row">
 			<view class="label">绑定手机</view>
 			<view class="label">绑定手机</view>
-			<view class="text">18863100789</view>
+			<view class="text">{{ userInfo.phone }}</view>
 		</view>
 		</view>
 		<view class="space"></view>
 		<view class="space"></view>
 		<view class="row">
 		<view class="row">
 			<view class="label">所属单位</view>
 			<view class="label">所属单位</view>
-			<view class="text">天津超易达胜科技</view>
+			<view class="text">--</view>
 		</view>
 		</view>
 		<view class="row">
 		<view class="row">
 			<view class="label">所属部门</view>
 			<view class="label">所属部门</view>
-			<view class="text">办公室</view>
+			<view class="text">--</view>
 		</view>
 		</view>
 		<view class="row">
 		<view class="row">
 			<view class="label">职务</view>
 			<view class="label">职务</view>
-			<view class="text">经理</view>
+			<view class="text">--</view>
 		</view>
 		</view>
 		<view class="space" style="height: 27.47rpx"></view>
 		<view class="space" style="height: 27.47rpx"></view>
-		<view class="row">
+		<view class="row" @click="handleLogout">
 			<view class="label">退出登录</view>
 			<view class="label">退出登录</view>
 		</view>
 		</view>
+		<uni-popup ref="alertDialog" type="dialog">
+			<uni-popup-dialog
+				type="info"
+				cancelText="取消"
+				confirmText="确认"
+				title="系统提示"
+				content="确认退出当前登录账号?"
+				@confirm="dialogConfirm"
+				@close="dialogClose"
+			></uni-popup-dialog>
+		</uni-popup>
 	</view>
 	</view>
 </template>
 </template>
 
 
-<script></script>
+<script>
+import userService from '@/api/user.js';
+export default {
+	components: {},
+	data() {
+		return {
+			userInfo: ''
+		};
+	},
+	onLoad() {
+		this.getUserInfo();
+	},
+	methods: {
+		handleLogout() {
+			this.$refs.alertDialog.open();
+		},
+		async getUserInfo() {
+			const { data } = await userService.getUserInfo();
+			this.userInfo = data;
+		},
+		async dialogConfirm() {
+			await userService.logout();
+			uni.navigateBack();
+		}
+	}
+};
+</script>
 
 
 <style lang="scss" scoped>
 <style lang="scss" scoped>
 .page-wrap {
 .page-wrap {
-	.row{
+	.row {
 		min-height: 96.15rpx;
 		min-height: 96.15rpx;
 		font-size: 27.47rpx;
 		font-size: 27.47rpx;
 		display: flex;
 		display: flex;
@@ -47,7 +84,7 @@
 		background: #fff;
 		background: #fff;
 		position: relative;
 		position: relative;
 		&:first-child::before,
 		&:first-child::before,
-		&+.row::before{
+		& + .row::before {
 			content: '';
 			content: '';
 			position: absolute;
 			position: absolute;
 			left: 0;
 			left: 0;
@@ -55,15 +92,15 @@
 			top: 0;
 			top: 0;
 			height: 1px;
 			height: 1px;
 			background: #e0e0e0;
 			background: #e0e0e0;
-			transform: scaleY(.5);
+			transform: scaleY(0.5);
 		}
 		}
-		.avatar{
+		.avatar {
 			width: 82.42rpx;
 			width: 82.42rpx;
 			height: 82.42rpx;
 			height: 82.42rpx;
 			border-radius: 50%;
 			border-radius: 50%;
 		}
 		}
 	}
 	}
-	.space{
+	.space {
 		background: #f3f3f3;
 		background: #f3f3f3;
 		height: 13.74rpx;
 		height: 13.74rpx;
 	}
 	}