index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2023 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. import store from '@/store';
  21. /**
  22. * 绑定用户授权
  23. * @param {Object} puid
  24. */
  25. export function silenceBindingSpread(app) {
  26. //#ifdef H5
  27. let puid = Cache.get('spread'),
  28. code = 0;
  29. //#endif
  30. //#ifdef MP || APP-PLUS
  31. let puid = app.spid,
  32. code = app.code;
  33. //#endif
  34. puid = parseInt(puid);
  35. if (Number.isNaN(puid)) {
  36. puid = 0;
  37. }
  38. if ((code || puid) && store.state.app.token) {
  39. spread({
  40. puid,
  41. code
  42. }).then(res => {
  43. //#ifdef H5
  44. Cache.clear('spread');
  45. //#endif
  46. //#ifdef MP || APP-PLUS
  47. app.spid = 0;
  48. app.code = 0;
  49. //#endif
  50. }).catch(res => {});
  51. }
  52. }
  53. export function isWeixin() {
  54. return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
  55. }
  56. export function getCustomer(url) {
  57. getCustomerType().then(res => {
  58. let type = res.data.customer_type
  59. if (type == '0') {
  60. uni.navigateTo({
  61. url: url || '/pages/extension/customer_list/chat'
  62. })
  63. } else if (type == '1') {
  64. uni.makePhoneCall({
  65. phoneNumber: res.data.customer_phone //客服电话
  66. });
  67. } else {
  68. // #ifdef APP-PLUS
  69. plus.runtime.openURL(res.data.customer_url)
  70. // #endif
  71. // #ifdef H5 || MP
  72. if (res.data.customer_url.indexOf('work.weixin.qq.com') > 0) {
  73. // #ifdef H5
  74. return window.location.href = res.data.customer_url
  75. // #endif
  76. // #ifdef MP
  77. uni.openCustomerServiceChat({
  78. extInfo: {
  79. url: res.data.customer_url
  80. },
  81. corpId: res.data.customer_corpId,
  82. success(res) {},
  83. fail(err) {
  84. uni.showToast({
  85. title: err.errMsg,
  86. icon: 'none',
  87. duration: 2000
  88. });
  89. }
  90. })
  91. // #endif
  92. } else {
  93. uni.navigateTo({
  94. url: `/pages/annex/web_view/index?url=${res.data.customer_url}`
  95. });
  96. }
  97. // #endif
  98. }
  99. })
  100. }
  101. export function parseQuery() {
  102. const res = {};
  103. const query = (location.href.split("?")[1] || "")
  104. .trim()
  105. .replace(/^(\?|#|&)/, "");
  106. if (!query) {
  107. return res;
  108. }
  109. query.split("&").forEach(param => {
  110. const parts = param.replace(/\+/g, " ").split("=");
  111. const key = decodeURIComponent(parts.shift());
  112. const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
  113. if (res[key] === undefined) {
  114. res[key] = val;
  115. } else if (Array.isArray(res[key])) {
  116. res[key].push(val);
  117. } else {
  118. res[key] = [res[key], val];
  119. }
  120. });
  121. return res;
  122. }
  123. export function updateURLParameter(url, param, paramVal) {
  124. var newAdditionalURL = "";
  125. var tempArray = url.split("?");
  126. var baseURL = tempArray[0];
  127. var additionalURL = tempArray[1];
  128. var temp = "";
  129. if (additionalURL) {
  130. tempArray = additionalURL.split("&");
  131. for (let i = 0; i < tempArray.length; i++) {
  132. if (tempArray[i].split('=')[0] != param) {
  133. newAdditionalURL += temp + tempArray[i];
  134. temp = "&";
  135. }
  136. }
  137. }
  138. var rows_txt = temp + "" + param + "=" + paramVal;
  139. return baseURL + "?" + newAdditionalURL + rows_txt;
  140. }
  141. let VUE_APP_WS_URL = Cache.get('WORKERMAN_URL') || ''
  142. getWorkermanUrl().then(res => {
  143. Cache.set('WORKERMAN_URL', res.data.chat)
  144. VUE_APP_WS_URL = res.data.chat;
  145. })
  146. export {
  147. VUE_APP_WS_URL
  148. }
  149. export default parseQuery;