index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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. const d = dayjs(time);
  338. if (!d.isValid()) return time;
  339. const nowYear = dayjs().year();
  340. // 今年:01-22 10:22,往年:2025-12-22 10:22
  341. return d.year() === nowYear ? d.format('MM-DD HH:mm') : d.format('YYYY-MM-DD HH:mm');
  342. }
  343. // 快捷日期选择
  344. function handleQuickDate(type: string) {
  345. activeQuickBtn.value = type;
  346. const today = dayjs();
  347. switch (type) {
  348. case 'last3days':
  349. startDate.value = today.subtract(3, 'day').format('YYYY-MM-DD');
  350. endDate.value = today.format('YYYY-MM-DD');
  351. break;
  352. case 'last7days':
  353. startDate.value = today.subtract(7, 'day').format('YYYY-MM-DD');
  354. endDate.value = today.format('YYYY-MM-DD');
  355. break;
  356. case 'lastMonth':
  357. startDate.value = today.subtract(30, 'day').format('YYYY-MM-DD');
  358. endDate.value = today.format('YYYY-MM-DD');
  359. break;
  360. }
  361. }
  362. // 查询
  363. function handleQuery() {
  364. loadData();
  365. }
  366. // 加载账号列表
  367. async function loadAccountList() {
  368. try {
  369. const res = await request.get('/api/accounts');
  370. if (res.data.success) {
  371. accountList.value = (res.data.data || []).map((a: any) => ({
  372. id: a.id,
  373. nickname: a.nickname || a.username,
  374. }));
  375. }
  376. } catch (error) {
  377. console.error('加载账号列表失败:', error);
  378. }
  379. }
  380. // 加载分组列表
  381. async function loadGroups() {
  382. try {
  383. const res = await request.get('/api/accounts/groups');
  384. if (res.data.success) {
  385. accountGroups.value = res.data.data || [];
  386. }
  387. } catch (error) {
  388. console.error('加载分组失败:', error);
  389. }
  390. }
  391. // 加载数据
  392. async function loadData() {
  393. const userId = authStore.user?.id;
  394. if (!userId) return;
  395. loading.value = true;
  396. try {
  397. const queryParams = new URLSearchParams({
  398. user_id: userId.toString(),
  399. start_date: startDate.value,
  400. end_date: endDate.value,
  401. page: currentPage.value.toString(),
  402. page_size: pageSize.value.toString(),
  403. sort_by: sortBy.value,
  404. });
  405. if (selectedPlatform.value) {
  406. queryParams.append('platform', selectedPlatform.value);
  407. }
  408. if (selectedAccounts.value.length > 0) {
  409. queryParams.append('account_ids', selectedAccounts.value.join(','));
  410. }
  411. if (searchKeyword.value) {
  412. queryParams.append('keyword', searchKeyword.value);
  413. }
  414. const response = await fetch(`${PYTHON_API_URL}/work_day_statistics/works?${queryParams}`);
  415. const result = await response.json();
  416. if (result.success && result.data) {
  417. workList.value = result.data.works || [];
  418. totalWorks.value = result.data.total || 0;
  419. if (result.data.summary) {
  420. summaryData.value = result.data.summary;
  421. }
  422. }
  423. } catch (error) {
  424. console.error('加载作品数据失败:', error);
  425. } finally {
  426. loading.value = false;
  427. }
  428. }
  429. // 查看详情
  430. function handleView(row: WorkData) {
  431. selectedWork.value = row;
  432. drawerVisible.value = true;
  433. }
  434. // 导出数据
  435. function handleExport() {
  436. ElMessage.info('导出功能开发中');
  437. }
  438. onMounted(() => {
  439. loadAccountList();
  440. loadGroups();
  441. loadData();
  442. });
  443. </script>
  444. <style lang="scss" scoped>
  445. @use '@/styles/variables.scss' as *;
  446. .work-analytics {
  447. .filter-bar {
  448. display: flex;
  449. align-items: center;
  450. justify-content: space-between;
  451. margin-bottom: 20px;
  452. padding: 16px 20px;
  453. background: #fff;
  454. border-radius: $radius-lg;
  455. box-shadow: $shadow-sm;
  456. &.secondary {
  457. margin-bottom: 16px;
  458. padding: 12px 20px;
  459. }
  460. .filter-left {
  461. display: flex;
  462. align-items: center;
  463. gap: 12px;
  464. .filter-label {
  465. font-size: 14px;
  466. color: $text-regular;
  467. }
  468. .quick-btns {
  469. display: flex;
  470. gap: 8px;
  471. }
  472. }
  473. }
  474. .stats-row {
  475. display: grid;
  476. grid-template-columns: repeat(7, 1fr);
  477. gap: 0;
  478. margin-bottom: 20px;
  479. background: #fff;
  480. border-radius: $radius-lg;
  481. box-shadow: $shadow-sm;
  482. overflow: hidden;
  483. .stat-card {
  484. padding: 20px 16px;
  485. display: flex;
  486. align-items: center;
  487. gap: 12px;
  488. border-right: 1px solid #f0f0f0;
  489. &:last-child {
  490. border-right: none;
  491. }
  492. .stat-icon {
  493. width: 36px;
  494. height: 36px;
  495. background: $primary-color-light;
  496. border-radius: 8px;
  497. display: flex;
  498. align-items: center;
  499. justify-content: center;
  500. color: $primary-color;
  501. flex-shrink: 0;
  502. }
  503. .stat-info {
  504. .stat-label {
  505. font-size: 12px;
  506. color: $text-secondary;
  507. margin-bottom: 4px;
  508. white-space: nowrap;
  509. }
  510. .stat-value {
  511. font-size: 20px;
  512. font-weight: 600;
  513. color: $text-primary;
  514. }
  515. }
  516. }
  517. }
  518. .data-table {
  519. background: #fff;
  520. border-radius: $radius-lg;
  521. box-shadow: $shadow-sm;
  522. overflow: hidden;
  523. .account-cell {
  524. display: flex;
  525. align-items: center;
  526. gap: 8px;
  527. .account-name {
  528. font-weight: 500;
  529. color: $text-primary;
  530. }
  531. }
  532. .title-cell {
  533. .work-title {
  534. font-weight: 500;
  535. color: $primary-color;
  536. margin-bottom: 6px;
  537. cursor: pointer;
  538. &:hover {
  539. text-decoration: underline;
  540. }
  541. }
  542. .work-stats {
  543. display: flex;
  544. gap: 16px;
  545. font-size: 12px;
  546. color: $text-secondary;
  547. .stat-item {
  548. em {
  549. font-style: normal;
  550. color: $primary-color;
  551. margin-left: 2px;
  552. }
  553. }
  554. }
  555. }
  556. .publish-time {
  557. font-size: 13px;
  558. color: $text-secondary;
  559. }
  560. .pagination-wrapper {
  561. padding: 16px 20px;
  562. display: flex;
  563. justify-content: flex-end;
  564. }
  565. }
  566. }
  567. .work-detail {
  568. .detail-header {
  569. display: flex;
  570. gap: 16px;
  571. margin-bottom: 24px;
  572. .work-cover {
  573. width: 120px;
  574. height: 120px;
  575. border-radius: 8px;
  576. flex-shrink: 0;
  577. .cover-placeholder {
  578. width: 100%;
  579. height: 100%;
  580. background: #f3f4f6;
  581. display: flex;
  582. align-items: center;
  583. justify-content: center;
  584. color: #9ca3af;
  585. }
  586. }
  587. .header-info {
  588. flex: 1;
  589. h3 {
  590. margin: 0 0 12px 0;
  591. font-size: 16px;
  592. line-height: 1.5;
  593. }
  594. .meta-info {
  595. display: flex;
  596. align-items: center;
  597. gap: 12px;
  598. .publish-time {
  599. font-size: 13px;
  600. color: $text-secondary;
  601. }
  602. }
  603. }
  604. }
  605. .detail-stats {
  606. display: grid;
  607. grid-template-columns: repeat(5, 1fr);
  608. gap: 16px;
  609. margin-bottom: 24px;
  610. .stat-item {
  611. background: #f8fafc;
  612. border-radius: 12px;
  613. padding: 16px;
  614. text-align: center;
  615. .stat-value {
  616. font-size: 24px;
  617. font-weight: 600;
  618. color: $primary-color;
  619. }
  620. .stat-label {
  621. font-size: 13px;
  622. color: $text-secondary;
  623. margin-top: 4px;
  624. }
  625. }
  626. }
  627. .detail-content {
  628. h4 {
  629. margin: 0 0 12px 0;
  630. font-size: 15px;
  631. color: $text-primary;
  632. }
  633. .content-text {
  634. font-size: 14px;
  635. line-height: 1.8;
  636. color: $text-regular;
  637. white-space: pre-wrap;
  638. }
  639. }
  640. }
  641. @media (max-width: 1400px) {
  642. .work-analytics {
  643. .stats-row {
  644. grid-template-columns: repeat(4, 1fr);
  645. .stat-card {
  646. &:nth-child(4) {
  647. border-right: none;
  648. }
  649. &:nth-child(n+5) {
  650. border-top: 1px solid #f0f0f0;
  651. }
  652. }
  653. }
  654. }
  655. }
  656. @media (max-width: 1200px) {
  657. .work-analytics {
  658. .filter-bar {
  659. flex-direction: column;
  660. align-items: flex-start;
  661. gap: 12px;
  662. .filter-left {
  663. flex-wrap: wrap;
  664. }
  665. }
  666. .stats-row {
  667. grid-template-columns: repeat(3, 1fr);
  668. .stat-card {
  669. &:nth-child(3n) {
  670. border-right: none;
  671. }
  672. &:nth-child(n+4) {
  673. border-top: 1px solid #f0f0f0;
  674. }
  675. }
  676. }
  677. }
  678. }
  679. </style>