From 8337c34fcc761d07acaad796d10f3e12e9bbe2d1 Mon Sep 17 00:00:00 2001
From: lrj <owen.stl@gmail.com>
Date: 星期日, 05 十月 2025 08:56:04 +0800
Subject: [PATCH] feat: 微信项目详情支持阶段评分时间轴
---
wx/app.js | 98 +++++++++++++++++++++++++------------------------
1 files changed, 50 insertions(+), 48 deletions(-)
diff --git a/wx/app.js b/wx/app.js
index 6b689f7..41ba5ea 100644
--- a/wx/app.js
+++ b/wx/app.js
@@ -4,7 +4,7 @@
userInfo: null,
token: null,
sessionKey: null, // 寰俊浼氳瘽瀵嗛挜锛岀敤浜庤В瀵嗘墜鏈哄彿绛夋晱鎰熸暟鎹�
- baseUrl: 'http://localhost:8080/api/graphql', // 鍚庡彴GraphQL鎺ュ彛鍦板潃
+ baseUrl: 'http://localhost:8080/graphql', // 鍚庡彴GraphQL鎺ュ彛鍦板潃
hasPhoneAuth: false, // 鏄惁宸叉巿鏉冩墜鏈哄彿
rejectPhone: false, // 鏄惁鎷掔粷杩囨墜鏈哄彿鎺堟潈
cos: {
@@ -134,50 +134,18 @@
}
console.log('=== 鍑嗗璋冪敤鍚庣wxLogin鎺ュ彛 ===')
- console.log('璇锋眰URL:', this.globalData.baseUrl)
+ console.log('璇锋眰URL:', 'http://localhost:8080/api/auth/wx-login')
console.log('璁惧淇℃伅:', deviceInfo)
console.log('璇锋眰鍙傛暟:', requestData)
console.log('璇锋眰寮�濮嬫椂闂�:', new Date().toISOString())
wx.request({
- url: this.globalData.baseUrl,
+ url: 'http://localhost:8080/api/auth/wx-login',
method: 'POST',
header: {
'Content-Type': 'application/json'
},
- data: {
- query: `
- mutation wxLogin($input: WxLoginRequest!) {
- wxLogin(input: $input) {
- token
- userInfo {
- userId
- name
- phone
- userType
- employee {
- id
- name
- }
- judge {
- id
- name
- }
- player {
- id
- name
- }
- }
- isNewUser
- loginRecordId
- sessionKey
- }
- }
- `,
- variables: {
- input: requestData
- }
- },
+ data: requestData,
success: (res) => {
console.log('=== 鍚庣wxLogin鎺ュ彛鍝嶅簲 ===')
console.log('鍝嶅簲鏃堕棿:', new Date().toISOString())
@@ -194,17 +162,28 @@
return
}
- if (res.data.errors) {
- console.error('鉂� GraphQL閿欒:', res.data.errors)
+ // 妫�鏌ユ槸鍚︽湁閿欒淇℃伅锛堥�傞厤涓嶅悓鐨勯敊璇搷搴旀牸寮忥級
+ if (res.data.error || res.data.message || res.data.success === false) {
+ const errorMsg = res.data.error || res.data.message || '鐧诲綍澶辫触'
+ console.error('鉂� 鐧诲綍澶辫触:', errorMsg)
wx.showToast({
- title: '鐧诲綍澶辫触',
+ title: errorMsg,
icon: 'error'
})
return
}
- if (res.data.data && res.data.data.wxLogin) {
- const loginResult = res.data.data.wxLogin
+ // 妫�鏌ュ搷搴旀暟鎹牸寮忥細鏀寔鐩存帴杩斿洖WxLoginResponse鎴栧寘瑁呮牸寮�
+ let loginResult = null
+ if (res.data.token && res.data.userInfo) {
+ // 鐩存帴杩斿洖WxLoginResponse鏍煎紡
+ loginResult = res.data
+ } else if (res.data.success && res.data.data) {
+ // 鍖呰鏍煎紡 {success: true, data: WxLoginResponse}
+ loginResult = res.data.data
+ }
+
+ if (loginResult) {
console.log('鉁� 鐧诲綍鎴愬姛!')
console.log('鐢ㄦ埛ID:', loginResult.userInfo.userId)
@@ -239,10 +218,10 @@
console.log('鈩癸笍 鑰佺敤鎴锋垨宸叉嫆缁濇墜鏈哄彿鎺堟潈锛岃烦杩囨巿鏉冨脊绐�')
}
} else {
- console.error('鉂� 鍝嶅簲鏁版嵁鏍煎紡閿欒锛岀己灏憌xLogin瀛楁')
+ console.error('鉂� 鍝嶅簲鏁版嵁鏍煎紡閿欒锛岀己灏戝繀瑕佸瓧娈�(token鎴杣serInfo)')
console.error('瀹為檯鍝嶅簲:', res.data)
wx.showToast({
- title: '鐧诲綍澶辫触',
+ title: '鐧诲綍鏁版嵁鏍煎紡閿欒',
icon: 'error'
})
}
@@ -297,12 +276,21 @@
// GraphQL璇锋眰灏佽
graphqlRequest(query, variables = {}) {
return new Promise((resolve, reject) => {
+ // 纭繚token鐨勪竴鑷存�э細浼樺厛浣跨敤globalData涓殑token锛屽鏋滄病鏈夊垯浠巗torage鑾峰彇
+ let token = this.globalData.token
+ if (!token) {
+ token = wx.getStorageSync('token')
+ if (token) {
+ this.globalData.token = token // 鍚屾鍒癵lobalData
+ }
+ }
+
wx.request({
url: this.globalData.baseUrl,
method: 'POST',
header: {
'Content-Type': 'application/json',
- 'Authorization': this.globalData.token ? `Bearer ${this.globalData.token}` : ''
+ 'Authorization': token ? `Bearer ${token}` : ''
},
data: {
query: query,
@@ -310,18 +298,32 @@
},
success: (res) => {
console.log('GraphQL鍝嶅簲:', res.data)
+
+ // 妫�鏌TTP鐘舵�佺爜
+ if (res.statusCode !== 200) {
+ console.error('GraphQL HTTP閿欒:', res.statusCode)
+ reject(new Error(`HTTP閿欒: ${res.statusCode}`))
+ return
+ }
+
+ // 妫�鏌raphQL閿欒
if (res.data.errors) {
console.error('GraphQL閿欒:', res.data.errors)
- reject(res.data.errors)
- } else if (res.data.data) {
+ reject(new Error(res.data.errors[0]?.message || 'GraphQL璇锋眰閿欒'))
+ return
+ }
+
+ // 妫�鏌ユ暟鎹�
+ if (res.data.data !== undefined) {
resolve(res.data.data)
} else {
console.error('GraphQL鍝嶅簲寮傚父:', res.data)
- reject('璇锋眰澶辫触')
+ reject(new Error('GraphQL鍝嶅簲鏁版嵁寮傚父'))
}
},
fail: (err) => {
- reject(err)
+ console.error('GraphQL缃戠粶璇锋眰澶辫触:', err)
+ reject(new Error('缃戠粶璇锋眰澶辫触'))
}
})
})
--
Gitblit v1.8.0