index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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 (res.msg != '成功') return wx.showToast({
  102. title: res.data,
  103. icon: "none"
  104. })
  105. for (let i = 0; i < res.data.length; i++) {
  106. let data = res.data[i].datetime.split(" ");
  107. res.data[i].datetime = data[1]
  108. }
  109. this.setData({
  110. oldDialogue: res.data
  111. })
  112. /* if (this.data.oldDialogue.length == 0) {
  113. } else {
  114. let oldDialogue = this.data.oldDialogue,
  115. newDialogue = res.data;
  116. if (!Object.is(JSON.stringify(oldDialogue), JSON.stringify(newDialogue))) {
  117. let data = JSON.stringify(oldDialogue)
  118. for (let i = 0; i < newDialogue.length; i++) {
  119. if (!data.includes(newDialogue[i].id)) {
  120. let data = newDialogue[i].datetime.split(" ");
  121. newDialogue[i].datetime = data[1]
  122. oldDialogue.unshift(newDialogue[i]);
  123. }
  124. }
  125. this.setData({
  126. oldDialogue
  127. })
  128. }
  129. } */
  130. })
  131. },
  132. /* 获取当前用户列表 */
  133. getRealTimeViewerList() {
  134. _Http.basic({
  135. "accesstoken": wx.getStorageSync('userData').token,
  136. "classname": "customer.live.live",
  137. "method": "getRealTimeViewerList",
  138. "content": {
  139. "pageNumber": this.data.pageNumber,
  140. "pageSize": 20,
  141. "channelid": this.data.accountMsg.channelid
  142. }
  143. }, false).then(res => {
  144. if (res.msg != '成功') {
  145. if (this.data.liveUserList.length <= 0) return wx.showToast({
  146. title: res.data,
  147. icon: "none"
  148. });
  149. return;
  150. }
  151. this.setData({
  152. crLiveUserList: res.data,
  153. pageTotal: res.pageTotal
  154. })
  155. })
  156. },
  157. /* 自定义model回调 */
  158. showModelCallBack({
  159. detail
  160. }) {
  161. if (detail == 'true') this.copyTheAddress(this.data.accountMsg.fliveurl_web);
  162. },
  163. /* 显示自定义model */
  164. showMyModel() {
  165. this.setData({
  166. myShowModel: true
  167. })
  168. },
  169. /* 申请直播账号 */
  170. applyForLive() {
  171. _Http.basic({
  172. "accesstoken": wx.getStorageSync('userData').token,
  173. "classname": "customer.live.live",
  174. "method": "applySYLive",
  175. "content": {}
  176. }).then(res => {
  177. if (res.code == 1) {
  178. wx.showToast({
  179. title: res.msg,
  180. icon: "none"
  181. })
  182. this.setData({
  183. accountStatus: 2
  184. })
  185. } else {
  186. if (res.data == '私域直播已申请') return this.setData({
  187. myShowModel2: true
  188. })
  189. }
  190. })
  191. },
  192. /* 复制地址 */
  193. copyTheAddress(e) {
  194. const url = (typeof e == "string" || typeof e == String) ? e : e.target.dataset.url;
  195. wx.setClipboardData({
  196. data: url,
  197. success(res) {
  198. wx.getClipboardData({
  199. success(res) {
  200. console.log('内容已复制') // data
  201. }
  202. })
  203. }
  204. })
  205. },
  206. /* 获取直播账号详情 */
  207. getLiveInfo() {
  208. const method = (this.data.tabsIndex == 0) ? 'getSYLiveInfo' : 'getLiveInfo';
  209. _Http.basic({
  210. "accesstoken": wx.getStorageSync('userData').token,
  211. "classname": "customer.live.live",
  212. "method": method,
  213. "content": {}
  214. }).then(res => {
  215. const isSy = (method == "getSYLiveInfo") ? true : false;
  216. console.log("直播账号详情", res)
  217. this.setData({
  218. accountStatus: res.code,
  219. accountMsg: res.data[0],
  220. isSy
  221. })
  222. //获取授权地址
  223. if (res.data[0].fisneedauth == 1) {
  224. _Http.basic({
  225. "accesstoken": wx.getStorageSync('userData').token,
  226. "classname": "enterprise.live.live",
  227. "method": "liveauthorization",
  228. "content": {
  229. "tliveid": res.data[0].tliveid
  230. }
  231. }).then(res => {
  232. this.setData({
  233. "accountMsg.fliveshowurl": res.msg
  234. })
  235. })
  236. }
  237. //获取实时数据
  238. this.realTime()
  239. //直播场次列表查询
  240. if (res.code == 1) this.getLiveSessionList();
  241. })
  242. },
  243. /* 直播场次列表查询 */
  244. getLiveSessionList() {
  245. const method = (this.data.tabsIndex == 0) ? "getSYLiveSessionList" : "getLiveSessionList"
  246. _Http.basic({
  247. "accesstoken": wx.getStorageSync('userData').token,
  248. "classname": "customer.live.live",
  249. "method": method,
  250. "content": {
  251. "getdatafromdbanyway": true,
  252. "pageNumber": this.data.pageNumber,
  253. "pageSize": 10,
  254. "channelid": this.data.accountMsg.channelid
  255. }
  256. }).then(res => {
  257. if (res.msg != '成功') return wx.showToast({
  258. title: res.data,
  259. icon: "none"
  260. });
  261. let sessionList = [];
  262. for (let i = 0; i < res.data.length; i++) {
  263. let checkdate = res.data[i].starttime,
  264. time = checkdate.slice(0, checkdate.lastIndexOf('.')),
  265. t = time.split(' ');
  266. res.data[i].starttime = t[0];
  267. sessionList.push(t[0])
  268. };
  269. this.setData({
  270. liveSessionList: res.data,
  271. pageTotal: res.pageTotal,
  272. sessionList
  273. });
  274. if (res.data.length > 0) this.viewDetails(0);
  275. })
  276. },
  277. /* 查看场次详情 */
  278. selectorChange(e) {
  279. this.viewDetails(e.detail.value);
  280. },
  281. viewDetails(index) {
  282. const sessionid = this.data.liveSessionList[index].sessionid;
  283. this.setData({
  284. showStartTime: this.data.liveSessionList[index].starttime,
  285. sessionid
  286. })
  287. /* 场次详情统计 */
  288. _Http.basic({
  289. "accesstoken": wx.getStorageSync('userData').token,
  290. "classname": "customer.live.live",
  291. "method": "getSYLiveDataCountForSession",
  292. "content": {
  293. "sessionid": sessionid
  294. }
  295. }).then(res => {
  296. if (res.msg != '成功') wx.showToast({
  297. title: '数据统计获取失败,请稍后再试',
  298. icon: "none"
  299. })
  300. this.setData({
  301. liveDataCountForSession: res.data
  302. })
  303. });
  304. this.LiveUserList();
  305. this.setData({
  306. dataTypes: 1
  307. })
  308. },
  309. /* 观看用户列表 */
  310. LiveUserList() {
  311. /* 用户观看列表 */
  312. const method = (this.data.tabsIndex == 0) ? "getSYLiveUserList" : "getLiveUserList";
  313. _Http.basic({
  314. "accesstoken": wx.getStorageSync('userData').token,
  315. "classname": "customer.live.live",
  316. "method": method,
  317. "content": {
  318. "getdatafromdbanyway": true,
  319. "pageNumber": this.data.userPageNumber,
  320. "pageSize": 10,
  321. "sessionid": this.data.sessionid,
  322. "channelid": this.data.accountMsg.channelid
  323. }
  324. }).then(res => {
  325. if (res.msg != '成功') wx.showToast({
  326. title: '观看列表获取失败,请稍后再试',
  327. icon: "none"
  328. })
  329. for (let i = 0; i < res.data.length; i++) {
  330. const index = res.data[i].datetime.lastIndexOf('.');
  331. res.data[i].datetime = res.data[i].datetime.slice(0, index)
  332. }
  333. this.setData({
  334. userPageTotal: res.pageTotal,
  335. liveUserList: res.data
  336. })
  337. });
  338. },
  339. /* 下一页 */
  340. buttonRightClick() {
  341. if (this.data.CheckTheType == '当前直播') {
  342. if (this.data.pageNumber == this.data.pageTotal) return wx.showToast({
  343. title: '已经到达最后一页',
  344. icon: "none"
  345. });
  346. this.setData({
  347. pageNumber: this.data.pageNumber + 1
  348. })
  349. this.getRealTimeViewerList()
  350. } else {
  351. if (this.data.userPageNumber == this.data.userPageTotal) return wx.showToast({
  352. title: '已经到达最后一页',
  353. icon: "none"
  354. });
  355. this.setData({
  356. userPageNumber: this.data.userPageNumber + 1
  357. })
  358. this.LiveUserList()
  359. }
  360. },
  361. /* 上一页 */
  362. buttonLifeClick() {
  363. if (this.data.CheckTheType == '当前直播') {
  364. if (this.data.pageNumber == 1) return wx.showToast({
  365. title: '已经在第一页了',
  366. icon: "none"
  367. });
  368. this.setData({
  369. pageNumber: this.data.pageNumber - 1
  370. })
  371. this.getRealTimeViewerList()
  372. } else {
  373. if (this.data.userPageNumber == 1) return wx.showToast({
  374. title: '已经在第一页了',
  375. icon: "none"
  376. });
  377. this.setData({
  378. userPageNumber: this.data.userPageNumber - 1
  379. })
  380. this.LiveUserList()
  381. }
  382. },
  383. /* 选中行 */
  384. listRowAvtion(e) {
  385. this.setData({
  386. listRowIndex: e.currentTarget.dataset.index
  387. })
  388. },
  389. /* tabs回调 */
  390. setIndex({
  391. detail
  392. }) {
  393. if (this.data.tabsIndex == detail) return;
  394. this.setData({
  395. tabsIndex: detail,
  396. pageNumber: 1,
  397. pageTotal: 1,
  398. userPageNumber: 1,
  399. userPageTotal: 1
  400. });
  401. if (detail != 2) this.getLiveInfo();
  402. if (detail == 2) this.getCooperationAgentsLiveList();
  403. },
  404. /* 获取合作商直播列表 */
  405. getCooperationAgentsLiveList() {
  406. _Http.basic({
  407. "accesstoken": wx.getStorageSync('userData').token,
  408. "classname": "customer.live.live",
  409. "method": "getCooperationAgentsLiveList",
  410. "content": {}
  411. }).then(res => {
  412. this.setData({
  413. partnerLiveList: res.data
  414. })
  415. })
  416. },
  417. /* 查看合作商直播 */
  418. toLive(e) {
  419. const {
  420. index
  421. } = e.currentTarget.dataset,
  422. data = this.data.partnerLiveList[index];
  423. console.log(data.fisneedauth)
  424. if (data.fisneedauth == 1) {
  425. _Http.basic({
  426. "accesstoken": wx.getStorageSync('userData').token,
  427. "classname": "enterprise.live.live",
  428. "method": "liveauthorization",
  429. "content": {
  430. "tliveid": data.tliveid
  431. }
  432. }).then(res => {
  433. console.log(res)
  434. if (res.data != '成功') return wx.showToast({
  435. title: '网络错误,请稍后再试',
  436. })
  437. let str = res.msg;
  438. const url = str.slice(0, 8) + '04de51d4c1.' + str.slice(8);
  439. wx.navigateTo({
  440. url: '/pages/webView/index?url=' + encodeURIComponent(url),
  441. })
  442. })
  443. } else {
  444. let str = data.fliveshowurl;
  445. const url = str.slice(0, 8) + '04de51d4c1.' + str.slice(8);
  446. wx.navigateTo({
  447. url: '/pages/webView/index?url=' + encodeURIComponent(url)
  448. })
  449. }
  450. },
  451. /**
  452. * 生命周期函数--监听页面初次渲染完成
  453. */
  454. onReady: function () {},
  455. /**
  456. * 生命周期函数--监听页面显示
  457. */
  458. onShow: function () {},
  459. /**
  460. * 生命周期函数--监听页面隐藏
  461. */
  462. onHide: function () {},
  463. /**
  464. * 生命周期函数--监听页面卸载
  465. */
  466. onUnload: function () {
  467. clearInterval(rep)
  468. },
  469. /**
  470. * 页面相关事件处理函数--监听用户下拉动作
  471. */
  472. onPullDownRefresh: function () {},
  473. /**
  474. * 页面上拉触底事件的处理函数
  475. */
  476. onReachBottom: function () {},
  477. /**
  478. * 用户点击右上角分享
  479. */
  480. onShareAppMessage: function () {
  481. let str = this.data.accountMsg.fliveshowurl;
  482. const url = str.slice(0, 8) + '04de51d4c1.' + str.slice(8)
  483. return {
  484. title: this.data.accountMsg.channelname,
  485. path: "/pages/webView/index?url=" + url,
  486. imageUrl: this.data.accountMsg.channelcoverimageurl
  487. }
  488. }
  489. })