feat: 九宫格基础结构

This commit is contained in:
2025-08-13 09:20:29 +08:00
parent 3c200051e6
commit c507d7397f
5 changed files with 501 additions and 475 deletions
-475
View File
@@ -1,475 +0,0 @@
{
"easycom": {
"autoscan": true,
// 注意一定要放在custom里,否则无效,https://ask.dcloud.net.cn/question/131175
"custom": {
"^u--(.*)": "@/uni_modules/uview-plus/components/u-$1/u-$1.vue",
"^up-(.*)": "@/uni_modules/uview-plus/components/u-$1/u-$1.vue",
"^u-([^-].*)": "@/uni_modules/uview-plus/components/u-$1/u-$1.vue"
}
},
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/home/home",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "%index.title%",
"navigationStyle": "custom"
}
},
{
"path": "pages/sort/sort",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/hash_union/hash_union",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/shopping_cart/shopping_cart",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine/mine",
"style": {
"navigationStyle": "custom"
}
}, {
"path": "pages/mine_bank_card/mine_bank_card",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_bank_add/mine_bank_add",
"style": {
"navigationBarTitleText": "%bankCard.add.title%",
"navigationBarBackgroundColor": "#FFFFFF",
"navigationBarTextStyle": "black",
"enablePullDownRefresh": false,
"navigationStyle": "default" // 默认样式,会显示返回图标
}
},
{
"path": "pages/mine_address/mine_address",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_address_add/mine_address_add",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_authentication/mine_authentication",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_authentication_ok/mine_authentication_ok",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_purse/mine_purse",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_order/mine_order",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_order_info/mine_order_info",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_purse_bonus/mine_purse_bonus",
"style": {
"navigationBarTitleText": "%purse.bonus.title%",
"navigationBarBackgroundColor": "#03AD27",
"navigationBarTextStyle": "white",
"enablePullDownRefresh": false,
"navigationStyle": "default" // 默认样式,会显示返回图标
}
},
{
"path": "pages/login/login",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/register/register",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/turntable/turntable",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/search/search",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/preference/preference",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/welcome/welcome",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/invite_friends/invite_friends",
"style": {
"navigationBarTitleText": "%invite.friends.title%",
"navigationBarBackgroundColor": "#FFFFFF",
"navigationBarTextStyle": "black",
"enablePullDownRefresh": false,
"navigationStyle": "default" // 默认样式,会显示返回图标
}
},
{
"path": "pages/productInfo/productInfo",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/order_submit/order_submit",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/order_submit_ok/order_submit_ok",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/LuckyWheel/LuckyWheel",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mine_winning_record/mine_winning_record",
"style": {
"navigationBarTitleText": "%mine.winning.record.title%",
"navigationBarBackgroundColor": "#F5F5F5",
"navigationBarTextStyle": "black",
"enablePullDownRefresh": false,
"navigationStyle": "default" // 默认样式,会显示返回图标
}
},
{
"path": "pages/merchant_settlement/merchant_settlement",
"style": {
"navigationBarTitleText": "%mine.merchant.settlement.title%",
"navigationBarBackgroundColor": "#FFFFFF",
"navigationBarTextStyle": "black",
"enablePullDownRefresh": false,
"navigationStyle": "default" // 默认样式,会显示返回图标
}
},
{
"path": "pages/brand_settlement/brand_settlement",
"style": {
"navigationBarTitleText": "%mine.brand.settlement.title%",
"navigationBarBackgroundColor": "#FFFFFF",
"navigationBarTextStyle": "black",
"enablePullDownRefresh": false,
"navigationStyle": "default" // 默认样式,会显示返回图标
}
},
{
"path": "pages/accelerate/accelerate",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_my_team/mine_my_team",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_coupon/mine_coupon",
"style": {
"navigationBarTitleText": "%mine.coupon.title%",
"navigationBarBackgroundColor": "#FFFFFF",
"navigationBarTextStyle": "black",
"enablePullDownRefresh": false,
"navigationStyle": "default" // 默认样式,会显示返回图标
}
},
{
"path": "pages/order_submit_error/order_submit_error",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/get_prize/get_prize",
"style": {
"navigationBarTitleText": "%mine.get.prize%",
"navigationBarBackgroundColor": "#FFFFFF",
"navigationBarTextStyle": "black",
"enablePullDownRefresh": false,
"navigationStyle": "default" // 默认样式,会显示返回图标
}
},
{
"path": "pages/mine_my_team_list/mine_my_team_list",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_purse_bonus_withdraw/mine_purse_bonus_withdraw",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_purse_bonus_withdraw_log/mine_purse_bonus_withdraw_log",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_settings/mine_settings",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_about_us/mine_about_us",
"style": {
"navigationBarTitleText": "%mine.about.us.title%",
"navigationBarBackgroundColor": "#FFFFFF",
"navigationBarTextStyle": "black",
"enablePullDownRefresh": false,
"navigationStyle": "default" // 默认样式,会显示返回图标
}
},
{
"path": "pages/mine_privacy_agreement/mine_privacy_agreement",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_user_agreement/mine_user_agreement",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_collection_alipay/mine_collection_alipay",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mine_purse_log/mine_purse_log",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_purse_recharge/mine_purse_recharge",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mine_purse_exchange/mine_purse_exchange",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/mine_product_agreement/mine_product_agreement",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/zfb_payment/zfb_payment",
"style": {
"navigationBarTitleText": "支付",
"navigationBarBackgroundColor": "#FFFFFF",
"navigationBarTextStyle": "black",
"enablePullDownRefresh": false,
"navigationStyle": "default" // 默认样式,会显示返回图标
}
},
{
"path": "pages/payment_processing/payment_processing",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/news/news",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/news_info/news_info",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/pointsRedemption/pointsRedemption",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/supply_chain/supply_chain",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/merchant_settlement_ok/merchant_settlement_ok",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/finance/finance",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/customized_zone/customized_zone",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/rwa/rwa",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/rwa_add/rwa_add",
"style": {
"navigationStyle": "custom"
}
}, {
"path": "pages/rwa_binding/rwa_binding",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/rwa_withdrawal/rwa_withdrawal",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/rwa_withdrawal_log/rwa_withdrawal_log",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/mine_transaction_password/mine_transaction_password",
"style": {
"navigationBarTitleText": ""
}
}
],
"tabBar": {
// "color": "#000000",
// "selectedColor": "#03AD27",
// "borderStyle": "black",
// "backgroundColor": "#F8F8F8",
"custom": true,
"list": [{
"pagePath": "pages/home/home",
"text": "%index.home%",
"iconPath": "/static/column/home.png",
"selectedIconPath": "/static/column/home_sel.png"
},
{
"pagePath": "pages/sort/sort",
"text": "%index.sort%",
"iconPath": "/static/column/sort.png",
"selectedIconPath": "/static/column/sort_sel.png"
},
// {
// "pagePath": "pages/hash_union/hash_union",
// "text": "%index.hash.union%",
// "iconPath": "/static/column/hx.png",
// "selectedIconPath": "/static/column/hx_sel.png"
// },
{
"pagePath": "pages/supply_chain/supply_chain",
"text": "供应链",
"iconPath": "/static/column/supply_chain.png",
"selectedIconPath": "/static/column/supply_chain_sel.png"
},
{
"pagePath": "pages/shopping_cart/shopping_cart",
"text": "%index.shopping.cart%",
"iconPath": "/static/column/shopping.png",
"selectedIconPath": "/static/column/shopping_sel.png"
}, {
"pagePath": "pages/mine/mine",
"text": "%index.mine%",
"iconPath": "/static/column/mine.png",
"selectedIconPath": "/static/column/mine_sel.png"
}
]
},
"globalStyle": {
"navigationStyle": "custom",
"app-plus": {
"safearea": {
"bottom": "env(safe-area-inset-bottom)"
}
}
}
}
+5
View File
@@ -366,6 +366,11 @@
"style": {
"navigationStyle": "custom"
}
}, {
"path": "nine-grid/nine-grid",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "get_prize/get_prize",
@@ -0,0 +1,276 @@
<template>
<!-- 九宫格容器 -->
<view class="lottery-grid">
<!-- 高亮选中框 -->
<view class="highlight-box" :style="{
top: highlightTop,
left: highlightLeft,
transition: isRotating ? 'all 0.07s linear' : 'none'
}"></view>
<!-- 9个格子 -->
<view class="grid-item" v-for="(item, index) in 9" :key="index">
<!-- 中间格子作为抽奖按钮 (索引4) -->
<template v-if="index === 4">
<view class="lottery-btn" @click="handleStartClick">
<text>{{ isRotating ? '抽奖中...' : '开始抽奖' }}</text>
</view>
</template>
<!-- 其他8个奖品格子 -->
<template v-else>
<image :src="prizes[index].img" class="prize-img" mode="widthFix"></image>
<text class="prize-name">{{ prizes[index].name }}</text>
</template>
</view>
</view>
</template>
<script>
export default {
props: {
// 奖品数据数组
prizes: {
type: Array,
required: true,
default: () => []
},
// 是否禁用抽奖
isDisabled: {
type: Boolean,
default: false
}
},
data() {
return {
isRotating: false, // 是否正在旋转
highlightTop: '0rpx', // 高亮框顶部位置
highlightLeft: '0rpx', // 高亮框左侧位置
// 抽奖配置常量
LOTTERY_PATH: [0, 1, 2, 5, 8, 7, 6, 3], // 抽奖路径顺序(顺时针)
INITIAL_SPEED: 100, // 初始速度(ms) - 调慢以便观察
MAX_STEPS: 50, // 最大步数,防止无限循环
ACCELERATE_STEPS: 5, // 加速步数
SPEED_DECREMENT: 10, // 加速时的速度减少量
SPEED_INCREMENT: 15, // 减速时的速度增加量
MIN_SPEED: 50, // 最小速度
STOP_SPEED: 250, // 停止时的速度阈值
animationTimer: null // 动画计时器
}
},
methods: {
/**
* 移动高亮框到指定索引位置
* @param {number} index - 格子索引
*/
moveHighlight(index) {
const row = Math.floor(index / 3) // 计算行
const col = index % 3 // 计算列
this.highlightTop = `${row * 200}rpx`
this.highlightLeft = `${col * 200}rpx`
},
/**
* 执行抽奖动画
* @param {Object} options - 动画参数
*/
runAnimation(options) {
const { currentStep, speed, targetStep, cycleCount, totalSteps } = options
// 清除之前的计时器
if (this.animationTimer) {
clearTimeout(this.animationTimer)
}
// 计算下一步
const nextStep = (currentStep + 1) % this.LOTTERY_PATH.length
const nextTotalSteps = totalSteps + 1
let nextCycleCount = cycleCount
let nextSpeed = speed
// 计算循环次数
if (nextStep === 0) {
nextCycleCount++
}
// 速度控制逻辑
if (nextCycleCount < 1 && nextTotalSteps < this.ACCELERATE_STEPS) {
// 加速阶段
nextSpeed = Math.max(this.MIN_SPEED, nextSpeed - this.SPEED_DECREMENT)
} else {
// 减速阶段
nextSpeed += this.SPEED_INCREMENT
}
// 移动高亮框到当前步骤位置
this.moveHighlight(this.LOTTERY_PATH[nextStep])
// 检查是否应该停止
const shouldStop =
(nextSpeed > this.STOP_SPEED && nextStep === targetStep) || nextTotalSteps > this.MAX_STEPS
if (shouldStop) {
// 动画结束
this.isRotating = false
this.animationTimer = null
// 触发抽奖完成事件,返回中奖奖品
this.$emit('complete', this.prizes[this.LOTTERY_PATH[nextStep]])
return
}
// 继续下一帧动画
this.animationTimer = setTimeout(() => {
this.runAnimation({
currentStep: nextStep,
speed: nextSpeed,
targetStep,
cycleCount: nextCycleCount,
totalSteps: nextTotalSteps
})
}, nextSpeed)
},
/**
* 随机生成目标位置(带权重)
* @returns {number} 目标位置索引
*/
getRandomTarget() {
// 奖品权重配置,数值越高概率越大
const weights = [2, 2, 1, 0.5, 2, 1, 3, 2]
const total = weights.reduce((sum, w) => sum + w, 0) // 计算总权重
let random = Math.random() * total // 生成随机数
// 根据权重计算目标位置
for (let i = 0; i < weights.length; i++) {
random -= weights[i]
if (random <= 0) return i
}
// 兜底:随机返回一个位置
return Math.floor(Math.random() * this.LOTTERY_PATH.length)
},
/**
* 处理开始抽奖点击事件
*/
handleStartClick() {
// 如果正在抽奖或被禁用,则不执行
if (this.isDisabled || this.isRotating) {
console.log('抽奖被禁用或正在进行中')
return
}
// 通知父组件开始抽奖
this.$emit('start')
// 开始抽奖动画(无论父组件做了什么处理)
this.startLotteryAnimation()
},
/**
* 开始抽奖动画
*/
startLotteryAnimation() {
// 重置动画参数
clearTimeout(this.animationTimer)
// 标记为正在抽奖
this.isRotating = true
// 开始动画
this.runAnimation({
currentStep: 0,
speed: this.INITIAL_SPEED,
targetStep: this.getRandomTarget(),
cycleCount: 0,
totalSteps: 0
})
}
},
beforeDestroy() {
// 组件销毁时清理计时器
if (this.animationTimer) {
clearTimeout(this.animationTimer)
this.animationTimer = null
}
}
}
</script>
<style scoped>
.lottery-grid {
width: 600rpx;
height: 600rpx;
display: flex;
flex-wrap: wrap;
position: relative;
border: 8rpx solid #ffc107;
border-radius: 16rpx;
background-color: #fff;
box-sizing: content-box;
margin: 0 auto;
}
.grid-item {
width: 200rpx;
height: 200rpx;
box-sizing: border-box;
border: 2rpx solid #ffeeba;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
flex-shrink: 0;
}
.lottery-btn {
width: 180rpx;
height: 180rpx;
background: linear-gradient(135deg, #ff5252 0%, #e63946 100%);
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 6rpx 12rpx rgba(230, 57, 70, 0.3);
/* 增加点击反馈 */
transition: transform 0.2s;
}
.lottery-btn:active {
transform: scale(0.95);
}
.lottery-btn text {
color: #fff;
font-size: 32rpx;
font-weight: bold;
text-align: center;
padding: 0 10rpx;
}
.prize-img {
width: 100rpx;
height: 100rpx;
margin-bottom: 10rpx;
}
.prize-name {
font-size: 26rpx;
color: #333;
text-align: center;
padding: 0 10rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.highlight-box {
position: absolute;
width: 200rpx;
height: 200rpx;
box-sizing: border-box;
border: 6rpx solid #ff4081;
background-color: rgba(255, 64, 129, 0.1);
z-index: 1;
pointer-events: none;
/* 增加高亮动画效果 */
box-shadow: 0 0 15rpx 2rpx rgba(255, 64, 129, 0.5);
}
</style>
@@ -0,0 +1,104 @@
<template>
<!-- 中奖结果弹窗 -->
<view class="result-modal" v-if="visible">
<view class="modal-content">
<text class="result-title">恭喜您获得</text>
<image :src="prize.img" class="result-img" mode="widthFix" :alt="prize.name || '奖品图片'"></image>
<text class="result-desc">{{ prize.name || '未知奖品' }}</text>
<button class="confirm-btn" @click="$emit('close')">确定</button>
</view>
</view>
</template>
<script>
export default {
props: {
// 是否显示弹窗
visible: {
type: Boolean,
default: false
},
// 中奖奖品信息
prize: {
type: Object,
default: () => ({})
}
}
}
</script>
<style scoped>
.result-modal {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 999;
}
.modal-content {
width: 500rpx;
background-color: #fff;
border-radius: 20rpx;
padding: 40rpx;
display: flex;
flex-direction: column;
align-items: center;
/* 添加弹窗动画 */
animation: popup 0.3s ease-out;
}
@keyframes popup {
0% {
transform: scale(0.8);
opacity: 0;
}
100% {
transform: scale(1);
opacity: 1;
}
}
.result-title {
font-size: 36rpx;
color: #e63946;
font-weight: bold;
margin-bottom: 30rpx;
}
.result-img {
width: 150rpx;
height: 150rpx;
margin-bottom: 30rpx;
object-fit: contain;
}
.result-desc {
font-size: 32rpx;
color: #333;
margin-bottom: 40rpx;
font-weight: bold;
}
.confirm-btn {
width: 300rpx;
height: 80rpx;
line-height: 80rpx;
background-color: #e63946;
color: #fff;
border-radius: 40rpx;
font-size: 32rpx;
border: none;
transition: background-color 0.2s;
}
.confirm-btn:active {
background-color: #c72c3a;
}
</style>
+116
View File
@@ -0,0 +1,116 @@
<template>
<view class="lottery-page">
<view class="lottery-title">幸运九宫格抽奖</view>
<view class="remain-count"> 剩余抽奖次数: {{ remainCount }} </view>
<!-- 九宫格抽奖组件 -->
<LotteryGrid :prizes="prizes" :remain-count="remainCount" :is-disabled="isRotating" @start="handleStartLottery"
@complete="handleLotteryComplete" />
<!-- 中奖结果弹窗 -->
<ResultModal :visible="showResult" :prize="currentPrize" @close="showResult = false" />
</view>
</template>
<script>
import LotteryGrid from './components/LotteryGrid.vue'
import ResultModal from './components/ResultModal.vue'
import { getActivityList, raffleExecute } from '@/api/raffle.js';
export default {
components: {
LotteryGrid,
ResultModal
},
data() {
return {
// 奖品配置数据
prizes: [
{ name: '10元红包', img: 'https://image.whzb.com/chain/inte-cloud/inte-cloud-train/logo.png' },
{ name: '20积分', img: 'https://image.whzb.com/chain/inte-cloud/inte-cloud-train/teacher.png' },
{ name: '50元红包', img: 'https://image.whzb.com/chain/inte-cloud/inte-cloud-train/student.png' },
{ name: '谢谢参与', img: 'https://image.whzb.com/chain/inte-cloud/inte-cloud-train/recommend.png' },
{ name: '', img: '' }, // 中间按钮位置,不使用
{ name: '100积分', img: 'https://image.whzb.com/chain/inte-cloud/inte-cloud-train/uncollection.png' },
{ name: '2元红包', img: 'https://image.whzb.com/chain/inte-cloud/inte-cloud-train/p-mn.png' },
{ name: '50积分', img: 'https://image.whzb.com/chain/inte-cloud/inte-cloud-train/p-lx.png' },
{ name: '8元红包', img: 'https://image.whzb.com/chain/inte-cloud/inte-cloud-train/p-lx.png' }
],
// 状态管理
remainCount: 3, // 剩余抽奖次数
isRotating: false, // 是否正在抽奖
showResult: false, // 是否显示结果弹窗
currentPrize: {} // 当前中奖奖品
}
},
mounted() {
this.getActivityList();
},
methods: {
//
/**
* 查询活动详情
*/
async getActivityList() {
const { bizcode, data } = await getActivityList();
if (bizcode === 100) {
this.prizes = data.prizes || [];
this.prizes.split(4, 1, { iconUrl:'https://image.whzb.com/chain/inte-cloud/inte-cloud-train/p-lx.png',})
}
},
/**
* 处理开始抽奖事件
*/
handleStartLottery() {
if (this.remainCount <= 0) {
uni.showToast({ title: '没有抽奖次数了', icon: 'none' })
return false
}
// 减少抽奖次数并标记为正在抽奖
this.remainCount--
this.isRotating = true
this.showResult = false
return true
},
/**
* 处理抽奖完成事件
* @param {Object} prize - 中奖奖品
*/
handleLotteryComplete(prize) {
this.isRotating = false
this.currentPrize = prize
this.showResult = true
}
}
}
</script>
<style scoped>
.lottery-page {
display: flex;
flex-direction: column;
align-items: center;
padding: 30rpx;
background-color: #f8f9fa;
min-height: 100vh;
}
.lottery-title {
font-size: 40rpx;
font-weight: bold;
color: #e63946;
margin-bottom: 20rpx;
}
.remain-count {
font-size: 30rpx;
color: #666;
margin-bottom: 30rpx;
padding: 10rpx 20rpx;
background-color: #fff;
border-radius: 20rpx;
}
</style>