Переглянути джерело

```
feat: 更新API基础URL配置和课程标签功能

- 修改.env.development中的API基础URL配置
- 优化课程详情页面的导航逻辑
- 添加课程标签获取功能,包括学习阶段、教程分类和技能标签
- 增加国际化语言包,包含返回、购买、成功、失败、提示等翻译
- 实现课程购买确认功能,包括余额检查和支付流程
- 优化订单确认页面,添加返回按钮
- 修复支付成功后用户信息更新问题
- 添加通用购买确认工具函数
```

zhangningning 1 місяць тому
батько
коміт
37e2bf4d3c

+ 1 - 1
.env.development

@@ -1,6 +1,6 @@
 # 乔功
 VITE_API_BASE_URL=http://192.168.100.134:8080/api
 # 高运甲
-# VITE_API_BASE_URL=http://192.168.100.89:8080/api
+VITE_API_BASE_URL=http://192.168.100.89:8080/api
 
 

+ 1 - 1
src/App.vue

@@ -108,7 +108,7 @@ const activeIndex = computed(() => {
   if (route.path.startsWith('/mibi-shop')) {
     return '5'
   }
-  return '1' // 默认返回首页
+  return '' // 默认返回首页
 });
 // 处理注销
 const handleLogout = () => {

+ 7 - 0
src/api/course.js

@@ -8,4 +8,11 @@ export function getCourseList(data = {}) {
 // 课程详情
 export function getCourseDetail(data = {}) {
   return request.get('/course/'+data.id)
+}
+// 获取课程标签
+//学习阶段  bus_study_stage
+//教程分类  bus_course_category
+//技能标签  bus_skill_tag
+export function getDictType(data = {}) {
+  return request.get('/system/dict/type')
 }

+ 5 - 0
src/locales/en.js

@@ -35,6 +35,11 @@ export default {
     quantity: 'Quantity',
     amount: 'Amount',
     RMB: 'RMB',
+    back: 'Back',
+    buy: 'Buy',
+    success: 'Success',
+    fail: 'Fail',
+    tip: 'Tip',
   },
   login: {
     smsLogin: 'SMS Login',

+ 5 - 0
src/locales/zh-CN.js

@@ -36,6 +36,11 @@ export default {
     quantity: '数量',
     amount: '金额',
     RMB: '元',
+    back: '返回',
+    buy: '购买',
+    success: '成功',
+    fail: '失败',
+    tip: '提示',
   },
   login: {
     smsLogin: '短信登录',

+ 17 - 10
src/pages/LearningSystem/LearningSystemDetail.vue

@@ -77,6 +77,9 @@
 
   // 引入api
   import { getCourseDetail } from '@/api/course.js'
+  import { confirmBuy } from '@/utils/util.js'
+  import { useI18n } from 'vue-i18n' 
+  const { t } = useI18n() 
 
   import { useRouter, useRoute } from 'vue-router'
   const router = useRouter()
@@ -92,7 +95,7 @@
   import { useAppStore } from '@/pinia/appStore'
   const appStore = useAppStore()
 
-  const activeName = ref('xuxibiji');
+  const activeName = ref('first');
 
  
 
@@ -114,15 +117,19 @@
   };
   const goDetail = (item) => {
     //如果未支付,跳转到支付页面
-    // if(true){
-    //   router.push({
-    //     path: `/order-confirm`,
-    //     query: {
-    //       courseId: item.courseId,
-    //     }
-    //   })
-    //   return
-    // }
+    if(false ){
+      confirmBuy({
+        callback:getDetail,
+        appStore,
+        router,
+        price:item.coursePrice,
+        t,
+        productId:item.courseId,
+        orderType:'course_purchase',
+        payMethod:'BMI'
+      })
+      return
+    }
     //增加参数名称
     router.push({
       path: `/learning-system/detail/course`,

+ 10 - 3
src/pages/order/orderConfirm.vue

@@ -1,6 +1,10 @@
 <template>
   <div class="orderConfirm container-height">
-    <Breadcrumb />
+    <!-- <Breadcrumb /> -->
+    <el-button class="mt20 mb20" @click="router.back()">
+      <el-icon><ArrowLeft /></el-icon>
+      <span>{{$t('common.back')}}</span>
+    </el-button>
     <div class="gap10">
       <div class="font_size24 bold">{{$t('route.recharge')}}</div>
       <!-- <span class="font_size16 color_price">{{$t('common.orderConfirmTip')}}</span> -->
@@ -209,6 +213,8 @@ import qrcode from 'qrcode'
 import { reactive, ref, onBeforeUnmount, nextTick } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
 import DGTMessage from '@/utils/message'
+import { useAppStore } from '@/pinia/appStore'
+const appStore = useAppStore()
 //获取参数
 const route = useRoute()
 const router = useRouter()
@@ -317,7 +323,8 @@ const startPolling = () => {
   pollingTimer.value = setInterval(() => {
     payResult({id:orderId.value}).then((res) => {
       if (res.code == 200 && res.data) {
-        DGTMessage.success('支付成功!')
+        DGTMessage.success('支付成功!');
+        appStore.USERINFO();
         stopPolling()
       }
     })
@@ -377,7 +384,7 @@ const payConfigDearchFn = () => {
       BusinessAccount.value = res.data || [];
     }
   })
-}
+};
 
 
 

+ 1 - 1
src/pinia/appStore.js

@@ -35,7 +35,7 @@ export const useAppStore = defineStore('app', {
       localStorage.setItem('userInfo', JSON.stringify(userInfo));
       // uniLogin();
     },
-     async USERINFO(force) {
+    async USERINFO(force) {
       try {
         if (!this.token) {
           return;

+ 46 - 0
src/utils/util.js

@@ -1,5 +1,7 @@
 import DGTMessage from '@/utils/message'//浏览器下载文件
 import { signUp } from '@/api/apply.js'
+import { ElMessageBox } from 'element-plus'
+import { createOrder } from '@/api/order.js'
 export function downloadFile(url, fileName) {
   if (!url) {
     DGTMessage.error('文件地址不存在');
@@ -46,3 +48,47 @@ export function formatDeadline(deadline) {
   const diffHours = Math.ceil(diffTime / (1000 * 60 * 60)) % 24;
   return {diffDays,diffHours};
 }
+export function confirmBuy({type='baoMiBalance',price=0,callback,appStore,router,t,payMethod,orderType,productId}){
+  const balance = appStore.userInfo?.[type] || 0;
+  if(balance < price ){
+    ElMessageBox.confirm('您的余额不足,是否前往充值?', t('common.tip'), {
+      confirmButtonText: t('common.confirm'),
+      cancelButtonText: t('common.cancel'),
+      type: 'warning'
+    }).then(() => {
+      // 确认购买
+      router.push({
+        path: `/order-confirm`,
+      })
+    }).catch(() => {
+      // 取消购买
+    });
+  }else{
+    const unit = type === 'baoMiBalance' ? t('common.baomibi') : t('common.mibi');
+    const ms = `${t('common.payNow')} ${price} ${unit}?`
+    ElMessageBox.confirm(ms, t('common.tip'), {
+      confirmButtonText: t('common.confirm'),
+      cancelButtonText: t('common.cancel'),
+      type: 'warning'
+    }).then(async () => {
+      const res = await createOrder({
+        payMethod,
+        orderType,
+        orderAmt:price,
+        productId,
+        orderNum:1
+      })
+      if(res.code === 200){
+        DGTMessage.success(t('common.buy')+t('common.success'));
+        if(callback && typeof callback === 'function'){
+          callback();
+        }
+      }else{
+        // DGTMessage.error(res.msg || t('common.buy')+t('common.fail'));
+      }
+      
+    }).catch(() => {
+      // 取消购买
+    });
+  }
+}