fs-grid-item.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view
  3. class="fs-grid-item"
  4. :class="{ 'fs-grid-item-border': border, 'fs-grid-item-radius': radius }"
  5. :style="{ padding: padding ? '20rpx 0' : 0, backgroundColor: bgColor }"
  6. @click="handleClick"
  7. >
  8. <slot></slot>
  9. </view>
  10. </template>
  11. <script>
  12. /**
  13. * 宫格项组件
  14. * @description 宫格项组件
  15. * @property {String} link 跳转地址
  16. * @property {String} linkType 跳转类型
  17. */
  18. export default {
  19. name: 'fs-grid-item'
  20. }
  21. </script>
  22. <script setup>
  23. import { inject } from 'vue'
  24. const props = defineProps({
  25. link: String,
  26. linkType: {
  27. type: String,
  28. default: 'navigateTo'
  29. }
  30. })
  31. const emits = defineEmits(['click'])
  32. const gird = inject('fsGrid', {})
  33. const { border, padding, bgColor, radius } = gird
  34. const handleClick = () => {
  35. if (props.link) {
  36. uni[props.linkType]({
  37. url: props.link
  38. })
  39. }
  40. emits('click')
  41. }
  42. </script>
  43. <style lang="scss" scoped>
  44. .fs-grid-item {
  45. display: flex;
  46. align-items: center;
  47. justify-content: center;
  48. flex-direction: column;
  49. text-align: center;
  50. position: relative;
  51. height: 100%;
  52. background-color: #fff;
  53. &-border::before {
  54. position: absolute;
  55. content: '';
  56. top: 0;
  57. right: 0;
  58. bottom: 0;
  59. left: 0;
  60. border: 1px solid var(--border-color);
  61. margin-left: -1px;
  62. margin-top: -1px;
  63. }
  64. &-radius {
  65. border-radius: var(--radius);
  66. }
  67. }
  68. </style>