Parcourir la source

添加购卡跳转

shmily1213 il y a 5 jours
Parent
commit
0fb417aa2b

+ 2 - 2
index.html

@@ -16,10 +16,10 @@
   <!--preload-links-->
   <!--app-context-->
   
-  <!-- <script src="https://unpkg.com/vconsole@3.15.1/dist/vconsole.min.js"></script>
+  <script src="https://unpkg.com/vconsole@3.15.1/dist/vconsole.min.js"></script>
   <script>
     const vconsole = new VConsole();
-  </script> -->
+  </script>
 </head>
 
 <body>

+ 11 - 5
src/components/ie-page/components/vip-popup.vue

@@ -14,7 +14,7 @@
               <text>权限</text>
             </view>
             <view class="mt-10 text-32 text-fore-light">开通会员,立即畅享专属权益与服务</view>
-            <!-- <ie-button custom-class="mt-60" @click="handleBuy">升级VIP权限</ie-button> -->
+            <ie-button custom-class="mt-60" @click="handleBuy">升级VIP权限</ie-button>
             <ie-button type="info" custom-class="mt-40" @click="handleActivate">已线下购买,去激活</ie-button>
           </view>
           <ie-image :is-oss="true" src="/study-bg14.png" custom-class="absolute bottom-0 left-0 w-full h-full z-0"
@@ -33,7 +33,6 @@ import { useTransferPage } from '@/hooks/useTransferPage';
 const { transferTo } = useTransferPage();
 const popupRef = ref();
 const open = () => {
-  console.log('open');
   popupRef.value.open();
 }
 const close = () => {
@@ -41,12 +40,19 @@ const close = () => {
 }
 const handleBuy = () => {
   close();
+  setTimeout(() => {
+    transferTo('/pagesSystem/pages/pay/pay', {
+      data: {}
+    });
+  }, 0);
 }
 const handleActivate = () => {
   close();
-  transferTo('/pagesSystem/pages/card-verify/card-verify', {
-    data: {}
-  });
+  setTimeout(() => {
+    transferTo('/pagesSystem/pages/card-verify/card-verify', {
+      data: {}
+    });
+  }, 0);
 }
 defineExpose({
   open,

+ 2 - 5
src/components/ie-page/ie-page.vue

@@ -76,13 +76,10 @@ const addListener = () => {
 const removeListener = () => {
   uni.$off(EnumEvent.OPEN_VIP_POPUP);
 }
-onMounted(() => {
+
+onShow(() => {
   addListener();
 });
-onBeforeUnmount(() => {
-  removeListener();
-});
-
 onHide(() => {
   removeListener();
 });

+ 0 - 4
src/hooks/useCacheStore.js

@@ -49,7 +49,6 @@ export const useCacheStore = createGlobalState(() => {
     }
     const executeAction = async (action, payload) => {
         let result = action.handler(payload)
-        console.log(result)
         if (result instanceof Promise) result = await result
         return result
     }
@@ -63,7 +62,6 @@ export const useCacheStore = createGlobalState(() => {
     * @returns {Object} 缓存结果
     * */
     const dispatchCache = async (action, payload = undefined, options = undefined) => {
-      console.log(111, action)
         // TODO:并发锁, 并发机会不高且没有致命性影响,以后再优化
         const formatAction = checkActionDefine(action)
         let typeNode = container.get(formatAction.type)
@@ -82,9 +80,7 @@ export const useCacheStore = createGlobalState(() => {
             return cacheData.data
         }
         // cache miss, execute action and cache result
-        console.log(222)
         const result = await executeAction(formatAction, payload)
-        console.log(333, result)
         const cacheOptions = _.merge(defaultOptions, options)
         cacheData = new CacheResult(result, cacheOptions)
         if (!(empty(result) && cacheOptions.emptyIgnore)) {

+ 27 - 10
src/hooks/usePay.ts

@@ -36,6 +36,10 @@ export const usePay = () => {
       });
       uni.$ie.hideLoading();
       outTradeNo.value = data.outTradeNo;
+      const no = outTradeNo.value.split('_')[1];
+      if (no) {
+        payStore.setOrderId(Number(no));
+      }
       h5url.value = data.h5url;
       if (outTradeNo && h5url) {
         clearResultFrame()
@@ -48,18 +52,30 @@ export const usePay = () => {
       uni.$ie.showToast('下单失败,请稍后再试');
     }
   }
-  const checkOrderStatus = async () => {
-    if (!outTradeNo.value) {
-      return;
+
+  const queryPayStatus = () => {
+    if (payStore.orderId) {
+      return queryOrderStatus(payStore.orderId + '')
     }
+    return null;
+  }
 
-    const no = outTradeNo.value.split('_')[1];
-    if (!no) {
-      console.error('checkOrderStatus: 订单号格式错误');
-      callback.value.onFailed?.();
+  const queryOrderStatus = async (orderId: string) => {
+    try {
+      const { data } = await queryOrder(orderId);
+      if (!data) {
+        return null;
+      }
+      return data;
+    } catch (error) {
+      return null;
+    }
+  }
+  const checkOrderStatus = async () => {
+    const no = payStore.orderId;
+    if (no == null) {
       return;
     }
-
     let queryCount = 0; // 当前查询次数
     const queryInterval = 3000; // 查询间隔(毫秒)
     let timerId: ReturnType<typeof setTimeout> | null = null;
@@ -83,7 +99,7 @@ export const usePay = () => {
     const query = async () => {
       try {
         queryCount++;
-        const { data } = await queryOrder(no);
+        const data = await queryOrderStatus(no + '');
         console.log(`checkOrderStatus: 第 ${queryCount} 次查询订单状态`);
         console.log(JSON.stringify(data))
         if (!data) {
@@ -208,6 +224,7 @@ export const usePay = () => {
     ready,
     pay,
     loading,
-    setCallback
+    setCallback,
+    queryPayStatus
   }
 }

+ 0 - 10
src/pagesMain/pages/me/me.vue

@@ -10,18 +10,8 @@
 </template>
 
 <script lang="ts" setup>
-import { usePay } from '@/hooks/usePay';
-import { useUserStore } from '@/store/userStore';
 import meInfo from './components/me-info.vue';
 import meMenu from './components/me-menu.vue';
-
-const userStore = useUserStore();
-const { getPrice } = usePay();
-onLoad(() => {
-  if (userStore.isLogin) {
-    getPrice();
-  }
-});
 </script>
 
 <style></style>

+ 1 - 1
src/pagesOther/pages/career/query-segment/query-segment.vue

@@ -94,8 +94,8 @@ const eqTable = computed(() => {
     eqSeat[r.year] = r.seat || '-'
     eqScore[r.year] = r.score || '-'
   })
-  rows.push(eqSeat)
   rows.push(eqScore)
+  rows.push(eqSeat)
   return { cols, rows }
 })
 

+ 25 - 20
src/pagesStudy/components/vhs-exam-item.vue

@@ -18,16 +18,18 @@
       </view>
       <view class="px-20 py-8 border border-solid rounded-full text-24 text-white"
         :class="[isFinished ? 'bg-success border-success' : 'bg-primary border-primary']" @click="handleStartExam">
-        <text>{{ isFinished ? '查看分析' : '继续考试' }}</text>
+        <text>{{ isFinished ? '查看分析' : '开始考试' }}</text>
       </view>
     </view>
   </view>
 </template>
 <script lang="ts" setup>
-import { EnumPaperType, EnumSimulatedRecordStatus } from '@/common/enum';
+import { EnumPaperType, EnumSimulatedRecordStatus, EnumUserRole } from '@/common/enum';
 import { Study, Transfer } from '@/types';
 import { useTransferPage } from '@/hooks/useTransferPage';
+import { useAuth } from '@/hooks/useAuth';
 
+const { hasPermission } = useAuth();
 const { transferTo } = useTransferPage();
 const props = defineProps<{
   data: Study.VHSPaper;
@@ -38,26 +40,29 @@ const isFinished = computed(() => {
 });
 
 const handleStartExam = () => {
-  if (isFinished.value) {
-    transferTo('/pagesStudy/pages/simulation-analysis/simulation-analysis', {
-      data: {
-        examineeId: props.data.examineeId,
-        paperType: EnumPaperType.SIMULATED
-      }
-    });
-  } else {
-    const pageOptions: Transfer.ExamAnalysisPageOptions = {
-      paperType: EnumPaperType.SIMULATED,
-      readonly: false,
-      simulationInfo: {
-        name: props.data.paperName,
-        // 难受
-        examineeId: props.data.id,
+  const hasAuth = hasPermission([EnumUserRole.VIP]);
+  if (hasAuth) {
+    if (isFinished.value) {
+      transferTo('/pagesStudy/pages/simulation-analysis/simulation-analysis', {
+        data: {
+          examineeId: props.data.examineeId,
+          paperType: EnumPaperType.SIMULATED
+        }
+      });
+    } else {
+      const pageOptions: Transfer.ExamAnalysisPageOptions = {
+        paperType: EnumPaperType.SIMULATED,
+        readonly: false,
+        simulationInfo: {
+          name: props.data.paperName,
+          // 难受
+          examineeId: props.data.id,
+        }
       }
+      transferTo('/pagesStudy/pages/exam-start/exam-start', {
+        data: pageOptions,
+      });
     }
-    transferTo('/pagesStudy/pages/exam-start/exam-start', {
-      data: pageOptions,
-    });
   }
 }
 

+ 7 - 2
src/pagesStudy/pages/study-history/components/vhs-exam-history-student.vue

@@ -1,7 +1,12 @@
 <template>
   <view class="flex flex-col gap-20 px-30 pb-20 bg-back h-fit">
-    <view class="" v-for="(item, index) in simulatedRecordList" :key="index">
-      <vhs-exam-record-item :data="item" />
+    <template v-if="simulatedRecordList.length > 0">
+      <view class="" v-for="(item, index) in simulatedRecordList" :key="index">
+        <vhs-exam-record-item :data="item" />
+      </view>
+    </template>
+    <view v-else class="mt-200">
+      <z-paging-empty-view :empty-view-fixed="false" />
     </view>
   </view>
 </template>

+ 7 - 1
src/pagesSystem/pages/bind-profile/bind-profile.vue

@@ -116,6 +116,8 @@ import { CardInfo, ClassItem, LoginInfo, RegisterInfo, SchoolItem, Scores, UserI
 
 import { getClassList } from '@/api/modules/user';
 import { EnumBindScene, EnumExamRecordType, EnumExamType, EnumUserType } from '@/common/enum';
+import { usePay } from '@/hooks/usePay';
+import { usePayStore } from '@/store/payStore';
 type PrevDataInfo = {
   cardInfo: CardInfo;
   userInfo: UserInfo;
@@ -411,7 +413,7 @@ const handleBack = () => {
   const pages = getCurrentPages();
   const page = pages[pages.length - 2];
   // 如果是登录页,允许直接返回
-  if (page?.route && ['pagesMain/pages/index/index', 'pagesSystem/pages/pay/pay'].includes(page.route)) {
+  if (page?.route && ['pagesMain/pages/index/index', 'pagesMain/pages/me/me', 'pagesSystem/pages/pay/pay'].includes(page.route)) {
     uni.$ie.showToast('请先完善信息');
   } else {
     transferBack();
@@ -419,6 +421,10 @@ const handleBack = () => {
 };
 
 const goHome = () => {
+  // 清除订单信息,不管有没有
+  const payStore = usePayStore();
+  payStore.setOrderId(null);
+  console.log('清除订单信息:', payStore.orderId)
   setTimeout(() => {
     transferTo('/pagesMain/pages/index/index', {
       type: 'reLaunch'

+ 2 - 2
src/pagesSystem/pages/pay/pay.vue

@@ -53,9 +53,9 @@ const handlePay = () => {
   setCallback({
     onSuccess: () => {
       uni.$ie.showSuccess('支付成功');
-      setTimeout(() => {
+      setTimeout(async () => {
         userStore.checkInfoStudentComplete();
-      }, 500);
+      }, 300);
     },
     onFailed: () => {
       uni.$ie.showError('支付失败');

+ 4 - 0
src/store/appStore.ts

@@ -4,6 +4,8 @@ import { getConfig, getProvinces } from '@/api/modules/system';
 import { useDictStore } from '@/store/dictStore';
 import { EnumDictName } from '@/common/enum';
 import { useUserStore } from '@/store/userStore';
+import { usePay } from '@/hooks/usePay';
+
 const preloadDicts: string[] = [
   EnumDictName.EXAM_TYPE
 ];
@@ -31,11 +33,13 @@ export const useAppStore = defineStore('ie-app', {
       this.clear();
       try {
         const dictStore = useDictStore();
+        const { getPrice } = usePay();
         // 预加载字典数据
         dictStore.loadDicts(preloadDicts).then(finish => { });
         const userStore = useUserStore();
         if (userStore.isLogin) {
           await userStore.getUserInfo();
+          getPrice();
         }
         this.isInitialized = true;
         this.sysInfo = uni.getSystemInfoSync();

+ 4 - 0
src/store/payStore.ts

@@ -1,10 +1,14 @@
 export const usePayStore = defineStore('ie-pay', {
   state: () => ({
     price: 468000,
+    orderId: null as number | null
   }),
   actions: {
     setPrice(price: number) {
       this.price = price;
+    },
+    setOrderId(id: number | null) {
+      this.orderId = id;
     }
   },
   persist: {

+ 9 - 3
src/store/userStore.ts

@@ -3,6 +3,7 @@ import { useTransferPage } from '@/hooks/useTransferPage';
 import { getUserBindCard } from '@/api/modules/user';
 import { getUserInfo } from '@/api/modules/login';
 import config from '@/config';
+import { usePay } from '@/hooks/usePay';
 
 import { Study, UserStoreState } from '@/types';
 import { UserInfo, VipCardInfo } from '@/types/user';
@@ -134,7 +135,7 @@ export const useUserStore = defineStore('ie-user', {
       try {
         this.accessToken = token;
         await oldUserStore.SyncToken(token);
-        const userInfo = await this.getUserInfo();;
+        const userInfo = await this.getUserInfo();
         return Promise.resolve({
           success: true,
           userInfo: userInfo
@@ -206,8 +207,10 @@ export const useUserStore = defineStore('ie-user', {
      * @returns 
      */
     checkInfoStudentComplete(): Promise<boolean> {
+      const { queryPayStatus } = usePay();
       return new Promise(async (resolve, reject) => {
-        if (this.user?.bindStatus === EnumUserBindCardStatus.BINDING) {
+        const payResult = await queryPayStatus();
+        if (payResult && payResult.isPaySuccess) {
           const { data } = await getUserBindCard();
           if (data && data.cardNo && data.password) {
             const submitInfo = {
@@ -229,8 +232,9 @@ export const useUserStore = defineStore('ie-user', {
               resolve(false);
             });
           }
+        } else {
+          resolve(false);
         }
-        return resolve(true);
       });
     },
     async getUserInfo() {
@@ -247,6 +251,8 @@ export const useUserStore = defineStore('ie-user', {
       if (org) {
         this.org = org;
       }
+      const { getPrice } = usePay();
+      getPrice();
       return data;
     },
     /**