Codex Assistant
1 天以前 ba94ceae1315174798ae1967ef62268c6d16cd5b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
// pages/project/detail.js
const app = getApp()
 
Page({
  data: {
    projectId: '',
    projectDetail: null,
    ratingStats: null,
    loading: true,
    error: '',
    statusText: '',
    genderText: '',
    educationText: ''
  },
 
  onLoad(options) {
    if (options.id) {
      this.setData({
        projectId: options.id
      })
      this.loadProjectDetail()
    } else {
      this.setData({
        error: '缺少项目ID参数',
        loading: false
      })
    }
  },
 
  // 加载项目详情
  async loadProjectDetail() {
    try {
      this.setData({ 
        loading: true, 
        error: '' 
      })
 
      // 调用API获取项目详情
      const projectDetail = await this.getProjectDetailFromAPI(this.data.projectId)
      
      if (projectDetail) {
        // 处理文件大小显示
        if (projectDetail.submissionFiles) {
          projectDetail.submissionFiles.forEach(file => {
            file.fileSizeText = this.formatFileSize(file.fileSize)
            // 字段已经是正确的名称,无需映射
            // fullUrl, fullThumbUrl, fileSize, fileExt 都是正确的字段名
          })
        }
 
        // 获取评分统计
        const ratingStats = await this.getRatingStatsFromAPI(this.data.projectId)
        
        // 处理评分时间显示
        if (ratingStats && ratingStats.judgeRatings) {
          ratingStats.judgeRatings.forEach(rating => {
            if (rating.ratingTime) {
              rating.ratingTimeText = this.formatDateTime(rating.ratingTime)
            }
          })
        }
 
        this.setData({
          projectDetail,
          ratingStats,
          statusText: this.getStatusText(projectDetail.state),
          genderText: this.getGenderText(projectDetail.playerInfo?.gender),
          educationText: this.getEducationText(projectDetail.playerInfo?.education),
          loading: false
        })
      } else {
        throw new Error('项目详情获取失败')
      }
    } catch (error) {
      console.error('加载项目详情失败:', error)
      this.setData({
        error: error.message || '加载失败,请重试',
        loading: false
      })
    }
  },
 
  // 从API获取项目详情
  async getProjectDetailFromAPI(projectId) {
    // 构建GraphQL查询
    const query = `
      query GetProjectDetail($id: ID!) {
        activityPlayerDetail(id: $id) {
          id
          playerInfo {
            id
            name
            phone
            gender
            birthday
            education
            introduction
            description
            avatarUrl
            avatar {
              id
              fullUrl
              fullThumbUrl
              name
              fileSize
              fileExt
            }
            userInfo {
              userId
              name
              phone
              avatarUrl
            }
          }
          regionInfo {
            id
            name
            fullPath
          }
          activityName
          projectName
          description
          feedback
          state
          stageId
          submissionFiles {
            id
            fullUrl
            fullThumbUrl
            name
            fileSize
            fileExt
            mediaType
          }
          ratingForm {
            schemeId
            schemeName
            items {
              id
              name
              maxScore
              orderNo
            }
            totalMaxScore
          }
        }
      }
    `
 
    try {
      const result = await app.graphqlRequest(query, { id: projectId })
      return result.activityPlayerDetail
    } catch (error) {
      throw error
    }
  },
 
  // 获取评分统计
  async getRatingStatsFromAPI(projectId) {
    // 暂时返回空的评分数据,避免GraphQL查询错误
    // TODO: 需要后端提供合适的评分统计查询接口
    try {
      return {
        averageScore: null,
        ratingCount: 0,
        judgeRatings: []
      }
    } catch (error) {
      throw error
    }
  },
 
  // 获取评委评分详情
  async getJudgeRatingDetail(activityPlayerId, judgeId) {
    const query = `
      query GetJudgeRatingDetail($activityPlayerId: ID!, $judgeId: ID!) {
        judgeRatingDetail(activityPlayerId: $activityPlayerId, judgeId: $judgeId) {
          remark
        }
      }
    `
 
    try {
      const result = await app.graphqlRequest(query, { activityPlayerId, judgeId })
      return result.judgeRatingDetail
    } catch (error) {
      throw error
    }
  },
 
  // 预览文件
  previewFile(e) {
    const file = e.currentTarget.dataset.file
    
    if (!file || !file.fullUrl) {
      wx.showToast({
        title: '文件链接无效',
        icon: 'none'
      })
      return
    }
 
    // 根据文件类型进行不同处理
    const fileExt = (file.fileExt || '').toLowerCase()
    
    if (this.isImageFile(fileExt)) {
      // 图片预览
      wx.previewImage({
        urls: [file.fullUrl],
        current: file.fullUrl
      })
    } else if (this.isVideoFile(fileExt)) {
      // 视频预览
      wx.navigateTo({
        url: `/pages/video/video?url=${encodeURIComponent(file.fullUrl)}&title=${encodeURIComponent(file.name)}`
      })
    } else if (this.isPdfFile(fileExt)) {
      // PDF文档预览
      this.previewPdfFile(file)
    } else if (this.isOfficeFile(fileExt)) {
      // Office文档预览
      this.previewOfficeFile(file)
    } else {
      // 其他文件类型,尝试下载打开
      this.downloadAndOpenFile(file)
    }
  },
 
  // PDF文档预览
  previewPdfFile(file) {
    wx.showLoading({
      title: '正在打开PDF...'
    })
    
    wx.downloadFile({
      url: file.fullUrl,
      success: (downloadRes) => {
        wx.hideLoading()
        if (downloadRes.statusCode === 200) {
          wx.openDocument({
            filePath: downloadRes.tempFilePath,
            fileType: 'pdf',
            success: () => {
              console.log('PDF打开成功')
            },
            fail: (error) => {
              console.error('PDF打开失败:', error)
              wx.showToast({
                title: 'PDF打开失败',
                icon: 'none'
              })
            }
          })
        } else {
          wx.showToast({
            title: 'PDF下载失败',
            icon: 'none'
          })
        }
      },
      fail: (error) => {
        wx.hideLoading()
        console.error('PDF下载失败:', error)
        wx.showToast({
          title: 'PDF下载失败',
          icon: 'none'
        })
      }
    })
  },
 
  // Office文档预览
  previewOfficeFile(file) {
    const fileExt = (file.fileExt || '').toLowerCase()
    
    wx.showLoading({
      title: '正在打开文档...',
      mask: true
    })
    
    wx.downloadFile({
      url: file.fullUrl,
      success: (downloadRes) => {
        wx.hideLoading()
        if (downloadRes.statusCode === 200) {
          // 文件类型映射
          const fileTypeMap = {
            'doc': 'doc',
            'docx': 'docx',
            'xls': 'xls',
            'xlsx': 'xlsx',
            'ppt': 'ppt',
            'pptx': 'pptx'
          }
          
          wx.openDocument({
            filePath: downloadRes.tempFilePath,
            fileType: fileTypeMap[fileExt] || 'doc',
            success: () => {
              console.log('文档打开成功')
            },
            fail: (error) => {
              console.error('文档打开失败:', error)
              wx.showModal({
                title: '打开失败',
                content: '文档打开失败,可能是文件格式不支持或文件损坏',
                showCancel: false,
                confirmText: '确定'
              })
            }
          })
        } else {
          wx.showToast({
            title: '文件下载失败',
            icon: 'none'
          })
        }
      },
      fail: (error) => {
        wx.hideLoading()
        console.error('文档下载失败:', error)
        wx.showToast({
          title: '文件下载失败',
          icon: 'none'
        })
      }
    })
  },
 
  // 下载并打开文件
  downloadAndOpenFile(file) {
    wx.showModal({
      title: '文件预览',
      content: '是否要下载并打开此文件?',
      confirmText: '下载',
      cancelText: '取消',
      success: (res) => {
        if (res.confirm) {
          wx.showLoading({
            title: '正在下载...'
          })
          
          wx.downloadFile({
            url: file.fullUrl,
            success: (downloadRes) => {
              wx.hideLoading()
              if (downloadRes.statusCode === 200) {
                wx.openDocument({
                  filePath: downloadRes.tempFilePath,
                  success: () => {
                    console.log('文档打开成功')
                  },
                  fail: (error) => {
                    console.error('文档打开失败:', error)
                    wx.showToast({
                      title: '文件打开失败',
                      icon: 'none'
                    })
                  }
                })
              } else {
                wx.showToast({
                  title: '文件下载失败',
                  icon: 'none'
                })
              }
            },
            fail: (error) => {
              wx.hideLoading()
              console.error('文件下载失败:', error)
              wx.showToast({
                title: '文件下载失败',
                icon: 'none'
              })
            }
          })
        }
      }
    })
  },
 
  // 判断是否为图片文件
  isImageFile(fileExt) {
    const imageExts = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp']
    return imageExts.includes(fileExt)
  },
 
  // 判断是否为视频文件
  isVideoFile(fileExt) {
    const videoExts = ['mp4', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'webm']
    return videoExts.includes(fileExt)
  },
 
  // 判断是否为PDF文件
  isPdfFile(fileExt) {
    return fileExt === 'pdf'
  },
 
  // 判断是否为Office文件
  isOfficeFile(fileExt) {
    const officeExts = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'dotx', 'xlsb', 'xlsm', 'ppsx', 'pps', 'potx', 'ppsm']
    return officeExts.includes(fileExt)
  },
 
  // 格式化文件大小
  formatFileSize(bytes) {
    if (!bytes || bytes === 0) return '0 B'
    
    const k = 1024
    const sizes = ['B', 'KB', 'MB', 'GB']
    const i = Math.floor(Math.log(bytes) / Math.log(k))
    
    return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
  },
 
  // 格式化日期时间
  formatDateTime(dateTimeStr) {
    if (!dateTimeStr) return ''
    
    try {
      const date = new Date(dateTimeStr)
      const year = date.getFullYear()
      const month = String(date.getMonth() + 1).padStart(2, '0')
      const day = String(date.getDate()).padStart(2, '0')
      const hours = String(date.getHours()).padStart(2, '0')
      const minutes = String(date.getMinutes()).padStart(2, '0')
      
      return `${year}-${month}-${day} ${hours}:${minutes}`
    } catch (error) {
      return dateTimeStr
    }
  },
 
  // 获取状态文本
  getStatusText(state) {
    const statusMap = {
      0: '未审核',
      1: '审核通过',
      2: '审核不通过'
    }
    return statusMap[state] || '未知状态'
  },
 
  // 获取性别文本
  getGenderText(gender) {
    const genderMap = {
      'MALE': '男',
      'FEMALE': '女'
    }
    return genderMap[gender] || ''
  },
 
  // 获取学历文本
  getEducationText(education) {
    const educationMap = {
      'HIGH_SCHOOL': '高中及以下',
      'COLLEGE': '大专',
      'BACHELOR': '本科',
      'MASTER': '硕士',
      'DOCTOR': '博士'
    }
    return educationMap[education] || ''
  },
 
  // 分享功能
  onShareAppMessage() {
    return {
      title: `项目详情 - ${this.data.projectDetail?.projectName || ''}`,
      path: `/pages/project/detail?id=${this.data.projectId}`
    }
  }
})