index.js 1.4 KB

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