fs-icon.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view
  3. :class="[type, colorType, source === 'inner' ? 'fsfont' : 'iconfont']"
  4. :style="style"
  5. @click="handleClick"
  6. ></view>
  7. </template>
  8. <script setup>
  9. import { computed } from 'vue'
  10. const props = defineProps({
  11. type: String,
  12. size: {
  13. type: String,
  14. default: '36rpx'
  15. },
  16. color: String,
  17. colorType: {
  18. type: String,
  19. validator(value) {
  20. return ['primary', 'success', 'info', 'warning', 'danger', 'gray'].includes(value)
  21. }
  22. },
  23. source: {
  24. type: String,
  25. default: 'inner'
  26. },
  27. link: String,
  28. linkType: {
  29. type: String,
  30. default: 'navigateTo'
  31. },
  32. rotate: String
  33. })
  34. const emits = defineEmits(['click'])
  35. const style = computed(() => {
  36. let style = `font-size: ${props.size};`
  37. if (props.color) {
  38. style += `color: ${props.color};`
  39. }
  40. if (props.rotate) {
  41. style += `transform: rotate(${props.rotate}deg);`
  42. }
  43. return style
  44. })
  45. const handleClick = () => {
  46. if (props.link) {
  47. uni[props.linkType]({
  48. url: props.link
  49. })
  50. }
  51. emits('click')
  52. }
  53. </script>
  54. <style lang="scss" scoped>
  55. @import '../../common/iconfont.css';
  56. @import './icon.css';
  57. .fsfont,
  58. .iconfont {
  59. display: inline-block;
  60. vertical-align: middle;
  61. }
  62. </style>