Codex Assistant
2025-11-06 375c18a6d2713ff19b22093eec57315992d8333f
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
// pages/activity/detail.js
const app = getApp()
const utils = require('../../lib/utils.js')
 
Page({
  data: {
    activityId: null,
    activity: null,
    myApplication: null,
    buttonDisabled: false,
    buttonText: '我要报名',
    // 导出相关
    isEmployee: false,
    exportingActivity: false,
    exportingStageId: null,
    loading: true,
    error: null
  },
 
  onLoad(options) {
    if (options.id) {
      this.setData({ activityId: options.id });
      this.loadActivityDetail(options.id);
    } else {
      this.setData({ loading: false, error: '无效的比赛ID' });
    }
  },
 
  onPullDownRefresh() {
    if (this.data.activityId) {
      this.loadActivityDetail(this.data.activityId).finally(() => {
        wx.stopPullDownRefresh();
      });
    } else {
      wx.stopPullDownRefresh();
    }
  },
 
  loadActivityDetail(id) {
    this.setData({ loading: true, error: null });
    const query = `
      query GetActivityDetailAndStatus($id: ID!) {
        activity(id: $id) {
          id
          name
          description
          signupDeadline
          matchTime
          address
          state
          stateName
          playerCount
          playerMax
          coverImage { fullUrl }
          images { fullUrl }
          videos { fullUrl, fullThumbUrl }
          stages {
            id
            name
            matchTime
            description
          }
        }
        myActivityPlayer(activityId: $id) {
          id
          state
        }
      }
    `;
 
    return app.graphqlRequest(query, { id: id })
      .then(res => {
        if (res.activity) {
          let buttonDisabled = false;
          let buttonText = '我要报名';
          const myApplication = res.myActivityPlayer;
 
          if (myApplication) {
            if (myApplication.state === 0) {
              buttonDisabled = true;
              buttonText = '等待审核';
            } else if (myApplication.state === 1) {
              buttonDisabled = true;
              buttonText = '已报名';
            }
          }
 
          if (!buttonDisabled) {
            if (new Date() > new Date(res.activity.signupDeadline)) {
              buttonDisabled = true;
              buttonText = '报名已截止';
            }
          }
 
          // 角色:是否员工(主办方/管理员)
          const isEmployee = !!(app.globalData?.userInfo?.employee && app.globalData.userInfo.employee.id)
 
          this.setData({
            activity: res.activity,
            myApplication: myApplication,
            loading: false,
            buttonDisabled: buttonDisabled,
            buttonText: buttonText,
            isEmployee: isEmployee
          });
        } else {
          throw new Error('未找到比赛信息');
        }
      })
      .catch(err => {
        this.setData({
          loading: false,
          error: '加载失败,请稍后重试'
        });
        console.error('加载比赛详情或报名状态失败:', err);
      });
  },
 
  handleRegister() {
    if (!this.data.activityId) {
      wx.showToast({
        title: '无效的活动ID',
        icon: 'none'
      });
      return;
    }
    wx.navigateTo({
      url: `/pages/registration/registration?id=${this.data.activityId}`
    });
  },
 
  // 格式化日期和时间
  formatDateTime(dateStr) {
    return utils.formatDate(dateStr, 'YYYY-MM-DD HH:mm');
  },
  
  // 格式化日期范围
  formatDateRange(start, end) {
    if (!start && !end) return '待定';
    const startDate = start ? utils.formatDate(start, 'YYYY-MM-DD') : '';
    const endDate = end ? utils.formatDate(end, 'YYYY-MM-DD') : '';
    if (startDate && endDate && startDate !== endDate) {
      return `${startDate} - ${endDate}`;
    }
    return startDate || endDate;
  },
 
  // 复制链接到剪贴板
  copyLink(e) {
    const url = e.currentTarget.dataset.url
    if (!url) {
      wx.showToast({ title: '暂无链接', icon: 'none' })
      return
    }
    wx.setClipboardData({
      data: url,
      success: () => {
        wx.showToast({ title: '已复制下载链接', icon: 'success' })
      }
    })
  },
 
  // 在WebView内打开链接(用于预览/下载)
  openWebView(e) {
    const url = e.currentTarget.dataset.url
    if (!url) {
      wx.showToast({ title: '暂无链接', icon: 'none' })
      return
    }
    wx.navigateTo({
      url: `/pages/webview/webview?url=${encodeURIComponent(url)}&title=${encodeURIComponent('评审导出ZIP')}`
    })
  },
 
  // 触发导出(主活动)
  async handleExportActivity() {
    if (!this.data.isEmployee) {
      wx.showToast({ title: '无权限执行导出', icon: 'none' })
      return
    }
    if (!this.data.activityId) {
      wx.showToast({ title: '无效的活动ID', icon: 'none' })
      return
    }
    this.setData({ exportingActivity: true })
    const mutation = `
      mutation ExportReviewZip($activityId: ID!, $stageIds: [ID]) {
        exportReviewZip(activityId: $activityId, stageIds: $stageIds) {
          success
          url
          message
        }
      }
    `
    try {
      const res = await app.graphqlRequest(mutation, { activityId: this.data.activityId, stageIds: null })
      const result = res && res.exportReviewZip
      if (result && result.success) {
        wx.showToast({ title: '导出成功', icon: 'success' })
        // 刷新以显示最新链接
        await this.loadActivityDetail(this.data.activityId)
      } else {
        wx.showToast({ title: result?.message || '导出失败', icon: 'none' })
      }
    } catch (err) {
      console.error('导出失败:', err)
      wx.showToast({ title: '导出失败', icon: 'none' })
    } finally {
      this.setData({ exportingActivity: false })
    }
  },
 
  // 触发导出(阶段)
  async handleExportStage(e) {
    if (!this.data.isEmployee) {
      wx.showToast({ title: '无权限执行导出', icon: 'none' })
      return
    }
    const stageId = e.currentTarget.dataset.stageId
    if (!stageId) {
      wx.showToast({ title: '无效的阶段ID', icon: 'none' })
      return
    }
    this.setData({ exportingStageId: stageId })
    const mutation = `
      mutation ExportReviewZip($activityId: ID!, $stageIds: [ID]) {
        exportReviewZip(activityId: $activityId, stageIds: $stageIds) {
          success
          url
          message
        }
      }
    `
    try {
      const res = await app.graphqlRequest(mutation, { activityId: this.data.activityId, stageIds: [stageId] })
      const result = res && res.exportReviewZip
      if (result && result.success) {
        wx.showToast({ title: '导出成功', icon: 'success' })
        await this.loadActivityDetail(this.data.activityId)
      } else {
        wx.showToast({ title: result?.message || '导出失败', icon: 'none' })
      }
    } catch (err) {
      console.error('导出阶段失败:', err)
      wx.showToast({ title: '导出失败', icon: 'none' })
    } finally {
      this.setData({ exportingStageId: null })
    }
  }
});