|
@@ -4,7 +4,7 @@
|
|
<u-cell-group :border="false" :customStyle="{background: '#fff', margin: '30rpx', borderRadius: '20rpx'}">
|
|
<u-cell-group :border="false" :customStyle="{background: '#fff', margin: '30rpx', borderRadius: '20rpx'}">
|
|
<u-cell title="头像" isLink @click="changeAvatar">
|
|
<u-cell title="头像" isLink @click="changeAvatar">
|
|
<template #value>
|
|
<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>
|
|
</template>
|
|
</u-cell>
|
|
</u-cell>
|
|
<u-cell title="姓名" :isLink="false" :border="false">
|
|
<u-cell title="姓名" :isLink="false" :border="false">
|
|
@@ -27,29 +27,27 @@
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
import {
|
|
import {
|
|
- uploadAvatarUrl
|
|
|
|
|
|
+ uploadAvatarUrl,
|
|
|
|
+ getUserInfoUrl
|
|
} from '@/common/config/api.js';
|
|
} from '@/common/config/api.js';
|
|
import {
|
|
import {
|
|
onMounted,
|
|
onMounted,
|
|
ref,
|
|
ref,
|
|
- getCurrentInstance
|
|
|
|
|
|
+ getCurrentInstance,
|
|
|
|
+ computed
|
|
} from 'vue';
|
|
} from 'vue';
|
|
- import {
|
|
|
|
- useStore
|
|
|
|
- } from 'vuex';
|
|
|
|
|
|
|
|
const {
|
|
const {
|
|
proxy
|
|
proxy
|
|
} = getCurrentInstance();
|
|
} = 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 = () => {
|
|
const changeAvatar = () => {
|
|
// console.log('更换头像');
|
|
// console.log('更换头像');
|
|
uni.chooseMedia({
|
|
uni.chooseMedia({
|
|
@@ -59,12 +57,12 @@
|
|
success: (e) => {
|
|
success: (e) => {
|
|
console.log(e.tempFiles[0].tempFilePath);
|
|
console.log(e.tempFiles[0].tempFilePath);
|
|
uploadAvatarUrl({
|
|
uploadAvatarUrl({
|
|
- avatarfile: e.tempFiles[0].tempFilePath,
|
|
|
|
filePath: e.tempFiles[0].tempFilePath,
|
|
filePath: e.tempFiles[0].tempFilePath,
|
|
- name: 'file'
|
|
|
|
|
|
+ name: 'avatarfile'
|
|
})
|
|
})
|
|
.then(res => {
|
|
.then(res => {
|
|
- console.log('您猜怎么着');
|
|
|
|
|
|
+ uni.$u.toast('修改成功');
|
|
|
|
+ getUserInfo();
|
|
})
|
|
})
|
|
.catch(err => {
|
|
.catch(err => {
|
|
console.log('上传Err', 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 = () => {
|
|
const logout = () => {
|
|
uni.showModal({
|
|
uni.showModal({
|
|
@@ -80,8 +95,6 @@
|
|
content: '您确定要退出登录吗?',
|
|
content: '您确定要退出登录吗?',
|
|
success(res) {
|
|
success(res) {
|
|
if (res.confirm) {
|
|
if (res.confirm) {
|
|
- // store.state.vuex_token = 'none';
|
|
|
|
- // store.state.vuex_user = {};
|
|
|
|
proxy.$u.vuex('vuex_token', '');
|
|
proxy.$u.vuex('vuex_token', '');
|
|
proxy.$u.vuex('vuex_login', false);
|
|
proxy.$u.vuex('vuex_login', false);
|
|
uni.redirectTo({
|
|
uni.redirectTo({
|
|
@@ -91,11 +104,6 @@
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- onMounted(() => {
|
|
|
|
- user.value = store.state.vuex_user;
|
|
|
|
- })
|
|
|
|
</script>
|
|
</script>
|
|
<style>
|
|
<style>
|
|
page {
|
|
page {
|