From 50dfe31d3285dbe4501453713b571d116c795db9 Mon Sep 17 00:00:00 2001 From: mozzie Date: Thu, 23 Mar 2023 12:17:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86&?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E5=9B=BD=E4=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/src/api/index.ts | 6 +- apps/admin/src/view/User/index.tsx | 189 +++++++++++++++++- apps/server/src/biz/code.ts | 1 + .../src/controller/course.controller.ts | 4 +- apps/server/src/controller/user.controller.ts | 33 ++- apps/server/src/entity/user.entity.ts | 3 + apps/server/src/service/user.service.ts | 8 + apps/web/src/api/axios.ts | 6 + apps/web/src/router/Guard.tsx | 7 +- apps/web/src/store/user.store.ts | 8 +- apps/web/src/util/cookie.ts | 10 + apps/web/src/view/CourseDetail/index.tsx | 72 +++---- 12 files changed, 300 insertions(+), 47 deletions(-) create mode 100644 apps/web/src/util/cookie.ts diff --git a/apps/admin/src/api/index.ts b/apps/admin/src/api/index.ts index e16ff82..cc85475 100644 --- a/apps/admin/src/api/index.ts +++ b/apps/admin/src/api/index.ts @@ -39,7 +39,7 @@ export const selectChapterList = ({ chapter_course_id: string; }) => R.post("/api/course/chapter/select", { chapter_course_id }); -export const updateChapter = (chapter: any) => +export const updateChapter = (chapter: IChapter) => R.post("/api/course/chapter/update", chapter); export const removeCourse = (course: ICourseBasic) => @@ -50,3 +50,7 @@ export const createChapter = (chapterList: IChapter[]) => export const removeChapter = (chapter: IChapter) => R.post("/api/course/chapter/remove", chapter); + +export const selectUserList = () => R.post("/api/user/admin/select/all"); + +export const updateUser = (user: any) => R.post("/api/user/admin/update", user); diff --git a/apps/admin/src/view/User/index.tsx b/apps/admin/src/view/User/index.tsx index 9487f4b..beef235 100644 --- a/apps/admin/src/view/User/index.tsx +++ b/apps/admin/src/view/User/index.tsx @@ -1,5 +1,192 @@ +import { + CheckOutlined, + EditOutlined, + SketchOutlined, + StopOutlined, + UserSwitchOutlined, +} from "@ant-design/icons"; +import { + Button, + Card, + DatePicker, + Popconfirm, + Space, + Table, + Tooltip, +} from "antd"; +import { RangePickerProps } from "antd/es/date-picker"; +import dayjs from "dayjs"; +import { useState } from "react"; +import { selectUserList, updateUser } from "../../api"; +import { useMount } from "../../hooks"; + +interface IEditUser { + key: string; + value: any; +} + +const defaultEditUser: IEditUser = { + key: "", + value: "", +}; + const User = () => { - return
用户据
; + const [userList, setUserList] = useState([]); + const [editUser, setEditUser] = useState(defaultEditUser); + + const onConfirmEditUser = (user: any) => { + updateUser(user).then((res: any) => { + if (res?.code === 10000) renderUserList(); + }); + }; + + const disabledDate: RangePickerProps["disabledDate"] = (current) => { + return current && current < dayjs().endOf("day"); + }; + + const columns = [ + { + title: "id", + dataIndex: "id", + key: "id", + }, + { + title: "用户", + dataIndex: "user_login", + key: "user_login", + }, + { + title: "创建时间", + dataIndex: "user_create_time", + key: "user_create_time", + render: (_: any, record: any) => { + return ( + + {dayjs(+record.user_create_time).format("YYYY-MM-DD HH:mm:ss")} + + ); + }, + }, + { + title: "状态", + dataIndex: "user_status", + key: "user_status", + render: (_: any, record: any) => { + return record.user_status ? ( + + ) : ( + "-" + ); + }, + }, + { + title: "订阅", + dataIndex: "user_sub", + key: "user_sub", + render: (_: any, record: any) => { + return record.user_sub ? ( + + ) : ( + "-" + ); + }, + }, + { + title: "订阅到期", + dataIndex: "user_sub_expired", + key: "user_sub_expired", + render: (_: any, record: any) => { + return record.user_sub ? ( + + + {dayjs(+record.user_sub_expired).format("YYYY-MM-DD HH:mm:ss")} + + { + setEditUser({ + key: "user_sub_expired", + value: "" + new Date(date).getTime(), + }); + }} + presets={[ + { label: "订阅 - 年", value: dayjs().add(1, "year") }, + { label: "订阅 - 季度", value: dayjs().add(3, "month") }, + { label: "订阅 - 月", value: dayjs().add(1, "month") }, + ]} + disabledDate={disabledDate} + format="YYYY-MM-DD HH:mm:ss" + showTime={{ defaultValue: dayjs("00:00:00", "HH:mm:ss") }} + /> + } + onConfirm={() => + onConfirmEditUser({ ...record, [editUser.key]: editUser.value }) + } + okText="确定" + cancelText="取消" + > +