From 92249648c46009bb9fa6a5587f6ef63aef03e0d8 Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 10 Sep 2025 09:31:56 +0800 Subject: [PATCH] 's' --- src/pages/index/index.jsx | 76 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/src/pages/index/index.jsx b/src/pages/index/index.jsx index fa71bdc..7129a55 100644 --- a/src/pages/index/index.jsx +++ b/src/pages/index/index.jsx @@ -335,6 +335,31 @@ const Index = () => { // window.alert(value) setopen(value); }; + const createUser = (username, password) => { + Taro.request({ + method: "POST", + url: `${process.env.TARO_API_API}/create_user`, + data: { + username: username, + password: password || "123456", // 如果没有传入密码,则使用默认密码 + }, + header: { + "content-type": "application/json", + }, + success: function (res) { + console.log("用户创建结果:", res.data); + window.localStorage.setItem("username", res?.data?.username); + window.localStorage.setItem("password", res?.data?.password); + }, + fail: function (err) { + console.error("创建用户失败:", err); + Taro.showToast({ + title: "请求失败", + icon: "error", + }); + }, + }); + }; const payh5 = (type, total_fee = 1000) => { // console.log("111"); @@ -372,8 +397,16 @@ const Index = () => { function (res) { // 支付成功 if (res.err_msg == "get_brand_wcpay_request:ok") { + // 新增memos用户 + // 动态生成用户名,若 username 没传入则使用默认值 "user" + 当前时间戳 + const finalUsername = `user${Date.now()}`; + createUser(finalUsername, "123456"); window.localStorage.setItem(type, 1); //订单类型 book/meetup/video/vip + window.localStorage.setItem("username", finalUsername); + window.localStorage.setItem("password", "123456"); WeixinJSBridge.call("closeWindow"); + } else { + window.alert("支付取消/失败"); } } ); @@ -386,6 +419,41 @@ const Index = () => { url: "/pages/book/index", }); }; + const handleCopyUsername = () => { + Taro.setClipboardData({ + data: window.localStorage.getItem("username"), // 复制账号 + success: () => { + Taro.showToast({ + title: "账号已复制", + icon: "success", + }); + }, + fail: () => { + Taro.showToast({ + title: "复制失败", + icon: "none", + }); + }, + }); + }; + + const handleCopyPassword = () => { + Taro.setClipboardData({ + data: "123456", // 复制密码 + success: () => { + Taro.showToast({ + title: "密码已复制", + icon: "success", + }); + }, + fail: () => { + Taro.showToast({ + title: "复制失败", + icon: "none", + }); + }, + }); + }; return ( <> @@ -477,7 +545,6 @@ const Index = () => { ) : ( - { window.location.href = `https://memos.hackrobot.org`; @@ -485,12 +552,15 @@ const Index = () => { > 👉星球地址: memos.hackrobot.org - + 账号:{window.localStorage.getItem("username")} + + 密码:{"123456"}{" "} 添加 微信好友: hackrobot - 获取 账号 + + {/* 获取 账号 */} )}