From 247f238377c8d9ea5077c84ee13143be24229e51 Mon Sep 17 00:00:00 2001 From: zzc <1761997216@qq.com> Date: Mon, 9 Feb 2026 20:13:20 +0800 Subject: [PATCH] fix: make content api --- pages/avatar/index.vue | 45 ++++++++++++++++++++++++++++++------------ utils/request.js | 4 ++-- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/pages/avatar/index.vue b/pages/avatar/index.vue index fbc9c92..7dcc573 100644 --- a/pages/avatar/index.vue +++ b/pages/avatar/index.vue @@ -71,15 +71,11 @@ 选择头像 - - + 上传头像 + { // Logic after successful login if needed }; -const onChooseAvatar = async (e) => { - const avatarUrl = e.detail.avatarUrl; - if (!avatarUrl) return; +const onChooseAlbum = () => { + uni.chooseImage({ + count: 1, + sizeType: ["original", "compressed"], + sourceType: ["album"], + success: (res) => { + const path = res.tempFilePaths[0]; + // 调用系统裁剪,强制 1:1 + uni.cropImage({ + src: path, + aspectRatio: "1:1", + success: (cropRes) => { + onAvatarSelect(cropRes.tempFilePath); + }, + fail: (err) => { + console.warn("Crop failed or cancelled", err); + onAvatarSelect(path); + }, + }); + }, + }); +}; + +const onAvatarSelect = async (url) => { + if (!url) return; uni.showLoading({ title: "上传中...", mask: true }); try { - const imageUrl = await uploadImage(avatarUrl); + const imageUrl = await uploadImage(url); currentAvatar.value = { - id: "wechat_" + Date.now(), + id: "custom_" + Date.now(), imageUrl: imageUrl, }; uni.hideLoading(); diff --git a/utils/request.js b/utils/request.js index 113e60b..022bc02 100644 --- a/utils/request.js +++ b/utils/request.js @@ -1,6 +1,6 @@ -const BASE_URL = "https://api.ai-meng.com"; +// const BASE_URL = "https://api.ai-meng.com"; // const BASE_URL = 'http://127.0.0.1:3999' -// const BASE_URL = "http://192.168.1.3:3999"; +const BASE_URL = "http://192.168.1.3:3999"; // const BASE_URL = "http://192.168.31.253:3999"; import { useUserStore } from "@/stores/user";