From bec58fa7fe4fae2deac88200d8d939e12ec8a08f Mon Sep 17 00:00:00 2001
From: lrj <owen.stl@gmail.com>
Date: 星期五, 03 十月 2025 22:26:39 +0800
Subject: [PATCH] 修复小程序WXS日期显示问题并重新设计【我的】页面
---
wx/pages/registration/registration.js | 376 ++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 338 insertions(+), 38 deletions(-)
diff --git a/wx/pages/registration/registration.js b/wx/pages/registration/registration.js
index 6de900a..68e7b91 100644
--- a/wx/pages/registration/registration.js
+++ b/wx/pages/registration/registration.js
@@ -9,6 +9,10 @@
activityId: '',
activity: null,
loading: false,
+ userInfo: null, // 褰撳墠鐢ㄦ埛淇℃伅
+ // 鎶ュ悕鐘舵�佹帶鍒�
+ submitDisabled: false,
+ submitText: '鎻愪氦鎶ュ悕',
// 琛ㄥ崟鏁版嵁
formData: {
@@ -97,16 +101,30 @@
this.setData({
activityId: activityId
})
+ // 浼樺厛妫�鏌ユ姤鍚嶇姸鎬�
+ this.checkRegistrationStatus(activityId)
+ // 鍔犺浇娲诲姩淇℃伅
this.loadActivityInfo()
} else {
console.log('鉂� 娌℃湁鎺ユ敹鍒癮ctivityId鍙傛暟')
}
+
+ // 鍔犺浇鐢ㄦ埛淇℃伅
+ this.loadUserInfo()
// 浠庡叏灞�鏁版嵁鑾峰彇鐢ㄦ埛淇℃伅棰勫~鍏�
this.prefillUserInfo()
// 鍔犺浇鍖哄煙鏁版嵁
this.loadRegions()
+ },
+
+ onShow() {
+ // 杩斿洖鏈〉鏃跺埛鏂版姤鍚嶇姸鎬�
+ const { activityId } = this.data
+ if (activityId) {
+ this.checkRegistrationStatus(activityId)
+ }
},
// 鍔犺浇娲诲姩淇℃伅
@@ -210,15 +228,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 +732,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 +835,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 +1125,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({
@@ -949,6 +1172,14 @@
async onSubmit() {
if (this.data.isSubmitting) return
+ if (this.data.submitDisabled) {
+ // 绂佺敤鎬佺洿鎺ユ嫤鎴偣鍑�
+ wx.showToast({
+ title: this.data.submitText,
+ icon: 'none'
+ })
+ return
+ }
// 琛ㄥ崟楠岃瘉
if (!this.validateForm()) {
@@ -1092,18 +1323,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 +1364,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 +1409,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 +1422,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 +1432,71 @@
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
}
},
+ // 妫�鏌ュ綋鍓嶆椿鍔ㄧ殑鎶ュ悕鐘舵�侊紝杩涘叆椤甸潰鏃惰皟鐢�
+ async checkRegistrationStatus(activityId) {
+ try {
+ // GraphQL 鏌ヨ鏈�鏂版姤鍚嶇姸鎬侊紙鍚庣杩斿洖鏈�鏂颁竴鏉¤褰曪級
+ const query = `
+ query GetPlayerRegistrationState($activityId: ID!) {
+ getPlayerRegistrationState(activityId: $activityId) {
+ id
+ status
+ registrationTime
+ reviewStatus
+ reviewComment
+ }
+ }
+ `
+ const res = await app.graphqlRequest(query, { activityId: parseInt(activityId) })
+ console.log('馃煢 鎶ュ悕鐘舵�佹煡璇㈢粨鏋滃師濮�:', res)
+
+ // 鍏煎澶氱杩斿洖缁撴瀯
+ const dataRoot = res?.getPlayerRegistrationState
+ || res?.playerRegistration
+ || res?.data?.getPlayerRegistrationState
+ || res?.data?.playerRegistration
+
+ let submitDisabled = false
+ let submitText = '鎻愪氦鎶ュ悕'
+
+ if (dataRoot && dataRoot.status !== undefined && dataRoot.status !== null) {
+ const statusNum = Number(dataRoot.status)
+ console.log('馃煢 瑙f瀽鍒版姤鍚嶇姸鎬�:', statusNum)
+ if (statusNum === 1) {
+ submitDisabled = true
+ submitText = '宸茬粡鎶ュ悕'
+ } else if (statusNum === 0) {
+ submitDisabled = true
+ submitText = '绛夊緟瀹℃牳'
+ } else {
+ submitDisabled = false
+ submitText = '鎻愪氦鎶ュ悕'
+ }
+ } else {
+ console.log('馃煢 鏈壘鍒版姤鍚嶈褰曟垨鐘舵�侊紝鍏佽鎻愪氦')
+ }
+
+ this.setData({ submitDisabled, submitText })
+ } catch (err) {
+ console.warn('鈿狅笍 鎶ュ悕鐘舵�佹煡璇㈠け璐ワ紝鍏佽鐢ㄦ埛鎻愪氦:', err)
+ this.setData({ submitDisabled: false, submitText: '鎻愪氦鎶ュ悕' })
+ }
+ },
+
+ // 鑾峰彇鏂囦欢鎵╁睍鍚�
+ getFileExtension(fileName) {
+ if (!fileName) return ''
+ return fileName.split('.').pop().toLowerCase()
+ },
+
// 鏍规嵁鏂囦欢鍚嶈幏鍙栧獟浣撶被鍨�
getMediaType(fileName) {
if (!fileName) return 1 // 榛樿鍥剧墖
--
Gitblit v1.8.0