Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
fix: 拦截好友已帮助填写后继续点击该链接
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin3go committed Apr 16, 2023
1 parent b233d27 commit 58cc8b2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/graphql/questionnaire.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ export const findOneU2QGQL = gql`
}
}
`;

export const isExistedGQL = gql`
query isExisted($data: findOneU2QInput!) {
isExisted(data: $data)
}
`;
36 changes: 35 additions & 1 deletion src/pages/questionnaire/write.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import { onLoad } from "@dcloudio/uni-app";
import { reactive, ref, type Ref } from "vue";
import { useQuery, useMutation } from "villus";
import { findOneQGQL, findOneU2QGQL, writeGQL } from "@/graphql/questionnaire.graphql";
import { findOneQGQL, isExistedGQL, writeGQL } from "@/graphql/questionnaire.graphql";
import type { QuestionI } from "./questionnaire.interface";
import { useMeStore } from "@/stores/me.store";
Expand Down Expand Up @@ -69,6 +69,20 @@ onLoad(async (option) => {
// 如果上个页面没有传递朋友(填写者)ID,就使用当前页面的全局用户ID,在分享给好友填写时极其有作用
params.friendId = option?.friendId || meStore.user?.id;
// TODO 检测该链接是否已经填写过
if (await isExisted()) {
console.log("已经填写过该问卷了");
// 帮助好友填写都是从登录页过来的,所以这里直接返回登录页面
uni.navigateBack({
delta: 1,
success: () => {
uni.showToast({
title: "已填写该问卷",
icon: "error",
duration: 2000,
});
},
});
}
await getQuestions(params.questionnaireId);
});
Expand All @@ -94,6 +108,26 @@ async function getQuestions(questionnaireId: string) {
console.log("questions: ", questions.value);
}
async function isExisted() {
const { execute } = useQuery({ query: isExistedGQL, variables: { data: { ...params } } });
uni.showLoading({ title: "正在校验中" });
const { error, data } = await execute();
if (error) {
uni.showToast({
title: `校验请求失败: ${error}`,
icon: "error",
duration: 2000,
});
throw new Error(`校验请求失败: ${error}`);
}
console.log("isExisted error: ", error);
console.log("isExisted data: ", data);
const isExisted: boolean = data?.isExisted;
return isExisted;
}
function radioChange(e: any) {
const [qIndex, oIndex] = e.detail.value.split("#");
result.value[qIndex] = oIndex;
Expand Down

0 comments on commit 58cc8b2

Please sign in to comment.