ChannelsModal.js
3.65 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
// pages/tab/index/components/ChannelsModal/ChannelsModal.js
import {
systemApi
} from '~/api/index'
import {
IMG_URL
} from '~/config'
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
showChannels: true
},
/**
* 组件的方法列表
*/
methods: {
noScroll() {},
async init(auto = true) {
const {
finderUserName
} = await wx.p.api.systemApi.getMockData()
this.setData({
finderUserName: finderUserName || 'sph7YsAMEGQixoU'
})
this.getChannelsLiveInfo(auto)
},
getChannelsLiveInfo(auto) {
const _this = this,
{
finderUserName
} = this.data
wx.getChannelsLiveInfo({
finderUserName,
success(liveInfo) {
console.log('视频号直播信息:', liveInfo)
if (liveInfo.status == 3) {
_this.getChannelsLiveNoticeInfo(finderUserName, auto)
liveInfo = null
} else if (!auto) _this.close()
_this.setData({
liveInfo
})
},
fail(err) {
console.log(err)
_this.getChannelsLiveNoticeInfo(finderUserName, auto)
}
})
},
getChannelsLiveNoticeInfo(finderUserName, auto) {
const _this = this
wx.getChannelsLiveNoticeInfo({
finderUserName,
success(liveNoticeInfo) {
console.log('视频号预告信息:', liveNoticeInfo)
let startTime = liveNoticeInfo.startTime * 1e3,
month = new Date(startTime).format('M'),
day = new Date(startTime).format('d'),
time = new Date(startTime).format('hh:mm')
liveNoticeInfo = {
...liveNoticeInfo,
month,
day,
time
}
_this.setData({
liveNoticeInfo
})
if (!auto) _this.close()
},
fail(err) {
console.log('视频号预告信息:', err)
_this.setData({
liveNoticeInfo: null
})
}
})
},
jumpLive() {
const {
liveInfo: {
feedId,
nonceId
},
finderUserName
} = this.data,
_this = this
wx.openChannelsLive({
finderUserName,
feedId,
nonceId,
success(res) {
_this.close()
},
fail(err) {
if (err && err.errMsg && !err.errMsg.includes('cancel')) wx.p.wxApi.showToast(err.errMsg)
}
})
},
reserve() {
this.close()
const {
noticeId
} = this.data.liveNoticeInfo
wx.reserveChannelsLive({
noticeId
})
},
close(e) {
if (e) this.setData({
animation: true
}, setTimeout(() => {
this.setBanner()
}, .3e3))
else this.setBanner()
},
async setBanner() {
const v = await systemApi.getImageVersion() || Date.now()
const {
liveInfo,
liveNoticeInfo,
finderUserName
} = this.data,
bannerImg = `${IMG_URL}home/live/${liveInfo ? 'live' :'notice'}.png?v=${v}`,
thisPage = wx.p.router.getPageInstance()
let {
bannerList
} = thisPage.data,
item = liveInfo || liveNoticeInfo,
obj = {
bannerImg,
bannerType: 'channels',
type: liveInfo ? 1 : 0,
finderUserName,
...item,
}
if (!bannerList) bannerList = []
bannerList.unshift(obj)
thisPage.setData({
bannerList
})
this.setData({
showChannels: false
})
}
},
lifetimes: {
ready() {
this.init()
}
}
})