index.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Toast, Notify } from 'vant'
  2. import Clipboard from "clipboard";
  3. import { getWxToken, setWxToken, openError } from "@/utils/auth";
  4. import { getIsIdentity, supremeAuthority, getIsWx, getTypes, getTypesName, getUserData, getEmployeeMap, getCache, setCache, removeCache, returnDeptName, getEmployeeMapItem, returnFh } from '@/utils/auth'
  5. //判断环境/登录状态
  6. export function isWxEnv(type,data) {
  7. return new Promise((resolve, reject) => {
  8. if (getIsWx()) {
  9. if (getWxToken()&&localStorage.getItem('wx_user_info')) {
  10. // Toast("微信环境已授权");
  11. resolve()
  12. } else {
  13. // Toast.fail("微信环境未授权");
  14. reject(1)
  15. //测试用,正式隐藏
  16. doWeixinLogin(type,data);
  17. }
  18. } else {
  19. // Toast.fail("当前不在微信环境中,请在微信中打开浏览");
  20. // reject(2)
  21. if (getWxToken()&&localStorage.getItem('wx_user_info')) {
  22. resolve()
  23. } else {
  24. Toast.fail("当前不在微信环境中,请在微信中打开浏览");
  25. reject(2)
  26. }
  27. }
  28. })
  29. }
  30. //请求微信授权
  31. export function doWeixinLogin(type,data) {
  32. // let defaultUrl = 'https://3g954g5149.picp.vip/wx/mp/auth/wx65f4dde5ec7c31e7?marketing=1'
  33. // let dealerUrl = 'https://3g954g5149.picp.vip/wx/mp/auth/wx65f4dde5ec7c31e7?marketing=2&pid='
  34. // let timinalUrl = 'https://3g954g5149.picp.vip/wx/mp/auth/wx65f4dde5ec7c31e7?marketing=3&expendCode='
  35. let defaultUrl = `${process.env.BASE_API}/wx/mp/auth/wx65f4dde5ec7c31e7?marketing=1`
  36. let dealerUrl = `${process.env.BASE_API}/wx/mp/auth/wx65f4dde5ec7c31e7?marketing=2&pid=`
  37. let timinalUrl = `${process.env.BASE_API}/wx/mp/auth/wx65f4dde5ec7c31e7?marketing=3&expendCode=`
  38. if (getCache("isAndroid")) {
  39. if (type == 'pid'&&data) {
  40. window.open(`${dealerUrl}${data}`)
  41. } else if(type == 'code'&&data){
  42. window.open(`${timinalUrl}${data}`)
  43. }else{
  44. window.open(`${defaultUrl}`)
  45. }
  46. } else {
  47. if (type == 'pid'&&data) {
  48. window.location.href = `${dealerUrl}${data}`;
  49. } else if(type == 'code'&&data){
  50. window.location.href = `${timinalUrl}${data}`;
  51. }else{
  52. window.location.href = `${defaultUrl}`;
  53. }
  54. }
  55. }
  56. //复制(event必须为点击元素)
  57. export function copyLink(event) {
  58. let that = this;
  59. //这里是复制目标的类名
  60. let clipboard = new Clipboard(event, {
  61. text: function (trigger) {
  62. return trigger.getAttribute("aria-label");
  63. }
  64. });
  65. clipboard.on("success", function (e) {
  66. e.clearSelection(); //清除选中的文字的选择状态
  67. that.$toast.success("复制成功~");
  68. });
  69. clipboard.on("error", function (e) {
  70. console.error(e);
  71. });
  72. }