index.js 2.0 KB

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