followHelper.js
1.5 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
import loginHelper from './loginHelper.js';
import utils from './utils.js';
let Follow_List = null
const followHelper = {
getFollowList() {
if (!loginHelper.hasLogin()) {
return []
}
if(!Follow_List) {
Follow_List = []
let temp_data = uni.getStorageSync('follow_list_key')
console.log(temp_data)
if (temp_data.length > 0) {
let temp_list = JSON.parse(temp_data)
Follow_List.push(...temp_list)
}
for (var i = 0; i < Follow_List.length; i++) {
var item = Follow_List[i]
if (utils.diffCurrentDay(item.MatchTime) >= 7) {
Follow_List.splice(i, 1);
}
}
let follow_str = JSON.stringify(Follow_List)
uni.setStorageSync('follow_list_key', follow_str)
}
console.log(Follow_List)
return Follow_List;
},
async follow_action(match) {
if (!loginHelper.hasLogin()) {
uni.showToast({
icon: "none",
title: "未登录",
});
return []
}
var index_flag = Follow_List.some(function(item, index) {
if (item.Id === match.Id) {
Follow_List.splice(index, 1);
}
return item.Id === match.Id;
})
let follow_str = JSON.stringify(Follow_List)
await uni.setStorageSync('follow_list_key', follow_str)
if (index_flag) {
uni.showToast({
title: "已取关"
})
match.isFollow = false
} else {
Follow_List.push(match)
match.isFollow = true
uni.showToast({
title: "已关注"
})
}
return Follow_List;
}
}
export default followHelper