fs-sidebar.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 === item[valueKey]}"
  7. v-for="(item, index) in list"
  8. :key="index"
  9. @click="handleClick(item, index)">
  10. {{item.title}}
  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. })
  33. const emits = defineEmits(['change'])
  34. const activeId = ref(props.value)
  35. const handleClick = (item, index) => {
  36. activeId.value = item[props.valueKey]
  37. emits('change', {
  38. item,
  39. index
  40. })
  41. }
  42. </script>
  43. <style lang="scss" scoped>
  44. .fs-side-bar{
  45. display: flex;
  46. height: 100%;
  47. &-left{
  48. width: 200rpx;
  49. flex-shrink: 0;
  50. background-color: #fafafa;
  51. overflow: auto;
  52. }
  53. &-item{
  54. padding: 26rpx var(--gutter);
  55. position: relative;
  56. }
  57. &-active{
  58. background-color: #fff;
  59. color: var(--primary);
  60. &::before{
  61. position: absolute;
  62. content: '';
  63. left: 0;
  64. top: 0;
  65. height: 100%;
  66. width: 4rpx;
  67. background-color: currentColor;
  68. }
  69. }
  70. &-right{
  71. flex: 1;
  72. background-color: #fff;
  73. overflow: auto;
  74. }
  75. }
  76. </style>