css 练习01

效果展示

在这里插入图片描述

源码

<template>
  <div class="container">
    <div class="search"></div>
    <div class="content">
      <div class="left">
        <div class="info">
          <div class="layout-list" v-for="item in layoutList" :key="item.id">
            <div v-if="item.type === 'column'">
              <div class="layout-item" v-for="child in item.children" :key="child.id">
                <div class="code-box">
                  <div class="code-number">{{ child.code }}</div>
                </div>
              </div>
            </div>
            <div v-else class="aisle">
              <div class="aisle-line"></div>
              <div class="aisle-middle">
                <div>
                  <div class="aisle-reat" v-for="r in 3" :key="r"></div>
                  <div class="aisle-id">{{ item.id }}</div>
                  <div class="aisle-reat" v-for="r in 3" :key="r"></div>
                </div>
              </div>
              <div class="aisle-line transform-rotate"></div>
            </div>
          </div>
          <div class="axis-x">
            <div class="x" v-for="(_, index) in layoutList" :key="index">
              {{ index + 1 }}
            </div>
          </div>
          <div class="axis-y">
            <div class="y" v-for="(_, index) in y" :key="index">
              {{ index + 1 }}
            </div>
          </div>
          <div class="axis-label">
            <div class="row"></div>
            <div class="split"></div>
            <div class="col"></div>
          </div>
        </div>
        <div class="tips">
          <a-space>
            <span class="bg-green btn">已设置</span>
            <span class="bg-gray btn">未设置</span>
            <span>
              库位合计:68个,已使用:30个,未使用:38</span>
          </a-space>
        </div>
      </div>
      <div class="right">
        <div style="height: 100%; width: 100%">
          <sv-table style="height: 100%" :data="tableData" ref="tableRef">
            <sv-column title="排名" field="sequence"></sv-column>
            <sv-column title="货主" field="owner"></sv-column>
            <sv-column title="物料" field="material"></sv-column>
            <sv-column title="描述" field="description"></sv-column>
            <sv-column title="类别" field="category"></sv-column>
            <sv-column title="ABC" field="abc"></sv-column>
            <sv-column title="出库频次" field="frequency"></sv-column>
            <sv-column title="拣货堆叠层级" field="stack"></sv-column>
          </sv-table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Sortable from 'sortablejs'

export default {
  name: 'layoutTable',
  data() {
    return {
      layoutList: [],
      tableData: []
    }
  },
  computed: {
    y() {
      return this.layoutList[0]?.children || []
    }
  },
  mounted() {
    this.fetchTableData(10)
    this.generateLayout(5, 5, [1])
    this.$nextTick(() => {
      this.initSortable()
    })
  },
  methods: {
    initSortable() {
      const tbody = this.$refs.tableRef.$el.querySelector('tbody')
      Sortable.create(tbody, {
        animation: 150,
        ghostClass: 'ghost',
        draggable: '.vxe-body--row'
      })
    },
    fetchTableData(num) {
      const tableDataArray = []
      for (let i = 0; i < num; i++) {
        tableDataArray.push({
          sequence: i + 1,
          owner: '货主' + i,
          material: '物料' + i,
          description: '描述' + i,
          category: '类别' + i,
          abc: 'ABC' + i,
          frequency: '出库频次' + i,
          stack: '拣货堆叠层级' + i
        })
      }
      this.tableData = tableDataArray
    },
    generateLayout(row, col, aislePositions) {
      const layout = []
      let code = 0
      // 创建列数据
      for (let i = 0; i < col; i++) {
        const columnObj = {
          id: i,
          name: '0' + i,
          type: 'column',
          children: []
        }
        for (let j = 0; j < row; j++) {
          code++
          columnObj.children.push({
            id: `${i}-${j}`,
            code
          })
        }
        layout.push(columnObj)
      }
      // 排序
      for (let i = 0; i < layout.length; i++) {
        const item = layout[i]
        if (item.type === 'column') {
          item.children.sort((a, b) => {
            return i % 2 === 0 ? a.code - b.code : b.code - a.code
          })
        }
      }
      // 处理过道
      if (aislePositions && aislePositions.length) {
        aislePositions.forEach((index) => {
          layout.splice(index, 0, {
            id: `aisle-${index}`,
            type: 'aisle',
            children: []
          })
        })
      }
      this.layoutList = layout
    }
  }
}
</script>

<style scoped lang="less">
@base-width: 160px;
@base-height: 96px;
@base-gap: 10px;
@w: 50px;
@h: 50px;
.container {
  padding: @base-gap;
  .content {
    display: flex;
    .left {
      flex: 1;
      margin-right: @base-gap;
      position: relative;
      padding-top: @w;
      padding-left: @w;
      .axis-x,
      .axis-y,
      .axis-label {
        position: absolute;
        top: 0;
        left: 0;
      }
      .axis-x {
        display: flex;
        left: @w;
        top: calc(@h - 20px);
        border-bottom: 1px solid #ccc;
        padding-left: 10px;
        .x {
          width: @base-width;
          text-align: center;
          margin-right: 20px;
        }
      }
      .axis-y {
        top: @h;
        left: calc(@w - 20px);
        border-right: 1px solid #ccc;
        padding-right: 10px;
        padding-top: 10px;
        width: 20px;
        .y {
          height: @base-height;
          width: 20px;
          margin-bottom: @base-gap;
          line-height: @base-height;
        }
      }
      .axis-label {
        width: @w;
        height: @h;
        border-right: 1px solid #ccc;
        border-bottom: 1px solid #ccc;
        top: 2px;
        left: 0;
        .row,
        .col,
        .split {
          position: absolute;
        }
        .row {
          right: 2px;
          top: 2px;
        }
        .col {
          bottom: 2px;
          left: 2px;
        }
        .split {
          top: 0;
          right: 0;
          width: 1px;
          height: 100%;
          background: #ccc;
          transform-origin: bottom right;
          transform: rotate(-45deg);
        }
      }
      .info {
        display: flex;
      }
      .layout-list {
        padding: @base-gap;
        .layout-item {
          width: @base-width;
          height: @base-height;
          border: 1px solid #ccc;
          margin-bottom: @base-gap;
          background: #bebebe;
          border-radius: 10px;
        }
        .code-box {
          width: 20px;
          height: 20px;
          border-radius: 50%;
          display: flex;
          align-items: center;
          justify-content: center;
          background-color: #fff;
        }
        .code-number {
          font-size: 12px;
        }
      }
      .aisle {
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        height: 100%;
        width: @base-width;
        border-radius: 10px;
        background-color: #efefef;
        border: 1px solid #bbbbbb;
        .aisle-line {
          height: 80%;
          width: 1px;
          background: red;
          position: relative;
          &::after {
            position: absolute;
            content: '';
            top: 0;
            left: -4px;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: red;
          }
          &::before {
            position: absolute;
            content: '';
            bottom: -12px;
            left: -10px;
            border: 10px solid transparent;
            border-top-color: red;
          }
        }
        .transform-rotate {
          transform: rotate(180deg);
        }
        .aisle-reat {
          width: 20px;
          height: 40px;
          border: 1px solid #ccc;
          margin: 0 auto;
          margin-bottom: @base-gap;
        }
        .aisle-middle {
          display: flex;
          align-items: center;
          justify-content: center;
          margin: 0 4px;
        }
        .aisle-id {
          font-size: 14px;
        }
      }
    }
    .right {
      width: 600px;
      border: 1px solid #ccc;
    }
  }
  .tips {
    .btn {
      padding: 4px 10px;
      color: #fff;
    }
  }
  .bg-gray {
    background-color: #bbbbbb;
  }
  .bg-green {
    background-color: #73d32e;
  }
  .bg-yellow {
    background-color: #FCCA00;
  }
  .bg-blue {
    background-color: #2A87FF;
  }
}
</style>

### 关于CSS练习题和学习资源 以下是关于CSS练习题和学习资源的相关建议: #### 1. 静态网页实践练习 通过实际操作来掌握HTML与CSS的基础技能是非常重要的。例如,在完成静态网页的页眉、页脚设计时,可以尝试使用更多复杂的布局技术[^1]。这不仅能够巩固基础语法,还能提升对响应式设计的理解。 #### 2. 精灵图的应用 精灵图是一种优化图片加载速度的技术,它将多个小图标合并成一张大图并通过`background-position`属性控制显示区域。这种技巧广泛应用于电商网站等需要频繁更新图像的地方,因此非常适合初学者深入研究并加以应用。 #### 3. 注册登录页面开发项目 对于新手来说,“某电商网站注册、登录页面”的制作是一个很好的综合训练机会[^2]。此过程涉及表单元素样式调整以及整体视觉效果的设计,有助于提高实战能力。 #### 4. HTML/CSS 牛客题库练习 牛客网提供了丰富的前端题目供学员练习,其中包括但不限于颜色设置、字体大小定义等内容[^3]。这些具体的实例可以帮助加深理解各种标签的作用及其对应的CSS规则。 #### 5. 页面结构案例分析 观察其他开发者如何构建简单的几何图形也能启发自己的创作思路[^4]。比如利用嵌套div实现正方形内的圆形展示就是一个不错的例子,从中我们可以学到层叠顺序、定位方式等方面的知识点。 ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS Practice</title> <style> body { text-align: center; } #outer-box { width: 300px; height: 300px; background-color: blue; position: relative; margin: auto; } #inner-circle { width: 150px; height: 150px; border-radius: 50%; background-color: yellow; position: absolute; top: calc(50% - 75px); left: calc(50% - 75px); } </style> </head> <body> <div id="outer-box"> <div id="inner-circle"></div> </div> </body> </html> ``` 上述代码片段展示了如何创建一个蓝色背景下的黄色圆圈居中的场景,这对于熟悉盒模型概念非常有帮助。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

web_Hsir

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值