fs-sidebar.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view class="fs-side-bar">
  3. <view class="fs-side-bar-left">
  4. <view
  5. class="fs-side-bar-item line1"
  6. :class="{'fs-side-bar-active': activeId ? (activeId === item[valueKey]) : (index === 0)}"
  7. v-for="(item, index) in list"
  8. :key="item[valueKey]"
  9. @click="handleClick(item, index)">
  10. {{item[titleKey]}}
  11. </view>
  12. </view>
  13. <view class="fs-side-bar-right">
  14. <slot></slot>
  15. </view>
  16. </view>
  17. </template>
  18. <script setup>
  19. import { ref } from 'vue'
  20. const props = defineProps({
  21. list: {
  22. type: Array,
  23. default() {
  24. return []
  25. }
  26. },
  27. value: null,
  28. valueKey: {
  29. type: String,
  30. default: 'id'
  31. },
  32. titleKey: {
  33. type: String,
  34. default: 'title'
  35. }
  36. })
  37. const emits = defineEmits(['change'])
  38. const activeId = ref(props.value)
  39. const handleClick = (item, index) => {
  40. activeId.value = item[props.valueKey]
  41. emits('change', {
  42. item,
  43. index
  44. })
  45. }
  46. </script>
  47. <style lang="scss" scoped>
  48. .fs-side-bar{
  49. display: flex;
  50. height: 100%;
  51. &-left{
  52. width: 200rpx;
  53. flex-shrink: 0;
  54. background-color: #fafafa;
  55. overflow: auto;
  56. }
  57. &-item{
  58. padding: 26rpx var(--gutter);
  59. position: relative;
  60. }
  61. &-active{
  62. background-color: #fff;
  63. color: var(--primary);
  64. &::before{
  65. position: absolute;
  66. content: '';
  67. left: 0;
  68. top: 0;
  69. height: 100%;
  70. width: 4rpx;
  71. background-color: currentColor;
  72. }
  73. }
  74. &-right{
  75. flex: 1;
  76. background-color: #fff;
  77. overflow: auto;
  78. }
  79. }
  80. </style>