fs-icon.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view
  3. :class="[type, colorType, source === 'inner' ? 'fsfont' : 'iconfont']"
  4. :style="style"
  5. @click="handleClick"
  6. ></view>
  7. </template>
  8. <script>
  9. /**
  10. * 图标组件
  11. * @description 图标组件
  12. * @property {String} type 图标类型
  13. * @property {String} size 图标大小
  14. * @property {String} source = [inner | outer] 来源
  15. * @property {String} rotate 旋转
  16. * @property {String} color 图标颜色
  17. * @property {String} colorType = [primary | danger | warning | info | success | gray] 图标颜色类型
  18. * @property {String} link 跳转地址
  19. * @property {String} linkType 跳转类型
  20. */
  21. export default {
  22. name: 'fs-icon'
  23. }
  24. </script>
  25. <script setup>
  26. import { computed } from 'vue'
  27. const props = defineProps({
  28. type: String,
  29. size: {
  30. type: String,
  31. default: '36rpx'
  32. },
  33. color: String,
  34. colorType: {
  35. type: String,
  36. validator(value) {
  37. return ['primary', 'success', 'info', 'warning', 'danger', 'gray'].includes(value)
  38. }
  39. },
  40. source: {
  41. type: String,
  42. default: 'inner'
  43. },
  44. link: String,
  45. linkType: {
  46. type: String,
  47. default: 'navigateTo'
  48. },
  49. rotate: String
  50. })
  51. const emits = defineEmits(['click'])
  52. const style = computed(() => {
  53. let style = `font-size: ${props.size};`
  54. if (props.color) {
  55. style += `color: ${props.color};`
  56. }
  57. if (props.rotate) {
  58. style += `transform: rotate(${props.rotate}deg);`
  59. }
  60. return style
  61. })
  62. const handleClick = () => {
  63. if (props.link) {
  64. uni[props.linkType]({
  65. url: props.link
  66. })
  67. }
  68. emits('click')
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. @import '../../common/iconfont.css';
  73. @import './icon.css';
  74. .fsfont,
  75. .iconfont {
  76. display: inline-block;
  77. vertical-align: middle;
  78. }
  79. </style>