Переглянути джерело

新增头像相关处理及其他BUG修复

shuchang 3 місяців тому
батько
коміт
d6ec96bdd8

+ 30 - 22
pages/subpack/pages/myInfo/info.vue

@@ -4,7 +4,7 @@
 		<u-cell-group :border="false" :customStyle="{background: '#fff', margin: '30rpx',  borderRadius: '20rpx'}">
 			<u-cell title="头像" isLink @click="changeAvatar">
 				<template #value>
-					<up-avatar :src="vuex_user.avatar" defaultUrl="/static/mine/avatar-def.png" bgColor="#305BFF" />
+					<up-avatar :src="computeAvatarUrl" defaultUrl="/static/mine/avatar-def.png" bgColor="#305BFF" />
 				</template>
 			</u-cell>
 			<u-cell title="姓名" :isLink="false" :border="false">
@@ -27,29 +27,27 @@
 
 <script setup>
 	import {
-		uploadAvatarUrl
+		uploadAvatarUrl,
+		getUserInfoUrl
 	} from '@/common/config/api.js';
 	import {
 		onMounted,
 		ref,
-		getCurrentInstance
+		getCurrentInstance,
+		computed
 	} from 'vue';
-	import {
-		useStore
-	} from 'vuex';
 
 	const {
 		proxy
 	} = getCurrentInstance();
 
-
-
-	// 获取 Vuex store 实例
-	const store = useStore();
-	const user = ref({
-		nickName: ' '
+	const computeAvatarUrl = computed(() => {
+		// console.log('proxy.vuex_user.avatar', proxy.vuex_user.avatar);
+		// console.log('proxy.vuex_user.avatar', uni.$u.http.config.baseURL);
+		return uni.$u.http.config.baseURL + proxy.vuex_user.avatar
 	})
 
+
 	const changeAvatar = () => {
 		// console.log('更换头像');
 		uni.chooseMedia({
@@ -59,12 +57,12 @@
 			success: (e) => {
 				console.log(e.tempFiles[0].tempFilePath);
 				uploadAvatarUrl({
-						avatarfile: e.tempFiles[0].tempFilePath,
 						filePath: e.tempFiles[0].tempFilePath,
-						name: 'file'
+						name: 'avatarfile'
 					})
 					.then(res => {
-						console.log('您猜怎么着');
+						uni.$u.toast('修改成功');
+						getUserInfo();
 					})
 					.catch(err => {
 						console.log('上传Err', err);
@@ -73,6 +71,23 @@
 		})
 	}
 
+	const getUserInfo = () => {
+		getUserInfoUrl()
+			.then(res => {
+				console.log('用户信息', res);
+				let user = {
+					avatar: res.user.avatar,
+					nickName: res.user.nickName,
+					phonenumber: res.user.phonenumber,
+					roles: res.roles
+				}
+				proxy.$u.vuex('vuex_user', user);
+			})
+			.catch(err => {
+				console.log('err', err);
+			})
+	}
+
 	// 登出
 	const logout = () => {
 		uni.showModal({
@@ -80,8 +95,6 @@
 			content: '您确定要退出登录吗?',
 			success(res) {
 				if (res.confirm) {
-					// store.state.vuex_token = 'none';
-					// store.state.vuex_user = {};
 					proxy.$u.vuex('vuex_token', '');
 					proxy.$u.vuex('vuex_login', false);
 					uni.redirectTo({
@@ -91,11 +104,6 @@
 			}
 		})
 	}
-
-
-	onMounted(() => {
-		user.value = store.state.vuex_user;
-	})
 </script>
 <style>
 	page {

+ 16 - 4
pages/tabbar/mine/mine.vue

@@ -4,7 +4,7 @@
 		<view class="top-box">
 			<u-image class="bg-box" width="690rpx" height="270rpx" src="/static/mine/user-center-bg.png" />
 			<div class="avatar-name">
-				<up-avatar size="116rpx" :src="vuex_user.avatar" defaultUrl="/static/mine/avatar-def.png"
+				<up-avatar size="116rpx" :src="computeAvatarUrl" defaultUrl="/static/mine/avatar-def.png"
 					bgColor="#305BFF" />
 				<!-- <u-image class="avatar" width="116rpx" bgColor="transparent" height="116rpx"
 					src="/static/mine/avatar-def.png" /> -->
@@ -20,13 +20,13 @@
 		</view>
 		<u-cell-group :border="false" :customStyle="{background: '#fff', margin: '30rpx', borderRadius: '20rpx'}">
 			<!-- 县民政 -->
-			<u-cell icon="setting-fill" title="护理申请" isLink url="/pages/subpack/pages/application/list">
+			<u-cell v-if="vuex_user.roles.includes('village')" icon="setting-fill" title="护理申请" isLink url="/pages/subpack/pages/application/list">
 				<template #icon>
 					<u-image src="/static/mine/task.png" bgColor="transparent" width="36rpx" height="36rpx" />
 				</template>
 			</u-cell>
 			<!-- 区民政 -->
-			<u-cell icon="setting-fill" title="护理审核" isLink url="/pages/subpack/pages/application/list">
+			<u-cell v-if="vuex_user.roles.includes('area')" icon="setting-fill" title="护理审核" isLink url="/pages/subpack/pages/application/list">
 				<template #icon>
 					<u-image src="/static/mine/task.png" bgColor="transparent" width="36rpx" height="36rpx" />
 				</template>
@@ -60,7 +60,9 @@
 <script setup>
 	import {
 		onMounted,
-		ref
+		ref,
+		computed,
+		getCurrentInstance
 	} from 'vue';
 	import {
 		useStore
@@ -68,6 +70,10 @@
 	import {
 		onLoad
 	} from '@dcloudio/uni-app'
+
+	const {
+		proxy
+	} = getCurrentInstance();
 	// 获取 Vuex store 实例
 	const store = useStore();
 	const user = ref({
@@ -84,6 +90,12 @@
 		nurse: '护理员'
 	}
 
+	const computeAvatarUrl = computed(() => {
+		// console.log('proxy.vuex_user.avatar', proxy.vuex_user.avatar);
+		// console.log('proxy.vuex_user.avatar', uni.$u.http.config.baseURL);
+		return uni.$u.http.config.baseURL + proxy.vuex_user.avatar
+	})
+
 	function handleRolesText() {
 		let roles = user.value.roles;
 		let roleText = [];

+ 2 - 2
utils/request/index.js

@@ -10,8 +10,8 @@ import {
 //  初始化请求配置
 const initRequest = (vm) => {
 	http.setConfig((defaultConfig) => {
-		defaultConfig.baseURL = 'http://133.46.158.100' /* 根域名 */
-		// defaultConfig.baseURL = 'http://tkhtest.natapp1.cc' /* 根域名 */
+		// defaultConfig.baseURL = 'http://133.46.158.100' /* 根域名 */
+		defaultConfig.baseURL = 'http://tkhtest.natapp1.cc' /* 根域名 */
 		// defaultConfig.baseURL = 'http://127.0.0.1' /* 根域名 */
 		defaultConfig = {
 			...defaultConfig,

+ 2 - 2
utils/request/interceptors.js

@@ -12,7 +12,7 @@ const requestInterceptors = (vm) => {
 			// 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{}
 			config.data = config.data || {}
 			// console.log(store.state);
-			// console.log(config)
+			console.log('config', config)
 			// config.header.token = store.state.vuex_token
 			config.header.Authorization = 'Bearer ' + store.state.vuex_token
 			if (config?.custom?.loading) {
@@ -62,7 +62,7 @@ const responseInterceptors = (vm) => {
 				return new Promise(() => {})
 			}
 		}
-		if(!data.data && data.rows) data.data = data.rows;
+		if (!data.data && data.rows) data.data = data.rows;
 		return data.data || {}
 	}, (response) => {
 		/*  对响应错误做点什么 (statusCode !== 200)*/