feat:微信群加入按钮/提示

This commit is contained in:
hackrobot
2024-04-07 22:00:57 +08:00
parent d2c4fb676c
commit f14fcdc0af

View File

@@ -13,6 +13,8 @@ import {
AtSteps, AtSteps,
AtForm, AtForm,
AtInput, AtInput,
AtToast,
AtMessage,
} from "taro-ui"; } from "taro-ui";
import "./index.scss"; import "./index.scss";
import beijing from "@/images/city/beijing.jpg"; import beijing from "@/images/city/beijing.jpg";
@@ -22,36 +24,37 @@ import shenzhen from "@/images/city/shenzhen.jpg";
import touxiang from "@/images/index/touxiang.jpg"; import touxiang from "@/images/index/touxiang.jpg";
import TabbarCom from "@/componments/TabbarCom"; import TabbarCom from "@/componments/TabbarCom";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { set } from "lodash";
const KeywordJoin = () => { const KeywordJoin = () => {
const [current, setcurrent] = useState(0); const [current, setcurrent] = useState(0);
const [value, setvalue] = useState(null); const [value, setvalue] = useState(null);
const [disabled, setdisabled] = useState(false);
const [localuserInfo, setlocaluserInfo] = useState(Taro.getStorageSync("userInfo")); const [btntext, setbtntext] = useState('立即加入');
const [localuserInfo, setlocaluserInfo] = useState(
Taro.getStorageSync("userInfo")
);
// 获取用户标识符
useEffect(() => {
// 获取路由参数
const params = Taro.getCurrentInstance().router.params;
console.log("params", params);
// const [wxid, openId] = params;
// 获取用户标识符 if (params.wxid) {
useEffect(() => { setuserInfo({
// 获取路由参数 wxid: params?.wxid, //个人号wxid
const params = Taro.getCurrentInstance().router.params; // openId: params?.openId, //小程序openid
console.log("params", params); });
// const [wxid, openId] = params; // 本地存储
if (params.wxid) {
setuserInfo({
wxid: params?.wxid, //个人号wxid
// openId: params?.openId, //小程序openid
});
// 本地存储
try {
Taro.setStorageSync("wxid", params?.wxid ?? "");
} catch (e) {}
}
}, []);
try {
Taro.setStorageSync("wxid", params?.wxid ?? "");
} catch (e) {}
}
}, []);
// useEffect(() => { // useEffect(() => {
// // 更新分享-minipro // // 更新分享-minipro
@@ -68,6 +71,13 @@ const KeywordJoin = () => {
// }, []); // }, []);
const handleClick = (text, type) => {
Taro.atMessage({
message: text,
type: type,
});
};
return ( return (
<View className="KeywordJoin"> <View className="KeywordJoin">
{/* 步骤栏 */} {/* 步骤栏 */}
@@ -128,23 +138,40 @@ const KeywordJoin = () => {
</View> </View>
</View> </View>
</View> </View>
<View className="tabbbarDiv"></View> <AtMessage />
<AtButton type="primary" className="jsonWechatBtn" onClick={()=>{ <AtButton
// 通过hook加入微信群邀请 type="primary"
//发起网络请求 className="jsonWechatBtn"
Taro.request({ disabled={disabled}
// url: "http://127.0.0.1:28369/joingroup", onClick={() => {
url: "https://kunpeng.hackrobot.cn/joingroup", // 通过hook加入微信群邀请
data: { //发起网络请求
wxid: localuserInfo?.wxid ?? null, //debug eric 的wxid Taro.request({
}, // url: "http://127.0.0.1:28369/joingroup",
success: function (resUser) { url: "https://kunpeng.hackrobot.cn/joingroup",
console.log('resUser--',resUser) data: {
console.log('加入微信群成功'); wxid: localuserInfo?.wxid ?? null, //debug eric 的wxid
}, },
}); success: function (resUser) {
}}> console.log("resUser--", resUser);
点击加入 console.log("加入微信群成功");
if (resUser?.data?.success == "fail") {
//已经在群聊中
handleClick("已经在群聊中", "warning");
setbtntext("已经在群聊中")
} else if (resUser?.data?.success == "ok") {
// 发送群聊邀请
handleClick("已发送群聊邀请", "warning");
setbtntext("已发送群聊邀请")
}
setdisabled(true);
},
});
}}
>
{btntext}
</AtButton> </AtButton>
</View> </View>
); );