|
@@ -3,8 +3,7 @@
|
|
|
<button
|
|
<button
|
|
|
class="avatar"
|
|
class="avatar"
|
|
|
open-type="chooseAvatar"
|
|
open-type="chooseAvatar"
|
|
|
- @chooseavatar="chooseAvatar"
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ @chooseavatar="chooseAvatar">
|
|
|
<image class="avatar_image" :src="avatar" @error="errorHandle"></image>
|
|
<image class="avatar_image" :src="avatar" @error="errorHandle"></image>
|
|
|
<view class="avatar_text flex-center">编辑</view>
|
|
<view class="avatar_text flex-center">编辑</view>
|
|
|
</button>
|
|
</button>
|
|
@@ -13,39 +12,30 @@
|
|
|
<view class="pl-50 pr-50">
|
|
<view class="pl-50 pr-50">
|
|
|
<view
|
|
<view
|
|
|
class="menu flex-align-center flex-between"
|
|
class="menu flex-align-center flex-between"
|
|
|
- v-for="(item, index) in state.menuList"
|
|
|
|
|
|
|
+ v-for="(item, index) in menu"
|
|
|
:key="index"
|
|
:key="index"
|
|
|
- @click="edit(index)"
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ @click="edit(index)">
|
|
|
<view class="fs-30">{{ item.title }}</view>
|
|
<view class="fs-30">{{ item.title }}</view>
|
|
|
<view class="flex">
|
|
<view class="flex">
|
|
|
<view
|
|
<view
|
|
|
:class="['fs-30', 'fw-500', `mr-${item.disabled ? '0' : '20'}`]"
|
|
:class="['fs-30', 'fw-500', `mr-${item.disabled ? '0' : '20'}`]"
|
|
|
- style="color: rgba(0, 0, 0, 0.8)"
|
|
|
|
|
- >{{ item.value }}
|
|
|
|
|
- </view
|
|
|
|
|
- >
|
|
|
|
|
- <uni-icons
|
|
|
|
|
- type="right"
|
|
|
|
|
- size="12"
|
|
|
|
|
- color="rgba(0,0,0,0.4)"
|
|
|
|
|
- v-if="!item.disabled"
|
|
|
|
|
- ></uni-icons>
|
|
|
|
|
|
|
+ style="color: rgba(0, 0, 0, 0.8)">{{ item.value }}
|
|
|
|
|
+ </view>
|
|
|
|
|
+ <uv-icon name="right-arrow" v-if="!item.disabled" size="12" color="rgba(0,0,0,0.4)"></uv-icon>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
|
|
|
- <style-bottom-view>
|
|
|
|
|
- <view class="pl-60 pr-60 pb-40">
|
|
|
|
|
- <style-button type="primary" @click="logoutUser">退出登录</style-button>
|
|
|
|
|
- </view>
|
|
|
|
|
- </style-bottom-view>
|
|
|
|
|
|
|
+ <view class="pl-60 pr-60 pb-40">
|
|
|
|
|
+ <uv-button :custom-style="customStyle" type="error" @click="logoutUser">退出登录</uv-button>
|
|
|
|
|
+ </view>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
-import {onHide, onShow} from "@dcloudio/uni-app";
|
|
|
|
|
-import {reactive, ref} from "vue";
|
|
|
|
|
-import {body, get, upload} from "@/utils/https"
|
|
|
|
|
|
|
+import {onLoad, onShow} from "@dcloudio/uni-app";
|
|
|
|
|
+import {ref} from "vue";
|
|
|
|
|
+import {body, get, upload} from "@/utils/https";
|
|
|
|
|
+import {clearToken} from "@/utils/auth"
|
|
|
|
|
|
|
|
const avatar = ref<string>();
|
|
const avatar = ref<string>();
|
|
|
const menu = ref<any[]>([]);
|
|
const menu = ref<any[]>([]);
|
|
@@ -77,92 +67,84 @@ const MENU_TEMPLATE = [
|
|
|
// },
|
|
// },
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-const initState = () => ({
|
|
|
|
|
- user: {},
|
|
|
|
|
- menuList: []
|
|
|
|
|
-})
|
|
|
|
|
-
|
|
|
|
|
-const state = reactive(initState())
|
|
|
|
|
|
|
+const customStyle = () => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ height: '80rpx',
|
|
|
|
|
+ borderRadius: '40rpx',
|
|
|
|
|
+ fontSize: '30rpx',
|
|
|
|
|
+ lineHeight: '80rpx',
|
|
|
|
|
+ background: '#FF6D00',
|
|
|
|
|
+ color: '#fff',
|
|
|
|
|
+ fontWeight: '500',
|
|
|
|
|
+ width: '60%',
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
const refresh = () => {
|
|
const refresh = () => {
|
|
|
const _menu = [...MENU_TEMPLATE];
|
|
const _menu = [...MENU_TEMPLATE];
|
|
|
- get(`user/profile`).then(res => {
|
|
|
|
|
- getApp<any>().globalData.user = res;
|
|
|
|
|
|
|
+ get(`user/profile`).then((res: any) => {
|
|
|
|
|
+ let {user, permission} = res;
|
|
|
|
|
+ getApp<any>().globalData.user = user;
|
|
|
|
|
+
|
|
|
|
|
+ if (user) {
|
|
|
|
|
+ _menu[0].value = user.nickname;
|
|
|
|
|
+ _menu[1].value = user.mobilePhone;
|
|
|
|
|
+ _menu[2].value = user.defaultPlateNo;
|
|
|
|
|
+ _menu[3].value = user.vin;
|
|
|
|
|
+ // _menu[4].value = user.card_no;
|
|
|
|
|
+ avatar.value =
|
|
|
|
|
+ user.avatar ||
|
|
|
|
|
+ "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0";
|
|
|
|
|
+ menu.value = _menu;
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
- // fetchProfile().then(() => {
|
|
|
|
|
- // const user = getApp<any>().globalData.user;
|
|
|
|
|
- // if (user) {
|
|
|
|
|
- // _menu[0].value = user.nickname;
|
|
|
|
|
- // _menu[1].value = user.mobilePhone;
|
|
|
|
|
- // _menu[2].value = user.defaultPlateNo;
|
|
|
|
|
- // _menu[3].value = user.vin;
|
|
|
|
|
- // // _menu[4].value = user.card_no;
|
|
|
|
|
- // avatar.value =
|
|
|
|
|
- // user.avatar ||
|
|
|
|
|
- // "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0";
|
|
|
|
|
- // menu.value = _menu;
|
|
|
|
|
- // }
|
|
|
|
|
- // });
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const save = (form: Record<string, any>) => {
|
|
const save = (form: Record<string, any>) => {
|
|
|
|
|
+ console.log(form)
|
|
|
uni.showLoading({
|
|
uni.showLoading({
|
|
|
title: "保存中",
|
|
title: "保存中",
|
|
|
});
|
|
});
|
|
|
- return body(`user/updateProfile`, form)
|
|
|
|
|
- .then((res) => {
|
|
|
|
|
- uni.hideLoading();
|
|
|
|
|
- uni.showToast({
|
|
|
|
|
- icon: "success",
|
|
|
|
|
- title: "保存成功",
|
|
|
|
|
- });
|
|
|
|
|
- refresh();
|
|
|
|
|
- return res;
|
|
|
|
|
- })
|
|
|
|
|
- .catch((err) => {
|
|
|
|
|
- uni.hideLoading();
|
|
|
|
|
- uni.showModal({
|
|
|
|
|
- content: `${err.errMsg},请重试`,
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ body(`user/updateProfile`, form).then(() => {
|
|
|
|
|
+ uni.hideLoading();
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ icon: "success",
|
|
|
|
|
+ title: "保存成功",
|
|
|
|
|
+ });
|
|
|
|
|
+ refresh();
|
|
|
|
|
+ }).catch((err: any) => {
|
|
|
|
|
+ uni.hideLoading();
|
|
|
|
|
+ })
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const chooseAvatar = (e: any) => {
|
|
const chooseAvatar = (e: any) => {
|
|
|
|
|
+ console.log(e)
|
|
|
if (e.detail.avatarUrl) {
|
|
if (e.detail.avatarUrl) {
|
|
|
uni.showLoading({
|
|
uni.showLoading({
|
|
|
title: "上传中",
|
|
title: "上传中",
|
|
|
});
|
|
});
|
|
|
- let params = {
|
|
|
|
|
- url: `file/upload`,
|
|
|
|
|
- filePath: e.detail.avatarUrl,
|
|
|
|
|
- success: (res) => {
|
|
|
|
|
- body(`user/updateAvatar`, {
|
|
|
|
|
- avatar: res.url,
|
|
|
|
|
- })
|
|
|
|
|
- .then(() => {
|
|
|
|
|
- uni.hideLoading();
|
|
|
|
|
- uni.showToast({
|
|
|
|
|
- title: "已更新",
|
|
|
|
|
- icon: "success",
|
|
|
|
|
- });
|
|
|
|
|
- avatar.value = res.url;
|
|
|
|
|
- })
|
|
|
|
|
- .catch((err) => {
|
|
|
|
|
- uni.hideLoading();
|
|
|
|
|
- uni.showModal({
|
|
|
|
|
- content: `${err.errMsg},请重试`,
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- upload(params)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ upload(`file/upload`, {filePath: e.detail.avatarUrl,name:'avatar.jpg'}).then((res: any) => {
|
|
|
|
|
+ body(`user/updateAvatar`, {avatar: res.url}).then(() => {
|
|
|
|
|
+ uni.hideLoading();
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ icon: "success",
|
|
|
|
|
+ title: "保存成功",
|
|
|
|
|
+ });
|
|
|
|
|
+ refresh();
|
|
|
|
|
+ }).catch((err: any) => {
|
|
|
|
|
+ console.error(err)
|
|
|
|
|
+ uni.hideLoading();
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
} else {
|
|
} else {
|
|
|
uni.showModal({
|
|
uni.showModal({
|
|
|
content: `${e.detail.errMsg},请重试`,
|
|
content: `${e.detail.errMsg},请重试`,
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
const edit = (index: number) => {
|
|
const edit = (index: number) => {
|
|
|
const menuItem = menu.value[index];
|
|
const menuItem = menu.value[index];
|
|
|
if (menuItem.disabled) {
|
|
if (menuItem.disabled) {
|
|
@@ -207,26 +189,22 @@ const logoutUser = () => {
|
|
|
uni.showLoading({
|
|
uni.showLoading({
|
|
|
title: "退出中",
|
|
title: "退出中",
|
|
|
});
|
|
});
|
|
|
- logout()
|
|
|
|
|
- .then(() => {
|
|
|
|
|
- uni.hideLoading();
|
|
|
|
|
- uni.showToast({
|
|
|
|
|
- icon: "success",
|
|
|
|
|
- title: "已退出",
|
|
|
|
|
- });
|
|
|
|
|
- clearToken();
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- uni.reLaunch({
|
|
|
|
|
- url: "/pages/map/map",
|
|
|
|
|
- });
|
|
|
|
|
- }, 1500);
|
|
|
|
|
- })
|
|
|
|
|
- .catch((err) => {
|
|
|
|
|
- uni.hideLoading();
|
|
|
|
|
- uni.showModal({
|
|
|
|
|
- content: `${err.errMsg},请重试`,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+
|
|
|
|
|
+ get(`user/logout`).then(() => {
|
|
|
|
|
+ uni.hideLoading();
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ icon: "success",
|
|
|
|
|
+ title: "已退出",
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ clearToken();
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ uni.reLaunch({
|
|
|
|
|
+ url: "/pages/map/map",
|
|
|
});
|
|
});
|
|
|
|
|
+ }, 1500);
|
|
|
|
|
+
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
@@ -236,20 +214,29 @@ const errorHandle = (e: any) => {
|
|
|
console.log(e);
|
|
console.log(e);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+onLoad(() => {
|
|
|
|
|
+ if (getApp<any>().globalData.user) {
|
|
|
|
|
+ const user = getApp<any>().globalData.user;
|
|
|
|
|
+ const _menu = [...MENU_TEMPLATE];
|
|
|
|
|
+ _menu[0].value = user.nickname;
|
|
|
|
|
+ _menu[1].value = user.mobilePhone;
|
|
|
|
|
+ _menu[2].value = user.defaultPlateNo;
|
|
|
|
|
+ _menu[3].value = user.vin;
|
|
|
|
|
+ // _menu[4].value = user.card_no;
|
|
|
|
|
+ avatar.value =
|
|
|
|
|
+ user.avatar ||
|
|
|
|
|
+ "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0";
|
|
|
|
|
+ menu.value = _menu;
|
|
|
|
|
+ }
|
|
|
|
|
+});
|
|
|
onShow(() => {
|
|
onShow(() => {
|
|
|
if (getApp<any>().globalData.lastData.profile) {
|
|
if (getApp<any>().globalData.lastData.profile) {
|
|
|
const {key, value} = getApp<any>().globalData.lastData.profile;
|
|
const {key, value} = getApp<any>().globalData.lastData.profile;
|
|
|
save({
|
|
save({
|
|
|
[key]: value,
|
|
[key]: value,
|
|
|
- }).then(() => {
|
|
|
|
|
- getApp<any>().globalData.lastData.profile = undefined;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
-onHide(() => {
|
|
|
|
|
- Object.assign(state, initState());
|
|
|
|
|
-})
|
|
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
<style lang="scss">
|