Ruoyi若依项目笔记--icons/index.vue

253 阅读1分钟

ruoyi-ui/src/views/components/icons/index.vue

<template>
  <div class="icons-container">
    <aside>
      <a href="#" target="_blank">Add and use
      </a>
    </aside>
    <el-tabs type="border-card">
      <el-tab-pane label="Icons">
        <div v-for="item of svgIcons" :key="item">
          <el-tooltip placement="top">
            <div slot="content">
              {{ generateIconCode(item) }}
            </div>
            <div class="icon-item">
              <svg-icon :icon-class="item" class-name="disabled" />
              <span>{{ item }}</span>
            </div>
          </el-tooltip>
        </div>
      </el-tab-pane>
      <el-tab-pane label="Element-UI Icons">
        <div v-for="item of elementIcons" :key="item">
          <el-tooltip placement="top">
            <div slot="content">
              {{ generateElementIconCode(item) }}
            </div>
            <div class="icon-item">
              <i :class="'el-icon-' + item" />
              <span>{{ item }}</span>
            </div>
          </el-tooltip>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import svgIcons from './svg-icons'
import elementIcons from './element-icons'

export default {
  name: 'Icons',
  data() {
    return {
      svgIcons,
      elementIcons
    }
  },
  methods: {
    generateIconCode(symbol) {
      return `<svg-icon icon-class="${symbol}" />`
    },
    generateElementIconCode(symbol) {
      return `<i class="el-icon-${symbol}" />`
    }
  }
}
</script>

<style lang="scss" scoped>
.icons-container {
  margin: 10px 20px 0;
  overflow: hidden;

  .icon-item {
    margin: 20px;
    height: 85px;
    text-align: center;
    width: 100px;
    float: left;
    font-size: 30px;
    color: #24292e;
    cursor: pointer;
  }

  span {
    display: block;
    font-size: 16px;
    margin-top: 10px;
  }

  .disabled {
    pointer-events: none;
  }
}
</style>

这是一个Vue组件,用于展示SVG图标和Element-UI图标,并提供相应的代码生成功能。下面对每个部分进行解释:

  1. 模板部分 (<template>):

    • 使用了<el-tabs>标签创建了选项卡,包含两个标签页:一个用于展示SVG图标,另一个用于展示Element-UI图标。
    • 使用v-for指令循环渲染每个图标。
    • 使用<el-tooltip>标签添加悬浮提示。
    • 使用<svg-icon><i>标签分别展示SVG图标和Element-UI图标。
    • 图标的名称和代码都被显示在页面上。
  2. 脚本部分 (<script>):

    • 引入了svg-iconselement-icons,分别包含SVG图标和Element-UI图标的名称。
    • data中定义了svgIconselementIcons用于存储图标名称。
    • 定义了两个方法 generateIconCodegenerateElementIconCode 用于生成相应图标的代码。
  3. 样式部分 (<style>):

    • 使用了scoped属性,将样式限定在当前组件内。
    • 定义了.icons-container样式,设置了外边距、溢出处理等。
    • 定义了.icon-item样式,设置了图标项的样式,包括外边距、高度、宽度、字体大小、颜色、光标等。
    • .disabled类样式使元素不可点击。

总体来说,这个组件展示了图标并提供了生成相应代码的功能,使得用户可以方便地复制使用。