index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2021 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 {
  15. getCustomerType
  16. } from '@/api/api.js'
  17. import {
  18. getWorkermanUrl
  19. } from '@/api/kefu.js'
  20. /**
  21. * 绑定用户授权
  22. * @param {Object} puid
  23. */
  24. export function silenceBindingSpread() {
  25. //#ifdef H5
  26. let puid = Cache.get('spread'),
  27. code = 0;
  28. //#endif
  29. //#ifdef MP || APP-PLUS
  30. let puid = getApp().globalData.spid,
  31. code = getApp().globalData.code;
  32. //#endif
  33. puid = parseInt(puid);
  34. if (Number.isNaN(puid)) {
  35. puid = 0;
  36. }
  37. if (puid) {
  38. spread({
  39. puid,
  40. code
  41. }).then(res => {
  42. //#ifdef H5
  43. Cache.clear('spread');
  44. //#endif
  45. //#ifdef MP || APP-PLUS
  46. getApp().globalData.spid = 0;
  47. getApp().globalData.code = 0;
  48. //#endif
  49. }).catch(res => {});
  50. }
  51. }
  52. export function isWeixin() {
  53. return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
  54. }
  55. export function getCustomer(url) {
  56. getCustomerType().then(res => {
  57. let type = res.data.customer_type
  58. if (type == '0') {
  59. uni.navigateTo({
  60. url: url || '/pages/customer_list/chat'
  61. })
  62. } else if (type == '1') {
  63. uni.makePhoneCall({
  64. phoneNumber: res.data.customer_phone //客服电话
  65. });
  66. } else {
  67. // #ifdef APP-PLUS
  68. plus.runtime.openURL(res.data.customer_url)
  69. // #endif
  70. // #ifdef H5
  71. // window.open(res.data.customer_url, '_blank')
  72. uni.navigateTo({
  73. url: `/pages/annex/web_view/index?url=${res.data.customer_url}`
  74. });
  75. // #endif
  76. }
  77. })
  78. }
  79. export function parseQuery() {
  80. const res = {};
  81. const query = (location.href.split("?")[1] || "")
  82. .trim()
  83. .replace(/^(\?|#|&)/, "");
  84. if (!query) {
  85. return res;
  86. }
  87. query.split("&").forEach(param => {
  88. const parts = param.replace(/\+/g, " ").split("=");
  89. const key = decodeURIComponent(parts.shift());
  90. const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
  91. if (res[key] === undefined) {
  92. res[key] = val;
  93. } else if (Array.isArray(res[key])) {
  94. res[key].push(val);
  95. } else {
  96. res[key] = [res[key], val];
  97. }
  98. });
  99. return res;
  100. }
  101. let VUE_APP_WS_URL = Cache.get('WORKERMAN_URL') || ''
  102. getWorkermanUrl().then(res => {
  103. Cache.set('WORKERMAN_URL', res.data.chat)
  104. VUE_APP_WS_URL = res.data.chat;
  105. })
  106. export {
  107. VUE_APP_WS_URL
  108. }
  109. export default parseQuery;