index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. const WXAPI = require('apifm-wxapi')
  2. const APP = getApp()
  3. // fixed首次打开不显示标题的bug
  4. APP.configLoadOK = () => {
  5. wx.setNavigationBarTitle({
  6. })
  7. }
  8. Date.prototype.format = function(format) {
  9. var date = {
  10. "M+": this.getMonth() + 1,
  11. "d+": this.getDate(),
  12. "h+": this.getHours(),
  13. "m+": this.getMinutes(),
  14. "s+": this.getSeconds(),
  15. "q+": Math.floor((this.getMonth() + 3) / 3),
  16. "S+": this.getMilliseconds()
  17. };
  18. if (/(y+)/i.test(format)) {
  19. format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  20. }
  21. for (var k in date) {
  22. if (new RegExp("(" + k + ")").test(format)) {
  23. format = format.replace(RegExp.$1, RegExp.$1.length == 1
  24. ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
  25. }
  26. }
  27. return format;
  28. }
  29. Page({
  30. /**
  31. * 页面的初始数据
  32. */
  33. data: {
  34. },
  35. onLoad: function (options) {
  36. this.wxaMpLiveRooms()
  37. },
  38. onShow: function () {
  39. },
  40. async wxaMpLiveRooms(){
  41. wx.showLoading({
  42. title: '',
  43. })
  44. const res = await WXAPI.wxaMpLiveRooms()
  45. wx.hideLoading({
  46. success: (res) => {},
  47. })
  48. if (res.code == 0 && res.data.length > 0) {
  49. res.data.forEach(ele => {
  50. if (ele.start_time) {
  51. ele.start_time_str = new Date(ele.start_time*1000).format('yyyy-MM-dd h:m:s')
  52. }
  53. })
  54. this.setData({
  55. aliveRooms: res.data
  56. })
  57. }
  58. },
  59. onPullDownRefresh: function() {
  60. // console.log('ppppp')
  61. this.setData({
  62. curPage: 1
  63. });
  64. this.wxaMpLiveRooms()
  65. wx.stopPullDownRefresh()
  66. },
  67. goLiveRoom(e) {
  68. const roomId = e.currentTarget.dataset.id
  69. const status = e.currentTarget.dataset.status
  70. if (status == 107 || status == 106 || status == 104) {
  71. return
  72. }
  73. wx.navigateTo({
  74. url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}`
  75. })
  76. }
  77. })