Prechádzať zdrojové kódy

vhs - index js re-define

abpcoder 1 mesiac pred
rodič
commit
5f5cb09a70

+ 1 - 1
package.json

@@ -58,7 +58,7 @@
     "@dcloudio/uni-h5": "3.0.0-4080720251210001",
     "@dcloudio/uni-mp-weixin": "3.0.0-4080720251210001",
     "@rojer/katex-mini": "^1.3.4",
-    "@vueuse/core": "^11.2.0",
+    "@vueuse/core": "^14.1.0",
     "echarts": "^6.0.0",
     "flyio": "^0.6.14",
     "katex": "^0.16.25",

+ 25 - 0
src/pagesOther/hooks/useUserSnapshotInjection.js

@@ -0,0 +1,25 @@
+import {useUserStore} from "@/store/userStore";
+import {VHS_USER_SNAPSHOT} from "@/types/injectionSymbols";
+
+export const useProvideUserSnapshot = function (userSnapshotRefOrGetter) {
+    // 有时志愿表会存储一部分当前用户信息,这部分信息命名为userSnapshot
+    // 使用时,用快照信息去覆盖用户信息,即可得到当时保存志愿表时的用户信息。
+    const {userInfo} = storeToRefs(useUserStore())
+
+    const userSnapshot = computed(() => {
+        const snapshot = toValue(userSnapshotRefOrGetter)
+        return {
+            ...toValue(userInfo),
+            ...snapshot
+        }
+    })
+
+    provide(VHS_USER_SNAPSHOT, userSnapshot)
+    return userSnapshot
+}
+
+export const useInjectUserSnapshot = function () {
+    // 默认值用currentUser填充
+    const {userInfo} = storeToRefs(useUserStore())
+    return inject(VHS_USER_SNAPSHOT, userInfo)
+}

+ 24 - 4
src/pagesOther/hooks/useVoluntaryDataInjection.ts

@@ -1,11 +1,15 @@
+import _ from 'lodash';
 import {VoluntaryData} from "@/types/vhs";
-import {empty} from "@/uni_modules/uv-ui-tools/libs/function/test";
+import {getVoluntaryData} from "@/api/modules/vhs";
+import {useUserStore} from "@/store/userStore";
+import {VHS_VOLUNTARY_DATA} from "@/types/injectionSymbols";
 
-export const useVoluntaryDataInjection = (yearRef: Ref<string> | null = null) => {
+export const useProvideVoluntaryData = (yearRef: Ref<string> | null = null) => {
     // 如果页面有年份要求就必须传年份ref参数;
     // 如果不传,表示只关心最新年份的配置;
 
     const voluntaryData = ref<VoluntaryData>({} as VoluntaryData)
+    const userStore = useUserStore()
 
     const loadData = async () => {
         let payload = undefined
@@ -14,11 +18,12 @@ export const useVoluntaryDataInjection = (yearRef: Ref<string> | null = null) =>
             if (!year) return
             payload = {year}
         }
-        voluntaryData.value = await dispatchCache(cacheActions.getVoluntaryData, payload)
+        const res = await getVoluntaryData(payload)
+        voluntaryData.value = res.data
     }
 
     const validate = async (score: string, silence: boolean) => {
-        if (empty(voluntaryData.value)) {
+        if (_.isEmpty(voluntaryData.value)) {
             return Promise.reject('VoluntaryData not be loaded.')
         }
         if (!score) {
@@ -35,4 +40,19 @@ export const useVoluntaryDataInjection = (yearRef: Ref<string> | null = null) =>
         }
         return true
     }
+
+    const dependents = yearRef ? [() => userStore.isLogin, yearRef] : [() => userStore.isLogin]
+    watch(dependents, () => userStore.isLogin && loadData(), {immediate: true})
+
+    const options = {
+        voluntaryData,
+        validate
+    }
+
+    provide(VHS_VOLUNTARY_DATA, options)
+    return options
+}
+
+export const useInjectVoluntaryData = () => {
+    return inject(VHS_VOLUNTARY_DATA)
 }

+ 12 - 14
src/pagesOther/pages/vhs/hooks/useVoluntaryAssistantInjection.js

@@ -1,12 +1,11 @@
-import {computed} from 'vue';
-import {createEventHook, injectLocal, provideLocal, toValue} from "@vueuse/core";
-import {sleep, toast} from "@/uni_modules/uv-ui-tools/libs/function";
-import MxConst from "@/common/mxConst";
+import {createEventHook, injectLocal, provideLocal} from "@vueuse/core";
+import {sleep} from "@/uni_modules/uv-ui-tools/libs/function";
 import {empty} from "@/uni_modules/uv-ui-tools/libs/function/test";
-import {saveZhiyuan} from "@/api/webApi/volunteer";
+import {recommendMajorSortFn} from "@/utils/common";
+import {saveZhiyuan} from "@/api/modules/vhs";
 
 const key = Symbol('VOLUNTARY_ASSISTANT')
-export const useProvideVoluntaryAssistant = function (stepSvc, dataSvc, formSvc, cartSvc, highlightSvc, scrollHeight) {
+export const useProvideVoluntaryAssistant = function (stepSvc, dataSvc, formSvc, cartSvc, highlightSvc) {
 
     const {title, currentStep} = stepSvc
     const {id, name, locking, selectedList, resetCart} = cartSvc
@@ -71,7 +70,7 @@ export const useProvideVoluntaryAssistant = function (stepSvc, dataSvc, formSvc,
 
     const save = async (isMockHeader) => {
         if (toValue(id) && !toValue(name)) {
-            toast('请设置志愿表名称')
+            uni.$ie.showError('请设置志愿表名称')
             return Promise.reject(false)
         }
         const wishes = selectedList.value.map(item => ({
@@ -89,7 +88,7 @@ export const useProvideVoluntaryAssistant = function (stepSvc, dataSvc, formSvc,
             seat: item.history?.seat,
             marjors: item.majors
                 .filter(major => major.selected)
-                .sort(MxConst.recommendMajorSortFn)
+                .sort(recommendMajorSortFn)
                 .map(major => ({
                     id: major.id,
                     code: major.marjorBelongs,
@@ -103,11 +102,11 @@ export const useProvideVoluntaryAssistant = function (stepSvc, dataSvc, formSvc,
         }))
         if (wishes.length < 1) {
             // NOTE: 职高对口院校较少,降低填报限制
-            toast('至少选择1个志愿组')
+            uni.$ie.showError('至少选择1个志愿组')
             return Promise.reject(false)
         }
         locking.value = true
-        uni.showLoading()
+        uni.$ie.showLoading()
         const vBatch = toValue(batch)
         const vModel = toValue(model)
         const vMode = toValue(mode)
@@ -139,11 +138,11 @@ export const useProvideVoluntaryAssistant = function (stepSvc, dataSvc, formSvc,
         let res = null
         try {
             res = await saveZhiyuan(data)
-            toast('保存成功,即将跳转3')
+            uni.$ie.showToast('保存成功,即将跳转3')
             await sleep(1000)
-            toast('保存成功,即将跳转2')
+            uni.$ie.showToast('保存成功,即将跳转2')
             await sleep(1000)
-            toast('保存成功,即将跳转1')
+            uni.$ie.showToast('保存成功,即将跳转1')
             await sleep(500)
             await complete.trigger(res.data)
         } finally {
@@ -164,7 +163,6 @@ export const useProvideVoluntaryAssistant = function (stepSvc, dataSvc, formSvc,
         voluntaryDataCalculate,
         save,
         resetAll,
-        scrollHeight,
         onBeforeBack: beforeBack.on,
         onAfterBack: afterBack.on,
         onBeforeForward: beforeForward.on,

+ 2 - 3
src/pagesOther/pages/vhs/hooks/useVoluntaryCartInjection.js

@@ -1,11 +1,10 @@
-import {ref} from 'vue';
 import _ from 'lodash';
-import {createEventHook, injectLocal, provideLocal} from "@vueuse/core";
+import {injectLocal, provideLocal} from "@vueuse/core";
 import {toast} from "@/uni_modules/uv-ui-tools/libs/function";
 
 const key = Symbol('VOLUNTARY_CART')
 
-export const useProvideVoluntaryCart = function (initId, n = '') {
+export const useProvideVoluntaryCart = function (initId = 0, n = '') {
     const id = ref(initId)
     const name = ref(n)
     const locking = ref(false)

+ 8 - 11
src/pagesOther/pages/vhs/hooks/useVoluntaryFormInjection.js

@@ -1,15 +1,12 @@
-import {ref, computed, watch} from 'vue';
-import {injectLocal, provideLocal, toValue} from "@vueuse/core";
+import {injectLocal, provideLocal} from "@vueuse/core";
 import {array, empty} from "@/uni_modules/uv-ui-tools/libs/function/test";
-import {useUserStore} from "@/hooks/useUserStore";
-import {zytbBatches} from "@/api/webApi/volunteer";
-import {useCacheStore} from "@/hooks/useCacheStore";
+import {useUserStore} from "@/store/userStore";
+import {zytbBatches} from "@/api/modules/vhs";
 
 const key = Symbol('VOLUNTARY_FORM')
 
 export const useProvideVoluntaryForm = function () {
-    const {currentUser} = useUserStore()
-    const {dispatchCache} = useCacheStore()
+    const currentUser = useUserStore()
 
     const model = ref({
         firstSubject: '',
@@ -45,7 +42,7 @@ export const useProvideVoluntaryForm = function () {
     }
 
     const reloadScoreAndMode = async () => {
-        const {mode, score, seatInput} = toValue(currentUser)
+        const {mode, score, seatInput} = toValue(currentUser.userInfo)
         const modeParams = mode?.split(',') || []
         model.value.score = score || ''
         model.value.firstSubject = modeParams[0]
@@ -57,18 +54,18 @@ export const useProvideVoluntaryForm = function () {
     const loadBatchList = async () => {
         const m = toValue(mode)
         const {score} = toValue(model)
-        const res = await dispatchCache(zytbBatches, {mode: m, score})
+        const res = await zytbBatches({mode: m, score})
         batchList.value = res.rows
     }
 
     const getBatchList = async (modelVal) => {
         const m = getMode(modelVal)
         const {score} = modelVal
-        const res = await dispatchCache(zytbBatches, {mode: m, score})
+        const res = await zytbBatches({mode: m, score})
         return res.rows
     }
 
-    watch(currentUser, () => reloadScoreAndMode(), {immediate: true})
+    watch(() => currentUser, () => reloadScoreAndMode(), {immediate: true})
 
     const options = {
         model, batch, batchList,

+ 4 - 8
src/pagesOther/pages/vhs/hooks/useVoluntaryHeaderInjection.js

@@ -1,17 +1,12 @@
-import {computed, ref, watch} from 'vue';
-import {injectLocal, provideLocal, toValue} from "@vueuse/core";
+import {injectLocal, provideLocal} from "@vueuse/core";
 import {empty} from "@/uni_modules/uv-ui-tools/libs/function/test";
-import {getVoluntaryHeaders} from "@/api/webApi/volunteer";
-import {useInjectVoluntaryForm} from "@/pagesOther/pages/voluntary/hooks/useVoluntaryFormInjection";
-import {useCacheStore} from "@/hooks/useCacheStore";
-import {useInjectVoluntaryStep} from "@/pagesOther/pages/voluntary/hooks/useVoluntaryStepInjection";
+import {getVoluntaryHeaders} from "@/api/modules/vhs";
 
 const key = Symbol('VOLUNTARY_HEADER')
 
 export const useProvideVoluntaryHeader = () => {
     const cols = ref([])
     const isMock = ref(undefined) // unset status
-    const {dispatchCache} = useCacheStore()
 
     const historyYears = computed(() => {
         if (empty(cols.value)) return []
@@ -19,6 +14,7 @@ export const useProvideVoluntaryHeader = () => {
             .filter(col => col.includes('&'))
             .map(col => col.split('&')[0])
     })
+
     const headerPlanYear = computed(() => {
         if (empty(cols.value)) return ''
         const suffix = '招生计划'
@@ -27,7 +23,7 @@ export const useProvideVoluntaryHeader = () => {
     })
 
     const ensureHistoryYears = async (payload) => {
-        const res = await dispatchCache(getVoluntaryHeaders, payload)
+        const res = await getVoluntaryHeaders(payload)
         cols.value = res.data
         isMock.value = res.isMock
     }

+ 3 - 5
src/pagesOther/pages/vhs/hooks/useVoluntaryMajorHighlightInjection.js

@@ -1,12 +1,9 @@
-import {ref, computed} from 'vue';
 import {injectLocal, provideLocal} from "@vueuse/core";
-import {useCacheStore} from "@/hooks/useCacheStore";
-import {cacheActions} from "@/hooks/defineCacheActions";
+import {getMajorTree} from "@/api/modules/major";
 
 const key = Symbol('VOLUNTARY_MAJOR_HIGHLIGHT')
 
 export const useProvideVoluntaryMajorHighlight = (readonly) => {
-    const {dispatchCache} = useCacheStore()
     const checkedList = ref([])
     const formedMajors = ref({})
     const majorTree = ref([])
@@ -54,7 +51,8 @@ export const useProvideVoluntaryMajorHighlight = (readonly) => {
     }
     const ensureMajorFullTree = async (batch) => {
         const params = {level: 3, batch}
-        majorTree.value = dispatchCache(cacheActions.getMajorTree, params)
+        const res = await getMajorTree(params)
+        majorTree.value = res.data
     }
     const resolveFormedMajorsFromSavedData = (data) => {
         const formed = {}

+ 0 - 1
src/pagesOther/pages/vhs/hooks/useVoluntaryStepInjection.js

@@ -1,4 +1,3 @@
-import {ref} from 'vue';
 import {injectLocal, provideLocal} from "@vueuse/core";
 
 const key = Symbol('VOLUNTARY_STEP')

+ 19 - 23
src/pagesOther/pages/vhs/index/index.vue

@@ -1,40 +1,39 @@
 <template>
-    <view class="page-content">
-        <mx-nav-bar v-bind="navBinding"/>
-        <view ref="container" class="flex-1 min-h-1">
-            <swiper :current="currentStep" disable-touch :style="{height: height+'px'}">
+    <ie-page>
+        <ie-navbar :title="navBinding.title"/>
+        <ie-auto-resizer>
+            <swiper :current="currentStep" disable-touch class="swiper h-full">
                 <swiper-item>
-                    <score-step/>
+<!--                    <score-step/>-->
                 </swiper-item>
                 <swiper-item>
-                    <batch-step/>
+<!--                    <batch-step/>-->
                 </swiper-item>
                 <swiper-item>
-                    <cart-step/>
+<!--                    <cart-step/>-->
                 </swiper-item>
             </swiper>
-        </view>
-    </view>
+        </ie-auto-resizer>
+    </ie-page>
 </template>
 
 <script setup>
-import {ref} from 'vue';
-import {useProvideTransfer} from "@/hooks/useTransfer";
+// import ScoreStep from "@/pagesOther/pages/vhs/index/components/score-step.vue";
+// import BatchStep from "@/pagesOther/pages/vhs/index/components/batch-step.vue";
+// import CartStep from "@/pagesOther/pages/vhs/index/components/cart-step.vue";
 import {useProvideVoluntaryStep} from "@/pagesOther/pages/vhs/hooks/useVoluntaryStepInjection";
-import {useProvideVoluntaryData} from "@/pagesOther/pages/vhs/hooks/useVoluntaryDataInjection";
+import {useProvideVoluntaryData} from "@/pagesOther/hooks/useVoluntaryDataInjection";
 import {useProvideVoluntaryForm} from "@/pagesOther/pages/vhs/hooks/useVoluntaryFormInjection";
 import {useProvideVoluntaryCart} from "@/pagesOther/pages/vhs/hooks/useVoluntaryCartInjection";
 import {useProvideVoluntaryAssistant} from "@/pagesOther/pages/vhs/hooks/useVoluntaryAssistantInjection";
-import ScoreStep from "@/pagesOther/pages/vhs/index/components/score-step.vue";
-import {useElementSize} from "@vueuse/core";
-import {useProvideUserSnapshot} from "@/pagesOther/pages/ie/hooks/useUserSnapshotInjection";
-import BatchStep from "@/pagesOther/pages/vhs/index/components/batch-step.vue";
-import CartStep from "@/pagesOther/pages/vhs/index/components/cart-step.vue";
+import {useProvideUserSnapshot} from "@/pagesOther/hooks/useUserSnapshotInjection";
 import {useProvideVoluntaryMajorHighlight} from "@/pagesOther/pages/vhs/hooks/useVoluntaryMajorHighlightInjection";
 import {useProvideVoluntaryHeader} from "@/pagesOther/pages/vhs/hooks/useVoluntaryHeaderInjection";
+import {useTransferPage} from "@/hooks/useTransferPage";
+import {routes} from "@/common/routes";
 
 useProvideUserSnapshot()
-const {transferTo} = useProvideTransfer()
+const {transferTo} = useTransferPage()
 const stepSvc = useProvideVoluntaryStep()
 const dataSvc = useProvideVoluntaryData()
 const formSvc = useProvideVoluntaryForm()
@@ -43,14 +42,11 @@ const highlightSvc = useProvideVoluntaryMajorHighlight()
 useProvideVoluntaryHeader()
 
 const {currentStep} = stepSvc
-const container = ref(null) // swiper必须指定明确的高度,所以多包了一层
-const {height} = useElementSize(container)
-
-const assistantSvc = useProvideVoluntaryAssistant(stepSvc, dataSvc, formSvc, cartSvc, highlightSvc, height)
+const assistantSvc = useProvideVoluntaryAssistant(stepSvc, dataSvc, formSvc, cartSvc, highlightSvc)
 const {navBinding, onComplete, resetAll} = assistantSvc
 
 onComplete((id) => {
-    transferTo('/pages/voluntary/detail/detail', {id})
+    transferTo(routes.VHSDetail, {data: {id}})
     currentStep.value = 0
     resetAll()
 })

+ 6 - 2
src/types/injectionSymbols.ts

@@ -1,6 +1,6 @@
 import type { InjectionKey } from 'vue'
 import { StudyPlan, StudyPlanStats } from './study';
-import { Study, Transfer, University, Voluntary, Major, VHS } from '.';
+import { Study, Transfer, University, Voluntary, Major, VHS, User } from '.';
 import { useExam } from '@/composables/useExam';
 
 /**
@@ -56,4 +56,8 @@ export const VOLUNTARY_REFRESHER_ENABLED = Symbol('VOLUNTARY_REFRESHER_ENABLED')
 export const UNIVERSITY_DETAIL = Symbol('UNIVERSITY_DETAIL') as InjectionKey<Ref<University.UniversityDetail>>
 export const MAJOR_TREE = Symbol('MAJOR_TREE') as InjectionKey<Ref<Major.MajorItem[]>>
 
-export const VOLUNTARY_DATA = Symbol('VOLUNTARY_DATA') as InjectionKey<Ref<VHS.VoluntaryData>>
+export const VHS_VOLUNTARY_DATA = Symbol('VHS_VOLUNTARY_DATA') as InjectionKey<{
+    voluntaryData: Ref<VHS.VoluntaryData>;
+    validate: (score: string, silence: boolean) => Promise<any>
+}>
+export const VHS_USER_SNAPSHOT = Symbol('VHS_USER_SNAPSHOT') as InjectionKey<Ref<User.UserInfo>>

+ 6 - 1
src/types/user.ts

@@ -164,7 +164,12 @@ export interface UserInfo {
   classSelect: number; // 0: 不可修改班级 1: 可修改班级
   wxOpenId?: string;
 
-  examMajorName?: string; // 职高对口的专业类别
+  // 职高对口相关类型
+  examMajorName?: string; // 专业类别
+  score?: string;
+  mode?: string;
+  seatInput?: string;
+  scoreLock?: number;
 }
 
 export interface VipCardInfo {

+ 3 - 1
src/utils/common.ts

@@ -9,4 +9,6 @@ export const SimulatePickTypes: SimulatePickType[] = [{
 }, {
     text: '保守型',
     value: 2
-}]
+}]
+
+export const recommendMajorSortFn = (a: any, b: any) => a.localPriority - b.localPriority