From f04f35b562760afbac0c477357e2a29f77aec3b9 Mon Sep 17 00:00:00 2001 From: lrj <owen.stl@gmail.com> Date: 星期四, 02 十月 2025 13:51:47 +0800 Subject: [PATCH] fix: 修复评审次数重复显示问题 --- wx/pages/registration/registration.js | 303 ++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 265 insertions(+), 38 deletions(-) diff --git a/wx/pages/registration/registration.js b/wx/pages/registration/registration.js index 6de900a..0c62a99 100644 --- a/wx/pages/registration/registration.js +++ b/wx/pages/registration/registration.js @@ -9,6 +9,7 @@ activityId: '', activity: null, loading: false, + userInfo: null, // 褰撳墠鐢ㄦ埛淇℃伅 // 琛ㄥ崟鏁版嵁 formData: { @@ -101,6 +102,9 @@ } else { console.log('鉂� 娌℃湁鎺ユ敹鍒癮ctivityId鍙傛暟') } + + // 鍔犺浇鐢ㄦ埛淇℃伅 + this.loadUserInfo() // 浠庡叏灞�鏁版嵁鑾峰彇鐢ㄦ埛淇℃伅棰勫~鍏� this.prefillUserInfo() @@ -210,15 +214,80 @@ } }, + // 鍔犺浇鐢ㄦ埛淇℃伅 + loadUserInfo() { + const userInfo = app.globalData.userInfo + console.log('馃攳 鍔犺浇鐢ㄦ埛淇℃伅鐢ㄤ簬鏄剧ず:', userInfo) + + if (userInfo) { + let displayUserInfo = { + name: userInfo.name || '', + phone: userInfo.phone || '', + avatarUrl: userInfo.avatarUrl || '', + gender: null, + education: '' + } + + // 濡傛灉鐢ㄦ埛鏈塒layer淇℃伅锛屼紭鍏堜娇鐢≒layer鐨勮缁嗕俊鎭� + if (userInfo.player) { + console.log('馃搵 浣跨敤Player淇℃伅鏄剧ず:', userInfo.player) + displayUserInfo.name = userInfo.player.name || userInfo.name || '' + displayUserInfo.phone = userInfo.player.phone || userInfo.phone || '' + displayUserInfo.avatarUrl = userInfo.player.avatarUrl || userInfo.avatarUrl || '' + + // 澶勭悊鎬у埆淇℃伅锛�0=鐢凤紝1=濂� + if (userInfo.player.gender !== undefined && userInfo.player.gender !== null) { + displayUserInfo.gender = parseInt(userInfo.player.gender) + } + + // 澶勭悊瀛﹀巻淇℃伅 + if (userInfo.player.education) { + displayUserInfo.education = userInfo.player.education + } + } + + console.log('鉁� 璁剧疆鏄剧ず鐢ㄦ埛淇℃伅:', displayUserInfo) + this.setData({ + userInfo: displayUserInfo + }) + } else { + console.log('鈿狅笍 鏈壘鍒扮敤鎴蜂俊鎭�') + } + }, + // 棰勫~鍏呯敤鎴蜂俊鎭� prefillUserInfo() { const userInfo = app.globalData.userInfo + console.log('馃攳 棰勫~鍏呯敤鎴蜂俊鎭�:', userInfo) + if (userInfo) { - this.setData({ + const updateData = { 'formData.name': userInfo.name || '', 'formData.phone': userInfo.phone || '', 'formData.email': userInfo.email || '' - }) + } + + // 濡傛灉鐢ㄦ埛鏈塒layer淇℃伅锛屼紭鍏堜娇鐢≒layer鐨勮缁嗕俊鎭� + if (userInfo.player) { + console.log('馃搵 浣跨敤Player淇℃伅棰勫~鍏�:', userInfo.player) + updateData['formData.name'] = userInfo.player.name || userInfo.name || '' + updateData['formData.phone'] = userInfo.player.phone || userInfo.phone || '' + + // 澶勭悊鎬у埆淇℃伅锛�0=鐢凤紝1=濂� + if (userInfo.player.gender !== undefined && userInfo.player.gender !== null) { + const genderIndex = parseInt(userInfo.player.gender) + if (genderIndex === 0 || genderIndex === 1) { + updateData['formData.gender'] = genderIndex + updateData['genderIndex'] = genderIndex + console.log('馃懁 璁剧疆鎬у埆:', genderIndex === 0 ? '鐢�' : '濂�') + } + } + } + + console.log('鉁� 棰勫~鍏呮暟鎹�:', updateData) + this.setData(updateData) + } else { + console.log('鈿狅笍 鏈壘鍒扮敤鎴蜂俊鎭紝鏃犳硶棰勫~鍏�') } }, @@ -649,18 +718,21 @@ this.setData({ attachments: updatedAttachments }) try { - const uploadResult = await cosUtil.uploadFile(attachment.path, { - onProgress: (progress) => { + const uploadResult = await cosUtil.uploadFile( + attachment.path, + 'attachment', + attachment.name || 'attachment', + (percent) => { // 鏇存柊涓婁紶杩涘害 const progressAttachments = this.data.attachments.map(item => { if (item.id === attachment.id) { - return { ...item, progress: Math.round(progress.percent) } + return { ...item, progress: Math.round(percent) } } return item }) this.setData({ attachments: progressAttachments }) } - }) + ) // 涓婁紶鎴愬姛 const successAttachments = this.data.attachments.map(item => { @@ -749,6 +821,141 @@ wx.hideLoading() wx.showToast({ title: '鍒犻櫎澶辫触', + icon: 'error' + }) + } + }, + + // 棰勮闄勪欢 + async onPreviewAttachment(e) { + try { + const index = e.currentTarget.dataset.index + const attachment = this.data.attachments[index] + + if (!attachment.uploaded || !attachment.url) { + wx.showToast({ + title: '鏂囦欢鏈笂浼犲畬鎴�', + icon: 'none' + }) + return + } + + const fileType = attachment.type + + if (fileType === 'image') { + // 棰勮鍥剧墖 (media_type = 1) + wx.previewImage({ + current: attachment.url, + urls: [attachment.url] + }) + } else if (fileType === 'video') { + // 鎾斁瑙嗛 (media_type = 2) - 璺宠浆鍒拌棰戞挱鏀鹃〉闈� + wx.navigateTo({ + url: `/pages/video/video?url=${encodeURIComponent(attachment.url)}&title=${encodeURIComponent(attachment.name)}` + }) + } else if (fileType === 'pdf') { + // PDF鏂囦欢 (media_type = 4) - 浣跨敤灏忕▼搴忓唴缃殑鏂囨。棰勮 + wx.showLoading({ + title: '姝e湪鎵撳紑...', + mask: true + }) + + wx.downloadFile({ + url: attachment.url, + success: (res) => { + wx.hideLoading() + if (res.statusCode === 200) { + wx.openDocument({ + filePath: res.tempFilePath, + fileType: 'pdf', + success: () => { + console.log('PDF鎵撳紑鎴愬姛') + }, + fail: (err) => { + console.error('PDF鎵撳紑澶辫触:', err) + wx.showToast({ + title: 'PDF鎵撳紑澶辫触', + icon: 'none' + }) + } + }) + } else { + wx.showToast({ + title: '鏂囦欢涓嬭浇澶辫触', + icon: 'none' + }) + } + }, + fail: (err) => { + wx.hideLoading() + console.error('PDF涓嬭浇澶辫触:', err) + wx.showToast({ + title: '鏂囦欢涓嬭浇澶辫触', + icon: 'none' + }) + } + }) + } else if (fileType === 'word' || fileType === 'excel' || fileType === 'ppt') { + // Office鏂囨。 (media_type = 4) - 浣跨敤灏忕▼搴忓唴缃殑鏂囨。棰勮 + wx.showLoading({ + title: '姝e湪鎵撳紑...', + mask: true + }) + + wx.downloadFile({ + url: attachment.url, + success: (res) => { + wx.hideLoading() + if (res.statusCode === 200) { + const fileTypeMap = { + 'word': 'doc', + 'excel': 'xls', + 'ppt': 'ppt' + } + + wx.openDocument({ + filePath: res.tempFilePath, + fileType: fileTypeMap[fileType] || 'doc', + success: () => { + console.log('鏂囨。鎵撳紑鎴愬姛') + }, + fail: (err) => { + console.error('鏂囨。鎵撳紑澶辫触:', err) + wx.showToast({ + title: '鏂囨。鎵撳紑澶辫触', + icon: 'none' + }) + } + }) + } else { + wx.showToast({ + title: '鏂囦欢涓嬭浇澶辫触', + icon: 'none' + }) + } + }, + fail: (err) => { + wx.hideLoading() + console.error('鏂囨。涓嬭浇澶辫触:', err) + wx.showToast({ + title: '鏂囦欢涓嬭浇澶辫触', + icon: 'none' + }) + } + }) + } else { + // 鍏朵粬鏂囦欢绫诲瀷 (media_type = 5) - 鎻愮ず鐢ㄦ埛 + wx.showModal({ + title: '鏂囦欢棰勮', + content: `鏆備笉鏀寔棰勮${fileType}绫诲瀷鐨勬枃浠讹紝璇蜂笅杞藉悗鏌ョ湅`, + showCancel: false, + confirmText: '鐭ラ亾浜�' + }) + } + } catch (error) { + console.error('棰勮闄勪欢澶辫触:', error) + wx.showToast({ + title: '棰勮澶辫触', icon: 'error' }) } @@ -904,13 +1111,15 @@ }) // 涓婁紶鍒癈OS - const uploadResult = await cosUtil.uploadAvatar(this.data.localAvatarPath, { - onProgress: (progress) => { - this.setData({ - avatarUploadProgress: Math.round(progress.percent) - }) - } - }) + const uploadResult = await cosUtil.uploadAvatar( + this.data.localAvatarPath, + 'avatar.jpg', + (percent) => { + this.setData({ + avatarUploadProgress: Math.round(percent) + }) + } + ) // 涓婁紶鎴愬姛锛屾洿鏂拌〃鍗曟暟鎹� this.setData({ @@ -1092,18 +1301,23 @@ }) // 绗竴姝ワ細涓婁紶鍒癈OS - const uploadResult = await cosUtil.uploadAvatar(this.data.localAvatarPath, 'avatar.jpg', (progress) => { - this.setData({ - avatarUploadProgress: Math.round(progress.percent) - }) - }) + const uploadResult = await cosUtil.uploadAvatar( + this.data.localAvatarPath, + 'avatar.jpg', + (percent) => { + this.setData({ + avatarUploadProgress: Math.round(percent) + }) + } + ) // 绗簩姝ワ細淇濆瓨濯掍綋璁板綍鍒版暟鎹簱 await this.saveMediaRecord({ - targetType: 7, // USER_AVATAR + targetType: 'player', // V2 浣跨敤瀛楃涓诧細player 琛ㄧず鐢ㄦ埛澶村儚锛屽搴� DB 鐨� 7 (USER_AVATAR) targetId: idInfo.userId, - url: uploadResult.url, + path: uploadResult.key, fileName: uploadResult.fileName || 'avatar.jpg', + fileExt: this.getFileExtension(uploadResult.fileName || 'avatar.jpg'), fileSize: uploadResult.fileSize, mediaType: 1 // 鍥剧墖 }) @@ -1128,21 +1342,27 @@ async uploadAttachmentsWithRegistrationId(idInfo) { for (let i = 0; i < this.data.attachments.length; i++) { const attachment = this.data.attachments[i] - if (!attachment.uploaded && attachment.localPath) { + if (!attachment.uploaded && attachment.path) { try { // 绗竴姝ワ細涓婁紶鍒癈OS - const uploadResult = await cosUtil.uploadFile(attachment.localPath, 'attachment', attachment.name || 'attachment', (progress) => { - this.setData({ - [`attachments[${i}].uploadProgress`]: Math.round(progress.percent) - }) - }) + const uploadResult = await cosUtil.uploadFile( + attachment.path, + 'attachment', + attachment.name || 'attachment', + (percent) => { + this.setData({ + [`attachments[${i}].uploadProgress`]: Math.round(percent) + }) + } + ) // 绗簩姝ワ細淇濆瓨濯掍綋璁板綍鍒版暟鎹簱 await this.saveMediaRecord({ - targetType: 5, // ACTIVITY_PLAYER_SUBMISSION + targetType: 'activity_player', // V2 浣跨敤瀛楃涓诧細activity_player 琛ㄧず鎶ュ悕闄勪欢锛屽搴� DB 鐨� 5 targetId: idInfo.activityPlayerId, - url: uploadResult.url, + path: uploadResult.key, fileName: uploadResult.fileName || attachment.name, + fileExt: this.getFileExtension(uploadResult.fileName || attachment.name), fileSize: uploadResult.fileSize, mediaType: this.getMediaType(attachment.name) // 鏍规嵁鏂囦欢鎵╁睍鍚嶅垽鏂被鍨� }) @@ -1167,11 +1387,11 @@ // 淇濆瓨濯掍綋璁板綍鍒版暟鎹簱 async saveMediaRecord(mediaData) { const mutation = ` - mutation SaveMedia($input: MediaInput!) { - saveMedia(input: $input) { - id - url - fileName + mutation SaveMediaV2($input: MediaSaveInput!) { + saveMediaV2(input: $input) { + success + message + mediaId } } ` @@ -1180,8 +1400,9 @@ input: { targetType: mediaData.targetType, targetId: mediaData.targetId, - url: mediaData.url, - fileName: mediaData.fileName, + path: mediaData.path, + fileName: mediaData.fileName || mediaData.name, // V2 瀛楁涓� fileName锛屽吋瀹规棫瀛楁 name + fileExt: mediaData.fileExt, fileSize: mediaData.fileSize, mediaType: mediaData.mediaType } @@ -1189,14 +1410,20 @@ try { const result = await app.graphqlRequest(mutation, variables) - console.log('濯掍綋璁板綍淇濆瓨鎴愬姛:', result.saveMedia) - return result.saveMedia + console.log('濯掍綋璁板綍淇濆瓨鎴愬姛(V2):', result.saveMediaV2) + return result.saveMediaV2 } catch (error) { - console.error('濯掍綋璁板綍淇濆瓨澶辫触:', error) + console.error('濯掍綋璁板綍淇濆瓨澶辫触(V2):', error) throw error } }, + // 鑾峰彇鏂囦欢鎵╁睍鍚� + getFileExtension(fileName) { + if (!fileName) return '' + return fileName.split('.').pop().toLowerCase() + }, + // 鏍规嵁鏂囦欢鍚嶈幏鍙栧獟浣撶被鍨� getMediaType(fileName) { if (!fileName) return 1 // 榛樿鍥剧墖 -- Gitblit v1.8.0