index.js 4.0 KB

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