@polyv/vote-sdk 2.0.0

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/index.es.d.ts ADDED
@@ -0,0 +1,267 @@
1
+ import { EventEmitter } from '@polyv/utils/es/event';
2
+ import { InteractionCore } from '@polyv/interaction-core';
3
+
4
+ declare class InteractionBase {
5
+ /**
6
+ * @deprecated 兼容旧版具备 __iarCore 属性,后续将移除
7
+ */
8
+ public __iarCore: InteractionCore;
9
+
10
+ /**
11
+ * @deprecated 兼容旧版具备 iarCore 属性,后续将移除
12
+ */
13
+ public iarCore: InteractionCore;
14
+
15
+ constructor(public interactionCore: InteractionCore) {
16
+ this.__iarCore = interactionCore;
17
+ this.iarCore = interactionCore;
18
+ }
19
+ }
20
+
21
+ export declare class Vote extends InteractionBase {
22
+ static appName: string;
23
+ VoteEvent: typeof VoteEvent;
24
+ eventEmitter: EventEmitter<VoteEventRelations, VoteEvent>;
25
+ /** 当前已投票列表 */
26
+ private __curVotedList;
27
+ /** 当前在进行的投票活动 */
28
+ private __votingList;
29
+ /** 缓存的投票结果数据 */
30
+ private __cachedVoteResult;
31
+ constructor(interactionCore: InteractionCore);
32
+ /**
33
+ * 处理socket缓存
34
+ */
35
+ private __processSocketCache;
36
+ /**
37
+ * 处理初始化消息中的投票信息
38
+ */
39
+ private __onSliceID;
40
+ /**
41
+ * 处理投票开始事件
42
+ */
43
+ private __onVoteStart;
44
+ /**
45
+ * 处理投票结束事件
46
+ */
47
+ private __onVoteStop;
48
+ /**
49
+ * 处理投票结果事件
50
+ */
51
+ private __onVoteResult;
52
+ /**
53
+ * 处理清空投票事件
54
+ */
55
+ private __onVoteDeleteAll;
56
+ /**
57
+ * 处理删除投票事件
58
+ */
59
+ private __onVoteDelete;
60
+ /**
61
+ * 处理更改投票顺序事件
62
+ */
63
+ private __onVoteChangeOrder;
64
+ /**
65
+ * 给选项投票
66
+ * @param id 投票ID
67
+ * @returns {Promise<VoteResponse>} 投票结果
68
+ * @example
69
+ * ```ts
70
+ * const res = await voteTarget.toVote('voteId');
71
+ * console.log('投票结果', res);
72
+ * ```
73
+ */
74
+ toVote(id: string): Promise<VoteResponse>;
75
+ /**
76
+ * 获取已投票列表
77
+ * @returns {string[]} 已投票 id 列表
78
+ * @example
79
+ * ```ts
80
+ * const list = voteTarget.getVotedList();
81
+ * console.log('已投票列表', list);
82
+ * ```
83
+ */
84
+ getVotedList(): string[];
85
+ /**
86
+ * 新增已投票的id
87
+ * @param id 投票 id
88
+ * @returns {void} 无返回值
89
+ * @example
90
+ * ```ts
91
+ * voteTarget.pushVotedList('voteId');
92
+ * ```
93
+ */
94
+ pushVotedList(id: string): void;
95
+ /**
96
+ * 获取投票选项列表
97
+ * @returns {Promise<VoteListResponse | undefined>} 投票列表
98
+ * @example
99
+ * ```ts
100
+ * const data = await voteTarget.getVoteList();
101
+ * console.log('投票列表', data);
102
+ * ```
103
+ */
104
+ getVoteList(): Promise<VoteListResponse | undefined>;
105
+ /**
106
+ * 应用投票结果到投票列表
107
+ */
108
+ private __applyVoteResult;
109
+ /**
110
+ * 获取缓存的投票结果
111
+ * @returns {VoteResultSocketData['list'] | null} 缓存投票结果
112
+ * @example
113
+ * ```ts
114
+ * const result = voteTarget.getCachedVoteResult();
115
+ * console.log('缓存结果', result);
116
+ * ```
117
+ */
118
+ getCachedVoteResult(): VoteResultSocketData['list'] | null;
119
+ /**
120
+ * 获取当前投票列表
121
+ * @returns {Record<string, VoteListItem>} 当前投票列表
122
+ * @example
123
+ * ```ts
124
+ * const list = voteTarget.getVotingList();
125
+ * console.log('当前投票列表', list);
126
+ * ```
127
+ */
128
+ getVotingList(): Record<string, VoteListItem>;
129
+ }
130
+
131
+ /**
132
+ * 投票数据
133
+ */
134
+ export declare interface VoteData extends VoteListItem {
135
+ coverUrl?: string;
136
+ }
137
+
138
+ export declare enum VoteEvent {
139
+ /**
140
+ * 更新已投票列表
141
+ */
142
+ UpdateVotedList = "UpdateVotedList",
143
+ /**
144
+ * 发起投票
145
+ */
146
+ Start = "Start",
147
+ /**
148
+ * 结束投票
149
+ */
150
+ Stop = "Stop",
151
+ /**
152
+ * 投票结果
153
+ */
154
+ VoteResult = "VoteResult",
155
+ /**
156
+ * 清空投票
157
+ */
158
+ DeleteAll = "DeleteAll",
159
+ /**
160
+ * 删除投票
161
+ */
162
+ Delete = "Delete",
163
+ /**
164
+ * 更改投票顺序
165
+ */
166
+ UpdateVoteOrder = "UpdateVoteOrder"
167
+ }
168
+
169
+ export declare type VoteEventRelations = {
170
+ [VoteEvent.UpdateVotedList]: {
171
+ /** 已投票列表 */
172
+ curVotedList: string[];
173
+ };
174
+ [VoteEvent.Start]: {
175
+ /** 投票数据 */
176
+ voteData: VoteData;
177
+ };
178
+ [VoteEvent.Stop]: {
179
+ /** 投票ID */
180
+ id: string;
181
+ };
182
+ [VoteEvent.VoteResult]: {
183
+ /** 投票人数 */
184
+ voteCount: number;
185
+ /** 投票结果列表 */
186
+ list: VoteResultItem[];
187
+ };
188
+ [VoteEvent.DeleteAll]: null;
189
+ [VoteEvent.Delete]: {
190
+ /** 投票ID */
191
+ id: string;
192
+ };
193
+ [VoteEvent.UpdateVoteOrder]: {
194
+ /** 投票ID */
195
+ id: string;
196
+ /** 旧顺序 */
197
+ oldOrder: number;
198
+ /** 新顺序 */
199
+ newOrder: number;
200
+ };
201
+ };
202
+
203
+ /**
204
+ * 投票列表项
205
+ */
206
+ export declare interface VoteListItem {
207
+ /** 投票ID */
208
+ id: string;
209
+ /** 投票名称 */
210
+ name: string;
211
+ /** 选项状态,Y表示在投票中,N表示投票已结束 */
212
+ status?: 'Y' | 'N';
213
+ /** 是否展示票数 */
214
+ showVoteCount?: boolean;
215
+ /** 票数 */
216
+ voteCount?: number;
217
+ /** 图片 */
218
+ voteCoverImage?: string;
219
+ /** 顺序 */
220
+ voteOrder?: number;
221
+ }
222
+
223
+ /**
224
+ * 投票列表接口返回数据
225
+ */
226
+ export declare interface VoteListResponse {
227
+ code: number;
228
+ data: {
229
+ list: VoteListItem[];
230
+ } | null;
231
+ message?: string;
232
+ }
233
+
234
+ /**
235
+ * 投票响应
236
+ */
237
+ export declare interface VoteResponse {
238
+ code: number;
239
+ message?: string;
240
+ }
241
+
242
+ /**
243
+ * 每项投票的结果
244
+ */
245
+ export declare interface VoteResultItem {
246
+ /** 投票ID */
247
+ id: string;
248
+ /** 投票名称 */
249
+ name: string;
250
+ /** 投票的数量 */
251
+ times: number;
252
+ }
253
+
254
+ /**
255
+ * 投票结果socket数据
256
+ */
257
+ declare interface VoteResultSocketData {
258
+ EVENT: 'VOTE_RESULT';
259
+ voteCount: number;
260
+ list: Array<{
261
+ id: string;
262
+ name: string;
263
+ times: number;
264
+ }>;
265
+ }
266
+
267
+ export { }