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