文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

vue实现卡片翻转轮播展示

2024-04-02 19:55

关注

vue卡片翻转轮播展示,同时在翻转时切换数据,供大家参考,具体内容如下

效果及代码

代码:


<template>
  <div class="list-container">
    <div class="reason" v-if="list1.length > 0 || list2.length > 0">
      <div class="logo">
        <svg-icon class="center-svg" icon-class="centerLogo"></svg-icon>
        <div class="echart">
          <echart :option="option" echartId="roadP" />
        </div>
      </div>
      <RoadComponent :list="list1[0]" :style="{ display: show1 }"></RoadComponent>
      <RoadComponent :list="list2[0]" :style="{ display: show2 }"></RoadComponent>
      <RoadComponent :list="list1[1]" :style="{ display: show3 }"></RoadComponent>
      <RoadComponent :list="list2[1]" :style="{ display: show4 }"></RoadComponent>
      <RoadComponent :list="list1[2]" :style="{ display: show5 }"></RoadComponent>
      <RoadComponent :list="list2[2]" :style="{ display: show6 }"></RoadComponent>
    </div>
  </div>
</template>
<script>
  import { defineComponent, inject, onMounted, reactive, onUnmounted, toRefs } from 'vue';
  import { congestionPredict } from '@/apis/fullView';
  import echart from '@/components/common/echart';
  import '@/assets/icons/fullView/westToEast.svg';
  import '@/assets/icons/fullView/eastToWest.svg';
  import '@/assets/icons/fullView/northToSouth.svg';
  import '@/assets/icons/fullView/southToNorth.svg';
  import '@/assets/icons/fullView/centerLogo.svg';
  import RoadComponent from '@/views/fullView/left/RoadComponent';
  export default defineComponent({
    name: 'RoadP',
    components: { echart, RoadComponent },
    setup() {
      let echarts = inject('ec');
      const dataMap = reactive({
        interval: null,
        interval1: null,
        list1: [],
        list2: [],
        list: [],
        option: {},
        timeout: 10,
        show1: 'block',
        show2: 'none',
        show3: 'block',
        show4: 'none',
        show5: 'block',
        show6: 'none',
      });
      onMounted(() => {
        getData();
        dataMap.interval = setInterval(() => {
          getData();
        }, 60 * 1000);
        dataMap.interval1 = setInterval(() => {
          if (dataMap.timeout > 8 && dataMap.timeout < 11) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'block';
            dataMap.show3 = 'block';
            dataMap.show5 = 'block';
            dataMap.show2 = 'none';
            dataMap.show4 = 'none';
            dataMap.show6 = 'none';
          } else if (dataMap.timeout === 8) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'none';
            dataMap.show3 = 'block';
            dataMap.show5 = 'block';
            dataMap.show2 = 'block';
            dataMap.show4 = 'none';
            dataMap.show6 = 'none';
          } else if (dataMap.timeout === 7) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'none';
            dataMap.show3 = 'none';
            dataMap.show5 = 'block';
            dataMap.show2 = 'block';
            dataMap.show4 = 'block';
            dataMap.show6 = 'none';
          } else if (dataMap.timeout < 7 && dataMap.timeout > 3) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'none';
            dataMap.show3 = 'none';
            dataMap.show5 = 'none';
            dataMap.show2 = 'block';
            dataMap.show4 = 'block';
            dataMap.show6 = 'block';
          } else if (dataMap.timeout === 3) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'block';
            dataMap.show3 = 'none';
            dataMap.show5 = 'none';
            dataMap.show2 = 'none';
            dataMap.show4 = 'block';
            dataMap.show6 = 'block';
          } else if (dataMap.timeout === 2) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'block';
            dataMap.show3 = 'block';
            dataMap.show5 = 'none';
            dataMap.show2 = 'none';
            dataMap.show4 = 'none';
            dataMap.show6 = 'block';
          } else if (dataMap.timeout === 1) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'block';
            dataMap.show3 = 'block';
            dataMap.show5 = 'block';
            dataMap.show2 = 'none';
            dataMap.show4 = 'none';
            dataMap.show6 = 'none';
          } else {
            dataMap.timeout = 10;
          }
        }, 1000);
      });
      onUnmounted(() => {
        clearInterval(dataMap.interval);
        clearInterval(dataMap.interval1);
      });
      const getData = () => {
        congestionPredict()
          .then((res) => {
            if (res && res.code === 0 && res.data) {
              dataMap.list1 = [];
              dataMap.list2 = [];
              for (let i = 0; i < 6; i = i + 2) {
                dataMap.list1.push([
                  {
                    name: res.data[i].name,
                    direction: res.data[i].direction,
                    value: res.data[i].index.toFixed(1),
                    icon: res.data[i].englishDirection,
                  },
                  {
                    name: res.data[i + 1].name,
                    direction: res.data[i + 1].direction,
                    value: res.data[i + 1].index.toFixed(1),
                    icon: res.data[i + 1].englishDirection,
                  },
                ]);
              }
              for (let j = res.data.length - 1; j > res.data.length - 6; j = j - 2) {
                dataMap.list2.push([
                  {
                    name: res.data[j].name,
                    direction: res.data[j].direction,
                    value: res.data[j].index.toFixed(1),
                    icon: res.data[j].englishDirection,
                  },
                  {
                    name: res.data[j - 1].name,
                    direction: res.data[j - 1].direction,
                    value: res.data[j - 1].index.toFixed(1),
                    icon: res.data[j - 1].englishDirection,
                  },
                ]);
              }
            }
          })
          .catch((err) => {
            console.log(err);
          })
          .finally(() => {
            dataMap.option = getOption();
          });
      };

      const getOption = () => {
        return {
          series: [
            {
              type: 'liquidFill',
              name: '',
              radius: '85%',
              center: ['50%', '45%'],
              data: [0.55, 0.5, 0.5],
              color: ['rgba(0,118,255,0.5)', 'rgba(0,102,255,0.5)', 'rgba(0,185,255,0.6)'],
              outline: {
                show: false,
              },
              backgroundStyle: {
                color: 'transparent',
                borderColor: 'transparent',
                borderWidth: 1,
                shadowColor: 'transparent',
                shadowBlur: 0,
              },
              label: {
                show: false,
              },
            },
          ],
        };
      };
      return {
        ...toRefs(dataMap),
      };
    },
  });
</script>
<style scoped lang="less">
  .list-container {
    width: 100%;
    height: 280px;
  }
  .reason {
    width: 696px;
    margin: 16px auto;
    height: 228px;
    position: relative;
    list-style: none;
    .logo {
      width: 150px;
      height: 150px;
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      margin: auto;
      background: url('~@/assets/img/fullView/centerGround.dynamic.png');
      background-size: 100% 100%;
    }
    .echart {
      width: 158px;
      height: 158px;
      position: absolute;
      left: -4px;
      top: 4px;
    }
  }
  .center-svg {
    width: 90px;
    height: 100px;
    position: absolute;
    left: 30px;
    top: 25px;
    z-index: 15;
  }
</style>

卡片组件


<template>
  <div class="goBack" v-if="list.length > 0">
    <div class="top">
      <svg-icon class="svg" :icon-class="list[0].icon"></svg-icon>
      <div>
        <div>
          <p class="span-container text-overflow">{{ list[0].name }}</p>
          <p class="index" :style="{ color: switchColor(list[0].value) }">{{ list[0].value }}</p>
        </div>
        <div>
          <p class="span-container text-overflow">{{ list[1].name }}</p>
          <p class="index" :style="{ color: switchColor(list[1].value) }">{{ list[1].value }}</p>
        </div>
      </div>
      <svg-icon class="svg" :icon-class="list[1].icon"></svg-icon>
    </div>
  </div>
</template>
<script>
  import { defineComponent } from 'vue';

  export default defineComponent({
    name: 'RoadComponent',
    props: {
      list: {},
    },
    setup() {
      const switchColor = (value) => {
        if (value > 0 && value <= 2) {
          return '#00DBEB';
        } else if (value > 2 && value <= 3) {
          return '#FFD200';
        } else if (value > 3 && value <= 4) {
          return '#FF7309';
        } else if (value > 4 && value <= 5) {
          return '#FF0000';
        }
      };
      return {
        switchColor,
      };
    },
  });
</script>
<style lang="less" scoped>
  .goBack {
    transform-style: preserve-3d;
    animation: back 0.5s linear 1;
  }
  .back:hover {
    animation-play-state: paused;
  }
  @keyframes back {
    0% {
      transform: rotateZ(0deg) rotateY(0deg) rotateX(-90deg);
    }
    100% {
      transform: rotateZ(0deg) rotateY(0deg) rotateX(0deg);
    }
  }
  .span-container {
    width: 150px;
    margin: 0 0 5px 5px;
    color: var(--text-blue);
    font-size: var(--font-traffic-size);
  }
  .svg {
    width: 41px;
    height: 41px;
  }
  .top {
    display: flex;
    flex-wrap: nowrap;
    padding: 0 20px;
    margin: 0 0 14px 0;
    justify-content: space-between;
    align-items: center;
    height: 68px;
    border-radius: 10px;
    opacity: 0.9;
    background: linear-gradient(
      89deg,
      rgba(0, 76, 169, 0.5) 0%,
      rgba(0, 76, 169, 0) 46%,
      rgba(0, 76, 169, 0) 49%,
      rgba(0, 76, 169, 0) 52%,
      rgba(0, 76, 169, 0.5) 100%
    );
  }
  .top > div {
    width: 640px;
    display: flex;
    text-align: center;
    align-items: center;
    flex-wrap: nowrap;
    justify-content: space-between;
    & > div {
      width: 160px;
      span {
        margin-left: 15px;
      }
    }
    .index {
      width: 155px;
      height: 28px;
      font-size: var(--font-size-chart-title);
      text-align: center;
      margin: 0;
      line-height: 28px;
    }
  }
</style>

关于vue.js组件的教程,请大家点击专题vue.js组件学习教程进行学习。

精彩专题分享:jQuery图片轮播 JavaScript图片轮播 Bootstrap图片轮播

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-前端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯