From 0cf76cb7e63ae7f6aac9b7c6368aef6be653d283 Mon Sep 17 00:00:00 2001 From: mozzie Date: Thu, 1 Feb 2024 13:32:21 +0800 Subject: [PATCH] feat: api --- apps/api/src/app.service.ts | 18 +++++----- apps/viewer/src/Dashboard.tsx | 66 ++++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 29 deletions(-) diff --git a/apps/api/src/app.service.ts b/apps/api/src/app.service.ts index 2ae6ca1..8d0faf6 100644 --- a/apps/api/src/app.service.ts +++ b/apps/api/src/app.service.ts @@ -26,14 +26,14 @@ export class AppService { .orderBy('user_level', 'DESC') .getRawMany(); - for (const item of data) { - const { user_id } = item; - const msg_contents = await this.danmuRepository.find({ - select: ['msg_content'], - where: { user_id }, - }); - item.msg_contents = msg_contents; - } + // for (const item of data) { + // const { user_id } = item; + // const msg_contents = await this.danmuRepository.find({ + // select: ['msg_content'], + // where: { user_id }, + // }); + // item.msg_contents = msg_contents; + // } return data; } @@ -42,6 +42,6 @@ export class AppService { select: ['msg_content'], where: { user_id }, }); - return data; + return data.map((i) => i.msg_content); } } diff --git a/apps/viewer/src/Dashboard.tsx b/apps/viewer/src/Dashboard.tsx index a0d2e83..2eca401 100644 --- a/apps/viewer/src/Dashboard.tsx +++ b/apps/viewer/src/Dashboard.tsx @@ -1,9 +1,11 @@ import { useState, useEffect } from "react"; -import { Table, Button, Space } from "antd"; +import { Table, Button, Space, Tag } from "antd"; import axios from "axios"; export const Dashboard = () => { const [dataSource, setDatasource] = useState<[]>([]); + const [expandedRowData, setExpandedRowData] = useState({}); + const [loading, setLoading] = useState(false); useEffect(() => { const fetchData = async () => { @@ -24,18 +26,19 @@ export const Dashboard = () => { const columns = [ { - title: "昵称", - dataIndex: "nickName", - key: "nickName", + title: "#", + key: "index", + render: (text, record, index) => index + 1, // 添加序号列 }, { - title: "身份", - key: "base", - render: (record) => { + title: "昵称", + key: "nickName", + render: (record: any) => { return ( - {record.user_isAdmin == 1 ? "管" : ""} - {record.user_is_super_admin == 1 ? "超" : ""} + {record.user_nickName} + {record.user_isAdmin == 1 && } + {record.user_is_super_admin == 1 && 超管} ); }, @@ -50,17 +53,40 @@ export const Dashboard = () => { dataIndex: "user_fans_club_level", key: "user_fans_club_level", }, - { - title: "听大哥的话", - key: "msg_content", - render: (record) => { - return record.msg_contents.map((item) => { - const { msg_content } = item; - return
{msg_content}
; - }); - }, - }, ]; - return
; + const expandedRowRender = (record) => { + const { key: user_id } = record; + const data = expandedRowData[user_id]; + if (loading) return

正在加载数据...

; + if (data) + return ( + <> + {data.map((i, index) => ( +
{i}
+ ))} + + ); + return null; + }; + + const onExpand = async (expanded, record) => { + const { key: user_id } = record; + if (user_id in expandedRowData || !expanded) return; + setLoading(true); + const { data } = await axios.get(`/api/msg_content/${user_id}`); + setExpandedRowData((p) => ({ ...p, [user_id]: data })); + setLoading(false); + }; + + return ( +
+ ); };