|
@@ -0,0 +1,38 @@
|
|
|
|
|
+import {injectLocal, provideLocal} from "@vueuse/core";
|
|
|
|
|
+import {getPaperKnowledges, getPaperSubjects} from "@/api/dz/papers.js";
|
|
|
|
|
+import {watch} from "vue";
|
|
|
|
|
+
|
|
|
|
|
+const key = Symbol('PaperFullCondition')
|
|
|
|
|
+
|
|
|
|
|
+export const useProvidePaperFullCondition = function () {
|
|
|
|
|
+ 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 = {subjectId, subjects, knowledgeId, knowledges, knowledgeCheckNodes, knowledgeIds}
|
|
|
|
|
+ provideLocal(key, payload)
|
|
|
|
|
+
|
|
|
|
|
+ onMounted(async () => {
|
|
|
|
|
+ const res = await getPaperSubjects()
|
|
|
|
|
+ subjects.value = res.data
|
|
|
|
|
+ // 给一个默认值
|
|
|
|
|
+ if (res.data.length) subjectId.value = res.data[0].subjectId
|
|
|
|
|
+ })
|
|
|
|
|
+ watch(subjectId, async () => {
|
|
|
|
|
+ // 先清空以前的知识点
|
|
|
|
|
+ knowledgeId.value = '' // 单选的情况
|
|
|
|
|
+ knowledgeCheckNodes.value = [] // 多选的情况
|
|
|
|
|
+
|
|
|
|
|
+ // 获取知识点数据
|
|
|
|
|
+ const res = await getPaperKnowledges({subjectId: toValue(subjectId)})
|
|
|
|
|
+ knowledges.value = res.data
|
|
|
|
|
+ })
|
|
|
|
|
+ return payload
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export const useInjectPaperFullCondition = function () {
|
|
|
|
|
+ return injectLocal(key)
|
|
|
|
|
+}
|