Codex Assistant
昨天 afeeed281e60466b576fbe74d339634cc5d07b82
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
const { graphqlRequest } = require('../../lib/utils')
 
const DETAIL_QUERY = `
  query ActivityPlayerDetail($id: ID!) {
    activityPlayerDetail(id: $id) {
      id
      activityName
      projectName
      description
      feedback
      state
      playerInfo {
        id
        name
        phone
      }
      submissionFiles {
        id
        name
        fullUrl
        fullThumbUrl
        fileExt
        fileSize
        mediaType
      }
    }
  }
`
 
const APPROVE_MUTATION = `
  mutation ApproveActivityPlayer($id: ID!, $feedback: String) {
    approveActivityPlayer(activityPlayerId: $id, feedback: $feedback)
  }
`
 
const REJECT_MUTATION = `
  mutation RejectActivityPlayer($id: ID!, $feedback: String) {
    rejectActivityPlayer(activityPlayerId: $id, feedback: $feedback)
  }
`
 
Page({
  data: {
    loading: false,
    submitting: false,
    activityPlayerId: null,
    detail: {
      playerInfo: {},
      submissionFiles: []
    },
    feedback: '',
    mediaList: []
  },
 
  onLoad(options) {
    if (options && options.id) {
      if (typeof this.getOpenerEventChannel === 'function') {
        this.eventChannel = this.getOpenerEventChannel()
      }
      this.setData({ activityPlayerId: options.id })
      this.loadDetail()
    } else {
      wx.showToast({ title: '缺少报名ID', icon: 'none' })
      setTimeout(() => wx.navigateBack(), 800)
    }
  },
 
  async loadDetail() {
    if (!this.data.activityPlayerId) {
      return
    }
 
    this.setData({ loading: true })
 
    try {
      const result = await graphqlRequest(DETAIL_QUERY, { id: this.data.activityPlayerId })
      const detail = result && result.activityPlayerDetail
 
      if (!detail) {
        wx.showToast({ title: '未找到报名信息', icon: 'none' })
        return
      }
 
      const mediaList = (detail.submissionFiles || []).map(item => this.transformMediaFile(item))
      const playerInfo = detail.playerInfo || {}
 
      this.setData({
        detail: {
          ...detail,
          playerInfo,
          stateText: this.getStateText(detail.state),
          submissionFiles: mediaList
        },
        mediaList,
        feedback: detail.feedback || ''
      })
    } catch (error) {
      console.error('加载审核详情失败:', error)
      wx.showToast({ title: '加载失败', icon: 'none' })
    } finally {
      this.setData({ loading: false })
    }
  },
 
  transformMediaFile(file = {}) {
    const url = file.fullUrl || file.fullThumbUrl || file.url || ''
    const thumbUrl = file.fullThumbUrl || file.fullUrl || url
    const ext = (file.fileExt || '').toLowerCase()
    let mediaType = 'file'
 
    if (file.mediaType === 1 || ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'heic'].includes(ext)) {
      mediaType = 'image'
    } else if (file.mediaType === 2 || ['mp4', 'mov', 'avi', 'wmv', 'mkv', 'webm', 'flv'].includes(ext)) {
      mediaType = 'video'
    } else if (ext === 'pdf') {
      mediaType = 'pdf'
    } else if (['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'wps', 'txt', 'rtf'].includes(ext)) {
      mediaType = 'word'
    }
 
    return {
      id: file.id,
      name: file.name || '资料文件',
      url,
      thumbUrl,
      mediaType,
      size: Number(file.fileSize) || 0
    }
  },
 
  onFeedbackInput(e) {
    this.setData({ feedback: e.detail.value })
  },
 
  onApprove() {
    this.handleAudit('APPROVE')
  },
 
  onReject() {
    this.handleAudit('REJECT')
  },
 
  async handleAudit(action) {
    if (!this.data.activityPlayerId) {
      return
    }
 
    const mutation = action === 'APPROVE' ? APPROVE_MUTATION : REJECT_MUTATION
    const successText = action === 'APPROVE' ? '审核通过' : '已驳回'
 
    this.setData({ submitting: true })
 
    try {
      const trimmedFeedback = (this.data.feedback || '').trim()
      const variables = {
        id: Number(this.data.activityPlayerId),
        feedback: trimmedFeedback ? trimmedFeedback : null
      }
      const result = await graphqlRequest(mutation, variables)
      const success = result && (action === 'APPROVE' ? result.approveActivityPlayer : result.rejectActivityPlayer)
 
      if (success) {
        wx.showToast({ title: successText, icon: 'success' })
        if (this.eventChannel) {
          this.eventChannel.emit('auditUpdated', { id: this.data.activityPlayerId })
        }
        setTimeout(() => wx.navigateBack(), 600)
      } else {
        wx.showToast({ title: '操作失败', icon: 'none' })
      }
    } catch (error) {
      console.error('提交审核决策失败:', error)
      wx.showToast({ title: '操作失败', icon: 'none' })
    } finally {
      this.setData({ submitting: false })
    }
  },
 
  onMediaTap(e) {
    const index = Number(e.currentTarget.dataset.index)
    const mediaList = this.data.mediaList || []
    const media = mediaList[index]
    if (!media) return
 
    if (media.mediaType === 'image') {
      const images = mediaList.filter(item => item.mediaType === 'image').map(item => item.url)
      wx.previewImage({
        current: media.url,
        urls: images
      })
    } else if (media.mediaType === 'video') {
      wx.navigateTo({
        url: `/pages/video/video?url=${encodeURIComponent(media.url)}&title=${encodeURIComponent(media.name)}`
      })
    } else {
      this.openDocumentMedia(media)
    }
  },
 
  async openDocumentMedia(media) {
    try {
      wx.showLoading({ title: '打开中...' })
      const downloadRes = await new Promise((resolve, reject) => {
        wx.downloadFile({
          url: media.url,
          success: resolve,
          fail: reject
        })
      })
 
      if (downloadRes.statusCode !== 200) {
        throw new Error('文件下载失败')
      }
 
      await new Promise((resolve, reject) => {
        wx.openDocument({
          filePath: downloadRes.tempFilePath,
          showMenu: true,
          success: resolve,
          fail: reject
        })
      })
    } catch (error) {
      console.error('打开文件失败:', error)
      wx.showToast({
        title: '无法打开文件',
        icon: 'error'
      })
    } finally {
      wx.hideLoading()
    }
  },
 
  getFileSizeText(size) {
    if (!size || size <= 0) {
      return '未知大小'
    }
    if (size < 1024) {
      return `${size}B`
    }
    if (size < 1024 * 1024) {
      return `${(size / 1024).toFixed(1)}KB`
    }
    return `${(size / (1024 * 1024)).toFixed(1)}MB`
  },
 
  getStateText(state) {
    switch (state) {
      case 0:
        return '未审核'
      case 1:
        return '审核通过'
      case 2:
        return '审核驳回'
      default:
        return '未知状态'
    }
  }
})