index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. <template>
  2. <div class="work-analytics">
  3. <!-- 顶部筛选栏 -->
  4. <div class="filter-bar">
  5. <div class="filter-left">
  6. <span class="filter-label">开始时间</span>
  7. <el-date-picker
  8. v-model="startDate"
  9. type="date"
  10. placeholder="选择日期"
  11. format="YYYY-MM-DD"
  12. value-format="YYYY-MM-DD"
  13. style="width: 140px"
  14. />
  15. <span class="filter-label">结束时间</span>
  16. <el-date-picker
  17. v-model="endDate"
  18. type="date"
  19. placeholder="选择日期"
  20. format="YYYY-MM-DD"
  21. value-format="YYYY-MM-DD"
  22. style="width: 140px"
  23. />
  24. <div class="quick-btns">
  25. <el-button
  26. v-for="btn in quickDateBtns"
  27. :key="btn.value"
  28. :type="activeQuickBtn === btn.value ? 'primary' : 'default'"
  29. size="small"
  30. @click="handleQuickDate(btn.value)"
  31. >
  32. {{ btn.label }}
  33. </el-button>
  34. </div>
  35. <el-select
  36. v-model="selectedAccounts"
  37. multiple
  38. collapse-tags
  39. collapse-tags-tooltip
  40. placeholder="选择账号"
  41. style="width: 160px"
  42. >
  43. <el-option
  44. v-for="account in accountList"
  45. :key="account.id"
  46. :label="account.nickname"
  47. :value="account.id"
  48. />
  49. </el-select>
  50. <el-button type="primary" @click="handleQuery">查询</el-button>
  51. </div>
  52. <div class="filter-right">
  53. <el-button @click="handleExport">导出数据</el-button>
  54. </div>
  55. </div>
  56. <!-- 统计卡片 -->
  57. <div class="stats-row">
  58. <div class="stat-card" v-for="(item, index) in summaryStats" :key="index">
  59. <div class="stat-icon">
  60. <el-icon :size="18"><component :is="item.icon" /></el-icon>
  61. </div>
  62. <div class="stat-info">
  63. <div class="stat-label">{{ item.label }}</div>
  64. <div class="stat-value">{{ item.value }}</div>
  65. </div>
  66. </div>
  67. </div>
  68. <!-- 第二行筛选 -->
  69. <div class="filter-bar secondary">
  70. <div class="filter-left">
  71. <el-select v-model="selectedGroup" placeholder="全部" clearable style="width: 120px">
  72. <el-option label="全部" value="" />
  73. <el-option
  74. v-for="group in accountGroups"
  75. :key="group.id"
  76. :label="group.name"
  77. :value="group.id"
  78. />
  79. </el-select>
  80. <el-select v-model="selectedPlatform" placeholder="全部平台" clearable style="width: 120px">
  81. <el-option label="全部平台" value="" />
  82. <el-option
  83. v-for="platform in availablePlatforms"
  84. :key="platform.value"
  85. :label="platform.label"
  86. :value="platform.value"
  87. />
  88. </el-select>
  89. <el-select v-model="sortBy" style="width: 160px">
  90. <el-option label="按发布时间顺序排列" value="publish_desc" />
  91. <el-option label="按发布时间倒序排列" value="publish_asc" />
  92. <el-option label="按阅读量排序" value="views_desc" />
  93. <el-option label="按点赞量排序" value="likes_desc" />
  94. <el-option label="按评论量排序" value="comments_desc" />
  95. </el-select>
  96. <el-input
  97. v-model="searchKeyword"
  98. placeholder="请输入要搜索的作品标题"
  99. clearable
  100. style="width: 240px"
  101. @clear="handleQuery"
  102. @keyup.enter="handleQuery"
  103. >
  104. <template #prefix>
  105. <el-icon><Search /></el-icon>
  106. </template>
  107. </el-input>
  108. </div>
  109. </div>
  110. <!-- 数据表格 -->
  111. <div class="data-table">
  112. <el-table :data="workList" v-loading="loading" stripe>
  113. <el-table-column label="账号" width="150">
  114. <template #default="{ row }">
  115. <div class="account-cell">
  116. <el-avatar :size="32" :src="row.accountAvatar">
  117. {{ row.accountName?.[0] }}
  118. </el-avatar>
  119. <span class="account-name">{{ row.accountName }}</span>
  120. </div>
  121. </template>
  122. </el-table-column>
  123. <el-table-column label="平台" width="100" align="center">
  124. <template #default="{ row }">
  125. <el-tag size="small" :type="getPlatformTagType(row.platform)">
  126. {{ getPlatformName(row.platform) }}
  127. </el-tag>
  128. </template>
  129. </el-table-column>
  130. <el-table-column label="标题" min-width="300">
  131. <template #default="{ row }">
  132. <div class="title-cell">
  133. <div class="work-title">{{ row.title }}</div>
  134. <div class="work-stats">
  135. <span class="stat-item">推荐 <em>{{ row.recommendCount ?? '--' }}</em></span>
  136. <span class="stat-item">阅读 <em>{{ row.viewsCount ?? 0 }}</em></span>
  137. <span class="stat-item">评论 <em>{{ row.commentsCount ?? 0 }}</em></span>
  138. <span class="stat-item">分享 <em>{{ row.sharesCount ?? 0 }}</em></span>
  139. <span class="stat-item">收藏 <em>{{ row.collectsCount ?? 0 }}</em></span>
  140. <span class="stat-item">点赞 <em>{{ row.likesCount ?? 0 }}</em></span>
  141. </div>
  142. </div>
  143. </template>
  144. </el-table-column>
  145. <el-table-column prop="workType" label="类型" width="80" align="center">
  146. <template #default="{ row }">
  147. <span>{{ row.workType || '动态' }}</span>
  148. </template>
  149. </el-table-column>
  150. <el-table-column prop="publishTime" label="发布时间" width="160" align="center">
  151. <template #default="{ row }">
  152. <span class="publish-time">{{ formatTime(row.publishTime) }}</span>
  153. </template>
  154. </el-table-column>
  155. <el-table-column label="操作" width="80" align="center" fixed="right">
  156. <template #default="{ row }">
  157. <el-button type="primary" link @click="handleView(row)">
  158. 查看
  159. </el-button>
  160. </template>
  161. </el-table-column>
  162. </el-table>
  163. <!-- 分页 -->
  164. <div class="pagination-wrapper">
  165. <el-pagination
  166. v-model:current-page="currentPage"
  167. v-model:page-size="pageSize"
  168. :total="totalWorks"
  169. :page-sizes="[10, 20, 50, 100]"
  170. layout="total, sizes, prev, pager, next, jumper"
  171. @size-change="handleQuery"
  172. @current-change="handleQuery"
  173. />
  174. </div>
  175. </div>
  176. <!-- 作品详情抽屉 -->
  177. <el-drawer v-model="drawerVisible" title="作品详情" size="50%">
  178. <div v-if="selectedWork" class="work-detail">
  179. <!-- 作品基本信息 -->
  180. <div class="detail-header">
  181. <el-image
  182. :src="selectedWork.coverUrl"
  183. class="work-cover"
  184. fit="cover"
  185. >
  186. <template #error>
  187. <div class="cover-placeholder">
  188. <el-icon :size="32"><Picture /></el-icon>
  189. </div>
  190. </template>
  191. </el-image>
  192. <div class="header-info">
  193. <h3>{{ selectedWork.title }}</h3>
  194. <div class="meta-info">
  195. <el-tag size="small">{{ getPlatformName(selectedWork.platform) }}</el-tag>
  196. <span class="publish-time">发布于 {{ formatTime(selectedWork.publishTime) }}</span>
  197. </div>
  198. </div>
  199. </div>
  200. <!-- 数据统计 -->
  201. <div class="detail-stats">
  202. <div class="stat-item">
  203. <div class="stat-value">{{ selectedWork.viewsCount || 0 }}</div>
  204. <div class="stat-label">阅读</div>
  205. </div>
  206. <div class="stat-item">
  207. <div class="stat-value">{{ selectedWork.likesCount || 0 }}</div>
  208. <div class="stat-label">点赞</div>
  209. </div>
  210. <div class="stat-item">
  211. <div class="stat-value">{{ selectedWork.commentsCount || 0 }}</div>
  212. <div class="stat-label">评论</div>
  213. </div>
  214. <div class="stat-item">
  215. <div class="stat-value">{{ selectedWork.collectsCount || 0 }}</div>
  216. <div class="stat-label">收藏</div>
  217. </div>
  218. <div class="stat-item">
  219. <div class="stat-value">{{ selectedWork.sharesCount || 0 }}</div>
  220. <div class="stat-label">分享</div>
  221. </div>
  222. </div>
  223. <!-- 作品内容 -->
  224. <div class="detail-content" v-if="selectedWork.content">
  225. <h4>作品内容</h4>
  226. <div class="content-text">{{ selectedWork.content }}</div>
  227. </div>
  228. </div>
  229. </el-drawer>
  230. </div>
  231. </template>
  232. <script setup lang="ts">
  233. import { ref, computed, onMounted } from 'vue';
  234. import { Search, Picture, Document, View, ChatDotRound, Share, Star, Pointer } from '@element-plus/icons-vue';
  235. import { PLATFORMS } from '@media-manager/shared';
  236. import type { PlatformType } from '@media-manager/shared';
  237. import { useAuthStore } from '@/stores/auth';
  238. import { ElMessage } from 'element-plus';
  239. import dayjs from 'dayjs';
  240. import request from '@/api/request';
  241. const PYTHON_API_URL = 'http://localhost:5005';
  242. const authStore = useAuthStore();
  243. const loading = ref(false);
  244. // 日期筛选
  245. const startDate = ref(dayjs().subtract(30, 'day').format('YYYY-MM-DD'));
  246. const endDate = ref(dayjs().format('YYYY-MM-DD'));
  247. const activeQuickBtn = ref('lastMonth');
  248. // 快捷日期按钮
  249. const quickDateBtns = [
  250. { label: '近三天', value: 'last3days' },
  251. { label: '近七天', value: 'last7days' },
  252. { label: '近一个月', value: 'lastMonth' },
  253. ];
  254. // 账号选择
  255. const selectedAccounts = ref<number[]>([]);
  256. const accountList = ref<{ id: number; nickname: string }[]>([]);
  257. // 分组和平台筛选
  258. const selectedGroup = ref<number | ''>('');
  259. const selectedPlatform = ref<PlatformType | ''>('');
  260. const sortBy = ref('publish_desc');
  261. const searchKeyword = ref('');
  262. // 分组列表
  263. interface AccountGroup {
  264. id: number;
  265. name: string;
  266. }
  267. const accountGroups = ref<AccountGroup[]>([]);
  268. // 可用平台
  269. const availablePlatforms = computed(() => {
  270. return Object.entries(PLATFORMS).map(([key, value]) => ({
  271. value: key as PlatformType,
  272. label: value.name,
  273. }));
  274. });
  275. // 分页
  276. const currentPage = ref(1);
  277. const pageSize = ref(20);
  278. const totalWorks = ref(0);
  279. // 汇总统计
  280. const summaryData = ref({
  281. totalWorks: 0,
  282. recommendCount: 0,
  283. viewsCount: 0,
  284. commentsCount: 0,
  285. sharesCount: 0,
  286. collectsCount: 0,
  287. likesCount: 0,
  288. });
  289. // 统计卡片数据
  290. const summaryStats = computed(() => [
  291. { label: '作品总数', value: summaryData.value.totalWorks, icon: Document },
  292. { label: '推荐量', value: summaryData.value.recommendCount, icon: Pointer },
  293. { label: '播放(阅读)量', value: summaryData.value.viewsCount, icon: View },
  294. { label: '评论量', value: summaryData.value.commentsCount, icon: ChatDotRound },
  295. { label: '分享量', value: summaryData.value.sharesCount, icon: Share },
  296. { label: '收藏量', value: summaryData.value.collectsCount, icon: Star },
  297. { label: '点赞量', value: summaryData.value.likesCount, icon: Pointer },
  298. ]);
  299. // 作品数据
  300. interface WorkData {
  301. id: number;
  302. title: string;
  303. coverUrl: string;
  304. content: string;
  305. platform: PlatformType;
  306. accountId: number;
  307. accountName: string;
  308. accountAvatar: string;
  309. workType: string;
  310. publishTime: string;
  311. recommendCount: number | null;
  312. viewsCount: number;
  313. commentsCount: number;
  314. sharesCount: number;
  315. collectsCount: number;
  316. likesCount: number;
  317. }
  318. const workList = ref<WorkData[]>([]);
  319. // 抽屉相关
  320. const drawerVisible = ref(false);
  321. const selectedWork = ref<WorkData | null>(null);
  322. function getPlatformName(platform: PlatformType) {
  323. return PLATFORMS[platform]?.name || platform;
  324. }
  325. function getPlatformTagType(platform: PlatformType) {
  326. const typeMap: Record<string, 'primary' | 'success' | 'warning' | 'danger' | 'info'> = {
  327. douyin: 'danger',
  328. xiaohongshu: 'danger',
  329. bilibili: 'primary',
  330. kuaishou: 'warning',
  331. weixin: 'success',
  332. };
  333. return typeMap[platform] || 'info';
  334. }
  335. function formatTime(time: string) {
  336. if (!time) return '-';
  337. return dayjs(time).format('YYYY-MM-DD HH:mm:ss');
  338. }
  339. // 快捷日期选择
  340. function handleQuickDate(type: string) {
  341. activeQuickBtn.value = type;
  342. const today = dayjs();
  343. switch (type) {
  344. case 'last3days':
  345. startDate.value = today.subtract(3, 'day').format('YYYY-MM-DD');
  346. endDate.value = today.format('YYYY-MM-DD');
  347. break;
  348. case 'last7days':
  349. startDate.value = today.subtract(7, 'day').format('YYYY-MM-DD');
  350. endDate.value = today.format('YYYY-MM-DD');
  351. break;
  352. case 'lastMonth':
  353. startDate.value = today.subtract(30, 'day').format('YYYY-MM-DD');
  354. endDate.value = today.format('YYYY-MM-DD');
  355. break;
  356. }
  357. }
  358. // 查询
  359. function handleQuery() {
  360. loadData();
  361. }
  362. // 加载账号列表
  363. async function loadAccountList() {
  364. try {
  365. const res = await request.get('/accounts');
  366. if (res.data.success) {
  367. accountList.value = (res.data.data || []).map((a: any) => ({
  368. id: a.id,
  369. nickname: a.nickname || a.username,
  370. }));
  371. }
  372. } catch (error) {
  373. console.error('加载账号列表失败:', error);
  374. }
  375. }
  376. // 加载分组列表
  377. async function loadGroups() {
  378. try {
  379. const res = await request.get('/accounts/groups');
  380. if (res.data.success) {
  381. accountGroups.value = res.data.data || [];
  382. }
  383. } catch (error) {
  384. console.error('加载分组失败:', error);
  385. }
  386. }
  387. // 加载数据
  388. async function loadData() {
  389. const userId = authStore.user?.id;
  390. if (!userId) return;
  391. loading.value = true;
  392. try {
  393. const queryParams = new URLSearchParams({
  394. user_id: userId.toString(),
  395. start_date: startDate.value,
  396. end_date: endDate.value,
  397. page: currentPage.value.toString(),
  398. page_size: pageSize.value.toString(),
  399. sort_by: sortBy.value,
  400. });
  401. if (selectedPlatform.value) {
  402. queryParams.append('platform', selectedPlatform.value);
  403. }
  404. if (selectedAccounts.value.length > 0) {
  405. queryParams.append('account_ids', selectedAccounts.value.join(','));
  406. }
  407. if (searchKeyword.value) {
  408. queryParams.append('keyword', searchKeyword.value);
  409. }
  410. const response = await fetch(`${PYTHON_API_URL}/work_day_statistics/works?${queryParams}`);
  411. const result = await response.json();
  412. if (result.success && result.data) {
  413. workList.value = result.data.works || [];
  414. totalWorks.value = result.data.total || 0;
  415. if (result.data.summary) {
  416. summaryData.value = result.data.summary;
  417. }
  418. }
  419. } catch (error) {
  420. console.error('加载作品数据失败:', error);
  421. } finally {
  422. loading.value = false;
  423. }
  424. }
  425. // 查看详情
  426. function handleView(row: WorkData) {
  427. selectedWork.value = row;
  428. drawerVisible.value = true;
  429. }
  430. // 导出数据
  431. function handleExport() {
  432. ElMessage.info('导出功能开发中');
  433. }
  434. onMounted(() => {
  435. loadAccountList();
  436. loadGroups();
  437. loadData();
  438. });
  439. </script>
  440. <style lang="scss" scoped>
  441. @use '@/styles/variables.scss' as *;
  442. .work-analytics {
  443. .filter-bar {
  444. display: flex;
  445. align-items: center;
  446. justify-content: space-between;
  447. margin-bottom: 20px;
  448. padding: 16px 20px;
  449. background: #fff;
  450. border-radius: $radius-lg;
  451. box-shadow: $shadow-sm;
  452. &.secondary {
  453. margin-bottom: 16px;
  454. padding: 12px 20px;
  455. }
  456. .filter-left {
  457. display: flex;
  458. align-items: center;
  459. gap: 12px;
  460. .filter-label {
  461. font-size: 14px;
  462. color: $text-regular;
  463. }
  464. .quick-btns {
  465. display: flex;
  466. gap: 8px;
  467. }
  468. }
  469. }
  470. .stats-row {
  471. display: grid;
  472. grid-template-columns: repeat(7, 1fr);
  473. gap: 0;
  474. margin-bottom: 20px;
  475. background: #fff;
  476. border-radius: $radius-lg;
  477. box-shadow: $shadow-sm;
  478. overflow: hidden;
  479. .stat-card {
  480. padding: 20px 16px;
  481. display: flex;
  482. align-items: center;
  483. gap: 12px;
  484. border-right: 1px solid #f0f0f0;
  485. &:last-child {
  486. border-right: none;
  487. }
  488. .stat-icon {
  489. width: 36px;
  490. height: 36px;
  491. background: $primary-color-light;
  492. border-radius: 8px;
  493. display: flex;
  494. align-items: center;
  495. justify-content: center;
  496. color: $primary-color;
  497. flex-shrink: 0;
  498. }
  499. .stat-info {
  500. .stat-label {
  501. font-size: 12px;
  502. color: $text-secondary;
  503. margin-bottom: 4px;
  504. white-space: nowrap;
  505. }
  506. .stat-value {
  507. font-size: 20px;
  508. font-weight: 600;
  509. color: $text-primary;
  510. }
  511. }
  512. }
  513. }
  514. .data-table {
  515. background: #fff;
  516. border-radius: $radius-lg;
  517. box-shadow: $shadow-sm;
  518. overflow: hidden;
  519. .account-cell {
  520. display: flex;
  521. align-items: center;
  522. gap: 8px;
  523. .account-name {
  524. font-weight: 500;
  525. color: $text-primary;
  526. }
  527. }
  528. .title-cell {
  529. .work-title {
  530. font-weight: 500;
  531. color: $primary-color;
  532. margin-bottom: 6px;
  533. cursor: pointer;
  534. &:hover {
  535. text-decoration: underline;
  536. }
  537. }
  538. .work-stats {
  539. display: flex;
  540. gap: 16px;
  541. font-size: 12px;
  542. color: $text-secondary;
  543. .stat-item {
  544. em {
  545. font-style: normal;
  546. color: $primary-color;
  547. margin-left: 2px;
  548. }
  549. }
  550. }
  551. }
  552. .publish-time {
  553. font-size: 13px;
  554. color: $text-secondary;
  555. }
  556. .pagination-wrapper {
  557. padding: 16px 20px;
  558. display: flex;
  559. justify-content: flex-end;
  560. }
  561. }
  562. }
  563. .work-detail {
  564. .detail-header {
  565. display: flex;
  566. gap: 16px;
  567. margin-bottom: 24px;
  568. .work-cover {
  569. width: 120px;
  570. height: 120px;
  571. border-radius: 8px;
  572. flex-shrink: 0;
  573. .cover-placeholder {
  574. width: 100%;
  575. height: 100%;
  576. background: #f3f4f6;
  577. display: flex;
  578. align-items: center;
  579. justify-content: center;
  580. color: #9ca3af;
  581. }
  582. }
  583. .header-info {
  584. flex: 1;
  585. h3 {
  586. margin: 0 0 12px 0;
  587. font-size: 16px;
  588. line-height: 1.5;
  589. }
  590. .meta-info {
  591. display: flex;
  592. align-items: center;
  593. gap: 12px;
  594. .publish-time {
  595. font-size: 13px;
  596. color: $text-secondary;
  597. }
  598. }
  599. }
  600. }
  601. .detail-stats {
  602. display: grid;
  603. grid-template-columns: repeat(5, 1fr);
  604. gap: 16px;
  605. margin-bottom: 24px;
  606. .stat-item {
  607. background: #f8fafc;
  608. border-radius: 12px;
  609. padding: 16px;
  610. text-align: center;
  611. .stat-value {
  612. font-size: 24px;
  613. font-weight: 600;
  614. color: $primary-color;
  615. }
  616. .stat-label {
  617. font-size: 13px;
  618. color: $text-secondary;
  619. margin-top: 4px;
  620. }
  621. }
  622. }
  623. .detail-content {
  624. h4 {
  625. margin: 0 0 12px 0;
  626. font-size: 15px;
  627. color: $text-primary;
  628. }
  629. .content-text {
  630. font-size: 14px;
  631. line-height: 1.8;
  632. color: $text-regular;
  633. white-space: pre-wrap;
  634. }
  635. }
  636. }
  637. @media (max-width: 1400px) {
  638. .work-analytics {
  639. .stats-row {
  640. grid-template-columns: repeat(4, 1fr);
  641. .stat-card {
  642. &:nth-child(4) {
  643. border-right: none;
  644. }
  645. &:nth-child(n+5) {
  646. border-top: 1px solid #f0f0f0;
  647. }
  648. }
  649. }
  650. }
  651. }
  652. @media (max-width: 1200px) {
  653. .work-analytics {
  654. .filter-bar {
  655. flex-direction: column;
  656. align-items: flex-start;
  657. gap: 12px;
  658. .filter-left {
  659. flex-wrap: wrap;
  660. }
  661. }
  662. .stats-row {
  663. grid-template-columns: repeat(3, 1fr);
  664. .stat-card {
  665. &:nth-child(3n) {
  666. border-right: none;
  667. }
  668. &:nth-child(n+4) {
  669. border-top: 1px solid #f0f0f0;
  670. }
  671. }
  672. }
  673. }
  674. }
  675. </style>