index.ts
10.0 KB
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
import { createStore } from 'vuex';
import { default as moment } from 'moment';
import { default as _ } from 'lodash';
import * as user_api from '@/api/user_api';
import { nm_live_message, updateLiveDate } from './ws_live/index';
import createPersistedState from 'vuex-persistedstate';
const store = createStore({
state: {
// 初始化
init: false,
// 列表
live_path: '', //默认初始化列表路径
updateListTime: null, // 列表更新时间
match_list_all_cache: [], // 全部缓存
match_list_all: [], // 全部
match_list_fixture: [], // 赛程
match_list_result: [], // 赛果
match_list_attention: {}, // 关注
attention_id_list: [], // 关注id合集
// 实时
updateWsTime: null, // ws更新时间
nm_live_message: {}, // 即时比分
nm_live_message_cache: {}, // 即时比分缓存
nm_game_message_cache: {}, // 比赛信息缓存
live_timer_switch: false, // 定时器开关
high_light: { score: {}, red: {}, yellow: {} }, // 高亮
// 时间
difference_time_switch: false, // 定时器开关
difference_time: null, // 服务器和客户端时间差
server_time: moment().valueOf(), // 服务器时间
// 设置
set_config: { switch: true, goal: true, red: true, yellow: true, type: 'all' },
// 用户|共用信息
userInfo: {},
common_data: {
isPc: false,
isAndroid: false,
isIos: false,
isApp: false,
isWeChat: false,
isLocalTest: false,
switchState: false,
isQianHai: false,
appHeight: 0,
},
//app调用返回开关
app_is_back: false,
//指数 亚盘 欧赔 总进球 角球 我的定制
my_asia: [],
my_euro: [],
my_bs: [],
my_cr: [],
// 比赛详情头部数据和专家数据
match_detail: {},
// 缓存数据
game_info_cache: {},
game_detail_cache: {},
},
mutations: {
// 初始化
updateInit (state, init) {
state.init = init;
},
// 列表
updateUpdateListTime (state, updateListTime) {
state.updateListTime = updateListTime;
},
updateMatchListAllCache (state, match_list_all_cache) {
state.match_list_all_cache = match_list_all_cache;
},
updateMatchListAll (state, match_list_all) {
state.match_list_all = match_list_all;
},
updateMatchListFixture (state, match_list_fixture) {
state.match_list_fixture = match_list_fixture;
},
updateMatchListResult (state, match_list_result) {
state.match_list_result = match_list_result;
},
updateMatchListAttention (state: any, match_list_attention) {
state.match_list_attention = match_list_attention;
let arr = [];
for (let i = 0; i < Object.keys(match_list_attention).length; i++) {
let key = Object.keys(match_list_attention)[i];
let list = match_list_attention[key];
for (let y = 0; y < list.length; y++) {
arr.push(list[y].id);
}
}
state.attention_id_list = arr;
},
// 实时
updateUpdateWsTime (state, updateWsTime) {
state.updateWsTime = updateWsTime;
},
updateLiveTimerSwitch (state, live_timer_switch) {
state.live_timer_switch = live_timer_switch;
},
updateNmLiveMessage (state, nm_live_message) {
state.nm_live_message = nm_live_message;
},
updateNmGameMessageCache (state, nm_game_message_cache) {
state.nm_game_message_cache = nm_game_message_cache;
},
updateNmLiveMessageCache (state, nm_live_message_cache) {
state.nm_live_message_cache = nm_live_message_cache;
},
updateHighLight (state, high_light) {
state.high_light = high_light;
},
// 时间
updateDifferenceTimeSwitch (state, difference_time_switch) {
state.difference_time_switch = difference_time_switch;
},
updateDifferenceTime (state, difference_time) {
state.difference_time = difference_time;
},
updateServerTime (state, server_time) {
state.server_time = server_time;
},
updateSetConfig (state, set_config) {
state.set_config = set_config;
},
// 用户|共用信息
get_common_data (state) {
const ua = window.navigator.userAgent;
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua);
const isAndroid = ua.indexOf('Android') > -1 || ua.indexOf('android') > -1;
const isIos = !!ua.match(/ipad|iphone|ios/) || (window as any).ios?.navBarHeight;
const isPc = !isMobile;
const isApp = ua.indexOf('app_ydniu') > 0 || ua.search('app_ydniu') > 0 || /(app_ydniu)/i.test(ua);
const isWeChat = /MicroMessenger/i.test(ua);
const isLocalTest = location.origin.indexOf('http://localhost') > -1 || location.origin.indexOf('192.168') > -1 || location.origin.indexOf('https://app-test.ydniu.com') > -1;
const isQianHai = location.origin.indexOf('m.ydn.com') > -1 || isLocalTest;
// const switchState = location.origin.indexOf('app.ydniu.com') > -1 || isLocalTest;
const switchState = true;
let appHeight = 0;
if (isApp) {
appHeight = 30;
if (isAndroid && (window as any).Android?.getStatusBarHeight) {
appHeight = (window as any).Android.getStatusBarHeight() || 30;
}
if (isIos && (window as any).ios?.navBarHeight) {
appHeight = (window as any).ios?.navBarHeight || 30;
}
//一定牛中目前吴良建没有提供此方法,下面默认给35
if(!(typeof appHeight === 'number') || (typeof appHeight === 'number' && appHeight <= 30)){
appHeight = 35;
}
}
state.common_data = {
isAndroid: isAndroid,
isIos: isIos,
isPc: isPc,
isApp: isApp,
isWeChat: isWeChat,
switchState: switchState,
isLocalTest: isLocalTest,
isQianHai: isQianHai,
appHeight: appHeight
};
},
updateAppHeight (state, appHeight) {
state.common_data.appHeight = appHeight;
},
updateUserInfo (state, user) {
state.userInfo = user;
},
updateLivePath (state, path) {
state.live_path = path;
},
updateMyAsia (state, asia) {
state.my_asia = asia;
},
updateMyEuro (state, euro) {
state.my_euro = euro;
},
updateMyBs (state, bs) {
state.my_bs = bs;
},
updateMyCr (state, cr) {
state.my_cr = cr;
},
updateAppIsBack (state, is_back) {
state.app_is_back = is_back;
},
updateMatchDetail (state, match_detail) {
state.match_detail = match_detail;
},
updateGameInfoCache (state, game_info_cache) {
state.game_info_cache = game_info_cache;
},
updateGameDetailCache (state, game_detail_cache) {
state.game_detail_cache = game_detail_cache;
}
},
actions: {
// 发起异步请求获取用户信息
async fetchUserInfo (context) {
const result: any = await user_api.user_login_state({});
if (result.res_code && result.res_code == 1) {
const user_data: any = await user_api.get_logined_virtual_account();
if (user_data.Error != "未登录" && user_data.Result != null) {
context.commit('updateUserInfo', user_data.Result);
} else {
context.commit('updateUserInfo', {});
context.commit('updateMatchListAttention', {});
}
} else {
context.commit('updateUserInfo', {});
context.commit('updateMatchListAttention', {});
}
},
// 发起异步请求即时比分数据
async asyncNmLiveMessage (context: any) {
try {
await updateLiveDate(context);
nm_live_message(context);
} catch (error) {
console.log(error);
}
},
// 异步处理高亮数据
async asyncHighLight (context: any) {
let timer: any = setInterval(() => {
if (!context.state.live_timer_switch) {
clearInterval(timer);
timer = null;
return;
}
let is_update = false;
let highLight = _.clone(context.state.high_light);
let typeArr = ['score', 'red', 'yellow'];
for (let index = 0; index < typeArr.length; index++) {
let type = typeArr[index];
for (let i = 0; i < Object.keys(highLight[type]).length; i++) {
let key = Object.keys(highLight[type])[i];
let item = highLight[type][key];
if (moment(item.time).add(5, 'seconds').valueOf() <= context.state.server_time) {
is_update = true;
delete highLight[type][key];
}
}
}
if (is_update) context.commit('updateHighLight', highLight);
}, 1000);
},
// 异步处理服务器时间
async asyncServerTime (context: any) {
(window as any).difference_timer = setInterval(() => {
if (!context.state.difference_time_switch) {
clearInterval((window as any).difference_timer);
(window as any).difference_timer = null;
return;
}
let server_time = moment().valueOf();
if (context.state.difference_time) server_time += context.state.difference_time;
context.commit('updateServerTime', server_time);
}, 1000);
}
},
modules: {},
plugins: [
createPersistedState({
storage: window.localStorage, // 使用localStorage存储状态
reducer (val: any) {
return {
init: val.init,
updateListTime: val.updateListTime,
match_list_all_cache: val.match_list_all_cache,
// updateWsTime: val.updateWsTime,
nm_live_message_cache: val.nm_live_message_cache,
match_list_attention: val.match_list_attention,
attention_id_list: val.attention_id_list,
set_config: val.set_config,
my_asia: val.my_asia,
my_euro: val.my_euro,
my_bs: val.my_bs,
my_cr: val.my_cr
};
}
}),
createPersistedState({
storage: window.sessionStorage,
key: `1000hi_live_session`,
reducer: state => ({
match_detail: state.match_detail,
game_info_cache: state.game_info_cache,
game_detail_cache: state.game_detail_cache,
})
}),
],
});
export default store;