|
@@ -1,124 +1,98 @@
|
|
|
|
|
+import {useProvidePaperBatchCondition} from "@/views/dz/papers/hooks/usePaperBatchCondition.js";
|
|
|
|
|
+import {getPaperMajors, getPaperUniversities} from "@/api/dz/papers.js";
|
|
|
import {createEventHook, injectLocal, provideLocal} from "@vueuse/core";
|
|
import {createEventHook, injectLocal, provideLocal} from "@vueuse/core";
|
|
|
-import {
|
|
|
|
|
- getPaperBatches,
|
|
|
|
|
- getPaperExamTypes,
|
|
|
|
|
- getPaperKnowledges,
|
|
|
|
|
- getPaperMajors,
|
|
|
|
|
- getPaperProvinces,
|
|
|
|
|
- getPaperSubjects,
|
|
|
|
|
- getPaperUniversities
|
|
|
|
|
-} from "@/api/dz/papers.js";
|
|
|
|
|
|
|
|
|
|
const key = Symbol('PaperExactCondition')
|
|
const key = Symbol('PaperExactCondition')
|
|
|
|
|
+export const useProvidePaperExactCondition = function (type) {
|
|
|
|
|
+ const {buildType, batchId, batchList} = useProvidePaperBatchCondition(type)
|
|
|
|
|
|
|
|
-export const useProvidePaperExactCondition = function () {
|
|
|
|
|
- const batchId = ref('')
|
|
|
|
|
- const batchList = ref([])
|
|
|
|
|
-
|
|
|
|
|
- const location = ref('')
|
|
|
|
|
- const provinces = ref([])
|
|
|
|
|
- const examType = ref('')
|
|
|
|
|
- const examTypes = ref([])
|
|
|
|
|
const universityId = ref('')
|
|
const universityId = ref('')
|
|
|
const universities = ref([])
|
|
const universities = ref([])
|
|
|
|
|
+
|
|
|
|
|
+ const _allMajors = ref([])
|
|
|
|
|
+
|
|
|
|
|
+ const majorGroup = ref('')
|
|
|
|
|
+ const majorGroups = computed(() => {
|
|
|
|
|
+ const results = []
|
|
|
|
|
+ _allMajors.value.forEach(m => {
|
|
|
|
|
+ if (results.includes(m.majorGroup)) return
|
|
|
|
|
+ results.push(m.majorGroup)
|
|
|
|
|
+ })
|
|
|
|
|
+ return results
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
const majorPlanId = ref('')
|
|
const majorPlanId = ref('')
|
|
|
- const majors = ref([])
|
|
|
|
|
-
|
|
|
|
|
- const subjects = ref([])
|
|
|
|
|
- const subjectId = ref('')
|
|
|
|
|
- const knowledges = ref([])
|
|
|
|
|
- const knowledgeNode = ref(null) // 单选节点
|
|
|
|
|
- const knowledgeCheckNodes = ref([]) // 多选的节点
|
|
|
|
|
- const knowledgeIds = computed(() => knowledgeCheckNodes.value.map(k => k.id))
|
|
|
|
|
- const knowledgeId = computed(() => knowledgeNode.value?.id || '') // 单选
|
|
|
|
|
- const knowledgeRemoveEvent = createEventHook()
|
|
|
|
|
- const removeKnowledge = async (k) => {
|
|
|
|
|
- const nodes = knowledgeCheckNodes.value
|
|
|
|
|
- const idx = nodes.indexOf(k)
|
|
|
|
|
- if (idx > -1) {
|
|
|
|
|
- nodes.splice(idx, 1)
|
|
|
|
|
- await knowledgeRemoveEvent.trigger(k)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const majors = computed(() => {
|
|
|
|
|
+ if (!majorGroup.value) return
|
|
|
|
|
+ return _allMajors.value.filter(m => m.majorGroup == majorGroup.value)
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- const paperArgs = computed(() => ({
|
|
|
|
|
- batchId: toValue(batchId),
|
|
|
|
|
- batchName: batchList.value.find(b => b.batchId == batchId.value)?.name,
|
|
|
|
|
- subjectId: toValue(subjectId),
|
|
|
|
|
- subjectName: subjects.value.find(s => s.subjectId == subjectId.value)?.subjectName,
|
|
|
|
|
- examTypes: [toValue(examType)],
|
|
|
|
|
- location: toValue(location),
|
|
|
|
|
- universityIds: [toValue(universityId)],
|
|
|
|
|
- planIds: [toValue(majorPlanId)]
|
|
|
|
|
|
|
+ const conditionArgs = computed(() => ({
|
|
|
|
|
+ buildType: toValue(buildType),
|
|
|
|
|
+ universityId: toValue(universityId),
|
|
|
|
|
+ majorGroup: toValue(majorGroup),
|
|
|
|
|
+ majorPlanId: toValue(majorPlanId)
|
|
|
|
|
+ }))
|
|
|
|
|
+ const conditionData = computed(() => ({
|
|
|
|
|
+ universities: toValue(universities),
|
|
|
|
|
+ majorGroups: toValue(majorGroups),
|
|
|
|
|
+ majors: toValue(majors)
|
|
|
}))
|
|
}))
|
|
|
- const payload = {
|
|
|
|
|
- location, provinces, examType, examTypes, universityId, universities,
|
|
|
|
|
- batchId, batchList, majorPlanId, majors, subjects, subjectId,
|
|
|
|
|
- knowledges, knowledgeNode, knowledgeId, knowledgeCheckNodes, knowledgeIds,
|
|
|
|
|
- removeKnowledge, onKnowledgeRemove: knowledgeRemoveEvent.on,
|
|
|
|
|
- paperArgs
|
|
|
|
|
|
|
+ const exactEvent = createEventHook()
|
|
|
|
|
+ const triggerExactEvent = async function (args) {
|
|
|
|
|
+ await exactEvent.trigger(args)
|
|
|
}
|
|
}
|
|
|
- provideLocal(key, payload)
|
|
|
|
|
|
|
|
|
|
- // hooks
|
|
|
|
|
- onMounted(async () => {
|
|
|
|
|
- const res = await getPaperProvinces()
|
|
|
|
|
- provinces.value = res.data
|
|
|
|
|
- })
|
|
|
|
|
- onMounted(async () => {
|
|
|
|
|
- const res = await getPaperBatches()
|
|
|
|
|
- batchList.value = res.data
|
|
|
|
|
- })
|
|
|
|
|
- watch(location, async (location) => {
|
|
|
|
|
- // clean
|
|
|
|
|
- examType.value = ''
|
|
|
|
|
- examTypes.value = []
|
|
|
|
|
-
|
|
|
|
|
- if (!location) return
|
|
|
|
|
- const resT = await getPaperExamTypes({location})
|
|
|
|
|
- examTypes.value = resT.data
|
|
|
|
|
- })
|
|
|
|
|
- watch([location, batchId], async ([location, batchId]) => {
|
|
|
|
|
- // clean
|
|
|
|
|
|
|
+ watch(batchId, async (batchId) => {
|
|
|
universityId.value = ''
|
|
universityId.value = ''
|
|
|
universities.value = []
|
|
universities.value = []
|
|
|
|
|
|
|
|
- if (!location || !batchId) return
|
|
|
|
|
- const resU = await getPaperUniversities({location, batchId})
|
|
|
|
|
- universities.value = resU.data
|
|
|
|
|
|
|
+ if (!batchId) return
|
|
|
|
|
+ const res = await getPaperUniversities({buildType, batchId})
|
|
|
|
|
+ universities.value = res.data
|
|
|
})
|
|
})
|
|
|
- watch([location, examType, batchId, universityId], async ([location, examType, batchId, universityId]) => {
|
|
|
|
|
- // clean
|
|
|
|
|
- majorPlanId.value = ''
|
|
|
|
|
- majors.value = []
|
|
|
|
|
|
|
|
|
|
- if (!location || !examType || !batchId || !universityId) return
|
|
|
|
|
- const res = await getPaperMajors({location, examType, batchId, universityId})
|
|
|
|
|
- majors.value = res.data
|
|
|
|
|
- if (res.data.length) majorPlanId.value = res.data[0].id
|
|
|
|
|
|
|
+ watch([batchId, universityId], async ([batchId, universityId]) => {
|
|
|
|
|
+ majorGroup.value = ''
|
|
|
|
|
+
|
|
|
|
|
+ if (!batchId || !universityId) return
|
|
|
|
|
+ const res = await getPaperMajors({buildType, batchId, universityId})
|
|
|
|
|
+ _allMajors.value = res.data
|
|
|
|
|
+
|
|
|
|
|
+ // 没有数据时,说明已经满足了条件
|
|
|
|
|
+ if (!majorGroups.value.length) await triggerExactEvent({buildType, batchId, universityId})
|
|
|
|
|
+ else if (majorGroups.value.length == 1) majorGroup.value = majorGroups.value[0]
|
|
|
})
|
|
})
|
|
|
- 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([batchId, universityId, majorGroup], async ([batchId, universityId, majorGroup]) => {
|
|
|
|
|
+ majorPlanId.value = ''
|
|
|
|
|
+
|
|
|
|
|
+ if (!batchId || !universityId || !majorGroup) return
|
|
|
|
|
+ if (!majors.value.length) await triggerExactEvent({buildType, batchId, universityId, majorGroup})
|
|
|
|
|
+ else if (majors.value.length == 1) majorPlanId.value = majors.value[0].id
|
|
|
})
|
|
})
|
|
|
- watch([majorPlanId, subjectId], async ([majorPlanId, subjectId]) => {
|
|
|
|
|
- // clean
|
|
|
|
|
- knowledges.value = []
|
|
|
|
|
- knowledgeNode.value = null // 单选的情况
|
|
|
|
|
- knowledgeCheckNodes.value = [] // 多选的情况
|
|
|
|
|
-
|
|
|
|
|
- if (!subjectId || !majorPlanId) return
|
|
|
|
|
- // 获取知识点数据
|
|
|
|
|
- const res = await getPaperKnowledges({subjectId, majorPlanId})
|
|
|
|
|
- knowledges.value = res.data
|
|
|
|
|
|
|
+
|
|
|
|
|
+ watch(majorPlanId, async (majorPlanId) => {
|
|
|
|
|
+ if (!majorPlanId) return
|
|
|
|
|
+
|
|
|
|
|
+ // 最细的情况,选中了专业
|
|
|
|
|
+ const args = {
|
|
|
|
|
+ buildType,
|
|
|
|
|
+ batchId: toValue(batchId),
|
|
|
|
|
+ universityId: toValue(universityId),
|
|
|
|
|
+ majorGroup: toValue(majorGroup),
|
|
|
|
|
+ majorPlanId
|
|
|
|
|
+ }
|
|
|
|
|
+ await triggerExactEvent(args)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ const payload = {buildType, batchId, batchList,
|
|
|
|
|
+ universityId, universities,
|
|
|
|
|
+ majorGroup, majorGroups,
|
|
|
|
|
+ majorPlanId, majors,
|
|
|
|
|
+ conditionArgs, conditionData,
|
|
|
|
|
+ onConditionReady: exactEvent.on}
|
|
|
|
|
+ provideLocal(key, payload)
|
|
|
return payload
|
|
return payload
|
|
|
}
|
|
}
|
|
|
|
|
|