From 92230c9a97dc9ce9df3313d11d26999c04bb6b26 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期二, 15 七月 2025 13:12:48 +0800
Subject: [PATCH] 项目初始化

---
 src/utils/geek.ts |   72 ++++++++++++++++++++++++++++++++++++
 1 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/src/utils/geek.ts b/src/utils/geek.ts
new file mode 100644
index 0000000..f7560dd
--- /dev/null
+++ b/src/utils/geek.ts
@@ -0,0 +1,72 @@
+import { tansParams } from "./ruoyi";
+
+/**
+ * 鑾峰彇uuid
+ * @returns 鐢熸垚鐨剈uid瀛楃涓�
+ */
+export function generateUUID(): string {
+  let uuid = "";
+  const chars = "0123456789abcdef";
+
+  for (let i = 0; i < 32; i++) {
+    if (i === 8 || i === 12 || i === 16 || i === 20) {
+      uuid += "-";
+    }
+    uuid += chars[Math.floor(Math.random() * chars.length)];
+  }
+
+  return uuid;
+}
+
+/**
+ * 鑾峰彇code
+ * @returns 鐢熸垚鐨刢ode瀛楃涓�
+ */
+export async function getWxCode(appid?: string, redirect_uri?: string) {
+  // #ifdef H5
+  if (appid == undefined || redirect_uri == undefined) return ""
+  let code = "";
+
+  // 鎴彇url涓殑code鏂规硶
+  function getUrlCode() {
+    let url = location.search;
+    console.log(url);
+    let theRequest: any = new Object();
+    if (url.indexOf("?") != -1) {
+      let str = url.substr(1);
+      let strs = str.split("&");
+      for (let i = 0; i < strs.length; i++) {
+        theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
+      }
+    }
+    return theRequest as { code: string };
+  }
+
+  code = getUrlCode().code; // 鎴彇code
+  if (code == undefined || code == "" || code == null) {
+    // 濡傛灉娌℃湁code锛屽垯鍘昏姹�
+    console.log("h5");
+    let href = "https://open.weixin.qq.com/connect/oauth2/authorize?" +
+      tansParams({
+        appid: appid,
+        redirect_uri: redirect_uri,
+        response_type: "code",
+        scope: "snsapi_userinfo",
+        state: "STATE",
+      }) +
+      "#wechat_redirect";
+    console.log(href);
+    setTimeout(() => {
+      window.location.href = href;
+    }, 5000);
+  } else {
+    return code;
+  }
+  // #endif
+
+  // #ifdef MP-WEIXIN
+  // @ts-ignore
+  const res = await wx.login();
+  return res.code;
+  // #endif
+}

--
Gitblit v1.9.3