From ef37c59e055a990ce247b265b27d3fcef430a243 Mon Sep 17 00:00:00 2001
From: 杨磊 <505174330@qq.com>
Date: 星期五, 15 八月 2025 10:19:18 +0800
Subject: [PATCH] first submit

---
 src/assets/js/userAction.js |  140 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 140 insertions(+), 0 deletions(-)

diff --git a/src/assets/js/userAction.js b/src/assets/js/userAction.js
new file mode 100644
index 0000000..98952f6
--- /dev/null
+++ b/src/assets/js/userAction.js
@@ -0,0 +1,140 @@
+import config from "@/assets/js/config.js";
+import toolClass from "@/assets/js/toolClass";
+
+
+import jobApi
+// newSession,
+// newJobWithNewView
+from "./middleGround/api/job"
+
+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,
+    device: "pc",
+    province: _province,
+    city: _city ? _city : _province,
+  };
+
+  jobApi.newSession(params).then((res) => {
+    storage.set("sessionGuid", res, 30);
+    setNewView(type, id)
+  });
+}
+
+export const storage = {
+  /*
+   * set 瀛樺偍鏂规硶
+   * @ param {String} 	key 閿�
+   * @ param {String} 	value 鍊硷紝
+   * @ param {String} 	expired 杩囨湡鏃堕棿锛屼互鍒嗛挓涓哄崟浣嶏紝闈炲繀椤�
+   */
+  set(key, val, expired) {
+    if (typeof val !== "string") {
+      val = JSON.stringify(val);
+    }
+    window.sessionStorage.setItem(key, val);
+    if (expired) {
+      window.sessionStorage.setItem(
+        `${key}__expires__`,
+        `${Date.now() + 1000 * 60 * expired}`
+      );
+    }
+  },
+  /*
+   * get 鑾峰彇鏂规硶
+   * @ param {String} 	key 閿�
+   * @ param {String} 	expired 瀛樺偍鏃朵负闈炲繀椤诲瓧娈碉紝鎵�浠ユ湁鍙兘鍙栦笉鍒帮紝榛樿涓� Date.now+1
+   */
+  get(key) {
+    const expired =
+      window.sessionStorage.getItem(`${key}__expires__`) || Date.now + 1;
+    const now = Date.now();
+
+    if (now >= expired) {
+      window.sessionStorage.removeItem(key);
+      return;
+    }
+    let val = window.sessionStorage.getItem(key);
+    try {
+      val = JSON.parse(val);
+    } catch (e) {
+      return e
+    }
+    return val;
+  }
+};
+
+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")) {
+    setSessionGuid(type, id)
+  }
+
+  const sessionGuid = sessionStorage.getItem("sessionGuid");
+  const fromPath = sessionStorage.getItem("fromPath");
+  const toPath = sessionStorage.getItem("toPath");
+  if (sessionGuid) {
+    let params = {
+      sessionGuid: sessionGuid,
+      appRefCode: config.appRefCode,
+      type: "View",
+      url: toPath == null ? "/" : toPath,
+      ref: fromPath == null ? "/" : fromPath
+    };
+    if (id) {
+      params[type] = id;
+    }
+    jobApi.newJobWithNewView(params).then((res) => {});
+  }
+}
\ No newline at end of file

--
Gitblit v1.9.1