【fix】优化代码

This commit is contained in:
黄少君
2024-02-22 18:37:23 +08:00
parent 17c043348a
commit f8fac0a5bc
246 changed files with 973 additions and 406 deletions

View File

@ -31,9 +31,9 @@ const {goBack} = useRouter()
*
*/
const props = defineProps({
scrollTop:{
type:Number,
default:()=>0
scrollTop: {
type: Number,
default: () => 0
},
systemBarAreaBg: {
type: String,
@ -57,7 +57,7 @@ const props = defineProps({
},
returnSize: {
type: Number,
default: () => 22
default: () => 16
},
textShadow: {
type: [Boolean, String],
@ -82,6 +82,10 @@ const props = defineProps({
leftWidth: {
type: Number,
default: () => 0
},
circleBack: {
type: Boolean,
default: false
}
})
@ -98,7 +102,8 @@ const {
propUp,
showRight,
leftWidth,
scrollTop
scrollTop,
circleBack
} = toRefs(props)
const emits = defineEmits(['getSystemInfo', 'animation'])
@ -118,6 +123,7 @@ const heightInfo = ref({
function getSystemInfo() {
const res = uni.getSystemInfoSync();
const heightObj = unref(heightInfo)
console.log(heightObj)
heightObj.safeAreaInsets = res.safeAreaInsets
heightObj.statusBarHeight = res.statusBarHeight
heightObj.screenWidth = res.screenWidth || res.windowWidth
@ -141,6 +147,7 @@ function getMenuInfo() {
const menuButtonBoundingClientRect = uni.getMenuButtonBoundingClientRect();
if (menuButtonBoundingClientRect) {
menuInfo.value = {...menuButtonBoundingClientRect}
console.log(menuInfo.value)
}
}
@ -155,7 +162,7 @@ const scssVarStyle = computed(() => {
const systemBarAreaStyle = computed(() => {
return {
width: '100%',
height: `${ unref(heightInfo).statusBarHeight * 2 }rpx`,
height: `${ unref(heightInfo).statusBarHeight }px`,
background: unref(systemBarAreaBg)
}
})
@ -164,7 +171,12 @@ const systemBarAreaStyle = computed(() => {
const headerAreaStyle = computed(() => {
// 计算margin top
// margin-top (导航条高度 - 胶囊高度) / 2 永远确保胶囊在header中央
const marginTop = unref(menuInfo).height > 0 ? `-${((HEADER_HEIGHT - unref(menuInfo).height))/2}px` : 0
let marginTop = 0
if (unref(menuInfo).height > 0) {
// buttonMarginTopDiff 此处 胶囊和statusBar是由一个距离的
const buttonMarginTopDiff = unref(menuInfo).top - unref(heightInfo).statusBarHeight
marginTop = `${ (-1 * ((HEADER_HEIGHT - unref(menuInfo).height) / 2)) + buttonMarginTopDiff }px`
}
return {
width: '100%',
background: unref(headerAreaBg),
@ -173,6 +185,12 @@ const headerAreaStyle = computed(() => {
}
})
const circleBackStyle = computed(() => {
return {
height: menuInfo.value.height > 0 ? menuInfo.value.height + 'px' : '32px'
}
})
// 文本样式
const textShadowStyle = computed(() => {
return {
@ -193,6 +211,15 @@ const titleStyle = computed(() => {
}
})
const rightStyle = computed(() => {
if (menuInfo.value.left > 0) {
return {
right: `${ (heightInfo.value.screenWidth - menuInfo.value.right) + menuInfo.value.width + 5 }px`
}
}
return {}
})
// 滚动后背景样式
const scrollMaskStyle = computed(() => {
return {
@ -203,7 +230,7 @@ const scrollMaskStyle = computed(() => {
// 总高度
const containerHeight = computed(() => {
const marginTop = unref(menuInfo).height > 0 ? `${((HEADER_HEIGHT - unref(menuInfo).height))/2}` : 0
const marginTop = unref(menuInfo).height > 0 ? `${ ((HEADER_HEIGHT - unref(menuInfo).height)) / 2 }` : 0
return (unref(heightInfo).statusBarHeight + HEADER_HEIGHT - marginTop)
})
@ -222,7 +249,7 @@ watch(scrollTop, () => {
})
defineExpose({containerHeight, heightInfo})
defineExpose({containerHeight, heightInfo, menuInfo})
onLoad(() => {
getSystemInfo()
@ -257,7 +284,19 @@ onLoad(() => {
v-if="showReturn"
>
<slot name="left">
<view
v-if="circleBack"
class="circle-back"
:style="circleBackStyle">
<uv-icon
name="arrow-left"
:color="returnColor"
:size="returnSize"
@click="goBack"
/>
</view>
<uv-icon
v-else
name="arrow-left"
:color="returnColor"
:size="returnSize"
@ -274,6 +313,7 @@ onLoad(() => {
</view>
<view
class="right"
:style="rightStyle"
v-if="showRight"
>
<slot name="right">
@ -367,4 +407,15 @@ onLoad(() => {
}
}
.circle-back {
aspect-ratio: 1/1;
display: flex;
align-items: center;
justify-content: center;
background: rgba(255, 255, 255, 0.7);
border-radius: 50%;
box-shadow: 0 0 10rpx rgba(225, 225, 225, 0.48);
border: 1rpx solid rgba(225, 225, 225, 0.8);
}
</style>

View File

@ -15,7 +15,7 @@ import { doPayment, PayType } from "@/utils/paymentUtils";
import { orderInfo as orderInfoRequest } from "@/api/order";
import { useInterface } from "@/hooks/useInterface";
import { useRouter } from "@/hooks/useRouter";
import {useMainStore} from "@/store/store";
import { useMainStore } from "@/store/modules/useMainStore";
const {toast} = useInterface()
const {push} = useRouter()
@ -54,7 +54,7 @@ const subLoading = ref(false)
async function handleSubmit() {
try {
subLoading.value = true
await doPayment({type: payType.value, payInfo: orderInfo.value,isGroup:orderInfo.value.campaignType===1})
await doPayment({type: payType.value, payInfo: orderInfo.value, isGroup: orderInfo.value.campaignType === 1})
subLoading.value = false
emits('confirm')
close()
@ -97,10 +97,14 @@ async function handleSubmit() {
:src="pay.icon"
/>
<view class="info">
<view class="label flex flex-nowrap flex-ai__end" style="white-space: nowrap">
<view
class="label flex flex-nowrap flex-ai__end"
style="white-space: nowrap">
{{ pay.label }}
<span v-if="pay.type===PayType['1']" style="font-size: 16rpx;white-space: nowrap;">
{{mainStore.user.nowMoney}}
<span
v-if="pay.type===PayType['1']"
style="font-size: 16rpx;white-space: nowrap;">
{{ mainStore.user.nowMoney }}
</span>
</view>
<view>

View File

@ -134,7 +134,7 @@ defineExpose({
<slot name="rightOption">
<view
>
<u-icon
<uv-icon
color="#000"
name="close"
size="16"
@ -157,6 +157,7 @@ defineExpose({
.popup_inner {
padding: 20rpx 20rpx env(safe-area-inset-bottom) 20rpx;
box-sizing: border-box;
.head {
padding: 20rpx 0;
font-weight: bolder;

View File

@ -7,7 +7,7 @@
-->
<script setup>
import { ref } from "vue";
import { useMainStore } from "@/store/store";
import { useMainStore } from "@/store/modules/useMainStore";
import { distributionShareBg } from '@/utils/images'
import { useImage } from "@/hooks/useImage";
import { generateMiniProgramQrCode } from "@/api/global";
@ -69,7 +69,7 @@ async function save() {
</script>
<template>
<u-overlay
<uv-overlay
:show="show"
@click="close">
<view
@ -109,7 +109,7 @@ async function save() {
</view>
</view>
</view>
</u-overlay>
</uv-overlay>
</template>
<style

View File

@ -8,7 +8,7 @@
<script setup>
import { getCurrentInstance, nextTick, ref } from "vue";
import { useImage } from "@/hooks/useImage";
import { useMainStore } from "@/store/store";
import { useMainStore } from "@/store/modules/useMainStore";
import { useShare } from "@/hooks/useShare";
import { generateMiniProgramQrCode } from "@/api/global";
@ -270,7 +270,7 @@ async function generatePoster() {
// #ifdef MP-WEIXIN
wx.canvasToTempFilePath({
canvasId: 'goods-canvas',
canvas:canvasRef.value,//这里是重点,获取实例的时候保存为全局变量就行了
canvas: canvasRef.value,//这里是重点,获取实例的时候保存为全局变量就行了
success: async (res) => {
posterImagePath.value = res.tempFilePath;
uni.hideLoading()
@ -279,7 +279,7 @@ async function generatePoster() {
console.log(err)
uni.hideLoading()
}
},_this)
}, _this)
// #endif
}
@ -299,7 +299,7 @@ async function save() {
</script>
<template>
<u-overlay
<uv-overlay
@touchmove="(e)=>{e.preventDefault();}"
:show="show"
@click="close">
@ -332,7 +332,7 @@ async function save() {
style="width:654rpx;height: 1032rpx;margin: 20rpx auto;position: absolute;z-index:999;top: -999px;"
id="goods-canvas" />
</u-overlay>
</uv-overlay>
</template>
<style

View File

@ -8,7 +8,7 @@
<script setup>
import { getCurrentInstance, nextTick, ref } from "vue";
import { useImage } from "@/hooks/useImage";
import { useMainStore } from "@/store/store";
import { useMainStore } from "@/store/modules/useMainStore";
import { generateMiniProgramQrCode } from "@/api/global";
// =================================== hooks ============================================
@ -268,7 +268,7 @@ async function generatePoster() {
// #ifdef MP-WEIXIN
wx.canvasToTempFilePath({
canvasId: 'goods-canvas',
canvas:canvasRef.value,//这里是重点,获取实例的时候保存为全局变量就行了
canvas: canvasRef.value,//这里是重点,获取实例的时候保存为全局变量就行了
success: async (res) => {
posterImagePath.value = res.tempFilePath;
uni.hideLoading()
@ -277,7 +277,7 @@ async function generatePoster() {
console.log(err)
uni.hideLoading()
}
},_this)
}, _this)
// #endif
}
@ -297,7 +297,7 @@ async function save() {
</script>
<template>
<u-overlay
<uv-overlay
@touchmove="(e)=>{e.preventDefault();}"
:show="show"
@click="close">
@ -330,7 +330,7 @@ async function save() {
style="width:654rpx;height: 1032rpx;margin: 20rpx auto;position: absolute;z-index:999;top: -999px;"
id="goods-canvas" />
</u-overlay>
</uv-overlay>
</template>
<style

View File

@ -7,7 +7,7 @@
-->
<script setup>
import { ref } from "vue";
import { useMainStore } from "@/store/store";
import { useMainStore } from "@/store/modules/useMainStore";
import { distributionShareBg } from '@/utils/images'
import { useImage } from "@/hooks/useImage";
import { generateMiniProgramQrCode } from "@/api/global";
@ -66,7 +66,7 @@ async function save() {
</script>
<template>
<u-overlay
<uv-overlay
:show="show"
@click="close">
<view
@ -105,7 +105,7 @@ async function save() {
</view>
</view>
</view>
</u-overlay>
</uv-overlay>
</template>
<style

View File

@ -50,7 +50,7 @@ defineExpose({ executeRefresh })
<template>
<!--push({ url: '/pages/goodsList/goodsList' }-->
<view class="recommend-container">
<view class="recommend-container" v-if="!listEmpty">
<slot name="head">
<view class="title-row">
商品推荐

View File

@ -1,5 +1,5 @@
<template>
<div class="coupon-box" >
<div class="coupon-box" v-if="couponsData?.length > 0">
<div class="coupon-list coupon-flex coupon-swiper" v-if="componentContent.arrangeType == '横向滑动'">
<swiper class="swiper"
:disable-touch="couponsData.length < 3"

View File

@ -157,12 +157,14 @@ const { activityData, productList, count, jumpProductDetail, jumpDiscount } = co
line-height: 28rpx;
color: #CCCCCC;
display: inline-block;
white-space: nowrap;
}
.stock{
line-height: 1em;
display: inline-block;
font-size: 20rpx;
color: #999999;
white-space: nowrap;
}
}
}

View File

@ -55,7 +55,9 @@ export default function (componentContent, typeId, shopId) {
(res) => {
afterGetData()
activityData.value = res.data
getTime()
if(res.data){
getTime()
}
},
() => {
afterGetData()

View File

@ -1,5 +1,5 @@
<template>
<div class="group-list">
<div class="group-list" v-if="productList.length > 0">
<div class="group-warp">
<div class="header">
<div class="header-warp">
@ -8,15 +8,15 @@
</div>
<a v-show="componentContent.showMore" class="btn-all a-link" @click="jumpGroupWorks(componentContent.id)">查看更多</a>
</div>
<div v-if="productList.length > 0">
<div>
<swiper class="swiper pro-box"
:disable-touch="productList.length < 3"
:circular="false"
:indicator-dots="false"
:autoplay="productList.length > 2"
:display-multiple-items="2"
:previous-margin="swiperCurrent === productList.length - 2?'60rpx':'0rpx'"
:next-margin="swiperCurrent === productList.length - 2?'0rpx':'60rpx'"
:previous-margin="swiperCurrent === productList.length - 2 && productList.length.length > 2?'60rpx':'0rpx'"
:next-margin="swiperCurrent === productList.length - 2 && productList.length.length > 2?'0rpx':'60rpx'"
@change="swiperChange">
<swiper-item class="swiper-slide pro-item-warp" v-for="(item,index) in productList" :key="index" @click="jumpProductDetail(item)">
<div class="pro-item-inner">

View File

@ -22,7 +22,6 @@ export default function (componentContent, typeId, shopId) {
})
function getData () {
if (componentContent.value.id) {
beforeGetData()
const params = {
method: 'POST',
@ -42,9 +41,6 @@ export default function (componentContent, typeId, shopId) {
afterGetData()
}
)
} else {
productList.value = []
}
}
return {

View File

@ -1,6 +1,6 @@
<template>
<global-loading />
<div class="hom-pro-list">
<div class="hom-pro-list" v-if="productData.length > 0">
<div class="header">
<div class="header-warp">
<div class="title">商品推荐</div>
@ -115,7 +115,7 @@
<div
class="product-list-box"
v-if="productData.length>0">
v-if="!loading">
<div
class="product-list-item-warp"
v-for="(col,i) in colList"
@ -216,7 +216,7 @@ const props = defineProps({
},
});
const {typeId, componentContent} = toRefs(props);
const {productData, jumpProductDetail, jumpProList, loadNext, getPercentageNum} = productMixin(componentContent);
const {productData, jumpProductDetail, jumpProList, loadNext, getPercentageNum, loading} = productMixin(componentContent);
const swiperCurrent = ref(0)
const colList = computed(() => [

View File

@ -6,11 +6,13 @@ export default function (componentContent) {
const { sendReq, beforeGetData, afterGetData, jumpProductDetail, jumpProList } = funMixin()
const productData = ref([])
const loading = ref(true)
onMounted(() => {
getData(true)
})
function getData (isFirst) {
loading.value = true
if (componentContent.value.productData.sourceType === '1') {
if (
componentContent.value.productData.productIdList?.length > 0
@ -24,12 +26,14 @@ export default function (componentContent) {
(proRes) => {
afterGetData()
productData.value = proRes.data.list
loading.value = false
if (isFirst) {
componentContent.value.productData.imgTextData = productData.value
}
},
() => {
afterGetData()
loading.value = false
}
)
} else {
@ -45,6 +49,7 @@ export default function (componentContent) {
},
(proRes) => {
afterGetData()
loading.value = false
productData.value = proRes.data.list
if (isFirst) {
componentContent.value.productData.imgTextData = productData.value
@ -53,6 +58,7 @@ export default function (componentContent) {
},
() => {
afterGetData()
loading.value = false
}
)
} else {
@ -73,6 +79,7 @@ export default function (componentContent) {
productData,
jumpProductDetail,
jumpProList,
getPercentageNum
getPercentageNum,
loading
}
}

View File

@ -151,6 +151,7 @@ const { activityData, productList, count, jumpProductDetail, jumpSeckills } = co
color: #EE6D46;
padding-right: 10rpx;
display: inline-block;
white-space: nowrap;
}
.original-price{
font-size: 20rpx;
@ -163,6 +164,7 @@ const { activityData, productList, count, jumpProductDetail, jumpSeckills } = co
display: inline-block;
font-size: 20rpx;
color: #999999;
white-space: nowrap;
}
}
}

View File

@ -55,7 +55,9 @@ export default function (componentContent, typeId, shopId) {
(res) => {
afterGetData()
activityData.value = res.data
getTime()
if(res.data){
getTime()
}
},
() => {
afterGetData()

View File

@ -12,7 +12,7 @@
<CouponItem
@receiveCoupon="handleGetDetail(props.id)"
:coupons="item"
:type="'get'"
type="get"
/>
</view>
</template>

View File

@ -88,7 +88,6 @@
<text v-if="data.stock">仅剩{{ data.stock }}</text>
<text v-else>库存不足</text>
</view>
<view
class="buy-num"
v-if="purchase"
@ -98,6 +97,7 @@
</view>
</view>
<uv-button
class="button"
round
block
type="primary"
@ -317,6 +317,11 @@ const percentage = computed(() => {
align-items: center;
justify-content: center;
.button {
flex-shrink: 0;
white-space: nowrap;
}
&-desc {
line-height: 28rpx;
font-size: 20rpx;

View File

@ -24,16 +24,11 @@
>
<view
v-for="(item, index) in data.cartInfo"
:key="index"
class="order-evaluate"
:class="{evaluateBtn: data._status._type == 3}"
>
<view
v-if="data._status._type == 3 && item.isReply === 0"
class="order-actions-primary order-evaluate-btn"
@tap.stop="toEvaluate(item.unique,data.orderId)"
>
去评价
</view>
<Goods
row
:jump="false"
@ -75,7 +70,14 @@
<span v-if="item.orderDetailState===2"> 售后中 </span>
<span v-if="item.orderDetailState===3"> 售后完成 </span>
</view>
<view class="price-box cart-num flex flex-ai__end">
<view class="price-box cart-num flex flex-ai__center">
<view
v-if="data._status._type == 3 && item.isReply === 0"
class="order-actions-primary order-evaluate-btn"
@tap.stop="toEvaluate(item.unique,data.orderId)"
>
去评价
</view>
x{{ item.cartNum }}
</view>
</view>
@ -254,14 +256,17 @@ async function doTakeGoods() {
let option = {
uni: data.value.orderId,
}
let payInfo = JSON.parse(data.value.payInfo)
showWsReceipt(payInfo.transaction_id).then(async (res) => {
if (res === 'success') {
await orderTake(option)
emit('refresh')
toast({title: '已收货'});
}
})
try {
let payInfo = JSON.parse(data.value.payInfo)
const res = await showWsReceipt(payInfo.transaction_id)
if (res !== 'success') return
await orderTake(option)
emit('refresh')
toast({title: '已收货'});
} catch (e) {
console.error(e)
toast({title: '收货失败', icon: 'error'});
}
}