index.js 3.9 KB

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