vue电影座位选座,最简单的写法没有之一

该代码段展示了一个使用Vue.js创建的座位选择界面,通过v-for指令遍历和渲染二维数组来生成座位图。根据seatList中的status属性显示不同状态的座位(可用、已选、已预订),并提供了点击座位进行状态切换的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

废话不多说,直接上代码,由于代码比较简单,不多做解析

<template>
    <div class="sm">
        <div class="sm-title"></div>
        <div class="sm-line"></div>
        <div style="display: flex; justify-content: center">
            <div>
                <div style="display: flex" v-for="(item1, index1) in seatList" :key="index1">
                    <!-- v-if="JSON.stringify(item1) !== '{}'" -->
                    <template>
                        <div @click="seatClk(item)" class="sm-img" v-for="item in item1" :key="item.id">
                            <img
                                v-if="item.status === 'N'"
                                class="o-w o-h"
                                src="https://hijinka.oss-cn-shanghai.aliyuncs.com/uploads/mall1/20220307/669dde5d9fe28a377c151cadecb8dd65.png"
                                alt=""
                            />
                            <img
                                v-if="item.status === 'Y' && !item.isCheck"
                                class="o-w o-h"
                                src="https://hijinka.oss-cn-shanghai.aliyuncs.com/uploads/mall1/20220307/123044531581e70133020f0265bcabb2.png"
                                alt=""
                            />
                            <img
                                v-if="item.status === 'Y' && item.isCheck"
                                class="o-w o-h"
                                src="https://hijinka.oss-cn-shanghai.aliyuncs.com/uploads/mall1/20220307/899c7f9e0365ce6d97f9d5fe89ffe878.png"
                                alt=""
                            />
                        </div>
                    </template>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'sysIndex',
    components: {},
    data() {
        return {
            // 页面渲染的数据
            seatList: [],
            // 后端返回的数据
            arrList: [
                {
                    id: 1,
                    seatNo: '1排1座',
                    status: 'N',
                    rowNo: '1',
                    colNo: '1'
                },
                {
                    id: 2,
                    seatNo: '1排2座',
                    status: 'Y',
                    rowNo: '1',
                    colNo: '2'
                },
                {
                    id: 3,
                    seatNo: '1排3座',
                    status: 'Y',
                    rowNo: '1',
                    colNo: '3'
                },
                {
                    id: 4,
                    seatNo: '1排4座',
                    status: 'Y',
                    rowNo: '1',
                    colNo: '4'
                },
                {
                    id: 5,
                    seatNo: '1排5座',
                    status: 'Y',
                    rowNo: '1',
                    colNo: '5'
                },

                {
                    id: 6,
                    seatNo: '2排2座',
                    status: 'Y',
                    rowNo: '2',
                    colNo: '2'
                },
                {
                    id: 7,
                    seatNo: '2排3座',
                    status: 'Y',
                    rowNo: '2',
                    colNo: '3'
                },
                {
                    id: 8,
                    seatNo: '2排4座',
                    status: 'Y',
                    rowNo: '2',
                    colNo: '4'
                },

                {
                    id: 9,
                    seatNo: '3排4座',
                    status: 'Y',
                    rowNo: '3',
                    colNo: '4'
                }
            ]
        };
    },
    mounted() {
        // 找到行的最大值
        const rowMax = this.findObjInArrMax(this.arrList, 'rowNo', true);
        // 找到列的最大值
        const colMax = this.findObjInArrMax(this.arrList, 'colNo', true);
        const rowNoMax = parseInt(rowMax.rowNo) + 1;
        const colNoMax = parseInt(colMax.colNo) + 1;
        // 将一维数组装成二维数组
        let list = [];
        for (var index = 0; index < rowNoMax; index++) {
            list[index] = [];
            for (var index1 = 0; index1 < colNoMax; index1++) {
                list[index][index1] = {};
            }
        }
        // 后端返回的数据组合到二维数组里面
        list.forEach((item1, index1) => {
            item1.forEach((item2, index2) => {
                this.arrList.forEach((item, index) => {
                    item.isCheck = false;
                    list[item.rowNo][item.colNo] = item;
                });
            });
        });
        console.log('list', list);
        this.seatList = list;
    },
    methods: {
        // 点击座位表
        seatClk(item) {
            // 如果是可以选择,而且没有选中状态
            if (item.status === 'Y' && !item.isCheck) {
                item.isCheck = true;
            } else if (item.status === 'Y' && item.isCheck) {
                item.isCheck = false;
            }
            console.log(item);
            this.$forceUpdate();
        },
        // 找到数组对象中的最大值
        findObjInArrMax(list, atr, returnVal) {
            let res = Math.max.apply(
                Math,
                list.map((item) => {
                    return item[atr];
                })
            );
            if (returnVal) {
                return list.filter((item) => {
                    return item[atr] == res;
                })[0];
            } else {
                return res;
            }
        },
        // 找到数组对象中的最小值
        findObjInArrMin(list, atr, returnVal) {
            let res = Math.min.apply(
                Math,
                list.map((item) => {
                    return item[atr];
                })
            );
            if (returnVal) {
                return list.filter((item) => {
                    return item[atr] == res;
                })[0];
            } else {
                return res;
            }
        }
    }
};
</script>

<style>
.sm-img {
    width: 26px;
    height: 26px;
}
.sm {
    position: relative;
}
.sm-line {
    width: 0;
    height: 100vh;
    border: 1px dashed #ccc;
    position: absolute;
    top: 18px;
    left: 50%;
}
.sm-title {
    background-color: #dddddd;
    width: 190px;
    height: 17px;
    -webkit-transform: perspective(17px) rotateX(-10deg);
    transform: perspective(17px) rotateX(-10deg);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
}
</style>

 

Spring Boot和Vue是目前非常热门的技术框架,它们可以很好地协同工作来实现电影功能。 首先,使用Spring Boot搭建后端服务。可以使用Spring Boot提供的丰富的特性来构建一个可靠稳定的后端系统。通过使用Spring Boot的注解和配置,可以快速地创建RESTful API接口,用于前后端数据交互。同时,Spring Boot还提供了简化开发的工具,如自动配置和依赖管理,以提高开发效率。 其次,使用Vue来构建前端界面。Vue是一个轻量级且强大的JavaScript框架,可以用于构建用户友好的交互式界面。通过使用Vue组件化开发模式,可以将界面划分为多个独立且可重用的组件,提高代码的可维护性。同时,Vue还提供了数据绑定、状态管理和路由等功能,使得开发者可以方便地构建复杂的前端应用。 在电影功能中,后端可以提供以下接口: 1. 获取电影列表:后端返回电影的基本信息,如电影名称、封面图片等。 2. 获取座位信息:后端返回电影场次的座位信息,如每个座位的状态(已/可)和价格等。 3. 预订座位前端将用户选择座位信息发送给后端,后端进行座位预订的逻辑处理,并返回结果给前端前端可以提供以下功能: 1. 展示电影列表:前端通过调用后端的接口获取电影列表,并展示在界面上供用户选择。 2. 显示座位信息:前端根据中的电影场次,调用后端接口获取座位信息,并展示在界面上供用户选择。 3. 功能:用户在界面上可以选择座位并提交预订请求,前端将用户选择座位信息发送给后端,后端进行逻辑处理。 通过Spring Boot和Vue的组合,我们可以实现一个功能完善、高效可靠的电影系统。前端提供良好的用户体验,后端提供快速、可靠的数据处理,让用户可以方便地并享受电影的乐趣。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值