index.js 3.2 KB

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