index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 { spread } from "@/api/user";
  11. import Cache from "@/utils/cache";
  12. import { getCustomerType } from "@/api/api.js";
  13. import { getWorkermanUrl } from "@/api/kefu.js";
  14. import store from "@/store";
  15. /**
  16. * 绑定用户授权
  17. * @param {Object} puid
  18. */
  19. export function silenceBindingSpread(app) {
  20. //#ifdef H5
  21. let puid = Cache.get("spread"),
  22. code = 0,
  23. agent_id = Cache.get("agent_id");
  24. //#endif
  25. //#ifdef MP || APP-PLUS
  26. let puid = app.spid,
  27. code = app.code,
  28. agent_id = 0;
  29. //#endif
  30. puid = parseInt(puid);
  31. if (Number.isNaN(puid)) {
  32. puid = 0;
  33. }
  34. if ((code || puid || agent_id) && store.state.app.token) {
  35. spread({
  36. puid,
  37. code,
  38. agent_id,
  39. })
  40. .then((res) => {
  41. //#ifdef H5
  42. Cache.clear("spread");
  43. //#endif
  44. //#ifdef MP || APP-PLUS
  45. app.spid = 0;
  46. app.code = 0;
  47. //#endif
  48. })
  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/extension/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 || MP
  71. if (res.data.customer_url.indexOf("work.weixin.qq.com") > 0) {
  72. // #ifdef H5
  73. return (window.location.href = res.data.customer_url);
  74. // #endif
  75. // #ifdef MP
  76. uni.openCustomerServiceChat({
  77. extInfo: {
  78. url: res.data.customer_url,
  79. },
  80. corpId: res.data.customer_corpId,
  81. success(res) {},
  82. fail(err) {
  83. uni.showToast({
  84. title: err.errMsg,
  85. icon: "none",
  86. duration: 2000,
  87. });
  88. },
  89. });
  90. // #endif
  91. } else {
  92. uni.navigateTo({
  93. url: `/pages/annex/web_view/index?url=${res.data.customer_url}`,
  94. });
  95. }
  96. // #endif
  97. }
  98. });
  99. }
  100. export function parseQuery() {
  101. const res = {};
  102. const query = (location.href.split("?")[1] || "")
  103. .trim()
  104. .replace(/^(\?|#|&)/, "");
  105. if (!query) {
  106. return res;
  107. }
  108. query.split("&").forEach((param) => {
  109. const parts = param.replace(/\+/g, " ").split("=");
  110. const key = decodeURIComponent(parts.shift());
  111. const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
  112. if (res[key] === undefined) {
  113. res[key] = val;
  114. } else if (Array.isArray(res[key])) {
  115. res[key].push(val);
  116. } else {
  117. res[key] = [res[key], val];
  118. }
  119. });
  120. return res;
  121. }
  122. export function updateURLParameter(url, param, paramVal) {
  123. var newAdditionalURL = "";
  124. var tempArray = url.split("?");
  125. var baseURL = tempArray[0];
  126. var additionalURL = tempArray[1];
  127. var temp = "";
  128. if (additionalURL) {
  129. tempArray = additionalURL.split("&");
  130. for (let i = 0; i < tempArray.length; i++) {
  131. if (tempArray[i].split("=")[0] != param) {
  132. newAdditionalURL += temp + tempArray[i];
  133. temp = "&";
  134. }
  135. }
  136. }
  137. var rows_txt = temp + "" + param + "=" + paramVal;
  138. return baseURL + "?" + newAdditionalURL + rows_txt;
  139. }
  140. let VUE_APP_WS_URL = Cache.get("WORKERMAN_URL") || "";
  141. setTimeout(() => {
  142. getWorkermanUrl().then((res) => {
  143. Cache.set("WORKERMAN_URL", res.data.chat);
  144. VUE_APP_WS_URL = res.data.chat;
  145. });
  146. }, 1000);
  147. export { VUE_APP_WS_URL };
  148. export default parseQuery;