index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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": 10,
  255. "channelid": this.data.accountMsg.channelid
  256. }
  257. }).then(res => {
  258. if (res.msg != '成功') return wx.showToast({
  259. title: res.data,
  260. icon: "none"
  261. });
  262. let sessionList = [];
  263. for (let i = 0; i < res.data.length; i++) {
  264. let checkdate = res.data[i].starttime,
  265. time = checkdate.slice(0, checkdate.lastIndexOf('.')),
  266. t = time.split(' ');
  267. res.data[i].starttime = t[0];
  268. sessionList.push(t[0])
  269. };
  270. this.setData({
  271. liveSessionList: res.data,
  272. pageTotal: res.pageTotal,
  273. sessionList
  274. });
  275. if (res.data.length > 0) this.viewDetails(0);
  276. })
  277. },
  278. /* 查看场次详情 */
  279. selectorChange(e) {
  280. this.viewDetails(e.detail.value);
  281. },
  282. viewDetails(index) {
  283. const sessionid = this.data.liveSessionList[index].sessionid;
  284. this.setData({
  285. showStartTime: this.data.liveSessionList[index].starttime,
  286. sessionid
  287. })
  288. /* const method = (this.data.tabsIndex == 0) ? "getSYLiveDataCountForSession" : "getLiveDataCountForSession" */
  289. const method = 'getLiveDataCountForSession';
  290. /* 场次详情统计 */
  291. _Http.basic({
  292. "accesstoken": wx.getStorageSync('userData').token,
  293. "classname": "customer.live.live",
  294. "method": method,
  295. "content": {
  296. "sessionid": sessionid
  297. }
  298. }).then(res => {
  299. if (res.msg != '成功') wx.showToast({
  300. title: '数据统计获取失败,请稍后再试',
  301. icon: "none"
  302. })
  303. res.data.viewDuration = Math.ceil(res.data.viewDuration / 60);
  304. res.data.viewDurationAvg = Math.ceil(res.data.viewDurationAvg / 60);
  305. this.setData({
  306. liveDataCountForSession: res.data
  307. })
  308. });
  309. this.LiveUserList();
  310. this.setData({
  311. dataTypes: 1
  312. })
  313. },
  314. /* 观看用户列表 */
  315. LiveUserList() {
  316. /* 用户观看列表 */
  317. /* const method = (this.data.tabsIndex == 0) ? "getSYLiveUserList" : "getLiveUserList"; */
  318. const method = "getLiveUserList";
  319. _Http.basic({
  320. "accesstoken": wx.getStorageSync('userData').token,
  321. "classname": "customer.live.live",
  322. "method": method,
  323. "content": {
  324. "getdatafromdbanyway": true,
  325. "pageNumber": this.data.userPageNumber,
  326. "pageSize": 10,
  327. "sessionid": this.data.sessionid,
  328. "channelid": this.data.accountMsg.channelid
  329. }
  330. }).then(res => {
  331. if (res.msg != '成功') wx.showToast({
  332. title: '观看列表获取失败,请稍后再试',
  333. icon: "none"
  334. })
  335. for (let i = 0; i < res.data.length; i++) {
  336. const index = res.data[i].datetime.lastIndexOf('.');
  337. res.data[i].datetime = res.data[i].datetime.slice(0, index);
  338. res.data[i].playduration = Math.ceil(res.data[i].playduration / 60);
  339. }
  340. this.setData({
  341. userPageTotal: res.pageTotal,
  342. liveUserList: res.data
  343. })
  344. });
  345. },
  346. /* 下一页 */
  347. buttonRightClick() {
  348. if (this.data.CheckTheType == '当前直播') {
  349. if (this.data.pageNumber == this.data.pageTotal) return wx.showToast({
  350. title: '已经到达最后一页',
  351. icon: "none"
  352. });
  353. this.setData({
  354. pageNumber: this.data.pageNumber + 1
  355. })
  356. this.getRealTimeViewerList()
  357. } else {
  358. if (this.data.userPageNumber == this.data.userPageTotal) return wx.showToast({
  359. title: '已经到达最后一页',
  360. icon: "none"
  361. });
  362. this.setData({
  363. userPageNumber: this.data.userPageNumber + 1
  364. })
  365. this.LiveUserList()
  366. }
  367. },
  368. /* 上一页 */
  369. buttonLifeClick() {
  370. if (this.data.CheckTheType == '当前直播') {
  371. if (this.data.pageNumber == 1) return wx.showToast({
  372. title: '已经在第一页了',
  373. icon: "none"
  374. });
  375. this.setData({
  376. pageNumber: this.data.pageNumber - 1
  377. })
  378. this.getRealTimeViewerList()
  379. } else {
  380. if (this.data.userPageNumber == 1) return wx.showToast({
  381. title: '已经在第一页了',
  382. icon: "none"
  383. });
  384. this.setData({
  385. userPageNumber: this.data.userPageNumber - 1
  386. })
  387. this.LiveUserList()
  388. }
  389. },
  390. /* 选中行 */
  391. listRowAvtion(e) {
  392. this.setData({
  393. listRowIndex: e.currentTarget.dataset.index
  394. })
  395. },
  396. /* tabs回调 */
  397. setIndex({
  398. detail
  399. }) {
  400. if (this.data.tabsIndex == detail) return;
  401. this.setData({
  402. tabsIndex: detail,
  403. pageNumber: 1,
  404. pageTotal: 1,
  405. userPageNumber: 1,
  406. userPageTotal: 1
  407. });
  408. // if (detail != 2) this.getLiveInfo();
  409. if (detail == 0) this.getLiveInfo();
  410. if (detail == 1) this.getCooperationAgentsLiveList();
  411. },
  412. /* 获取合作商直播列表 */
  413. getCooperationAgentsLiveList() {
  414. _Http.basic({
  415. "accesstoken": wx.getStorageSync('userData').token,
  416. "classname": "customer.live.live",
  417. "method": "getCooperationAgentsLiveList",
  418. "content": {}
  419. }).then(res => {
  420. this.setData({
  421. partnerLiveList: res.data
  422. })
  423. })
  424. },
  425. /* 查看合作商直播 */
  426. /* toLive(e) {
  427. const {
  428. index
  429. } = e.currentTarget.dataset,
  430. data = this.data.partnerLiveList[index];
  431. if (data.fisneedauth == 1) {
  432. _Http.basic({
  433. "accesstoken": wx.getStorageSync('userData').token,
  434. "classname": "enterprise.live.live",
  435. "method": "liveauthorization",
  436. "content": {
  437. "tliveid": data.tliveid
  438. }
  439. }).then(res => {
  440. console.log(res)
  441. if (res.data != '成功') return wx.showToast({
  442. title: '网络错误,请稍后再试',
  443. })
  444. let str = res.msg;
  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. } else {
  451. let str = data.fliveshowurl;
  452. const url = str.slice(0, 8) + '04de51d4c1.' + str.slice(8);
  453. wx.navigateTo({
  454. url: '/pages/webView/index?url=' + encodeURIComponent(url)
  455. })
  456. }
  457. }, */
  458. /**
  459. * 生命周期函数--监听页面初次渲染完成
  460. */
  461. onReady: function () {},
  462. /**
  463. * 生命周期函数--监听页面显示
  464. */
  465. onShow: function () {},
  466. /**
  467. * 生命周期函数--监听页面隐藏
  468. */
  469. onHide: function () {},
  470. /**
  471. * 生命周期函数--监听页面卸载
  472. */
  473. onUnload: function () {
  474. clearInterval(rep)
  475. },
  476. /**
  477. * 页面相关事件处理函数--监听用户下拉动作
  478. */
  479. onPullDownRefresh: function () {},
  480. /**
  481. * 页面上拉触底事件的处理函数
  482. */
  483. onReachBottom: function () {},
  484. /**
  485. * 用户点击右上角分享
  486. */
  487. onShareAppMessage: function () {
  488. let str = this.data.accountMsg.fliveshowurl;
  489. const url = str.slice(0, 8) + '04de51d4c1.' + str.slice(8)
  490. return {
  491. title: this.data.accountMsg.channelname,
  492. path: "/pages/webView/index?url=" + url,
  493. imageUrl: this.data.accountMsg.channelcoverimageurl
  494. }
  495. }
  496. })