icons.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view>
  3. <view class="uni-header">
  4. <view class="uni-group">
  5. <!-- 显示标题 -->
  6. <view class="uni-title">{{$t('demo.icons.title')}}(uni-icons)</view>
  7. <!-- 显示描述 -->
  8. <view class="uni-sub-title">{{$t('demo.icons.describle')}}</view>
  9. </view>
  10. </view>
  11. <view class="uni-container">
  12. <view class="icons">
  13. <!-- 循环显示图标 -->
  14. <view v-for="(icon,index) in icons" :key="index" class="icon-item pointer">
  15. <view @click="setClipboardData('tag',icon)" :class="'uni-icons-'+icon"></view>
  16. <text @click="setClipboardData('class',icon)" class="icon-text">uni-icons-{{icon}}</text>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 在非H5环境下显示fix-window组件 -->
  21. <!-- #ifndef H5 -->
  22. <fix-window v-if="fixWindow" />
  23. <!-- #endif -->
  24. </view>
  25. </template>
  26. <script>
  27. // 导入名为 "icons" 的模块,路径为 './uni-icons.js'
  28. import icons from './uni-icons.js'
  29. // 导出默认模块
  30. export default {
  31. // 数据属性
  32. data() {
  33. return {
  34. // 数据属性:icons
  35. icons
  36. }
  37. },
  38. // 属性
  39. props:{
  40. // 属性:tag
  41. tag: {
  42. // 类型为布尔型
  43. type: Boolean,
  44. // 默认值为 true
  45. default: true
  46. },
  47. // 属性:fixWindow
  48. fixWindow: {
  49. // 类型为布尔型
  50. type: Boolean,
  51. // 默认值为 true
  52. default: true
  53. }
  54. },
  55. // 方法
  56. methods: {
  57. // 方法:setClipboardData,参数为 type 和 icon
  58. setClipboardData(type, icon) {
  59. // 定义变量 data,值为 'uni-icons-' 加上 icon 参数
  60. let data = 'uni-icons-' + icon
  61. // 如果 this.tag 为真且 type 等于 'tag'
  62. if (this.tag && type === 'tag') {
  63. // 将 data 的值修改为带有 class 属性的字符串
  64. data = '<view class="' + data + '"></view>'
  65. }
  66. // 调用 uni.setClipboardData 函数
  67. uni.setClipboardData({
  68. // 数据为变量 data 的值
  69. data,
  70. // 成功回调函数
  71. success(res) {
  72. // 调用 uni.showToast 函数
  73. uni.showToast({
  74. // 图标为 'none'
  75. icon: 'none',
  76. // 提示信息为 '复制 ' 加上 data 的值,再加上 ' 成功!'
  77. title: '复制 ' + data + ' 成功!'
  78. })
  79. },
  80. // 失败回调函数
  81. fail(res) {
  82. // 调用 uni.showModal 函数
  83. uni.showModal({
  84. // 弹窗内容为 '复制 ' 加上 data 的值,再加上 ' 失败!'
  85. content: '复制 ' + data + ' 失败!',
  86. // 不显示取消按钮
  87. showCancel: false
  88. })
  89. }
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss">
  96. /* #ifndef H5 */
  97. page {
  98. padding-top: 85px;
  99. }
  100. /* #endif */
  101. .icons {
  102. display: flex;
  103. flex-direction: row;
  104. flex-wrap: wrap;
  105. }
  106. .icon-item {
  107. display: flex;
  108. width: 16.6%;
  109. height: 120px;
  110. font-size: 30px;
  111. text-align: center;
  112. justify-content: center;
  113. align-items: center;
  114. flex-direction: column;
  115. }
  116. .icon-item:hover,
  117. .icon-item:hover .icon-text {
  118. color: $uni-color-primary;
  119. }
  120. .icon-text {
  121. color: #99a9bf;
  122. font-size: 12px;
  123. text-align: center;
  124. height: 1em;
  125. line-height: 1em;
  126. margin-top: 15px;
  127. }
  128. /* #ifdef H5 */
  129. @media only screen and (max-width: 500px) {
  130. .icon-item {
  131. width: 33.3%;
  132. }
  133. }
  134. /* #endif */
  135. </style>