log-collapse.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="hc-log-time-tree">
  3. <uni-collapse accordion v-model="collapseKey" @change="collapseChange">
  4. <template v-for="(item, index) in dataList" :key="index">
  5. <uni-collapse-item :show-arrow="false" :name="item.hierarchy">
  6. <template v-slot:title>
  7. <view class="log-time-title-box">
  8. <view class="name-bar">
  9. <text class="i-ri-arrow-right-s-fill icon"/>
  10. <text class="name">{{item.hierarchy}}</text>
  11. <text class="text">({{item.logs.length}}条)</text>
  12. </view>
  13. <view class="action-bar"
  14. v-if="isAction"
  15. :class="item.treeList.length <= 0 ? 'is-disabled': ''"
  16. @click.stop="actionClick(item,index)"
  17. >
  18. <text class="i-ri-calendar-2-line"/>
  19. <text class="name">{{text}}</text>
  20. </view>
  21. </view>
  22. </template>
  23. <view class="log-time-content-bar">
  24. <slot :item="item" :index="index"/>
  25. </view>
  26. </uni-collapse-item>
  27. </template>
  28. </uni-collapse>
  29. </view>
  30. </template>
  31. <script setup>
  32. import { ref, watch } from "vue";
  33. import {getArrValue} from "js-fast-way";
  34. //参数
  35. const props = defineProps({
  36. modelValue: {
  37. type: String,
  38. default: '',
  39. },
  40. data: {
  41. type: Array,
  42. default: () => ([]),
  43. },
  44. text: {
  45. type: String,
  46. default: '月份',
  47. },
  48. action: {
  49. type: Boolean,
  50. default: true,
  51. },
  52. })
  53. //基础变量
  54. const collapseKey = ref(props.modelValue)
  55. const isAction = ref(props.action)
  56. const dataList = ref(props.data)
  57. //监听选中项
  58. watch(() => [
  59. props.modelValue
  60. ], ([val]) => {
  61. collapseKey.value = val
  62. })
  63. //监听列表数据
  64. watch(() => [
  65. props.data
  66. ], ([val]) => {
  67. dataList.value = val
  68. }, {deep: true})
  69. //事件
  70. const emit = defineEmits(['update:modelValue', 'change', 'action'])
  71. //选择数据改变
  72. const collapseChange = (key) => {
  73. emit('update:modelValue', key)
  74. emit('change', key)
  75. }
  76. //右边被点击
  77. const actionClick = (item, index) => {
  78. const arr = getArrValue(item.treeList)
  79. if (arr.length > 0) {
  80. emit('action', item, index)
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .hc-log-time-tree {
  86. position: relative;
  87. margin-top: 8rpx;
  88. margin-bottom: 10rpx;
  89. :deep(.uni-collapse-item__title.is-open) {
  90. border-color: #ebeef5;
  91. .name-bar .icon {
  92. transform: rotate(90deg);
  93. }
  94. }
  95. .log-time-title-box {
  96. position: relative;
  97. padding: 0 28rpx;
  98. height: 80rpx;
  99. display: flex;
  100. flex-direction: row;
  101. justify-content: space-between;
  102. align-items: center;
  103. padding-left: 14rpx;
  104. .name-bar {
  105. flex: 1;
  106. padding-right: 55rpx;
  107. display: flex;
  108. align-items: center;
  109. .icon {
  110. font-size: 20px;
  111. color: #7A7B7C;
  112. margin-right: 10rpx;
  113. transform: rotate(0);
  114. transition: transform .3s ease-in-out;
  115. }
  116. .text {
  117. margin-left: 8rpx;
  118. color: #7A7B7C;
  119. }
  120. }
  121. .action-bar {
  122. display: flex;
  123. align-items: center;
  124. justify-content: flex-end;
  125. position: relative;
  126. color: #007aff;
  127. .name {
  128. margin-left: 5rpx;
  129. }
  130. &:after {
  131. content: "";
  132. position: absolute;
  133. left: -26rpx;
  134. height: 100%;
  135. width: 1px;
  136. background: #eee;
  137. }
  138. &.is-disabled {
  139. color: #E9EAEC;
  140. }
  141. }
  142. }
  143. .log-time-content-bar {
  144. position: relative;
  145. background: #E9EAEC;
  146. :deep(.hc-all-user-list) {
  147. margin-top: 0;
  148. margin-bottom: 0;
  149. }
  150. }
  151. }
  152. </style>