add
This commit is contained in:
parent
a21cb33ef7
commit
1e617e1b39
6
config.js
Normal file
6
config.js
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
// 后端接口
|
||||
export const BASE_API_URL = "https://online.totustec.com/api";
|
||||
|
||||
// 静态数据
|
||||
export const BASE_IMG_URL = "https://online.totustec.com/upload";
|
@ -119,7 +119,6 @@ export default {
|
||||
// ---------------------- WebSocket 核心方法 ----------------------
|
||||
connectWebSocket () {
|
||||
const wsUrl = 'ws://e7eb22d8.natappfree.cc/webSocket/vue';
|
||||
|
||||
// 初始化 WebSocket 连接(使用 uni-app 接口)
|
||||
this.socketTask = uni.connectSocket({
|
||||
url: wsUrl,
|
||||
|
@ -122,8 +122,7 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
navigateToAccountSettings(path) {
|
||||
|
||||
navigateToAccountSettings(path) {
|
||||
uni.navigateTo({
|
||||
url: path,
|
||||
});
|
||||
@ -147,7 +146,6 @@ export default {
|
||||
"Content-Type": "application/x-www-form-urlencoded", // 关键配置
|
||||
},
|
||||
});
|
||||
|
||||
if (res.statusCode == 200) {
|
||||
this.userInfo = res.data;
|
||||
console.log('this.userInfo', this.userInfo);
|
||||
|
@ -5,7 +5,7 @@
|
||||
<view class="top_status_area" :style="{ height: statusBarHeight + 'px' }"></view>
|
||||
<view class="top_nav_warp">
|
||||
<view class="back_icon" @click="goBack">
|
||||
<image src="https://online.totustec.com/upload/minePage/back.png" mode="aspectFit"></image>
|
||||
<image :src="back" mode="aspectFit"></image>
|
||||
</view>
|
||||
<text>个人资料</text>
|
||||
</view>
|
||||
@ -18,7 +18,7 @@
|
||||
<text class="item_label">头像</text>
|
||||
<view class="avatar_wrapper" @click="changeAvatar">
|
||||
<image class="avatar"
|
||||
:src="userInfo.avatar || 'https://online.totustec.com/upload/minePage/user.png'"
|
||||
:src="userInfo.avatar || user"
|
||||
mode="aspectFill"></image>
|
||||
</view>
|
||||
</view>
|
||||
@ -26,21 +26,27 @@
|
||||
<!-- Nickname Section -->
|
||||
<view class="profile_item">
|
||||
<text class="item_label">昵称</text>
|
||||
<input class="nickname_input" v-model="userInfo.nickname" placeholder="请输入昵称" />
|
||||
<input class="nickname_input" v-model="userInfo.nikename" placeholder="请输入昵称" />
|
||||
</view>
|
||||
<!-- Save Button -->
|
||||
<button class="save_btn" @click="saveProfile">保存修改</button>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { BASE_API_URL,BASE_IMG_URL } from "@/config.js";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
back:BASE_IMG_URL + "/minePage/back.png", //返回图标
|
||||
user:BASE_IMG_URL + "/minePage/user.png", //用户默认图标
|
||||
statusBarHeight: 0,
|
||||
userInfo: {
|
||||
nickname: ""
|
||||
nikename: "",
|
||||
avatar:"",
|
||||
phone:""
|
||||
}
|
||||
};
|
||||
},
|
||||
@ -51,29 +57,54 @@
|
||||
this.getUserInfoFromCache();
|
||||
},
|
||||
methods: {
|
||||
navigateToAccountSettings(path) {
|
||||
uni.navigateTo({
|
||||
url: path,
|
||||
});
|
||||
},
|
||||
getUserInfoFromCache() {
|
||||
const userInfo = uni.getStorageSync("userInfo");
|
||||
if (userInfo) {
|
||||
this.userInfo.nickname = userInfo.nikeName;
|
||||
this.userInfo.avatar = "https://online.totustec.com/upload" + userInfo.avatar;
|
||||
|
||||
this.userInfo.nikename = userInfo.nikeName;
|
||||
this.userInfo.avatar = BASE_IMG_URL + userInfo.avatar;
|
||||
}
|
||||
},
|
||||
|
||||
changeAvatar() {
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
sizeType: ['compressed'],
|
||||
sourceType: ['album', 'camera'],
|
||||
success: (res) => {
|
||||
const tempFilePaths = res.tempFilePaths;
|
||||
this.userInfo.avatar = tempFilePaths[0];
|
||||
// Here you would typically upload the image to your server
|
||||
const tempFilePath = res.tempFilePaths[0];
|
||||
const userInfo = uni.getStorageSync("userInfo") || {};
|
||||
uni.uploadFile({
|
||||
url: "https://online.totustec.com/api/api/front/user/pictures",
|
||||
filePath: tempFilePath,
|
||||
name: "file",
|
||||
header: {
|
||||
"Authorization": userInfo.token || ""
|
||||
},
|
||||
success: (uploadRes) => {
|
||||
console.log(uploadRes)
|
||||
this.userInfo.avatar=
|
||||
"https://online.totustec.com/upload/file/image/" + uploadRes.data;
|
||||
uni.showToast({
|
||||
title: "头像上传成功"
|
||||
});
|
||||
console.log(this.userInfo.avatar)
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({
|
||||
title: "头像上传失败",
|
||||
icon: "none"
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
async saveProfile() {
|
||||
if (!this.userInfo.nickname.trim()) {
|
||||
if (!this.userInfo.nikename.trim()) {
|
||||
uni.showToast({
|
||||
title: '昵称不能为空',
|
||||
icon: 'none'
|
||||
@ -81,8 +112,9 @@
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const userInfo = uni.getStorageSync("userInfo") || {};
|
||||
const res = await uni.request({
|
||||
url: "https://online.totustec.com/api/api/front/user/update",
|
||||
url: BASE_API_URL + "/api/front/user/update",
|
||||
method: "POST",
|
||||
data: this.userInfo,
|
||||
header: {
|
||||
@ -90,28 +122,23 @@
|
||||
"Authorization": userInfo.token || ""
|
||||
},
|
||||
});
|
||||
console.log(res)
|
||||
if (res.statusCode == 200) {
|
||||
uni.showToast({
|
||||
title: "修改成功"
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: "/pages/mine/index",
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
uni.showToast({
|
||||
title: "修改失败",
|
||||
icon: "none"
|
||||
});
|
||||
}
|
||||
// Here you would typically send the updated info to your server
|
||||
// uni.showToast({
|
||||
// title: '保存成功',
|
||||
// icon: 'success'
|
||||
// });
|
||||
// Simulate API call
|
||||
|
||||
setTimeout(() => {
|
||||
uni.navigateBack();
|
||||
}, 1500);
|
||||
},
|
||||
goBack() {
|
||||
uni.navigateBack();
|
||||
|
Loading…
Reference in New Issue
Block a user