index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. import {
  11. spread
  12. } from "@/api/user";
  13. import Cache from "@/utils/cache";
  14. import Store from '@/store/index';
  15. export function configMap(args, init) {
  16. if(Array.isArray(args)) {
  17. return args.reduce((i, v)=>{
  18. i[v] = () => Store.getters.globalData[v];
  19. return i;
  20. }, init || {})
  21. }else{
  22. return Object.keys(args).reduce((i, v)=>{
  23. i[v] = () => {
  24. const val = Store.getters.globalData[v];
  25. return (val === undefined || val === null || val === '') ? args[v] : val;
  26. };
  27. return i;
  28. }, init || {})
  29. }
  30. }
  31. export function redirect(url){
  32. uni.switchTab({
  33. url,
  34. fail(){
  35. uni.redirectTo({
  36. url
  37. })
  38. }
  39. })
  40. }
  41. /**
  42. * 转换商户跳转链接, 自动追加商户 id
  43. * @param {string} path
  44. * @param {int} mer_id
  45. * @param {string} name 商户id 参数名, 默认 mer_id
  46. */
  47. export function merPath(path, mer_id, name){
  48. if(!mer_id) return path;
  49. path += ((path.indexOf('?') > -1 ? '&' : '?') + (name || 'mer_id') + '=' + mer_id);
  50. return path;
  51. }
  52. /**
  53. * 绑定用户授权
  54. * @param {Object} puid
  55. */
  56. export function silenceBindingSpread() {
  57. //#ifdef H5
  58. let puid = Cache.get('spread');
  59. //#endif
  60. //#ifdef MP || APP-PLUS
  61. let puid = getApp().globalData.spid;
  62. if (!puid) {
  63. puid = getApp().globalData.code;
  64. }
  65. //#endif
  66. puid = parseInt(puid);
  67. if (Number.isNaN(puid)) {
  68. puid = 0;
  69. }
  70. if (puid) {
  71. //#ifdef H5
  72. Cache.clear('spread');
  73. //#endif
  74. //#ifdef MP || APP-PLUS
  75. getApp().globalData.spid = 0;
  76. getApp().globalData.code = 0;
  77. //#endif
  78. }
  79. }
  80. export function isWeixin() {
  81. return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
  82. }
  83. export function parseQuery() {
  84. const res = {};
  85. const query = (location.href.split("?")[1] || "")
  86. .trim()
  87. .replace(/^(\?|#|&)/, "");
  88. if (!query) {
  89. return res;
  90. }
  91. query.split("&").forEach(param => {
  92. const parts = param.replace(/\+/g, " ").split("=");
  93. const key = decodeURIComponent(parts.shift());
  94. const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
  95. if (res[key] === undefined) {
  96. res[key] = val;
  97. } else if (Array.isArray(res[key])) {
  98. res[key].push(val);
  99. } else {
  100. res[key] = [res[key], val];
  101. }
  102. });
  103. return res;
  104. }
  105. // +----------------------------------------------------------------------
  106. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  107. // +----------------------------------------------------------------------
  108. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  109. // +----------------------------------------------------------------------
  110. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  111. // +----------------------------------------------------------------------
  112. // | Author: CRMEB Team <admin@crmeb.com>
  113. // +----------------------------------------------------------------------
  114. let token = ''
  115. try {
  116. token = uni.getStorageSync('LOGIN_STATUS_TOKEN')
  117. } catch (error) {
  118. }
  119. // const VUE_APP_WS_URL = process.env.VUE_APP_WS_URL || `ws://${location.hostname}?type=user&token=${token}`;
  120. // const VUE_APP_WS_URL = `wss://mer.crmeb.net?type=user&token=${token}`
  121. export default parseQuery;