appletUtils.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * 小程序工具
  3. */
  4. import { getQueryParams } from './h5Utils.js'
  5. // 跳转视频号直播
  6. export const toChannelsLive = (finderUserName = '') => {
  7. // #ifdef MP-WEIXIN
  8. wx.getChannelsLiveInfo({
  9. finderUserName,
  10. success: info => {
  11. const { feedId, nonceId } = info
  12. wx.openChannelsLive({
  13. finderUserName,
  14. feedId,
  15. nonceId,
  16. fail: (err) => {
  17. console.log(err);
  18. uni.showToast({
  19. title: err?.errMsg
  20. })
  21. }
  22. })
  23. },
  24. fail: (err) => {
  25. console.log(err);
  26. uni.showToast({
  27. title: err?.errMsg
  28. })
  29. }
  30. })
  31. // #endif
  32. // #ifndef MP-WEIXIN
  33. console.error('只支持在微信小程序中调用')
  34. // #endif
  35. }
  36. // 获取小程序分享参数
  37. export const getWxShareParams = (queryParams, title, imageUrl, path) => {
  38. const { appName } = uni.getSystemInfoSync()
  39. const pages = getCurrentPages()
  40. const { route, options, $page } = pages[pages.length - 1]
  41. const params = queryParams || options || getQueryParams($page?.fullPath)
  42. title = title || appName
  43. path = path || '/' + route
  44. path += Object.keys(params).reduce((prev, curr) => curr ? `${prev}${curr}=${params[curr]}&` : prev, path.includes('?') ? '&' : '?').slice(0, -1)
  45. console.log('getWxShareParams', title, path, imageUrl);
  46. return {
  47. title,
  48. path,
  49. imageUrl
  50. }
  51. }
  52. // 获取场景参数
  53. export const getSceneParams = () => {
  54. const { query } = uni.getLaunchOptionsSync()
  55. return getQueryParams(decodeURIComponent(query.scene))
  56. }