82 lines
1.9 KiB
JavaScript
82 lines
1.9 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 = 1,callback) => {
|
|
console.log("times", times);
|
|
try {
|
|
const body = {
|
|
moment_id: id,
|
|
times: times==1?-1:1,
|
|
};
|
|
const data = await require("POST", `/api/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 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({
|
|
type: "error",
|
|
text1: data.msg,
|
|
topOffset: 60,
|
|
});
|
|
return;
|
|
}
|
|
return data.data.is_account_relation_existed;
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|