|
|
@@ -0,0 +1,92 @@
|
|
|
+import {injectLocal, provideLocal} from "@vueuse/core";
|
|
|
+import {
|
|
|
+ getPaperExamTypes,
|
|
|
+ getPaperKnowledges,
|
|
|
+ getPaperMajors,
|
|
|
+ getPaperProvinces,
|
|
|
+ getPaperSubjects,
|
|
|
+ getPaperUniversities
|
|
|
+} from "@/api/dz/papers.js";
|
|
|
+
|
|
|
+const key = Symbol('PaperExactCondition')
|
|
|
+
|
|
|
+export const useProvidePaperExactCondition = function () {
|
|
|
+ const location = ref('')
|
|
|
+ const provinces = ref([])
|
|
|
+ const examType = ref('')
|
|
|
+ const examTypes = ref([])
|
|
|
+ const universityId = ref('')
|
|
|
+ const universities = ref([])
|
|
|
+ const majorPlanId = ref('')
|
|
|
+ const majors = ref([])
|
|
|
+
|
|
|
+ const subjects = ref([])
|
|
|
+ const subjectId = ref('')
|
|
|
+ const knowledges = ref([])
|
|
|
+ const knowledgeId = ref('') // 单选
|
|
|
+ const knowledgeCheckNodes = ref([]) // 多选的节点
|
|
|
+ const knowledgeIds = computed(() => knowledgeCheckNodes.value.map(k => k.id))
|
|
|
+
|
|
|
+ const payload = {
|
|
|
+ location, provinces, examType, examTypes, universityId, universities, majorPlanId, majors,
|
|
|
+ subjects, subjectId, knowledges, knowledgeId, knowledgeCheckNodes, knowledgeIds
|
|
|
+ }
|
|
|
+ provideLocal(key, payload)
|
|
|
+
|
|
|
+ // hooks
|
|
|
+ onMounted(async () => {
|
|
|
+ const res = await getPaperProvinces()
|
|
|
+ provinces.value = res.data
|
|
|
+ })
|
|
|
+ watch(location, async () => {
|
|
|
+ // clean
|
|
|
+ examType.value = ''
|
|
|
+ examTypes.value = []
|
|
|
+ universityId.value = ''
|
|
|
+ universities.value = []
|
|
|
+
|
|
|
+ if (!location.value) return
|
|
|
+ const resT = await getPaperExamTypes({location: toValue(location)})
|
|
|
+ examTypes.value = resT.data
|
|
|
+
|
|
|
+ const resU = await getPaperUniversities({location: toValue(location)})
|
|
|
+ universities.value = resU.data
|
|
|
+ })
|
|
|
+ watch([examType, universityId], async ([examType, universityId]) => {
|
|
|
+ // clean
|
|
|
+ majorPlanId.value = ''
|
|
|
+ majors.value = []
|
|
|
+
|
|
|
+ if (!examType || !universityId) return
|
|
|
+ const res = await getPaperMajors({location: toValue(location), examType, universityId})
|
|
|
+ majors.value = res.data
|
|
|
+ if (res.data.length) majorPlanId.value = res.data[0].id
|
|
|
+ })
|
|
|
+ watch(universityId, async (universityId) => {
|
|
|
+ // clean
|
|
|
+ subjects.value = []
|
|
|
+ subjectId.value = ''
|
|
|
+
|
|
|
+ if (!universityId) return
|
|
|
+ const res = await getPaperSubjects({universityId})
|
|
|
+ subjects.value = res.data
|
|
|
+ if (res.data.length) subjectId.value = res.data[0].subjectId
|
|
|
+ })
|
|
|
+ watch([majorPlanId, subjectId], async ([majorPlanId, subjectId]) => {
|
|
|
+ // clean
|
|
|
+ knowledges.value = []
|
|
|
+ knowledgeId.value = '' // 单选的情况
|
|
|
+ knowledgeCheckNodes.value = [] // 多选的情况
|
|
|
+
|
|
|
+ if (!subjectId || !majorPlanId) return
|
|
|
+ // 获取知识点数据
|
|
|
+ const res = await getPaperKnowledges({subjectId, majorPlanId})
|
|
|
+ knowledges.value = res.data
|
|
|
+ })
|
|
|
+
|
|
|
+ return payload
|
|
|
+}
|
|
|
+
|
|
|
+export const useInjectPaperExactCondition = function () {
|
|
|
+ return injectLocal(key)
|
|
|
+}
|