Procházet zdrojové kódy

优化:1.修复优惠券分享多次调用接口问题;2.优惠券列表界面分享弹窗样式错位问题

haiyang před 10 hodinami
rodič
revize
4f94d0731b

+ 1 - 1
env/.env.development

@@ -6,7 +6,7 @@ VITE_DELETE_CONSOLE = false
 VITE_SHOW_SOURCEMAP = false
 
 # 后台请求地址
-VITE_SERVER_BASEURL = 'http://192.168.1.28:8082/jeecg-boot'
+VITE_SERVER_BASEURL = 'http://192.168.1.28:8080/jeecg-boot'
 # VITE_SERVER_BASEURL = 'http://192.168.1.232:8082/jeecg-boot'
 # VITE_SERVER_BASEURL = 'https://life.baoxianzhanggui.com/locallive-pro-java'
 

+ 5 - 6
src/components/ShortLinkModal.vue

@@ -8,6 +8,7 @@ import { useCouponShare } from '../hooks/useCouponShare'
 const props = defineProps<{
     couponId?: string // 优惠券ID,从父组件传入
     showModal?: boolean // 控制弹窗显示/隐藏的prop
+    shareLink?: string // 分享短链,从父组件传入
 }>()
 
 // 定义emit
@@ -18,12 +19,10 @@ const emit = defineEmits<{
     (e: 'update:showModal', value: boolean): void
 }>()
 
-const { shareLink, copySuccess, shareLoading, shareCoupon, copyShareLink, cleanShareLink } = useCouponShare()
+const { copySuccess, shareLoading, copyShareLink, cleanShareLink } = useCouponShare()
+
 watch(() => props.showModal, (newVal) => {
-    console.log('showModal', newVal)
-    if (newVal && props.couponId) {
-        shareCoupon(props.couponId)
-    }
+    console.log('showModal变化', newVal)
 })
 
 // 弹窗关闭时触发事件
@@ -41,7 +40,7 @@ function handleClose() {
             <view class="share-link-container">
                 <up-loading-icon v-if="shareLoading" mode="semicircle" text="正在获取分享链接中" text-size="18" />
                 <template v-else>
-                    <text class="share-link">{{ shareLink }}</text>
+                    <text class="share-link">{{ shareLink || '' }}</text>
                     <button class="copy-btn" @click="copyShareLink">
                         复制
                     </button>

+ 16 - 2
src/components/discountCoupon.vue

@@ -15,8 +15,17 @@ const props = defineProps({
             ruleDiscountCapAmount: '0',
             validityType: '1',
         }),
+    },
+    scrollViewId: {
+        type: String,
+        default: '',
+    },
+    enableCustomShare: {
+        type: Boolean,
+        default: false,
     }
 })
+const emit = defineEmits(['shareClick'])
 const coupon = computed(() => props.coupon)
 const couponTemplateId = computed(() => coupon.value.templateId || '')
 const deadline = computed(() => {
@@ -53,6 +62,9 @@ async function handleShareCoupon() {
             if (shareLink) {
                 couponShareLink.value = shareLink
                 showShareModal.value = true
+                if (props.enableCustomShare) {
+                    emit('shareClick', couponShareLink.value)
+                }
             }
         }
         finally {
@@ -96,8 +108,10 @@ function handleCloseShareModal() {
             <view>立即</view>
             <view>发券</view>
         </button>
-        <ShortLinkModal v-model:show-modal="showShareModal" :coupon-id="couponTemplateId" :share-link="couponShareLink"
-            @close="handleCloseShareModal" />
+        <template v-if="!enableCustomShare">
+            <ShortLinkModal v-model:show-modal="showShareModal" :coupon-id="couponTemplateId"
+                :share-link="couponShareLink" :scroll-view-id="scrollViewId" @close="handleCloseShareModal" />
+        </template>
     </view>
 </template>
 

+ 16 - 3
src/components/spendAndSaveCoupon_large.vue

@@ -12,8 +12,17 @@ const props = defineProps({
             ruleReductionAmount: '0',
             ruleMinSpendAmount: '0',
         }),
+    },
+    scrollViewId: {
+        type: String,
+        default: '',
+    },
+    enableCustomShare: {
+        type: Boolean,
+        default: false,
     }
 })
+const emit = defineEmits(['shareClick'])
 const coupon = computed(() => props.coupon)
 const couponTemplateId = computed(() => coupon.value.templateId || '')
 const deadline = computed(() => {
@@ -30,7 +39,6 @@ const deadline = computed(() => {
 const category = computed(() => {
     const relatedType = props.coupon.relatedType
     const relatedName = getLastPartAfterSlash(props.coupon.relatedName)
-    console.log(props.coupon.relatedName, relatedName)
     if (relatedType === '1') {
         return `限${relatedName}分类商品使用`
     }
@@ -57,6 +65,9 @@ async function handleShareCoupon() {
             if (shareLink) {
                 couponShareLink.value = shareLink
                 showShareModal.value = true
+                if (props.enableCustomShare) {
+                    emit('shareClick', couponShareLink.value)
+                }
             }
         }
         finally {
@@ -111,8 +122,10 @@ function handleCloseShareModal() {
                 <view>立即</view>
                 <view>发券</view>
             </button>
-            <ShortLinkModal v-model:show-modal="showShareModal" :coupon-id="couponTemplateId"
-                :share-link="couponShareLink" @close="handleCloseShareModal" />
+            <template v-if="!enableCustomShare">
+                <ShortLinkModal v-model:show-modal="showShareModal" :coupon-id="couponTemplateId"
+                    :share-link="couponShareLink" :scroll-view-id="scrollViewId" @close="handleCloseShareModal" />
+            </template>
         </view>
     </view>
 </template>

+ 2 - 1
src/hooks/useCouponShare.ts

@@ -40,6 +40,7 @@ export function useCouponShare() {
                 toLoginPage()
                 return null
             }
+            console.log('分享链接')
             // 判断是否是发券人
             const IssuerResult = await getIssuerStatus()
             if (!IssuerResult) {
@@ -52,7 +53,7 @@ export function useCouponShare() {
                 return null
             }
 
-            // 请求短链
+            // // 请求短链
             const result = await getShareLink({
                 pathUrl: redirectPath.value,
                 templateId: couponId,

+ 15 - 14
src/pages-A/applyForm/index.vue

@@ -70,6 +70,20 @@ const {
     data: couponIssuerApplyByAddData,
 } = useRequest(couponIssuerApplyByAdd, {
     immediate: false,
+}).onSuccess(() => {
+    // 返回上一页
+    console.log('提交成功:', couponIssuerApplyByAddData)
+    uni.showToast({
+        title: '校验通过',
+        icon: 'success',
+    })
+    uni.navigateBack()
+}).onError((error) => {
+    console.log('校验失败:', error)
+    uni.showToast({
+        title: error.error.message,
+        icon: 'error',
+    })
 })
 
 function submitForm() {
@@ -79,20 +93,7 @@ function submitForm() {
                 name: model.name,
                 phone: model.phone,
             }
-            couponIssuerApplyByAddRequest(couponIssuerApplyByAddForm).then(() => {
-                // 返回上一页
-                console.log('提交成功:', couponIssuerApplyByAddData)
-                uni.showToast({
-                    title: '校验通过',
-                    icon: 'success',
-                })
-                uni.navigateBack()
-            }).catch(() => {
-                uni.showToast({
-                    title: '校验失败',
-                    icon: 'error',
-                })
-            })
+            couponIssuerApplyByAddRequest(couponIssuerApplyByAddForm)
         }
         else {
             uni.showToast({

+ 15 - 3
src/pages-A/discountcouponList/index.vue

@@ -1,5 +1,6 @@
 <script lang="ts" setup>
 import { computed, ref } from 'vue'
+import ShortLinkModal from '@/components/ShortLinkModal.vue'
 import { useScroll } from '@/hooks/useScroll'
 import { useShare } from '@/hooks/useShare'
 import { safeAreaInsets } from '@/utils'
@@ -44,6 +45,9 @@ const safeBottomHeight = computed(() => {
 
 const topSafeAreaHeight = safeAreaInsets?.top || 0
 
+const couponShareLink = ref('')
+const showShareModal = ref(false)
+
 // 页面加载时获取数据
 onLoad((options) => {
     if (options.type) {
@@ -76,6 +80,11 @@ onShareAppMessage(async (options) => {
     return null
 })
 // #endif
+
+function handleShareClick(shareLink) {
+    couponShareLink.value = shareLink
+    showShareModal.value = true
+}
 </script>
 
 <template>
@@ -83,11 +92,13 @@ onShareAppMessage(async (options) => {
         <view class="safe-top" :style="{ height: `${topSafeAreaHeight}px` }" />
         <up-navbar title="折扣券" :auto-back="true" />
         <!-- <up-status-bar /> -->
-        <scroll-view :style="{ paddingTop: `${topSafeAreaHeight}px` }" class="discount-coupon-list" scroll-y
-            refresher-enabled :refresher-triggered="loading" @refresherrefresh="onRefresh" @scrolltolower="onLoadMore">
+        <scroll-view id="discountCouponScrollView" :style="{ paddingTop: `${topSafeAreaHeight}px` }"
+            class="discount-coupon-list" scroll-y refresher-enabled :refresher-triggered="loading"
+            @refresherrefresh="onRefresh" @scrolltolower="onLoadMore">
             <view class="list-content">
                 <view v-for="item in data" :key="item.templateId" class="discount-coupon-item">
-                    <DiscountCoupon :coupon="item" />
+                    <DiscountCoupon :coupon="item" scroll-view-id="discountCouponScrollView" :enable-custom-share="true"
+                        @share-click="handleShareClick" />
                 </view>
 
                 <!-- 加载状态提示 -->
@@ -100,6 +111,7 @@ onShareAppMessage(async (options) => {
             </view>
         </scroll-view>
 
+        <ShortLinkModal v-model:show-modal="showShareModal" :share-link="couponShareLink" />
         <!-- 安全区底部占位 -->
         <view class="safe-bottom" :style="{ height: `${safeBottomHeight}px` }" />
     </view>

+ 33 - 21
src/pages-A/spendAndSaveCouponList/index.vue

@@ -1,5 +1,6 @@
 <script lang="ts" setup>
 import { computed, ref } from 'vue'
+import ShortLinkModal from '@/components/ShortLinkModal.vue'
 import { useScroll } from '@/hooks/useScroll'
 import { useShare } from '@/hooks/useShare'
 import { safeAreaInsets } from '@/utils'
@@ -37,28 +38,28 @@ const {
     pageSize: 7,
 })
 
-const { getShareConfig: getShareCouponConfig } = useShare({
-    shareType: 'COUPON',
-    imageSource: 'REMOTE',
-    path: '/pages/receiveCoupon/index',
-    pathParamKey: 'couponShareRecordId',
-})
+// const { getShareConfig: getShareCouponConfig } = useShare({
+//     shareType: 'COUPON',
+//     imageSource: 'REMOTE',
+//     path: '/pages/receiveCoupon/index',
+//     pathParamKey: 'couponShareRecordId',
+// })
 
 // #ifdef MP-WEIXIN
 // 分享功能实现
 // 分享生命周期函数
-onShareAppMessage(async (options) => {
-    if (options.from === 'button' && options.target.dataset.shareType === 'coupon') {
-        const couponId = options.target.dataset.couponId
-        const couponinfo = await getCouponDetail({ templateId: couponId })
-        return await getShareCouponConfig({
-            imageUrl: couponinfo?.imageUrl,
-        }, {
-            shareContentId: couponId,
-        })
-    }
-    return null
-})
+// onShareAppMessage(async (options) => {
+//     if (options.from === 'button' && options.target.dataset.shareType === 'coupon') {
+//         const couponId = options.target.dataset.couponId
+//         const couponinfo = await getCouponDetail({ templateId: couponId })
+//         return await getShareCouponConfig({
+//             imageUrl: couponinfo?.imageUrl,
+//         }, {
+//             shareContentId: couponId,
+//         })
+//     }
+//     return null
+// })
 // #endif
 
 // 计算底部安全区高度
@@ -68,6 +69,9 @@ const safeBottomHeight = computed(() => {
 
 const topSafeAreaHeight = safeAreaInsets?.top || 0
 
+const couponShareLink = ref('')
+const showShareModal = ref(false)
+
 // 页面加载时获取数据
 onLoad((options) => {
     if (options.type) {
@@ -75,6 +79,11 @@ onLoad((options) => {
         onRefresh()
     }
 })
+
+function handleShareClick(shareLink) {
+    couponShareLink.value = shareLink
+    showShareModal.value = true
+}
 </script>
 
 <template>
@@ -82,11 +91,13 @@ onLoad((options) => {
         <view class="safe-top" :style="{ height: `${topSafeAreaHeight}px` }" />
         <up-navbar title="满减券" :auto-back="true" />
         <!-- <up-status-bar /> -->
-        <scroll-view :style="{ paddingTop: `${topSafeAreaHeight}px` }" class="discount-coupon-list" scroll-y
-            refresher-enabled :refresher-triggered="loading" @refresherrefresh="onRefresh" @scrolltolower="onLoadMore">
+        <scroll-view id="spendAndSaveCouponScrollView" :style="{ paddingTop: `${topSafeAreaHeight}px` }"
+            class="discount-coupon-list" scroll-y refresher-enabled :refresher-triggered="loading"
+            @refresherrefresh="onRefresh" @scrolltolower="onLoadMore">
             <view class="list-content">
                 <view v-for="item in data" :key="item.templateId" class="discount-coupon-item">
-                    <SpendAndSaveCoupon :coupon="item" />
+                    <SpendAndSaveCoupon :coupon="item" scroll-view-id="spendAndSaveCouponScrollView"
+                        :enable-custom-share="true" @share-click="handleShareClick" />
                 </view>
 
                 <!-- 加载状态提示 -->
@@ -99,6 +110,7 @@ onLoad((options) => {
             </view>
         </scroll-view>
 
+        <ShortLinkModal v-model:show-modal="showShareModal" :share-link="couponShareLink" />
         <!-- 安全区底部占位 -->
         <view class="safe-bottom" :style="{ height: `${safeBottomHeight}px` }" />
     </view>