index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel;
  5. let rep = null;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. dataTypes: 0, //0-全部数据 1-单独数据
  12. tabsList: ["私域直播", "展会直播", "合作商直播"], //tabs列表
  13. buttonTabs: ["当前直播", "历史直播"], //按钮tabs
  14. tabsIndex: 0, //tabs下标
  15. accountStatus: -1, //直播账号状态 1-账号正常 2-账号审核中 3-没有账号
  16. //liveDataCount: {}, 实时数据统计
  17. liveDataCountForSession: {}, //单场次数据统计
  18. liveSessionList: [], //直播场次列表
  19. liveUserList: [], //直播用户观看记录
  20. crLiveUserList: [], //当前直播用户观看记录
  21. pageNumber: 1, //当前页码
  22. pageTotal: 1, //列表总页数
  23. userPageNumber: 1, //用户当前页码
  24. userPageTotal: 1, //用户总列表
  25. isSy: true, //是否为私域直播
  26. myShowModel: false, //自定义model
  27. myShowModel2: false, // 真正申请中提示
  28. listRowIndex: -1, //列表选中项
  29. CheckTheType: '当前直播', //查看类型
  30. onlineNumber: 0, //实时观看人数
  31. oldDialogue: [], //老直播聊天数据
  32. newDialogue: [], //新直播聊天数据
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad: function (options) {
  38. //获取直播账号
  39. this.getLiveInfo()
  40. },
  41. /* 按钮tab回调 */
  42. tabsSelectedIitem({
  43. detail
  44. }) {
  45. if (detail == this.data.CheckTheType) return;
  46. if (detail == '历史直播') {
  47. if (this.data.liveSessionList.length == 0) return wx.showToast({
  48. title: '当前没有开播记录',
  49. icon: "none"
  50. })
  51. }
  52. this.setData({
  53. CheckTheType: detail
  54. })
  55. },
  56. /* 实时 */
  57. realTime() {
  58. /* 获取当前用户列表 */
  59. this.getRealTimeViewerList();
  60. //获取聊天
  61. this.getRealTimeMessageList();
  62. //实时观看人数
  63. this.getRealTimeViewers();
  64. rep = setInterval(() => {
  65. /* 获取当前用户列表 */
  66. this.getRealTimeViewerList();
  67. //获取聊天
  68. this.getRealTimeMessageList();
  69. //实时观看人数
  70. this.getRealTimeViewers();
  71. }, 3000)
  72. },
  73. //实时观看人数
  74. getRealTimeViewers() {
  75. _Http.basic({
  76. "accesstoken": wx.getStorageSync('userData').token,
  77. "classname": "customer.live.live",
  78. "method": "getRealTimeViewers",
  79. "content": {
  80. "channelid": this.data.accountMsg.channelid
  81. }
  82. }, false).then(res => {
  83. if (res.msg != '成功') return;
  84. this.setData({
  85. onlineNumber: res.data.count
  86. })
  87. })
  88. },
  89. //获取聊天
  90. getRealTimeMessageList() {
  91. _Http.basic({
  92. "accesstoken": wx.getStorageSync('userData').token,
  93. "classname": "customer.live.live",
  94. "method": "getRealTimeMessageList",
  95. "content": {
  96. "pageNumber": 1,
  97. "pageSize": 999,
  98. "channelid": this.data.accountMsg.channelid
  99. }
  100. }, false).then(res => {
  101. if (this.data.oldDialogue.length == 0) {
  102. for (let i = 0; i < res.data.length; i++) {
  103. let data = res.data[i].datetime.split(" ");
  104. res.data[i].datetime = data[1]
  105. }
  106. this.setData({
  107. oldDialogue: res.data
  108. })
  109. } else {
  110. let oldDialogue = this.data.oldDialogue,
  111. newDialogue = res.data;
  112. if (!Object.is(JSON.stringify(oldDialogue), JSON.stringify(newDialogue))) {
  113. let data = JSON.stringify(oldDialogue)
  114. for (let i = 0; i < newDialogue.length; i++) {
  115. if (!data.includes(newDialogue[i].id)) {
  116. let data = newDialogue[i].datetime.split(" ");
  117. newDialogue[i].datetime = data[1]
  118. oldDialogue.unshift(newDialogue[i]);
  119. }
  120. }
  121. this.setData({
  122. oldDialogue
  123. })
  124. }
  125. }
  126. })
  127. },
  128. /* 获取当前用户列表 */
  129. getRealTimeViewerList() {
  130. _Http.basic({
  131. "accesstoken": wx.getStorageSync('userData').token,
  132. "classname": "customer.live.live",
  133. "method": "getRealTimeViewerList",
  134. "content": {
  135. "pageNumber": this.data.pageNumber,
  136. "pageSize": 20,
  137. "channelid": this.data.accountMsg.channelid
  138. }
  139. }, false).then(res => {
  140. if (res.msg != '成功') {
  141. if (this.data.liveUserList.length <= 0) return wx.showToast({
  142. title: res.data,
  143. icon: "none"
  144. });
  145. return;
  146. }
  147. this.setData({
  148. crLiveUserList: res.data,
  149. pageTotal: res.pageTotal
  150. })
  151. })
  152. },
  153. /* 自定义model回调 */
  154. showModelCallBack({
  155. detail
  156. }) {
  157. if (detail == 'true') this.copyTheAddress(this.data.accountMsg.fliveurl_web);
  158. },
  159. /* 显示自定义model */
  160. showMyModel() {
  161. this.setData({
  162. myShowModel: true
  163. })
  164. },
  165. /* 申请直播账号 */
  166. applyForLive() {
  167. _Http.basic({
  168. "accesstoken": wx.getStorageSync('userData').token,
  169. "classname": "customer.live.live",
  170. "method": "applySYLive",
  171. "content": {}
  172. }).then(res => {
  173. if (res.code == 1) {
  174. wx.showToast({
  175. title: res.msg,
  176. icon: "none"
  177. })
  178. this.setData({
  179. accountStatus: 2
  180. })
  181. } else {
  182. if (res.data == '私域直播已申请') return this.setData({
  183. myShowModel2: true
  184. })
  185. }
  186. })
  187. },
  188. /* 复制地址 */
  189. copyTheAddress(e) {
  190. const url = (typeof e == "string" || typeof e == String) ? e : e.target.dataset.url;
  191. wx.setClipboardData({
  192. data: url,
  193. success(res) {
  194. wx.getClipboardData({
  195. success(res) {
  196. console.log('内容已复制') // data
  197. }
  198. })
  199. }
  200. })
  201. },
  202. /* 获取直播账号详情 */
  203. getLiveInfo() {
  204. const method = (this.data.tabsIndex == 0) ? 'getSYLiveInfo' : 'getLiveInfo';
  205. _Http.basic({
  206. "accesstoken": wx.getStorageSync('userData').token,
  207. "classname": "customer.live.live",
  208. "method": method,
  209. "content": {}
  210. }).then(res => {
  211. const isSy = (method == "getSYLiveInfo") ? true : false;
  212. this.setData({
  213. accountStatus: res.code,
  214. accountMsg: res.data[0],
  215. isSy
  216. })
  217. //获取实时数据
  218. this.realTime()
  219. //直播场次列表查询
  220. if (res.code == 1) this.getLiveSessionList();
  221. })
  222. },
  223. /* 直播场次列表查询 */
  224. getLiveSessionList() {
  225. const method = (this.data.tabsIndex == 0) ? "getSYLiveSessionList" : "getLiveSessionList"
  226. _Http.basic({
  227. "accesstoken": wx.getStorageSync('userData').token,
  228. "classname": "customer.live.live",
  229. "method": method,
  230. "content": {
  231. "getdatafromdbanyway": true,
  232. "pageNumber": this.data.pageNumber,
  233. "pageSize": 10,
  234. "channelid": this.data.accountMsg.channelid
  235. }
  236. }).then(res => {
  237. if (res.msg != '成功') return wx.showToast({
  238. title: res.data,
  239. icon: "none"
  240. });
  241. let sessionList = [];
  242. for (let i = 0; i < res.data.length; i++) {
  243. let checkdate = res.data[i].starttime,
  244. time = checkdate.slice(0, checkdate.lastIndexOf('.')),
  245. t = time.split(' ');
  246. res.data[i].starttime = t[0];
  247. sessionList.push(t[0])
  248. };
  249. this.setData({
  250. liveSessionList: res.data,
  251. pageTotal: res.pageTotal,
  252. sessionList
  253. });
  254. if (res.data.length > 0) this.viewDetails(0);
  255. })
  256. },
  257. /* 查看场次详情 */
  258. selectorChange(e) {
  259. this.viewDetails(e.detail.value);
  260. },
  261. viewDetails(index) {
  262. const sessionid = this.data.liveSessionList[index].sessionid;
  263. this.setData({
  264. showStartTime: this.data.liveSessionList[index].starttime,
  265. sessionid
  266. })
  267. /* 场次详情统计 */
  268. _Http.basic({
  269. "accesstoken": wx.getStorageSync('userData').token,
  270. "classname": "customer.live.live",
  271. "method": "getSYLiveDataCountForSession",
  272. "content": {
  273. "sessionid": sessionid
  274. }
  275. }).then(res => {
  276. if (res.msg != '成功') wx.showToast({
  277. title: '数据统计获取失败,请稍后再试',
  278. icon: "none"
  279. })
  280. this.setData({
  281. liveDataCountForSession: res.data
  282. })
  283. });
  284. this.LiveUserList();
  285. this.setData({
  286. dataTypes: 1
  287. })
  288. },
  289. /* 观看用户列表 */
  290. LiveUserList() {
  291. /* 用户观看列表 */
  292. const method = (this.data.tabsIndex == 0) ? "getSYLiveUserList" : "getLiveUserList";
  293. _Http.basic({
  294. "accesstoken": wx.getStorageSync('userData').token,
  295. "classname": "customer.live.live",
  296. "method": method,
  297. "content": {
  298. "getdatafromdbanyway": true,
  299. "pageNumber": this.data.userPageNumber,
  300. "pageSize": 10,
  301. "sessionid": this.data.sessionid,
  302. "channelid": this.data.accountMsg.channelid
  303. }
  304. }).then(res => {
  305. if (res.msg != '成功') wx.showToast({
  306. title: '观看列表获取失败,请稍后再试',
  307. icon: "none"
  308. })
  309. for (let i = 0; i < res.data.length; i++) {
  310. const index = res.data[i].datetime.lastIndexOf('.');
  311. res.data[i].datetime = res.data[i].datetime.slice(0, index)
  312. }
  313. this.setData({
  314. userPageTotal: res.pageTotal,
  315. liveUserList: res.data
  316. })
  317. });
  318. },
  319. /* 下一页 */
  320. buttonRightClick() {
  321. if (this.data.CheckTheType == '当前直播') {
  322. if (this.data.pageNumber == this.data.pageTotal) return wx.showToast({
  323. title: '已经到达最后一页',
  324. icon: "none"
  325. });
  326. this.setData({
  327. pageNumber: this.data.pageNumber + 1
  328. })
  329. this.getRealTimeViewerList()
  330. } else {
  331. if (this.data.userPageNumber == this.data.userPageTotal) return wx.showToast({
  332. title: '已经到达最后一页',
  333. icon: "none"
  334. });
  335. this.setData({
  336. userPageNumber: this.data.userPageNumber + 1
  337. })
  338. this.LiveUserList()
  339. }
  340. },
  341. /* 上一页 */
  342. buttonLifeClick() {
  343. if (this.data.CheckTheType == '当前直播') {
  344. if (this.data.pageNumber == 1) return wx.showToast({
  345. title: '已经在第一页了',
  346. icon: "none"
  347. });
  348. this.setData({
  349. pageNumber: this.data.pageNumber - 1
  350. })
  351. this.getRealTimeViewerList()
  352. } else {
  353. if (this.data.userPageNumber == 1) return wx.showToast({
  354. title: '已经在第一页了',
  355. icon: "none"
  356. });
  357. this.setData({
  358. userPageNumber: this.data.userPageNumber - 1
  359. })
  360. this.LiveUserList()
  361. }
  362. },
  363. /* 选中行 */
  364. listRowAvtion(e) {
  365. this.setData({
  366. listRowIndex: e.currentTarget.dataset.index
  367. })
  368. },
  369. /* tabs回调 */
  370. setIndex({
  371. detail
  372. }) {
  373. if (this.data.tabsIndex == detail) return;
  374. this.setData({
  375. tabsIndex: detail,
  376. pageNumber: 1,
  377. pageTotal: 1,
  378. userPageNumber: 1,
  379. userPageTotal: 1
  380. });
  381. this.getLiveInfo();
  382. if (detail == 2) this.getCooperationAgentsLiveList();
  383. },
  384. /* 获取合作商直播列表 */
  385. getCooperationAgentsLiveList() {
  386. _Http.basic({
  387. "accesstoken": wx.getStorageSync('userData').token,
  388. "classname": "customer.live.live",
  389. "method": "getCooperationAgentsLiveList",
  390. "content": {}
  391. }).then(res => {
  392. this.setData({
  393. partnerLiveList: res.data
  394. })
  395. })
  396. },
  397. /* 查看合作商直播 */
  398. toLive(e) {
  399. const {
  400. fliveshowurl
  401. } = e.currentTarget.dataset;
  402. wx.navigateTo({
  403. url: '/pages/webView/index?url=' + fliveshowurl,
  404. })
  405. },
  406. /**
  407. * 生命周期函数--监听页面初次渲染完成
  408. */
  409. onReady: function () {},
  410. /**
  411. * 生命周期函数--监听页面显示
  412. */
  413. onShow: function () {},
  414. /**
  415. * 生命周期函数--监听页面隐藏
  416. */
  417. onHide: function () {},
  418. /**
  419. * 生命周期函数--监听页面卸载
  420. */
  421. onUnload: function () {
  422. clearInterval(rep)
  423. },
  424. /**
  425. * 页面相关事件处理函数--监听用户下拉动作
  426. */
  427. onPullDownRefresh: function () {},
  428. /**
  429. * 页面上拉触底事件的处理函数
  430. */
  431. onReachBottom: function () {},
  432. /**
  433. * 用户点击右上角分享
  434. */
  435. onShareAppMessage: function () {
  436. return {
  437. title: this.data.accountMsg.channelname,
  438. path: "/pages/webView/index?url=" + this.data.accountMsg.fliveshowurl,
  439. imageUrl: this.data.accountMsg.channelcoverimageurl
  440. }
  441. }
  442. })