IndexPage.vue 1.84 KB
Newer Older
hucy's avatar
hucy committed
1 2 3 4 5
<!--
 * 机台列表轮播图
  -->
<script setup lang="ts">
import { reactive, onMounted } from 'vue';
hucy's avatar
hucy committed
6
import { machineList1, machineList2 } from '../../config';
hucy's avatar
hucy committed
7 8 9 10 11 12 13 14 15 16 17 18 19
import EquipmentPage from './EquipmentPage.vue';

const state = reactive({
  list: [] as any,
  autoplay: 10000,
});

onMounted(() => {
  state.list = handleMachineList(machineList1);
  state.autoplay = 3000;
});

function handleMachineList(data: any) {
hucy's avatar
hucy committed
20
  const step = 10; // 10个一组
hucy's avatar
hucy committed
21 22 23 24 25 26
  const length = data.length;
  const divisionRes = division(length, step);

  let DATA = JSON.parse(JSON.stringify(data));
  let arr = [] as any;
  for (let i = 0; i < divisionRes.int; i++) {
hucy's avatar
hucy committed
27 28 29 30 31 32
    const newArr = DATA.slice(i * step, (i + 1) * step);
    arr.push(newArr);
  }
  const last = divisionRes.int * step;
  if (DATA.slice(last).length > 0) {
    arr.push(DATA.slice(last));
hucy's avatar
hucy committed
33 34
  }

hucy's avatar
hucy committed
35
  return arr;
hucy's avatar
hucy committed
36 37 38 39 40 41 42 43 44 45 46
}

// 取整 取余
function division(n: number, m: number) {
  const yu = n % m;
  const int = parseInt(String(n / m));
  return {
    yu,
    int,
  };
}
hucy's avatar
hucy committed
47 48 49 50 51 52 53 54 55 56 57 58 59

function changeData1() {
  state.list = handleMachineList(machineList2);
}
function resetData() {
  state.list = handleMachineList(machineList1);
}
function changeTime1() {
  state.autoplay = 1000;
}
function changeTime2() {
  state.autoplay = 5000;
}
hucy's avatar
hucy committed
60 61 62
</script>
<template>
  <div>机台列表</div>
hucy's avatar
hucy committed
63 64 65 66 67 68
  <div>
    <q-btn label="改变数据1" color="primary" @click="changeData1" />
    <q-btn label="重置" color="primary" @click="resetData" />
    <q-btn label="改变轮播时间1000" color="orange" @click="changeTime1" />
    <q-btn label="改变轮播时间5000" color="orange" @click="changeTime2" />
  </div>
hucy's avatar
hucy committed
69 70 71 72 73 74 75 76 77 78
  <div class="my-warp-box">
    <equipment-page :list="state.list" :autoplay="state.autoplay" />
  </div>
</template>

<style lang="scss" scoped>
.my-warp-box {
  width: 500px;
  height: 300px;
  border: 1px solid red;
hucy's avatar
hucy committed
79
  background-color: black;
hucy's avatar
hucy committed
80 81
}
</style>