dxz1228 лет назад: 3
Родитель
Сommit
91337b7f53

+ 5 - 0
src/apis/model/order.model.ts

@@ -275,6 +275,11 @@ export interface OrderCreateShoppingModel {
275 275
     cart_id: string
276 276
 }
277 277
 
278
+//
279
+export interface ProductSkustatusModel {
280
+   status:number
281
+   message:string
282
+}
278 283
 export interface ProductSkuModel {
279 284
     cart_id: string,
280 285
     unique : string

+ 6 - 5
src/apis/order.api.ts

@@ -1,8 +1,8 @@
1
-import {defHttp} from "~/utils/http"
1
+import {defHttp, detailHttp, skuhttp} from "~/utils/http"
2 2
 
3 3
 import type {
4 4
     IntegralOrderCreateModel, OrderCheckModel, OrderCreateModel,
5
-    OrderCreateShoppingModel, ProductSkuModel, OrderListDataModel, OrderListObligationResult, OrderListResult, OrderQuantityModel
5
+    OrderCreateShoppingModel, ProductSkuModel, OrderListDataModel, OrderListObligationResult, OrderListResult, OrderQuantityModel, ProductSkustatusModel
6 6
 } from "~/apis/model/order.model"
7 7
 import type {ThirdOrderResult} from "~/apis/model/third-order.model";
8 8
 import type {CommentProductRequest} from "~/apis/model/comment-product";
@@ -211,10 +211,11 @@ export function createShopping(params: {
211 211
 /**
212 212
  * 改变购物车商品sku
213 213
  */
214
-export function changeProdoctSku(cart_id:string,unique:string): Promise<ProductSkuModel> {
214
+export function changeProdoctSku(cart_id:string,unique:string): Promise<ProductSkustatusModel> {
215 215
     console.log(unique,'order的api接收的unique')
216
-    return defHttp.post({
217
-        url:API.CHANGE_PRODUCT_SKU + `/${cart_id}?unique=${unique}`,
216
+    console.log(cart_id,'order的api接收的unique')
217
+    return skuhttp.post({
218
+        url:API.CHANGE_PRODUCT_SKU + `/${cart_id}?`,
218 219
         data:{
219 220
             unique
220 221
         }

+ 1 - 1
src/components/CXBBackTop/CXBBackTop.vue

@@ -40,7 +40,7 @@ const scrollToTop = function () {
40 40
   border-radius: 50%;
41 41
   z-index: 999;
42 42
   right: 15px;
43
-  bottom: 20%;
43
+  bottom: 8%;
44 44
 }
45 45
 .backTopImg{
46 46
   width: 40px;

+ 42 - 55
src/components/CXBSkuPopup/CXBSkuPopup.vue

@@ -1,14 +1,14 @@
1 1
 <script setup lang="ts">
2 2
 import FPopup from "~/components/FPopup/FPopup.vue";
3
-import {CANCEL_EVENT, CONFIRM_EVENT} from "~/constants/event";
3
+import { CANCEL_EVENT, CONFIRM_EVENT } from "~/constants/event";
4 4
 import FPrice from "~/components/FPrice/FPrice.vue";
5
-import {SkuModel} from "~/apis/model/product.model";
6
-import {computed} from "vue";
7
-import {PopupProps} from "~/components/FPopup";
8
-import {CLOSE_EVENT, OPEN_EVENT, UPDATE_SHOW_EVENT} from "~/components/constants";
5
+import { SkuModel } from "~/apis/model/product.model";
6
+import { computed } from "vue";
7
+import { PopupProps } from "~/components/FPopup";
8
+import { CLOSE_EVENT, OPEN_EVENT, UPDATE_SHOW_EVENT } from "~/components/constants";
9 9
 import CXBButton from "~/components/CXBButton/CXBButton.vue";
10 10
 import FButton from "~/components/FButton/FButton.vue";
11
-import {findLast} from "lodash-es";
11
+import { findLast } from "lodash-es";
12 12
 const emit = defineEmits()
13 13
 const props = defineProps({
14 14
   show: {
@@ -24,8 +24,11 @@ const props = defineProps({
24 24
     default: () => {
25 25
       return []
26 26
     }
27
-  }
27
+  },
28 28
 })
29
+
30
+
31
+
29 32
 const show = ref(props.show || false)
30 33
 
31 34
 const showValue = computed<PopupProps['show']>({
@@ -75,16 +78,18 @@ const skuList = computed(() => {
75 78
 
76 79
 onMounted(() => {
77 80
   emit('selected:item', currentSku)
78
-
81
+  
79 82
 })
80 83
 
81
-function handleSelectedSku(skuItem) {
84
+function handleSelectedSku(skuItem: any) {
82 85
   currentSku.value = skuItem
86
+  console.log('我是数据', currentSku.value);
87
+ 
83 88
   emit('selected:item', currentSku)
84 89
 }
85 90
 function handleClose() {
86 91
   showValue.value = false
87
-
92
+  
88 93
   emit(CLOSE_EVENT)
89 94
 }
90 95
 
@@ -102,79 +107,66 @@ function handleCountChange(value) {
102 107
 </script>
103 108
 
104 109
 <template>
105
-  <FPopup
106
-      v-model:show="showValue"
107
-      @close="onCancel"
108
-      position="bottom"
109
-      exClass="rounded-rt-xl rounded-lt-xl flex flex-col pb-safe min-h-[70%] max-h-[80%] h-full"
110
-
111
-  >
110
+  <FPopup v-model:show="showValue" @close="onCancel" position="bottom"
111
+    exClass="rounded-rt-xl rounded-lt-xl flex flex-col pb-safe min-h-[70%] max-h-[80%] h-full">
112 112
     <div class="flex flex-col justify-between h-full">
113 113
       <div class="flex-1">
114 114
         <div class="p-3 flex flex-col gap-3">
115 115
           <div class="flex flex-row gap-3">
116
-            <image :src="detail.image"
117
-                   v-if="currentSku"
118
-                   mode="aspectFit" class="w-25 h-25 rounded"></image>
116
+            <image :src="currentSku.image" v-if="currentSku" mode="aspectFit" class="w-25 h-25 rounded"></image>
119 117
             <div class="flex flex-col w-full">
120 118
 
121 119
               <div class="flex gap-2 justify-between w-full">
122 120
                 <div class="text-overflow text-xs flex-1 line-clamp-2 h-fit" v-if="detail && detail.store_name">
123 121
                   {{ detail.store_name }}
124 122
                 </div>
125
-                <div
126
-                    @tap="handleClose"
127
-                    class="i-tabler-x w-5 h-5 text-gray-500"></div>
123
+                <div @tap="handleClose" class="i-tabler-x w-5 h-5 text-gray-500"></div>
128 124
               </div>
129 125
 
130 126
 
131 127
               <div class="flex flex-col" v-if="currentSku">
132 128
                 <div class="text-[12px] text-right text-gray-500 ">
133
-                  剩余库存{{currentSku.stock}}
129
+                  剩余库存{{ currentSku.stock }}
134 130
                 </div>
135 131
                 <div class="flex items-end gap-2" v-if="detail.mer_id === '148'">
136 132
                   {{ (currentSku.price * 30).toFixed(2) }} 积分
137 133
                 </div>
138 134
                 <div class="flex items-end gap-2" v-else>
139
-                  <FPrice :price="currentSku.price"/>
140
-                  <FPrice v-if="currentSku.ot_price" :price="currentSku.ot_price" :ex-class="'!text-black text-xs font-bold'" need-symbol strike-through/>
135
+                  <FPrice :price="currentSku.price" />
136
+                  <FPrice v-if="currentSku.ot_price" :price="currentSku.ot_price"
137
+                    :ex-class="'!text-black text-xs font-bold'" need-symbol strike-through />
141 138
                 </div>
142 139
               </div>
143 140
 
144 141
             </div>
145 142
           </div>
146 143
 
147
-<!--          <template v-if="skuList && skuList.length > 0"></template>-->
148
-<!--          <scroll-view-->
149
-<!--              :scroll-y="true"-->
150
-<!--              class="h-20"-->
151
-<!--          >-->
152
-
153
-            <div class="text-xs flex" v-if="skuList && skuList.length > 0">规格</div>
154
-            <div class="flex flex-row gap-2  flex-wrap ">
155
-              <div
156
-                  v-for="(item, index) in skuList"
157
-                  :key="index"
158
-                  @tap="handleSelectedSku(item)"
159
-
160
-              >
161
-                <div
162
-                    v-if="item.sku && item.sku !== ''"
163
-                    class="text-[11px] border border-solid rounded p-1 px-1 "
164
-                    :class="currentSku.unique === item.unique ? 'border-primary text-primary' : 'border-gray-500 text-gray-500'"
165
-                >
166
-                  {{ item.sku }}
144
+          <!--          <template v-if="skuList && skuList.length > 0"></template>-->
145
+          <!--          <scroll-view-->
146
+          <!--              :scroll-y="true"-->
147
+          <!--              class="h-20"-->
148
+          <!--          >-->
149
+
150
+          <div class="text-xs flex" v-if="skuList && skuList.length > 0">规格</div>
151
+          <div class="flex flex-row gap-2  flex-wrap ">
152
+            <div v-for="(item, index) in skuList" :key="index" @tap="handleSelectedSku(item)">
153
+              <div v-if="item.sku && item.sku !== ''" class="text-[11px] border border-solid rounded p-1 px-1 "
154
+                :class="currentSku.unique === item.unique ? 'border-primary text-primary' : 'border-gray-500 text-gray-500'">
155
+                {{ item.sku }}
167 156
 
168
-                </div>
169 157
               </div>
158
+
159
+
160
+
170 161
             </div>
162
+          </div>
171 163
 
172
-<!--          </scroll-view>-->
164
+          <!--          </scroll-view>-->
173 165
         </div>
174 166
         <div class="p-3">
175 167
           <div class="flex  justify-between text-sm">
176 168
             数量
177
-            <nut-input-number v-model="count" @change="handleCountChange"/>
169
+            <nut-input-number v-model="count" @change="handleCountChange" />
178 170
           </div>
179 171
 
180 172
 
@@ -182,12 +174,7 @@ function handleCountChange(value) {
182 174
       </div>
183 175
 
184 176
       <div class="px-3 pb-10">
185
-        <FButton
186
-            @click="handleAddCart"
187
-            size="small"
188
-            :exClass="['!bg-primary', 'rounded-full', 'text-white']"
189
-            block
190
-        >
177
+        <FButton @click="handleAddCart" size="small" :exClass="['!bg-primary', 'rounded-full', 'text-white']" block>
191 178
           确定
192 179
         </FButton>
193 180
 

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
src/pages.json


+ 41 - 36
src/pages/order_addcart/index.vue

@@ -34,7 +34,7 @@ const state = reactive({
34 34
 
35 35
 
36 36
   totalCartCount: 0,
37
-  totalPrice: 0,
37
+  totalPrice: '',
38 38
   selectAllIndeterminate: false,
39 39
 
40 40
   cart_id: [],
@@ -45,31 +45,39 @@ const state = reactive({
45 45
 
46 46
   isShowSku: false,
47 47
   cartNum: 1,
48
-  currentSku: {},
48
+  currentSku: {
49
+    unique: ''
50
+  },
49 51
   //新增
50 52
   shareImage: '',
51 53
   isRelation: '',
52 54
   shareId: '',
53
-  status:'',
55
+  status: '',
54 56
 })
55
-
57
+let uniqueclone=ref('')
56 58
 const detail: any = ref(null)
57 59
 
58 60
 
59
-function onSelectedSku(item) {
60
-  state.currentSku = item
61
+function onSelectedSku(currentSku : any ) {
62
+  console.log("item",currentSku);
63
+  
64
+  state.currentSku = currentSku
65
+
61 66
 }
62 67
 
68
+
63 69
 function handleCreateShopping() {
64 70
   // console.log(state.flag)
65
-  console.log(state.currentSku.unique, '切换sku展示的商品', state)
71
+  console.log(state.currentSku.unique, '切换sku展示的商品', state.changeSkuCart_id)
72
+  uniqueclone.value = state.currentSku.unique
66 73
   changeProdoctSku(
67 74
     // product_attr_unique: JSON.stringify(state.currentSku),
68 75
     // detail.value.unique
69 76
     state.changeSkuCart_id,
70 77
     state.currentSku.unique
71 78
   ).then(res => {
72
-    console.log(res)
79
+    console.log('我是res123', res)
80
+
73 81
     // if (res.cart_id) {
74 82
     //   // console.log(state.flag)
75 83
     //   if (state.flag == '1' || state.flag == '3') {
@@ -87,10 +95,14 @@ function handleCreateShopping() {
87 95
     //     state.isShowSku = false
88 96
     //   }
89 97
     // }
90
-    // if(res.status === 200){
91
-    //   state.isShowSku = false
92
-    // }
93
-    state.isShowSku = false
98
+    
99
+    if (res.status === 200) {
100
+      state.isShowSku = false
101
+      console.log("修改后",state.currentSku);
102
+      console.log('我是uniqueclone',uniqueclone);
103
+      detail.value.unique=uniqueclone.value
104
+    }
105
+
94 106
     uni.$on('cart-reload', () => {
95 107
       // console.log('新商品添加...')
96 108
       state.cart_id = []
@@ -202,7 +214,7 @@ function loadCartList() {
202 214
     uni.hideLoading()
203 215
     shopping.value = res
204 216
 
205
-    // console.log(res)
217
+    // console.log('shoping',res)
206 218
     shopping.value?.list.forEach((shopItem, index) => {
207 219
       // shopItem.allCheck = true
208 220
 
@@ -273,6 +285,8 @@ function shopCheck(shopItem) {
273 285
 }
274 286
 
275 287
 function handleShopTitleClick(shopItem) {
288
+  console.log('shopItem',shopItem);
289
+  
276 290
   if (shopItem.allCheck) {
277 291
     shopItem.list.forEach((good, index) => {
278 292
       good.check = true
@@ -326,7 +340,7 @@ function cartAllCheck(type: 'single' | 'all') {
326 340
         allArr.push(goods)
327 341
       }
328 342
     }
329
-
343
+    
330 344
     // 总金额|总数
331 345
     goods.list.forEach(goodItem => {
332 346
       if (goodItem.check) {
@@ -336,7 +350,7 @@ function cartAllCheck(type: 'single' | 'all') {
336 350
       }
337 351
     })
338 352
   })
339
-
353
+  
340 354
   isAllSelect.value = allArr.length === shopping.value?.list.length
341 355
   // state.totalCartCount = totalNum
342 356
   state.totalPrice = totalMoney
@@ -420,7 +434,7 @@ function handleSubmit() {
420 434
   }
421 435
 
422 436
 }
423
-
437
+//删除功能
424 438
 function handleDelete() {
425 439
   // const cart_id = <any>[]
426 440
   shopping.value?.list.forEach(shopItem => {
@@ -509,21 +523,18 @@ onPageScroll((page) => {
509 523
     headerClass.value = ''
510 524
   }
511 525
 })
512
-const openTestLog1 = (a) => {
513
-  console.log('商品的id', a.product_id)
514
-  console.log('测试点击sku,多规模');
515
-  state.isShowSku = true
516
-
517
-}
518 526
 
519 527
 function openTestLog(element) {
520 528
   state.isShowSku = true
521 529
   state.changeSkuCart_id = element.cart_id
522
-  console.log('用户点击sku,展示商品id和购物车id', element.product_id, element.cart_id)
530
+  console.log('用户点击sku', element.product_attr_unique)
531
+  uniqueclone.value=''
523 532
   getProductDetail(element.product_id).then(res => {
524
-    console.log(res.data, '点击sku,展示返回的res')
533
+    console.log('res>>>',res);
534
+    uniqueclone.value=element.product_attr_unique
525 535
     detail.value = res.data
526
-    // console.log(detail.value,'点击sku获取的商品信息,存储的detail')
536
+    detail.value.unique=uniqueclone.value
537
+    console.log(detail.value,'点击sku获取的商品信息,存储的detail')
527 538
     state.shareImage = detail.value.image
528 539
     if (res && res.mer_id && res.mer_id === '148') {
529 540
       if (detail.value && detail.value.price) {
@@ -539,12 +550,8 @@ function openTestLog(element) {
539 550
         console.info(res)
540 551
       })
541 552
     }
542
-
543
-    // if (detail.value.mer_id === '148') {
544
-    // }
545 553
     uni.hideLoading()
546 554
   }).catch(error => {
547
-    // console.log(error)
548 555
     uni.showToast({
549 556
       icon: "none",
550 557
       title: error
@@ -555,13 +562,11 @@ function openTestLog(element) {
555 562
     })
556 563
   })
557 564
 }
558
-const closeTestLog = () => {
559
-  console.log('测试点击sku,多规模');
560 565
 
561
-}
562 566
 </script>
563 567
 <template>
564 568
   <div class="">
569
+     <CXBBackTop :Scroll_X="Scroll_X" />
565 570
     <div v-if="hasShopping" class="bg-white h-10 fixed top-0 w-full z-1 flex justify-end ">
566 571
       <div class="pr-3">
567 572
         <FButton size="small" @click="handleManageCart">
@@ -595,7 +600,7 @@ const closeTestLog = () => {
595 600
             <div class="flex">
596 601
               <nut-checkbox v-model="goodItem.check" @change="handleGoodsItemCheck" label="单选"
597 602
                 class="!text-primary"></nut-checkbox>
598
-              <image @click="handleProductItemClick(goodItem)" :src="goodItem.product.image" mode="aspectFill"
603
+              <image @click="handleProductItemClick(goodItem)" :src="goodItem.productAttr.image" mode="aspectFill"
599 604
                 class="w-18 h-18 rounded"></image>
600 605
             </div>
601 606
 
@@ -623,7 +628,7 @@ const closeTestLog = () => {
623 628
       </div>
624 629
     </div>
625 630
 
626
-    <CXBBackTop :Scroll_X="Scroll_X" />
631
+    <!-- <CXBBackTop :Scroll_X="Scroll_X" /> -->
627 632
     <div class="pb-12">
628 633
       <div class="flex flex-row justify-center items-center gap-3 font-bold text-sm p-3 ">
629 634
         <image :src="like_adorn_220628Image" mode="widthFix" class="w-6 h-6"></image>
@@ -653,8 +658,8 @@ const closeTestLog = () => {
653 658
       </div>
654 659
     </div>
655 660
   </div>
656
-  <CXBSkuPopup v-model:show="state.isShowSku" :detail="detail" @selected:item="onSelectedSku"
657
-    @submit="handleCreateShopping" @count-change="handleCountChange" />
661
+  <CXBSkuPopup  v-model:show="state.isShowSku" :detail="detail" @selected:item="onSelectedSku"
662
+    @submit="handleCreateShopping" @count-change="handleCountChange"   />
658 663
   <div v-if="hasShopping" class="fixed bottom-0 w-full z-3">
659 664
     <div class="bg-white h-10 flex justify-between" v-if="shopping && shopping.list">
660 665
       <div class="flex justify-center items-center gap-2 pl-3" @tap.stop="handleSelectAll">

+ 0 - 121
src/pages/sold-out/sold-out.vue

@@ -1,121 +0,0 @@
1
-<script setup lang='ts'>
2
-import { ref, reactive, defineProps } from 'vue'
3
-import { getRecommendList } from '~/apis/merchant'
4
-import { DcProductModel } from '~/apis/model/dacang.model'
5
-import { DyProductModel, JdProductModel, SuNingProductModel, TaobaoProductThirdPartyWaresModel, VipProductModel } from '~/apis/model/product.model'
6
-import MerchantProductCard from "~/pages/store/home/components/MerchantProductCard.vue";
7
-let state=reactive({
8
-  recommendList:[]
9
-})
10
-
11
-onLoad((options: any) => {
12
-  YouLike()
13
-  uni.hideLoading()
14
-
15
-})
16
-
17
-
18
-//猜你喜欢
19
-function YouLike() {
20
-  getRecommendList({
21
-    page: 1,
22
-    limit: 10
23
-  }).then(res => {
24
-    state.recommendList = res.list
25
-    console.log(state.recommendList);
26
-    
27
-  })
28
-}
29
-
30
-function handleProductItemClick(
31
-  item:
32
-    JdProductModel
33
-    & DcProductModel
34
-    & DyProductModel
35
-    & SuNingProductModel
36
-    & TaobaoProductThirdPartyWaresModel
37
-    & VipProductModel
38
-) {
39
-  // function navigateToDetail(params) {
40
-  //   let otherDetailUrl = `/pages/store/product/other`
41
-  //   return uni.navigateTo({
42
-  //     url: `${otherDetailUrl}?params=${params}`
43
-  //   })
44
-  // }
45
-  // 大仓
46
-  uni.navigateTo({
47
-    url: `/pages/store/product/detail?id=${item.product_id}`
48
-  })
49
-}
50
-
51
-
52
-
53
-</script>
54
-
55
-<template>
56
-  <div class="box-out">
57
-    <div class="flex-box pb-3 px-3 ">
58
-      <div class="img-div">
59
-        <image lazy-load src="../../../static/icon/商品下架不存在@3x.png" mode="widthFix" class=" top-0 right-0 sold-out ">
60
-        </image>
61
-      </div>
62
-      <div class="out-conter">该商品下架不存在</div>
63
-    </div>
64
-
65
-  </div>
66
-  <div class="flex flex-col pb-safe gap-3">
67
-      <div class="p-3 bg-white">
68
-        <div
69
-            class="before:content-[''] before:block before:absolute before:w-1 before:h-full before:bg-gradient-to-b from-red-500 to-red-600 before:rounded relative inline-block">
70
-          <div class="pl-2">
71
-            猜你喜欢
72
-          </div>
73
-        </div>
74
-      </div>
75
-      <div class="pb-3 px-3" v-if="state.recommendList.length!=0">
76
-        <grid-view type="masonry" cross-axis-count="2" cross-axis-gap="10px" main-axis-gap="10px">
77
-          <div v-for="(item, index) in state.recommendList"
78
-               :key="index"
79
-               @click="handleProductItemClick(item)"
80
-          >
81
-            <MerchantProductCard :item="item"/>
82
-
83
-          </div>
84
-        </grid-view>
85
-      </div>
86
-
87
-    </div>
88
-</template>
89
-
90
-
91
-<style scoped>
92
-.box-out {
93
-  background: #f8f8f8;
94
-  height: 200px;
95
-}
96
-
97
-.flex-box {
98
-  background: #ffffff;
99
-  box-shadow: 3px;
100
-  height: 80%;
101
-  display: flex;
102
-  flex-direction: column;
103
-  justify-content: space-evenly;
104
-}
105
-
106
-.img-div {
107
-  width: 100%;
108
-
109
-}
110
-
111
-.sold-out {
112
-  display: block;
113
-  width: 120px;
114
-  height: 120px;
115
-  margin: 0 auto;
116
-}
117
-
118
-.out-conter {
119
-  text-align: center;
120
-}
121
-</style>

+ 6 - 6
src/pages/store/product/detail.vue

@@ -57,7 +57,7 @@ const state = reactive({
57 57
       '//img14.360buyimg.com/n4/jfs/t1/215845/12/3788/221990/618a5c4dEc71cb4c7/7bd6eb8d17830991.jpg'
58 58
   },
59 59
   //1表示立即购买;2表示加入购物车,3表示立即兑换
60
-  flag: '1',
60
+  flag: 1,
61 61
   isNew: '0',
62 62
   cartNum: 1,
63 63
   cartCount: NaN,
@@ -290,7 +290,7 @@ function handleShowShopCart() {
290 290
   })
291 291
 }
292 292
 
293
-function onSelectedSku(item) {
293
+function onSelectedSku(item :any) {
294 294
   state.currentSku = item
295 295
 }
296 296
 
@@ -303,7 +303,7 @@ function handleAddCart() {
303 303
 
304 304
 function handleCreateShopping() {
305 305
   // console.log(state.flag)
306
-  // console.log(state.currentSku.unique)
306
+  console.log('我是detail数据',detail.value)
307 307
   createShopping({
308 308
     product_id: detail.value.product_id,
309 309
     // product_attr_unique: JSON.stringify(state.currentSku),
@@ -311,7 +311,8 @@ function handleCreateShopping() {
311 311
     cart_num: state.cartNum,
312 312
     is_new: (state.flag === '1' || state.flag === '3') ? '1' : '0'
313 313
   }).then(res => {
314
-    // console.log(res)
314
+    console.log('resres',res)
315
+  
315 316
     if (res.cart_id) {
316 317
       // console.log(state.flag)
317 318
       if (state.flag == '1' || state.flag == '3') {
@@ -320,7 +321,7 @@ function handleCreateShopping() {
320 321
         })
321 322
       } else {
322 323
         uni.$emit('cart-reload')
323
-
324
+        loadProductDetail()
324 325
         uni.showToast({
325 326
           title: '添加购物车成功',
326 327
           icon: 'none'
@@ -702,7 +703,6 @@ onPageScroll((page) => {
702 703
   </div>
703 704
   <!-- 商品下架 -->
704 705
   <div class="relative w-screen " v-if="isShow">
705
-    <CXBBackTop :Scroll_X="Scroll_X" />
706 706
     <div class="box-out">
707 707
       <div class="flex-box pb-3 px-3 ">
708 708
         <div class="img-div">

+ 38 - 0
src/utils/http/index.ts

@@ -1,5 +1,6 @@
1 1
 import { VRequest } from './http'
2 2
 import { vRequest } from './detailhttp'
3
+import { kRequest } from './skuhttp'
3 4
 import { deepMerge } from '~/utils'
4 5
 import { ContentTypeEnum } from '~/enums/httpEnum'
5 6
 
@@ -80,6 +81,43 @@ function onRequest(options?: any) {
80 81
 }
81 82
 
82 83
 export const detailHttp = onRequest()
84
+//sku
85
+function skuRequest(options?: any) {
86
+    return new vRequest(deepMerge(
87
+        {
88
+            url: '',
89
+            timeout: 5 * 1000,
90
+            authenticationScheme: 'Bearer',
91
+            authenticationHeader: 'X-Token',
92
+            // authenticationHeader: 'Authorization',
93
+            // authenticationScheme: '',
94
+
95
+            header: { 'Content-Type': ContentTypeEnum.JSON },
96
+            // 配置项,下面的选项都可以在独立的接口请求中覆盖
97
+            requestOptions: {
98
+                urlPrefix: '',
99
+                joinPrefix: false,
100
+                // 接口地址
101
+                apiUrl,
102
+                // 消息提示类型
103
+                errorMessageMode: 'message',
104
+                // 请求参数拼接到url
105
+                joinParamsToUrl: true,
106
+                //  是否加入时间戳
107
+                joinTime: true,
108
+                // 请求头是否携带token
109
+                withToken: true,
110
+                // 是否返回原生响应头 比如:需要获取响应头时使用该属性
111
+                isReturnNativeResponse: false,
112
+                // 需要对返回数据进行处理
113
+                isTransformResponse: true,
114
+            },
115
+        },
116
+        options || {},
117
+    ))
118
+}
119
+
120
+export const skuhttp = skuRequest()
83 121
 
84 122
 // other api url
85 123
 // export const otherHttp = createRequest({

+ 111 - 0
src/utils/http/skuhttp.ts

@@ -0,0 +1,111 @@
1
+import { cloneDeep } from 'lodash-es'
2
+import { joinTimestamp } from './helper'
3
+import { checkStatus } from './checkStatus'
4
+import type { RequestOptions, Result } from './types'
5
+import { isString } from '~/utils/is'
6
+import { getToken } from '~/utils/auth'
7
+import { RequestEnum, ResultEnum } from '~/enums/httpEnum'
8
+import { setObjToUrlParams } from '~/utils'
9
+
10
+// const { showNotify } = usePageStoreWidthOut()
11
+
12
+type UniRequestOptions = UniApp.RequestOptions & { params?: any }
13
+
14
+export interface CreateRequestOptions extends UniRequestOptions {
15
+    authenticationScheme?: string
16
+    authenticationHeader: string
17
+    urlPrefix?: string
18
+    requestOptions?: RequestOptions
19
+}
20
+
21
+export class vRequest {
22
+    private readonly options: CreateRequestOptions
23
+
24
+    constructor(options: CreateRequestOptions) {
25
+        this.options = options
26
+    }
27
+
28
+    request<T = any>(config: UniRequestOptions, options?: RequestOptions): Promise<T> {
29
+        const configTemp: CreateRequestOptions = cloneDeep(Object.assign({}, this.options, config))
30
+        const optionsTemp: RequestOptions = Object.assign({}, this.options.requestOptions, options)
31
+
32
+        const {
33
+            urlPrefix, apiUrl, joinPrefix, joinTime = true, withToken, joinParamsToUrl,
34
+            isReturnNativeResponse, isTransformResponse,
35
+        } = optionsTemp
36
+
37
+        // token header
38
+        const token = getToken()
39
+        if (token && withToken !== false) {
40
+            // jwt token
41
+            Object.assign(configTemp.header, {
42
+                [configTemp.authenticationHeader]: configTemp.authenticationScheme
43
+                    ? `${configTemp.authenticationScheme} ${token}`
44
+                    : token,
45
+            })
46
+        }
47
+
48
+        // add prefix
49
+        if (joinPrefix)
50
+            configTemp.url = `${urlPrefix}${configTemp.url}`
51
+
52
+        const params = configTemp.params || {}
53
+        if (params) {
54
+            if (configTemp.method?.toUpperCase() === RequestEnum.GET) {
55
+                // add timestamp avoid cache
56
+                if (!isString(params)) {
57
+                    configTemp.params = Object.assign(params || {}, joinTimestamp(joinTime, false))
58
+                    if (joinParamsToUrl && configTemp.params) {
59
+                        configTemp.url = setObjToUrlParams(
60
+                            configTemp.url,
61
+                            Object.assign({}, configTemp.params, configTemp.data))
62
+                        configTemp.params = undefined
63
+                    }
64
+                }
65
+                else {
66
+                    // compatible with restful style
67
+                    configTemp.url = `${config.url + params}${joinTimestamp(joinTime, true)}`
68
+                    configTemp.params = undefined
69
+                }
70
+            }
71
+        }
72
+
73
+        if (apiUrl && isString(apiUrl))
74
+            configTemp.url = `${apiUrl}${configTemp.url}`
75
+
76
+        return new Promise((resolve, reject) => {
77
+            uni.request({
78
+                url: configTemp.url,
79
+                data: configTemp.data || {},
80
+                method: configTemp.method?.toUpperCase() as UniApp.RequestOptions['method'],
81
+                header: configTemp.header || {},
82
+                success: (res) => {
83
+                    // console.log('我是商品res啊', res);
84
+
85
+                    resolve(res as any)
86
+
87
+                },
88
+                fail: (e) => {
89
+                    reject(e.errMsg)
90
+                },
91
+                complete() { },
92
+            })
93
+        })
94
+    }
95
+
96
+    post<T = any>(config: UniRequestOptions, options?: RequestOptions): Promise<T> {
97
+        return this.request({ ...config, method: 'POST' }, options)
98
+    }
99
+
100
+    get<T = any>(config: UniRequestOptions, options?: RequestOptions): Promise<T> {
101
+        return this.request({ ...config, method: 'GET' }, options)
102
+    }
103
+
104
+    put<T = any>(config: UniRequestOptions, options?: RequestOptions): Promise<T> {
105
+        return this.request({ ...config, method: 'PUT' }, options)
106
+    }
107
+
108
+    delete<T = any>(config: UniRequestOptions, options?: RequestOptions): Promise<T> {
109
+        return this.request({ ...config, method: 'DELETE' }, options)
110
+    }
111
+}