Files
gitlab-instance-0a899031_ci…/src/pages/index/index.jsx
hackrobot 8134ccb2eb update
2024-08-08 20:09:36 +08:00

698 lines
22 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Component } from "react";
import Taro from "@tarojs/taro";
import { View, Text, Image, Button } from "@tarojs/components";
import "./index.scss";
import { AtTabBar } from "taro-ui";
import React, { useCallback, useEffect, useState } from "react";
import { AtGrid } from "taro-ui";
import { Swiper, SwiperItem } from "@tarojs/components";
import { AtCard } from "taro-ui";
import { AtImagePicker } from "taro-ui";
import { AtButton } from "taro-ui";
import { AtSearchBar } from "taro-ui";
import { Picker } from "@tarojs/components";
import { AtList, AtListItem, AtNavBar, AtTag, AtMessage } from "taro-ui";
import {
AtModal,
AtModalHeader,
AtModalContent,
AtModalAction,
AtAvatar,
AtAccordion,
} from "taro-ui";
import { AtToast } from "taro-ui";
import { AtIcon } from "taro-ui";
import { VIEW } from "@tarojs/runtime";
import "animate.css";
import touxiang from "../../images/touxiang.png";
import emoji from "../../images/emoji.png";
import phone from "../../images/phone.png";
import robot from "../../images/robot.png";
import nomad from "../../images/nomad.png";
import book from "../../images/book.png";
import qrcode from "../../images/qrcode.png";
import meetup from "../../images/meetup.jpg";
import bookqr from "../../images/bookqr.jpg";
// export default class Index extends Component {
const Index = () => {
const [current, setcurrent] = useState(0);
const [openId, setopenId] = useState(null);
const [wxid, setwxid] = useState(null);
const [userInfo, setuserInfo] = useState({});
const [open, setopen] = useState(false);
const [referer, setreferer] = useState(window.document.referrer);
const [isOpened, setisOpened] = useState(false);
const [meetupQR, setmeetupQR] = useState(false);
const [bookToast, setbookToast] = useState(false);
const [meetupToast, setmeetupToast] = useState(false);
const [joinMeetup, setjoinMeetup] = useState(false);
const [isWeChat, setisWeChat] = useState(false);
const getOpenidFromUrl = (url) => {
const pattern = /[?&]openid=([^&#]+)/;
const match = url.match(pattern);
if (match) {
return match[1];
}
return null;
};
// 是否在微信客户端
const isWeChatFun = () => {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("micromessenger") != -1) {
setisWeChat(true);
return true;
} else {
setisWeChat(false);
return false;
}
};
// 获取openid
const getOpenid = () => {
// let newparams = Taro.getCurrentInstance().router.params;
// let urlopenid = newparams.openid;
// hash模式
// http://192.168.31.245:10086/?openid=o7LFAwR32hWGq9XOpd7ZxK1wZxq8#/pages/index/index
let hashopenid = null;
if (window.location.href.includes("openid")) {
hashopenid = getOpenidFromUrl(window.location.href);
} else {
// hashopenid = window.localStorage.getItem("openid");
}
if (!!hashopenid && hashopenid != "undefined" && hashopenid != "null") {
// 获取到openid
window.localStorage.setItem("openid", hashopenid);
setopenId(hashopenid);
// window.alert(hashopenid);
// 查询数据库是否存在openid
Taro.request({
method: "GET",
url: `/api/user/${hashopenid}`, //仅为示例,并非真实的接口地址
// url: `/api/user/${window.localStorage.getItem("openid")}`, //仅为示例,并非真实的接口地址
success: function (res) {
if (res?.data?.userInfo) {
// 有完整的用户信息userInfo
setuserInfo(res?.data?.userInfo);
window.localStorage.setItem("userInfo", userInfo);
}
},
complete: function (finy) {
// 获取wxid参数
getWxidFromUrl();
},
});
} else {
let nowUrl = window.location.href;
window.localStorage.removeItem("openid");
let payUrl = `https://payjs.cn/api/openid?mchid=1561724891&callback_url=${nowUrl}`;
window.location.href = payUrl;
}
};
// 获取更新用户信息
const getUserinfo = (wxid) => {
Taro.request({
method: "GET",
url: `/api/user/${wxid}`, //仅为示例,并非真实的接口地址
// url: `/api/user/${window.localStorage.getItem("openid")}`, //仅为示例,并非真实的接口地址
success: function (res) {
if (res?.data?.userInfo) {
//判断wxid是否存在
if (res?.data?.userInfo?.openid) {
// 有完整的用户信息userInfo
setuserInfo(res?.data?.userInfo);
window.localStorage.setItem("userInfo", userInfo);
}
}
},
complete: function (finy) {},
});
};
// 获取url中的wxid
const getWxidFromUrl = () => {
const urlParams = new URLSearchParams(window.location.search);
const urlwxid = urlParams.get("wxid");
if (!!urlwxid) {
setwxid(urlwxid);
window.localStorage.setItem("wxid", wxid);
// 优先查询openid是否存在数据库
Taro.request({
method: "GET",
url: `/api/user/${urlwxid}`, //仅为示例,并非真实的接口地址
// url: `/api/user/${window.localStorage.getItem("openid")}`, //仅为示例,并非真实的接口地址
success: function (res) {
if (res?.data?.userInfo) {
//判断wxid是否存在
if (res?.data?.userInfo?.openid) {
// window.alert(res?.data?.userInfo?.openid);
// window.alert(window.localStorage.getItem("openid"));
if (
res?.data?.userInfo?.openid !==
window.localStorage.getItem("openid")
) {
// 删除其他用户的wxid
window.localStorage.removeItem("userInfo");
window.localStorage.removeItem("openid");
window.localStorage.removeItem("wxid");
window.location.href = "http://nomad.hackrobot.cn";
} else {
// 有完整的用户信息userInfo
setuserInfo(res?.data?.userInfo);
window.localStorage.setItem("userInfo", userInfo);
}
} else {
// 绑定wxid与openid到数据库
wxidTapopenid(urlwxid);
}
} else {
// 新增wxid用户
}
},
complete: function (finy) {
// tg消息通知
tgMessage();
},
});
} else {
// tg消息通知
tgMessage();
}
return wxid;
};
// 绑定wxid与openid
const wxidTapopenid = (newWxid) => {
const userUpdateData = {
openid: window.localStorage.getItem("openid"), // 只更新 openid 字段
};
Taro.request({
method: "PUT",
// url: `/api/user/${urlwxid}`, //仅为示例,并非真实的接口地址
url: `/api/user/${newWxid}`, //仅为示例,并非真实的接口地址
data: userUpdateData,
header: {
"Content-Type": "application/json",
},
success: function (res) {},
fail: function (err) {},
complete: function (finy) {},
});
};
// 新增openid用户
const addopenidUser = () => {
const userUpdateData = {
openid: window.localStorage.getItem("openid"), // 只更新 openid 字段
};
Taro.request({
method: "GET",
// url: `/api/user/${urlwxid}`, //仅为示例,并非真实的接口地址
url: `/api/user/${window.localStorage.getItem("openid")}`, //仅为示例,并非真实的接口地址
data: userUpdateData,
header: {
"Content-Type": "application/json",
},
success: function (res) {},
fail: function (err) {},
complete: function (finy) {},
});
};
// 网页查看通知
const tgMessage = () => {
Taro.request({
method: "GET",
url: `/api/tgMessage?openid=${window.localStorage.getItem("openid")}`, //仅为示例,并非真实的接口地址
// url: "https://pay.hackrobot.cn/api/payh5", //仅为示例,并非真实的接口地址
success: function (res) {
console.log("访问提醒发送成功");
},
});
};
// 入群申请
useEffect(() => {
let inwechat = isWeChatFun();
if (inwechat) {
// 获取openId
getOpenid();
} else {
// window.alert('不在微信')
}
}, []);
const goBack = () => {
Taro.navigateBack({});
};
const handleClick = (value) => {
// window.alert(value)
setopen(value);
};
return (
<View className="index">
{/* <Button
onClick={() => {
// 跳转到目的页面,在当前页面打开
Taro.navigateTo({
url: "/pages/group/index",
});
}}
>
111
</Button> */}
{/* 公众号 */}
<View
className="index-title"
onClick={() => {
// window.location.href=""
}}
>
<AtAvatar
size="small"
circle
// image="https://www.hackrobot.cn/wp-content/uploads/2023/05/cropped-cropped-Screenshot-2023-05-22-at-17.26.38.png"
image={touxiang}
></AtAvatar>
<View className="yidooplanet">异度世界</View>
</View>
{/* 标签 */}
<View className="index-tags animate__animated animate__pulse">
<AtTag className="index-AtTag" type="primary" AtNavBar={true} circle>
独立开发者
</AtTag>
<AtTag className="index-AtTag" type="primary" AtNavBar={true} circle>
跨境电商
</AtTag>
<AtTag className="index-AtTag" type="primary" AtNavBar={true} circle>
树莓派
</AtTag>
</View>
<View className="index-article">
{/* className="at-article__p" */}
<View>
普通的独立开发者,平时喜欢折腾树莓派
<br />
副业是做跨境电商
<br />
做一个<span className="spanText">数字游民</span>ing😎
</View>
</View>
{/* 付费合集 */}
<View className="index-list">
<AtList>
<AtListItem
title="云手机"
arrow="right"
// hasBorder={false}
thumb={phone}
onClick={() => {
window.location.href =
"https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzU4NTgyNDUxNw==&action=getalbum&album_id=3403853254399082501#wechat_redirect";
}}
/>
<AtListItem
title="微信机器人"
arrow="right"
// hasBorder={false}
thumb={robot}
onClick={() => {
window.location.href =
"https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzU4NTgyNDUxNw==&action=getalbum&album_id=3545545030499270661#wechat_redirect";
}}
/>
{/* <AtListItem
title="数字游民"
arrow="right"
// hasBorder={false}
thumb={nomad}
onClick={() => {
window.location.href =
"https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzU4NTgyNDUxNw==&action=getalbum&album_id=3545541605766168582#wechat_redirect";
}}
/> */}
</AtList>
</View>
{/* 在线图书 */}
{/* 参考资料https://readmake.com/ */}
<View className="index-book">
<View className="bookImg">
<Image
style="width: 40%px;height:100%;background: #fff;"
src={book}
/>
</View>
<View className="book-middle"></View>
<View className="nomad-right">
<View className="nomad-title">
<Image
style="width: 30px;height:30px;background: #fff;"
src={nomad}
/>
<View className="bookNmae">数字游民手册</View>
</View>
<View className="subtitle">多元自动化收入</View>
<View className="bookText">
{/* 两个核心主题: <br /> */}
1. 微信运营:云手机+机器人+AIGC
<br />
2. 自媒体:youtube获利+wordpress <br />
3. 跨境电商:amazon
<br />
4. 软件saas:独立开发
<br />
5. 知识付费:如何出版一本书?
<br />
</View>
<View
className="bookPrice"
onClick={() => {
return false
if (!!userInfo?.ebook) {
// 已预约
Taro.atMessage({
message: "已预约成功",
type: "warning",
});
} else {
if (!!wxid) {
// 发起预约
const userUpdateData = {
ebook: 1, // 只更新 openid 字段
};
Taro.request({
method: "PUT",
// url: `/api/user/${urlwxid}`, //仅为示例,并非真实的接口地址
url: `/api/user/${wxid}`, //仅为示例,并非真实的接口地址
data: userUpdateData,
header: {
"Content-Type": "application/json",
},
success: function (res) {
// 预约成功
// Taro.atMessage({
// message: "预约成功",
// type: "success",
// });
if (res.data.code == "200") {
setbookToast(true);
}
},
fail: function (err) {},
complete: function (finy) {
// setTimeout(() => {
// window.location.reload();
// }, 2000);
// getUserinfo()
},
});
} else {
setmeetupQR(true);
}
}
}}
>
<View
className="join"
// style={{ backgroundColor: !!userInfo?.ebook ? "#1890ff" : null }}
style={{ backgroundColor: !!userInfo?.ebook ? "#1890ff" : "#1890ff" }}
>
{/* {!!userInfo?.ebook ? "已预约" : "预约"} */}
{!!userInfo?.ebook ? "未完结" : "未完结"}
</View>
</View>
</View>
</View>
{/* 软件下载 */}
<View className="software">
<View className="emojiTitle">
<span style={{ color: "green" }}>|</span>
</View>
<View className="emojitext">
<View>
<AtIcon value="file-generic" size="30" color="#F00"></AtIcon>{" "}
markdown转emoji编辑器
</View>
<AtIcon
value="download-cloud"
size="30"
color="#F00"
onClick={() => {
setisOpened(true);
}}
></AtIcon>
</View>
{/* <View className="software-emoji">
<Image
style="width: 80%;height: 240px;background: #fff;"
src={emoji}
/>
</View> */}
</View>
<View className="index-meetup animate__animated animate__pulse">
<AtCard
// note="提示文字"
extra="2024/08/24"
title="线下活动"
thumb="http://img12.360buyimg.com/jdphoto/s72x72_jfs/t10660/330/203667368/1672/801735d7/59c85643N31e68303.png"
>
<View className="meetup-card">
{/* 左边 */}
<View className="meetup-left">
<Image
style="width: 100%;height: 100px;background: #fff;"
src={meetup}
/>
</View>
{/* 右边 */}
<View className="meetup-right">
<View className="title">数字游民 | 自由职业者沙龙</View>
<View className="address">
<AtIcon value="map-pin" size="30" color="#F00"></AtIcon>
<span>深圳市龙华区</span>
</View>
<View className="meetBtn">
<View>
<AtIcon value="clock" size="30" color="#F00"></AtIcon>
19:00--21:00
</View>
<View
className="join"
style={{
backgroundColor: !!userInfo?.activity_status
? "#1890ff"
// : null,
: "#1890ff"
//
}}
onClick={() => {
return false
if (userInfo?.activity_status == "1") {
// 已预约
Taro.atMessage({
message: "已预约成功",
type: "warning",
});
} else if (userInfo?.activity_status == "2") {
// 已预约
Taro.atMessage({
message: "审核中",
type: "warning",
});
} else {
if (!!wxid) {
// 发起预约
const userUpdateData = {
activity_status: "2", // 审核中
};
Taro.request({
method: "PUT",
// url: `/api/user/${urlwxid}`, //仅为示例,并非真实的接口地址
url: `/api/user/${wxid}`, //仅为示例,并非真实的接口地址
data: userUpdateData,
header: {
"Content-Type": "application/json",
},
success: function (res) {
// 预约成功
// Taro.atMessage({
// message: "预约成功",
// type: "success",
// });
if (res.data.code == "200") {
setmeetupToast(true);
}
},
fail: function (err) {},
complete: function (finy) {
window.location.reload();
},
});
} else {
setmeetupQR(true);
}
}
}}
>
{userInfo?.activity_status == "2"
? "审核中"
: userInfo?.activity_status == "1"
? "已报名"
// : "立即报名"}
: "已满"}
</View>
</View>
</View>
</View>
</AtCard>
</View>
{/* 付费入群 */}
{/* <View>付费入群</View> */}
{/* 联系我 */}
{!wxid && !Object.keys(userInfo)?.length > 0 ? (
<View className="contack">
<View className="wechatNum">微信号: hackrobot</View>
<Image
style="width: 185px;height: 200px;background: #fff;"
src={qrcode}
/>
</View>
) : null}
{/* <View className="payBtn">
<AtButton type="primary">立即购买 -- 29.8元</AtButton>
</View> */}
<View className="emojiModel">
{/* 软件下载模态窗 */}
<AtModal isOpened={isOpened}>
<AtModalHeader>emoji编辑器</AtModalHeader>
<AtModalContent>
<View className="modelText">
emoji编辑器是将markdown转换成标准的emoji格式
<br />
适用于各种图文场景
<br />
- 平台:小红书/微博/微信"小绿书"朋友圈
<br />- 评论区
</View>
{/* 软件图片展示 */}
<View className="model-emoji">
<Image
style="width: 100%;height: 240px;background: #fff;"
src={emoji}
/>
</View>
{/* <View>
百度网盘链接https://pan.baidu.com/s/1XXVnMimjUD8qVdmaVhb6rg?pwd=hqyo
<br />
提取码hqyo
</View> */}
</AtModalContent>
<AtModalAction>
<Button
onClick={() => {
setisOpened(false);
}}
>
取消
</Button>
<Button
onClick={() => {
window.location.href =
"https://pan.baidu.com/s/1XXVnMimjUD8qVdmaVhb6rg?pwd=hqyo";
}}
>
下载
</Button>
</AtModalAction>
</AtModal>
</View>
<View className="meetupQR">
{/* 软件下载模态窗 */}
<AtModal isOpened={meetupQR}>
<AtModalHeader>电子书</AtModalHeader>
<AtModalContent>
<View className="modelText">
1.加微信好友
<br />
2.发送关键词: 数字游民
</View>
{/* 软件图片展示 */}
<View className="model-emoji">
<Image
// style="width: 100%;height: 240px;background: #fff;"
src={qrcode}
/>
</View>
</AtModalContent>
<AtModalAction>
<Button
onClick={() => {
setmeetupQR(false);
}}
>
知道了
</Button>
</AtModalAction>
</AtModal>
</View>
{/* 腾讯云推广: https://curl.qcloud.com/8bJ1d9U0 */}
{/* <View></View> */}
<AtMessage />
<AtToast
isOpened={bookToast}
hasMask={true}
text={"预约成功"}
icon={"check"}
onClose={() => {
window.location.reload();
}}
></AtToast>
<AtToast
isOpened={meetupToast}
text={"报名成功"}
icon={"check"}
hasMask={true}
onClose={() => {
window.location.reload();
}}
></AtToast>
</View>
);
};
export default Index;