mixin.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const NET = require('@/utils/request')
  2. const API = require('@/config/api')
  3. import { funMixin } from '../../config/mixin'
  4. export const commonMixin = {
  5. mixins: [ funMixin ],
  6. data() {
  7. return {
  8. appid: 'wx123456789abcdefg',
  9. roomId: [], // 填写具体的房间号
  10. roomList: [],
  11. page: {
  12. page: 1,
  13. pageSize: 6
  14. }
  15. }
  16. },
  17. props: {
  18. terminal: {
  19. type: Number,
  20. default: 4
  21. },
  22. typeId: {
  23. type: Number,
  24. default: 1
  25. },
  26. shopId: {
  27. type: Number,
  28. default: 0
  29. },
  30. componentContent: {
  31. type: Object
  32. }
  33. },
  34. created() {
  35. this.getLiveRooms()
  36. },
  37. methods: {
  38. // 获取直播间列表
  39. getLiveRooms() {
  40. NET.request(API.LiveRoomes, this.page, 'get').then((res) => {
  41. this.roomList = res.data.list
  42. })
  43. },
  44. toLiveRoom(item) {
  45. this.roomId.push(item.roomid)
  46. if (!this.appid || !this.roomId.length) {
  47. return
  48. }
  49. // 路由参数
  50. const customParams = encodeURIComponent(JSON.stringify({ path: 'livePage/index', pid: 1 }))
  51. // let customParams
  52. // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  53. // #ifdef MP-WEIXIN
  54. wx.navigateTo({
  55. url: `plugin-private://${this.appid}/pages/live-player-plugin?room_id=${this.roomId}&custom_params=${customParams}`
  56. })
  57. // #endif
  58. }
  59. }
  60. }