index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: index.vue
  4. * @Description: 特征词查询页
  5. * @Author: Cheney
  6. */
  7. import { Download, Search } from '@element-plus/icons-vue';
  8. import WeightTable from './WeightTable.vue';
  9. import emitter from '/@/utils/emitter';
  10. import { onMounted, provide, ref } from 'vue';
  11. import dayjs from 'dayjs';
  12. import _ from 'lodash';
  13. import enLocale from 'element-plus/es/locale/lang/en';
  14. import FeatureWordTable from '/@/views/featureWord/queryPage/FeatureWordTable.vue';
  15. const date = ref(calculateLastMonthFirstWeek());
  16. const dateRange = ref(date.value[0]);
  17. const filter = ref({
  18. searchTerm: 'zosi',
  19. marketIds: 'ATVPDKIKX0DER',
  20. reportType: 'WEEKLY',
  21. reportDate: date
  22. });
  23. provide('filter', filter);
  24. onMounted(() => {
  25. handleQuery();
  26. });
  27. /**
  28. * 计算上个月第一周的日期
  29. */
  30. function calculateLastMonthFirstWeek() {
  31. const lastMonth = dayjs().subtract(1, 'month');
  32. const firstDayOfLastMonth = lastMonth.startOf('month');
  33. const firstSundayOfLastMonth = firstDayOfLastMonth.day(0); // 获取上个月第一个星期日
  34. const firstSaturdayOfLastMonth = firstSundayOfLastMonth.add(6, 'day'); // 获取对应的星期六
  35. return [
  36. firstSundayOfLastMonth.format('YYYY-MM-DD'),
  37. firstSaturdayOfLastMonth.format('YYYY-MM-DD')
  38. ];
  39. }
  40. /**
  41. * 判断当前日期类型 并 计算起始和结束日期
  42. */
  43. function calculateDate() {
  44. if (filter.value.reportType === 'WEEKLY') {
  45. date.value[0] = dateRange.value;
  46. date.value[1] = dayjs(dateRange.value).add(6, 'day').format('YYYY-MM-DD');
  47. } else if (filter.value.reportType === 'MONTHLY') {
  48. const selectedMonth = dayjs(dateRange.value);
  49. date.value[0] = selectedMonth.startOf('month').format('YYYY-MM-DD');
  50. date.value[1] = selectedMonth.endOf('month').format('YYYY-MM-DD');
  51. }
  52. }
  53. const throttledEmit = _.throttle(() => {
  54. emitter.emit('QueryPage-query');
  55. }, 3000);
  56. function handleQuery() {
  57. throttledEmit();
  58. }
  59. function handleDownload() {
  60. }
  61. </script>
  62. <template>
  63. <div class="py-2 px-2.5">
  64. <el-card body-class="flex justify-between gap-3.5" shadow="hover" style="border: none; margin-bottom: 10px">
  65. <div class="flex flex-wrap gap-7">
  66. <div>
  67. <span class="font-bold mr-2" style="color: #303133">关键词:</span>
  68. <el-input v-model="filter.searchTerm" style="width: 180px"></el-input>
  69. </div>
  70. <div>
  71. <span class="font-bold mr-2" style="color: #303133">市场ID:</span>
  72. <el-input v-model="filter.marketIds" style="width: 180px"></el-input>
  73. </div>
  74. <div>
  75. <span class="font-bold mr-2" style="color: #303133">报告类型:</span>
  76. <el-select v-model="filter.reportType" style="width: 100px" @change="calculateDate">
  77. <el-option label="月度" value="MONTHLY"></el-option>
  78. <el-option label="周度" value="WEEKLY"></el-option>
  79. </el-select>
  80. </div>
  81. <div>
  82. <span class="font-bold mr-2" style="color: #303133">报告日期:</span>
  83. <el-config-provider v-if="filter.reportType === 'WEEKLY'" :locale="enLocale">
  84. <el-date-picker
  85. v-model="dateRange"
  86. :clearable="false"
  87. :disabled-date="(time: Date) => time > new Date()"
  88. :format="`${date[0]} To ${date[1]}`"
  89. type="week"
  90. value-format="YYYY-MM-DD"
  91. @change="calculateDate"
  92. />
  93. </el-config-provider>
  94. <el-date-picker
  95. v-else
  96. v-model="dateRange"
  97. :clearable="false"
  98. :disabled-date="(time: Date) => time > new Date()"
  99. :format="`${date[0]} To ${date[1]}`"
  100. type="month"
  101. value-format="YYYY-MM-DD"
  102. @change="calculateDate"
  103. />
  104. </div>
  105. </div>
  106. <div class="flex gap-3.5">
  107. <el-button :icon="Search" plain type="primary" @click="handleQuery">查询</el-button>
  108. <el-button :icon="Download" plain round type="success" @click="handleDownload">下载管理</el-button>
  109. </div>
  110. </el-card>
  111. <WeightTable/>
  112. <FeatureWordTable/>
  113. </div>
  114. </template>
  115. <style scoped></style>