up uni-app

This commit is contained in:
CQ 2025-08-23 17:12:25 +08:00
parent 0022acba80
commit 195cea7bd4
31 changed files with 4051 additions and 1398 deletions

View File

@ -4,7 +4,8 @@
<view v-show="requestData.status == 1 && requestData.error && requestData.error.length === 0 && !diy.getLoading()" class="diy-template-wrap">
<diy-group ref="diyGroupRef" :data="diyFormData"/>
</view>
<view class="flex flex-col" v-if="requestData.error && requestData.error.length > 0">
<!-- 目前只有自定义表单才展示错误信息其他类型暂时不控制 -->
<view class="flex flex-col" v-if="requestData.error && requestData.error.length > 0 && diy.data == 'DIY_FORM'">
<view class="flex-1 flex flex-col items-center pt-[20rpx]" v-for="(item, index) in requestData.error.slice(0, 1)" :key="index">
<text class="nc-iconfont nc-icon-tanhaoV6mm text-[#ccc] mb-[30rpx] !text-[100rpx]"></text>
<view class="text-[38rpx] font-bold mt-3">{{ item.title }}</view>

View File

@ -122,6 +122,9 @@
<diy-form-file ref="diyFormFileRef" :component="component" :global="data.global" :index="index" />
</template>
<!-- 以下是addon文件夹下的自定义组件 -->
</view>
</view>
</template>
@ -132,6 +135,7 @@
</view>
</template>
<script lang="ts" setup>
import topTabbar from '@/components/top-tabbar/top-tabbar.vue'
import popAds from '@/components/pop-ads/pop-ads.vue'
import { useDiyGroup } from './useDiyGroup'

View File

@ -8,6 +8,88 @@
<text class="text-[#ec0003]">{{ diyComponent.field.required ? '*' : '' }}</text>
</view>
</view>
<view>
<!-- <uni-table border>
<uni-tr v-for="(column, columnIndex) in diyComponent.columnList" :key="columnIndex">
<uni-th>{{ column.name }}</uni-th>
<uni-td>
<view class="layout-two-content"
v-if="column.type === 'text' || column.type === 'number' || column.type === 'idcard'">
<input :type="column.type" class="layout-one-content"
placeholderClass="layout-one-input-placeholder"
:placeholder-style="{'font-size': (diyComponent.fontSize * 2) + 'rpx' }"
:style="{'color': diyComponent.textColor,'font-size': (diyComponent.fontSize * 2) + 'rpx'}"
v-model="column.value" :disabled="isDisabled" />
</view>
<view class="layout-two-content"
v-else-if="column.type === 'mobile'">
<input type="tel" class="layout-one-content"
placeholderClass="layout-one-input-placeholder"
:placeholder-style="{'font-size': (diyComponent.fontSize * 2) + 'rpx' }"
:style="{'color': diyComponent.textColor,'font-size': (diyComponent.fontSize * 2) + 'rpx'}"
v-model="column.value" :disabled="isDisabled" />
</view>
<view v-else-if="column.type === 'gender'">
<view @click="openSex(column)"
class="px-[16rpx] box-border h-[80rpx] flex items-center justify-between border-solid border-[2rpx] border-[#e6e6e6] rounded-[10rpx] w-[100%]">
<view>
<text class="mr-[10rpx] text-[28rpx]"
:style="{'color': diyComponent.textColor,'font-size': (diyComponent.fontSize * 2) + 'rpx'}">
{{ getSexName(column) }}
</text>
</view>
<text class="nc-iconfont nc-icon-xiaV6xx pull-down-arrow text-[#666]"
:class="{'selected': selectShow[columnIndex]}"
:style="{'font-size': (diyComponent.fontSize * 2 + 2) + 'rpx !important'}"></text>
</view>
</view>
<view v-else-if="column.type === 'date'">
<view class="layout-one-content" @click="openCalendar(column)">
<view
class="nc-iconfont nc-icon-a-riliV6xx-36 !text-[32rpx] text-[#999] mr-[16rpx]">
</view>
<view class="flex-1 text-overflow-ellipsis flex"
:class="{'!text-[#999]' : !diyComponent.field.value.date && !diyComponent.defaultControl}"
:style="{'color': diyComponent.textColor,'font-size': (diyComponent.fontSize * 2) + 'rpx' }">
{{ startDate }}
</view>
</view>
</view>
<view v-else-if="column.type === 'address'">
<view class="flex layout-one-content justify-between items-center">
<input type="text" class="flex-1" :placeholder="inputPlaceholder(column)"
placeholderClass="layout-one-input-placeholder"
:placeholder-style="{'font-size': (diyComponent.fontSize * 2) + 'rpx' }"
:style="{'color': diyComponent.textColor,'font-size': (diyComponent.fontSize * 2) + 'rpx'}"
v-model="column.value" :disabled="isDisabled" @click="selectArea(column)" />
<view class="text-[var(&#45;&#45;primary-color)]" v-if="column.value" @click="column.value=''">
清除
</view>
</view>
<textarea v-if="column.addressFormat=='province/city/district/address'" type="textarea" class="layout-one-content mt-2 w-full" placeholderClass="layout-one-input-placeholder" :placeholder-style="{'font-size': (diyComponent.fontSize * 2) + 'rpx' }" placeholder="详细地址(如小区门牌号)" :disabled="isDisabled"></textarea>
</view>
&lt;!&ndash; 仅当字段类型为 'radio' 时才显示 &ndash;&gt;
<view class="layout-two-content" v-else-if="column.type === 'radio'">
<view @click="openPicker(columnIndex)"
class="px-[16rpx] box-border h-[80rpx] flex items-center justify-between border-solid border-[2rpx] border-[#e6e6e6] rounded-[10rpx] w-[100%]">
<view v-if="column.value">
<text class="mr-[10rpx] text-[28rpx]"
:style="{'color': diyComponent.textColor,'font-size': (diyComponent.fontSize * 2) + 'rpx'}">
{{ getSelectRadioName(columnIndex) }}
</text>
</view>
<text v-else class="text-[28rpx] text-[#999]"
:style="{'font-size': (diyComponent.fontSize * 2) + 'rpx'}">请选择</text>
<text class="nc-iconfont nc-icon-xiaV6xx pull-down-arrow text-[#666]"
:class="{'selected': selectShow[columnIndex]}"
:style="{'font-size': (diyComponent.fontSize * 2 + 2) + 'rpx !important'}"></text>
</view>
</view>
</uni-td>
</uni-tr>
</uni-table>-->
</view>
</view>
<!-- 下拉弹窗 -->
@ -50,7 +132,10 @@
import { ref, computed, watch, onMounted } from 'vue';
import useDiyStore from '@/app/stores/diy';
import { img, timeStampTurnTime, timeTurnTimeStamp } from '@/utils/common';
// import uniTable from '@/addon/o2o/components/uni-table/components/uni-table/uni-table.vue'
// import uniTr from '@/addon/o2o/components/uni-table/components/uni-tr/uni-tr.vue'
// import uniTh from '@/addon/o2o/components/uni-table/components/uni-th/uni-th.vue'
// import uniTd from '@/addon/o2o/components/uni-table/components/uni-td/uni-td.vue'
const props = defineProps(['component', 'index', 'global']);
const diyStore = useDiyStore();
const formData: any = ref({
@ -251,8 +336,8 @@
const warpCss = computed(() => {
var style = '';
style += 'position:relative;';
let style = '';
style += 'position:relative;';
if (diyComponent.value.componentStartBgColor) {
if (diyComponent.value.componentStartBgColor && diyComponent.value.componentEndBgColor) style += `background:linear-gradient(${diyComponent.value.componentGradientAngle},${diyComponent.value.componentStartBgColor},${diyComponent.value.componentEndBgColor});`;
else style += 'background-color:' + diyComponent.value.componentStartBgColor + ';';

View File

@ -10,13 +10,13 @@
<view class="text-[26rpx] leading-[39rpx] text-[var(--text-color-light6)] mt-[24rpx] mb-[90rpx]">{{ t('bindMobileTip') }}</view>
<u-form labelPosition="left" :model="formData" errorType='toast' :rules="rules" ref="formRef">
<view
class="h-[90rpx] flex w-full items-center px-[30rpx] rounded-[var(--goods-rounded-mid)] box-border bg-[#F6F6F6]">
class="h-[90rpx] flex w-full items-center px-[30rpx] rounded-[40rpx] box-border bg-[#F6F6F6]">
<u-form-item label="" prop="mobile" :border-bottom="false">
<u-input v-model="formData.mobile" type="number" maxlength="11" border="none" :placeholder="t('mobilePlaceholder')" class="!bg-transparent" :disabled="real_name_input" fontSize="26rpx" placeholderClass="!text-[var(--text-color-light9)] text-[26rpx]" />
</u-form-item>
</view>
<view
class="h-[90rpx] flex w-full items-center px-[30rpx] rounded-[var(--goods-rounded-mid)] box-border bg-[#F6F6F6] mt-[40rpx]">
class="h-[90rpx] flex w-full items-center px-[30rpx] rounded-[40rpx] box-border bg-[#F6F6F6] mt-[40rpx]">
<u-form-item label="" prop="mobile_code" :border-bottom="false">
<u-input v-model="formData.mobile_code" type="number" maxlength="4" border="none" :placeholder="t('codePlaceholder')" class="!bg-transparent" :disabled="real_name_input" fontSize="26rpx" placeholderClass="!text-[var(--text-color-light9)]">
<template #suffix>
@ -84,18 +84,11 @@ const formData: any = reactive({
const real_name_input = ref(true);
const wxPrivacyPopupRef: any = ref(null)
onLoad(() => {
//
setTimeout(() => {
real_name_input.value = false;
}, 800)
// #ifdef MP
nextTick(() => {
if (wxPrivacyPopupRef.value) wxPrivacyPopupRef.value.proactive();
})
// #endif
uni.getStorageSync('openid') && (Object.assign(formData, { openid: uni.getStorageSync('openid') }))
uni.getStorageSync('pid') && (Object.assign(formData, { pid: uni.getStorageSync('pid') }))

View File

@ -18,7 +18,7 @@
<u-input v-model="formData.username" border="none" maxlength="40"
:placeholder="t('usernamePlaceholder')" autocomplete="off" class="!bg-transparent"
:disabled="real_name_input" fontSize="26rpx"
placeholderClass="!text-[var(--text-color-light6)] text-[26rpx]" />
placeholderClass="!text-[var(--text-color-light9)] text-[26rpx]" />
</u-form-item>
</view>
<view class="h-[88rpx] flex w-full items-center px-[30rpx] rounded-[40rpx] box-border bg-[#F6F6F6] mt-[40rpx]">
@ -26,7 +26,7 @@
<u-input v-model="formData.password" border="none" :password="isPassword" maxlength="40"
:placeholder="t('passwordPlaceholder')" autocomplete="new-password"
class="!bg-transparent" :disabled="real_name_input" fontSize="26rpx"
placeholderClass="!text-[var(--text-color-light6)] text-[26rpx]">
placeholderClass="!text-[var(--text-color-light9)] text-[26rpx]">
<template #suffix>
<view @click="changePassword" v-if="formData.password">
<u-icon :name="isPassword?'eye-off':'eye-fill'" color="#b9b9b9" size="20"></u-icon>
@ -42,15 +42,15 @@
<u-input v-model="formData.mobile" type="number" maxlength="11" border="none"
:placeholder="t('mobilePlaceholder')" autocomplete="off" class="!bg-transparent"
:disabled="real_name_input" fontSize="26rpx"
placeholderClass="!text-[var(--text-color-light6)] text-[26rpx]" />
placeholderClass="!text-[var(--text-color-light9)] text-[26rpx]" />
</u-form-item>
</view>
<view class="h-[88rpx] flex w-full items-center px-[30rpx] rounded-[40rpx] box-border bg-[#F6F6F6] mt-[40rpx] text-[26rpx]">
<view class="h-[88rpx] flex w-full items-center px-[30rpx] rounded-[40rpx] box-border bg-[#F6F6F6] mt-[40rpx]">
<u-form-item label="" prop="mobile_code" :border-bottom="false">
<u-input v-model="formData.mobile_code" type="number" maxlength="4" border="none"
class="!bg-transparent" fontSize="26rpx" :disabled="real_name_input"
:placeholder="t('codePlaceholder')"
placeholderClass="!text-[var(--text-color-light6)] text-[26rpx]">
placeholderClass="!text-[var(--text-color-light9)] text-[26rpx]">
<template #suffix>
<sms-code v-if="configStore.login.agreement_show" :mobile="formData.mobile" type="login" v-model="formData.mobile_key" :isAgree="isAgree"></sms-code>
<sms-code v-else :mobile="formData.mobile" type="login" v-model="formData.mobile_key"></sms-code>

View File

@ -39,7 +39,7 @@
</view>
<view class="flex-1">
<view class="text-[22rpx] text-[var(--text-color-light9)] mb-[10rpx] leading-[30rpx]">核销员</view>
<view class="text-[26rpx] text-[#303133] leading-[36rpx]">{{ item.member ? item.member.nickname : '--' }}</view>
<view class="text-[26rpx] text-[#303133] leading-[36rpx]">{{ (item.is_admin == 1 ? '后台核销' : item.member?.nickname) || '--' }}</view>
</view>
</view>
</view>

View File

@ -17,16 +17,16 @@
</view>
<view class="flex-1 pr-[10rpx]" v-else></view>
</view>
<scroll-view scroll-y="true" class="h-[50vh]">
<view class="flex p-[30rpx] pt-[0] text-sm font-500">
<view v-if="areaList.province.length" class="flex-1 pr-[10rpx]" :style="{ opacity: currSelect == 'province' ? 1 : 0, pointerEvents: currSelect == 'province' ? 'auto' : 'none' }">
<view v-for="item in areaList.province" class="h-[80rpx] flex items-center" :class="{'text-[var(--primary-color)]': selected.province && selected.province.id == item.id }" @click="selected.province = item">{{ item.name }}</view>
<scroll-view scroll-y="true" class="h-[50vh]" :scroll-top="scrollTop" scroll-with-animation @touchmove.stop>
<view class="flex p-[30rpx] pt-[0] text-sm font-500 h-[50vh]">
<view v-if="areaList.province.length" class="flex-1 pr-[10rpx]" :style="{ opacity: currSelect == 'province' ? 1 : 0, pointerEvents: currSelect == 'province' ? 'auto' : 'none',height: currSelect == 'province' ? 'auto' : '0',overflow: currSelect == 'province' ? 'auto' : 'hidden' }">
<view v-for="(item, index) in areaList.province" :key="item.id" class="h-[80rpx] flex items-center" :class="{'text-[var(--primary-color)]': selected.province && selected.province.id == item.id }" @click="handleProvinceClick(item)">{{ item.name }}</view>
</view>
<view v-if="areaList.city.length" class="flex-1 pr-[10rpx]" :style="{ opacity: currSelect == 'city' ? 1 : 0, pointerEvents: currSelect == 'city' ? 'auto' : 'none' }">
<view v-for="item in areaList.city" class="h-[80rpx] flex items-center" :class="{'text-[var(--primary-color)]': selected.city && selected.city.id == item.id }" @click="selected.city = item">{{ item.name }}</view>
<view v-if="areaList.city.length" class="flex-1 pr-[10rpx]" :style="{ opacity: currSelect == 'city' ? 1 : 0, pointerEvents: currSelect == 'city' ? 'auto' : 'none',height: currSelect == 'city' ? 'auto' : '0',overflow: currSelect == 'city' ? 'auto' : 'hidden' }">
<view v-for="(item, index) in areaList.city" :key="item.id" class="h-[80rpx] flex items-center" :class="{'text-[var(--primary-color)]': selected.city && selected.city.id == item.id }" @click="handleCityClick(item)">{{ item.name }}</view>
</view>
<view v-if="areaList.district.length" class="flex-1 pr-[10rpx]" :style="{ opacity: currSelect == 'district' ? 1 : 0, pointerEvents: currSelect == 'district' ? 'auto' : 'none' }">
<view v-for="item in areaList.district" class="h-[80rpx] flex items-center " :class="{'text-[var(--primary-color)]': selected.district && selected.district.id == item.id }" @click="selected.district = item">{{ item.name }}</view>
<view v-if="areaList.district.length" class="flex-1 pr-[10rpx]" :style="{ opacity: currSelect == 'district' ? 1 : 0, pointerEvents: currSelect == 'district' ? 'auto' : 'none',height: currSelect == 'district' ? 'auto' : '0',overflow: currSelect == 'district' ? 'auto' : 'hidden' }">
<view v-for="(item, index) in areaList.district" :key="item.id" class="h-[80rpx] flex items-center " :class="{'text-[var(--primary-color)]': selected.district && selected.district.id == item.id }" @click="selected.district = item">{{ item.name }}</view>
</view>
<view class="flex-1 pr-[10rpx]" v-else></view>
</view>
@ -36,7 +36,7 @@
</template>
<script setup lang="ts">
import { ref, reactive, watch } from 'vue'
import { ref, reactive, watch, nextTick } from 'vue'
import { getAreaListByPid, getAreaByCode } from '@/app/api/system'
const prop = defineProps({
@ -60,6 +60,9 @@ const selected = reactive({
district: null
})
//
const scrollTop = ref(0)
getAreaListByPid(0).then(({ data }) => {
areaList.province = data
}).catch()
@ -86,14 +89,21 @@ watch(() => selected.province, () => {
if (selected.city) {
let isExist = false
let selectedIndex = -1
for (let i = 0; i < data.length; i++) {
if (selected.city.id == data[i].id) {
isExist = true
selectedIndex = i
break
}
}
if (!isExist) {
selected.city = null
} else {
//
setTimeout(() => {
scrollToSelected('city', selectedIndex)
}, 100)
}
}
}).catch()
@ -110,14 +120,21 @@ watch(() => selected.city, (nval) => {
if (selected.district) {
let isExist = false
let selectedIndex = -1
for (let i = 0; i < data.length; i++) {
if (selected.district.id == data[i].id) {
isExist = true
selectedIndex = i
break
}
}
if (!isExist) {
selected.district = null
} else {
//
setTimeout(() => {
scrollToSelected('district', selectedIndex)
}, 100)
}
}
if (!data.length) {
@ -135,6 +152,44 @@ watch(() => selected.city, (nval) => {
const emits = defineEmits(['complete'])
//
const scrollToSelected = (type: string, selectedIndex: number) => {
//
const itemHeight = 80 // 80rpx
const targetScrollTop = Math.max(0, (selectedIndex - 2) * itemHeight) // 3
scrollTop.value = targetScrollTop
}
//
const resetScrollTop = () => {
scrollTop.value = 0
}
//
watch(() => currSelect.value, (newVal) => {
//
resetScrollTop()
setTimeout(() => {
if (newVal === 'province' && selected.province) {
const index = areaList.province.findIndex((item: any) => item.id === selected.province.id)
if (index >= 0) {
scrollToSelected('province', index)
}
} else if (newVal === 'city' && selected.city) {
const index = areaList.city.findIndex((item: any) => item.id === selected.city.id)
if (index >= 0) {
scrollToSelected('city', index)
}
} else if (newVal === 'district' && selected.district) {
const index = areaList.district.findIndex((item: any) => item.id === selected.district.id)
if (index >= 0) {
scrollToSelected('district', index)
}
}
}, 150)
})
/**
* 监听区县变更
*/
@ -146,6 +201,24 @@ watch(() => selected.district, (nval) => {
}
}, { deep: true })
//
const handleProvinceClick = (item: any) => {
selected.province = item
//
nextTick(() => {
resetScrollTop()
})
}
//
const handleCityClick = (item: any) => {
selected.city = item
//
nextTick(() => {
resetScrollTop()
})
}
const open = () => {
show.value = true
if(prop.areaId){

View File

@ -0,0 +1,191 @@
<template>
<view class="carousel-container">
<view class="carousel-track" :style="trackStyle">
<view
v-for="(item, index) in displayList"
:key="item.key"
class="carousel-item"
:style="itemStyle(index)"
:class="{ 'scale-in': item.isNew }"
>
<u--image width="30rpx" height="30rpx" radius="15rpx" :src="img(item.src)" mode="aspectFill">
<template #error>
<image
class="w-[30rpx] h-[30rpx] rounded-full"
:src="img('static/resource/images/default_headimg.png')"
mode="aspectFill"
/>
</template>
</u--image>
</view>
</view>
</view>
</template>
<script setup lang="ts">
import { ref, onMounted, onUnmounted, computed, nextTick } from 'vue';
import { img } from '@/utils/common';
const props = defineProps<{
avatars: string[];
interval?: number; // 2000ms
}>();
//
const VISIBLE_COUNT = 3;
const ITEM_WIDTH = 30;
const OVERLAP = 10;
const ANIMATION_DURATION = 500; //
const EASING = 'cubic-bezier(0.25, 0.1, 0.25, 1)'; // 线
const slideDistance = ITEM_WIDTH - OVERLAP;
//
const displayList = ref<{
src: string;
isNew: boolean;
key: string; // keyv-for
}[]>([]);
let currentIndex = 0;
let timer: ReturnType<typeof setInterval> | null = null;
const isTransitioning = ref(false);
const trackOffset = ref(0);
/**
* 初始化列表确保初始状态稳定
*/
const initList = () => {
if (props.avatars.length <= VISIBLE_COUNT) {
displayList.value = props.avatars.map((src, i) => ({
src,
isNew: true,
key: `init-${i}-${src}` // key
}));
} else {
displayList.value = props.avatars.slice(0, VISIBLE_COUNT).map((src, i) => ({
src,
isNew: true,
key: `init-${i}-${src}`
}));
currentIndex = VISIBLE_COUNT;
}
};
/**
* 单个头像样式同步动画参数
*/
const itemStyle = (index: number) => ({
zIndex: VISIBLE_COUNT + 1 - index,
transition: `transform ${ANIMATION_DURATION}ms ${EASING}`, //
});
/**
* 轨道样式启用硬件加速优化过渡
*/
const trackStyle = computed(() => ({
transform: `translateX(${trackOffset.value}rpx)`,
transition: isTransitioning.value
? `transform ${ANIMATION_DURATION}ms ${EASING}`
: 'none',
display: 'flex',
//
willChange: isTransitioning.value ? 'transform' : 'auto',
backfaceVisibility: 'hidden',
perspective: '1000px',
}));
/**
* 滑动动画优化时序避免闪烁
*/
const slide = async () => {
if (props.avatars.length <= VISIBLE_COUNT || isTransitioning.value) return;
isTransitioning.value = true;
try {
// 1. key
const nextKey = `slide-${currentIndex}-${Date.now()}`; //
const nextAvatar = {
src: props.avatars[currentIndex % props.avatars.length],
isNew: false, //
key: nextKey
};
displayList.value.unshift(nextAvatar);
await nextTick(); // DOM
// 2.
trackOffset.value = -slideDistance;
isTransitioning.value = false;
await nextTick(); //
// 3.
isTransitioning.value = true;
trackOffset.value = 0; //
// 4.
setTimeout(() => {
nextAvatar.isNew = true; //
}, 500); //
// 5.
await new Promise(resolve => {
setTimeout(resolve, ANIMATION_DURATION);
});
// 6.
displayList.value.pop();
// 7.
currentIndex = (currentIndex + 1) % props.avatars.length;
} finally {
isTransitioning.value = false; //
}
};
/**
* 组件挂载与清理
*/
onMounted(() => {
if (props.avatars?.length) {
initList();
if (props.avatars.length > VISIBLE_COUNT) {
const delay = props.interval || 2000;
timer = setInterval(slide, delay);
}
}
});
onUnmounted(() => {
if (timer) clearInterval(timer);
});
</script>
<style scoped lang="scss">
.carousel-container {
width: 70rpx;
height: 30rpx;
overflow: hidden;
position: relative;
display: flex;
justify-content: flex-end; // 3
}
.carousel-track {
height: 100%;
position: relative;
}
.carousel-item {
width: 30rpx;
height: 30rpx;
position: relative;
flex-shrink: 0;
&:not(:first-child) {
margin-left: -10rpx; //
}
transform: scale(0); //
}
//
.carousel-item.scale-in {
transform: scale(0.9);
}
</style>

View File

@ -0,0 +1,107 @@
@ -1,108 +0,0 @@
<template>
<view :style="itemStyle">
<view class="danmu-item" :style="{ backgroundColor: bgColor, borderRadius: rounded, color: textColor }">
<image class="w-[40rpx] h-[40rpx] rounded-[100rpx]" :src="data.headimg?img(data.headimg):img('static/resource/images/default_headimg.png')" :mode="'aspectFill'"
/>
<text class="username max-w-[160rpx] truncate">{{ data.nickname }}</text>
<text class="time whitespace-nowrap">{{ data.time }}下单</text>
</view>
</view>
</template>
<script setup>
import { computed } from 'vue'
import { img } from '@/utils/common';
const props = defineProps({
bgColor: {
type: String,
default: '#B0B0B0'
},
opacity: {
type: String,
default: '1'
},
textColor: {
type: String,
default: '#FFFFFF'
},
rounded: {
type: Number,
default: 20
},
data: {
type: Object,
required: true
},
delay: {
type: Number,
default: 0
},
speed: {
type: Number,
default: 8
}
})
const itemStyle = computed(() => {
return {
'--speed': `${props.speed}s`,
'--delay': `${props.delay}s`,
'--height': `-300rpx`
}
})
</script>
<style scoped>
.danmu-item {
position: absolute;
left: 30rpx;
bottom: 0;
min-width: 180rpx;
white-space: nowrap;
padding: 10rpx;
padding-right: 20rpx;
background-color: rgba(255, 255, 255, 0.9);
border-radius: 40rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
font-size: 28rpx;
color: #333;
transform: translateY(0);
opacity: 0;
animation: moveUp linear var(--speed) forwards;
animation-delay: var(--delay);
display: flex;
align-items: center;
margin-bottom: 0;
}
.username {
margin-left: 8rpx;
font-size: 24rpx;
}
.time {
font-size: 24rpx;
}
@keyframes moveUp {
0% {
transform: translateY(0);
opacity: 0;
}
10% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
transform: translateY(var(--height));
opacity: 0;
}
}
</style>

View File

@ -0,0 +1,176 @@
<template>
<view class="danmu-container">
<barrage-item v-for="(item, index) in danmuList" :key="`${item.id}-${item.timestamp}`" :data="item" :delay="item.delay" :speed="item.speed"
:textColor="props.textColor" :bgColor="props.bgColor" :rounded="props.rounded" />
</view>
</template>
<script setup>
import { ref, onMounted, computed,nextTick, watch, onUpdated, onUnmounted } from 'vue'
import barrageItem from '@/components/barrage/barrage-item.vue'
const props = defineProps({
bgColor: {
type: String,
default: '#B0B0B0'
},
textColor: {
type: String,
default: '#FFFFFF'
},
rounded: {
type: Number,
default: 20
},
maxCount: {
type: Number,
default: 6
},
speed: {
type: Number,
default: 6
},
interval: {
type: Number,
default: 1.5
},
data: {
type: Object,
default: []
},
play:{ // ,true:,false:
type: Boolean,
default: true
}
})
const danmuList = ref([]) //
const waitList = ref([]) //
const initTimeId = ref([]) // id
const loopTimeId = ref(null) // id
//
const initDanmu = () => {
nextTick(() => {
danmuList.value = props.data.map((item, index) => {
let obj = {}
const timestamp = Date.now() + Math.random()
obj.id = item.id ? `danmu-${item.id}-${timestamp}` : `danmu-${timestamp}`
obj.timestamp = timestamp
obj.nickname = item.nickname
obj.headimg = item.headimg
obj.time = formatTimestampToHumanTime(item.time)
obj.delay = index * props.interval,
obj.speed = props.speed
return obj
})
danmuList.value.forEach((item, index) => {
initTimeId.value[index] = setTimeout(() => {
waitList.value.push(item)
danmuList.value.shift();
loopTriggerFn()
}, (item.delay + item.speed) * 1000)
})
})
}
//
const loopTriggerFn = () => {
if (!danmuList.value.length) {
loopTimeId.value = setTimeout(() => {
//
danmuList.value = waitList.value.map(item => {
const timestamp = Date.now() + Math.random()
return {
...item,
id: `${item.id}-loop-${timestamp}`,
timestamp: timestamp
}
})
waitList.value = []
danmuList.value.forEach((item, index) => {
initTimeId.value[index] = setTimeout(() => {
waitList.value.push(item)
danmuList.value.shift();
loopTriggerFn()
}, (item.delay + item.speed) * 1000)
})
}, 1000)
}
}
watch(() => props.play, (newVal, oldVal) => {
nextTick(() => {
if (newVal) {
initTimeId.value.forEach((item, index) => {
if (item) {
clearTimeout(item)
}
})
clearTimeout(loopTimeId.value)
waitList.value = []
danmuList.value = []
initDanmu()
}else{
initTimeId.value.forEach((item, index) => {
if (item) {
clearTimeout(item)
}
})
clearTimeout(loopTimeId.value)
waitList.value = []
danmuList.value = []
}
})
})
onMounted(() => {
initDanmu()
})
/**
* 将时间戳转换为最合适的可读时间单位分钟小时天等并舍去小数部分
* @param {number} timestamp - 时间戳毫秒
* @returns {string} 人类可读的相对时间字符串
*/
const formatTimestampToHumanTime = (timestamp) => {
const now = Date.now();
let seconds = Math.round((now - timestamp) / 1000); //
//
if (seconds < 0) {
return '未来';
}
const intervals = [
{ label: '年', seconds: 31536000 }, // 60 * 60 * 24 * 365
{ label: '个月', seconds: 2592000 }, // 60 * 60 * 24 * 30
{ label: '周', seconds: 604800 }, // 60 * 60 * 24 * 7
{ label: '天', seconds: 86400 }, // 60 * 60 * 24
{ label: '小时', seconds: 3600 }, // 60 * 60
{ label: '分钟', seconds: 60 }
];
for (let i = 0; i < intervals.length; i++) {
const interval = intervals[i];
const count = Math.floor(seconds / interval.seconds); //
if (count >= 1) {
return `${count}${interval.label}`;
}
}
return '刚刚';
}
</script>
<style scoped>
.danmu-container {
position: fixed;
top: 160rpx;
left: 0;
height: 500rpx;
width: 100%;
pointer-events: none;
z-index: 9;
overflow: hidden;
}
</style>

View File

@ -0,0 +1,253 @@
# 🎆 简单烟花特效组件
一个轻量级的uni-app烟花特效组件专注于提供最佳的用户体验。
## 📁 组件结构
```
firework-effect/
├── firework-effect.vue # 主要的烟花特效组件
├── simple-firework.vue # 简单烟花特效组件
└── README.md # 说明文档
```
## ✨ 特效特点
### 🎇 简单烟花 (simple-firework)
- 从底部发射,空中爆炸成彩色粒子
- 自动发射,可定义持续时间
- **不阻挡用户操作** - 设置了 `pointer-events: none`
- **自动停止** - 默认30秒可自定义
- **无黑色阴影** - 使用透明背景
- **兼容性最好** - 使用传统Canvas API
### 🧧 红包雨 (red-packet-rain)
- **新增功能**
- 从屏幕顶部飘落的红包雨效果
- **点击获得金额** - 点击红包显示随机金额提示
- **不阻挡用户操作** - 设置了 `pointer-events: none`,不会挡住底部按钮
- **自定义时间** - 可设置持续时间
- **自定义密度** - 可调节红包数量
- **自定义速度** - 可调节下落速度
- **自定义大小** - 可设置红包大小范围
- **自定义金额** - 可设置金额范围
- **精美动画** - 金额提示有向上飘动的动画效果
- **自动绘制红包** - 无需图片资源,自动绘制精美红包
## 🎯 使用方法
### 1. 基本使用
```vue
<template>
<view>
<!-- 你的页面内容 -->
<!-- 基础配置 -->
<firework-effect
ref="fireworkRef"
:duration="20000"
:no-trail="true"
:red-packet-density="5"
:red-packet-speed="3"
:red-packet-min-size="80"
:red-packet-max-size="120"
:red-packet-min-amount="0.1"
:red-packet-max-amount="50.0"
:red-packet-clickable="true"
></firework-effect>
</view>
</template>
<script setup>
import { ref } from 'vue';
import FireworkEffect from '@/components/firework-effect/firework-effect.vue';
const fireworkRef = ref(null);
// 显示简单烟花特效
const showFireworks = () => {
fireworkRef.value?.handleShowEffect({
type: 'simple-firework',
duration: 15000 // 15秒后自动停止可选参数
});
};
// 显示红包雨特效(新功能)
const showRedPacketRain = () => {
fireworkRef.value?.handleShowEffect({
type: 'red-packet-rain',
duration: 10000 // 10秒后自动停止
});
};
// 使用默认30秒
const showDefaultFireworks = () => {
fireworkRef.value?.handleShowEffect({ type: 'simple-firework' });
};
</script>
```
### 2. API 说明
#### FireworkEffect 组件
**Props:**
- `duration`: 特效持续时间毫秒默认3000030秒
- `noTrail`: 是否禁用拖尾效果避免黑色阴影默认true
- `redPacketImages`: 红包图片数组,如:`['/static/images/hongbao1.png']`
- `redPacketUseImages`: 是否使用图片模式默认false使用绘制模式
- `redPacketDensity`: 红包密度每次生成数量默认3
- `redPacketSpeed`: 红包下落速度默认2
- `redPacketMinSize`: 红包最小大小px默认60
- `redPacketMaxSize`: 红包最大大小px默认100
- `redPacketMinAmount`: 红包最小金额默认0.01
- `redPacketMaxAmount`: 红包最大金额默认10.00
- `redPacketClickable`: 是否可点击红包默认true
**方法:**
- `handleShowEffect(params)`: 显示特效
- `params.type`: 特效类型
- `'simple-firework'`: 简单烟花特效
- `'red-packet-rain'``'hongbao'`: 红包雨特效
- `params.duration`: 自定义持续时间(可选)
### 🚫 解决黑色阴影问题
如果您看到黑色阴影,请确保:
1. **设置 `no-trail="true"`**(默认已启用)
2. **避免使用拖尾效果**,这会产生半透明覆盖
```vue
<!-- ✅ 推荐:无阴影版本 -->
<firework-effect :no-trail="true"></firework-effect>
<!-- ❌ 不推荐:可能有阴影 -->
<firework-effect :no-trail="false"></firework-effect>
```
### 📋 注意事项
1. 确保页面有足够的渲染性能
2. 在低端设备上可能需要减少粒子数量
3. 长时间运行建议定期清理资源
4. 某些小程序平台可能对 Canvas API 有限制
5. **只支持 `simple-firework` 类型**,不会阻挡用户操作
### 🎁 红包雨详细配置
#### 方式一:使用自定义图片
```vue
<template>
<!-- 使用自定义红包图片 -->
<firework-effect
ref="fireworkRef"
:red-packet-images="[
'/static/images/hongbao1.png',
'/static/images/hongbao2.png',
'/static/images/hongbao3.png'
]"
:red-packet-use-images="true" <!-- 启用图片模式 -->
:red-packet-min-size="100" <!-- 红包最小100px -->
:red-packet-max-size="150" <!-- 红包最大150px -->
:red-packet-min-amount="1.0" <!-- 最小1元 -->
:red-packet-max-amount="100.0" <!-- 最大100元 -->
:red-packet-density="6" <!-- 每次生成6个红包 -->
:red-packet-speed="1.5" <!-- 较慢的下落速度 -->
:red-packet-clickable="true" <!-- 启用点击功能 -->
></firework-effect>
</template>
```
#### 方式二:使用代码绘制(默认)
```vue
<template>
<!-- 使用代码绘制的红包 -->
<firework-effect
ref="fireworkRef"
:red-packet-use-images="false" <!-- 使用绘制模式(默认) -->
:red-packet-min-size="80" <!-- 红包最小80px -->
:red-packet-max-size="120" <!-- 红包最大120px -->
:red-packet-min-amount="0.1" <!-- 最小0.1元 -->
:red-packet-max-amount="50.0" <!-- 最大50元 -->
:red-packet-density="4" <!-- 每次生成4个红包 -->
:red-packet-speed="2.5" <!-- 下落速度 -->
:red-packet-clickable="true" <!-- 启用点击功能 -->
></firework-effect>
</template>
```
#### 方式三:使用网络图片
```vue
<template>
<!-- 使用网络红包图片 -->
<firework-effect
ref="fireworkRef"
:red-packet-images="[
'https://example.com/hongbao1.png',
'https://example.com/hongbao2.png'
]"
:red-packet-use-images="true"
:red-packet-min-size="100"
:red-packet-max-size="150"
></firework-effect>
</template>
```
### 🖼️ 红包图片要求
#### 图片格式
- **PNG**(推荐,支持透明背景)
- **JPG/JPEG**
- **WebP**
#### 尺寸建议
- **推荐尺寸**: 200x160px宽高比5:4
- **最小尺寸**: 100x80px
- **最大尺寸**: 400x320px
#### 文件大小
- **建议**: 小于100KB
- **最大**: 不超过500KB
#### 图片准备步骤
1. 将红包图片放在 `uni-app/public/static/images/` 目录
2. 文件命名建议:`hongbao1.png`, `hongbao2.png`
3. 确保图片背景透明PNG格式
4. 图片内容应该是完整的红包设计
### 📏 红包大小控制
```vue
<!-- 小红包 -->
:red-packet-min-size="60"
:red-packet-max-size="80"
<!-- 中等红包 -->
:red-packet-min-size="80"
:red-packet-max-size="120"
<!-- 大红包 -->
:red-packet-min-size="120"
:red-packet-max-size="180"
<!-- 超大红包 -->
:red-packet-min-size="150"
:red-packet-max-size="200"
```
### 🎯 红包点击功能
- **点击检测**: 自动检测用户点击的红包
- **金额显示**: 显示随机金额(在设定范围内)
- **动画效果**: 金额提示向上飘动并淡出
- **防重复**: 已点击的红包变为半透明,不可重复点击
- **响应式**: 支持触摸和鼠标点击
### 🔧 兼容性
- 支持 Vue 2 和 Vue 3
- 支持 uni-app 各平台H5、小程序、App
- 使用传统 Canvas API兼容性最佳

View File

@ -0,0 +1,155 @@
<template>
<!-- 简单烟花特效 -->
<simple-firework ref="simpleFireworkRef" :duration="fireworkDuration" :no-trail="props.noTrail"></simple-firework>
<!-- 红包雨特效 -->
<red-packet-rain
ref="redPacketRainRef"
:duration="fireworkDuration"
:images="redPacketImages"
:density="redPacketDensity"
:speed="redPacketSpeed"
:min-size="redPacketMinSize"
:max-size="redPacketMaxSize"
:min-amount="redPacketMinAmount"
:max-amount="redPacketMaxAmount"
:clickable="redPacketClickable"
:use-images="redPacketUseImages"
></red-packet-rain>
</template>
<script setup>
//
import SimpleFirework from './simple-firework.vue'
import RedPacketRain from './red-packet-rain.vue'
// #ifdef VUE3
import {
ref,
computed
} from 'vue';
// #endif
// #ifndef VUE3
import {
ref,
computed
} from '@vue/composition-api';
// #endif
// props
const props = defineProps({
duration: {
type: Number,
default: 30000 // 30
},
noTrail: {
type: Boolean,
default: true //
},
//
redPacketImages: {
type: Array,
default: () => ['/static/images/hongbao.png']
},
redPacketDensity: {
type: Number,
default: 3 //
},
redPacketSpeed: {
type: Number,
default: 2 //
},
//
redPacketMinSize: {
type: Number,
default: 60 //
},
redPacketMaxSize: {
type: Number,
default: 100 //
},
//
redPacketMinAmount: {
type: Number,
default: 0.01 //
},
redPacketMaxAmount: {
type: Number,
default: 10.00 //
},
//
redPacketClickable: {
type: Boolean,
default: true //
},
// 使
redPacketUseImages: {
type: Boolean,
default: false // 使
}
});
//
const simpleFireworkRef = ref(null)
const redPacketRainRef = ref(null)
//
const fireworkDuration = computed(() => props.duration)
const handleShowEffect = (params) => {
const {
type,
duration
} = params;
//
if (type == 'simple-firework') {
handleShowSimpleFirework(duration)
} else if (type == 'red-packet-rain' || type == 'hongbao') {
handleShowRedPacketRain(duration)
} else {
console.warn('🎆 支持的特效类型: simple-firework, red-packet-rain当前类型:', type)
}
}
//
const handleShowSimpleFirework = (customDuration) => {
if (simpleFireworkRef.value) {
simpleFireworkRef.value.startFireworks(customDuration);
}
}
//
const handleShowRedPacketRain = (customDuration) => {
if (redPacketRainRef.value) {
redPacketRainRef.value.startRedPacketRain(customDuration);
}
}
//
const stopFireworks = () => {
if (simpleFireworkRef.value && typeof simpleFireworkRef.value.stopFireworks === 'function') {
simpleFireworkRef.value.stopFireworks();
}
}
//
const stopRedPacketRain = () => {
if (redPacketRainRef.value && typeof redPacketRainRef.value.stopRedPacketRain === 'function') {
redPacketRainRef.value.stopRedPacketRain();
}
}
//
const stopAllEffects = () => {
stopFireworks();
stopRedPacketRain();
}
//
defineExpose({
handleShowEffect,
stopFireworks,
stopRedPacketRain,
stopAllEffects
})
</script>

View File

@ -0,0 +1,682 @@
<template>
<view class="red-packet-container" v-if="isVisible">
<canvas
class="red-packet-canvas"
canvas-id="redPacketRain"
id="redPacketRain"
></canvas>
<!-- 红包元素图片模式或绘制模式 -->
<view
v-for="packet in redPackets"
:key="packet.id"
class="red-packet-item"
:style="{
left: packet.x + 'px',
top: packet.y + 'px',
width: packet.width + 'px',
height: packet.height + 'px',
transform: `rotate(${packet.rotation}rad)`,
opacity: packet.opacity
}"
@click="handlePacketClick(packet, $event)"
>
<!-- 图片模式 -->
<image
v-if="props.useImages && packet.image"
:src="packet.image"
class="red-packet-image"
mode="aspectFit"
@load="onRedPacketImageLoad"
@error="onRedPacketImageError"
/>
<!-- 绘制模式 -->
<view
v-else
class="red-packet-drawn"
:style="{
width: '100%',
height: '100%'
}"
>
<view class="red-packet-body"></view>
<view class="red-packet-text"></view>
</view>
</view>
<!-- 预加载图片隐藏 -->
<image
v-for="(imagePath, index) in props.images"
:key="'preload-' + index"
:src="imagePath"
class="preload-image"
@load="onImageLoad"
@error="onImageError"
/>
<!-- 金额提示弹窗 -->
<view
v-for="tip in amountTips"
:key="tip.id"
class="amount-tip"
:style="{
left: tip.x + 'px',
top: tip.y + 'px',
opacity: tip.opacity
}"
>
<view class="tip-content">
<text class="amount">+¥{{ tip.amount }}</text>
<text class="label">{{ tip.label }}</text>
</view>
</view>
</view>
</template>
<script setup>
import { ref, getCurrentInstance, onUnmounted } from 'vue';
// props
const props = defineProps({
duration: {
type: Number,
default: 30000 // 30
},
images: {
type: Array,
default: () => [
//
// 'https://example.com/hongbao1.png',
// '/static/images/hongbao.png',
// 使
]
},
// 使
useImages: {
type: Boolean,
default: false // 使
},
density: {
type: Number,
default: 3 //
},
speed: {
type: Number,
default: 2 //
},
//
minSize: {
type: Number,
default: 60 //
},
maxSize: {
type: Number,
default: 100 //
},
//
minAmount: {
type: Number,
default: 0.01 //
},
maxAmount: {
type: Number,
default: 10.00 //
},
//
clickable: {
type: Boolean,
default: true
}
});
const app = getCurrentInstance();
let ctx = null;
let animationId = null;
let isRunning = false;
let canvasWidth = 375;
let canvasHeight = 667;
let autoStopTimer = null;
let createTimer = null;
let loadedImages = new Map(); //
let tipIdCounter = 0; // ID
const isVisible = ref(false);
const amountTips = ref([]); //
const redPackets = ref([]); //
//
class RedPacket {
constructor(x, y, image) {
this.x = x;
this.y = y;
// 使props
this.width = props.minSize + Math.random() * (props.maxSize - props.minSize);
this.height = this.width * 0.8; //
this.speed = props.speed + Math.random() * 2; //
this.rotation = Math.random() * 0.2 - 0.1; //
this.rotationSpeed = (Math.random() - 0.5) * 0.02;
this.image = image;
this.opacity = 0.9 + Math.random() * 0.1;
//
this.amount = (props.minAmount + Math.random() * (props.maxAmount - props.minAmount)).toFixed(2);
this.clicked = false; //
this.id = Date.now() + Math.random(); // ID
}
update() {
this.y += this.speed;
this.rotation += this.rotationSpeed;
//
this.x += Math.sin(this.y * 0.01) * 0.5;
}
draw() {
if (!ctx) return;
ctx.save();
ctx.globalAlpha = this.opacity;
ctx.translate(this.x + this.width / 2, this.y + this.height / 2);
ctx.rotate(this.rotation);
//
if (props.useImages && this.image) {
console.log('🧧 使用图片模式绘制红包:', this.image);
this.drawImage();
} else {
console.log('🧧 使用代码绘制红包');
this.drawRedPacket();
}
ctx.restore();
}
//
drawImage() {
const halfWidth = this.width / 2;
const halfHeight = this.height / 2;
try {
if (this.image && typeof this.image === 'string') {
console.log('🧧 绘制图片红包:', this.image);
// uni-app使ctx.drawImage
// , x, y, width, height
ctx.drawImage(this.image, -halfWidth, -halfHeight, this.width, this.height);
console.log('🧧 图片绘制完成');
} else {
console.log('🧧 图片无效,使用绘制模式');
this.drawRedPacket();
}
} catch (error) {
console.warn('🧧 图片绘制失败,降级到绘制模式:', error);
this.drawRedPacket();
}
}
drawRedPacket() {
const halfWidth = this.width / 2;
const halfHeight = this.height / 2;
//
ctx.setFillStyle('#ff4444');
ctx.fillRect(-halfWidth, -halfHeight, this.width, this.height);
//
ctx.setStrokeStyle('#ffd700');
ctx.setLineWidth(2);
ctx.strokeRect(-halfWidth, -halfHeight, this.width, this.height);
// ""
ctx.setFillStyle('#ffd700');
try {
ctx.setFontSize(this.width * 0.4);
ctx.setTextAlign('center');
ctx.fillText('福', 0, this.height * 0.1);
} catch (error) {
//
ctx.beginPath();
ctx.arc(0, 0, this.width * 0.15, 0, 2 * Math.PI);
ctx.fill();
}
//
ctx.setFillStyle('#ffaa00');
ctx.fillRect(-halfWidth * 0.6, -halfHeight, this.width * 0.6, this.height * 0.2);
}
isOffScreen() {
return this.y > canvasHeight + this.height;
}
//
isClicked(touchX, touchY) {
if (this.clicked) return false;
const centerX = this.x + this.width / 2;
const centerY = this.y + this.height / 2;
const distance = Math.sqrt(
Math.pow(touchX - centerX, 2) + Math.pow(touchY - centerY, 2)
);
return distance <= Math.max(this.width, this.height) / 2;
}
//
markAsClicked() {
this.clicked = true;
//
this.opacity = 0.3;
}
}
//
const onImageLoad = (event) => {
console.log('🧧 预加载图片成功:', event.target.src);
};
//
const onImageError = (event) => {
console.error('🧧 预加载图片失败:', event.target.src);
};
//
const onRedPacketImageLoad = () => {
//
};
//
const onRedPacketImageError = () => {
// 使
};
// image
const loadImages = async () => {
if (!props.useImages || props.images.length === 0) {
loadedImages.set('default', 'default');
return Promise.resolve();
}
// loadedImages
// templateimage
for (const imagePath of props.images) {
loadedImages.set(imagePath, imagePath);
}
return Promise.resolve();
};
// Canvas
const initCanvas = () => {
try {
ctx = uni.createCanvasContext('redPacketRain', app.proxy);
if (ctx) {
//
const systemInfo = uni.getSystemInfoSync();
canvasWidth = systemInfo.windowWidth || 375;
canvasHeight = systemInfo.windowHeight || 667;
//
ctx.setFillStyle('rgba(0, 0, 0, 0)');
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
ctx.draw();
return true;
} else {
return false;
}
} catch (error) {
return false;
}
};
//
const createRedPackets = () => {
if (!isRunning) {
return;
}
for (let i = 0; i < props.density; i++) {
const x = Math.random() * (canvasWidth - 100);
const y = -100 - Math.random() * 200; //
let image = null;
if (props.useImages && loadedImages.size > 0) {
//
const allKeys = Array.from(loadedImages.keys());
const imageKeys = allKeys.filter(key => key !== 'default');
if (imageKeys.length > 0) {
const randomImage = imageKeys[Math.floor(Math.random() * imageKeys.length)];
image = loadedImages.get(randomImage);
} else {
// 使
if (allKeys.length > 0) {
const firstKey = allKeys[0];
image = loadedImages.get(firstKey);
}
}
}
const packet = new RedPacket(x, y, image);
redPackets.value.push(packet);
}
};
//
const animate = () => {
if (!isRunning) return;
try {
// HTML
redPackets.value = redPackets.value.filter(packet => {
packet.update();
return !packet.isOffScreen();
});
//
if (isRunning) {
setTimeout(animate, 16); // 60fps
}
} catch (error) {
if (isRunning) {
setTimeout(animate, 50);
}
}
};
//
const startAnimation = () => {
isRunning = true;
animate();
};
//
const stopAnimation = () => {
isRunning = false;
if (animationId) {
clearTimeout(animationId);
animationId = null;
}
};
//
const startCreating = () => {
if (createTimer) {
clearInterval(createTimer);
}
//
createRedPackets();
//
createTimer = setInterval(() => {
if (isRunning && createTimer) { //
createRedPackets();
}
}, 1000); //
};
//
const stopCreating = () => {
if (createTimer) {
clearInterval(createTimer);
createTimer = null;
}
};
//
const startRedPacketRain = async (customDuration) => {
//
isVisible.value = true;
//
await loadImages();
// Canvas
initCanvas();
//
startAnimation();
startCreating();
//
const duration = customDuration || props.duration;
if (autoStopTimer) {
clearTimeout(autoStopTimer);
}
autoStopTimer = setTimeout(() => {
stopRedPacketRain();
}, duration);
};
//
const stopRedPacketRain = () => {
//
stopCreating();
//
if (autoStopTimer) {
clearTimeout(autoStopTimer);
autoStopTimer = null;
}
//
const waitForPacketsToFall = () => {
if (redPackets.value.length === 0) {
//
stopAnimation();
amountTips.value = [];
//
setTimeout(() => {
isVisible.value = false;
}, 1000);
} else {
//
setTimeout(waitForPacketsToFall, 500);
}
};
waitForPacketsToFall();
};
//
const handlePacketClick = (packet, event) => {
if (!props.clickable || packet.clicked) return;
console.log('🧧 点击红包图片,金额:', packet.amount);
//
packet.markAsClicked();
//
const touchX = event.currentTarget.offsetLeft + packet.width / 2;
const touchY = event.currentTarget.offsetTop + packet.height / 2;
//
showAmountTip(touchX, touchY, packet.amount);
};
//
const showAmountTip = (x, y, amount) => {
const tipId = ++tipIdCounter;
const tip = {
id: tipId,
x: x - 50, //
y: y - 30,
amount: amount,
label: '恭喜获得',
opacity: 1
};
amountTips.value.push(tip);
//
let animationStep = 0;
const animate = () => {
animationStep++;
const progress = animationStep / 60; // 60
if (progress >= 1) {
//
const index = amountTips.value.findIndex(t => t.id === tipId);
if (index !== -1) {
amountTips.value.splice(index, 1);
}
return;
}
//
const tipIndex = amountTips.value.findIndex(t => t.id === tipId);
if (tipIndex !== -1) {
amountTips.value[tipIndex].y = y - 30 - progress * 50; // 50px
amountTips.value[tipIndex].opacity = 1 - progress; //
}
setTimeout(animate, 16); // 60fps
};
animate();
};
//
onUnmounted(() => {
console.log('🧧 红包雨组件卸载,清理资源');
stopRedPacketRain();
});
//
defineExpose({
startRedPacketRain,
stopRedPacketRain
});
</script>
<style lang="scss" scoped>
.red-packet-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 998; /* 比烟花稍低的层级 */
pointer-events: none; /* 容器本身不阻挡点击事件 */
.red-packet-canvas {
width: 100%;
height: 100%;
pointer-events: none; /* Canvas 背景不阻挡点击事件 */
}
.test-red-packet {
border: 2px solid red;
}
.red-packet-image {
position: absolute;
pointer-events: auto; /* 红包图片可以被点击 */
z-index: 999;
transition: opacity 0.3s ease;
&:active {
transform: scale(0.95);
}
}
.red-packet-item {
position: absolute;
pointer-events: auto; /* 红包元素可以被点击 */
z-index: 999;
transition: opacity 0.3s ease;
}
.red-packet-image {
width: 100%;
height: 100%;
object-fit: contain;
}
.red-packet-drawn {
position: relative;
background: linear-gradient(135deg, #ff4444, #cc0000);
border: 2px solid #ffd700;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
&::before {
content: '';
position: absolute;
top: -8px;
left: 50%;
transform: translateX(-50%);
width: 60%;
height: 12px;
background: linear-gradient(135deg, #ffaa00, #ff8800);
border-radius: 6px;
border: 1px solid #ffd700;
}
}
.red-packet-text {
color: #ffd700;
font-size: 24px;
font-weight: bold;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}
.preload-image {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
pointer-events: none;
z-index: -1;
}
.amount-tip {
position: fixed;
pointer-events: none; /* 金额提示不阻挡点击事件 */
z-index: 1000; /* 确保金额提示在最上层显示 */
transition: all 0.3s ease-out;
.tip-content {
background: linear-gradient(135deg, #ff6b6b, #ff8e8e);
color: white;
padding: 8px 16px;
border-radius: 20px;
box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
text-align: center;
min-width: 100px;
.amount {
display: block;
font-size: 18px;
font-weight: bold;
margin-bottom: 2px;
}
.label {
display: block;
font-size: 12px;
opacity: 0.9;
}
}
}
}
</style>

View File

@ -0,0 +1,378 @@
<template>
<view class="firework-container" v-if="isVisible">
<canvas
class="firework-canvas"
canvas-id="simpleFirework"
id="simpleFirework"
></canvas>
</view>
</template>
<script setup>
// #ifdef VUE3
import {
ref,
onMounted,
onUnmounted,
getCurrentInstance
} from 'vue';
// #endif
// #ifndef VUE3
import {
ref,
onMounted,
onUnmounted,
getCurrentInstance
} from '@vue/composition-api';
// #endif
// props
const props = defineProps({
duration: {
type: Number,
default: 30000 // 30
},
autoStart: {
type: Boolean,
default: false
},
noTrail: {
type: Boolean,
default: true //
}
});
const app = getCurrentInstance();
let ctx = null;
let animationId = null;
let fireworks = [];
let isRunning = false;
let canvasWidth = 375;
let canvasHeight = 667;
let autoStopTimer = null;
let autoLaunchTimer = null;
const isVisible = ref(false);
//
const getRandomColor = () => {
const colors = ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#ff00ff', '#00ffff'];
return colors[Math.floor(Math.random() * colors.length)];
};
//
class SimpleFirework {
constructor(startX, startY, targetX, targetY) {
this.x = startX;
this.y = startY;
this.targetX = targetX;
this.targetY = targetY;
this.color = getRandomColor();
this.particles = [];
this.exploded = false;
this.speed = 5;
//
const dx = targetX - startX;
const dy = targetY - startY;
const distance = Math.sqrt(dx * dx + dy * dy);
this.vx = (dx / distance) * this.speed;
this.vy = (dy / distance) * this.speed;
}
update() {
if (!this.exploded) {
this.x += this.vx;
this.y += this.vy;
//
const distance = Math.sqrt((this.targetX - this.x) ** 2 + (this.targetY - this.y) ** 2);
if (distance < 20 || this.y <= this.targetY) {
this.explode();
this.exploded = true;
}
} else {
//
this.particles = this.particles.filter(particle => {
particle.x += particle.vx;
particle.y += particle.vy;
particle.vy += 0.1; //
particle.alpha -= 0.02;
return particle.alpha > 0;
});
}
}
explode() {
//
for (let i = 0; i < 20; i++) {
const angle = (Math.PI * 2 * i) / 20;
const speed = Math.random() * 4 + 2;
this.particles.push({
x: this.x,
y: this.y,
vx: Math.cos(angle) * speed,
vy: Math.sin(angle) * speed,
alpha: 1,
color: this.color
});
}
}
draw() {
if (!ctx) return;
try {
if (!this.exploded) {
//
if (ctx.setFillStyle) {
ctx.setFillStyle(this.color);
ctx.beginPath();
ctx.arc(this.x, this.y, 3, 0, Math.PI * 2);
ctx.fill();
}
} else {
//
this.particles.forEach(particle => {
if (ctx.setGlobalAlpha && ctx.setFillStyle) {
ctx.setGlobalAlpha(particle.alpha);
ctx.setFillStyle(particle.color);
ctx.beginPath();
ctx.arc(particle.x, particle.y, 2, 0, Math.PI * 2);
ctx.fill();
}
});
if (ctx.setGlobalAlpha) {
ctx.setGlobalAlpha(1);
}
}
} catch (error) {
//
}
}
isDead() {
return this.exploded && this.particles.length === 0;
}
}
// Canvas
const initCanvas = () => {
try {
// Canvas
ctx = uni.createCanvasContext('simpleFirework', app.proxy);
if (ctx) {
//
const systemInfo = uni.getSystemInfoSync();
canvasWidth = systemInfo.windowWidth || 375;
canvasHeight = systemInfo.windowHeight || 667;
//
ctx.setFillStyle('rgba(255, 255, 255, 0.01)');
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
// Canvas
ctx.setFillStyle('#ff0000');
ctx.fillRect(canvasWidth / 2, canvasHeight / 2, 10, 10);
ctx.draw(); //
// Canvas
setTimeout(() => {
startAnimation();
}, 1000);
} else {
//
setTimeout(() => {
initCanvas();
}, 1000);
}
} catch (error) {
//
setTimeout(() => {
initCanvas();
}, 1000);
}
};
//
const animate = () => {
if (!isRunning || !ctx) {
return;
}
try {
// props
if (props.noTrail) {
//
ctx.clearRect && ctx.clearRect(0, 0, canvasWidth, canvasHeight);
// clearRect使
if (!ctx.clearRect) {
ctx.setFillStyle('rgba(255, 255, 255, 0.02)');
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
}
} else {
//
ctx.setFillStyle('rgba(255, 255, 255, 0.08)');
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
}
//
fireworks = fireworks.filter(firework => {
firework.update();
firework.draw();
return !firework.isDead();
});
//
ctx.draw();
//
setTimeout(animate, 16); // 60fps
} catch (error) {
if (isRunning) {
setTimeout(animate, 50);
}
}
};
//
const startAnimation = () => {
isRunning = true;
animate();
};
//
const stopAnimation = () => {
isRunning = false;
fireworks = [];
};
//
const createFirework = (targetX, targetY) => {
if (!ctx) {
return;
}
const startX = Math.random() * canvasWidth;
const startY = canvasHeight;
const finalTargetX = targetX || Math.random() * canvasWidth;
const finalTargetY = targetY || Math.random() * canvasHeight * 0.5;
fireworks.push(new SimpleFirework(startX, startY, finalTargetX, finalTargetY));
};
//
const startAutoLaunch = () => {
if (autoLaunchTimer) {
clearInterval(autoLaunchTimer);
}
autoLaunchTimer = setInterval(() => {
if (isRunning && autoLaunchTimer) { //
createFirework();
}
}, 800); // 0.8
};
const stopAutoLaunch = () => {
if (autoLaunchTimer) {
clearInterval(autoLaunchTimer);
autoLaunchTimer = null;
}
};
//
//
const startFireworks = (customDuration) => {
//
isVisible.value = true;
if (!isRunning) {
startAnimation();
}
//
createFirework();
//
startAutoLaunch();
//
const duration = customDuration || props.duration;
if (autoStopTimer) {
clearTimeout(autoStopTimer);
}
autoStopTimer = setTimeout(() => {
stopFireworks();
}, duration);
};
//
const stopFireworks = () => {
//
stopAutoLaunch();
//
if (autoStopTimer) {
clearTimeout(autoStopTimer);
autoStopTimer = null;
}
//
const waitForFireworksToFinish = () => {
if (fireworks.length === 0) {
//
stopAnimation();
//
setTimeout(() => {
isVisible.value = false;
}, 1000);
} else {
//
setTimeout(waitForFireworksToFinish, 500);
}
};
waitForFireworksToFinish();
};
onMounted(() => {
setTimeout(() => {
initCanvas();
}, 1000);
});
onUnmounted(() => {
stopFireworks();
});
defineExpose({
startFireworks,
stopFireworks,
createFirework
});
</script>
<style lang="scss" scoped>
.firework-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none; /* 不阻挡用户操作 */
z-index: 999; /* 降低层级避免遮挡重要UI */
.firework-canvas {
width: 100%;
height: 100%;
pointer-events: none; /* Canvas也不接收事件完全不阻挡操作 */
}
}
</style>

View File

@ -22,7 +22,7 @@
<u-form-item :label=" t('nickname')" prop="nickname" :border-bottom="true">
<input type="nickname" v-model="formData.nickname" :placeholder="t('nicknamePlaceholder')" placeholderClass="text-[28rpx]" class="text-[28rpx]" @blur="bindNickname" @click="checkAuth($event, 'nickname')"/>
</u-form-item>
<u-form-item :label="t('mobile')" prop="mobile" :border-bottom="true" v-if="isBindMobile">
<u-form-item :label="t('mobile')" prop="mobile" :border-bottom="true" v-if="isBindMobile || config.login.is_bind_mobile">
<input type="mobile" v-model="formData.mobile" :disabled="true" v-if="formData.mobile">
<template v-else>
<u-button v-if="info" :customStyle="{border:'none',color: 'var(--primary-color)',width:'140rpx', textAlign:'left',margin:'0rpx'}" :text="t('getMobile')" open-type="getPhoneNumber" @getphonenumber="memberStore.bindMobile"></u-button>

View File

@ -0,0 +1,355 @@
<template>
<view class="music-container" :class="{ playing: isPlaying }" :style="musicStyle">
<view class="music-control" :style="defaultStyleCss" @click="togglePlay">
<view class="music-disc " :class="{ rotate: isPlaying }">
<image v-if="discImage" class="disc-image" :src="discImage" mode="aspectFill"></image>
<block v-else>
<text class="default-style iconfont iconyinfuV6mm" v-if="isPlaying"></text>
<text class="default-style disable iconfont iconyinfuV6mm" v-else></text>
</block>
</view>
<view class="music-icon">
<text v-if="isPlaying" class="iconfont icon-pause"></text>
<text v-else class="iconfont icon-play"></text>
</view>
</view>
</view>
</template>
<script lang="ts" setup>
import { ref, watch, onMounted, onBeforeUnmount, computed } from 'vue';
import { img } from '@/utils/common';
//
const props = defineProps({
//
src: {
type: String,
default: ''
},
//
autoplay: {
type: Boolean,
default: true
},
//
loop: {
type: Boolean,
default: true
},
//
discImage: {
type: String,
default: ''
},
defaultBgColor: {
type: String,
default: '#B0B0B0'
},
defaultTextColor: {
type: String,
default: '#FFFFFF'
},
defaultRounded: {
type: Number,
default: 20
}
});
//
const defaultDiscImage = img('/addon/seckill/goods/music1.png');
const defaultDiscImage2 = img('/addon/seckill/goods/music2.png');
//
const isPlaying = ref(false);
//
let audioContext: any = null;
//
const createAudioContext = () => {
console.log('创建音频实例,音乐地址:', props.src);
// #ifdef MP-WEIXIN
audioContext = uni.createInnerAudioContext();
// #endif
// #ifdef APP-PLUS || H5
audioContext = uni.createInnerAudioContext();
// #endif
if (!audioContext) {
console.error('无法创建音频实例');
return;
}
audioContext.src = props.src;
audioContext.loop = props.loop;
//
audioContext.onPlay(() => {
console.log('音乐开始播放');
isPlaying.value = true;
});
//
audioContext.onPause(() => {
console.log('音乐暂停播放');
isPlaying.value = false;
});
//
audioContext.onStop(() => {
console.log('音乐停止播放');
isPlaying.value = false;
});
//
audioContext.onEnded(() => {
console.log('音乐播放结束');
isPlaying.value = false;
});
//
audioContext.onError((res: any) => {
console.error('音频播放错误:', res.errMsg || res);
isPlaying.value = false;
});
//
if (props.autoplay && props.src) {
// #ifdef H5
// H5
console.log('H5环境不自动播放音乐');
isPlaying.value = false;
// #endif
// #ifndef H5
// H5
console.log('准备自动播放音乐');
//
setTimeout(() => {
playMusic();
}, 300);
// #endif
}
};
const defaultStyleCss = computed(() => {
let style = '';
style += `background:${props.defaultBgColor};`;
if(props.defaultTextColor){ style += `color:${props.defaultTextColor};`; }
if(props.defaultRounded){
style += `border-border-top-left-radius:${props.defaultRounded * 2}rpx;`;
style += `border-border-bottom-left-radius:${props.defaultRounded * 2}rpx;`;
}
return style;
});
//
const playMusic = () => {
if (!audioContext || !props.src) {
console.error('无法播放音乐audioContext或src为空');
return;
}
console.log('尝试播放音乐:', props.src);
//
audioContext.play();
//
isPlaying.value = true;
//
// #ifdef MP-WEIXIN
try {
const systemInfo = uni.getSystemInfoSync();
if (systemInfo.platform === 'ios') {
// iOS
uni.showToast({
title: '音乐播放中...',
icon: 'none',
duration: 1000
});
}
} catch (error) {
console.error('获取系统信息失败:', error);
}
// #endif
};
//
const pauseMusic = () => {
if (!audioContext) return;
console.log('暂停音乐');
audioContext.pause();
isPlaying.value = false;
};
//
const togglePlay = () => {
console.log('切换播放状态,当前状态:', isPlaying.value);
if (isPlaying.value) {
pauseMusic();
} else {
playMusic();
}
};
//
watch(() => props.src, (newSrc) => {
console.log('音乐地址变化:', newSrc);
if (!audioContext) return;
const wasPlaying = isPlaying.value;
//
audioContext.src = newSrc;
//
if (wasPlaying && newSrc) {
playMusic();
}
});
//
watch(() => props.autoplay, (newAutoplay) => {
console.log('自动播放状态变化:', newAutoplay);
if (newAutoplay && audioContext && !isPlaying.value && props.src) {
playMusic();
}
});
//
onMounted(() => {
console.log('音乐组件挂载,初始化音频');
createAudioContext();
});
//
onBeforeUnmount(() => {
console.log('音乐组件卸载,释放资源');
if (audioContext) {
//
if (isPlaying.value) {
audioContext.stop();
}
//
audioContext.destroy();
audioContext = null;
}
});
const musicStyle = computed(() => {
return {
'--color': `${props.defaultTextColor}`
}
})
// 使
defineExpose({
play: playMusic,
pause: pauseMusic,
toggle: togglePlay,
isPlaying: () => isPlaying.value
});
</script>
<style lang="scss" scoped>
.music-container {
position: fixed;
right: 0;
top: calc(120rpx + var(--status-bar-height));
z-index: 999;
.music-control {
width: 80rpx;
height: 80rpx;
position: relative;
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(0, 0, 0, 0.5);
border-top-left-radius: 20rpx;
border-bottom-left-radius: 20rpx;
}
.music-disc {
transition: all 0.3s;
&.rotate {
animation: rotate 5s linear infinite;
animation-play-state: running;
}
.disc-image {
width: 60rpx;
height: 60rpx;
// background-color: #ffffff;
}
}
.music-icon {
position: absolute;
width: 80rpx;
height: 80rpx;
display: flex;
align-items: center;
justify-content: center;
.iconfont {
font-size: 40rpx;
color: #ffffff;
text-shadow: 0 0 5rpx rgba(0, 0, 0, 0.5);
}
}
}
@keyframes rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
/* 适配不同平台 */
/* #ifdef MP-WEIXIN */
.music-container {
z-index: 900;
}
/* #endif */
/* #ifdef APP-PLUS */
.music-container {
z-index: 999;
}
/* #endif */
/* #ifdef H5 */
.music-container {
position: fixed;
z-index: 999;
}
/* #endif */
.default-style{
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 60rpx;
height: 60rpx;
font-size: 34rpx;
box-sizing: border-box;
&.disable:after{
content: '';
position: absolute;
left: 0;
height: 50rpx;
width: 2rpx;
background: var(--color);
left: 50%;
transform: translateX(-50%) rotate(-45deg);
}
}
</style>

View File

@ -0,0 +1,69 @@
<template>
<view @touchmove.prevent.stop>
<u-popup class="popup-type" mode="center" :show="servicesDataShow" @close="servicesDataShow = false" bgColor="transparent" overlayOpacity="0.8">
<view @touchmove.prevent.stop class="flex flex-colitems-center">
<view class="bg-[#ffff] rounded-[34rpx]">
<view class="text-center text-[30rpx] mt-[40rpx] mb-[40rpx]">联系在线客服</view>
<scroll-view scroll-y="true" class="w-[570rpx] pb-[60rpx] max-h-[580rpx] overflow-y-auto">
<view class="flex flex-col items-center justify-center px-[30rpx]" v-if="data.customer_phone">
<text class="text-[45rpx]">{{ data.customer_phone }}</text>
<view class="rounded-[30rpx] mt-[30rpx] bg-[#EF000C] text-[#fff] h-[60rpx] leading-[60rpx] w-[240rpx] text-center text-[24rpx]" @click="makePhoneCallFn(data.customer_phone)">一键拨打</view>
</view>
<view v-if="data.customer_phone" class="w-full h-[1rpx] bg-dashed-style my-[40rpx]"></view>
<view class="px-[24rpx] flex flex-col items-center justify-center" v-if="data.customer_qrcode">
<view class="border border-[#eee] border-solid rounded-[10rpx] border-[1rpx] w-[240rpx] h-[240rpx] flex items-center justify-center">
<image class="w-[226rpx] h-[226rpx]" :src="img(data.customer_qrcode)" mode="widthFix" />
</view>
<view class="text-[26rpx] text-[#333] mt-[20rpx]">扫描二维码添加客服</view>
</view>
<view class="px-[50rpx] mt-[16rpx] text-[22rpx] text-[#999] leading-[1.5]" style="text-indent: 2em;">{{ data.customer_guided_words }}</view>
</scroll-view>
</view>
<!-- <view @click="servicesDataShow = false" class="mt-[50rpx] nc-iconfont nc-icon-cuohaoV6xx1 !text-[50rpx] text-[#fff]"></view> -->
</view>
</u-popup>
</view>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue';
import { redirect, img } from '@/utils/common'
const props = defineProps({
data: {
type: Object,
default: {}
}
})
const servicesDataShow = ref<boolean>(false)
const data = computed(() => {
return props.data;
})
const open = () => {
servicesDataShow.value = true;
}
const makePhoneCallFn = (data: any)=>{
uni.makePhoneCall({
phoneNumber: data,
success: (res) => {
},
fail: (res) => {
}
});
}
defineExpose({
open
})
</script>
<style scoped lang="scss">
.bg-dashed-style {
background: linear-gradient(to right, #eee 60%, transparent 40%);
background-size: 24rpx 100%; /* 控制线段长度20rpx和间隔 */
background-repeat: repeat-x;
}
</style>

View File

@ -1,7 +1,7 @@
<template>
<!-- 分享弹窗 -->
<view @touchmove.prevent.stop class="share-popup">
<u-popup :show="sharePopupShow" type="bottom" @close="sharePopupClose" overlayOpacity="0.8">
<u-popup :show="sharePopupShow" @close="sharePopupClose" overlayOpacity="0.8">
<view @touchmove.prevent.stop>
<view class="poster-img-wrap" :style="{'top': shareTop}">
<image v-if="isPosterAnimation" class="poster-animation" :src="img('addon/shop/poster_animation.gif')" mode="aspectFit"/>
@ -61,7 +61,7 @@ import useSystemStore from "@/stores/system";
const props = defineProps({
posterId: {
type: String || Number,
type: [String, Number],
default: 0
},
posterType: {
@ -79,6 +79,10 @@ const props = defineProps({
copyUrlParam: {
type: String,
default: ''
},
isPreload: {
type: Boolean,
default: true
}
})
@ -117,7 +121,7 @@ const isPosterImg = ref(false)
//
const poster = ref('');
const loadPoster = () => {
if (poster.value) {
if (poster.value && props.isPreload) {
//
isPosterAnimation.value = false;
isPosterImg.value = true;
@ -222,9 +226,10 @@ defineExpose({
</script>
<style lang="scss" scoped>
.share-popup {
:deep(.u-transition), :deep(.u-popup__content) {
background-color: transparent;
}
//
// :deep(.u-transition), :deep(.u-popup__content) {
// background-color: transparent;
// }
.share-content {
border-top-left-radius: 40rpx;

View File

@ -17,7 +17,7 @@
</view>
<view v-if="topStatusBarData.style == 'style-3'" :style="navbarInnerStyle" class="content-wrap">
<view class="back-wrap -ml-[16rpx] text-[26px] nc-iconfont nc-icon-zuoV6xx" :style="{ color: titleTextColor }" @tap="goBack" :class="{'!text-transparent': !isBackShow}"></view>
<view v-if="isBackShow" class="back-wrap -ml-[16rpx] text-[26px] nc-iconfont nc-icon-zuoV6xx" :style="{ color: titleTextColor }" @tap="goBack" :class="{'!text-transparent': !isBackShow}"></view>
<view class="title-wrap" @click="diyStore.toRedirect(topStatusBarData.link)">
<image :src="img(topStatusBarData.imgUrl)" mode="heightFix"/>
</view>

View File

@ -202,7 +202,7 @@ export function useDiy(params: any = {}) {
if (e.scrollTop > 0) {
diyStore.scrollTop = e.scrollTop;
}
uni.$emit('scroll')
// uni.$emit('scroll')
})
}

View File

@ -140,6 +140,7 @@ export function useDiyForm(params: any = {}) {
if (requestData.value) {
diyData.pageMode = requestData.mode;
diyData.title = requestData.title;
diyData.type = requestData.type;
diyStore.id = requestData.form_id;
let sources = requestData.value;

View File

@ -22,13 +22,14 @@ export function useLogin() {
const systemStore = useSystemStore()
// #ifdef MP-WEIXIN
if (!uni.getStorageSync('autoLoginLock') && uni.getStorageSync('openid') && config.login.is_bind_mobile) {
if (!uni.getStorageSync('autoLoginLock') && config.login.is_bind_mobile) {
uni.setStorageSync('isBindMobile', true) // 强制绑定手机号标识
}
// #endif
// #ifdef H5
if (!uni.getStorageSync('autoLoginLock') && isWeixinBrowser() && uni.getStorageSync('openid') && config.login.is_bind_mobile) {
if (!uni.getStorageSync('autoLoginLock') && isWeixinBrowser() && config.login.is_bind_mobile) {
uni.setStorageSync('isBindMobile', true) // 强制绑定手机号标识
}
// #endif
@ -213,7 +214,7 @@ export function useLogin() {
})
}
}).catch((err) => {
if (err.msg == -1) {
if (err.code == -1) {
getAuthCode({ scopes: 'snsapi_userinfo' })
} else {
uni.showToast({ title: err.msg, icon: 'none' })

View File

@ -40,6 +40,7 @@ export const useShare = () => {
}
const setShare = (options: any = {}) => {
console.log('setShare options',options)
if (currRoute() == '' || currRoute().indexOf('app/pages/index/close') != -1 || currRoute().indexOf('app/pages/index/nosite') != -1) return;
let queryStr = getQuery();
@ -60,10 +61,9 @@ export const useShare = () => {
query: queryStr.join('&'),
}
// #endif
if (options && Object.keys(options).length) {
if (options.wechat) {
// #ifdef H5
wechatOptions.title = options.wechat.title || ''
wechatOptions.link = options.wechat.link || h5Link
@ -89,37 +89,38 @@ export const useShare = () => {
}
getShareInfo({
route: '/' + currRoute(),
params: JSON.stringify(currShareRoute().params)
}).then((res: any) => {
route: '/' + currRoute(),
params: JSON.stringify(currShareRoute().params)
}).then((res: any) => {
let data = res.data;
let data = res.data;
// #ifdef H5
let wechat = data.wechat;
if (wechat) {
wechatOptions.title = wechat.title
wechatOptions.desc = wechat.desc
wechatOptions.imgUrl = wechat.url ? img(wechat.url) : ''
} else {
wechatOptions.title = document.title;
wechatOptions.desc = ''
}
wechatShare()
// #endif
// #ifdef MP-WEIXIN
let weapp = data.weapp;
if (weapp) {
weappOptions.title = weapp.title
weappOptions.imageUrl = weapp.url ? img(weapp.url) : ''
}
// #endif
if(!weappOptions.title && !weappOptions.imageUrl){
return;
}
uni.setStorageSync('weappOptions', weappOptions)
})
// #ifdef H5
let wechat = data.wechat;
if (wechat) {
wechatOptions.title = wechat.title
wechatOptions.desc = wechat.desc
wechatOptions.imgUrl = wechat.url ? img(wechat.url) : ''
} else {
wechatOptions.title = document.title;
wechatOptions.desc = ''
}
wechatShare()
// #endif
// #ifdef MP-WEIXIN
let weapp = data.weapp;
if (weapp) {
weappOptions.title = weapp.title
weappOptions.imageUrl = weapp.url ? img(weapp.url) : ''
}
// #endif
if(!weappOptions.title && !weappOptions.imageUrl){
return;
}
uni.setStorageSync('weappOptions', weappOptions)
})
}
// 小程序分享,分享给好友
@ -149,10 +150,41 @@ export const useShare = () => {
})
}
// 禁用当前页面的分享功能(同时支持小程序和公众号)
const disableShare = () => {
// 公众号H5禁用分享
// #ifdef H5
if (isWeixinBrowser()) {
// 确保SDK初始化后再禁用
wechat.init(() => {
wechat.disableShare();
});
}
// #endif
// 小程序禁用分享
// #ifdef MP-WEIXIN
// 隐藏分享菜单(转发给朋友、朋友圈)
uni.hideShareMenu({
menus: ['shareAppMessage', 'shareTimeline'],
success: () => {
console.log('小程序分享已禁用');
},
fail: (err) => {
console.error('小程序禁用分享失败:', err);
}
});
// 覆盖分享方法,返回空对象
onShareAppMessage(() => ({}));
onShareTimeline(() => ({}));
// #endif
};
return {
wechatInit: wechatInit,
setShare: setShare,
onShareAppMessage: shareApp,
onShareTimeline: shareTime,
disableShare: disableShare,
}
}

View File

@ -1,41 +0,0 @@
.account-info-wrap{
@apply bg-[#F5F6FA] min-h-[100vh];
.account-info-head{
@apply relative h-40;
.name{
@apply ml-4 pt-7 text-white text-lg mb-3;
}
.content{
@apply absolute bg-white left-3 right-3 rounded-lg p-5;
.money{
@apply text-xl font-bold;
}
.text{
@apply text-xs text-slate-500 mt-2;
}
.money-wrap{
@apply mt-5 flex;
.money-item{
@apply flex-1;
}
.money{
@apply text-lg;
}
.text{
@apply mt-1;
}
}
}
}
.account-info-btn{
@apply flex mt-24 ml-3 mr-3;
.btn{
&:first-of-type{
@apply mr-1 rounded;
}
&:last-of-type{
@apply ml-1 rounded;
}
}
}
}

View File

@ -552,4 +552,18 @@ button[type='primary'],uni-button[type='primary']{
}
.information-filling .u-line{
border-color: #dddddd !important;
}
.order-grey-hollow-btn{
border: 2rpx solid #ccc;
height: 56rpx;
font-size: 24rpx;
background-color: #fff;
border-radius: 30rpx;
display: flex;
justify-content: center;
align-items: center;
box-sizing: border-box;
padding: 0 24rpx;
min-width: 144rpx;
color: #333;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +0,0 @@
page{
background-color: #f5f6fa;
@apply pt-4;
}
.member-record-detail{
@apply m-4 mt-0 bg-white rounded-md px-4 py-6;
.money-wrap{
@apply flex items-center flex-col mb-6;
text:first-of-type{
@apply text-3xl font-bold mt-1;
}
text:last-of-type{
@apply text-sm mt-3;
}
}
.line-wrap{
@apply flex justify-between text-sm mt-3;
.label{
@apply text-[#878787];
}
.value{
@apply text-[#222];
}
}
}

View File

@ -1,21 +0,0 @@
.member-record-list{
@apply min-h-[100vh];
.member-record-item{
@apply relative sidebar-margin border-solid border-t-0 border-l-0 border-r-0 border-b-1 border-[#ECEBEC] py-3 mx-[var(--sidebar-m)];
.name{
@apply text-sm;
}
.desc{
@apply text-xs text-[#8D8C8D] mt-1;
}
.text-active{
color: #FF0D3E;
}
.money{
@apply absolute right-0 top-4 text-base font-bold;
}
.state{
@apply absolute right-0 top-11 text-[#8D8C8D] text-xs;
}
}
}

View File

@ -401,53 +401,132 @@ export function timeStampTurnTime(timeStamp: any, type = "") {
* @param dateStr
*/
export function timeTurnTimeStamp(dateStr: string) {
let timestamp;
let date;
// 输入验证
if (!dateStr || typeof dateStr !== 'string' || dateStr.trim() === '') {
return null;
}
// 尝试解析 'YYYY年M月D日'
try {
let dateStr1 = dateStr.replace('年', '-').replace('月', '-').replace('日', '');
date = new Date(dateStr1);
timestamp = date.getTime();
} catch (e) {
// 尝试解析 'YYYY-MM-DD'
try {
date = new Date(dateStr);
timestamp = date.getTime();
} catch (e) {
// 尝试解析 'YYYY/MM/DD'
try {
date = new Date(dateStr.replace(/\//g, "-"));
timestamp = date.getTime();
} catch (e) {
// 尝试解析 'YYYY年M月D日 HH时mm分'
try {
let dateStr1 = dateStr.replace('年', '-').replace('月', '-').replace('日', ' ').replace('时', ':').replace('分', '');
date = new Date(dateStr1);
timestamp = date.getTime();
} catch (e) {
// 尝试解析 'YYYY-MM-DD HH:mm'
try {
date = new Date(dateStr);
timestamp = date.getTime();
} catch (e) {
// 尝试解析 'YYYY/MM/DD HH:mm'
try {
date = new Date(dateStr.replace(/\//g, "-"));
timestamp = date.getTime();
} catch (e) {
// 如果所有格式都失败返回null
console.error("无法解析日期字符串:", dateStr);
return null;
}
}
}
}
const trimmedDateStr = dateStr.trim();
// 定义支持的日期格式转换规则
const formatRules = [
// 'YYYY年M月D日' -> 'YYYY-MM-DD'
{
pattern: /(\d{4})年(\d{1,2})月(\d{1,2})日/,
transform: (str: string) => str.replace(/(\d{4})年(\d{1,2})月(\d{1,2})日/, '$1-$2-$3')
},
// 'YYYY年M月D日 HH时mm分' -> 'YYYY-MM-DD HH:mm'
{
pattern: /(\d{4})年(\d{1,2})月(\d{1,2})日\s+(\d{1,2})时(\d{1,2})分/,
transform: (str: string) => str.replace(/(\d{4})年(\d{1,2})月(\d{1,2})日\s+(\d{1,2})时(\d{1,2})分/, '$1-$2-$3 $4:$5')
},
// 'YYYY/MM/DD' -> 'YYYY-MM-DD'
{
pattern: /^\d{4}\/\d{1,2}\/\d{1,2}(\s+\d{1,2}:\d{1,2}(:\d{1,2})?)?$/,
transform: (str: string) => str.replace(/\//g, '-')
},
// 标准格式,无需转换
{
pattern: /^\d{4}-\d{1,2}-\d{1,2}(\s+\d{1,2}:\d{1,2}(:\d{1,2})?)?$/,
transform: (str: string) => str
}
];
// 尝试匹配并转换格式
let normalizedDateStr = null;
for (const rule of formatRules) {
if (rule.pattern.test(trimmedDateStr)) {
normalizedDateStr = rule.transform(trimmedDateStr);
break;
}
}
return (timestamp / 1000);
// 如果没有匹配的格式,直接尝试原始字符串
if (!normalizedDateStr) {
normalizedDateStr = trimmedDateStr;
}
// 创建日期对象并验证
const date = new Date(normalizedDateStr);
// 检查日期是否有效
if (isNaN(date.getTime())) {
return null;
}
// 返回秒级时间戳
return Math.floor(date.getTime() / 1000);
}
/**
* ( iOS)
* @param dateStr
*/
export function timeTurnTimeStampTwo(dateStr: string) {
if (!dateStr || typeof dateStr !== 'string' || dateStr.trim() === '') {
return null;
}
let trimmedDateStr = dateStr.trim();
// 定义支持的日期格式转换规则
const formatRules = [
// 'YYYY年M月D日'
{
pattern: /(\d{4})年(\d{1,2})月(\d{1,2})日/,
transform: (str: string) =>
str.replace(/(\d{4})年(\d{1,2})月(\d{1,2})日/, '$1/$2/$3'),
},
// 'YYYY年M月D日 HH时mm分'
{
pattern: /(\d{4})年(\d{1,2})月(\d{1,2})日\s+(\d{1,2})时(\d{1,2})分/,
transform: (str: string) =>
str.replace(
/(\d{4})年(\d{1,2})月(\d{1,2})日\s+(\d{1,2})时(\d{1,2})分/,
'$1/$2/$3 $4:$5'
),
},
// 'YYYY-MM-DD HH:mm:ss' -> 'YYYY/MM/DD HH:mm:ss' (iOS兼容)
{
pattern: /^\d{4}-\d{1,2}-\d{1,2}\s+\d{1,2}:\d{1,2}(:\d{1,2})?$/,
transform: (str: string) => str.replace(/-/g, '/'),
},
// 'YYYY-MM-DD' -> 'YYYY/MM/DD' (iOS兼容)
{
pattern: /^\d{4}-\d{1,2}-\d{1,2}$/,
transform: (str: string) => str.replace(/-/g, '/'),
},
// 'YYYY/MM/DD' / 'YYYY/MM/DD HH:mm:ss'
{
pattern: /^\d{4}\/\d{1,2}\/\d{1,2}(\s+\d{1,2}:\d{1,2}(:\d{1,2})?)?$/,
transform: (str: string) => str,
},
];
// 尝试匹配并转换
let normalizedDateStr: string | null = null;
for (const rule of formatRules) {
if (rule.pattern.test(trimmedDateStr)) {
normalizedDateStr = rule.transform(trimmedDateStr);
break;
}
}
if (!normalizedDateStr) {
normalizedDateStr = trimmedDateStr;
}
// 创建日期对象
const date = new Date(normalizedDateStr);
if (isNaN(date.getTime())) {
return null;
}
return Math.floor(date.getTime() / 1000);
}
/**
*
* @param {Object} value

View File

@ -97,6 +97,7 @@ const loadShare = () => {
// 分享其它页面时,需要设置当前页面为白名单
const shareWhiteList = [
'addon/cms/pages/detail',
'addon/seckill/pages/goods/detail',
'addon/shop/pages/goods/detail',
'addon/shop/pages/point/detail',
'addon/shop_fenxiao/pages/promote_code',

View File

@ -24,7 +24,7 @@ class Wechat {
timestamp: data.timestamp, // 必填,生成签名的时间戳
nonceStr: data.nonceStr, // 必填,生成签名的随机串
signature: data.signature,// 必填,签名
jsApiList: ['chooseWXPay', 'updateAppMessageShareData', 'updateTimelineShareData', 'scanQRCode', 'getLocation'] // 必填需要使用的JS接口列表
jsApiList: ['chooseWXPay', 'updateAppMessageShareData', 'updateTimelineShareData', 'scanQRCode', 'getLocation','hideMenuItems'] // 必填需要使用的JS接口列表
});
if (callback) callback();
})
@ -138,6 +138,52 @@ class Wechat {
})
// #endif
}
/**
*
*/
public disableShare() {
// 公众号H5禁用分享
// #ifdef H5
if (isWeixinBrowser()) {
wx.ready(() => {
// 先检查是否有权限
wx.checkJsApi({
jsApiList: ['hideMenuItems'],
success: (res) => {
// 若有权限,执行隐藏
if (res.checkResult.hideMenuItems) {
wx.hideMenuItems({
menuList: [
"menuItem:share:appMessage",
"menuItem:share:timeline",
"menuItem:share:qq",
"menuItem:share:QZone",
"menuItem:share:weiboApp",
"menuItem:favorite"
],
success: () => console.log("公众号分享已禁用"),
fail: (err) => console.error("隐藏菜单失败:", err)
});
} else {
console.warn("无hideMenuItems权限无法禁用分享");
}
},
fail: (err) => console.error("检查权限失败:", err)
});
});
}
// #endif
// 小程序禁用分享
// #ifdef MP-WEIXIN
wx.hideShareMenu({
menus: ['shareAppMessage', 'shareTimeline'], // 隐藏转发给朋友、朋友圈
success: () => console.log("小程序分享已禁用"),
fail: (err) => console.error("小程序禁用分享失败:", err)
});
// #endif
}
}
export default new Wechat()