index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div class="report-header flex items-center justify-between">
  3. <div class="title flex items-center">
  4. <span class="report-header-title" style="margin-right: 10px">{{
  5. props.title
  6. }}</span>
  7. <slot />
  8. <CustomDatePicker
  9. v-if="!props.hideTimePicker"
  10. style="margin-left: 10px"
  11. v-model="range"
  12. @timeChange="timeChange"
  13. ></CustomDatePicker
  14. ></div>
  15. <div class="right-box flex h-full items-center">
  16. <img class="time-icon" src="../../../assets//imgs/time.png" />
  17. <p>{{ timeText }} &nbsp; {{ getCurrentWeek() }}</p>
  18. <t-button
  19. v-if="appStore.isFullscreen"
  20. variant="outline"
  21. class="m-l-16px"
  22. @click="switchFullscreen"
  23. >
  24. <template #icon><SwapLeftIcon /></template>
  25. 返回
  26. </t-button>
  27. <t-button
  28. v-else
  29. variant="outline"
  30. class="m-l-16px"
  31. @click="switchFullscreen"
  32. >
  33. <template #icon><Fullscreen2Icon /></template>
  34. 全屏
  35. </t-button>
  36. </div>
  37. </div>
  38. </template>
  39. <script setup name="ReportHeader">
  40. import { ref, computed, onBeforeUnmount, onMounted } from 'vue';
  41. import { useIntervalFn } from '@vueuse/core';
  42. import { dateFormat } from '@/utils/tool';
  43. import { useVModel } from '@vueuse/core';
  44. import CustomDatePicker from '../custom-date-picker';
  45. import { Fullscreen2Icon, SwapLeftIcon } from 'tdesign-icons-vue-next';
  46. import { useAppStore } from '@/store';
  47. import useFullscreen from '@/hooks/useFullscreen';
  48. const { switchFullscreen } = useFullscreen();
  49. const emit = defineEmits(['update:dateRange', 'timeChange']);
  50. const timeChange = (value) => {
  51. emit('timeChange', value);
  52. };
  53. const props = defineProps({
  54. title: String,
  55. dateRange: Array,
  56. hideTimePicker: Boolean,
  57. });
  58. const appStore = useAppStore();
  59. const range = useVModel(props, 'dateRange', emit);
  60. const currentTime = ref(Date.now());
  61. const updateTime = () => {
  62. currentTime.value = new Date().getTime();
  63. };
  64. const timeText = computed(() => {
  65. return dateFormat(currentTime.value, `yyyy年MM月dd日 HH:mm:ss`);
  66. });
  67. const weeks = ref([
  68. '星期天',
  69. '星期一',
  70. '星期二',
  71. '星期三',
  72. '星期四',
  73. '星期五',
  74. '星期六',
  75. ]);
  76. const getCurrentWeek = () => {
  77. return weeks.value[new Date().getDay()];
  78. };
  79. const { pause, resume, isActive } = useIntervalFn(
  80. () => {
  81. updateTime();
  82. },
  83. 1000,
  84. { immediate: false }
  85. );
  86. onMounted(() => {
  87. resume();
  88. });
  89. onBeforeUnmount(() => {
  90. pause();
  91. });
  92. </script>
  93. <style lang="less" scoped>
  94. .report-header {
  95. height: 57px;
  96. padding: 0 16px;
  97. background-color: #fff;
  98. border-bottom: 1px solid #e5e5e5;
  99. .title {
  100. color: #262626;
  101. font-size: 16px;
  102. font-weight: bold;
  103. }
  104. .right-box {
  105. .time-icon {
  106. height: 20px;
  107. margin-right: 10px;
  108. }
  109. & > p {
  110. color: #595959;
  111. font-size: 14px;
  112. }
  113. }
  114. }
  115. </style>