tiefen_space_h5/api/public.js

233 lines
5.4 KiB
JavaScript
Raw Normal View History

2024-07-06 11:05:19 +08:00
import { get } from "@/utils/storeInfo";
import require from "@/utils/require";
import { Toast } from "antd-mobile";
//关注和取关功能
2024-07-12 22:52:48 +08:00
export const handleLogout = async () => {
const account = get("account");
try {
const data = await require("POST", `/api/login/logout`, {
body: {
mid:account.mid
},
});
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
} else {
console.error(error);
}
} catch (error) {
console.error(error);
}
};
//关注和取关功能
2024-07-06 11:05:19 +08:00
export const handleFollow = async (isFollowed, followedID, callback) => {
const account = get("account");
let body = {
[!isFollowed ? "account_relations" : "sentences"]: [
{ sub_mid: account.mid, obj_mid: followedID, predicate: 0 },
{ sub_mid: followedID, obj_mid: account.mid, predicate: 1 },
],
};
try {
const data = await require("POST", `/api/account_relation/${
!isFollowed ? "create" : "delete"
}`, {
body,
});
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
} else {
callback(!isFollowed);
}
} catch (error) {
console.error(error);
}
};
//点赞和取消点赞功能
2024-07-08 20:07:36 +08:00
export const thumbsUp = async (id, times, callback,isZone) => {
try {
const body = isZone?{
zone_moment_id: id,
times: times == 1 ? -1 : 1,
}:{
moment_id: id,
times: times == 1 ? -1 : 1,
};
console.log("body", body);
const data = await require("POST", `/api/${isZone?"zone_moment":"moment"}/thumbs_up`, {
body,
});
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
} else {
callback(times == 1 ? -1 : 1);
}
} catch (error) {
console.error(error);
}
};
//点赞和取消点赞功能
export const zoneThumbsUp = async (id, times = 1, callback) => {
2024-07-06 11:05:19 +08:00
console.log("times", times);
try {
const body = {
moment_id: id,
2024-07-08 20:07:36 +08:00
times: times == 1 ? -1 : 1,
2024-07-06 11:05:19 +08:00
};
2024-07-08 20:07:36 +08:00
const data = await require("POST", `/api/zone/thumbs_up`, {
2024-07-06 11:05:19 +08:00
body,
});
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
2024-07-08 20:07:36 +08:00
} else {
callback(times == 1 ? -1 : 1);
2024-07-06 11:05:19 +08:00
}
} catch (error) {
console.error(error);
}
};
2024-07-10 16:50:53 +08:00
// 查看关系
2024-07-06 11:05:19 +08:00
export async function checkRelation(subMid, objMid, predicate) {
try {
2024-07-08 20:07:36 +08:00
const data =
await require("POST", `/api/account_relation/list_by_sentence`, {
body: {
sub_mid: subMid,
obj_mid: objMid,
predicate: predicate,
},
});
2024-07-06 11:05:19 +08:00
if (data.ret === -1) {
Toast.show({
2024-07-08 20:07:36 +08:00
icon: "fail",
content: data.msg,
position: "top",
2024-07-06 11:05:19 +08:00
});
return;
}
return data.data.is_account_relation_existed;
} catch (error) {
console.error(error);
}
}
2024-07-10 16:50:53 +08:00
// 获取用户信息
2024-07-10 00:48:37 +08:00
export async function getUserInfo() {
try {
const data =
await require("POST", `/api/account/list_by_mid`, null, true);
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
}
return data.data.account;
} catch (error) {
console.error(error);
}
}
2024-07-10 16:50:53 +08:00
// 创建订单
export const createOrder = async (type = "alipay_h5") => {
if (!selectedPrice.id && !customCoin.selected) {
Toast.show({
content: "请选择充值档位",
});
return;
}
if (customCoin.selected && customCoin.num < 10) {
Toast.show({
content: "最低充值1元哦",
});
return;
}
const base = webviewBaseRequest();
const body = {
...base,
product_id: customCoin.selected ? "h5_custom_coin" : selectedPrice.id,
custom_coins: customCoin.selected ? customCoin.num : 0,
pay_type: type,
redirect_url: type === "yeepay_wxpay_h5" ? window.location.href : "",
from: "app",
};
//如果是微信jsapi支付直接跳转到中间页
if (type === "wxpay_jsapi") {
router.push(`/pay/${encodeURIComponent(JSON.stringify(body))}`);
return;
}
setIsLoading(true);
const signature = generateSignature(body);
try {
const response = await fetch(
`/api/vas/create_order?signature=${signature}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
}
);
const data = await response.json();
if (data.ret === -1) {
Toast.show({
content: data.msg,
});
return;
}
switch (type) {
case "yeepay_alipay_h5":
router.push(`${data.data.yeepay_alipay_h5_param_str}`);
break;
case "yeepay_wxpay_h5":
router.push(`${data.data.yeepay_wxpay_h5_param_str}`);
break;
case "alipay_h5":
router.push(`${data.data.alipay_h5_param_str}`);
break;
case "wxpay_h5":
router.push(
`https://shop.tiefen.fun/pay/wxpay_h5/${encodeURIComponent(
data.data.wxpay_h5_param_str
)}`
);
break;
default:
router.push(`${data.data.alipay_h5_param_str}`);
break;
}
} catch (error) {
console.error(error);
} finally {
setIsLoading(false);
}
};