闫增涛
2024-03-27 696a0561d73970efdef2136d111269f626369fc9
assets/js/userAction.js
@@ -1,40 +1,20 @@
import config from "@/assets/js/config.js";
import jobApi from "./middleGround/api/job"; // newJobWithNewView // newSession,
import config from "./config.js";
import jobApi from "./middleGround/api/job";// newJobWithNewView // newSession,
export function setSessionGuid(type, id) {
  var cityCode = null;
  var SnIp = null;
  try {
    // eslint-disable-next-line
    SnIp = window.returnCitySN;
  } catch (error) {
    SnIp = null;
    console.log(error);
  }
  if (SnIp != undefined && SnIp != null) {
    cityCode = SnIp;
  } else {
    cityCode = {
      cip: "0.0.0.0",
      cname: "未知",
    };
  }
  const _city = cityCode.cname.substring(3);
  const _province = cityCode.cname.substring(0, 3);
  const params = {
    appRefCode: config.appRefCode,
    hostName: config.requestCtx,
    ipAddress: cityCode.cip,
    browser: myBrowser(),
    os: navigator.platform,
    ipAddress: "0.0.0.0", // 后台获取,前台随便传
    browser: 'WeChatApp',
    os: 'WeChat',
    device: "pc",
    province: _province,
    city: _city ? _city : _province,
    province: "未知",// 后台获取,前台随便传
    city: "未知",// 后台获取,前台随便传
  };
  jobApi.newSession(params).then(res => {
    storage.set("sessionGuid", res, 30);
    wx.setStorageSync("sessionGuid", res);
    setNewView(type, id);
  });
}
@@ -82,43 +62,13 @@
  },
};
function myBrowser() {
  const userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
  const isOpera = userAgent.indexOf("Opera") > -1;
  if (isOpera) {
    //判断是否Opera浏览器
    return "Opera";
  }
  if (userAgent.indexOf("Firefox") > -1) {
    //判断是否Firefox浏览器
    return "Firefox";
  }
  if (userAgent.indexOf("Chrome") > -1) {
    return "Chrome";
  }
  if (userAgent.indexOf("Safari") > -1) {
    //判断是否Safari浏览器
    return "Safari";
  }
  if (
    userAgent.indexOf("compatible") > -1 &&
    userAgent.indexOf("MSIE") > -1 &&
    !isOpera
  ) {
    //判断是否IE浏览器
    return "IE";
  }
  return "";
}
export function setNewView(type, id) {
  if (!sessionStorage.getItem("sessionGuid")) {
  if (!wx.getStorageSync("sessionGuid")) {
    setSessionGuid(type, id);
  }
  const sessionGuid = sessionStorage.getItem("sessionGuid");
  const fromPath = sessionStorage.getItem("fromPath");
  const toPath = sessionStorage.getItem("toPath");
  const sessionGuid = wx.getStorageSync("sessionGuid");
  const fromPath = wx.getStorageSync("fromPath");
  const toPath = wx.getStorageSync("toPath");
  if (sessionGuid) {
    let params = {
      sessionGuid: sessionGuid,
@@ -130,6 +80,6 @@
    if (id) {
      params[type] = id;
    }
    jobApi.newJobWithNewView(params).then(res => {});
    jobApi.newJobWithNewView(params).then(res => { });
  }
}