fix:修复bug

This commit is contained in:
2026-03-17 12:03:54 +08:00
parent 5d7b973ddd
commit 60df817de5
32 changed files with 654 additions and 528 deletions
+1 -1
View File
@@ -5,6 +5,6 @@ VITE_DELETE_CONSOLE=false
#本地环境
VITE_SERVER_BASEURL=https://howhowfresh.com/prod-api
#VITE_SERVER_BASEURL=http://192.168.5.64:8080
#VITE_SERVER_BASEURL=http://192.168.5.36:8080
#VITE_SERVER_BASEURL=http://192.168.0.148:8888
#VITE_SERVER_BASEURL=http://liuyao.nat100.top/meiguowaimai
+6
View File
@@ -10,6 +10,12 @@ const props = withDefaults(defineProps<{
});
function handleClickLeft() {
// 页面栈不足时,navigateBack 会失败;兜底回首页
const pages = getCurrentPages?.() || []
if (pages.length <= 1) {
uni.switchTab({ url: '/pages/home/index' })
return
}
uni.navigateBack()
}
</script>
+2 -2
View File
@@ -4,8 +4,8 @@ const show = ref(false);
const pickerValue = ref(0)
const emits = defineEmits(['confirm'])
function onOpen(value: number) {
if (value) {
function onOpen(value?: number) {
if (value !== undefined && value !== null) {
pickerValue.value = value;
}
show.value = true;
+4
View File
@@ -34,6 +34,8 @@
"loading": "Loading",
"mile": "mile",
"minutes": "minutes",
"day": "day",
"days": "days",
"no": "No",
"obtain": "get",
"operation-success": "Operation successful",
@@ -439,6 +441,7 @@
"claimCoupon": "Claim coupon",
"couponOff": "Off",
"validDays": "Valid Days",
"day": "day",
"days": "days",
"get": "Get",
"congratulations": "Congratulations",
@@ -493,6 +496,7 @@
"tips3": "membership to enjoy a ",
"tips4": "Enjoy delivery service over",
"tips5": "Delivery fee",
"start": " and up",
"title": "The minimum order amount for this store is",
"toast": {
"deliveryService": "This merchant does not provide delivery service",
+4
View File
@@ -34,6 +34,8 @@
"loading": "加载中",
"mile": "英里",
"minutes": "分钟",
"day": "天",
"days": "天",
"no": "否",
"obtain": "获取",
"operation-success": "操作成功",
@@ -439,6 +441,7 @@
"claimCoupon": "领取优惠券",
"couponOff": "优惠",
"validDays": "有效天数",
"day": "天",
"days": "天",
"get": "获取",
"congratulations": "恭喜!",
@@ -493,6 +496,7 @@
"tips3": "会员可享受",
"tips4": "最低起送金额",
"tips5": "配送费",
"start": "起",
"title": "这家店的起送金额是",
"toast": {
"deliveryService": "该商家未开通配送服务",
+2 -2
View File
@@ -2,8 +2,8 @@
"name" : "CHEFLINK delivery",
"appid" : "__UNI__06509BE",
"description" : "",
"versionName" : "1.0.21",
"versionCode" : 121,
"versionName" : "1.0.26",
"versionCode" : 126,
"transformPx" : false,
/* 5+App */
"app-plus" : {
+25 -8
View File
@@ -30,8 +30,9 @@ const userStore = useUserStore();
// 送达偏好
const visitMethodRef = ref();
// value 与 visit-method 组件保持一致:0-亲自送达 1-放门口
const visitMethod = ref({
value: 2,
value: 1,
label: t("components.visit.putItAtTheDoor"),
});
function chooseVisitMethod() {
@@ -633,15 +634,14 @@ function getAddressList() {
let data = addressesList.value[0]
// 回显用户地址中的送达偏好
// 回显送达偏好
if(+data.deliveryRemark === 1) {
// 回显送达偏好deliveryType: 1-亲自送达 2-放门口)
if(+data.deliveryType === 1) {
visitMethod.value.label = t('components.visit.leaveItToMePersonally')
visitMethod.value.value = 1
visitMethod.value.value = 0
}
if(+data.deliveryRemark === 2) {
if(+data.deliveryType === 2) {
visitMethod.value.label = t('components.visit.putItAtTheDoor')
visitMethod.value.value = 2
visitMethod.value.value = 1
}
// 如果是批量模式,地址加载完成后重新计算价格
@@ -664,12 +664,14 @@ function chooseAddress() {
// 将新选择的地址id存储到selectedAddressId中
selectedAddressId.value = data.data
// 回显送达偏好
// 回显送达偏好deliveryType: 1-亲自送达 2-放门口)
if(+data.deliveryType === 1) {
visitMethod.value.label = t('components.visit.leaveItToMePersonally')
visitMethod.value.value = 0
}
if(+data.deliveryType === 2) {
visitMethod.value.label = t('components.visit.putItAtTheDoor')
visitMethod.value.value = 1
}
// 重新计算价格
@@ -895,9 +897,16 @@ function appMerchantOrderPayOrder() {
})
setTimeout(()=> {
// 支付成功后跳转到当前订单详情页
if (resOrderId.value) {
uni.reLaunch({
url: `/pages-store/pages/order/index?id=${resOrderId.value}`
})
} else {
uni.navigateBack({
delta: 2,
})
}
}, 500)
})
}
@@ -920,9 +929,17 @@ function appMerchantOrderPayOrderBatch() {
})
setTimeout(()=> {
// 批量支付后,优先跳转到第一笔订单详情;若无订单ID则返回
const firstOrderId = resOrderIds.value && resOrderIds.value.length > 0 ? resOrderIds.value[0] : ''
if (firstOrderId) {
uni.redirectTo({
url: `/pages-store/pages/order/index?id=${firstOrderId}`
})
} else {
uni.navigateBack({
delta: 2,
})
}
}, 500)
}).catch(err => {
console.error('批量支付失败', err)
+33 -9
View File
@@ -4,8 +4,6 @@ import {
getCurrentInstance
} from 'vue';
import Search from "@/pages/home/components/tabbar-home/components/search.vue";
import useEventEmit from "@/hooks/useEventEmit";
import {EventEnum} from "@/constant/enums";
const { t } = useI18n();
import {useAddressStore} from "@/pages/address/store/address";
import {appUserAddressListPost} from "@/service";
@@ -15,6 +13,8 @@ const addressStore = useAddressStore()
const addressesList = ref([])
const currentAddressId = ref('')
// 从 checkout 等页面通过 URL 传入的地址 id,用于进入页面时保持正确选中项
const initialAddressIdFromQuery = ref('')
function getAddressList() {
appUserAddressListPost({
params: {
@@ -25,37 +25,61 @@ function getAddressList() {
console.log('获取用户地址列表', res)
addressesList.value = res.rows
if(res.rows.length > 0) {
// 若有从上一页传入的 id 且该 id 在列表中,则保持选中该地址;否则选中第一个
const fromQuery = initialAddressIdFromQuery.value
const existsInList = res.rows.some((row: any) => String(row.id) === String(fromQuery))
if (fromQuery && existsInList) {
currentAddressId.value = fromQuery
} else {
currentAddressId.value = res.rows[0].id
}
}
})
}
function handleClickSearch() {
uni.navigateTo({
url: '/pages-user/pages/search-address/index',
});
}
useEventEmit(EventEnum.CHOOSE_ADDRESS, (data) => {
events: {
chooseAddress: (data: any) => {
console.log('搜索的地址信息', data)
if(data) {
if (!data) return
// 先判断是否已有相同地址
const exist = addressesList.value.find((item: any) => {
return (
item.formattedAddress === data.formattedAddress &&
(item.displayName || '') === (data.displayName || '')
)
})
if (exist) {
// 已存在:直接选择这个地址,走原有 chooseAddress 流程
chooseAddress(exist)
} else {
// 不存在:走新增地址流程
addressStore.setAddressLocation({
displayName: data.displayName,
formattedAddress: data.formattedAddress,
longitude: data.location.lng,
latitude: data.location.lat,
})
setTimeout(()=> {
setTimeout(() => {
uni.navigateTo({
url: '/pages/address/choose-type'
})
}, 300)
}
})
}
}
});
}
onShow(()=> {
getAddressList()
})
onLoad((options: any)=> {
if(options.id) {
initialAddressIdFromQuery.value = options.id
currentAddressId.value = options.id
}
})
+2
View File
@@ -163,6 +163,8 @@ const payMethodOptions = ref({
payMethod: 1, // 支付方式 1信用卡 2余额
payPassword: '',
})
// 支付密码输入框 ref
const passwordInputRef = ref()
useEventEmit(EventEnum.CHOOSE_PAYMENT_METHOD, (data) => {
if(data) {
if(data.payMethod === 1) {
@@ -3,12 +3,12 @@ import {useConfigStore} from "@/store";
import {receiveCouponApi} from "@/pages-user/service";
const configStore = useConfigStore()
const {t} = useI18n()
const { t, locale } = useI18n()
const emit = defineEmits(['confirm'])
const props = defineProps({
couponList: {
type: Array,
type: Array as unknown as PropType<any[]>,
default: () => []
}
})
@@ -37,6 +37,57 @@ function confirmCoupon(item: any) {
defineExpose({
init
});
function daySuffix(value: unknown) {
const n = Number(value)
const isEn = String(locale.value || '').toLowerCase().startsWith('en')
if (isEn) {
return n === 1 ? ` ${t('pages-store.store.day')}` : ` ${t('pages-store.store.days')}`
}
return t('pages-store.store.days')
}
function isEnLocale() {
return String(locale.value || '').toLowerCase().startsWith('en')
}
function formatMoney(value: unknown) {
const n = Number(value)
if (!Number.isFinite(n)) return '0.00'
return n.toFixed(2)
}
function couponTitleText(item: any) {
const type = Number(item?.couponType)
const discountValue = Number(item?.discountValue)
// 标题保持原样:折扣券显示百分比,满减券只显示减免金额(不展示门槛)
if (type === 1) {
const pct = Number.isFinite(discountValue) ? Number(discountValue * 100).toFixed(0) : '0'
return `${pct}% ${t('pages-store.store.couponOff')}`
}
return `$${formatMoney(discountValue)} ${t('pages-store.store.couponOff')}`
}
function couponBenefitText(item: any) {
const type = Number(item?.couponType)
const discountValue = Number(item?.discountValue)
const minAmount = Number(item?.minAmount)
if (type === 2) {
const discountText = `$${formatMoney(discountValue)}`
const hasMin = Number.isFinite(minAmount) && minAmount > 0
if (hasMin) {
const minText = `$${formatMoney(minAmount)}`
return isEnLocale() ? `Min ${minText} · Off ${discountText}` : `${minText}${discountText} 优惠`
}
return isEnLocale() ? `Off ${discountText}` : `立减${discountText}`
}
const pct = Number.isFinite(discountValue) ? Number(discountValue * 100).toFixed(0) : '0'
return `${pct}%`
}
</script>
<template>
@@ -44,20 +95,15 @@ defineExpose({
<view class="bg-#F5F5F5 px-32rpx pt-30rpx">
<view class="text-40rpx lh-40rpx text-#333 font-bold text-center mb-60rpx">{{ t('pages-store.store.claimCoupon') }}</view>
<scroll-view scroll-y class="h-1000rpx">
<template v-for="item in couponList">
<template v-for="item in couponList" :key="item.id">
<view class="coupon-item h-328rpx flex flex-col mb-30rpx last:mb-0">
<view class="flex-1 pt-40rpx px-58rpx">
<view class="line-clamp-1 text-34rpx lh-34rpx text-#333 font-bold">
<!-- couponType 1-折扣券, 2-满减券-->
<template v-if="item.couponType === 1">
{{ Number(item.discountValue * 100).toFixed(0) }}% {{ t('pages-store.store.couponOff') }}
</template>
<template v-else>
${{ item.discountValue }} {{ t('pages-store.store.couponOff') }}
</template>
{{ couponTitleText(item) }}
</view>
<view class="text-24rpx lh-32rpx text-#999 my-18rpx">
{{ t('pages-store.store.validDays') }}: {{ item.validDays }} {{ t('pages-store.store.days') }}
{{ t('pages-store.store.validDays') }}: {{ item.validDays }}{{ daySuffix(item.validDays) }}
</view>
<view class="text-24rpx lh-32rpx text-#999 my-18rpx">
{{ item.nameZh }}
@@ -67,12 +113,8 @@ defineExpose({
class="w-36rpx h-36rpx shrink-0 mr-10rpx"
src="@img/chef/106.png"
></image>
{{ t('pages-store.store.get') }} <template v-if="item.couponType === 1">
{{ Number(item.discountValue * 100).toFixed(0) }}%
</template>
<template v-else>
${{ item.discountValue }}
</template> {{ t('pages-store.store.couponOff') }}
{{ t('pages-store.store.get') }} {{ couponBenefitText(item) }}
<template v-if="Number(item?.couponType) === 1"> {{ t('pages-store.store.couponOff') }}</template>
</view>
</view>
<template v-if="item.userCouponVo">
+19 -20
View File
@@ -2,7 +2,7 @@
import { debounce } from 'throttle-debounce'
import dayjs from 'dayjs'
import Config from '@/config/index'
const { t } = useI18n();
const { t, locale } = useI18n();
import StoreSkeleton from './components/store-skeleton.vue';
import { useScrollThreshold } from '@/hooks/useScrollThreshold'
import {
@@ -271,20 +271,6 @@ const deliveryMethod = ref(0);
const deliveryMethodOptions = [t('pages-store.store.delivery'), t('pages-store.store.pickup')];
const showDeliverySwitch = ref(true); // 是否显示配送方式切换组件
// 配送时间显示:后端返回分钟;>= 1 天时换算成“天”,否则保持“分钟”
function formatMinutesToDaysText(minutes?: number | string) {
const m = Number(minutes)
if (!Number.isFinite(m) || m <= 0) return '--'
const MINUTES_PER_DAY = 60 * 24
if (m < MINUTES_PER_DAY) return `${m} ${t('common.minutes')}`
const days = m / MINUTES_PER_DAY
// 保留 1 位小数并去掉末尾 0(例如 2.0 -> 2
let daysText = days.toFixed(1).replace(/\.0$/, '')
daysText = '3';
return `${daysText}${t('pages-store.store.days')}`
}
const deliveryTimeText = computed(() => formatMinutesToDaysText(storeDetail.value?.deliveryTime as any))
function handleClickSegmented(index: number) {
console.log("切换配送方式:", index);
if(+storeDetail.value.deliveryService !== 1 && index === 0) {
@@ -307,6 +293,15 @@ function handleClickSegmented(index: number) {
const activeTab = ref(0);
const tabs = ref<any[]>([]);
function daySuffix(value: unknown) {
const n = Number(value)
const isEn = String(locale.value || '').toLowerCase().startsWith('en')
if (isEn) {
return n === 1 ? ` ${t('pages-store.store.day')}` : ` ${t('pages-store.store.days')}`
}
return t('pages-store.store.days')
}
// 分页相关状态
const pageNum = ref(1);
const pageSize = ref(10);
@@ -563,7 +558,9 @@ function handleShare() {
></image>
CHEFLINK
</view>
<text v-if="+storeDetail?.deliveryService === 1" class="text-#7D7D7D"> {{ deliveryTimeText }}</text>
<text v-if="+storeDetail?.deliveryService === 1" class="text-#7D7D7D">
{{ storeDetail?.deliveryTime }}{{ daySuffix(storeDetail?.deliveryTime) }}
</text>
</view>
<view class="text-24rpx lh-24rpx text-#7D7D7D text-center mt-16rpx">
{{ t('pages-store.store.title') }} US${{ storeDetail?.minOrderPrice }}
@@ -627,11 +624,13 @@ function handleShare() {
<template v-if="+storeDetail?.deliveryService === 1 && deliveryMethod === 0">
<view class="w-full h-full flex-1 text-center text-#CE7138 pr-44rpx">
<view>{{ t('pages-store.store.tips4') }} ${{ storeDetail?.minOrderPrice }}</view>
<view>{{ t('pages-store.store.tips5') }} ${{ storeDetail?.deliveryFee }}</view>
<view>{{ t('pages-store.store.tips5') }} ${{ storeDetail?.deliveryFee }}{{ t('pages-store.store.start') }}</view>
</view>
<view class="h-128rpx w-1rpx rotate-0 bg-#D8D8D8"></view>
<view class="w-full flex-1 center flex-col pl-44rpx">
<view class="text-#333 mb-8rpx">{{ deliveryTimeText }}</view>
<view class="text-#333 mb-8rpx">
{{ storeDetail?.deliveryTime }}{{ daySuffix(storeDetail?.deliveryTime) }}
</view>
<view class="text-#7D7D7D">{{ t('pages-store.store.earTime') }}</view>
</view>
</template>
@@ -661,7 +660,7 @@ function handleShare() {
<view v-if="tabs.length > 0" class="px-30rpx pb-120rpx">
<view v-if="currentDishList.length > 0" class="text-40rpx lh-40rpx font-500 my-36rpx">{{ t('pages-store.store.recommend') }}</view>
<view v-if="currentDishList.length > 0" class="grid grid-cols-2 gap-30rpx">
<template v-for="item in currentDishList">
<template v-for="item in currentDishList" :key="item.id">
<view @click="navigateToDishes(item)" class="w-100% mb-10rpx">
<view class="relative h-248rpx rounded-24rpx mb-28rpx">
<view @click.stop="handleDishCollectionClick(item)" class="w-68rpx h-68rpx absolute z-2 top-0 right-0">
@@ -704,7 +703,7 @@ function handleShare() {
<view class="flex-center-sb mt-12rpx">
<view class="text-28rpx text-#999">
<view class="line-through">US${{ item.originalPrice }}</view>
<!-- <view>{{ t('pages-store.store.sales') }}:{{ item.salesCount }}</view> -->
<view>{{ t('pages-store.store.sales') }}:{{ item.salesCount }}</view>
</view>
<view class="center w-64rpx h-64rpx rounded-50% bg-white shadow-lg">
+46 -67
View File
@@ -1,35 +1,35 @@
<script setup>
import * as R from "ramda";
const { t } = useI18n();
// @ts-ignore
import { debounce } from "throttle-debounce";
// @ts-ignore
import Config from "@/config";
import * as R from "ramda";
const { t } = useI18n();
// @ts-ignore
import {debounce} from "throttle-debounce";
// @ts-ignore
import Config from "@/config";
const isSubmit = ref(false)
const isSubmit = ref(false)
function submit() {
function submit() {
isSubmit.value = true
setTimeout(() => {
isSubmit.value = false
}, 3000)
}
}
// 提交
const handleSubmit = debounce(Config.debounceLongTime, submit, {
// 提交
const handleSubmit = debounce(Config.debounceLongTime, submit, {
atBegin: true
})
})
</script>
<script>
// @ts-ignore
import { debounce } from "throttle-debounce";
// @ts-ignore
import Config from "@/config";
import { appUserCardSavePost } from "@/service";
</script>
<script>
// @ts-ignore
import {debounce} from "throttle-debounce";
// @ts-ignore
import Config from "@/config";
import {appUserCardSavePost} from "@/service";
export default {
export default {
data() {
return {
isSubmit: false
@@ -59,38 +59,28 @@ export default {
body: params
})
console.log('handleSuccess', res)
if (uni.getStorageSync('UNI_LOCALE') == 'zh-Hans') {
await uni.showToast({
icon: 'none',
title: '信用卡添加成功'
})
} else {
await uni.showToast({
icon: 'none',
title: 'The credit card was added successfully.'
})
}
// const eventChannel = this.getOpenerEventChannel();
// const id = res.data
// eventChannel.emit('acceptDataFromOpenedPage', {...params, id});
setTimeout(uni.navigateBack, 1000)
} catch (e) {
uni.showToast({
icon: 'none',
title: e?.message || e?.data?.msg || 'Add credit card failed'
})
}
},
}
}
</script>
<script module="addRenderjs" lang="renderjs">
import {loadStripe} from '@stripe/stripe-js/pure';
import Config from '@/config/index'
}
</script>
<script module="addRenderjs" lang="renderjs">
import {loadStripe} from '@stripe/stripe-js/pure';
import Config from '@/config/index'
// @ts-ignore
export default {
// @ts-ignore
export default {
data(){
return {
isCompleted: false,
@@ -101,17 +91,10 @@ export default {
mounted() {
console.log('mounted')
const locale = uni.getStorageSync('UNI_LOCALE') || 'en'
const loadingText = locale === 'zh-Hans' ? '加载中...' : 'Loading...'
uni.showLoading({
title: loadingText,
mask: true
})
this.init()
},
methods: {
async init(){
try {
console.log('本次初始化使用的key', Config.stripeKey)
loadStripe.setLoadParameters({advancedFraudSignals: false});
const stripe = await loadStripe(Config.stripeKey);
@@ -131,17 +114,6 @@ export default {
// enable payment button
}
});
uni.hideLoading()
} catch (error) {
console.error('初始化失败', error)
uni.hideLoading()
const locale = uni.getStorageSync('UNI_LOCALE') || 'en'
const errorText = locale === 'zh-Hans' ? '加载失败,请重试' : 'Loading failed, please try again'
uni.showToast({
icon: 'none',
title: errorText
})
}
},
async handleSubmit(isSubmit){
console.log('handleSubmit',isSubmit,this.isCompleted)
@@ -164,9 +136,9 @@ export default {
}
}
}
}
</script>
<template>
}
</script>
<template>
<view class="">
<navbar customClass="!bg-transparent" />
<view class="text-center px-30rpx mt-98rpx">
@@ -174,16 +146,23 @@ export default {
<view class="text-32rpx text-#333 font-500 mt-70rpx mb-12rpx">{{ t('pages-user.card.title') }}</view>
<view class="text-28rpx lh-28rpx text-#999">{{ t('pages-user.card.desc') }}</view>
</view>
<view class="mt-188rpx px-30rpx py-40rpx bg-#fff" id="payment-form" :prop="isSubmit"
:change:prop="addRenderjs.handleSubmit"></view>
<view class="mt-188rpx px-30rpx py-40rpx bg-#fff" id="payment-form"
:prop="isSubmit"
:change:prop="addRenderjs.handleSubmit"
></view>
<!-- 底部确认按钮 -->
<fixed-bottom-large-btn class="z-100" fixed :text="t('common.save')" @click="handleSubmit" />
<fixed-bottom-large-btn
class="z-100"
fixed
:text="t('common.save')"
@click="handleSubmit"
/>
</view>
</template>
</template>
<style scoped lang="scss">
page {
<style scoped lang="scss">
page {
background-color: #F5F5F5;
}
</style>
}
</style>
+42 -19
View File
@@ -1,25 +1,57 @@
<script setup lang="ts">
import {appCouponExchangeCouponPost, appCouponUserCouponListPost} from "@/service";
const { t } = useI18n();
const { t, locale } = useI18n();
import { throttle } from "throttle-debounce";
import Config from "@/config";
import {dayjs} from "@/plugin";
function isEnLocale() {
return String(locale.value || '').toLowerCase().startsWith('en')
}
function formatMoney(value: unknown) {
const n = Number(value)
if (!Number.isFinite(n)) return '0.00'
return n.toFixed(2)
}
function formatCouponDetail(item: any) {
const type = Number(item?.snapshotType)
const discount = Number(item?.snapshotDiscount)
const minAmount = Number(item?.snapshotMinAmount)
// 1-折扣券(percentage), 2-满减券(amount off with minimum spend)
if (type === 2) {
const hasMin = Number.isFinite(minAmount) && minAmount > 0
const discountText = `$${formatMoney(discount)}`
if (hasMin) {
const minText = `$${formatMoney(minAmount)}`
return isEnLocale()
? `Min ${minText} · Off ${discountText}`
: `${minText}${discountText}`
}
return isEnLocale() ? `Off ${discountText}` : `立减${discountText}`
}
if (type === 1) {
const pct = Number.isFinite(discount) ? Number(discount * 100).toFixed(0) : '0'
return `${pct}% ${t('pages-store.store.discount')}`
}
return t('pages-store.store.discount')
}
function getList(pageNum: number, pageSize: number) {
return new Promise(resolve => {
appCouponUserCouponListPost({
return appCouponUserCouponListPost({
params: {
pageNum,
pageSize,
}
}).then(res => {
resolve(res)
})
})
}) as any
}
const {paging, loading, firstLoaded, dataList, queryList} = usePage(getList)
const {paging, loading, firstLoaded, dataList, queryList} = usePage<any>(getList)
const keyword = ref<string>("");
@@ -120,23 +152,14 @@ function handleSubmit() {
{{ item.snapshotMerchantId ? t('pages-user.coupon.merchant-specific') : t('pages-user.coupon.all-merchants') }}
</view>
<view class="text-24rpx lh-32rpx text-#999 my-18rpx">
{{ t('pages-user.coupon.expiry-date') }}{{ dayjs(Number(item.snapshotValidEnd))
.format('MM:DD HH:mm:ss') }}
{{ dayjs(Number(item.snapshotValidEnd)).format('YYYY-MM-DD HH:mm') }}{{ isEnLocale() ? ' expires' : '到期' }}
</view>
<view class="text-28rpx lh-28rpx text-#333 flex items-center">
<image
class="w-36rpx h-36rpx shrink-0 mr-10rpx"
src="@img/chef/106.png"
></image>
<template v-if="item.snapshotType === 2">
<!-- 满减-->
{{ item.snapshotDiscount }}
</template>
<template v-else>
{{ Number(item.snapshotDiscount * 100).toFixed(0) }}%
</template>
{{ t('pages-store.store.discount') }}
{{ formatCouponDetail(item) }}
</view>
</view>
<view class="h-84rpx lh-84rpx text-center text-28rpx text-#fff">
+42 -12
View File
@@ -5,7 +5,7 @@ import {
appMerchantOrderCanUseCouponListMerchantIdGet
} from "@/service";
const { t } = useI18n();
const { t, locale } = useI18n();
import { throttle } from "throttle-debounce";
import Config from "@/config";
import {dayjs} from "@/plugin";
@@ -23,15 +23,51 @@ function getList(pageNum: number, pageSize: number) {
return new Promise(resolve => {
appMerchantOrderCanUseCouponListMerchantIdGet({
params: {
merchantId: props.id || ''
merchantId: props.id || '',
}
}).then(res => {
resolve({ rows: res.data })
})
resolve({ rows: res.data } as any)
})
}) as any
}
const {paging, loading, firstLoaded, dataList, queryList} = usePage(getList)
const {paging, loading, firstLoaded, dataList, queryList} = usePage<any>(getList)
function isEnLocale() {
return String(locale.value || '').toLowerCase().startsWith('en')
}
function formatMoney(value: unknown) {
const n = Number(value)
if (!Number.isFinite(n)) return '0.00'
return n.toFixed(2)
}
function formatCouponDetail(item: any) {
const type = Number(item?.snapshotType)
const discount = Number(item?.snapshotDiscount)
const minAmount = Number(item?.snapshotMinAmount)
// 1-折扣券(percentage), 2-满减券(amount off with minimum spend)
if (type === 2) {
const hasMin = Number.isFinite(minAmount) && minAmount > 0
const discountText = `$${formatMoney(discount)}`
if (hasMin) {
const minText = `$${formatMoney(minAmount)}`
return isEnLocale()
? `Min ${minText} · Off ${discountText}`
: `${minText}${discountText}`
}
return isEnLocale() ? `Off ${discountText}` : `立减${discountText}`
}
if (type === 1) {
const pct = Number.isFinite(discount) ? Number(discount * 100).toFixed(0) : '0'
return `${pct}% ${t('pages-store.store.discount')}`
}
return t('pages-store.store.discount')
}
function confirmCoupon(item: any) {
eventChannel.emit('selectedCoupon', item);
@@ -72,13 +108,7 @@ function confirmCoupon(item: any) {
class="w-36rpx h-36rpx shrink-0 mr-10rpx"
src="@img/chef/106.png"
></image>
<template v-if="item.snapshotType === 2">
<!-- 满减-->
{{ item.snapshotDiscount }}
</template>
<template v-else>
{{ Number(item.snapshotDiscount * 100).toFixed(0) }}%
</template>{{ t('pages-store.store.discount') }}
{{ formatCouponDetail(item) }}
</view>
</view>
<view @click="confirmCoupon(item)" class="h-84rpx lh-84rpx text-center text-28rpx text-#fff">
+1 -1
View File
@@ -69,7 +69,7 @@ function appMembershipRechargeItem() {
<template v-if="!userStore.userInfo.userMembershipVo">
<!-- <text class="ml-20rpx text-#CE7138">{{ membershipRechargeItem.trialWeeksDisplay || 0 }} {{ t('pages-user.member.weeks') }}</text>
<text class="ml-20rpx text-#CE7138">{{ t('pages-user.member.free') }}</text> -->
<text class="ml-20rpx text-#CE7138">Free for 7 days</text>
<!-- <text class="ml-20rpx text-#CE7138">Free for 7 days</text> -->
<!-- <image :src="membershipRechargeItem.image"></image> -->
</template>
</view>
+62 -58
View File
@@ -52,14 +52,22 @@
</template>
<script lang="ts" setup>
import Config from "@/config";
import {EventEnum} from "@/constant/enums";
import {useLogicStore} from "@/pages-user/store/logic";
import {useUserStore} from "@/store";
import { getCurrentInstance } from "vue";
const {t, locale} = useI18n();
const userStore = useUserStore()
const logicStore = useLogicStore()
let openerEventChannel: any = null
onLoad(() => {
// 统一通过 getOpenerEventChannel 获取导航传入的 eventChannel
const pages = getCurrentPages() as any[]
const page = pages[pages.length - 1]
openerEventChannel = page?.getOpenerEventChannel?.() || null
})
// 生命周期:清空地址列表
onMounted(() => {
logicStore.clearPlacesList()
@@ -99,7 +107,7 @@ const querySearch = computed(() => {
function handleClickLocation(item: any) {
console.log('item', item)
uni.$emit(EventEnum.CHOOSE_ADDRESS, item)
openerEventChannel?.emit?.('chooseAddress', item)
uni.navigateBack()
}
@@ -130,7 +138,7 @@ function handleUseLocation() {
},
})
} else {
uni.$emit(EventEnum.CHOOSE_ADDRESS, {
openerEventChannel?.emit?.('chooseAddress', {
displayName: userStore.location.location,
formattedAddress: userStore.location.formattedAddress || '',
location: {
@@ -192,8 +200,8 @@ function getCityName(latitude: number, longitude: number) {
latitude
};
// 发事件
uni.$emit(EventEnum.CHOOSE_ADDRESS, {
// 回传上一页(eventChannel
openerEventChannel?.emit?.('chooseAddress', {
displayName: cityName,
formattedAddress,
location: { lng: longitude, lat: latitude }
@@ -220,69 +228,65 @@ const mapDataComputed = computed(() => {
lat: userStore.location.latitude || -36.8485,
}
})
</script>
<script lang="ts">
import { defineComponent } from "vue";
import { useLogicStore } from "@/pages-user/store/logic";
// 监听来自 renderjs 的事件
onMounted(() => {
// 监听搜索结果
uni.$on('MAP_SEARCH_RESULT', (places: any) => {
export default defineComponent({
methods: {
onMapSearchResult(places: any) {
const logicStore = useLogicStore()
console.log(places, '接收到的搜索结果')
if (places && places.length > 0) {
// 解析实际返回的数据结构
const parsedPlaces = places.map((placeArray: any) => {
const placeData = placeArray[0]?.[0];
if (!placeData) return null;
const placeId = placeData[1];
const formattedAddress = placeData[8] || '';
const locationArray = placeData[11];
const displayNameArray = placeData[27];
if (places && places.length > 0) {
// 保持与原先一致的解析逻辑
const parsedPlaces = places
.map((placeArray: any) => {
const placeData = placeArray[0]?.[0]
if (!placeData) return null
const placeId = placeData[1]
const formattedAddress = placeData[8] || ''
const locationArray = placeData[11]
const displayNameArray = placeData[27]
return {
id: placeId,
displayName: displayNameArray?.[0] || formattedAddress,
formattedAddress: formattedAddress,
location: locationArray ? {
location: locationArray
? {
lat: locationArray[0],
lng: locationArray[1]
} : null
};
}).filter(Boolean);
console.log('解析后的地址列表', parsedPlaces);
logicStore.setPlacesList(parsedPlaces);
} else {
logicStore.setPlacesList([]);
lng: locationArray[1],
}
: null,
}
})
.filter(Boolean)
// 监听地图未加载提示
uni.$on('MAP_NOT_LOADED', () => {
console.log('解析后的地址列表', parsedPlaces)
logicStore.setPlacesList(parsedPlaces)
} else {
logicStore.setPlacesList([])
}
},
onMapNotLoaded() {
uni.showToast({
title: 'Map is not loaded yet, please wait',
icon: 'none'
});
icon: 'none',
})
// 监听搜索超时提示
uni.$on('MAP_SEARCH_TIMEOUT', () => {
},
onMapSearchTimeout() {
uni.showToast({
title: 'Search timeout, please try again',
icon: 'none'
});
icon: 'none',
})
// 监听搜索加载状态
uni.$on('MAP_SEARCH_LOADING', (isLoading: boolean) => {
// logicStore.searchLoading = isLoading;
})
})
onUnmounted(() => {
// 清理事件监听
uni.$off('MAP_SEARCH_RESULT')
uni.$off('MAP_NOT_LOADED')
uni.$off('MAP_SEARCH_TIMEOUT')
uni.$off('MAP_SEARCH_LOADING')
},
onMapSearchLoading(_isLoading: boolean) {
// 如需联动 loading,可在此处驱动 store
},
},
})
</script>
<script lang="renderjs" module="mapRenderjs">
@@ -377,24 +381,24 @@ export default {
async searchPlace({keyword}) {
console.log('搜索关键词', keyword);
if (!keyword) {
uni.$emit('MAP_SEARCH_RESULT', [])
this.$ownerInstance.callMethod('onMapSearchResult', [])
return;
}
if (!mapLoaded) {
console.log('地图未加载完成,无法搜索');
uni.$emit('MAP_NOT_LOADED');
this.$ownerInstance.callMethod('onMapNotLoaded');
return;
}
if (!map || !this.google) {
return
}
uni.$emit('MAP_SEARCH_LOADING', true);
this.$ownerInstance.callMethod('onMapSearchLoading', true);
let timeoutId;
try {
// 设置搜索超时
const timeoutPromise = new Promise((_, reject) => {
timeoutId = setTimeout(() => {
uni.$emit('MAP_SEARCH_LOADING', false);
this.$ownerInstance.callMethod('onMapSearchLoading', false);
reject(new Error('Search timeout'));
}, 10000); // 10 秒超时
});
@@ -430,16 +434,16 @@ export default {
});
console.log('序列化后的搜索结果', serializedPlaces);
uni.$emit('MAP_SEARCH_RESULT', serializedPlaces);
this.$ownerInstance.callMethod('onMapSearchResult', serializedPlaces);
} catch (e) {
console.log('搜索错误原因', e);
if (e.message === 'Search timeout') {
uni.$emit('MAP_SEARCH_TIMEOUT');
this.$ownerInstance.callMethod('onMapSearchTimeout');
}
uni.$emit('MAP_SEARCH_RESULT', []);
this.$ownerInstance.callMethod('onMapSearchResult', []);
} finally {
clearTimeout(timeoutId);
uni.$emit('MAP_SEARCH_LOADING', false);
this.$ownerInstance.callMethod('onMapSearchLoading', false);
}
}
},
+7 -40
View File
@@ -14,46 +14,10 @@ const message = useMessage();
function handleClickSearch() {
uni.navigateTo({
url: '/pages-user/pages/search-address/index',
});
}
useEventEmit(EventEnum.CHOOSE_ADDRESS, (data) => {
events: {
chooseAddress: (data: any) => {
console.log('搜索的地址信息', data)
if(data) {
// 从addressComponents中提取州名/省名
// let stateName = '';
// if (data.addressComponents && Array.isArray(data.addressComponents)) {
// // 先判断是否为中国地址
// const countryComponent = data.addressComponents.find(component =>
// component.types && component.types.includes('country')
// );
// const isChina = countryComponent && (countryComponent.shortText === 'CN' || countryComponent.longText === '中国');
//
// if (isChina) {
// // 中国地址:优先取市级(locality),如果没有则取省级(administrative_area_level_1
// const cityComponent = data.addressComponents.find(component =>
// component.types && component.types.includes('locality')
// );
// const provinceComponent = data.addressComponents.find(component =>
// component.types && component.types.includes('administrative_area_level_1')
// );
//
// if (cityComponent) {
// stateName = cityComponent.longText || cityComponent.shortText || '';
// } else if (provinceComponent) {
// stateName = provinceComponent.longText || provinceComponent.shortText || '';
// }
// } else {
// // 美国等其他国家:取州级(administrative_area_level_1
// const stateComponent = data.addressComponents.find(component =>
// component.types && component.types.includes('administrative_area_level_1')
// );
// if (stateComponent) {
// stateName = stateComponent.longText || stateComponent.shortText || '';
// }
// }
// }
if (data) {
addressStore.setAddressLocation({
displayName: data.displayName,
formattedAddress: data.formattedAddress,
@@ -66,7 +30,10 @@ useEventEmit(EventEnum.CHOOSE_ADDRESS, (data) => {
})
}, 300)
}
})
}
}
});
}
function reservationTime() {
uni.navigateTo({ url: '/pages/address/reservation-time' })
+2 -2
View File
@@ -11,8 +11,8 @@ import dayjs from "dayjs";
// MONDAY/TUESDAY/WEDNESDAY 09:00-16:00
// MONDAY 09:00-18:00;TUESDAY 09:00-10:00;WEDNESDAY 09:00-18:00;THURSDAY 09:00-18:00;FRIDAY 08:00-09:00
const storeBusinessHours = ref('');
// 是否仅选择日期(当进入页面传递了 storeBusinessHours 时开启
const onlySelectDay = ref(false);
// 是否仅选择日期(当前需求:只选哪一天配送,不选具体时间段
const onlySelectDay = ref(true);
// 业务规则:只能预约周一 / 周四 / 周五
// JS 中:0-周日 1-周一 ... 4-周四 5-周五
+3 -2
View File
@@ -15,10 +15,11 @@ const addressStore = useAddressStore()
const visitMethodRef = ref<InstanceType<typeof VisitMethod>>()
const buildingTypeRef = ref<InstanceType<typeof BuildingType>>()
function openVisitMethod() {
visitMethodRef.value?.onOpen()
// deliveryType: 1-亲自送达(0) 2-放门口(1),打开时回显当前选中
visitMethodRef.value?.onOpen(+addressStore.addressInfo.deliveryType === 2 ? 1 : 0)
}
const visitMethod = ref(t('components.visit.leaveItToMePersonally')) // 默认选择亲自送达
const visitMethod = ref(t('components.visit.putItAtTheDoor')) // 默认选择放在门口
function visitMethodConfirm(data: any) {
console.log('visitMethodConfirm', data)
visitMethod.value = data.label;
+3 -2
View File
@@ -14,10 +14,11 @@ const addressStore = useAddressStore()
const visitMethodRef = ref<InstanceType<typeof VisitMethod>>()
const buildingTypeRef = ref<InstanceType<typeof BuildingType>>()
function openVisitMethod() {
visitMethodRef.value?.onOpen()
// deliveryType: 1-亲自送达(0) 2-放门口(1),打开时回显当前选中
visitMethodRef.value?.onOpen(+addressStore.addressInfo.deliveryType === 2 ? 1 : 0)
}
const visitMethod = ref(t('components.visit.leaveItToMePersonally')) // 默认选择亲自送达
const visitMethod = ref(t('components.visit.putItAtTheDoor')) // 默认选择放在门口
function visitMethodConfirm(data: any) {
console.log('visitMethodConfirm', data)
visitMethod.value = data.label;
+3 -2
View File
@@ -14,10 +14,11 @@ const addressStore = useAddressStore()
const visitMethodRef = ref<InstanceType<typeof VisitMethod>>()
const buildingTypeRef = ref<InstanceType<typeof BuildingType>>()
function openVisitMethod() {
visitMethodRef.value?.onOpen()
// deliveryType: 1-亲自送达(0) 2-放门口(1),打开时回显当前选中
visitMethodRef.value?.onOpen(+addressStore.addressInfo.deliveryType === 2 ? 1 : 0)
}
const visitMethod = ref(t('components.visit.leaveItToMePersonally')) // 默认选择亲自送达
const visitMethod = ref(t('components.visit.putItAtTheDoor')) // 默认选择放在门口
function visitMethodConfirm(data: any) {
console.log('visitMethodConfirm', data)
visitMethod.value = data.label;
+3 -2
View File
@@ -14,10 +14,11 @@ const addressStore = useAddressStore()
const visitMethodRef = ref<InstanceType<typeof VisitMethod>>()
const buildingTypeRef = ref<InstanceType<typeof BuildingType>>()
function openVisitMethod() {
visitMethodRef.value?.onOpen()
// deliveryType: 1-亲自送达(0) 2-放门口(1),打开时回显当前选中
visitMethodRef.value?.onOpen(+addressStore.addressInfo.deliveryType === 2 ? 1 : 0)
}
const visitMethod = ref(t('components.visit.leaveItToMePersonally')) // 默认选择亲自送达
const visitMethod = ref(t('components.visit.putItAtTheDoor')) // 默认选择放在门口
function visitMethodConfirm(data: any) {
console.log('visitMethodConfirm', data)
visitMethod.value = data.label;
+3 -2
View File
@@ -14,10 +14,11 @@ const addressStore = useAddressStore()
const visitMethodRef = ref<InstanceType<typeof VisitMethod>>()
const buildingTypeRef = ref<InstanceType<typeof BuildingType>>()
function openVisitMethod() {
visitMethodRef.value?.onOpen()
// deliveryType: 1-亲自送达(0) 2-放门口(1),打开时回显当前选中
visitMethodRef.value?.onOpen(+addressStore.addressInfo.deliveryType === 2 ? 1 : 0)
}
const visitMethod = ref(t('components.visit.leaveItToMePersonally')) // 默认选择亲自送达
const visitMethod = ref(t('components.visit.putItAtTheDoor')) // 默认选择放在门口
function visitMethodConfirm(data: any) {
console.log('visitMethodConfirm', data)
visitMethod.value = data.label;
+4 -4
View File
@@ -3,8 +3,8 @@ import type { UserAddressBo } from '@/service/types';
export const useAddressStore = defineStore('store-address', () => {
const addressInfo = ref<UserAddressBo>({
type: '',
/** 配送类型 1 2 */
deliveryType: '1',
/** 配送类型 1-亲自送达 2-放门口,默认放门口 */
deliveryType: '2',
/** 配送说明 */
deliveryRemark: '',
/** 配送图片 */
@@ -60,8 +60,8 @@ export const useAddressStore = defineStore('store-address', () => {
addressInfo.value = {
id: '',
type: '',
/** 配送类型 1 2 */
deliveryType: '1',
/** 配送类型 1-亲自送达 2-放门口,默认放门口 */
deliveryType: '2',
/** 配送说明 */
deliveryRemark: '',
/** 配送图片 */
@@ -1,34 +1,32 @@
<template>
<view class="class-bullet-container">
<!-- 第一行可拖 + 自动滚动 -->
<!-- 第一行自动缓慢滚 + 可手动滑动 -->
<view class="scroll-row first-row">
<scroll-view
class="ab-scroll mb-22rpx"
scroll-x
show-scrollbar="false"
id="sv-1"
style="--ab-scroll-timeout: 50s"
:scroll-left="scrollLeft1"
@touchstart="onTouchStart1"
@touchend="onTouchEnd1"
@touchcancel="onTouchEnd1"
@scroll="onScroll1"
>
<view id="sv-inner-1" :class="['sv-inner', { 'paused': isDragging1 }]">
<view class="sv-inner" id="sv1-inner">
<!-- 一份内容 -->
<view
v-for="(item, idx) in categories"
:key="item.id + '-a-' + idx"
:key="item.id + '-row1-a-' + idx"
class="category-item"
@click="handleItemClick(item)"
>
<image v-if="item.categoryImage || item.logoUrl" :src="item.categoryImage || item.logoUrl" class="category-icon" mode="aspectFit" />
<text class="category-text">{{ item.categoryName || item.name }}</text>
</view>
<!-- 第二份重复内容用于无缝循环 -->
<!-- 第二份重复内容用于无缝滚动 -->
<view
v-for="(item, idx) in categories"
:key="item.id + '-b-' + idx"
:key="item.id + '-row1-b-' + idx"
class="category-item"
@click="handleItemClick(item)"
>
@@ -39,24 +37,22 @@
</scroll-view>
</view>
<!-- 第二行可拖动 + 自动滚动速度不同 -->
<!-- 第二行反向数据自动滚动速度不同 -->
<view class="scroll-row">
<scroll-view
class="ab-scroll"
scroll-x
show-scrollbar="false"
id="sv-2"
style="--ab-scroll-timeout: 70s"
:scroll-left="scrollLeft2"
@touchstart="onTouchStart2"
@touchend="onTouchEnd2"
@touchcancel="onTouchEnd2"
@scroll="onScroll2"
>
<view id="sv-inner-2" :class="['sv-inner', { 'paused': isDragging2 }]">
<view class="sv-inner" id="sv2-inner">
<view
v-for="(item, idx) in categoriesReversed"
:key="item.id + '-c-' + idx"
:key="item.id + '-row2-a-' + idx"
class="category-item"
@click="handleItemClick(item)"
>
@@ -65,7 +61,7 @@
</view>
<view
v-for="(item, idx) in categoriesReversed"
:key="item.id + '-d-' + idx"
:key="item.id + '-row2-b-' + idx"
class="category-item"
@click="handleItemClick(item)"
>
@@ -80,7 +76,7 @@
</template>
<script setup lang="ts">
import { computed, ref, onMounted, nextTick, getCurrentInstance } from 'vue'
import { computed, ref, onMounted, onUnmounted, nextTick } from 'vue'
// 定义分类项接口(与模板字段一致)
interface CategoryItem {
@@ -88,7 +84,7 @@ interface CategoryItem {
categoryImage?: string
logoUrl?: string
name?: string
categoryName: string
categoryName?: string
}
// 定义组件属性
@@ -128,116 +124,121 @@ const categoriesReversed = computed(() => {
return list.slice().reverse()
})
// 自动滚动(CSS 动画)+ 手动拖动时暂停
const isDragging1 = ref(false)
const isDragging2 = ref(false)
const RESUME_DELAY_MS = 1200
let resumeTimer1: any
let resumeTimer2: any
// ===== 自动滚动相关(电商标签推荐风格) =====
// 视口宽度,用于计算最大可滚动距离(scrollWidth - viewportWidth
const systemInfo = uni.getSystemInfoSync()
const viewportWidth = systemInfo.windowWidth || 0
// 中心定位与边界重置,避免滚动到底卡住
const scrollLeft1 = ref(0)
const scrollLeft2 = ref(0)
const copyWidth1Px = ref(0)
const copyWidth2Px = ref(0)
const viewportWidth1Px = ref(0)
const viewportWidth2Px = ref(0)
function measureAndInit() {
const ins = getCurrentInstance()
const q = uni.createSelectorQuery().in(ins?.proxy as any)
q.select('#sv-1').boundingClientRect()
.select('#sv-inner-1').boundingClientRect()
.select('#sv-2').boundingClientRect()
.select('#sv-inner-2').boundingClientRect()
.exec((res) => {
const sv1 = res?.[0]
const inner1 = res?.[1]
const sv2 = res?.[2]
const inner2 = res?.[3]
if (sv1?.width) viewportWidth1Px.value = sv1.width
if (inner1?.width) copyWidth1Px.value = inner1.width / 2
if (sv2?.width) viewportWidth2Px.value = sv2.width
if (inner2?.width) copyWidth2Px.value = inner2.width / 2
// 初始化到中间位置
if (copyWidth1Px.value) scrollLeft1.value = copyWidth1Px.value
if (copyWidth2Px.value) scrollLeft2.value = copyWidth2Px.value
})
// 最大可滚动距离(由 scroll 事件提供,避免自己算)
const maxScroll1 = ref(0)
const maxScroll2 = ref(0)
const isTouching1 = ref(false)
const isTouching2 = ref(false)
let autoTimer1: any = null
let autoTimer2: any = null
let resumeTimer1: any = null
let resumeTimer2: any = null
// 速度和间隔可以根据效果微调
const AUTO_INTERVAL = 30
const AUTO_STEP_1 = 0.6
const AUTO_STEP_2 = 0.4
const RESUME_DELAY = 800
const RESET_THRESHOLD = 2 // 在距离末尾一定范围内就重置
function startAuto1() {
if (autoTimer1) return
autoTimer1 = setInterval(() => {
if (isTouching1.value) return
let next = scrollLeft1.value + AUTO_STEP_1
const max = maxScroll1.value
if (max > 0 && next >= max - RESET_THRESHOLD) {
// 距离最右侧很近时,从头开始,实现循环
next = 0
}
scrollLeft1.value = next
}, AUTO_INTERVAL)
}
function recenter1(currentLeft?: number) {
const cw = copyWidth1Px.value
const vw = viewportWidth1Px.value
if (!cw || !vw) return
const left = currentLeft ?? scrollLeft1.value
const mod = left % cw
scrollLeft1.value = cw + mod
function startAuto2() {
if (autoTimer2) return
autoTimer2 = setInterval(() => {
if (isTouching2.value) return
let next = scrollLeft2.value + AUTO_STEP_2
const max = maxScroll2.value
if (max > 0 && next >= max - RESET_THRESHOLD) {
next = 0
}
scrollLeft2.value = next
}, AUTO_INTERVAL)
}
function recenter2(currentLeft?: number) {
const cw = copyWidth2Px.value
const vw = viewportWidth2Px.value
if (!cw || !vw) return
const left = currentLeft ?? scrollLeft2.value
const mod = left % cw
scrollLeft2.value = cw + mod
function stopAuto1() {
if (autoTimer1) {
clearInterval(autoTimer1)
autoTimer1 = null
}
}
function stopAuto2() {
if (autoTimer2) {
clearInterval(autoTimer2)
autoTimer2 = null
}
}
function onTouchStart1() {
isDragging1.value = true
isTouching1.value = true
if (resumeTimer1) clearTimeout(resumeTimer1)
stopAuto1()
}
function onTouchEnd1() {
// 手指松开后,若在边界附近,立即重置到中间位置,保持无缝
recenter1(scrollLeft1.value)
resumeTimer1 = setTimeout(() => {
isDragging1.value = false
}, RESUME_DELAY_MS)
isTouching1.value = false
startAuto1()
}, RESUME_DELAY)
}
function onScroll1(e: any) {
isDragging1.value = true
if (resumeTimer1) clearTimeout(resumeTimer1)
const left = e?.detail?.scrollLeft ?? 0
const cw = copyWidth1Px.value
const vw = viewportWidth1Px.value
if (cw && vw) {
const total = cw * 2
// 临界阈值,靠近起点或终点时重置
const threshold = 10
if (left <= threshold || left >= total - vw - threshold) {
recenter1(left)
const detail = e?.detail
if (detail && typeof detail.scrollLeft === 'number') {
scrollLeft1.value = detail.scrollLeft
// scrollWidth - viewportWidth 为最大可滚动距离
if (typeof detail.scrollWidth === 'number' && viewportWidth > 0) {
const max = detail.scrollWidth - viewportWidth
maxScroll1.value = max > 0 ? max : 0
}
}
resumeTimer1 = setTimeout(() => {
isDragging1.value = false
}, RESUME_DELAY_MS)
}
function onTouchStart2() {
isDragging2.value = true
isTouching2.value = true
if (resumeTimer2) clearTimeout(resumeTimer2)
stopAuto2()
}
function onTouchEnd2() {
recenter2(scrollLeft2.value)
resumeTimer2 = setTimeout(() => {
isDragging2.value = false
}, RESUME_DELAY_MS)
isTouching2.value = false
startAuto2()
}, RESUME_DELAY)
}
function onScroll2(e: any) {
isDragging2.value = true
if (resumeTimer2) clearTimeout(resumeTimer2)
const left = e?.detail?.scrollLeft ?? 0
const cw = copyWidth2Px.value
const vw = viewportWidth2Px.value
if (cw && vw) {
const total = cw * 2
const threshold = 10
if (left <= threshold || left >= total - vw - threshold) {
recenter2(left)
const detail = e?.detail
if (detail && typeof detail.scrollLeft === 'number') {
scrollLeft2.value = detail.scrollLeft
if (typeof detail.scrollWidth === 'number' && viewportWidth > 0) {
const max = detail.scrollWidth - viewportWidth
maxScroll2.value = max > 0 ? max : 0
}
}
resumeTimer2 = setTimeout(() => {
isDragging2.value = false
}, RESUME_DELAY_MS)
}
// 点击处理
@@ -252,9 +253,20 @@ function navigateTo(url: string) {
onMounted(() => {
nextTick(() => {
measureAndInit()
// 启动自动滚动,maxScroll 值会在第一次 scroll 事件时更新
setTimeout(() => {
startAuto1()
startAuto2()
}, 300)
})
})
onUnmounted(() => {
stopAuto1()
stopAuto2()
if (resumeTimer1) clearTimeout(resumeTimer1)
if (resumeTimer2) clearTimeout(resumeTimer2)
})
</script>
<style lang="scss" scoped>
@@ -280,8 +292,6 @@ onMounted(() => {
display: flex;
flex-direction: row;
gap: 20rpx;
animation: ab-move-marquee var(--ab-scroll-timeout) linear infinite;
will-change: transform;
}
.category-item {
@@ -316,17 +326,5 @@ onMounted(() => {
}
}
// GPU 动画,无缝循环(两份内容)
@keyframes ab-move-marquee {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-50%);
}
}
.paused {
animation-play-state: paused;
}
// 取消 CSS 动画,由 JS 控制的 scroll-left 实现无缝滚动,避免与手势滚动冲突导致的抖动
</style>
@@ -24,7 +24,7 @@ function handleClickFood(item: any) {
<view class="text-24rpx lh-24rpx flex items-center mt-12rpx">
<text class="text-#333 font-500">{{ item.rating }}</text>
<image src="@img/chef/124.png" class="w-24rpx h-24rpx mx-4rpx mt-2rpx"></image>
<text class="text-#7D7D7D">({{ item.commentCount }}) {{ item.deliveryTime }} {{ t('common.minutes') }}</text>
<text class="text-#7D7D7D">({{ item.commentCount }}) {{ item.deliveryTime }} {{ Number(item.deliveryTime) === 1 ? t('common.day') : t('common.days') }}</text>
</view>
</view>
</template>
@@ -7,12 +7,24 @@
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="ts">
// @ts-ignore - Vue SFC default export is provided by tooling
import Collection from "@/components/collection/index.vue";
import {appCollectCollectPost} from "@/service";
import {CollectionType} from "@/constant/enums";
const { t } = useI18n();
type FoodBoxItem = {
id: number | string;
merchantId?: string;
isCollect?: boolean;
dishImage?: string;
logo?: string;
dishName?: string;
merchantName?: string;
originalPrice?: string | number;
[key: string]: any;
};
const props = defineProps<{
item: object;
item: FoodBoxItem;
}>();
function handleClickFood() {
@@ -34,10 +46,11 @@ if(props.item.merchantId){
}
function handleCollectionChange(value: boolean) {
const isDish = !!props.item?.merchantId;
appCollectCollectPost({
body: {
targetId: props.item.id,
targetType: CollectionType.STORE
targetId: String(props.item.id),
targetType: isDish ? CollectionType.DISH : CollectionType.STORE
}
}).then(res=> {
props.item.isCollect = value;
@@ -69,7 +82,7 @@ function handleCollectionChange(value: boolean) {
<!-- <text class="text-#7D7D7D">({{ item.commentCount }}) {{ item.deliveryTime }}{{ t('common.minutes') }}</text> -->
</view>
</view>
<collection :is-collected="item.isCollect" @collectionChange="handleCollectionChange" />
<collection :is-collected="item.isCollect" @collection-change="handleCollectionChange" />
</view>
</view>
</template>
@@ -25,7 +25,7 @@ function handleClickFood(item: any) {
<view class="w-156rpx text-center line-clamp-1 text-#333 text-28rpx lh-28rpx mt-12rpx font-500">
{{ item.merchantName }}
</view>
<view v-if="+item.deliveryService === 1" class="mt-12rpx text-center text-24rpx lh-24rpx text-#7D7D7D">{{ item.deliveryTime }}{{ t('common.minutes') }}</view>
<view v-if="+item.deliveryService === 1" class="mt-12rpx text-center text-24rpx lh-24rpx text-#7D7D7D">{{ item.deliveryTime }}{{ Number(item.deliveryTime) === 1 ? t('common.day') : t('common.days') }}</view>
</view>
</template>
<view class="shrink-0 w-30rpx op-0">1</view>
@@ -392,7 +392,7 @@ const debouncedEmit = debounce(1300, (isCollected: boolean, id: string, type: Co
<view class="flex-center-sb mt-12rpx">
<view class="text-28rpx text-#999">
<view class="line-through">US${{ item?.originalPrice }}</view>
<!-- <view>{{ t('pages-store.store.sales') }}:{{ item?.salesCount }}</view> -->
<view>{{ t('pages-store.store.sales') }}:{{ item?.salesCount }}</view>
</view>
<view class="center w-64rpx h-64rpx rounded-50% bg-white shadow-lg">
+11 -2
View File
@@ -36,7 +36,16 @@ import {getCouponReceiveListApi, receiveAllCouponApi} from "@/pages-user/service
const userStore = useUserStore();
const configStore = useConfigStore();
const message = useMessage();
const { t } = useI18n();
const { t, locale } = useI18n();
function daySuffix(value: unknown) {
const n = Number(value)
const isEn = String(locale.value || '').toLowerCase().startsWith('en')
if (isEn) {
return n === 1 ? ` ${t('pages-store.store.day')}` : ` ${t('pages-store.store.days')}`
}
return t('pages-store.store.days')
}
const tabbarHomeRef = ref<InstanceType<typeof TabbarHome>>();
const tabbarShopRef = ref<InstanceType<typeof TabbarShop>>();
const tabbarOrderRef = ref<InstanceType<typeof TabbarOrder>>();
@@ -614,7 +623,7 @@ function getInviteInfo() {
</text>
</view>
<view class="mt-4rpx text-24rpx text-#a0611d">
{{ t('pages-store.store.validDays') }}: {{ item.validDays }} {{ t('pages-store.store.days') }}</view>
{{ t('pages-store.store.validDays') }}: {{ item.validDays }}{{ daySuffix(item.validDays) }}</view>
<view class="mt-8rpx text-24rpx text-#a0611d">
{{ item?.merchantVo?.merchantName }}
</view>
@@ -152,7 +152,7 @@ function handleSubmitCollectRecipe(item: any) {
const collectRecipe = debounce(1000, (item: any) => {
appCollectCollectPost({
body: {
targetId: item.id,
targetId: String(item.id),
targetType: CollectionType.RECIPE
}
}).then(res=> {
+3 -3
View File
@@ -290,7 +290,7 @@
export type AppMerchantOrderCanUseCouponListmerchantIdGetParams =
{
'merchantId': number;
'merchantId': any;
}
@@ -5609,8 +5609,8 @@
'userId'?: number;
/** 用户类型 */
'userPort'?: number;
/** 收藏对象ID */
'targetId'?: number;
/** 收藏对象ID(建议传字符串避免大数四舍五入) */
'targetId'?: number | string;
/** 收藏对象类型(1-菜谱 2-菜品 3-配菜) */
'targetType'?: number;
/** 1-正常 2-删除 3-禁用 */