tiefen_space_h5/api/public.js

113 lines
2.5 KiB
JavaScript

import { get } from "@/utils/storeInfo";
import require from "@/utils/require";
import { Toast } from "antd-mobile";
//关注和取关功能
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);
}
};
//点赞和取消点赞功能
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) => {
console.log("times", times);
try {
const body = {
moment_id: id,
times: times == 1 ? -1 : 1,
};
const data = await require("POST", `/api/zone/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 async function checkRelation(subMid, objMid, predicate) {
try {
const data =
await require("POST", `/api/account_relation/list_by_sentence`, {
body: {
sub_mid: subMid,
obj_mid: objMid,
predicate: predicate,
},
});
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
}
return data.data.is_account_relation_existed;
} catch (error) {
console.error(error);
}
}