@hupu-tech/shaper 0.2.12 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +6 -0
- package/dist/auth/auth.d.ts +1 -0
- package/dist/cli.js +2 -2
- package/dist/cloud/client.d.ts +0 -1
- package/dist/cloud/service-build.d.ts +2 -4
- package/dist/index.js +1 -1
- package/dist/platform/api.d.ts +2 -0
- package/dist/project/create.d.ts +9 -3
- package/dist/project/delivery.d.ts +5 -5
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.js +1 -1
- package/dist/shared-UKIFY6QO.js +19 -0
- package/package.json +1 -1
- package/skills/business/SKILL.md +158 -0
- package/skills/business/activity/README.md +14 -0
- package/skills/business/activity/hupu-leaderboard-template/SKILL.md +52 -0
- package/skills/business/activity/hupu-leaderboard-template/example/README.md +20 -0
- package/skills/business/activity/hupu-leaderboard-template/example/cloudfunctions/activity_api/.cloudignore +3 -0
- package/skills/business/activity/hupu-leaderboard-template/example/cloudfunctions/activity_api/index.js +218 -0
- package/skills/business/activity/hupu-leaderboard-template/example/cloudfunctions/activity_api/package.json +15 -0
- package/skills/business/activity/hupu-leaderboard-template/example/cloudfunctions/activity_api/scf_bootstrap +3 -0
- package/skills/business/activity/hupu-leaderboard-template/example/index.html +291 -0
- package/skills/business/activity/hupu-leaderboard-template/example/migrations/20260828210000_create_leaderboard.sql +54 -0
- package/skills/business/activity/hupu-lottery-draw/SKILL.md +50 -0
- package/skills/business/activity/hupu-lottery-draw/example/README.md +21 -0
- package/skills/business/activity/hupu-lottery-draw/example/cloudfunctions/activity_api/.cloudignore +3 -0
- package/skills/business/activity/hupu-lottery-draw/example/cloudfunctions/activity_api/index.js +142 -0
- package/skills/business/activity/hupu-lottery-draw/example/cloudfunctions/activity_api/package.json +9 -0
- package/skills/business/activity/hupu-lottery-draw/example/cloudfunctions/activity_api/scf_bootstrap +3 -0
- package/skills/business/activity/hupu-lottery-draw/example/index.html +178 -0
- package/skills/business/activity/hupu-lottery-draw/example/migrations/20260828220000_create_draw.sql +193 -0
- package/skills/business/activity/hupu-pk-voting/SKILL.md +54 -0
- package/skills/business/activity/hupu-pk-voting/example/README.md +44 -0
- package/skills/business/activity/hupu-pk-voting/example/cloudfunctions/activity_api/.cloudignore +3 -0
- package/skills/business/activity/hupu-pk-voting/example/cloudfunctions/activity_api/index.js +370 -0
- package/skills/business/activity/hupu-pk-voting/example/cloudfunctions/activity_api/package.json +15 -0
- package/skills/business/activity/hupu-pk-voting/example/cloudfunctions/activity_api/scf_bootstrap +2 -0
- package/skills/business/activity/hupu-pk-voting/example/index.html +729 -0
- package/skills/business/activity/hupu-pk-voting/example/migrations/20260828220000_create_pk_vote.sql +168 -0
- package/skills/business/activity/hupu-request-activity-execute-vote-task/SKILL.md +77 -0
- package/skills/business/activity/hupu-request-activity-get-vote-detail/SKILL.md +84 -0
- package/skills/business/activity/hupu-request-activity-get-vote-task-list/SKILL.md +86 -0
- package/skills/business/activity/hupu-request-activity-list-by-biz-keys/SKILL.md +153 -0
- package/skills/business/activity/hupu-request-activity-report-vote-task/SKILL.md +58 -0
- package/skills/business/activity/hupu-request-activity-submit-vote/SKILL.md +58 -0
- package/skills/business/activity/hupu-vote-task/SKILL.md +47 -0
- package/skills/business/community/README.md +13 -0
- package/skills/business/community/hupu-request-bbs-detail/SKILL.md +197 -0
- package/skills/business/community/hupu-request-bbs-get-tag-thread-list/SKILL.md +257 -0
- package/skills/business/community/hupu-request-bbs-get-topic-threads/SKILL.md +159 -0
- package/skills/business/community/hupu-request-bbs-gets-thread-post-list/SKILL.md +124 -0
- package/skills/business/community/hupu-request-bbs-open-post-editor/SKILL.md +75 -0
- package/skills/business/community/hupu-request-bbs-reply-post/SKILL.md +59 -0
- package/skills/business/community/hupu-score-add-score/SKILL.md +57 -0
- package/skills/business/community/hupu-score-get-item-detail/SKILL.md +173 -0
- package/skills/business/community/hupu-score-get-score/SKILL.md +263 -0
- package/skills/business/quality/README.md +7 -0
- package/skills/business/quality/hupu-security-check-audit/SKILL.md +39 -0
- package/skills/business/quality/hupu-wasm-compression/SKILL.md +69 -0
- package/skills/business/quality/hupu-wasm-compression/agents/openai.yaml +4 -0
- package/skills/business/quality/hupu-wasm-compression/tool/checks.mjs +90 -0
- package/skills/business/quality/hupu-wasm-compression/tool/compress-worker.mjs +40 -0
- package/skills/business/quality/hupu-wasm-compression/tool/public/app.js +84 -0
- package/skills/business/quality/hupu-wasm-compression/tool/public/index.html +80 -0
- package/skills/business/quality/hupu-wasm-compression/tool/public/style.css +3 -0
- package/skills/business/quality/hupu-wasm-compression/tool/server.mjs +126 -0
- package/skills/business/quality/hupu-web-security-audit/SKILL.md +45 -0
- package/skills/business/quality/hupu-web-security-audit/agents/openai.yaml +4 -0
- package/skills/business/rewards/README.md +13 -0
- package/skills/business/rewards/hupu-vacoin/SKILL.md +70 -0
- package/skills/business/rewards/hupu-vacoin-consume-coins/SKILL.md +47 -0
- package/skills/business/rewards/hupu-vacoin-get-coin-overview/SKILL.md +52 -0
- package/skills/business/rewards/hupu-vacoin-get-session-coins/SKILL.md +44 -0
- package/skills/business/rewards/hupu-vacoin-reset-session-id/SKILL.md +39 -0
- package/skills/business/rewards/hupu-vatask/SKILL.md +63 -0
- package/skills/business/rewards/hupu-vatask-complete-reward-video/SKILL.md +43 -0
- package/skills/business/rewards/hupu-vatask-consume-activity-chance/SKILL.md +48 -0
- package/skills/business/rewards/hupu-vatask-get-activity-task-state/SKILL.md +49 -0
- package/skills/business/runtime/README.md +13 -0
- package/skills/business/runtime/hupu-add-to-desktop/SKILL.md +51 -0
- package/skills/business/runtime/hupu-close-webview/SKILL.md +48 -0
- package/skills/business/runtime/hupu-cloud-auth/SKILL.md +43 -0
- package/skills/business/runtime/hupu-cloud-request/SKILL.md +56 -0
- package/skills/business/runtime/hupu-fullscreen-safe-top/SKILL.md +33 -0
- package/skills/business/runtime/hupu-navigate-to/SKILL.md +45 -0
- package/skills/business/runtime/hupu-request/SKILL.md +67 -0
- package/skills/business/runtime/hupu-seer-chat/SKILL.md +183 -0
- package/skills/business/runtime/hupu-track-report/SKILL.md +71 -0
- package/skills/business/sharing/README.md +7 -0
- package/skills/business/sharing/hupu-oss-upload-file/SKILL.md +40 -0
- package/skills/business/sharing/hupu-result-poster-posting/SKILL.md +37 -0
- package/skills/business/sharing/hupu-result-poster-posting/example/README.md +14 -0
- package/skills/business/sharing/hupu-result-poster-posting/example/cloudfunctions/activity_api/.cloudignore +3 -0
- package/skills/business/sharing/hupu-result-poster-posting/example/cloudfunctions/activity_api/index.js +187 -0
- package/skills/business/sharing/hupu-result-poster-posting/example/cloudfunctions/activity_api/package.json +15 -0
- package/skills/business/sharing/hupu-result-poster-posting/example/cloudfunctions/activity_api/scf_bootstrap +3 -0
- package/skills/business/sharing/hupu-result-poster-posting/example/index.html +256 -0
- package/skills/business/sharing/hupu-result-poster-posting/example/migrations/20260828213000_create_result_poster_results.sql +60 -0
- package/skills/business/sharing/hupu-result-poster-posting/references/api-contract.md +46 -0
- package/skills/business/sharing/hupu-social-share/SKILL.md +27 -0
- package/skills/business/sports/README.md +27 -0
- package/skills/business/sports/hupu-request-basketball-player-info/SKILL.md +131 -0
- package/skills/business/sports/hupu-request-basketball-single-match/SKILL.md +158 -0
- package/skills/business/sports/hupu-request-basketball-team-info/SKILL.md +96 -0
- package/skills/business/sports/hupu-request-basketball-team-player-list/SKILL.md +108 -0
- package/skills/business/sports/hupu-request-basketball-team-salary-info/SKILL.md +85 -0
- package/skills/business/sports/hupu-request-football-coach-info/SKILL.md +76 -0
- package/skills/business/sports/hupu-request-football-live-room-news-list/SKILL.md +85 -0
- package/skills/business/sports/hupu-request-football-match-info/SKILL.md +126 -0
- package/skills/business/sports/hupu-request-football-player-info/SKILL.md +82 -0
- package/skills/business/sports/hupu-request-football-team-info/SKILL.md +83 -0
- package/skills/business/sports/hupu-request-football-team-player-season-stats/SKILL.md +73 -0
- package/skills/business/sports/hupu-request-football-team-season-year/SKILL.md +68 -0
- package/skills/business/sports/hupu-request-kog-playbyplay/SKILL.md +77 -0
- package/skills/business/sports/hupu-request-live-tab-info-list/SKILL.md +85 -0
- package/skills/business/sports/hupu-request-live-tab-list/SKILL.md +66 -0
- package/skills/business/sports/hupu-request-lol-playbyplay/SKILL.md +77 -0
- package/skills/business/sports/hupu-request-match-get-tab-detail-schedule-list/SKILL.md +113 -0
- package/skills/business/sports/hupu-request-match-query-all-diagram-info-by-id/SKILL.md +79 -0
- package/skills/business/sports/hupu-request-match-query-match-stats-by-match-info/SKILL.md +85 -0
- package/skills/business/sports/hupu-request-news-news-common-list/SKILL.md +90 -0
- package/skills/business/sports/hupu-request-news-player-news-list/SKILL.md +79 -0
- package/skills/business/sports/hupu-request-news-subject-news/SKILL.md +89 -0
- package/skills/business/sports/hupu-request-news-team-news-list/SKILL.md +76 -0
- package/skills/business/storage/README.md +9 -0
- package/skills/business/storage/hupu-cloud-save/SKILL.md +129 -0
- package/skills/business/storage/hupu-cloud-save/references/legacy-migration.md +111 -0
- package/skills/business/storage/hupu-cloud-save-load/SKILL.md +41 -0
- package/skills/business/storage/hupu-cloud-save-save/SKILL.md +45 -0
- package/skills/business/storage/hupu-storage-get-value/SKILL.md +26 -0
- package/skills/business/storage/hupu-storage-set-value/SKILL.md +42 -0
- package/skills/business/user/README.md +6 -0
- package/skills/business/user/hupu-auth-get-user-info/SKILL.md +47 -0
- package/skills/business/user/hupu-game-auth/SKILL.md +46 -0
- package/skills/core/hupu-business/SKILL.md +1 -1
- package/skills/core/hupu-business/references/runtime.md +17 -11
- package/skills/core/shaper-backend/SKILL.md +1 -1
- package/skills/core/shaper-backend/references/database.md +2 -2
- package/skills/core/shaper-backend/references/legacy.md +1 -1
- package/skills/core/shaper-backend/references/node-server.md +29 -20
- package/skills/core/shaper-development/SKILL.md +6 -1
- package/skills/core/shaper-development/references/materials.md +14 -0
- package/skills/core/shaper-development/references/project-setup.md +1 -1
- package/skills/core/shaper-game-development/SKILL.md +16 -9
- package/skills/core/shaper-game-development/references/implementation.md +13 -0
- package/skills/core/shaper-game-development/references/iteration.md +11 -0
- package/skills/core/shaper-game-development/references/playable-loop.md +12 -0
- package/skills/core/shaper-game-development/references/playtest.md +18 -0
- package/skills/core/shaper-game-development/references/sources.md +6 -0
- package/skills/core/shaper-release/SKILL.md +1 -1
- package/templates/cloud-service/README.md +4 -30
- package/templates/cloud-service/cloud.json +5 -8
- package/templates/cloud-service/package-lock.json +922 -15
- package/templates/cloud-service/release.json +4 -4
- package/templates/cloud-service/server.cjs +37 -0
- package/templates/leaderboard/README.md +3 -0
- package/templates/leaderboard/cloud/database/migrations/202611130001_leaderboard.sql +6 -0
- package/templates/leaderboard/cloud/functions/api/cloud.json +10 -0
- package/templates/leaderboard/cloud/functions/api/leaderboard.cjs +49 -0
- package/templates/leaderboard/cloud/functions/api/package-lock.json +1093 -0
- package/templates/leaderboard/cloud/functions/api/package.json +19 -0
- package/templates/leaderboard/cloud/functions/api/server.cjs +25 -0
- package/templates/leaderboard/cloud/gateway/routes.json +15 -0
- package/templates/leaderboard/docs/design.md +1 -0
- package/templates/leaderboard/docs/integration.md +12 -0
- package/templates/leaderboard/docs/product.md +1 -0
- package/templates/leaderboard/docs/validation.md +1 -0
- package/templates/leaderboard/index.html +12 -0
- package/templates/leaderboard/package-lock.json +828 -0
- package/templates/leaderboard/package.json +17 -0
- package/templates/leaderboard/public/.gitkeep +1 -0
- package/templates/leaderboard/shaper.config.json +7 -0
- package/templates/leaderboard/src/main.js +67 -0
- package/templates/leaderboard/src/style.css +69 -0
- package/templates/leaderboard/test/leaderboard.test.cjs +93 -0
- package/templates/offline-game/README.md +3 -0
- package/templates/offline-game/docs/design.md +1 -0
- package/templates/offline-game/docs/integration.md +10 -0
- package/templates/offline-game/docs/product.md +1 -0
- package/templates/offline-game/docs/validation.md +1 -0
- package/templates/offline-game/index.html +12 -0
- package/templates/offline-game/package-lock.json +828 -0
- package/templates/offline-game/package.json +16 -0
- package/templates/offline-game/public/.gitkeep +1 -0
- package/templates/offline-game/shaper.config.json +7 -0
- package/templates/offline-game/src/game.js +42 -0
- package/templates/offline-game/src/main.js +60 -0
- package/templates/offline-game/src/style.css +69 -0
- package/templates/offline-game/test/game.test.js +25 -0
- package/dist/shared-APGA5MU5.js +0 -19
- package/templates/cloud-service/handlers.cjs +0 -46
|
@@ -0,0 +1,729 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<script type="application/json" id="shaper-skill-usage">
|
|
5
|
+
{
|
|
6
|
+
"skills": [
|
|
7
|
+
"hupu-cloud-auth",
|
|
8
|
+
"hupu-cloud-request",
|
|
9
|
+
"hupu-oss-upload-file"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
</script>
|
|
13
|
+
<meta charset="UTF-8" />
|
|
14
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
15
|
+
<title>PK 投票功能</title>
|
|
16
|
+
<style>
|
|
17
|
+
:root {
|
|
18
|
+
color: #3d3d3d;
|
|
19
|
+
background: #f4f7f8;
|
|
20
|
+
font-family:
|
|
21
|
+
"PingFang SC",
|
|
22
|
+
-apple-system,
|
|
23
|
+
BlinkMacSystemFont,
|
|
24
|
+
"Segoe UI",
|
|
25
|
+
Roboto,
|
|
26
|
+
Helvetica,
|
|
27
|
+
Arial,
|
|
28
|
+
sans-serif;
|
|
29
|
+
font-variant-numeric: tabular-nums;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
* {
|
|
33
|
+
box-sizing: border-box;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
body {
|
|
37
|
+
min-width: 320px;
|
|
38
|
+
min-height: 100vh;
|
|
39
|
+
margin: 0;
|
|
40
|
+
background: #f4f7f8;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
button,
|
|
44
|
+
input {
|
|
45
|
+
font: inherit;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
main {
|
|
49
|
+
display: flex;
|
|
50
|
+
width: min(100%, 390px);
|
|
51
|
+
min-height: 100vh;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
padding: 34px 16px 20px;
|
|
54
|
+
margin: 0 auto;
|
|
55
|
+
background: #ffffff;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
header {
|
|
59
|
+
padding-bottom: 14px;
|
|
60
|
+
border-bottom: 1px solid #edf3f4;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
h1 {
|
|
64
|
+
margin: 0;
|
|
65
|
+
color: #1a1f26;
|
|
66
|
+
font-size: 17px;
|
|
67
|
+
font-weight: 600;
|
|
68
|
+
line-height: 1.35;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.description {
|
|
72
|
+
margin: 7px 0 0;
|
|
73
|
+
color: #6f7e8c;
|
|
74
|
+
font-size: 11px;
|
|
75
|
+
line-height: 1.55;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.options {
|
|
79
|
+
display: grid;
|
|
80
|
+
gap: 10px;
|
|
81
|
+
margin-top: 20px;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.option {
|
|
85
|
+
display: grid;
|
|
86
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
87
|
+
min-height: 72px;
|
|
88
|
+
align-items: center;
|
|
89
|
+
gap: 6px 10px;
|
|
90
|
+
padding: 10px 11px;
|
|
91
|
+
color: #3d3d3d;
|
|
92
|
+
text-align: left;
|
|
93
|
+
background: #ffffff;
|
|
94
|
+
border: 1px solid #d8e3e8;
|
|
95
|
+
border-radius: 0;
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.option:hover,
|
|
100
|
+
.option.selected {
|
|
101
|
+
color: #1a1f26;
|
|
102
|
+
background: #f0f7f7;
|
|
103
|
+
border-color: #4a8b8f;
|
|
104
|
+
outline: 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.option:focus-visible {
|
|
108
|
+
outline: 2px solid #4a8b8f;
|
|
109
|
+
outline-offset: 2px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.option:disabled {
|
|
113
|
+
cursor: not-allowed;
|
|
114
|
+
opacity: 0.62;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.candidate {
|
|
118
|
+
display: grid;
|
|
119
|
+
min-width: 0;
|
|
120
|
+
grid-template-columns: auto minmax(0, 1fr);
|
|
121
|
+
align-items: center;
|
|
122
|
+
gap: 8px;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.candidate-image {
|
|
126
|
+
width: 34px;
|
|
127
|
+
height: 34px;
|
|
128
|
+
object-fit: cover;
|
|
129
|
+
background: #edf3f4;
|
|
130
|
+
border-radius: 50%;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.candidate-copy {
|
|
134
|
+
display: grid;
|
|
135
|
+
min-width: 0;
|
|
136
|
+
gap: 2px;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.candidate-name {
|
|
140
|
+
overflow: hidden;
|
|
141
|
+
font-size: 13px;
|
|
142
|
+
font-weight: 600;
|
|
143
|
+
line-height: 1.35;
|
|
144
|
+
text-overflow: ellipsis;
|
|
145
|
+
white-space: nowrap;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.candidate-description {
|
|
149
|
+
overflow: hidden;
|
|
150
|
+
color: #6f7e8c;
|
|
151
|
+
font-size: 10px;
|
|
152
|
+
line-height: 1.4;
|
|
153
|
+
text-overflow: ellipsis;
|
|
154
|
+
white-space: nowrap;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.percentage {
|
|
158
|
+
color: #1a1f26;
|
|
159
|
+
font-size: 13px;
|
|
160
|
+
font-weight: 600;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.bar-track {
|
|
164
|
+
grid-column: 1 / -1;
|
|
165
|
+
height: 4px;
|
|
166
|
+
overflow: hidden;
|
|
167
|
+
background: #edf3f4;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.bar {
|
|
171
|
+
display: block;
|
|
172
|
+
width: 0;
|
|
173
|
+
height: 100%;
|
|
174
|
+
background: #78aeb0;
|
|
175
|
+
transition: width 180ms ease;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.selected .bar {
|
|
179
|
+
background: #4a8b8f;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.option-meta {
|
|
183
|
+
grid-column: 1 / -1;
|
|
184
|
+
color: #8aa0b3;
|
|
185
|
+
font-size: 9px;
|
|
186
|
+
line-height: 1.3;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.total {
|
|
190
|
+
display: flex;
|
|
191
|
+
align-items: center;
|
|
192
|
+
gap: 5px;
|
|
193
|
+
margin-top: 16px;
|
|
194
|
+
color: #6f7e8c;
|
|
195
|
+
font-size: 10px;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.vote-mark {
|
|
199
|
+
width: 8px;
|
|
200
|
+
height: 8px;
|
|
201
|
+
border: 1px solid #4a8b8f;
|
|
202
|
+
border-radius: 50%;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.proof {
|
|
206
|
+
display: grid;
|
|
207
|
+
gap: 7px;
|
|
208
|
+
padding: 16px 0;
|
|
209
|
+
margin-top: 18px;
|
|
210
|
+
border-top: 1px solid #edf3f4;
|
|
211
|
+
border-bottom: 1px solid #edf3f4;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.proof-label {
|
|
215
|
+
color: #3d3d3d;
|
|
216
|
+
font-size: 11px;
|
|
217
|
+
font-weight: 600;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.proof-help,
|
|
221
|
+
.proof-status {
|
|
222
|
+
color: #8aa0b3;
|
|
223
|
+
font-size: 9px;
|
|
224
|
+
line-height: 1.45;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.proof-picker {
|
|
228
|
+
display: inline-flex;
|
|
229
|
+
width: max-content;
|
|
230
|
+
min-height: 30px;
|
|
231
|
+
align-items: center;
|
|
232
|
+
padding: 0 10px;
|
|
233
|
+
color: #356f72;
|
|
234
|
+
font-size: 10px;
|
|
235
|
+
background: #f0f7f7;
|
|
236
|
+
border: 1px solid #b9d4d5;
|
|
237
|
+
cursor: pointer;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.proof-picker:focus-within {
|
|
241
|
+
outline: 2px solid #4a8b8f;
|
|
242
|
+
outline-offset: 2px;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.proof-picker.disabled {
|
|
246
|
+
cursor: not-allowed;
|
|
247
|
+
opacity: 0.58;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.proof-picker input {
|
|
251
|
+
position: absolute;
|
|
252
|
+
width: 1px;
|
|
253
|
+
height: 1px;
|
|
254
|
+
overflow: hidden;
|
|
255
|
+
clip: rect(0 0 0 0);
|
|
256
|
+
clip-path: inset(50%);
|
|
257
|
+
white-space: nowrap;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.selection {
|
|
261
|
+
min-height: 42px;
|
|
262
|
+
padding-top: 22px;
|
|
263
|
+
margin-top: auto;
|
|
264
|
+
color: #6f7e8c;
|
|
265
|
+
font-size: 10px;
|
|
266
|
+
line-height: 1.5;
|
|
267
|
+
text-align: center;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.selection.error {
|
|
271
|
+
color: #b04a43;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
@media (min-width: 480px) {
|
|
275
|
+
body {
|
|
276
|
+
display: grid;
|
|
277
|
+
place-items: center;
|
|
278
|
+
padding: 24px;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
main {
|
|
282
|
+
min-height: 640px;
|
|
283
|
+
border: 1px solid #d8e3e8;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
@media (prefers-reduced-motion: reduce) {
|
|
288
|
+
.bar {
|
|
289
|
+
transition: none;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
</style>
|
|
293
|
+
</head>
|
|
294
|
+
<body>
|
|
295
|
+
<main>
|
|
296
|
+
<header>
|
|
297
|
+
<h1 id="match-title">正在加载投票</h1>
|
|
298
|
+
<p class="description" id="match-description">请稍候...</p>
|
|
299
|
+
</header>
|
|
300
|
+
|
|
301
|
+
<section class="options" aria-label="投票选项">
|
|
302
|
+
<button class="option" data-side="left" type="button" disabled>
|
|
303
|
+
<span class="candidate">
|
|
304
|
+
<img class="candidate-image" alt="" hidden />
|
|
305
|
+
<span class="candidate-copy">
|
|
306
|
+
<span class="candidate-name">左侧选项</span>
|
|
307
|
+
<span class="candidate-description"></span>
|
|
308
|
+
</span>
|
|
309
|
+
</span>
|
|
310
|
+
<strong class="percentage">--</strong>
|
|
311
|
+
<span class="bar-track" aria-hidden="true"><i class="bar"></i></span>
|
|
312
|
+
<span class="option-meta">-- 票</span>
|
|
313
|
+
</button>
|
|
314
|
+
|
|
315
|
+
<button class="option" data-side="right" type="button" disabled>
|
|
316
|
+
<span class="candidate">
|
|
317
|
+
<img class="candidate-image" alt="" hidden />
|
|
318
|
+
<span class="candidate-copy">
|
|
319
|
+
<span class="candidate-name">右侧选项</span>
|
|
320
|
+
<span class="candidate-description"></span>
|
|
321
|
+
</span>
|
|
322
|
+
</span>
|
|
323
|
+
<strong class="percentage">--</strong>
|
|
324
|
+
<span class="bar-track" aria-hidden="true"><i class="bar"></i></span>
|
|
325
|
+
<span class="option-meta">-- 票</span>
|
|
326
|
+
</button>
|
|
327
|
+
</section>
|
|
328
|
+
|
|
329
|
+
<div class="total" aria-live="polite">
|
|
330
|
+
<span class="vote-mark" aria-hidden="true"></span>
|
|
331
|
+
<span id="total-votes">正在读取参与人数</span>
|
|
332
|
+
</div>
|
|
333
|
+
|
|
334
|
+
<section class="proof" aria-label="应援图">
|
|
335
|
+
<span class="proof-label">应援图(可选)</span>
|
|
336
|
+
<span class="proof-help">选择图片后先上传,单张不超过 10 MB;上传成功再点击选项投票。</span>
|
|
337
|
+
<label class="proof-picker" id="proof-picker">
|
|
338
|
+
选择图片
|
|
339
|
+
<input id="proof-file" type="file" accept="image/*" />
|
|
340
|
+
</label>
|
|
341
|
+
<span class="proof-status" id="proof-status" aria-live="polite">未添加图片</span>
|
|
342
|
+
</section>
|
|
343
|
+
|
|
344
|
+
<div class="selection" id="selection" role="status" aria-live="polite">正在加载投票...</div>
|
|
345
|
+
</main>
|
|
346
|
+
|
|
347
|
+
<script>
|
|
348
|
+
window.ACTIVITY_API_BASE = "";
|
|
349
|
+
window.ACTIVITY_ENV_ID = "";
|
|
350
|
+
window.PK_MATCH_ID = "plan-final";
|
|
351
|
+
|
|
352
|
+
const DEMO_MATCH = {
|
|
353
|
+
id: "plan-final",
|
|
354
|
+
title: "你更支持哪一个方案?",
|
|
355
|
+
description: "每个账号限投 1 票,本地预览的投票不会提交到服务器。",
|
|
356
|
+
startsAt: new Date(Date.now() - 86400000).toISOString(),
|
|
357
|
+
endsAt: new Date(Date.now() + 30 * 86400000).toISOString(),
|
|
358
|
+
status: "live",
|
|
359
|
+
candidates: [
|
|
360
|
+
{ side: "left", name: "方案 A", description: "稳健推进,优先保证核心体验。", imageUrl: null, voteCount: 74 },
|
|
361
|
+
{ side: "right", name: "方案 B", description: "快速突破,优先验证创新方向。", imageUrl: null, voteCount: 54 }
|
|
362
|
+
]
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const state = {
|
|
366
|
+
match: null,
|
|
367
|
+
results: null,
|
|
368
|
+
me: null,
|
|
369
|
+
proofUrl: null,
|
|
370
|
+
busy: false,
|
|
371
|
+
uploading: false,
|
|
372
|
+
authenticated: false,
|
|
373
|
+
demo: false
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
const titleNode = document.getElementById("match-title");
|
|
377
|
+
const descriptionNode = document.getElementById("match-description");
|
|
378
|
+
const totalNode = document.getElementById("total-votes");
|
|
379
|
+
const selectionNode = document.getElementById("selection");
|
|
380
|
+
const proofInput = document.getElementById("proof-file");
|
|
381
|
+
const proofPicker = document.getElementById("proof-picker");
|
|
382
|
+
const proofStatus = document.getElementById("proof-status");
|
|
383
|
+
const optionButtons = Array.from(document.querySelectorAll(".option"));
|
|
384
|
+
|
|
385
|
+
function apiBase() {
|
|
386
|
+
return String(window.ACTIVITY_API_BASE || "").trim().replace(/\/$/, "");
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function matchId() {
|
|
390
|
+
return String(window.PK_MATCH_ID || "").trim();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function isHttpsUrl(value) {
|
|
394
|
+
try {
|
|
395
|
+
const url = new URL(value);
|
|
396
|
+
return url.protocol === "https:" && Boolean(url.hostname) && !url.username && !url.password;
|
|
397
|
+
} catch (error) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function setSelection(message, isError) {
|
|
403
|
+
selectionNode.textContent = message;
|
|
404
|
+
selectionNode.classList.toggle("error", Boolean(isError));
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function createRequestError(response, fallback) {
|
|
408
|
+
const error = new Error(response && response.message ? response.message : fallback);
|
|
409
|
+
error.statusCode = Number(response && response.statusCode) || 500;
|
|
410
|
+
error.code = response && response.code;
|
|
411
|
+
return error;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function friendlyMessage(error, fallback) {
|
|
415
|
+
if (error && error.statusCode === 401) return "请先登录虎扑账号后再投票";
|
|
416
|
+
if (error && error.statusCode === 429) return "操作太频繁,请稍后再试";
|
|
417
|
+
if (error && error.statusCode >= 500) return "服务暂时不可用,请稍后重试";
|
|
418
|
+
return (error && error.message) || fallback;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
async function cloudRequest(path, options) {
|
|
422
|
+
const sdk = window.ShaperAI && window.ShaperAI.cloud;
|
|
423
|
+
if (!sdk || typeof sdk.request !== "function") {
|
|
424
|
+
throw new Error("当前环境缺少 ShaperAI Cloud 请求能力");
|
|
425
|
+
}
|
|
426
|
+
const config = options || {};
|
|
427
|
+
const params = {
|
|
428
|
+
url: apiBase() + path,
|
|
429
|
+
method: config.method || "GET"
|
|
430
|
+
};
|
|
431
|
+
if (config.data !== undefined) params.data = config.data;
|
|
432
|
+
if (config.auth) {
|
|
433
|
+
params.auth = true;
|
|
434
|
+
params.envId = String(window.ACTIVITY_ENV_ID || "").trim();
|
|
435
|
+
}
|
|
436
|
+
const response = await sdk.request(params);
|
|
437
|
+
const statusCode = Number(response && response.statusCode);
|
|
438
|
+
const businessCode = response && response.code;
|
|
439
|
+
const statusOk = statusCode >= 200 && statusCode < 300;
|
|
440
|
+
const codeOk = businessCode === 0 || businessCode === 200;
|
|
441
|
+
if (!statusOk || !codeOk) throw createRequestError(response, "请求失败");
|
|
442
|
+
return response.data;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function resultForSide(side) {
|
|
446
|
+
const items = state.results && Array.isArray(state.results.candidates)
|
|
447
|
+
? state.results.candidates
|
|
448
|
+
: [];
|
|
449
|
+
return items.find((item) => item.side === side) || { side, voteCount: 0, percentage: 0 };
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function candidateForSide(side) {
|
|
453
|
+
const candidates = state.match && Array.isArray(state.match.candidates)
|
|
454
|
+
? state.match.candidates
|
|
455
|
+
: [];
|
|
456
|
+
return candidates.find((candidate) => candidate.side === side) || null;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function lifecycleMessage() {
|
|
460
|
+
if (!state.match) return "正在加载投票...";
|
|
461
|
+
if (state.match.status === "scheduled") {
|
|
462
|
+
return "投票尚未开始,开始时间:" + new Date(state.match.startsAt).toLocaleString("zh-CN");
|
|
463
|
+
}
|
|
464
|
+
if (state.match.status === "ended") return "投票已经结束,当前展示最终结果";
|
|
465
|
+
if (state.me && state.me.voted) {
|
|
466
|
+
const candidate = candidateForSide(state.me.side);
|
|
467
|
+
return "你已选择" + (candidate ? candidate.name : "该选项");
|
|
468
|
+
}
|
|
469
|
+
if (state.demo) return "本地演示模式:点击选项模拟投票";
|
|
470
|
+
if (!state.authenticated) return "登录后点击选项完成投票";
|
|
471
|
+
return "点击选项完成投票";
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function render() {
|
|
475
|
+
if (!state.match) return;
|
|
476
|
+
titleNode.textContent = state.match.title || "PK 投票";
|
|
477
|
+
descriptionNode.textContent = state.match.description || "每个登录账号限投 1 票";
|
|
478
|
+
|
|
479
|
+
optionButtons.forEach((button) => {
|
|
480
|
+
const side = button.dataset.side;
|
|
481
|
+
const candidate = candidateForSide(side);
|
|
482
|
+
const result = resultForSide(side);
|
|
483
|
+
const selected = Boolean(state.me && state.me.voted && state.me.side === side);
|
|
484
|
+
const image = button.querySelector(".candidate-image");
|
|
485
|
+
|
|
486
|
+
button.querySelector(".candidate-name").textContent = candidate ? candidate.name : "选项未配置";
|
|
487
|
+
button.querySelector(".candidate-description").textContent = candidate ? candidate.description || "" : "";
|
|
488
|
+
button.querySelector(".percentage").textContent = Number(result.percentage || 0).toLocaleString("zh-CN", { maximumFractionDigits: 1 }) + "%";
|
|
489
|
+
button.querySelector(".option-meta").textContent = Number(result.voteCount || 0).toLocaleString("zh-CN") + " 票";
|
|
490
|
+
button.querySelector(".bar").style.width = Math.max(0, Math.min(100, Number(result.percentage || 0))) + "%";
|
|
491
|
+
button.classList.toggle("selected", selected);
|
|
492
|
+
button.setAttribute("aria-pressed", selected ? "true" : "false");
|
|
493
|
+
|
|
494
|
+
if (candidate && isHttpsUrl(candidate.imageUrl)) {
|
|
495
|
+
image.src = candidate.imageUrl;
|
|
496
|
+
image.alt = candidate.name || "候选项图片";
|
|
497
|
+
image.hidden = false;
|
|
498
|
+
} else {
|
|
499
|
+
image.removeAttribute("src");
|
|
500
|
+
image.alt = "";
|
|
501
|
+
image.hidden = true;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const unavailable = !candidate || state.busy || state.uploading || state.match.status !== "live" || Boolean(state.me && state.me.voted);
|
|
505
|
+
button.disabled = unavailable;
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
const totalVotes = Number(state.results && state.results.totalVotes || 0);
|
|
509
|
+
totalNode.textContent = "已有 " + totalVotes.toLocaleString("zh-CN") + " 人参与";
|
|
510
|
+
proofInput.disabled = state.busy || state.uploading || Boolean(state.me && state.me.voted);
|
|
511
|
+
proofPicker.classList.toggle("disabled", proofInput.disabled);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function resultsFromMatch(match) {
|
|
515
|
+
const candidates = Array.isArray(match.candidates) ? match.candidates : [];
|
|
516
|
+
const totalVotes = candidates.reduce((sum, item) => sum + Number(item.voteCount || 0), 0);
|
|
517
|
+
return {
|
|
518
|
+
totalVotes,
|
|
519
|
+
candidates: candidates.map((item) => ({
|
|
520
|
+
side: item.side,
|
|
521
|
+
voteCount: Number(item.voteCount || 0),
|
|
522
|
+
percentage: totalVotes ? Math.round((Number(item.voteCount || 0) / totalVotes) * 1000) / 10 : 0
|
|
523
|
+
}))
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
async function ensureAuthenticated() {
|
|
528
|
+
if (state.authenticated) return;
|
|
529
|
+
const sdk = window.ShaperAI && window.ShaperAI.cloud;
|
|
530
|
+
if (!sdk || typeof sdk.auth !== "function") {
|
|
531
|
+
const error = new Error("当前环境缺少 ShaperAI 登录能力");
|
|
532
|
+
error.statusCode = 401;
|
|
533
|
+
throw error;
|
|
534
|
+
}
|
|
535
|
+
const auth = await sdk.auth({ envId: String(window.ACTIVITY_ENV_ID || "").trim() });
|
|
536
|
+
if (!auth || auth.code !== 200) {
|
|
537
|
+
const error = new Error(auth && auth.message ? auth.message : "请先登录");
|
|
538
|
+
error.statusCode = auth && auth.code === 401 ? 401 : 500;
|
|
539
|
+
throw error;
|
|
540
|
+
}
|
|
541
|
+
state.authenticated = true;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
async function loadViewer(options) {
|
|
545
|
+
const config = options || {};
|
|
546
|
+
try {
|
|
547
|
+
if (config.authenticate !== false) await ensureAuthenticated();
|
|
548
|
+
state.me = await cloudRequest("/pk/me?matchId=" + encodeURIComponent(matchId()), { auth: true });
|
|
549
|
+
state.authenticated = true;
|
|
550
|
+
return true;
|
|
551
|
+
} catch (error) {
|
|
552
|
+
if (error.statusCode === 401) {
|
|
553
|
+
state.authenticated = false;
|
|
554
|
+
state.me = { voted: false, side: null, remaining: 1 };
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
throw error;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
async function loadResults() {
|
|
562
|
+
state.results = await cloudRequest(
|
|
563
|
+
"/pk/matches/" + encodeURIComponent(matchId()) + "/results"
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function simulateVote(side) {
|
|
568
|
+
const result = resultForSide(side);
|
|
569
|
+
result.voteCount = Number(result.voteCount || 0) + 1;
|
|
570
|
+
state.results.totalVotes = Number(state.results.totalVotes || 0) + 1;
|
|
571
|
+
state.results.candidates.forEach((item) => {
|
|
572
|
+
item.percentage = state.results.totalVotes
|
|
573
|
+
? Math.round((Number(item.voteCount || 0) / state.results.totalVotes) * 1000) / 10
|
|
574
|
+
: 0;
|
|
575
|
+
});
|
|
576
|
+
state.me = { voted: true, side, remaining: 0 };
|
|
577
|
+
render();
|
|
578
|
+
setSelection(lifecycleMessage(), false);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
async function vote(side) {
|
|
582
|
+
if (state.busy || state.uploading || !state.match || state.match.status !== "live") return;
|
|
583
|
+
if (state.me && state.me.voted) {
|
|
584
|
+
setSelection("每个账号只能投 1 票", true);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
if (state.demo) {
|
|
588
|
+
simulateVote(side);
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
state.busy = true;
|
|
593
|
+
render();
|
|
594
|
+
setSelection("正在提交投票...", false);
|
|
595
|
+
try {
|
|
596
|
+
await ensureAuthenticated();
|
|
597
|
+
const payload = { matchId: matchId(), side };
|
|
598
|
+
if (state.proofUrl) payload.proofUrl = state.proofUrl;
|
|
599
|
+
const submitted = await cloudRequest("/pk/votes", { method: "POST", data: payload, auth: true });
|
|
600
|
+
state.me = {
|
|
601
|
+
voted: true,
|
|
602
|
+
side: submitted && submitted.side ? submitted.side : side,
|
|
603
|
+
remaining: 0
|
|
604
|
+
};
|
|
605
|
+
render();
|
|
606
|
+
try {
|
|
607
|
+
await Promise.all([loadResults(), loadViewer({ authenticate: false })]);
|
|
608
|
+
} catch (refreshError) {
|
|
609
|
+
setSelection("投票已提交,最新票数暂未刷新,请稍后重新打开页面", true);
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
setSelection(lifecycleMessage(), false);
|
|
613
|
+
} catch (error) {
|
|
614
|
+
if (error.statusCode === 409) {
|
|
615
|
+
try {
|
|
616
|
+
await loadViewer({ authenticate: false });
|
|
617
|
+
await loadResults();
|
|
618
|
+
} catch (refreshError) {
|
|
619
|
+
/* Keep the original actionable conflict message. */
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
setSelection(friendlyMessage(error, "投票失败,请重试"), true);
|
|
623
|
+
} finally {
|
|
624
|
+
state.busy = false;
|
|
625
|
+
render();
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
async function uploadProof(file) {
|
|
630
|
+
if (!file) return;
|
|
631
|
+
if (!file.type || !file.type.startsWith("image/")) {
|
|
632
|
+
proofStatus.textContent = "请选择图片文件";
|
|
633
|
+
proofInput.value = "";
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
if (file.size > 10 * 1024 * 1024) {
|
|
637
|
+
proofStatus.textContent = "图片不能超过 10 MB";
|
|
638
|
+
proofInput.value = "";
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
if (state.demo) {
|
|
642
|
+
proofStatus.textContent = "本地预览不上传图片,请在虎扑 App 内验证";
|
|
643
|
+
proofInput.value = "";
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
const upload = window.ShaperAI && window.ShaperAI.oss && window.ShaperAI.oss.uploadFile;
|
|
648
|
+
if (typeof upload !== "function") {
|
|
649
|
+
proofStatus.textContent = "当前环境不支持图片上传";
|
|
650
|
+
proofInput.value = "";
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
state.uploading = true;
|
|
655
|
+
render();
|
|
656
|
+
proofStatus.textContent = "正在上传图片...";
|
|
657
|
+
try {
|
|
658
|
+
const extension = file.name && file.name.includes(".") ? file.name.slice(file.name.lastIndexOf(".")).slice(0, 10) : ".jpg";
|
|
659
|
+
const result = await upload({ file, filename: "pk-vote-proof-" + Date.now() + extension });
|
|
660
|
+
if (!result || !isHttpsUrl(result.downloadUrl)) throw new Error("上传结果缺少有效图片地址");
|
|
661
|
+
state.proofUrl = result.downloadUrl;
|
|
662
|
+
proofStatus.textContent = "图片上传成功,将随投票一并提交";
|
|
663
|
+
} catch (error) {
|
|
664
|
+
state.proofUrl = null;
|
|
665
|
+
proofStatus.textContent = (error && error.message) || "图片上传失败,请重新选择";
|
|
666
|
+
proofInput.value = "";
|
|
667
|
+
} finally {
|
|
668
|
+
state.uploading = false;
|
|
669
|
+
render();
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
async function initialize() {
|
|
674
|
+
state.demo = window.location.protocol === "file:"
|
|
675
|
+
|| window.location.hostname === "localhost"
|
|
676
|
+
|| window.location.hostname === "127.0.0.1";
|
|
677
|
+
try {
|
|
678
|
+
if (state.demo) {
|
|
679
|
+
state.match = typeof structuredClone === "function"
|
|
680
|
+
? structuredClone(DEMO_MATCH)
|
|
681
|
+
: JSON.parse(JSON.stringify(DEMO_MATCH));
|
|
682
|
+
state.results = resultsFromMatch(state.match);
|
|
683
|
+
state.me = { voted: false, side: null, remaining: 1 };
|
|
684
|
+
render();
|
|
685
|
+
setSelection(lifecycleMessage(), false);
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
if (!apiBase() || !window.ACTIVITY_ENV_ID || !matchId()) {
|
|
690
|
+
throw new Error("投票服务尚未配置,请设置 API 地址、环境 ID 和对阵 ID");
|
|
691
|
+
}
|
|
692
|
+
if (!window.ShaperAI || !window.ShaperAI.cloud) {
|
|
693
|
+
throw new Error("当前环境缺少 ShaperAI Cloud 能力");
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
const data = await cloudRequest("/pk/matches/" + encodeURIComponent(matchId()));
|
|
697
|
+
if (!data || !data.match || !Array.isArray(data.match.candidates)) {
|
|
698
|
+
throw new Error("对阵数据格式不正确");
|
|
699
|
+
}
|
|
700
|
+
state.match = data.match;
|
|
701
|
+
state.results = resultsFromMatch(state.match);
|
|
702
|
+
render();
|
|
703
|
+
|
|
704
|
+
try {
|
|
705
|
+
await loadViewer();
|
|
706
|
+
} catch (error) {
|
|
707
|
+
setSelection(friendlyMessage(error, "用户状态读取失败"), true);
|
|
708
|
+
render();
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
render();
|
|
712
|
+
setSelection(lifecycleMessage(), false);
|
|
713
|
+
} catch (error) {
|
|
714
|
+
titleNode.textContent = "投票暂不可用";
|
|
715
|
+
descriptionNode.textContent = "请稍后重试或联系活动运营人员";
|
|
716
|
+
totalNode.textContent = "未能读取投票数据";
|
|
717
|
+
setSelection(friendlyMessage(error, "投票加载失败"), true);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
optionButtons.forEach((button) => {
|
|
722
|
+
button.addEventListener("click", () => vote(button.dataset.side));
|
|
723
|
+
});
|
|
724
|
+
proofInput.addEventListener("change", () => uploadProof(proofInput.files && proofInput.files[0]));
|
|
725
|
+
|
|
726
|
+
initialize();
|
|
727
|
+
</script>
|
|
728
|
+
</body>
|
|
729
|
+
</html>
|