index.js 14 KB

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