SIconModal2.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. const n = `<template>
  2. <s-modal
  3. v-model:value="show"
  4. keyboard
  5. :title="$l('图标选择')"
  6. :width="width"
  7. :tabs="tabs"
  8. @tabsChange="handTabChange"
  9. @handCancel="cancelHandel"
  10. >
  11. <div class="icon-body">
  12. <a-input-search
  13. v-model:value="keyword"
  14. class="icon-search"
  15. :placeholder="$l('搜索图标')"
  16. allow-clear
  17. />
  18. <div class="icon-list">
  19. <div
  20. v-for="icon in icons"
  21. :key="icon"
  22. class="item-icon"
  23. v-clipboard="\`<\${icon}/>\`"
  24. @click="handToast(icon)"
  25. >
  26. <component :is="icon" :class="icon" />
  27. <div class="name">{{ icon }}</div>
  28. </div>
  29. <div v-if="!icons.length" class="icon-empty">{{ $l('暂无数据') }}</div>
  30. </div>
  31. </div>
  32. </s-modal>
  33. </template>
  34. <script setup>
  35. import { computed, ref, watch } from 'vue'
  36. import { filterIcons, getIconTabs } from './icon-groups'
  37. const props = defineProps({
  38. // 显隐(v-model:value)
  39. value: {
  40. type: Boolean,
  41. default: false
  42. },
  43. // 弹窗宽度
  44. width: {
  45. type: Number,
  46. default: 1028
  47. }
  48. })
  49. const emit = defineEmits(['update:value'])
  50. const show = ref(false)
  51. // 顶部页签:全部 / 线框 / 实底 / 双色,按图标风格后缀分类
  52. const tabs = computed(() => getIconTabs().slice(1))
  53. const activeGroup = ref('outlined')
  54. const keyword = ref('')
  55. const icons = computed(() => filterIcons(activeGroup.value, keyword.value))
  56. watch(
  57. () => props.value,
  58. (val) => {
  59. show.value = val
  60. }
  61. )
  62. const cancelHandel = () => {
  63. show.value = false
  64. emit('update:value', false)
  65. }
  66. const handTabChange = (key) => {
  67. activeGroup.value = key
  68. }
  69. // 弹窗关闭就清空关键字,下次打开回到完整列表
  70. watch(show, (val) => {
  71. if (!val) keyword.value = ''
  72. })
  73. const handToast = (icon) => {
  74. window.$message.success(\`<\${icon}/>\`)
  75. }
  76. <\/script>
  77. <style lang="less" scoped>
  78. .icon-body {
  79. height: 60vh;
  80. display: flex;
  81. flex-direction: column;
  82. }
  83. .icon-search {
  84. flex: 0 0 auto;
  85. margin-bottom: 12px;
  86. }
  87. .icon-list {
  88. flex: 1 1 auto;
  89. min-height: 0;
  90. overflow: hidden auto;
  91. width: 100%;
  92. display: flex;
  93. justify-content: flex-start;
  94. align-items: flex-start;
  95. align-content: flex-start;
  96. flex-wrap: wrap;
  97. .item-icon {
  98. width: 130px;
  99. margin: 16px;
  100. cursor: pointer;
  101. font-size: 28px;
  102. display: flex;
  103. flex-direction: column;
  104. justify-content: center;
  105. align-items: center;
  106. .name {
  107. font-size: 11px;
  108. margin-top: 10px;
  109. }
  110. }
  111. }
  112. .icon-empty {
  113. width: 100%;
  114. padding: 60px 0;
  115. text-align: center;
  116. color: var(--s-text-color-secondary);
  117. }
  118. </style>
  119. `;
  120. export {
  121. n as default
  122. };