fs-sidebar.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view class="fs-side-bar">
  3. <view class="fs-side-bar-left" :style="{width: width}">
  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. width: {
  37. type: String,
  38. default: '210rpx'
  39. }
  40. })
  41. const emits = defineEmits(['change'])
  42. const activeId = ref(props.value)
  43. const handleClick = (item, index) => {
  44. activeId.value = item[props.valueKey]
  45. emits('change', {
  46. item,
  47. index
  48. })
  49. }
  50. </script>
  51. <style lang="scss" scoped>
  52. .fs-side-bar{
  53. display: flex;
  54. height: 100%;
  55. &-left{
  56. flex-shrink: 0;
  57. background-color: #fafafa;
  58. overflow: auto;
  59. }
  60. &-item{
  61. padding: 30rpx var(--gutter);
  62. position: relative;
  63. }
  64. &-active{
  65. background-color: #fff;
  66. color: var(--primary);
  67. &::before{
  68. position: absolute;
  69. content: '';
  70. left: 0;
  71. top: 0;
  72. height: 100%;
  73. width: 6rpx;
  74. background-color: currentColor;
  75. }
  76. }
  77. &-right{
  78. flex: 1;
  79. background-color: #fff;
  80. overflow: auto;
  81. }
  82. }
  83. </style>