remixIcon.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div class="colorful-icon-container">
  3. <el-row :gutter="20">
  4. <el-col :span="24">
  5. <el-divider content-position="left">
  6. 小清新图标在演示环境中使用的是cdn加速服务,开发时需存储到本地,使用方法可查看群文档,点击图标即可复制源码,点击图标即可复制源码
  7. </el-divider>
  8. </el-col>
  9. <el-col :span="24">
  10. <el-form :inline="true" label-width="80px" @submit.native.prevent>
  11. <el-form-item label="图标名称">
  12. <el-input v-model="queryForm.title"></el-input>
  13. </el-form-item>
  14. <el-form-item label-width="0">
  15. <el-button native-type="submit" type="primary" @click="queryData">
  16. 搜索
  17. </el-button>
  18. </el-form-item>
  19. <!-- <el-form-item label-width="0">
  20. <el-input :value="copyText" type="text"></el-input>
  21. </el-form-item>-->
  22. </el-form>
  23. </el-col>
  24. <el-col
  25. v-for="(item, index) in queryIcon"
  26. :key="index"
  27. :xs="6"
  28. :sm="8"
  29. :md="3"
  30. :lg="2"
  31. :xl="2"
  32. >
  33. <el-card
  34. shadow="hover"
  35. style="cursor: pointer"
  36. @click.native="handleCopyIcon(index, $event)"
  37. >
  38. <vab-remix-icon
  39. :icon-class="`https://cdn.jsdelivr.net/gh/chuzhixin/zx-remixicon/src/icons/svg/${item}.svg`"
  40. @click.stop
  41. ></vab-remix-icon>
  42. </el-card>
  43. <div class="icon-text">{{ item }}</div>
  44. </el-col>
  45. <el-col :span="24">
  46. <el-pagination
  47. :background="background"
  48. :current-page="queryForm.pageNo"
  49. :page-size="queryForm.pageSize"
  50. :page-sizes="[72, 144, 216, 288]"
  51. :layout="layout"
  52. :total="total"
  53. @size-change="handleSizeChange"
  54. @current-change="handleCurrentChange"
  55. ></el-pagination>
  56. </el-col>
  57. </el-row>
  58. </div>
  59. </template>
  60. <script>
  61. import { getIconList } from "@/api/remixIcon";
  62. import clip from "@/utils/clipboard";
  63. export default {
  64. name: "RemixIcon",
  65. data() {
  66. return {
  67. copyText: "",
  68. layout: "total, sizes, prev, pager, next, jumper",
  69. total: 0,
  70. background: true,
  71. height: 0,
  72. selectRows: "",
  73. elementLoadingText: "正在加载...",
  74. queryIcon: [],
  75. queryForm: {
  76. pageNo: 1,
  77. pageSize: 72,
  78. title: "",
  79. },
  80. };
  81. },
  82. created() {
  83. this.fetchData();
  84. },
  85. methods: {
  86. handleSizeChange(val) {
  87. this.queryForm.pageSize = val;
  88. this.fetchData();
  89. },
  90. handleCurrentChange(val) {
  91. this.queryForm.pageNo = val;
  92. this.fetchData();
  93. },
  94. queryData() {
  95. this.queryForm.pageNo = 1;
  96. this.fetchData();
  97. },
  98. async fetchData() {
  99. const { data, totalCount } = await getIconList(this.queryForm);
  100. this.queryIcon = data;
  101. this.allIcon = data;
  102. this.total = totalCount;
  103. },
  104. handleCopyIcon(index, event) {
  105. //const copyText = `<vab-remix-icon icon-class="https://cdn.jsdelivr.net/gh/chuzhixin/zx-remixicon@master/src/icons/svg/${this.queryIcon[index]}.svg" />`;
  106. const copyText = `<vab-remix-icon icon-class="${this.queryIcon[index]}" />`;
  107. this.copyText = copyText;
  108. clip(copyText, event);
  109. },
  110. },
  111. };
  112. </script>
  113. <style lang="scss" scoped>
  114. .colorful-icon-container {
  115. ::v-deep {
  116. .el-card__body {
  117. position: relative;
  118. display: flex;
  119. flex-direction: column;
  120. align-items: center; /* 垂直居中 */
  121. justify-content: center; /* 水平居中 */
  122. svg:not(:root),
  123. .svg-external-icon {
  124. font-size: 28px;
  125. font-weight: bold;
  126. color: $base-color-gray;
  127. text-align: center;
  128. vertical-align: middle;
  129. pointer-events: none;
  130. cursor: pointer;
  131. }
  132. }
  133. }
  134. .icon-text {
  135. height: 30px;
  136. margin-top: -15px;
  137. overflow: hidden;
  138. font-size: 12px;
  139. line-height: 30px;
  140. text-align: center;
  141. text-overflow: ellipsis;
  142. white-space: nowrap;
  143. }
  144. }
  145. </style>