From 8560ff778e316a8a419bf408046cce150baafb15 Mon Sep 17 00:00:00 2001 From: ISFP_T <68358856@qq.com> Date: Wed, 8 Oct 2025 02:29:48 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=A2=9E=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=A1=B5=E9=9D=A2=E4=B8=8E=E7=9B=B8=E5=85=B3=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E7=A7=BB=E9=99=A4=E8=87=AA=E5=8A=A8=E7=99=BB?= =?UTF-8?q?=E5=BD=95=EF=BC=8C=E5=AF=B9=E6=8E=A5=E7=94=A8=E6=88=B7=E5=8F=8D?= =?UTF-8?q?=E9=A6=88=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 11 +-- config/http.js | 18 ++++- config/url.js | 4 +- config/user.js | 34 +++++++++ pages.json | 8 +++ pages/feedback/index.vue | 81 ++++++++++++++++----- pages/index/index.vue | 21 +++++- pages/login/index.vue | 150 +++++++++++++++++++++++++++++++++++++++ pages/my/index.vue | 17 ++++- pnpm-lock.yaml | 8 +++ 10 files changed, 317 insertions(+), 35 deletions(-) create mode 100644 pages/login/index.vue diff --git a/App.vue b/App.vue index 4f33a6a..bcff131 100644 --- a/App.vue +++ b/App.vue @@ -11,25 +11,20 @@ }, onShow: async function() { - // if (this.getUserInfoData()) { - - // } else { - // console.log('App Show') - await this.autoLogin() - // } + // 手动登录模式:不再自动登录 + // 如需保留可开关逻辑,可在此读取配置决定是否执行 autoLogin }, onHide: function() { console.log('App Hide') }, methods: { + // 保留方法但不调用 async autoLogin() { try { const loginResult = await wxLogin() // await getUserInfo() } catch (error) { console.error('自动登录失败:', error) - // 登录失败的处理可以在 wxLogin 中统一处理 - // 这里可以添加特殊的错误处理逻辑 } }, async getUserInfoData() { diff --git a/config/http.js b/config/http.js index 1b70aaa..02168af 100644 --- a/config/http.js +++ b/config/http.js @@ -19,7 +19,7 @@ const request = (option) => { method: option.method, data: option.data, header: { - "Content-Type": "application/x-www-form-urlencoded", + "Content-Type": option.headers && option.headers["Content-Type"] ? option.headers["Content-Type"] : (option.method && option.method.toUpperCase() === 'POST' ? 'application/json' : 'application/x-www-form-urlencoded'), ...option.headers, 'appid': appid, 'Authorization': "Bearer " + uni.getStorageSync('token'), @@ -42,6 +42,22 @@ const request = (option) => { return } + // 未登录或 token 失效处理(支持多种后端返回) + if (res.statusCode === 401 || res.data?.code === 401 || res.data?.code === 40101) { + try { + // 清理本地登录态 + uni.removeStorageSync('token') + // 计算重定向地址 + const pages = getCurrentPages() + const current = pages && pages.length ? pages[pages.length - 1] : null + const route = current && current.route ? ('/' + current.route) : '/pages/index/index' + const query = current && current.options ? Object.keys(current.options).map(k => `${k}=${encodeURIComponent(current.options[k])}`).join('&') : '' + const redirect = encodeURIComponent(query ? `${route}?${query}` : route) + // 跳转到登录页 + uni.reLaunch({ url: `/pages/login/index?redirect=${redirect}` }) + } catch (e) {} + } + // 检查业务状态码 if (res.data && res.data.code !== 200) { console.warn(`业务状态码错误: ${res.data.code}`, res.data) diff --git a/config/url.js b/config/url.js index 62a5ac5..e8c67f0 100644 --- a/config/url.js +++ b/config/url.js @@ -1,5 +1,5 @@ -export const URL = "https://my.gxfs123.com/api" //正式服务器 -// export const URL = "https://fansdev.gxfs123.com/api" //测试服务器 +// export const URL = "https://my.gxfs123.com/api" //正式服务器 +export const URL = "https://fansdev.gxfs123.com/api" //测试服务器 // export const URL = "http://192.168.5.22:8080" //本地调试 // export const URL = "http://127.0.0.1:8080" //本地调试 diff --git a/config/user.js b/config/user.js index e9e36bb..42a81ad 100644 --- a/config/user.js +++ b/config/user.js @@ -1,4 +1,5 @@ import request from './http' +import { URL, appid } from './url' export const login = (data) => { @@ -203,4 +204,37 @@ export const getPotionsDetail = (data) => { method: 'get', data }) +} + +// 文件上传到 OSS(若依后端) +export const uploadOssResource = (filePath) => { + return new Promise((resolve, reject) => { + uni.uploadFile({ + url: URL + '/resource/oss/upload', + filePath, + name: 'file', + header: { + 'appid': appid, + 'Authorization': 'Bearer ' + uni.getStorageSync('token'), + 'Clientid': uni.getStorageSync('client_id') + }, + success: (res) => { + try { + const parsed = typeof res.data === 'string' ? JSON.parse(res.data) : res.data + const codeOk = (res.statusCode === 200 || res.statusCode === 201 || parsed?.code === 200) + const url = parsed?.url || parsed?.data?.url || parsed?.data?.fileUrl || parsed?.fileUrl || parsed?.path || parsed?.data + if (codeOk && url) { + resolve(url) + return + } + reject(parsed || res) + } catch (e) { + reject(e) + } + }, + fail: (err) => { + reject(err) + } + }) + }) } \ No newline at end of file diff --git a/pages.json b/pages.json index 1a23f98..92c4194 100644 --- a/pages.json +++ b/pages.json @@ -12,6 +12,14 @@ "navigationBarTitleText": "附近场地" } }, + { + "path": "pages/login/index", + "style": { + "navigationBarTitleText": "登录", + "navigationBarBackgroundColor": "#ffffff", + "navigationBarTextStyle": "black" + } + }, { "path": "pages/my/index", "style": { diff --git a/pages/feedback/index.vue b/pages/feedback/index.vue index 351390b..8dbe01a 100644 --- a/pages/feedback/index.vue +++ b/pages/feedback/index.vue @@ -1,6 +1,6 @@ @@ -55,10 +55,11 @@ ref } from 'vue' import { - URL + URL, + appid } from '../../config/url' import { - addUserFeedback + uploadOssResource } from '../../config/user' // 响应式数据 @@ -78,8 +79,25 @@ const chooseImage = () => { uni.chooseImage({ count: 3 - images.value.length, - success: (res) => { - images.value = [...images.value, ...res.tempFilePaths] + success: async (res) => { + const toUpload = res.tempFilePaths || [] + for (const localPath of toUpload) { + // 先追加本地预览,再上传并替换为远程URL + images.value.push(localPath) + try { + const remoteUrl = await uploadOssResource(localPath) + const idx = images.value.indexOf(localPath) + if (idx !== -1) { + images.value.splice(idx, 1, remoteUrl) + } + } catch (e) { + const idx = images.value.indexOf(localPath) + if (idx !== -1) { + images.value.splice(idx, 1) + } + uni.showToast({ title: '图片上传失败', icon: 'none' }) + } + } } }) } @@ -126,18 +144,43 @@ phone: contact.value, // images: images.value } - const res = await addUserFeedback(feedbackData); - if (res.code == 200) { - uni.showToast({ - title: '反馈成功', - icon: 'success' - }) - } else { - uni.showToast({ - title: '反馈失败', - icon: 'none' - }) - } + + uni.request({ + url: `${apiUrl}/app/feedback/add`, + method: 'POST', + data: feedbackData, + header: { + 'Content-Type': 'application/json', + 'appid': appid, + 'Authorization': 'Bearer ' + uni.getStorageSync('token'), + 'Clientid': uni.getStorageSync('client_id') + }, + dataType: 'json', + success: (res) => { + // 兼容后端返回 { code: 200 } 或 HTTP 200 情况 + if ((res.statusCode === 200) && ((res.data && res.data.code === 200) || res.data === true || res.data?.success === true)) { + uni.showToast({ + title: '反馈成功', + icon: 'success' + }) + setTimeout(() => { + uni.navigateBack(); + }, 1500); + return + } + uni.showToast({ + title: (res.data && (res.data.msg || res.data.message)) || '反馈失败', + icon: 'none' + }) + }, + fail: (err) => { + console.error('feedback request failed:', err) + uni.showToast({ + title: '网络错误,请稍后重试', + icon: 'none' + }) + } + }) } diff --git a/pages/index/index.vue b/pages/index/index.vue index c47aaf7..c83a25d 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -128,6 +128,18 @@ + + + diff --git a/pages/my/index.vue b/pages/my/index.vue index 844d978..ec2d59d 100644 --- a/pages/my/index.vue +++ b/pages/my/index.vue @@ -149,8 +149,8 @@ try { const token = uni.getStorageSync('token'); if (!token) { - await wxLogin(); - return; + redirectToLogin() + return } const res = await getUserInfo(); @@ -183,6 +183,19 @@ } }; + const redirectToLogin = () => { + try { + const pages = getCurrentPages() + const current = pages && pages.length ? pages[pages.length - 1] : null + const route = current && current.route ? ('/' + current.route) : '/pages/index/index' + const query = current && current.options ? Object.keys(current.options).map(k => `${k}=${encodeURIComponent(current.options[k])}`).join('&') : '' + const redirect = encodeURIComponent(query ? `${route}?${query}` : route) + uni.reLaunch({ url: `/pages/login/index?redirect=${redirect}` }) + } catch (e) { + uni.reLaunch({ url: '/pages/login/index' }) + } + } + // 导航到指定页面 const navigateTo = (url) => { uni.navigateTo({ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ca3847..48419b4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@climblee/uv-ui': + specifier: ^1.1.20 + version: 1.1.20 axios: specifier: ^1.7.9 version: 1.10.0 @@ -30,6 +33,9 @@ importers: packages: + '@climblee/uv-ui@1.1.20': + resolution: {integrity: sha512-jkyesHJsPJkF4Nap9ZmG1/ibKlxXA5M8+ntqKXwwloIsYSYL5SOKb0gyPj17aBOU1PkJpmeiZ8PwnTolhK2/HA==} + '@jridgewell/gen-mapping@0.3.8': resolution: {integrity: sha512-imAbBGkb+ebQyxKgzv5Hu2nmROxoDOXHh80evxdoXNOrvAnVx7zimzc1Oo5h9RlfV4vPXaE2iM5pOFbvOCClWA==} engines: {node: '>=6.0.0'} @@ -604,6 +610,8 @@ packages: snapshots: + '@climblee/uv-ui@1.1.20': {} + '@jridgewell/gen-mapping@0.3.8': dependencies: '@jridgewell/set-array': 1.2.1