index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: index.vue
  4. * @Description: 特征词下载页
  5. * @Author: Cheney
  6. */
  7. import enLocale from 'element-plus/es/locale/lang/en';
  8. import dayjs from 'dayjs';
  9. import { usePagination } from '/@/utils/usePagination';
  10. import FileDownLoader from '/@/components/FileDowlander/index.vue';
  11. import * as api from './api';
  12. import { useElTableData } from '/@/utils/useElTableData';
  13. import { Download, Refresh } from '@element-plus/icons-vue';
  14. import { ElMessage } from 'element-plus';
  15. import { marketplaceIdMap } from '/@/views/featureWord/queryPage/marketplaceIdMap';
  16. const date = ref(calculateLastMonthFirstWeek());
  17. const dateRange = ref(date.value[0]);
  18. const loading = ref(false);
  19. const btnLoading = ref(false);
  20. const { tableData, total, currentPage, pageSize, handlePageChange } = usePagination(handleQuery);
  21. const filter = ref({
  22. search_term: 'zosi',
  23. marketplace_Ids: 'ATVPDKIKX0DER',
  24. report_type: 'WEEKLY',
  25. reportDate: date
  26. });
  27. onMounted(() => {
  28. handleQuery();
  29. });
  30. /**
  31. * 计算上个月第一周的日期
  32. */
  33. function calculateLastMonthFirstWeek() {
  34. const lastMonth = dayjs().subtract(1, 'month');
  35. const firstDayOfLastMonth = lastMonth.startOf('month');
  36. const firstSundayOfLastMonth = firstDayOfLastMonth.day(0); // 获取上个月第一个星期日
  37. const firstSaturdayOfLastMonth = firstSundayOfLastMonth.add(6, 'day'); // 获取对应的星期六
  38. return [
  39. firstSundayOfLastMonth.format('YYYY-MM-DD'),
  40. firstSaturdayOfLastMonth.format('YYYY-MM-DD')
  41. ];
  42. }
  43. /**
  44. * 判断当前日期类型 并 计算起始和结束日期
  45. */
  46. function calculateDate() {
  47. if (filter.value.report_type === 'WEEKLY') {
  48. date.value[0] = dateRange.value;
  49. date.value[1] = dayjs(dateRange.value).add(6, 'day').format('YYYY-MM-DD');
  50. } else if (filter.value.report_type === 'MONTHLY') {
  51. const selectedMonth = dayjs(dateRange.value);
  52. date.value[0] = selectedMonth.startOf('month').format('YYYY-MM-DD');
  53. date.value[1] = selectedMonth.endOf('month').format('YYYY-MM-DD');
  54. }
  55. }
  56. async function handleQuery() {
  57. const query = {
  58. ...filter.value,
  59. date_start: date.value[0],
  60. date_end: date.value[1],
  61. reportDate: undefined,
  62. page: currentPage.value,
  63. limit: pageSize.value,
  64. display: 'yes'
  65. };
  66. await useElTableData(api.wordDownload, query, tableData, total, loading);
  67. }
  68. function handleDownload(row: any) {
  69. const url = row.Url;
  70. const fileName = url.split('/').pop();
  71. const link = document.createElement('a');
  72. link.href = url;
  73. link.download = fileName;
  74. document.body.appendChild(link);
  75. link.click();
  76. document.body.removeChild(link);
  77. }
  78. async function queryDownload() {
  79. btnLoading.value = true;
  80. const query = {
  81. ...filter.value,
  82. date_start: date.value[0],
  83. date_end: date.value[1],
  84. reportDate: undefined,
  85. page: currentPage.value,
  86. limit: pageSize.value,
  87. };
  88. try {
  89. const response = await api.wordDownload(query);
  90. if (response.code === 2000) ElMessage.success(response.msg);
  91. } catch(error) {
  92. console.log('Error==>', error);
  93. } finally {
  94. btnLoading.value = false;
  95. await handleQuery();
  96. }
  97. }
  98. async function handleRefresh(row: any) {
  99. const query = {
  100. search_term: row.searchTerm,
  101. marketplace_Ids: row.marketplace_id,
  102. report_type: row.tableName.split('_').pop(),
  103. date_start: row.daterange.slice(0, 10),
  104. date_end: row.daterange.slice(10),
  105. };
  106. try {
  107. const { code, msg } = await useElTableData(api.wordDownload, query, tableData, total, loading);
  108. if (code === 2000) ElMessage.success({ message: msg, plain: true})
  109. } catch(error) {
  110. console.log('Error==>', error);
  111. }
  112. }
  113. </script>
  114. <template>
  115. <div class="py-2 px-2.5">
  116. <el-card body-class="flex justify-between gap-3.5" shadow="hover" style="border: none; margin-bottom: 10px">
  117. <div class="flex flex-wrap gap-7">
  118. <div>
  119. <span class="font-bold mr-2" style="color: #303133">关键词:</span>
  120. <el-input v-model="filter.search_term" style="width: 180px"></el-input>
  121. </div>
  122. <div>
  123. <span class="font-bold mr-2" style="color: #303133">市场ID:</span>
  124. <el-select v-model="filter.marketplace_Ids" style="width: 180px">
  125. <el-option v-for="item in marketplaceIdMap" :label="item.Country" :value="item.MarketplaceId"
  126. :key="item.MarketplaceId"></el-option>
  127. </el-select>
  128. </div>
  129. <div>
  130. <span class="font-bold mr-2" style="color: #303133">报告类型:</span>
  131. <el-select v-model="filter.report_type" style="width: 100px" @change="calculateDate">
  132. <el-option label="月度" value="MONTHLY"></el-option>
  133. <el-option label="周度" value="WEEKLY"></el-option>
  134. </el-select>
  135. </div>
  136. <div>
  137. <span class="font-bold mr-2" style="color: #303133">报告日期:</span>
  138. <el-config-provider v-if="filter.report_type === 'WEEKLY'" :locale="enLocale">
  139. <el-date-picker
  140. v-model="dateRange"
  141. :clearable="false"
  142. :disabled-date="(time: Date) => time > new Date()"
  143. :format="`${date[0]} To ${date[1]}`"
  144. type="week"
  145. value-format="YYYY-MM-DD"
  146. @change="calculateDate"
  147. />
  148. </el-config-provider>
  149. <el-date-picker
  150. v-else
  151. v-model="dateRange"
  152. :clearable="false"
  153. :disabled-date="(time: Date) => time > new Date()"
  154. :format="`${date[0]} To ${date[1]}`"
  155. type="month"
  156. value-format="YYYY-MM-DD"
  157. @change="calculateDate"
  158. />
  159. </div>
  160. </div>
  161. <div class="flex gap-3.5">
  162. <el-button @click="queryDownload" :icon="Download" plain round type="success" :loading="btnLoading">
  163. 文件下载
  164. </el-button>
  165. </div>
  166. </el-card>
  167. <el-card shadow="hover" style="border: none; margin-bottom: 10px">
  168. <el-table v-loading="loading" :data="tableData" height="600" style="width: 100%">
  169. <el-table-column align="center" type="index" width="60">
  170. <template #header>
  171. <span>序号</span>
  172. </template>
  173. </el-table-column>
  174. <el-table-column align="center" label="操作时间" prop="OperateTime">
  175. <template #default="{ row }">
  176. <span class="font-semibold">{{ row.OperateTime }}</span>
  177. </template>
  178. </el-table-column>
  179. <el-table-column align="center" label="关键词" prop="searchTerm">
  180. <template #default="{ row }">
  181. <span class="font-semibold">{{ row.searchTerm }}</span>
  182. </template>
  183. </el-table-column>
  184. <el-table-column align="center" label="日期范围" prop="daterange">
  185. <template #default="{ row }">
  186. <span class="font-semibold">{{ row.daterange.slice(0, 10) }} To {{ row.daterange.slice(10) }}</span>
  187. </template>
  188. </el-table-column>
  189. <el-table-column align="center" label="表名" prop="tableName">
  190. <template #default="{ row }">
  191. <span class="font-semibold">{{ row.tableName }}</span>
  192. </template>
  193. </el-table-column>
  194. <el-table-column align="center" label="状态" prop="State">
  195. <template #default="{ row }">
  196. <span class="font-semibold">{{ row.State }}</span>
  197. <el-button :icon="Download" class="ml-2" link type="success" :disabled="row.State!='success'" @click="handleDownload(row)"></el-button>
  198. <el-button :icon="Refresh" type="primary" link @click="handleRefresh(row)"></el-button>
  199. </template>
  200. </el-table-column>
  201. </el-table>
  202. <div class="mt-3.5 flex justify-end">
  203. <el-pagination
  204. v-model:current-page="currentPage"
  205. v-model:page-size="pageSize"
  206. :page-sizes="[10, 20, 30, 50, 100, 200]"
  207. :total="total"
  208. layout="sizes, prev, pager, next, total"
  209. @change="handlePageChange"/>
  210. </div>
  211. </el-card>
  212. </div>
  213. </template>
  214. <style scoped>
  215. </style>