Taro+vue3 实现电影切换列表

1.需求

 我们在做类似于猫眼电影的小程序或者H5 的时候 我们会做到那种 左右滑动的电影列表,这种列表一般带有电影场次 

2.效果

3.说明

 这种效果在淘票票 猫眼电影上 都有的 ,一般电影类型的H5 或者小程序 这个是都有的 第一是好看 第二是客观性比较好

4.代码、

1.整体页面
<template>
    <div class="movie-container-index">
        <Header></Header>
        <div class="swiper-main">
            <image class="background-img-vague" :src="chooseMovice.posterUrl" style="height: 100%;"></image>
            <div class="wrap">
                <MovieList :list="movieList" @onchangeMovie="MovieChange" :model-value="chooseMovice.movieId"></MovieList>
            </div>
            <div class="box"></div>

        </div>
        <div class="movie-detail">
            <div class="name">{{ chooseMovice.movieName }}</div>
            <div class="center-detail">
                <div>{{ chooseMovice.movieType }}</div>
                <div>{{ chooseMovice.duration }}</div>

            </div>
            <div class="cast">{{ chooseMovice.cast }}</div>

        </div>
        <div class="movie-time-container">
            <Filter v-if="timeList.length" :data="timeList" @onChanged="onTimeChanged"></Filter>
        </div>
        <div class="movie-arrgement-container" v-if="arrangementList.length && !loading">
            <Item v-for="(item, index) in arrangementList" :info="item" :key="index"></Item>
        </div>
        <template v-if="arrangementList.length === 0 && loading">
            <div style="padding:  0 15px;">
                <nut-skeleton :style="{ width: '100%', margin: '0.5rem 0' }" width="100%" height="15px" title animated
                    row="1">
                </nut-skeleton>
                <nut-skeleton :style="{ width: '100%', margin: '0.5rem 0' }" width="100%" height="15px" title animated
                    row="1">
                </nut-skeleton>
                <nut-skeleton :style="{ width: '100%', margin: '0.5rem 0' }" width="100%" height="15px" title animated
                    row="1">
                </nut-skeleton>
                <nut-skeleton :style="{ width: '100%', margin: '0.5rem 0' }" width="100%" height="15px" title animated
                    row="1">
                </nut-skeleton>
                <nut-skeleton :style="{ width: '100%', margin: '0.5rem 0' }" width="100%" height="15px" title animated
                    row="1">
                </nut-skeleton>
                <nut-skeleton :style="{ width: '100%', margin: '0.5rem 0' }" width="100%" height="15px" title animated
                    row="1">
                </nut-skeleton>
                <nut-skeleton :style="{ width: '100%', margin: '0.5rem 0' }" width="100%" height="15px" title animated
                    row="1">
                </nut-skeleton>
                <nut-skeleton :style="{ width: '100%', margin: '0.5rem 0' }" width="100%" height="15px" title animated
                    row="1">
                </nut-skeleton>
                <nut-skeleton :style="{ width: '100%', margin: '0.5rem 0' }" width="100%" height="15px" title animated
                    row="1">
                </nut-skeleton>
                <nut-skeleton :style="{ width: '100%', margin: '0.5rem 0' }" width="100%" height="15px" title animated
                    row="1">
                </nut-skeleton>
            </div>
        </template>
        <template v-if="arrangementList.length === 0 && !loading">
            <nut-empty description="暂无场次"></nut-empty>
        </template>


    </div>
</template>
<script setup>
import Header from './header.vue'
import MovieList from './movie-list.vue'
import Filter from './filter.vue'
import { ref, reactive, onMounted } from 'vue'
import Item from './item.vue'
const chooseMovice = ref({
    movieId: 12343,
    duration: 149,
    movieType: '剧情|历史|战争',
    cast: '吴京 易烊千玺 段奕宏 张涵予 朱亚文',
    posterUrl: "https://gw.alicdn.com/i1/O1CN01sSmj2b1daSm6IAUcs_!!6000000003752-0-alipicbeacon.jpg_480x480Q30s150.jpg",
    movieName: '长津湖之水门桥',


})
const timeList = ref(["2024-01-09", "2024-01-10", "2024-01-13"])
const arrangementList = ref([])
const loading = ref(true)
const movieList = ref([
    {
        movieId: 12343,
        duration: 149,
        movieType: '剧情|历史|战争',
        cast: '吴京 易烊千玺 段奕宏 张涵予 朱亚文',
        movieName: '长津湖之水门桥',
        posterUrl: "https://gw.alicdn.com/i1/O1CN01sSmj2b1daSm6IAUcs_!!6000000003752-0-alipicbeacon.jpg_480x480Q30s150.jpg"
    },
    {
        cast: "易烊千玺 田雨 陈哈琳 齐溪 公磊 许君聪 王宁 黄尧 巩金国",
        duration: 106,
        movieId: 147885,
        movieName: "奇迹·笨小孩",
        movieType: "剧情",
        posterUrl: "https://gw.alicdn.com/i1/O1CN013Ggc2s1Z8HwrwxAfn_!!6000000003149-0-alipicbeacon.jpg_480x480Q30s150.jpg"
    },
    {
        cast: "张译,李晨,魏晨,曹炳琨,王骁,张子贤,杨新鸣",
        duration: 106,
        movieId: 147886,
        movieName: "三大队",
        movieType: "剧情,犯罪",
        posterUrl: "https://gw.alicdn.com/i4/O1CN01zQvWon1SuCCkUXTr8_!!6000000002306-0-alipicbeacon.jpg_480x480Q30s150.jpg"
    },
    {
        cast: "岑珈其,梁朝伟,刘德华,蔡卓妍,任达华,陈家乐,白只,姜皓文,方中信,太保,钱嘉乐,周家怡",
        duration: 106,
        movieId: 147887,
        movieName: "金手指",
        movieType: "犯罪,剧情",
        posterUrl: "https://gw.alicdn.com/i4/O1CN01mdCwok1K4QV7FV8gv_!!6000000001110-0-alipicbeacon.jpg_480x480Q30s150.jpg"
    },
    {
        cast: "李栋,大鹏,白客,庄达菲,王迅,孙艺洲,李乃文",
        duration: 106,
        movieId: 147888,
        movieName: "年会不能停!",
        movieType: "喜剧,剧情",
        posterUrl: "https://gw.alicdn.com/i1/O1CN01v6g8341QMBaLa2FhI_!!6000000001961-0-alipicbeacon.jpg_480x480Q30s150.jpg"
    },
    {
        cast: "屈楚萧,张佳宁,傅菁,蒋昀霖,牛超,田壮壮,沙溢",
        duration: 106,
        movieId: 147889,
        movieName: "一闪一闪亮星星",
        movieType: "爱情,奇幻",
        posterUrl: "https://gw.alicdn.com/i4/O1CN01W8mzt61aa3k1Xtw3N_!!6000000003345-0-alipicbeacon.jpg_480x480Q30s150.jpg"
    },
    {
        cast: "江户川柯南,高山南,山崎和佳奈,小山力也,林原惠美,置鲇龙太郎,三石琴乃,土师孝也,乃村健次,飞田展男,绪方贤一,松井菜樱子,岩居由希子,大谷育江,茶风林",
        duration: 106,
        movieId: 147890,
        movieName: "名侦探柯南:黑铁的鱼影",
        movieType: "动画,悬疑,动作",
        posterUrl: "https://gw.alicdn.com/i1/O1CN01U9wWR81pfku0aqB6O_!!6000000005388-0-alipicbeacon.jpg_480x480Q30s150.jpg"
    }

])
const MovieChange = (e) => {
    console.log(e);
    chooseMovice.value = movieList.value.filter((item) => item.movieId == e)[0]

}
onMounted(() => {
    arrangementList.value = [
        {
            finishTime: "1704782520000",
            hallName: "7号激光杜比全景声厅",
            id: "1194219979173253121",
            pickUpPrice: 3380,
            price: 3500,
            showTime: "1704775500000"
        }
    ]
    loading.value = false
})
</script>
<style lang="scss">
.movie-container-index {
    display: flex;
    flex-direction: column;

    .movie-arregment-container {}


    .swiper-main {
        height: 324px;
        position: relative;
        overflow: hidden;
        width: 100%;

        .background-img-vague {
            position: absolute;
            left: 0;
            right: 0;
            width: 100%;
            height: 100%;
            filter: blur(15px);
            -webkit-filter: blur(15px);
        }
    }

    .movie-detail {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background-color: #fff;
        padding: 20px;

        .name {
            font-size: 30px;
            font-weight: 700;
            color: #15181d;

        }

        .center-detail {
            display: flex;
            align-items: center;
            color: #858a99;
            font-size: 24px;
            margin-top: 5px;

        }

        .cast {
            color: #858a99;
            font-size: 24px;
            margin-top: 5px;
            word-break: break-all;
            text-align: center;
            overflow: hidden;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;

        }
    }



    .wrap {
        padding: 10px 0;


    }

    .box {
        width: 0;
        height: 0;
        border: 10rpx solid;
        border-color: transparent transparent #fff #fff;
        transform: rotate(135deg);
        position: absolute;
        bottom: -10rpx;
        left: 0;
        right: 0;
        margin: 0 auto;
    }
}
</style>
2.movie-list代码


<template>
    <div class="movie-list-component">
        <div class="list-container">
            <scroll-view id="contentScroll" class="scroll-view" :scroll-with-animation="true" :scroll-left="scrollLeft"
                :scroll-x="true">
                <div class="movie-item seat"></div>
                <div :data-id="item.movieId" @click="selectMovie" :id="`movieItem${item.movieId}`" class="movie-item" 
                    :class="{ active: modelValue == item.movieId }" v-for="( item, index ) in  list " :key="index">
                    <div class="img-container">
                        <image class="img" :src="item?.posterUrl" alt="" />
                    </div>
                </div>
                <div class="movie-item seat1"></div>
            </scroll-view>
        </div>
    </div>
</template>
<script setup lang="ts">
import Taro from "@tarojs/taro";
import { onMounted, ref, reactive, toRefs, watch } from "vue";
const props = defineProps({
    // 子组件接收父组件传递过来的值
    list: {
        type: Array<any>,
        required: true,
    },
    modelValue: {
        type: Number,
        required: true,
    },
});
//使用父组件传递过来的值
const { list, modelValue } = toRefs(props);
const emit = defineEmits(["onchangeMovie"]);

onMounted(() => {
    // selectMovie(list.value[0].movieId)
    list?.value.map((item, index) => {
        if (item.id === modelValue?.value) {
            list?.value.unshift(list?.value.splice(index, 1)[0]);
        }
    });

});
const scrollLeft = ref(0);
//选择电影
const selectMovie = (e) => {
    let offsetLeft = e.currentTarget.offsetLeft;
    let { id } = e.currentTarget.dataset;
    if (!id) {
        id = list.value[0].movieId;
    }
    if (modelValue.value == id) {
        return;
    }
    emit("onchangeMovie", id);
    getRect(id, offsetLeft);
};
//计算电影item的偏移量
const getRect = async (id, offsetLeft) => {

    const eleId = `#movieItem${id}`;

    const contentScrollWidth: any = await getContentScrollWidth("#contentScroll");
    const query = Taro.createSelectorQuery();
    query.select(eleId).boundingClientRect();
    query.selectViewport().scrollOffset();
    query.exec(async (res) => {

        //获取item的宽度de 一半
        const subhalfwidth = res[0].width / 2;
        //需要scrollview 移动的距离是
        const juli = offsetLeft - contentScrollWidth / 2 + subhalfwidth;
        scrollLeft.value = juli;

    });
};
// 获取ScrollView的宽度
const getContentScrollWidth = (ele) => {
    return new Promise((resolve) => {
        const query = Taro.createSelectorQuery();
        query.select(ele).boundingClientRect();
        query.selectViewport().scrollOffset();
        query.exec((res) => {
            const width = res[0].width;
            resolve(width);
        });
    });
};
</script>
<style lang="scss">
.movie-list-component {
    display: flex;
    flex-direction: column;

    .list-container {
        display: flex;
        flex-direction: column;
        justify-content: center;
        height: 324px;

        .scroll-view {
            width: 100%;
            height: 324px;
            white-space: nowrap;
            position: relative;

            .movie-item:nth-child(n+2) {
                margin-left: 35px;
            }

            .movie-item {
                display: inline-block;
                position: relative;

                margin-top: 30px;
                border-radius: 18px;
                width: 156px;
                height: 218px;
                // line-height: 208px;
                transition: width 1s;
                transition: height 1s;

                .img-container {
                    border-radius: 8px;
                    width: 100%;
                    height: 100%;
                    overflow: hidden;
                    position: relative;
                    z-index: 2;
                    // border: 5px #ffffff solid;

                    .img {
                        width: 100%;
                        height: 100%;
                    }
                }
            }

            .movie-item.active {
                transform: scale(1.15);
                /* 放大1.2倍 */
                transition: transform 1s ease;
                /* 过渡效果 */
            }

            .seat {
                display: inline-block;
                width: 50%;
                // height: 290px;
                margin-left: -110px;
            }

            .seat1 {
                display: inline-block;
                width: 35%;
            }
        }
    }
}
</style>
filter 组件

<template>
    <div class="cinema-detail-filter-container">
        <div class="date-tab">
            <nut-tabs :title-gutter="15" v-model="tabTimesIndex" title-scroll>
                <nut-tab-pane v-for="(item, index) in tabTimesList" :pane-key="index" :title="`${item.t} ${item.a}`">
                </nut-tab-pane>
            </nut-tabs>
        </div>
    </div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref, toRefs, watch } from 'vue';
import moment from "moment";
const tabTimesIndex = ref(0)
const tabTimesList: any = ref([])
const props = defineProps({
    //子组件接收父组件传递过来的值
    data: Object,
});
//使用父组件传递过来的值
const { data: timesList } = toRefs(props);
onMounted(() => {
    getTimes()
});
const emit = defineEmits(['onChanged'])
watch(tabTimesIndex, (index) => {
    emit('onChanged', tabTimesList.value[index])
})
watch(tabTimesList, () => {
    emit('onChanged', tabTimesList.value[0])
})
const getTimes = () => {
    const times = timesList?.value
    
    const arr: any = []
    times?.forEach(item => {
        const time = item
        let t = getweek(moment(time).startOf('day').format('E'))
        if (time === moment().format('YYYY-MM-DD')) {
            t = '今天'
        } else if (time === moment().subtract(-1, 'days').format('YYYY-MM-DD')) {
            t = '明天'
        } else if (time === moment().subtract(-2, 'days').format('YYYY-MM-DD')) {
            t = '后天'
        }
        arr.push({
            time: time,
            t: t,
            a: time.substr(5, 9)
        })
    });
    tabTimesList.value = arr

}
const getweek = (val) => {
    const week = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    return week[val - 1];
};
</script>
<style lang="scss">
.cinema-detail-filter-container {
    display: flex;
    flex-direction: column;

    .nut-tabs {
        .nut-tabs__titles {
            background: #ffffff !important;

            .nut-tabs__titles-item {
                .nut-tabs__titles-item__smile {
                    display: none;
                }

                .nut-tabs__titles-item__text {
                    color: #858a99;
                    font-size: 22px !important;

                }
            }

            .nut-tabs__titles-item__line {
                background: linear-gradient(to right, #5232B7, #7237BC, #5232B7) !important;
                border-radius: 30px !important;
            }

            .nut-tabs__titles-item.active {
                .nut-tabs__titles-item__smile {
                    display: block;
                    margin-top: 10px;
                }

                .nut-tabs__titles-item__text {
                    color: #15181d;
                }
            }
        }

        .nut-tabs__content {
            display: none !important;
        }
    }
}
</style>
header 组件

<template>
    <div class="movie-header-box">
        <div class="left">
            <div class="name">万达影城(北京昌平保利光魔店)</div>
            <div class="address">昌平区鼓楼街贾琏时代广场四楼</div>

        </div>
        <div class="right">
            <IconFont name="locationg3" color="#5232B7"></IconFont>
        </div>
    </div>
</template>
<script setup>
import { IconFont } from '@nutui/icons-vue-taro';
</script>
<style lang="scss">
.movie-header-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #fff;
    padding: 25px 30px;

    .left {
        .name {
            color: #15181d;
            font-weight: 700;
            font-size: 26px;
        }

        .address {
            color: #858a99;
            font-size: 22px;
            margin-top: 10px;
        }
    }
}
</style>

5.我这个项目是基于Taro +vue3 +ts 来写的 用的组件库也是京东的nut-ui  以上的代码和组件 也有的是我二次封装的组件 组件也挺方便的

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
后台采用apache服务器下的cgi处理c语言做微信小程序后台逻辑的脚本映射。PC端的服务器和客户端都是基于c语言写的。采用mysql数据库进行用户数据和聊天记录的存储。.zip C语言是一种广泛使用的编程语言,它具有高效、灵活、可移植性强等特点,被广泛应用于操作系统、嵌入式系统、数据库、编译器等领域的开发。C语言的基本语法包括变量、数据类型、运算符、控制结构(如if语句、循环语句等)、函数、指针等。下面详细介绍C语言的基本概念和语法。 1. 变量和数据类型 在C语言中,变量用于存储数据,数据类型用于定义变量的类型和范围。C语言支持多种数据类型,包括基本数据类型(如int、float、char等)和复合数据类型(如结构体、联合等)。 2. 运算符 C语言中常用的运算符包括算术运算符(如+、、、/等)、关系运算符(如==、!=、、=、<、<=等)、逻辑运算符(如&&、||、!等)。此外,还有位运算符(如&、|、^等)和指针运算符(如、等)。 3. 控制结构 C语言中常用的控制结构包括if语句、循环语句(如for、while等)和switch语句。通过这些控制结构,可以实现程序的分支、循环和多路选择等功能。 4. 函数 函数是C语言中用于封装代码的单元,可以实现代码的复用和模块化。C语言中定义函数使用关键字“void”或返回值类型(如int、float等),并通过“{”和“}”括起来的代码块来实现函数的功能。 5. 指针 指针是C语言中用于存储变量地址的变量。通过指针,可以实现对内存的间接访问和修改。C语言中定义指针使用星号()符号,指向数组、字符串和结构体等数据结构时,还需要注意数组名和字符串常量的特殊性质。 6. 数组和字符串 数组是C语言中用于存储同类型数据的结构,可以通过索引访问和修改数组中的元素。字符串是C语言中用于存储文本数据的特殊类型,通常以字符串常量的形式出现,用双引号("...")括起来,末尾自动添加'\0'字符。 7. 结构体和联合 结构体和联合是C语言中用于存储不同类型数据的复合数据类型。结构体由多个成员组成,每个成员可以是不同的数据类型;联合由多个变量组成,它们共用同一块内存空间。通过结构体和联合,可以实现数据的封装和抽象。 8. 文件操作 C语言中通过文件操作函数(如fopen、fclose、fread、fwrite等)实现对文件的读写操作。文件操作函数通常返回文件指针,用于表示打开的文件。通过文件指针,可以进行文件的定位、读写等操作。 总之,C语言是一种功能强大、灵活高效的编程语言,广泛应用于各种领域。掌握C语言的基本语法和数据结构,可以为编程学习和实践打下坚实的基础。
如果你想在 Taro + Vue 3 + TypeScript 的小程序项目中使用 Pinia,你可以按照以下步骤进行配置: 1. 首先,确保你已安装了 TaroVue 3 模板。你可以使用以下命令创建一个新的 Taro + Vue 3 + TypeScript 项目: ```bash npx @tarojs/cli@next init myApp --template vue3-ts ``` 2. 在项目目录下安装 Pinia: ```bash npm install pinia@2.0.23 ``` 3. 在 `src/main.ts` 文件中,导入 `createPinia` 并创建一个 Pinia 实例,并将其传递给 Vue 的 `createApp` 方法: ```typescript import { createApp } from 'vue' import { createPinia } from 'pinia' const app = createApp(...) const pinia = createPinia() app.use(pinia) ... ``` 4. 接下来,你可以根据需要创建和使用 Pinia 的 store。在 `src/store` 目录下创建一个新的文件来定义你的 store,例如 `counter.ts`: ```typescript import { defineStore } from 'pinia' export const useCounterStore = defineStore('counter', { state: () => ({ count: 0, }), actions: { increment() { this.count++ }, decrement() { this.count-- }, }, }) ``` 5. 在组件中使用 store。在你的组件中,你可以使用 `useStore` 函数来获取 store 的实例: ```typescript import { useCounterStore } from '../store/counter' export default { setup() { const counterStore = useCounterStore() return { counterStore, } }, } ``` 6. 最后,你可以在你的组件中使用 store: ```vue <template> <div> <p>Count: {{ counterStore.count }}</p> <button @click="counterStore.increment()">Increment</button> <button @click="counterStore.decrement()">Decrement</button> </div> </template> <script setup> import { useCounterStore } from '../store/counter' const counterStore = useCounterStore() </script> ``` 这样,你就可以在 Taro + Vue 3 + TypeScript 的小程序项目中使用 Pinia 了。如果你遇到任何问题,请提供更多的上下文和相关代码,我将尽力帮助你解决。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值