index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * Platform v1.0.0
  3. * @Class Platform
  4. * @description shopro-platform 1.0.0 全平台兼容
  5. * @Author lidongtony
  6. * @Date 2021-04-07
  7. * @Email lidongtony@qq.com
  8. */
  9. // #ifdef H5
  10. // 微信H5
  11. import wxsdk from '@/shopro/wechat/sdk';
  12. import {
  13. router
  14. } from '@/shopro/router';
  15. // #endif
  16. export default {
  17. // 获取当前运行平台
  18. get() {
  19. let platform = '';
  20. // #ifdef H5
  21. wxsdk.isWechat() ? (platform = 'wxOfficialAccount') : (platform = 'H5');
  22. // #endif
  23. // #ifdef APP-PLUS
  24. platform = 'App';
  25. // #endif
  26. // #ifdef MP-WEIXIN
  27. platform = 'wxMiniProgram';
  28. // #endif
  29. // #ifdef MP-ALIPAY
  30. platform = 'alipayMiniProgram';
  31. // #endif
  32. if (platform !== '') {
  33. uni.setStorageSync('platform', platform);
  34. } else {
  35. uni.showToast({
  36. title: '暂不支持该平台',
  37. icon: 'none'
  38. });
  39. }
  40. return platform;
  41. },
  42. set(platform) {
  43. uni.setStorageSync('platform', platform);
  44. return platform;
  45. },
  46. // 检测当前运行机型
  47. device() {
  48. return uni.getSystemInfoSync().platform;
  49. },
  50. // 获取前端真实主机
  51. host() {
  52. let host = location.origin;
  53. let basePath = router.$route.options.base;
  54. let mode = router.$route.options.mode;
  55. host += basePath;
  56. if (mode === 'hash') {
  57. host += '#/';
  58. }
  59. return host;
  60. },
  61. // 处理wechat jssdk 签名网址(针对IOS微信浏览器做优化)
  62. entry() {
  63. let that = this;
  64. var entryUrl = location.href;
  65. if (this.device() === 'ios') {
  66. if (typeof(location.entryUrl) !== 'undefined') {
  67. entryUrl = location.entryUrl;
  68. } else {
  69. location.entryUrl = entryUrl;
  70. }
  71. }
  72. return entryUrl;
  73. },
  74. }