init
This commit is contained in:
3
.env.example
Normal file
3
.env.example
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
DATABASE_URL=mysql+pymysql://user:password@127.0.0.1:3306/pt_manager
|
||||||
|
JWT_SECRET_KEY=eVhIHuh1p655xZW76O8qusmIqdLiW9wj
|
||||||
|
SECRET_KEY=eVhIHuh1p655xZW76O8qusmIqdLiW9wj
|
||||||
124
.gitignore
vendored
Normal file
124
.gitignore
vendored
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
# ===================================================================
|
||||||
|
# .gitignore for a FastAPI (Python) + Vue.js (Node.js) Project
|
||||||
|
# ===================================================================
|
||||||
|
*.db
|
||||||
|
.vscode
|
||||||
|
**/config.json
|
||||||
|
# --- General ---
|
||||||
|
#忽略所有 .env 文件,只提交 .env.example 模板
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
|
||||||
|
#日志文件
|
||||||
|
*.log
|
||||||
|
*.log*
|
||||||
|
|
||||||
|
#临时文件
|
||||||
|
*~
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
|
||||||
|
# ===================================================================
|
||||||
|
# Python / FastAPI (Backend)
|
||||||
|
# ===================================================================
|
||||||
|
|
||||||
|
#虚拟环境 (常见的名称:venv, env, .venv, .env)
|
||||||
|
#使用斜杠 / 确保只匹配根目录下的,避免误伤子目录
|
||||||
|
/venv/
|
||||||
|
/env/
|
||||||
|
/.venv/
|
||||||
|
/.env/
|
||||||
|
|
||||||
|
# Python 缓存文件
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
#运行时文件
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
#单元测试和覆盖率报告
|
||||||
|
.pytest_cache/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
/htmlcov/
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
|
||||||
|
# Sphinx 文档
|
||||||
|
/docs/_build/
|
||||||
|
|
||||||
|
# Jupyter Notebook 检查点
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
#数据库文件 (开发时使用的本地数据库)
|
||||||
|
*.sqlite3
|
||||||
|
db.sqlite3
|
||||||
|
|
||||||
|
|
||||||
|
# ===================================================================
|
||||||
|
# Node.js / Vue.js (Frontend)
|
||||||
|
# ===================================================================
|
||||||
|
|
||||||
|
#依赖目录 (最重要的规则!)
|
||||||
|
/node_modules/
|
||||||
|
|
||||||
|
#本地环境配置文件 (Vue CLI 和 Vite 的标准)
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
|
||||||
|
#构建输出目录 (Vue CLI, Vite, etc.)
|
||||||
|
/dist/
|
||||||
|
/public/build/
|
||||||
|
|
||||||
|
#日志文件
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
|
||||||
|
# Vite 缓存
|
||||||
|
.vite/
|
||||||
|
|
||||||
|
|
||||||
|
# ===================================================================
|
||||||
|
# IDE 和编辑器配置
|
||||||
|
# ===================================================================
|
||||||
|
|
||||||
|
# VSCode
|
||||||
|
#忽略所有 .vscode 下的文件,但保留团队共享的配置
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
|
||||||
|
# JetBrains / PyCharm
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Sublime Text
|
||||||
|
*.sublime-project
|
||||||
|
*.sublime-workspace
|
||||||
|
|
||||||
|
# Atom
|
||||||
|
.atom/
|
||||||
|
|
||||||
|
|
||||||
|
# ===================================================================
|
||||||
|
# 操作系统生成的文件
|
||||||
|
# ===================================================================
|
||||||
|
|
||||||
|
# macOS
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
._*
|
||||||
|
.Spotlight-V100
|
||||||
|
.Trashes
|
||||||
|
|
||||||
|
# Windows
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
Desktop.ini
|
||||||
|
$RECYCLE.BIN/
|
||||||
661
LICENSE
Normal file
661
LICENSE
Normal file
@@ -0,0 +1,661 @@
|
|||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
0
api/__init__.py
Normal file
0
api/__init__.py
Normal file
300
api/statistics.py
Normal file
300
api/statistics.py
Normal file
@@ -0,0 +1,300 @@
|
|||||||
|
from flask import Blueprint, request, jsonify, make_response
|
||||||
|
from flask_jwt_extended import get_jwt_identity
|
||||||
|
from models import db, Task, User
|
||||||
|
from auth import login_required, admin_required
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from sqlalchemy import func, and_
|
||||||
|
import csv
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
statistics_bp = Blueprint('statistics', __name__)
|
||||||
|
|
||||||
|
# 个人统计
|
||||||
|
@statistics_bp.route('/statistics/user/<int:user_id>', methods=['GET'])
|
||||||
|
@login_required
|
||||||
|
def get_user_statistics(user_id):
|
||||||
|
current_user_id = int(get_jwt_identity())
|
||||||
|
current_user = db.session.get(User, current_user_id)
|
||||||
|
|
||||||
|
# 非管理员只能查看自己的统计
|
||||||
|
if current_user.role != 'admin' and current_user_id != user_id:
|
||||||
|
return jsonify({'error': '无权查看他人统计'}), 403
|
||||||
|
|
||||||
|
date_from = request.args.get('date_from')
|
||||||
|
date_to = request.args.get('date_to')
|
||||||
|
group_id = request.args.get('group_id', type=int)
|
||||||
|
|
||||||
|
query = Task.query.filter_by(claimed_by=user_id, status='completed')
|
||||||
|
|
||||||
|
if group_id:
|
||||||
|
query = query.filter_by(group_id=group_id)
|
||||||
|
|
||||||
|
if date_from:
|
||||||
|
try:
|
||||||
|
date_from_obj = datetime.strptime(date_from, '%Y-%m-%d')
|
||||||
|
query = query.filter(Task.completed_at >= date_from_obj)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if date_to:
|
||||||
|
try:
|
||||||
|
date_to_obj = datetime.strptime(date_to, '%Y-%m-%d')
|
||||||
|
date_to_obj = date_to_obj.replace(hour=23, minute=59, second=59)
|
||||||
|
query = query.filter(Task.completed_at <= date_to_obj)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 总完成数
|
||||||
|
total_completed = query.count()
|
||||||
|
|
||||||
|
# 按日期分组统计
|
||||||
|
daily_stats = db.session.query(
|
||||||
|
func.date(Task.completed_at).label('date'),
|
||||||
|
func.count(Task.id).label('count')
|
||||||
|
).filter(
|
||||||
|
Task.claimed_by == user_id,
|
||||||
|
Task.status == 'completed'
|
||||||
|
)
|
||||||
|
|
||||||
|
if date_from:
|
||||||
|
daily_stats = daily_stats.filter(Task.completed_at >= date_from_obj)
|
||||||
|
if date_to:
|
||||||
|
daily_stats = daily_stats.filter(Task.completed_at <= date_to_obj)
|
||||||
|
|
||||||
|
daily_stats = daily_stats.group_by(func.date(Task.completed_at)).all()
|
||||||
|
|
||||||
|
# 当前认领未完成
|
||||||
|
claimed_pending = Task.query.filter_by(
|
||||||
|
claimed_by=user_id,
|
||||||
|
status='claimed'
|
||||||
|
).count()
|
||||||
|
|
||||||
|
user = db.session.get(User, user_id)
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'user': {
|
||||||
|
'id': user.id,
|
||||||
|
'username': user.username
|
||||||
|
},
|
||||||
|
'total_completed': total_completed,
|
||||||
|
'claimed_pending': claimed_pending,
|
||||||
|
'daily_stats': [
|
||||||
|
{
|
||||||
|
'date': str(stat.date),
|
||||||
|
'count': stat.count
|
||||||
|
} for stat in daily_stats
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
# 组别排行榜
|
||||||
|
@statistics_bp.route('/statistics/leaderboard', methods=['GET'])
|
||||||
|
@login_required
|
||||||
|
def get_leaderboard():
|
||||||
|
group_id = request.args.get('group_id', type=int)
|
||||||
|
period = request.args.get('period', 'monthly') # daily/monthly
|
||||||
|
|
||||||
|
now = datetime.utcnow()
|
||||||
|
|
||||||
|
if period == 'daily':
|
||||||
|
start_date = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
|
else: # monthly
|
||||||
|
start_date = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|
||||||
|
|
||||||
|
query = db.session.query(
|
||||||
|
User.id,
|
||||||
|
User.username,
|
||||||
|
func.count(Task.id).label('completed_count')
|
||||||
|
).join(
|
||||||
|
Task, Task.claimed_by == User.id
|
||||||
|
).filter(
|
||||||
|
Task.status == 'completed',
|
||||||
|
Task.completed_at >= start_date
|
||||||
|
)
|
||||||
|
|
||||||
|
if group_id:
|
||||||
|
query = query.filter(Task.group_id == group_id)
|
||||||
|
|
||||||
|
leaderboard = query.group_by(User.id, User.username).order_by(
|
||||||
|
func.count(Task.id).desc()
|
||||||
|
).limit(20).all()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'period': period,
|
||||||
|
'leaderboard': [
|
||||||
|
{
|
||||||
|
'rank': idx + 1,
|
||||||
|
'user_id': row.id,
|
||||||
|
'username': row.username,
|
||||||
|
'completed_count': row.completed_count
|
||||||
|
} for idx, row in enumerate(leaderboard)
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
# 整体统计(支持管理员和普通用户)
|
||||||
|
@statistics_bp.route('/statistics/overview', methods=['GET'])
|
||||||
|
@login_required
|
||||||
|
def get_overview():
|
||||||
|
current_user_id = get_jwt_identity()
|
||||||
|
current_user = db.session.get(User, current_user_id)
|
||||||
|
group_id = request.args.get('group_id', type=int, default=1)
|
||||||
|
|
||||||
|
# 获取时间范围参数
|
||||||
|
date_from = request.args.get('date_from')
|
||||||
|
date_to = request.args.get('date_to')
|
||||||
|
|
||||||
|
# 基础查询条件
|
||||||
|
base_filter = [Task.group_id == group_id]
|
||||||
|
|
||||||
|
# 普通用户只能看自己的数据
|
||||||
|
if current_user.role != 'admin':
|
||||||
|
base_filter.append(Task.claimed_by == current_user_id)
|
||||||
|
|
||||||
|
# 解析时间范围
|
||||||
|
date_from_obj = None
|
||||||
|
date_to_obj = None
|
||||||
|
if date_from:
|
||||||
|
try:
|
||||||
|
date_from_obj = datetime.strptime(date_from, '%Y-%m-%d')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
if date_to:
|
||||||
|
try:
|
||||||
|
date_to_obj = datetime.strptime(date_to, '%Y-%m-%d')
|
||||||
|
date_to_obj = date_to_obj.replace(hour=23, minute=59, second=59)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 各状态任务数量
|
||||||
|
status_query = db.session.query(
|
||||||
|
Task.status,
|
||||||
|
func.count(Task.id).label('count')
|
||||||
|
).filter(and_(*base_filter)).group_by(Task.status)
|
||||||
|
status_counts = status_query.all()
|
||||||
|
|
||||||
|
# 今日完成
|
||||||
|
today = datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
|
today_filter = base_filter + [
|
||||||
|
Task.status == 'completed',
|
||||||
|
Task.completed_at >= today
|
||||||
|
]
|
||||||
|
today_completed = Task.query.filter(and_(*today_filter)).count()
|
||||||
|
|
||||||
|
# 本月完成
|
||||||
|
month_start = datetime.utcnow().replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|
||||||
|
month_filter = base_filter + [
|
||||||
|
Task.status == 'completed',
|
||||||
|
Task.completed_at >= month_start
|
||||||
|
]
|
||||||
|
month_completed = Task.query.filter(and_(*month_filter)).count()
|
||||||
|
|
||||||
|
# 趋势图(根据时间范围或默认最近7天)
|
||||||
|
if date_from_obj:
|
||||||
|
trend_start = date_from_obj
|
||||||
|
else:
|
||||||
|
trend_start = datetime.utcnow() - timedelta(days=7)
|
||||||
|
|
||||||
|
trend_filter = base_filter + [
|
||||||
|
Task.status == 'completed',
|
||||||
|
Task.completed_at >= trend_start
|
||||||
|
]
|
||||||
|
if date_to_obj:
|
||||||
|
trend_filter.append(Task.completed_at <= date_to_obj)
|
||||||
|
|
||||||
|
trend = db.session.query(
|
||||||
|
func.date(Task.completed_at).label('date'),
|
||||||
|
func.count(Task.id).label('count')
|
||||||
|
).filter(and_(*trend_filter)).group_by(func.date(Task.completed_at)).all()
|
||||||
|
# 计算时间范围内的总完成数
|
||||||
|
completed_filter = base_filter + [Task.status == 'completed']
|
||||||
|
if date_from_obj:
|
||||||
|
completed_filter.append(Task.completed_at >= date_from_obj)
|
||||||
|
if date_to_obj:
|
||||||
|
completed_filter.append(Task.completed_at <= date_to_obj)
|
||||||
|
total_completed = Task.query.filter(and_(*completed_filter)).count()
|
||||||
|
|
||||||
|
# 当前认领未完成数
|
||||||
|
claimed_filter = base_filter + [Task.status == 'claimed']
|
||||||
|
claimed_pending = Task.query.filter(and_(*claimed_filter)).count()
|
||||||
|
return jsonify({
|
||||||
|
'status_counts': {row.status: row.count for row in status_counts},
|
||||||
|
'today_completed': today_completed,
|
||||||
|
'month_completed': month_completed,
|
||||||
|
'total_completed': total_completed,
|
||||||
|
'claimed_pending': claimed_pending,
|
||||||
|
'is_admin': current_user.role == 'admin',
|
||||||
|
'trend': [
|
||||||
|
{'date': str(row.date), 'count': row.count} for row in trend
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
# 导出统计数据(CSV格式)
|
||||||
|
@statistics_bp.route('/statistics/export', methods=['GET'])
|
||||||
|
@login_required
|
||||||
|
def export_statistics():
|
||||||
|
current_user_id = get_jwt_identity()
|
||||||
|
current_user = db.session.get(User, current_user_id)
|
||||||
|
group_id = request.args.get('group_id', type=int, default=1)
|
||||||
|
date_from = request.args.get('date_from')
|
||||||
|
date_to = request.args.get('date_to')
|
||||||
|
|
||||||
|
# 构建查询条件
|
||||||
|
query = Task.query.filter_by(group_id=group_id, status='completed')
|
||||||
|
|
||||||
|
# 普通用户只能导出自己的数据
|
||||||
|
if current_user.role != 'admin':
|
||||||
|
query = query.filter_by(claimed_by=current_user_id)
|
||||||
|
|
||||||
|
# 时间范围筛选
|
||||||
|
if date_from:
|
||||||
|
try:
|
||||||
|
date_from_obj = datetime.strptime(date_from, '%Y-%m-%d')
|
||||||
|
query = query.filter(Task.completed_at >= date_from_obj)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if date_to:
|
||||||
|
try:
|
||||||
|
date_to_obj = datetime.strptime(date_to, '%Y-%m-%d')
|
||||||
|
date_to_obj = date_to_obj.replace(hour=23, minute=59, second=59)
|
||||||
|
query = query.filter(Task.completed_at <= date_to_obj)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
tasks = query.order_by(Task.completed_at.desc()).all()
|
||||||
|
|
||||||
|
# 生成CSV
|
||||||
|
output = StringIO()
|
||||||
|
writer = csv.writer(output)
|
||||||
|
|
||||||
|
# 写入表头
|
||||||
|
writer.writerow(['任务ID', '剧集名称', '优先级', '认领人', '种子ID', '完成时间', '认领时间', '耗时(小时)'])
|
||||||
|
|
||||||
|
# 写入数据
|
||||||
|
for task in tasks:
|
||||||
|
duration = ''
|
||||||
|
if task.claimed_at and task.completed_at:
|
||||||
|
delta = task.completed_at - task.claimed_at
|
||||||
|
duration = f'{delta.total_seconds() / 3600:.1f}'
|
||||||
|
|
||||||
|
claimer_name = task.claimer.username if task.claimer else '-'
|
||||||
|
|
||||||
|
writer.writerow([
|
||||||
|
task.id,
|
||||||
|
task.series_name,
|
||||||
|
task.priority or '-',
|
||||||
|
claimer_name,
|
||||||
|
task.torrent_id or '-',
|
||||||
|
task.completed_at.strftime('%Y-%m-%d %H:%M:%S') if task.completed_at else '-',
|
||||||
|
task.claimed_at.strftime('%Y-%m-%d %H:%M:%S') if task.claimed_at else '-',
|
||||||
|
duration
|
||||||
|
])
|
||||||
|
|
||||||
|
# 创建响应
|
||||||
|
response = make_response(output.getvalue())
|
||||||
|
response.headers['Content-Type'] = 'text/csv; charset=utf-8-sig'
|
||||||
|
response.headers['Content-Disposition'] = f'attachment; filename=statistics_{datetime.now().strftime("%Y%m%d_%H%M%S")}.csv'
|
||||||
|
|
||||||
|
return response
|
||||||
250
api/tasks.py
Normal file
250
api/tasks.py
Normal file
@@ -0,0 +1,250 @@
|
|||||||
|
from flask import Blueprint, request, jsonify
|
||||||
|
from flask_jwt_extended import get_jwt_identity
|
||||||
|
from models import db, Task, TaskLog, Group, User
|
||||||
|
from auth import login_required, admin_required, group_member_required, get_current_user
|
||||||
|
from datetime import datetime
|
||||||
|
from sqlalchemy import func, and_
|
||||||
|
|
||||||
|
tasks_bp = Blueprint('tasks', __name__)
|
||||||
|
|
||||||
|
# 获取任务列表
|
||||||
|
@tasks_bp.route('/groups/<int:group_id>/tasks', methods=['GET'])
|
||||||
|
@login_required
|
||||||
|
def get_tasks(group_id):
|
||||||
|
status = request.args.get('status') # pending/claimed/completed
|
||||||
|
user_id = request.args.get('user_id', type=int)
|
||||||
|
page = request.args.get('page', 1, type=int)
|
||||||
|
per_page = request.args.get('per_page', 20, type=int)
|
||||||
|
|
||||||
|
query = Task.query.filter_by(group_id=group_id)
|
||||||
|
|
||||||
|
if status:
|
||||||
|
query = query.filter_by(status=status)
|
||||||
|
|
||||||
|
if user_id:
|
||||||
|
query = query.filter_by(claimed_by=user_id)
|
||||||
|
|
||||||
|
query = query.order_by(Task.series_date.desc(), Task.created_at.desc())
|
||||||
|
|
||||||
|
pagination = query.paginate(page=page, per_page=per_page, error_out=False)
|
||||||
|
|
||||||
|
tasks = []
|
||||||
|
for task in pagination.items:
|
||||||
|
tasks.append({
|
||||||
|
'id': task.id,
|
||||||
|
'series_name': task.series_name,
|
||||||
|
'series_link': task.series_link,
|
||||||
|
'series_date': task.series_date.strftime('%Y-%m-%d') if task.series_date else None,
|
||||||
|
'priority': task.priority,
|
||||||
|
'status': task.status,
|
||||||
|
'claimed_by': task.claimer.username if task.claimer else None,
|
||||||
|
'claimed_by_id': task.claimed_by,
|
||||||
|
'claimed_at': task.claimed_at.strftime('%Y-%m-%d %H:%M') if task.claimed_at else None,
|
||||||
|
'claim_note': task.claim_note,
|
||||||
|
'torrent_id': task.torrent_id,
|
||||||
|
'complete_note': task.complete_note,
|
||||||
|
'completed_at': task.completed_at.strftime('%Y-%m-%d %H:%M') if task.completed_at else None,
|
||||||
|
'creator': task.creator.username,
|
||||||
|
'created_at': task.created_at.strftime('%Y-%m-%d %H:%M')
|
||||||
|
})
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'tasks': tasks,
|
||||||
|
'total': pagination.total,
|
||||||
|
'page': page,
|
||||||
|
'pages': pagination.pages
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
# 创建任务(管理员)
|
||||||
|
@tasks_bp.route('/groups/<int:group_id>/tasks', methods=['POST'])
|
||||||
|
@admin_required
|
||||||
|
def create_task(group_id):
|
||||||
|
data = request.json
|
||||||
|
|
||||||
|
# 验证必填字段
|
||||||
|
if not data.get('series_name'):
|
||||||
|
return jsonify({'error': '剧集名称不能为空'}), 400
|
||||||
|
|
||||||
|
if not data.get('series_date'):
|
||||||
|
return jsonify({'error': '剧集更新日期不能为空'}), 400
|
||||||
|
|
||||||
|
try:
|
||||||
|
series_date = datetime.strptime(data['series_date'], '%Y-%m-%d').date()
|
||||||
|
except:
|
||||||
|
return jsonify({'error': '日期格式错误'}), 400
|
||||||
|
|
||||||
|
user_id = get_jwt_identity()
|
||||||
|
|
||||||
|
task = Task(
|
||||||
|
group_id=group_id,
|
||||||
|
series_name=data['series_name'],
|
||||||
|
series_link=data.get('series_link'),
|
||||||
|
series_date=series_date,
|
||||||
|
priority=data.get('priority', '中'),
|
||||||
|
created_by=user_id
|
||||||
|
)
|
||||||
|
|
||||||
|
db.session.add(task)
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
|
# 记录日志
|
||||||
|
log = TaskLog(
|
||||||
|
task_id=task.id,
|
||||||
|
user_id=user_id,
|
||||||
|
action='create',
|
||||||
|
comment=f'创建任务:{task.series_name}'
|
||||||
|
)
|
||||||
|
db.session.add(log)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({'message': '任务创建成功', 'task_id': task.id}), 201
|
||||||
|
|
||||||
|
|
||||||
|
# 认领任务
|
||||||
|
@tasks_bp.route('/tasks/<int:task_id>/claim', methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
def claim_task(task_id):
|
||||||
|
task = db.session.get(Task, task_id)
|
||||||
|
if not task:
|
||||||
|
return jsonify({'error': '任务不存在'}), 404
|
||||||
|
|
||||||
|
if task.status != 'pending':
|
||||||
|
return jsonify({'error': '该任务已被认领或已完成'}), 400
|
||||||
|
|
||||||
|
user_id = get_jwt_identity()
|
||||||
|
data = request.json or {}
|
||||||
|
|
||||||
|
# 使用数据库锁防止并发认领
|
||||||
|
task = db.session.query(Task).filter_by(id=task_id, status='pending').with_for_update().first()
|
||||||
|
if not task:
|
||||||
|
return jsonify({'error': '任务已被他人认领'}), 400
|
||||||
|
|
||||||
|
task.status = 'claimed'
|
||||||
|
task.claimed_by = user_id
|
||||||
|
task.claimed_at = datetime.utcnow()
|
||||||
|
task.claim_note = data.get('claim_note')
|
||||||
|
|
||||||
|
log = TaskLog(
|
||||||
|
task_id=task_id,
|
||||||
|
user_id=user_id,
|
||||||
|
action='claim',
|
||||||
|
comment=data.get('claim_note')
|
||||||
|
)
|
||||||
|
db.session.add(log)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({'message': '认领成功'})
|
||||||
|
|
||||||
|
|
||||||
|
# 完成任务
|
||||||
|
# 完成任务
|
||||||
|
@tasks_bp.route('/tasks/<int:task_id>/complete', methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
def complete_task(task_id):
|
||||||
|
task = db.session.get(Task, task_id)
|
||||||
|
if not task:
|
||||||
|
return jsonify({'error': '任务不存在'}), 404
|
||||||
|
|
||||||
|
user_id = get_jwt_identity()
|
||||||
|
|
||||||
|
# 确保类型一致,转换为整数比较
|
||||||
|
if task.claimed_by != int(user_id):
|
||||||
|
return jsonify({'error': f'只能完成自己认领的任务 (任务认领者: {task.claimed_by}, 当前用户: {user_id})'}), 403
|
||||||
|
|
||||||
|
if task.status != 'claimed':
|
||||||
|
return jsonify({'error': '任务状态错误'}), 400
|
||||||
|
|
||||||
|
data = request.json
|
||||||
|
if not data.get('torrent_id'):
|
||||||
|
return jsonify({'error': '种子ID不能为空'}), 400
|
||||||
|
|
||||||
|
task.status = 'completed'
|
||||||
|
task.torrent_id = data['torrent_id']
|
||||||
|
task.complete_note = data.get('complete_note')
|
||||||
|
task.completed_at = datetime.utcnow()
|
||||||
|
|
||||||
|
log = TaskLog(
|
||||||
|
task_id=task_id,
|
||||||
|
user_id=int(user_id),
|
||||||
|
action='complete',
|
||||||
|
comment=f'种子ID: {data["torrent_id"]}'
|
||||||
|
)
|
||||||
|
db.session.add(log)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({'message': '任务完成'})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 取消认领(用户自己)
|
||||||
|
@tasks_bp.route('/tasks/<int:task_id>/cancel-claim', methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
def cancel_claim(task_id):
|
||||||
|
task = db.session.get(Task, task_id)
|
||||||
|
if not task:
|
||||||
|
return jsonify({'error': '任务不存在'}), 404
|
||||||
|
|
||||||
|
user_id = get_jwt_identity()
|
||||||
|
|
||||||
|
if task.claimed_by != user_id:
|
||||||
|
return jsonify({'error': '只能取消自己认领的任务'}), 403
|
||||||
|
|
||||||
|
if task.status != 'claimed':
|
||||||
|
return jsonify({'error': '任务状态错误'}), 400
|
||||||
|
|
||||||
|
task.status = 'pending'
|
||||||
|
task.claimed_by = None
|
||||||
|
task.claimed_at = None
|
||||||
|
task.claim_note = None
|
||||||
|
|
||||||
|
log = TaskLog(
|
||||||
|
task_id=task_id,
|
||||||
|
user_id=user_id,
|
||||||
|
action='cancel_claim',
|
||||||
|
comment='取消认领'
|
||||||
|
)
|
||||||
|
db.session.add(log)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({'message': '已取消认领'})
|
||||||
|
|
||||||
|
|
||||||
|
# 删除任务(管理员)
|
||||||
|
@tasks_bp.route('/tasks/<int:task_id>', methods=['DELETE'])
|
||||||
|
@admin_required
|
||||||
|
def delete_task(task_id):
|
||||||
|
task = db.session.get(Task, task_id)
|
||||||
|
if not task:
|
||||||
|
return jsonify({'error': '任务不存在'}), 404
|
||||||
|
|
||||||
|
db.session.delete(task)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({'message': '任务已删除'})
|
||||||
|
|
||||||
|
|
||||||
|
# 获取任务详情
|
||||||
|
@tasks_bp.route('/tasks/<int:task_id>', methods=['GET'])
|
||||||
|
@login_required
|
||||||
|
def get_task(task_id):
|
||||||
|
task = db.session.get(Task, task_id)
|
||||||
|
if not task:
|
||||||
|
return jsonify({'error': '任务不存在'}), 404
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'id': task.id,
|
||||||
|
'series_name': task.series_name,
|
||||||
|
'series_link': task.series_link,
|
||||||
|
'series_date': task.series_date.strftime('%Y-%m-%d'),
|
||||||
|
'priority': task.priority,
|
||||||
|
'status': task.status,
|
||||||
|
'claimed_by': task.claimer.username if task.claimer else None,
|
||||||
|
'claimed_at': task.claimed_at.strftime('%Y-%m-%d %H:%M') if task.claimed_at else None,
|
||||||
|
'claim_note': task.claim_note,
|
||||||
|
'torrent_id': task.torrent_id,
|
||||||
|
'complete_note': task.complete_note,
|
||||||
|
'completed_at': task.completed_at.strftime('%Y-%m-%d %H:%M') if task.completed_at else None,
|
||||||
|
'creator': task.creator.username,
|
||||||
|
'created_at': task.created_at.strftime('%Y-%m-%d %H:%M')
|
||||||
|
})
|
||||||
199
api/user_management.py
Normal file
199
api/user_management.py
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
from flask import Blueprint, request, jsonify
|
||||||
|
from flask_jwt_extended import get_jwt_identity
|
||||||
|
from models import db, User
|
||||||
|
from auth import login_required, admin_required
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
user_mgmt_bp = Blueprint('user_management', __name__)
|
||||||
|
|
||||||
|
# 用户注册
|
||||||
|
@user_mgmt_bp.route('/register', methods=['POST'])
|
||||||
|
def register():
|
||||||
|
data = request.json
|
||||||
|
|
||||||
|
if not all([data.get('username'), data.get('email'), data.get('password')]):
|
||||||
|
return jsonify({'error': '用户名、邮箱和密码不能为空'}), 400
|
||||||
|
|
||||||
|
if User.query.filter_by(username=data['username']).first():
|
||||||
|
return jsonify({'error': '用户名已存在'}), 400
|
||||||
|
|
||||||
|
if User.query.filter_by(email=data['email']).first():
|
||||||
|
return jsonify({'error': '邮箱已被注册'}), 400
|
||||||
|
|
||||||
|
user = User(
|
||||||
|
username=data['username'],
|
||||||
|
email=data['email'],
|
||||||
|
uid=data.get('uid'),
|
||||||
|
status='pending'
|
||||||
|
)
|
||||||
|
user.set_password(data['password'])
|
||||||
|
|
||||||
|
db.session.add(user)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({'message': '注册成功,请等待管理员审核'}), 201
|
||||||
|
|
||||||
|
# 获取用户列表(管理员)
|
||||||
|
@user_mgmt_bp.route('/users', methods=['GET'])
|
||||||
|
@admin_required
|
||||||
|
def get_users():
|
||||||
|
status = request.args.get('status')
|
||||||
|
page = request.args.get('page', 1, type=int)
|
||||||
|
per_page = request.args.get('per_page', 20, type=int)
|
||||||
|
|
||||||
|
query = User.query
|
||||||
|
if status:
|
||||||
|
query = query.filter_by(status=status)
|
||||||
|
|
||||||
|
pagination = query.order_by(User.created_at.desc()).paginate(
|
||||||
|
page=page, per_page=per_page, error_out=False
|
||||||
|
)
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'users': [{
|
||||||
|
'id': u.id,
|
||||||
|
'username': u.username,
|
||||||
|
'email': u.email,
|
||||||
|
'uid': u.uid,
|
||||||
|
'role': u.role,
|
||||||
|
'status': u.status,
|
||||||
|
'tags': u.tags,
|
||||||
|
'note': u.note,
|
||||||
|
'created_at': u.created_at.strftime('%Y-%m-%d %H:%M'),
|
||||||
|
'approved_at': u.approved_at.strftime('%Y-%m-%d %H:%M') if u.approved_at else None
|
||||||
|
} for u in pagination.items],
|
||||||
|
'total': pagination.total,
|
||||||
|
'page': page,
|
||||||
|
'pages': pagination.pages
|
||||||
|
})
|
||||||
|
|
||||||
|
# 审核用户(管理员)
|
||||||
|
@user_mgmt_bp.route('/users/<int:user_id>/approve', methods=['POST'])
|
||||||
|
@admin_required
|
||||||
|
def approve_user(user_id):
|
||||||
|
user = db.session.get(User, user_id)
|
||||||
|
if not user:
|
||||||
|
return jsonify({'error': '用户不存在'}), 404
|
||||||
|
|
||||||
|
data = request.json or {}
|
||||||
|
action = data.get('action') # approve/reject
|
||||||
|
|
||||||
|
if action == 'approve':
|
||||||
|
user.status = 'active'
|
||||||
|
user.approved_at = datetime.utcnow()
|
||||||
|
user.approved_by = get_jwt_identity()
|
||||||
|
db.session.commit()
|
||||||
|
return jsonify({'message': '已通过审核'})
|
||||||
|
elif action == 'reject':
|
||||||
|
db.session.delete(user)
|
||||||
|
db.session.commit()
|
||||||
|
return jsonify({'message': '已拒绝申请'})
|
||||||
|
|
||||||
|
return jsonify({'error': '无效的操作'}), 400
|
||||||
|
|
||||||
|
# 编辑用户(管理员)
|
||||||
|
@user_mgmt_bp.route('/users/<int:user_id>', methods=['PUT'])
|
||||||
|
@admin_required
|
||||||
|
def update_user(user_id):
|
||||||
|
current_user_id = get_jwt_identity()
|
||||||
|
|
||||||
|
if current_user_id == user_id:
|
||||||
|
return jsonify({'error': '不能修改自己的信息'}), 403
|
||||||
|
|
||||||
|
user = db.session.get(User, user_id)
|
||||||
|
if not user:
|
||||||
|
return jsonify({'error': '用户不存在'}), 404
|
||||||
|
|
||||||
|
data = request.json
|
||||||
|
|
||||||
|
if 'email' in data:
|
||||||
|
user.email = data['email']
|
||||||
|
if 'uid' in data:
|
||||||
|
user.uid = data['uid']
|
||||||
|
if 'role' in data:
|
||||||
|
user.role = data['role']
|
||||||
|
if 'status' in data:
|
||||||
|
user.status = data['status']
|
||||||
|
if 'tags' in data:
|
||||||
|
user.tags = data['tags']
|
||||||
|
if 'note' in data:
|
||||||
|
user.note = data['note']
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
return jsonify({'message': '用户信息已更新'})
|
||||||
|
|
||||||
|
# 删除用户(管理员)
|
||||||
|
@user_mgmt_bp.route('/users/<int:user_id>', methods=['DELETE'])
|
||||||
|
@admin_required
|
||||||
|
def delete_user(user_id):
|
||||||
|
current_user_id = get_jwt_identity()
|
||||||
|
|
||||||
|
if current_user_id == user_id:
|
||||||
|
return jsonify({'error': '不能删除自己'}), 403
|
||||||
|
|
||||||
|
user = db.session.get(User, user_id)
|
||||||
|
if not user:
|
||||||
|
return jsonify({'error': '用户不存在'}), 404
|
||||||
|
|
||||||
|
db.session.delete(user)
|
||||||
|
db.session.commit()
|
||||||
|
return jsonify({'message': '用户已删除'})
|
||||||
|
|
||||||
|
# 修改密码(用户自己)
|
||||||
|
@user_mgmt_bp.route('/users/change-password', methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
def change_password():
|
||||||
|
user_id = get_jwt_identity()
|
||||||
|
user = db.session.get(User, user_id)
|
||||||
|
|
||||||
|
data = request.json
|
||||||
|
old_password = data.get('old_password')
|
||||||
|
new_password = data.get('new_password')
|
||||||
|
|
||||||
|
if not old_password or not new_password:
|
||||||
|
return jsonify({'error': '旧密码和新密码不能为空'}), 400
|
||||||
|
|
||||||
|
if not user.check_password(old_password):
|
||||||
|
return jsonify({'error': '旧密码错误'}), 400
|
||||||
|
|
||||||
|
user.set_password(new_password)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({'message': '密码修改成功'})
|
||||||
|
|
||||||
|
# 获取个人信息
|
||||||
|
@user_mgmt_bp.route('/users/profile', methods=['GET'])
|
||||||
|
@login_required
|
||||||
|
def get_profile():
|
||||||
|
user_id = get_jwt_identity()
|
||||||
|
user = db.session.get(User, user_id)
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'id': user.id,
|
||||||
|
'username': user.username,
|
||||||
|
'email': user.email,
|
||||||
|
'uid': user.uid,
|
||||||
|
'role': user.role,
|
||||||
|
'status': user.status,
|
||||||
|
'created_at': user.created_at.strftime('%Y-%m-%d %H:%M')
|
||||||
|
})
|
||||||
|
|
||||||
|
# 更新个人信息
|
||||||
|
@user_mgmt_bp.route('/users/profile', methods=['PUT'])
|
||||||
|
@login_required
|
||||||
|
def update_profile():
|
||||||
|
user_id = get_jwt_identity()
|
||||||
|
user = db.session.get(User, user_id)
|
||||||
|
|
||||||
|
data = request.json
|
||||||
|
|
||||||
|
if 'email' in data:
|
||||||
|
if User.query.filter(User.email == data['email'], User.id != user_id).first():
|
||||||
|
return jsonify({'error': '邮箱已被使用'}), 400
|
||||||
|
user.email = data['email']
|
||||||
|
|
||||||
|
if 'uid' in data:
|
||||||
|
user.uid = data['uid']
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
return jsonify({'message': '个人信息已更新'})
|
||||||
81
api/users.py
Normal file
81
api/users.py
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
from flask import Blueprint, request, jsonify
|
||||||
|
from flask_jwt_extended import create_access_token, jwt_required, get_jwt_identity
|
||||||
|
from models import User, db
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
users_bp = Blueprint('users', __name__)
|
||||||
|
|
||||||
|
@users_bp.route('/login', methods=['POST'])
|
||||||
|
def login():
|
||||||
|
data = request.json
|
||||||
|
user = User.query.filter_by(username=data['username']).first()
|
||||||
|
|
||||||
|
if not user or not user.check_password(data['password']):
|
||||||
|
return jsonify({'error': '用户名或密码错误'}), 401
|
||||||
|
|
||||||
|
if user.status != 'active':
|
||||||
|
return jsonify({'error': '账号未激活或已被禁用'}), 403
|
||||||
|
|
||||||
|
access_token = create_access_token(
|
||||||
|
identity=str(user.id),
|
||||||
|
expires_delta=timedelta(hours=24)
|
||||||
|
)
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'access_token': access_token,
|
||||||
|
'user': {
|
||||||
|
'id': user.id,
|
||||||
|
'username': user.username,
|
||||||
|
'role': user.role
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
@users_bp.route('/me', methods=['GET'])
|
||||||
|
@jwt_required()
|
||||||
|
def get_current_user():
|
||||||
|
user_id = get_jwt_identity()
|
||||||
|
user = db.session.get(User, user_id)
|
||||||
|
|
||||||
|
if not user:
|
||||||
|
return jsonify({'error': '用户不存在'}), 404
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'id': user.id,
|
||||||
|
'username': user.username,
|
||||||
|
'email': user.email,
|
||||||
|
'role': user.role,
|
||||||
|
'status': user.status
|
||||||
|
})
|
||||||
|
|
||||||
|
@users_bp.route('/users', methods=['POST'])
|
||||||
|
@jwt_required()
|
||||||
|
def create_user():
|
||||||
|
current_user_id = get_jwt_identity()
|
||||||
|
current_user = db.session.get(User, current_user_id)
|
||||||
|
|
||||||
|
if current_user.role != 'admin':
|
||||||
|
return jsonify({'error': '权限不足'}), 403
|
||||||
|
|
||||||
|
data = request.json
|
||||||
|
|
||||||
|
if not data.get('username') or not data.get('password'):
|
||||||
|
return jsonify({'error': '用户名和密码不能为空'}), 400
|
||||||
|
|
||||||
|
if User.query.filter_by(username=data['username']).first():
|
||||||
|
return jsonify({'error': '用户名已存在'}), 400
|
||||||
|
|
||||||
|
user = User(
|
||||||
|
username=data['username'],
|
||||||
|
email=data.get('email'),
|
||||||
|
role=data.get('role', 'user')
|
||||||
|
)
|
||||||
|
user.set_password(data['password'])
|
||||||
|
db.session.add(user)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'id': user.id,
|
||||||
|
'username': user.username,
|
||||||
|
'email': user.email,
|
||||||
|
'role': user.role
|
||||||
|
}), 201
|
||||||
123
app.py
Normal file
123
app.py
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
from flask import Flask, render_template, jsonify
|
||||||
|
from flask_jwt_extended import JWTManager
|
||||||
|
from flask_cors import CORS
|
||||||
|
from config import Config
|
||||||
|
from models import db
|
||||||
|
from api.users import users_bp
|
||||||
|
from api.tasks import tasks_bp
|
||||||
|
from api.statistics import statistics_bp
|
||||||
|
from api.user_management import user_mgmt_bp
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.config.from_object(Config)
|
||||||
|
|
||||||
|
jwt = JWTManager(app)
|
||||||
|
|
||||||
|
# 添加 JWT 错误处理
|
||||||
|
from flask import request
|
||||||
|
import traceback
|
||||||
|
@jwt.invalid_token_loader
|
||||||
|
def invalid_token_callback(callback):
|
||||||
|
print(f"=== JWT Token 验证失败 ===")
|
||||||
|
print(f"完整错误信息: {callback}")
|
||||||
|
print(f"请求头: {dict(request.headers)}")
|
||||||
|
print(f"Authorization 头: {request.headers.get('Authorization')}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc() # 打印堆栈跟踪
|
||||||
|
print("=======================")
|
||||||
|
return jsonify({'error': '无效的认证令牌', 'detail': callback}), 422
|
||||||
|
@jwt.unauthorized_loader
|
||||||
|
def unauthorized_callback(callback):
|
||||||
|
print(f"=== 未授权访问 ===")
|
||||||
|
print(f"错误信息: {callback}")
|
||||||
|
print(f"请求头: {dict(request.headers)}")
|
||||||
|
print(f"认证信息: {request.authorization}")
|
||||||
|
print("==================")
|
||||||
|
return jsonify({'error': '缺少认证令牌'}), 401
|
||||||
|
@jwt.expired_token_loader
|
||||||
|
def expired_token_callback(jwt_header, jwt_payload):
|
||||||
|
print(f"=== Token 已过期 ===")
|
||||||
|
print(f"JWT Header: {jwt_header}")
|
||||||
|
print(f"JWT Payload: {jwt_payload}")
|
||||||
|
print("====================")
|
||||||
|
return jsonify({'error': '认证令牌已过期'}), 401
|
||||||
|
# 添加一个 token 加载失败的回调(有助于调试更多错误)
|
||||||
|
@jwt.token_in_blocklist_loader
|
||||||
|
def check_if_token_revoked(jwt_header, jwt_payload):
|
||||||
|
# 如果你实现了 token 黑名单,这里会有逻辑
|
||||||
|
return False # 默认返回 False
|
||||||
|
# 初始化扩展
|
||||||
|
db.init_app(app)
|
||||||
|
CORS(app)
|
||||||
|
# 注册蓝图
|
||||||
|
app.register_blueprint(users_bp, url_prefix='/api')
|
||||||
|
app.register_blueprint(tasks_bp, url_prefix='/api')
|
||||||
|
app.register_blueprint(statistics_bp, url_prefix='/api')
|
||||||
|
app.register_blueprint(user_mgmt_bp, url_prefix='/api')
|
||||||
|
# 前端路由
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
return render_template('login.html')
|
||||||
|
|
||||||
|
@app.route('/tasks')
|
||||||
|
def tasks():
|
||||||
|
return render_template('task_list.html')
|
||||||
|
|
||||||
|
@app.route('/tasks/create')
|
||||||
|
def create_task_page():
|
||||||
|
return render_template('task_create.html')
|
||||||
|
|
||||||
|
@app.route('/statistics')
|
||||||
|
def statistics():
|
||||||
|
return render_template('statistics.html')
|
||||||
|
|
||||||
|
@app.route('/register')
|
||||||
|
def register_page():
|
||||||
|
return render_template('register.html')
|
||||||
|
|
||||||
|
@app.route('/users')
|
||||||
|
def users_page():
|
||||||
|
return render_template('users.html')
|
||||||
|
|
||||||
|
@app.route('/profile')
|
||||||
|
def profile_page():
|
||||||
|
return render_template('profile.html')
|
||||||
|
|
||||||
|
# 初始化数据库
|
||||||
|
@app.cli.command()
|
||||||
|
def init_db():
|
||||||
|
"""初始化数据库"""
|
||||||
|
db.create_all()
|
||||||
|
print('数据库初始化完成')
|
||||||
|
|
||||||
|
@app.cli.command()
|
||||||
|
def create_admin():
|
||||||
|
"""创建管理员账户"""
|
||||||
|
from models import User, Group, UserGroup
|
||||||
|
|
||||||
|
# 创建管理员
|
||||||
|
admin = User.query.filter_by(username='admin').first()
|
||||||
|
if not admin:
|
||||||
|
admin = User(username='admin', email='admin@example.com', role='admin')
|
||||||
|
admin.set_password('admin123')
|
||||||
|
db.session.add(admin)
|
||||||
|
print('管理员账户创建成功: admin / admin123')
|
||||||
|
else:
|
||||||
|
print('管理员账户已存在')
|
||||||
|
|
||||||
|
# 创建发布组
|
||||||
|
group = Group.query.filter_by(group_key='release').first()
|
||||||
|
if not group:
|
||||||
|
group = Group(
|
||||||
|
group_name='发布组',
|
||||||
|
group_key='release',
|
||||||
|
description='负责PT资源的发布'
|
||||||
|
)
|
||||||
|
db.session.add(group)
|
||||||
|
print('发布组创建成功')
|
||||||
|
else:
|
||||||
|
print('发布组已存在')
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True, host='0.0.0.0', port=5000)
|
||||||
73
auth.py
Normal file
73
auth.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
from functools import wraps
|
||||||
|
from flask import jsonify
|
||||||
|
from flask_jwt_extended import verify_jwt_in_request, get_jwt_identity
|
||||||
|
from models import User, UserGroup, db
|
||||||
|
|
||||||
|
def login_required(f):
|
||||||
|
@wraps(f)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
verify_jwt_in_request()
|
||||||
|
user_id = get_jwt_identity()
|
||||||
|
user = db.session.get(User, user_id)
|
||||||
|
|
||||||
|
# 检查用户是否存在且状态为激活
|
||||||
|
if not user:
|
||||||
|
return jsonify({'error': '用户不存在', 'code': 'USER_NOT_FOUND'}), 401
|
||||||
|
if user.status != 'active':
|
||||||
|
return jsonify({'error': '账号已被禁用', 'code': 'USER_DISABLED'}), 403
|
||||||
|
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
def admin_required(f):
|
||||||
|
@wraps(f)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
verify_jwt_in_request()
|
||||||
|
user_id = get_jwt_identity()
|
||||||
|
user = db.session.get(User, user_id)
|
||||||
|
|
||||||
|
# 检查用户是否存在且状态为激活
|
||||||
|
if not user:
|
||||||
|
return jsonify({'error': '用户不存在', 'code': 'USER_NOT_FOUND'}), 401
|
||||||
|
if user.status != 'active':
|
||||||
|
return jsonify({'error': '账号已被禁用', 'code': 'USER_DISABLED'}), 403
|
||||||
|
if user.role != 'admin':
|
||||||
|
return jsonify({'error': '需要管理员权限'}), 403
|
||||||
|
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
def group_member_required(group_id):
|
||||||
|
def decorator(f):
|
||||||
|
@wraps(f)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
verify_jwt_in_request()
|
||||||
|
user_id = get_jwt_identity()
|
||||||
|
|
||||||
|
# 检查用户是否存在且状态为激活
|
||||||
|
user = db.session.get(User, user_id)
|
||||||
|
if not user:
|
||||||
|
return jsonify({'error': '用户不存在', 'code': 'USER_NOT_FOUND'}), 401
|
||||||
|
if user.status != 'active':
|
||||||
|
return jsonify({'error': '账号已被禁用', 'code': 'USER_DISABLED'}), 403
|
||||||
|
|
||||||
|
# 检查是否为管理员
|
||||||
|
if user.role == 'admin':
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
|
||||||
|
# 检查是否为组成员
|
||||||
|
membership = UserGroup.query.filter_by(
|
||||||
|
user_id=user_id,
|
||||||
|
group_id=group_id
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if not membership:
|
||||||
|
return jsonify({'error': '无权访问该组别'}), 403
|
||||||
|
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
return wrapper
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
def get_current_user():
|
||||||
|
user_id = get_jwt_identity()
|
||||||
|
return db.session.get(User, user_id)
|
||||||
32
config.py
Normal file
32
config.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
# 加载 .env 文件中的环境变量
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
# 数据库配置
|
||||||
|
SQLALCHEMY_DATABASE_URI = os.getenv(
|
||||||
|
'DATABASE_URL',
|
||||||
|
'mysql+pymysql://root:your_password@localhost:3306/pt_manager'
|
||||||
|
)
|
||||||
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
|
SQLALCHEMY_ECHO = True # 开发时显示SQL语句
|
||||||
|
|
||||||
|
# Flask密钥
|
||||||
|
SECRET_KEY = os.getenv('SECRET_KEY', 'dev-secret-key-change-this')
|
||||||
|
|
||||||
|
# JWT配置
|
||||||
|
JWT_SECRET_KEY = os.getenv('JWT_SECRET_KEY', 'dev-secret-key-change-this')
|
||||||
|
JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=24)
|
||||||
|
JWT_TOKEN_LOCATION = ['headers']
|
||||||
|
JWT_HEADER_NAME = 'Authorization'
|
||||||
|
JWT_HEADER_TYPE = 'Bearer'
|
||||||
|
|
||||||
|
# 禁用CSRF保护(仅使用headers中的Bearer token)
|
||||||
|
JWT_COOKIE_CSRF_PROTECT = False
|
||||||
|
|
||||||
|
# 添加这些配置
|
||||||
|
JWT_ERROR_MESSAGE_KEY = 'error'
|
||||||
|
PROPAGATE_EXCEPTIONS = True
|
||||||
99
models.py
Normal file
99
models.py
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
import bcrypt
|
||||||
|
|
||||||
|
db = SQLAlchemy()
|
||||||
|
|
||||||
|
class User(db.Model):
|
||||||
|
__tablename__ = 'users'
|
||||||
|
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
username = db.Column(db.String(50), unique=True, nullable=False)
|
||||||
|
password_hash = db.Column(db.String(255), nullable=False)
|
||||||
|
email = db.Column(db.String(100), unique=True, nullable=False)
|
||||||
|
uid = db.Column(db.String(50)) # 站点UID
|
||||||
|
role = db.Column(db.String(20), default='user') # admin/user
|
||||||
|
status = db.Column(db.String(20), default='pending') # pending/active/disabled
|
||||||
|
tags = db.Column(db.String(200)) # 用户标签,逗号分隔
|
||||||
|
note = db.Column(db.Text) # 管理员备注
|
||||||
|
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||||
|
approved_at = db.Column(db.DateTime) # 审核通过时间
|
||||||
|
approved_by = db.Column(db.Integer, db.ForeignKey('users.id')) # 审核人
|
||||||
|
|
||||||
|
def set_password(self, password):
|
||||||
|
self.password_hash = generate_password_hash(password, method='pbkdf2:sha256')
|
||||||
|
|
||||||
|
def check_password(self, password):
|
||||||
|
return check_password_hash(self.password_hash, password)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Group(db.Model):
|
||||||
|
__tablename__ = 'groups'
|
||||||
|
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
group_name = db.Column(db.String(50), nullable=False)
|
||||||
|
group_key = db.Column(db.String(50), unique=True, nullable=False)
|
||||||
|
description = db.Column(db.Text)
|
||||||
|
status = db.Column(db.String(20), default='active')
|
||||||
|
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||||
|
|
||||||
|
|
||||||
|
class UserGroup(db.Model):
|
||||||
|
__tablename__ = 'user_groups'
|
||||||
|
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
|
||||||
|
group_id = db.Column(db.Integer, db.ForeignKey('groups.id'), nullable=False)
|
||||||
|
is_admin = db.Column(db.Boolean, default=False) # 是否为组管理员
|
||||||
|
join_date = db.Column(db.DateTime, default=datetime.utcnow)
|
||||||
|
|
||||||
|
user = db.relationship('User', backref='user_groups')
|
||||||
|
group = db.relationship('Group', backref='user_groups')
|
||||||
|
|
||||||
|
|
||||||
|
class Task(db.Model):
|
||||||
|
__tablename__ = 'tasks'
|
||||||
|
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
group_id = db.Column(db.Integer, db.ForeignKey('groups.id'), nullable=False)
|
||||||
|
|
||||||
|
# 发布组特定字段
|
||||||
|
series_name = db.Column(db.String(200), nullable=False)
|
||||||
|
series_link = db.Column(db.String(500))
|
||||||
|
series_date = db.Column(db.Date, nullable=False)
|
||||||
|
priority = db.Column(db.String(20)) # 高/中/低
|
||||||
|
|
||||||
|
# 流程字段
|
||||||
|
status = db.Column(db.String(20), default='pending') # pending/claimed/completed/cancelled
|
||||||
|
claimed_by = db.Column(db.Integer, db.ForeignKey('users.id'))
|
||||||
|
claimed_at = db.Column(db.DateTime)
|
||||||
|
claim_note = db.Column(db.Text)
|
||||||
|
|
||||||
|
torrent_id = db.Column(db.String(100))
|
||||||
|
complete_note = db.Column(db.Text)
|
||||||
|
completed_at = db.Column(db.DateTime)
|
||||||
|
|
||||||
|
created_by = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
|
||||||
|
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||||
|
|
||||||
|
# 关系
|
||||||
|
group = db.relationship('Group', backref='tasks')
|
||||||
|
claimer = db.relationship('User', foreign_keys=[claimed_by], backref='claimed_tasks')
|
||||||
|
creator = db.relationship('User', foreign_keys=[created_by], backref='created_tasks')
|
||||||
|
|
||||||
|
|
||||||
|
class TaskLog(db.Model):
|
||||||
|
__tablename__ = 'task_logs'
|
||||||
|
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
task_id = db.Column(db.Integer, db.ForeignKey('tasks.id'), nullable=False)
|
||||||
|
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
|
||||||
|
action = db.Column(db.String(50), nullable=False) # create/claim/complete/cancel
|
||||||
|
comment = db.Column(db.Text)
|
||||||
|
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||||
|
|
||||||
|
task = db.relationship('Task', backref='logs')
|
||||||
|
user = db.relationship('User', backref='task_logs')
|
||||||
8
requirements.txt
Normal file
8
requirements.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
Flask
|
||||||
|
Flask-SQLAlchemy
|
||||||
|
Flask-JWT-Extended
|
||||||
|
Flask-CORS
|
||||||
|
PyMySQL
|
||||||
|
python-dotenv
|
||||||
|
bcrypt
|
||||||
|
marshmallow
|
||||||
2018
static/css/bootstrap-icons.css
vendored
Normal file
2018
static/css/bootstrap-icons.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
6
static/css/bootstrap.min.css
vendored
Normal file
6
static/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
static/css/fonts/bootstrap-icons.woff
Normal file
BIN
static/css/fonts/bootstrap-icons.woff
Normal file
Binary file not shown.
BIN
static/css/fonts/bootstrap-icons.woff2
Normal file
BIN
static/css/fonts/bootstrap-icons.woff2
Normal file
Binary file not shown.
74
static/css/style.css
Normal file
74
static/css/style.css
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
body {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.075);
|
||||||
|
border: none;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-hover tbody tr:hover {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-status {
|
||||||
|
padding: 0.35em 0.65em;
|
||||||
|
font-size: 0.875em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-pending {
|
||||||
|
background-color: #ffc107;
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-claimed {
|
||||||
|
background-color: #17a2b8;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-completed {
|
||||||
|
background-color: #28a745;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.priority-high {
|
||||||
|
color: #dc3545;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.priority-medium {
|
||||||
|
color: #007bff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.priority-low {
|
||||||
|
color: #6c757d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-sm {
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-brand {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
#task-detail dt {
|
||||||
|
font-weight: 600;
|
||||||
|
color: #495057;
|
||||||
|
}
|
||||||
|
|
||||||
|
#task-detail dd {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-container {
|
||||||
|
position: relative;
|
||||||
|
height: 300px;
|
||||||
|
}
|
||||||
7
static/js/bootstrap.bundle.min.js
vendored
Normal file
7
static/js/bootstrap.bundle.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
20
static/js/chart.umd.min.js
vendored
Normal file
20
static/js/chart.umd.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
121
static/js/common.js
Normal file
121
static/js/common.js
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
// 通用工具函数
|
||||||
|
// AJAX全局设置
|
||||||
|
$.ajaxSetup({
|
||||||
|
beforeSend: function(xhr, settings) {
|
||||||
|
if (!settings.url.includes('/api/login')) {
|
||||||
|
const token = localStorage.getItem('access_token');
|
||||||
|
if (token) {
|
||||||
|
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 检查登录状态
|
||||||
|
function checkAuth() {
|
||||||
|
const token = localStorage.getItem('access_token');
|
||||||
|
if (!token) {
|
||||||
|
window.location.href = '/';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当前用户信息
|
||||||
|
function getCurrentUser() {
|
||||||
|
if (!checkAuth()) return;
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/me',
|
||||||
|
method: 'GET',
|
||||||
|
success: function(data) {
|
||||||
|
$('#current-username').text(data.username);
|
||||||
|
localStorage.setItem('current_user', JSON.stringify(data));
|
||||||
|
|
||||||
|
if (data.role === 'admin') {
|
||||||
|
$('.admin-only').show();
|
||||||
|
$('#nav-users').show();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
if (xhr.status === 401 || xhr.status === 422) {
|
||||||
|
logout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 退出登录
|
||||||
|
function logout() {
|
||||||
|
localStorage.removeItem('access_token');
|
||||||
|
localStorage.removeItem('current_user');
|
||||||
|
window.location.href = '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化日期
|
||||||
|
function formatDate(dateString) {
|
||||||
|
if (!dateString) return '-';
|
||||||
|
const date = new Date(dateString);
|
||||||
|
return date.toLocaleDateString('zh-CN');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化日期时间
|
||||||
|
function formatDateTime(dateString) {
|
||||||
|
if (!dateString) return '-';
|
||||||
|
const date = new Date(dateString);
|
||||||
|
return date.toLocaleString('zh-CN');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示错误消息
|
||||||
|
function showError(message) {
|
||||||
|
alert(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示成功消息
|
||||||
|
function showSuccess(message) {
|
||||||
|
alert(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// AJAX错误处理
|
||||||
|
function handleAjaxError(xhr) {
|
||||||
|
if (xhr.status === 401) {
|
||||||
|
alert('登录已过期,请重新登录');
|
||||||
|
logout();
|
||||||
|
} else if (xhr.status === 403 && xhr.responseJSON?.code === 'USER_DISABLED') {
|
||||||
|
alert('您的账号已被禁用,请联系管理员');
|
||||||
|
logout();
|
||||||
|
} else {
|
||||||
|
const error = xhr.responseJSON?.error || '操作失败';
|
||||||
|
showError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取状态徽章HTML
|
||||||
|
function getStatusBadge(status) {
|
||||||
|
const statusMap = {
|
||||||
|
'pending': { text: '待认领', class: 'status-pending' },
|
||||||
|
'claimed': { text: '已认领', class: 'status-claimed' },
|
||||||
|
'completed': { text: '已完成', class: 'status-completed' }
|
||||||
|
};
|
||||||
|
|
||||||
|
const info = statusMap[status] || { text: status, class: '' };
|
||||||
|
return `<span class="badge badge-status ${info.class}">${info.text}</span>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取优先级样式类
|
||||||
|
function getPriorityClass(priority) {
|
||||||
|
const map = {
|
||||||
|
'高': 'priority-high',
|
||||||
|
'中': 'priority-medium',
|
||||||
|
'低': 'priority-low'
|
||||||
|
};
|
||||||
|
return map[priority] || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 页面加载时初始化
|
||||||
|
$(document).ready(function() {
|
||||||
|
// 如果不是登录页,检查认证
|
||||||
|
if (!window.location.pathname.match(/^\/?$/)) {
|
||||||
|
checkAuth();
|
||||||
|
getCurrentUser();
|
||||||
|
}
|
||||||
|
});
|
||||||
2
static/js/jquery.min.js
vendored
Normal file
2
static/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
33
static/js/login.js
Normal file
33
static/js/login.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
$(document).ready(function() {
|
||||||
|
// 如果已登录,跳转到任务列表
|
||||||
|
if (localStorage.getItem('access_token')) {
|
||||||
|
window.location.href = '/tasks';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#login-form').submit(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const username = $('#username').val();
|
||||||
|
const password = $('#password').val();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/login',
|
||||||
|
method: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({
|
||||||
|
username: username,
|
||||||
|
password: password
|
||||||
|
}),
|
||||||
|
success: function(response) {
|
||||||
|
localStorage.setItem('access_token', response.access_token);
|
||||||
|
localStorage.setItem('current_user', JSON.stringify(response.user));
|
||||||
|
window.location.href = '/tasks';
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
const error = xhr.responseJSON?.error || '登录失败';
|
||||||
|
$('#error-msg').text(error).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
76
static/js/profile.js
Normal file
76
static/js/profile.js
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
$(document).ready(function() {
|
||||||
|
loadProfile();
|
||||||
|
|
||||||
|
$('#profile-form').submit(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
updateProfile();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#password-form').submit(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
changePassword();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function loadProfile() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/users/profile',
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + localStorage.getItem('access_token')
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
$('#username').val(data.username);
|
||||||
|
$('#email').val(data.email);
|
||||||
|
$('#uid').val(data.uid);
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateProfile() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/users/profile',
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + localStorage.getItem('access_token')
|
||||||
|
},
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({
|
||||||
|
email: $('#email').val(),
|
||||||
|
uid: $('#uid').val()
|
||||||
|
}),
|
||||||
|
success: function(data) {
|
||||||
|
alert(data.message);
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function changePassword() {
|
||||||
|
const newPassword = $('#new-password').val();
|
||||||
|
const confirmPassword = $('#confirm-password').val();
|
||||||
|
|
||||||
|
if (newPassword !== confirmPassword) {
|
||||||
|
alert('两次密码不一致');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/users/change-password',
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + localStorage.getItem('access_token')
|
||||||
|
},
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({
|
||||||
|
old_password: $('#old-password').val(),
|
||||||
|
new_password: newPassword
|
||||||
|
}),
|
||||||
|
success: function(data) {
|
||||||
|
alert(data.message);
|
||||||
|
$('#password-form')[0].reset();
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
32
static/js/register.js
Normal file
32
static/js/register.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
$(document).ready(function() {
|
||||||
|
$('#register-form').submit(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const password = $('#password').val();
|
||||||
|
const confirmPassword = $('#confirm-password').val();
|
||||||
|
|
||||||
|
if (password !== confirmPassword) {
|
||||||
|
alert('两次密码不一致');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/register',
|
||||||
|
method: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({
|
||||||
|
username: $('#username').val(),
|
||||||
|
email: $('#email').val(),
|
||||||
|
uid: $('#uid').val(),
|
||||||
|
password: password
|
||||||
|
}),
|
||||||
|
success: function(data) {
|
||||||
|
alert(data.message);
|
||||||
|
window.location.href = '/';
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
alert(xhr.responseJSON?.error || '注册失败');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
316
static/js/statistics.js
Normal file
316
static/js/statistics.js
Normal file
@@ -0,0 +1,316 @@
|
|||||||
|
let myChart, trendChart;
|
||||||
|
let isAdmin = false;
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
// 设置默认日期范围(最近30天)
|
||||||
|
applyQuickSelect('30days');
|
||||||
|
|
||||||
|
// 加载统计数据
|
||||||
|
loadStatistics();
|
||||||
|
});
|
||||||
|
|
||||||
|
// 快捷时间选择
|
||||||
|
function applyQuickSelect(value) {
|
||||||
|
if (!value) {
|
||||||
|
value = $('#quick-select').val();
|
||||||
|
}
|
||||||
|
|
||||||
|
const today = new Date();
|
||||||
|
let dateFrom, dateTo;
|
||||||
|
|
||||||
|
switch(value) {
|
||||||
|
case 'today':
|
||||||
|
dateFrom = dateTo = today;
|
||||||
|
break;
|
||||||
|
case 'week':
|
||||||
|
dateFrom = new Date(today);
|
||||||
|
dateFrom.setDate(today.getDate() - today.getDay());
|
||||||
|
dateTo = today;
|
||||||
|
break;
|
||||||
|
case 'month':
|
||||||
|
dateFrom = new Date(today.getFullYear(), today.getMonth(), 1);
|
||||||
|
dateTo = today;
|
||||||
|
break;
|
||||||
|
case '30days':
|
||||||
|
dateFrom = new Date(today);
|
||||||
|
dateFrom.setDate(today.getDate() - 30);
|
||||||
|
dateTo = today;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#date-from').val(dateFrom.toISOString().split('T')[0]);
|
||||||
|
$('#date-to').val(dateTo.toISOString().split('T')[0]);
|
||||||
|
$('#quick-select').val(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载统计数据
|
||||||
|
function loadStatistics() {
|
||||||
|
loadOverview();
|
||||||
|
loadUserStatistics();
|
||||||
|
loadLeaderboard();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载概览数据
|
||||||
|
function loadOverview() {
|
||||||
|
const dateFrom = $('#date-from').val();
|
||||||
|
const dateTo = $('#date-to').val();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/statistics/overview',
|
||||||
|
method: 'GET',
|
||||||
|
data: {
|
||||||
|
group_id: 1,
|
||||||
|
date_from: dateFrom,
|
||||||
|
date_to: dateTo
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
isAdmin = data.is_admin;
|
||||||
|
|
||||||
|
$('#today-count').text(data.today_completed);
|
||||||
|
$('#month-count').text(data.month_completed);
|
||||||
|
$('#pending-count').text(data.status_counts.pending || 0);
|
||||||
|
$('#claimed-count').text(data.status_counts.claimed || 0);
|
||||||
|
|
||||||
|
// 更新标题和统计数据
|
||||||
|
if (isAdmin) {
|
||||||
|
$('#stats-title').text('全局完成统计');
|
||||||
|
$('#trend-title').text('全局完成趋势');
|
||||||
|
// 管理员使用全局数据
|
||||||
|
$('#my-total').text(data.total_completed);
|
||||||
|
$('#my-pending').text(data.claimed_pending);
|
||||||
|
// 渲染管理员图表
|
||||||
|
renderMyChart(data.total_completed, data.claimed_pending);
|
||||||
|
} else {
|
||||||
|
$('#stats-title').text('我的完成统计');
|
||||||
|
$('#trend-title').text('我的完成趋势');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渲染趋势图
|
||||||
|
renderTrendChart(data.trend);
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载个人统计
|
||||||
|
function loadUserStatistics() {
|
||||||
|
const userStr = localStorage.getItem('current_user');
|
||||||
|
if (isAdmin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!userStr) {
|
||||||
|
console.error('用户信息不存在');
|
||||||
|
$('#my-total').text('0');
|
||||||
|
$('#my-pending').text('0');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let user;
|
||||||
|
try {
|
||||||
|
user = JSON.parse(userStr);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('用户信息格式错误', e);
|
||||||
|
$('#my-total').text('0');
|
||||||
|
$('#my-pending').text('0');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user || !user.id) {
|
||||||
|
console.error('用户ID不存在');
|
||||||
|
$('#my-total').text('0');
|
||||||
|
$('#my-pending').text('0');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateFrom = $('#date-from').val();
|
||||||
|
const dateTo = $('#date-to').val();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: `/api/statistics/user/${user.id}`,
|
||||||
|
method: 'GET',
|
||||||
|
data: {
|
||||||
|
group_id: 1,
|
||||||
|
date_from: dateFrom,
|
||||||
|
date_to: dateTo
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
$('#my-total').text(data.total_completed);
|
||||||
|
$('#my-pending').text(data.claimed_pending);
|
||||||
|
|
||||||
|
// 渲染个人图表
|
||||||
|
renderMyChart(data.total_completed, data.claimed_pending);
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载排行榜
|
||||||
|
function loadLeaderboard() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/statistics/leaderboard',
|
||||||
|
method: 'GET',
|
||||||
|
data: {
|
||||||
|
group_id: 1,
|
||||||
|
period: 'monthly'
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
renderLeaderboard(data.leaderboard);
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渲染个人图表
|
||||||
|
function renderMyChart(totalCompleted, claimedPending) {
|
||||||
|
const ctx = document.getElementById('myChart');
|
||||||
|
|
||||||
|
if (myChart) {
|
||||||
|
myChart.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
myChart = new Chart(ctx, {
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: ['总完成数', '待完成数'],
|
||||||
|
datasets: [{
|
||||||
|
label: '任务数量',
|
||||||
|
data: [totalCompleted, claimedPending],
|
||||||
|
backgroundColor: [
|
||||||
|
'rgba(75, 192, 192, 0.5)',
|
||||||
|
'rgba(255, 159, 64, 0.5)'
|
||||||
|
],
|
||||||
|
borderColor: [
|
||||||
|
'rgba(75, 192, 192, 1)',
|
||||||
|
'rgba(255, 159, 64, 1)'
|
||||||
|
],
|
||||||
|
borderWidth: 1
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: true,
|
||||||
|
scales: {
|
||||||
|
y: {
|
||||||
|
beginAtZero: true,
|
||||||
|
ticks: {
|
||||||
|
stepSize: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渲染趋势图
|
||||||
|
function renderTrendChart(trend) {
|
||||||
|
const ctx = document.getElementById('trendChart');
|
||||||
|
|
||||||
|
if (trendChart) {
|
||||||
|
trendChart.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
const labels = trend.map(t => t.date);
|
||||||
|
const data = trend.map(t => t.count);
|
||||||
|
|
||||||
|
trendChart = new Chart(ctx, {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
labels: labels,
|
||||||
|
datasets: [{
|
||||||
|
label: '完成数',
|
||||||
|
data: data,
|
||||||
|
fill: true,
|
||||||
|
backgroundColor: 'rgba(75, 192, 192, 0.2)',
|
||||||
|
borderColor: 'rgba(75, 192, 192, 1)',
|
||||||
|
tension: 0.4
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: true,
|
||||||
|
scales: {
|
||||||
|
y: {
|
||||||
|
beginAtZero: true,
|
||||||
|
ticks: {
|
||||||
|
stepSize: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渲染排行榜
|
||||||
|
function renderLeaderboard(leaderboard) {
|
||||||
|
const tbody = $('#leaderboard');
|
||||||
|
tbody.empty();
|
||||||
|
|
||||||
|
if (leaderboard.length === 0) {
|
||||||
|
tbody.append('<tr><td colspan="3" class="text-center">暂无数据</td></tr>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentUser = JSON.parse(localStorage.getItem('current_user'));
|
||||||
|
|
||||||
|
leaderboard.forEach(function(row) {
|
||||||
|
const isCurrentUser = row.user_id === currentUser.id;
|
||||||
|
const rowClass = isCurrentUser ? 'table-primary' : '';
|
||||||
|
|
||||||
|
let rankBadge = '';
|
||||||
|
if (row.rank === 1) {
|
||||||
|
rankBadge = '<i class="bi bi-trophy-fill text-warning"></i> ';
|
||||||
|
} else if (row.rank === 2) {
|
||||||
|
rankBadge = '<i class="bi bi-trophy-fill text-secondary"></i> ';
|
||||||
|
} else if (row.rank === 3) {
|
||||||
|
rankBadge = '<i class="bi bi-trophy-fill text-danger"></i> ';
|
||||||
|
}
|
||||||
|
|
||||||
|
tbody.append(`
|
||||||
|
<tr class="${rowClass}">
|
||||||
|
<td>${rankBadge}${row.rank}</td>
|
||||||
|
<td>${row.username}${isCurrentUser ? ' <span class="badge bg-primary">我</span>' : ''}</td>
|
||||||
|
<td><strong>${row.completed_count}</strong></td>
|
||||||
|
</tr>
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出数据
|
||||||
|
function exportData() {
|
||||||
|
const dateFrom = $('#date-from').val();
|
||||||
|
const dateTo = $('#date-to').val();
|
||||||
|
const token = localStorage.getItem('access_token');
|
||||||
|
|
||||||
|
let url = '/api/statistics/export?group_id=1';
|
||||||
|
if (dateFrom) url += `&date_from=${dateFrom}`;
|
||||||
|
if (dateTo) url += `&date_to=${dateTo}`;
|
||||||
|
|
||||||
|
// 创建隐藏的下载链接
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = `statistics_${new Date().toISOString().split('T')[0]}.csv`;
|
||||||
|
|
||||||
|
// 添加认证头(通过fetch实现)
|
||||||
|
fetch(url, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + token
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(response => response.blob())
|
||||||
|
.then(blob => {
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = `statistics_${new Date().toISOString().split('T')[0]}.csv`;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
document.body.removeChild(a);
|
||||||
|
showSuccess('数据导出成功!');
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
showError('导出失败:' + error.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
329
static/js/task_list.js
Normal file
329
static/js/task_list.js
Normal file
@@ -0,0 +1,329 @@
|
|||||||
|
let currentPage = 1;
|
||||||
|
let claimModal, completeModal, detailModal;
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
// 初始化模态框
|
||||||
|
claimModal = new bootstrap.Modal(document.getElementById('claimModal'));
|
||||||
|
completeModal = new bootstrap.Modal(document.getElementById('completeModal'));
|
||||||
|
detailModal = new bootstrap.Modal(document.getElementById('detailModal'));
|
||||||
|
|
||||||
|
// 加载任务列表
|
||||||
|
loadTasks();
|
||||||
|
});
|
||||||
|
|
||||||
|
// 加载任务列表
|
||||||
|
function loadTasks(page = 1) {
|
||||||
|
const status = $('#filter-status').val();
|
||||||
|
const scope = $('#filter-scope').val();
|
||||||
|
|
||||||
|
let params = {
|
||||||
|
page: page,
|
||||||
|
per_page: 20
|
||||||
|
};
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
params.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scope === 'my') {
|
||||||
|
const user = JSON.parse(localStorage.getItem('current_user'));
|
||||||
|
params.user_id = user.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/groups/1/tasks',
|
||||||
|
method: 'GET',
|
||||||
|
data: params,
|
||||||
|
success: function(response) {
|
||||||
|
renderTasks(response.tasks);
|
||||||
|
renderPagination(response.page, response.pages);
|
||||||
|
currentPage = page;
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渲染任务列表
|
||||||
|
function renderTasks(tasks) {
|
||||||
|
const tbody = $('#task-list');
|
||||||
|
tbody.empty();
|
||||||
|
|
||||||
|
if (tasks.length === 0) {
|
||||||
|
tbody.append('<tr><td colspan="9" class="text-center">暂无数据</td></tr>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentUser = JSON.parse(localStorage.getItem('current_user'));
|
||||||
|
|
||||||
|
tasks.forEach(function(task) {
|
||||||
|
const priorityClass = getPriorityClass(task.priority);
|
||||||
|
|
||||||
|
let actions = '';
|
||||||
|
|
||||||
|
// 待认领状态 - 所有人可认领
|
||||||
|
if (task.status === 'pending') {
|
||||||
|
actions = `<button class="btn btn-sm btn-primary" onclick="openClaimModal(${task.id})">
|
||||||
|
<i class="bi bi-hand-thumbs-up"></i> 认领
|
||||||
|
</button>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 已认领状态 - 认领人可完成或取消
|
||||||
|
if (task.status === 'claimed' && task.claimed_by_id === currentUser.id) {
|
||||||
|
actions = `
|
||||||
|
<button class="btn btn-sm btn-success" onclick="openCompleteModal(${task.id})">
|
||||||
|
<i class="bi bi-check-circle"></i> 完成
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-sm btn-warning" onclick="cancelClaim(${task.id})">
|
||||||
|
<i class="bi bi-x-circle"></i> 取消
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查看详情按钮
|
||||||
|
actions += ` <button class="btn btn-sm btn-info" onclick="viewDetail(${task.id})">
|
||||||
|
<i class="bi bi-eye"></i> 详情
|
||||||
|
</button>`;
|
||||||
|
|
||||||
|
// 管理员可删除
|
||||||
|
if (currentUser.role === 'admin') {
|
||||||
|
actions += ` <button class="btn btn-sm btn-danger" onclick="deleteTask(${task.id})">
|
||||||
|
<i class="bi bi-trash"></i> 删除
|
||||||
|
</button>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const row = `
|
||||||
|
<tr>
|
||||||
|
<td>${task.id}</td>
|
||||||
|
<td>
|
||||||
|
${task.series_link ?
|
||||||
|
`<a href="${task.series_link}" target="_blank">${task.series_name}</a>` :
|
||||||
|
task.series_name
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>${formatDate(task.series_date)}</td>
|
||||||
|
<td><span class="${priorityClass}">${task.priority || '-'}</span></td>
|
||||||
|
<td>${getStatusBadge(task.status)}</td>
|
||||||
|
<td>${task.claimed_by || '-'}</td>
|
||||||
|
<td>${task.torrent_id || '-'}</td>
|
||||||
|
<td>${formatDateTime(task.created_at)}</td>
|
||||||
|
<td>${actions}</td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
|
||||||
|
tbody.append(row);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渲染分页
|
||||||
|
function renderPagination(current, total) {
|
||||||
|
const pagination = $('#pagination');
|
||||||
|
pagination.empty();
|
||||||
|
|
||||||
|
if (total <= 1) return;
|
||||||
|
|
||||||
|
// 上一页
|
||||||
|
pagination.append(`
|
||||||
|
<li class="page-item ${current === 1 ? 'disabled' : ''}">
|
||||||
|
<a class="page-link" href="#" onclick="loadTasks(${current - 1}); return false;">上一页</a>
|
||||||
|
</li>
|
||||||
|
`);
|
||||||
|
|
||||||
|
// 页码
|
||||||
|
for (let i = 1; i <= total; i++) {
|
||||||
|
if (i === 1 || i === total || (i >= current - 2 && i <= current + 2)) {
|
||||||
|
pagination.append(`
|
||||||
|
<li class="page-item ${i === current ? 'active' : ''}">
|
||||||
|
<a class="page-link" href="#" onclick="loadTasks(${i}); return false;">${i}</a>
|
||||||
|
</li>
|
||||||
|
`);
|
||||||
|
} else if (i === current - 3 || i === current + 3) {
|
||||||
|
pagination.append('<li class="page-item disabled"><span class="page-link">...</span></li>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下一页
|
||||||
|
pagination.append(`
|
||||||
|
<li class="page-item ${current === total ? 'disabled' : ''}">
|
||||||
|
<a class="page-link" href="#" onclick="loadTasks(${current + 1}); return false;">下一页</a>
|
||||||
|
</li>
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打开认领模态框
|
||||||
|
function openClaimModal(taskId) {
|
||||||
|
$('#claim-task-id').val(taskId);
|
||||||
|
$('#claim-note').val('');
|
||||||
|
claimModal.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提交认领
|
||||||
|
function submitClaim() {
|
||||||
|
const taskId = $('#claim-task-id').val();
|
||||||
|
const note = $('#claim-note').val();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: `/api/tasks/${taskId}/claim`,
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data: JSON.stringify({
|
||||||
|
claim_note: note
|
||||||
|
}),
|
||||||
|
success: function() {
|
||||||
|
claimModal.hide();
|
||||||
|
showSuccess('认领成功!');
|
||||||
|
loadTasks(currentPage);
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打开完成模态框
|
||||||
|
function openCompleteModal(taskId) {
|
||||||
|
$('#complete-task-id').val(taskId);
|
||||||
|
$('#torrent-id').val('');
|
||||||
|
$('#complete-note').val('');
|
||||||
|
completeModal.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提交完成
|
||||||
|
function submitComplete() {
|
||||||
|
const taskId = $('#complete-task-id').val();
|
||||||
|
const torrentId = $('#torrent-id').val();
|
||||||
|
const note = $('#complete-note').val();
|
||||||
|
|
||||||
|
if (!torrentId) {
|
||||||
|
alert('请填写种子ID');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: `/api/tasks/${taskId}/complete`,
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data: JSON.stringify({
|
||||||
|
torrent_id: torrentId,
|
||||||
|
complete_note: note
|
||||||
|
}),
|
||||||
|
success: function() {
|
||||||
|
completeModal.hide();
|
||||||
|
showSuccess('任务完成!');
|
||||||
|
loadTasks(currentPage);
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消认领
|
||||||
|
function cancelClaim(taskId) {
|
||||||
|
if (!confirm('确定要取消认领吗?')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: `/api/tasks/${taskId}/cancel-claim`,
|
||||||
|
method: 'POST',
|
||||||
|
success: function() {
|
||||||
|
showSuccess('已取消认领');
|
||||||
|
loadTasks(currentPage);
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查看详情
|
||||||
|
function viewDetail(taskId) {
|
||||||
|
$.ajax({
|
||||||
|
url: `/api/tasks/${taskId}`,
|
||||||
|
method: 'GET',
|
||||||
|
success: function(task) {
|
||||||
|
const html = `
|
||||||
|
<dl class="row">
|
||||||
|
<dt class="col-sm-3">任务ID</dt>
|
||||||
|
<dd class="col-sm-9">${task.id}</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">剧集名称</dt>
|
||||||
|
<dd class="col-sm-9">${task.series_name}</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">剧集链接</dt>
|
||||||
|
<dd class="col-sm-9">
|
||||||
|
${task.series_link ?
|
||||||
|
`<a href="${task.series_link}" target="_blank">${task.series_link}</a>` :
|
||||||
|
'-'
|
||||||
|
}
|
||||||
|
</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">更新日期</dt>
|
||||||
|
<dd class="col-sm-9">${formatDate(task.series_date)}</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">优先级</dt>
|
||||||
|
<dd class="col-sm-9"><span class="${getPriorityClass(task.priority)}">${task.priority || '-'}</span></dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">状态</dt>
|
||||||
|
<dd class="col-sm-9">${getStatusBadge(task.status)}</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">创建人</dt>
|
||||||
|
<dd class="col-sm-9">${task.creator}</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">创建时间</dt>
|
||||||
|
<dd class="col-sm-9">${formatDateTime(task.created_at)}</dd>
|
||||||
|
|
||||||
|
${task.claimed_by ? `
|
||||||
|
<dt class="col-sm-3">认领人</dt>
|
||||||
|
<dd class="col-sm-9">${task.claimed_by}</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">认领时间</dt>
|
||||||
|
<dd class="col-sm-9">${formatDateTime(task.claimed_at)}</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">认领备注</dt>
|
||||||
|
<dd class="col-sm-9">${task.claim_note || '-'}</dd>
|
||||||
|
` : ''}
|
||||||
|
|
||||||
|
${task.torrent_id ? `
|
||||||
|
<dt class="col-sm-3">种子ID</dt>
|
||||||
|
<dd class="col-sm-9">${task.torrent_id}</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">完成时间</dt>
|
||||||
|
<dd class="col-sm-9">${formatDateTime(task.completed_at)}</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">完成备注</dt>
|
||||||
|
<dd class="col-sm-9">${task.complete_note || '-'}</dd>
|
||||||
|
` : ''}
|
||||||
|
</dl>
|
||||||
|
`;
|
||||||
|
|
||||||
|
$('#task-detail').html(html);
|
||||||
|
detailModal.show();
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除任务
|
||||||
|
function deleteTask(taskId) {
|
||||||
|
if (!confirm('确定要删除这个任务吗?此操作不可恢复!')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: `/api/tasks/${taskId}`,
|
||||||
|
method: 'DELETE',
|
||||||
|
success: function() {
|
||||||
|
showSuccess('任务已删除');
|
||||||
|
loadTasks(currentPage);
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置筛选器
|
||||||
|
function resetFilters() {
|
||||||
|
$('#filter-status').val('');
|
||||||
|
$('#filter-scope').val('all');
|
||||||
|
loadTasks(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
164
static/js/users.js
Normal file
164
static/js/users.js
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
let currentStatus = '';
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
loadUsers();
|
||||||
|
|
||||||
|
$('.nav-tabs .nav-link').click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
$('.nav-tabs .nav-link').removeClass('active');
|
||||||
|
$(this).addClass('active');
|
||||||
|
currentStatus = $(this).data('status');
|
||||||
|
loadUsers();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function loadUsers() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/users',
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + localStorage.getItem('access_token')
|
||||||
|
},
|
||||||
|
data: { status: currentStatus },
|
||||||
|
success: function(data) {
|
||||||
|
renderUsers(data.users);
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderUsers(users) {
|
||||||
|
const tbody = $('#users-table');
|
||||||
|
tbody.empty();
|
||||||
|
|
||||||
|
users.forEach(function(user) {
|
||||||
|
const statusBadge = {
|
||||||
|
'pending': '<span class="badge bg-warning">待审核</span>',
|
||||||
|
'active': '<span class="badge bg-success">已激活</span>',
|
||||||
|
'disabled': '<span class="badge bg-secondary">已禁用</span>'
|
||||||
|
}[user.status];
|
||||||
|
|
||||||
|
const roleBadge = user.role === 'admin' ?
|
||||||
|
'<span class="badge bg-danger">管理员</span>' :
|
||||||
|
'<span class="badge bg-primary">用户</span>';
|
||||||
|
|
||||||
|
let actions = '';
|
||||||
|
if (user.status === 'pending') {
|
||||||
|
actions = `
|
||||||
|
<button class="btn btn-sm btn-success" onclick="approveUser(${user.id}, 'approve')">
|
||||||
|
<i class="bi bi-check"></i> 通过
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-sm btn-danger" onclick="approveUser(${user.id}, 'reject')">
|
||||||
|
<i class="bi bi-x"></i> 拒绝
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
|
actions = `
|
||||||
|
<button class="btn btn-sm btn-primary" onclick="editUser(${user.id})">
|
||||||
|
<i class="bi bi-pencil"></i>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-sm btn-danger" onclick="deleteUser(${user.id})">
|
||||||
|
<i class="bi bi-trash"></i>
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
tbody.append(`
|
||||||
|
<tr>
|
||||||
|
<td>${user.username}</td>
|
||||||
|
<td>${user.email}</td>
|
||||||
|
<td>${user.uid || '-'}</td>
|
||||||
|
<td>${roleBadge}</td>
|
||||||
|
<td>${statusBadge}</td>
|
||||||
|
<td>${user.tags || '-'}</td>
|
||||||
|
<td>${user.created_at}</td>
|
||||||
|
<td>${actions}</td>
|
||||||
|
</tr>
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function approveUser(userId, action) {
|
||||||
|
const message = action === 'approve' ? '确认通过审核?' : '确认拒绝申请?';
|
||||||
|
if (!confirm(message)) return;
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: `/api/users/${userId}/approve`,
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + localStorage.getItem('access_token')
|
||||||
|
},
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({ action: action }),
|
||||||
|
success: function(data) {
|
||||||
|
alert(data.message);
|
||||||
|
loadUsers();
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function editUser(userId) {
|
||||||
|
$.ajax({
|
||||||
|
url: `/api/users`,
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + localStorage.getItem('access_token')
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
const user = data.users.find(u => u.id === userId);
|
||||||
|
$('#edit-user-id').val(user.id);
|
||||||
|
$('#edit-email').val(user.email);
|
||||||
|
$('#edit-uid').val(user.uid);
|
||||||
|
$('#edit-role').val(user.role);
|
||||||
|
$('#edit-status').val(user.status);
|
||||||
|
$('#edit-tags').val(user.tags);
|
||||||
|
$('#edit-note').val(user.note);
|
||||||
|
$('#editModal').modal('show');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveUser() {
|
||||||
|
const userId = $('#edit-user-id').val();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: `/api/users/${userId}`,
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + localStorage.getItem('access_token')
|
||||||
|
},
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({
|
||||||
|
email: $('#edit-email').val(),
|
||||||
|
uid: $('#edit-uid').val(),
|
||||||
|
role: $('#edit-role').val(),
|
||||||
|
status: $('#edit-status').val(),
|
||||||
|
tags: $('#edit-tags').val(),
|
||||||
|
note: $('#edit-note').val()
|
||||||
|
}),
|
||||||
|
success: function(data) {
|
||||||
|
alert(data.message);
|
||||||
|
$('#editModal').modal('hide');
|
||||||
|
loadUsers();
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteUser(userId) {
|
||||||
|
if (!confirm('确认删除该用户?')) return;
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: `/api/users/${userId}`,
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + localStorage.getItem('access_token')
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
alert(data.message);
|
||||||
|
loadUsers();
|
||||||
|
},
|
||||||
|
error: handleAjaxError
|
||||||
|
});
|
||||||
|
}
|
||||||
72
templates/base.html
Normal file
72
templates/base.html
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>{% block title %}PT站点管理系统{% endblock %}</title>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-icons.css') }}">
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
||||||
|
|
||||||
|
{% block extra_css %}{% endblock %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- 导航栏 -->
|
||||||
|
{% if show_nav %}
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<a class="navbar-brand" href="{{ url_for('tasks') }}">PT管理系统</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav me-auto">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{{ url_for('tasks') }}">
|
||||||
|
<i class="bi bi-list-task"></i> 任务列表
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{{ url_for('statistics') }}">
|
||||||
|
<i class="bi bi-graph-up"></i> 统计报表
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item admin-only" style="display:none;">
|
||||||
|
<a class="nav-link" href="{{ url_for('create_task_page') }}">
|
||||||
|
<i class="bi bi-plus-circle"></i> 创建任务
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item" id="nav-users" style="display:none;">
|
||||||
|
<a class="nav-link" href="{{ url_for('users_page') }}">
|
||||||
|
<i class="bi bi-people"></i> 用户管理
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{{ url_for('profile_page') }}">
|
||||||
|
<i class="bi bi-person"></i> 个人资料
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div class="d-flex align-items-center text-white">
|
||||||
|
<span class="me-3">欢迎,<span id="current-username"></span></span>
|
||||||
|
<button class="btn btn-outline-light btn-sm" onclick="logout()">退出</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- 主内容 -->
|
||||||
|
<div class="{% if show_nav %}container-fluid mt-4{% endif %}">
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Bootstrap JS -->
|
||||||
|
<script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/bootstrap.bundle.min.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/common.js') }}"></script>
|
||||||
|
|
||||||
|
{% block extra_js %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
38
templates/login.html
Normal file
38
templates/login.html
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}登录 - PT管理系统{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center mt-5">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card shadow">
|
||||||
|
<div class="card-body">
|
||||||
|
<h3 class="card-title text-center mb-4">PT管理系统</h3>
|
||||||
|
<form id="login-form">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="username" class="form-label">用户名</label>
|
||||||
|
<input type="text" class="form-control" id="username" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="password" class="form-label">密码</label>
|
||||||
|
<input type="password" class="form-control" id="password" required>
|
||||||
|
</div>
|
||||||
|
<div class="d-grid">
|
||||||
|
<button type="submit" class="btn btn-primary">登录</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div id="error-msg" class="alert alert-danger mt-3" style="display:none;"></div>
|
||||||
|
<div class="text-center mt-3">
|
||||||
|
<a href="/register">没有账号?立即注册</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_js %}
|
||||||
|
<script src="{{ url_for('static', filename='js/login.js') }}"></script>
|
||||||
|
{% endblock %}
|
||||||
64
templates/profile.html
Normal file
64
templates/profile.html
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% set show_nav = true %}
|
||||||
|
|
||||||
|
{% block title %}个人资料{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<h2 class="mb-4">个人资料</h2>
|
||||||
|
|
||||||
|
<div class="card mb-3">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5>基本信息</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<form id="profile-form">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">用户名</label>
|
||||||
|
<input type="text" class="form-control" id="username" disabled>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">邮箱</label>
|
||||||
|
<input type="email" class="form-control" id="email">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">站点UID</label>
|
||||||
|
<input type="text" class="form-control" id="uid">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">保存</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5>修改密码</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<form id="password-form">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">旧密码</label>
|
||||||
|
<input type="password" class="form-control" id="old-password" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">新密码</label>
|
||||||
|
<input type="password" class="form-control" id="new-password" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">确认新密码</label>
|
||||||
|
<input type="password" class="form-control" id="confirm-password" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-warning">修改密码</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_js %}
|
||||||
|
<script src="{{ url_for('static', filename='js/profile.js') }}"></script>
|
||||||
|
{% endblock %}
|
||||||
52
templates/register.html
Normal file
52
templates/register.html
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>用户注册</title>
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-icons.css') }}">
|
||||||
|
</head>
|
||||||
|
<body class="bg-light">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center mt-5">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card shadow">
|
||||||
|
<div class="card-body p-5">
|
||||||
|
<h3 class="text-center mb-4">用户注册</h3>
|
||||||
|
<form id="register-form">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">用户名 *</label>
|
||||||
|
<input type="text" class="form-control" id="username" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">邮箱 *</label>
|
||||||
|
<input type="email" class="form-control" id="email" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">站点UID</label>
|
||||||
|
<input type="text" class="form-control" id="uid">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">密码 *</label>
|
||||||
|
<input type="password" class="form-control" id="password" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">确认密码 *</label>
|
||||||
|
<input type="password" class="form-control" id="confirm-password" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary w-100">注册</button>
|
||||||
|
</form>
|
||||||
|
<div class="text-center mt-3">
|
||||||
|
<a href="/">已有账号?立即登录</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/bootstrap.bundle.min.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/register.js') }}"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
153
templates/statistics.html
Normal file
153
templates/statistics.html
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% set show_nav = true %}
|
||||||
|
|
||||||
|
{% block title %}统计报表{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_css %}
|
||||||
|
<script src="{{ url_for('static', filename='js/chart.umd.min.js') }}"></script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container-fluid">
|
||||||
|
<h2 class="mb-4">统计报表</h2>
|
||||||
|
|
||||||
|
<!-- 筛选器 -->
|
||||||
|
<div class="card mb-3">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row g-3 align-items-end">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label class="form-label">快捷选择</label>
|
||||||
|
<select class="form-select" id="quick-select" onchange="applyQuickSelect()">
|
||||||
|
<option value="">自定义</option>
|
||||||
|
<option value="today">今天</option>
|
||||||
|
<option value="week">本周</option>
|
||||||
|
<option value="month">本月</option>
|
||||||
|
<option value="30days">最近30天</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label class="form-label">开始日期</label>
|
||||||
|
<input type="date" class="form-control" id="date-from">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label class="form-label">结束日期</label>
|
||||||
|
<input type="date" class="form-control" id="date-to">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<button class="btn btn-primary me-2" onclick="loadStatistics()">
|
||||||
|
<i class="bi bi-search"></i> 查询
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-success" onclick="exportData()">
|
||||||
|
<i class="bi bi-download"></i> 导出CSV
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 概览卡片 -->
|
||||||
|
<div class="row mb-4">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-white bg-primary">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">今日完成</h5>
|
||||||
|
<h2 id="today-count">-</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-white bg-success">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">本月完成</h5>
|
||||||
|
<h2 id="month-count">-</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-white bg-warning">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">待认领</h5>
|
||||||
|
<h2 id="pending-count">-</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-white bg-info">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">进行中</h5>
|
||||||
|
<h2 id="claimed-count">-</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 个人统计 -->
|
||||||
|
<div class="row mb-4">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 id="stats-title">我的完成统计</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="mb-3">
|
||||||
|
<strong>总完成数:</strong><span id="my-total">-</span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<strong>待完成数:</strong><span id="my-pending">-</span>
|
||||||
|
</div>
|
||||||
|
<div style="height: 250px;">
|
||||||
|
<canvas id="myChart"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 排行榜 -->
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5>本月排行榜</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div style="max-height: 400px; overflow-y: auto;">
|
||||||
|
<table class="table table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>排名</th>
|
||||||
|
<th>用户</th>
|
||||||
|
<th>完成数</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="leaderboard">
|
||||||
|
<tr>
|
||||||
|
<td colspan="3" class="text-center">加载中...</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 趋势图 -->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 id="trend-title">完成趋势</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div style="height: 300px;">
|
||||||
|
<canvas id="trendChart"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_js %}
|
||||||
|
<script src="{{ url_for('static', filename='js/statistics.js') }}"></script>
|
||||||
|
{% endblock %}
|
||||||
91
templates/task_create.html
Normal file
91
templates/task_create.html
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% set show_nav = true %}
|
||||||
|
|
||||||
|
{% block title %}创建任务{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h4>创建新任务</h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<form id="create-task-form">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="series-name" class="form-label">剧集名称 <span class="text-danger">*</span></label>
|
||||||
|
<input type="text" class="form-control" id="series-name" required
|
||||||
|
placeholder="例如:某某剧集 S01E01">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="series-link" class="form-label">剧集链接(可选)</label>
|
||||||
|
<input type="url" class="form-control" id="series-link"
|
||||||
|
placeholder="https://...">
|
||||||
|
<small class="form-text text-muted">资源来源链接</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="series-date" class="form-label">剧集更新日期 <span class="text-danger">*</span></label>
|
||||||
|
<input type="date" class="form-control" id="series-date" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="priority" class="form-label">优先级</label>
|
||||||
|
<select class="form-select" id="priority">
|
||||||
|
<option value="中" selected>中</option>
|
||||||
|
<option value="高">高</option>
|
||||||
|
<option value="低">低</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
|
||||||
|
<a href="/tasks" class="btn btn-secondary">取消</a>
|
||||||
|
<button type="submit" class="btn btn-primary">创建任务</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_js %}
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
// 设置默认日期为今天
|
||||||
|
$('#series-date').val(new Date().toISOString().split('T')[0]);
|
||||||
|
|
||||||
|
$('#create-task-form').submit(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
series_name: $('#series-name').val(),
|
||||||
|
series_link: $('#series-link').val() || null,
|
||||||
|
series_date: $('#series-date').val(),
|
||||||
|
priority: $('#priority').val()
|
||||||
|
};
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/groups/1/tasks',
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + localStorage.getItem('access_token'),
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data: JSON.stringify(data),
|
||||||
|
success: function(response) {
|
||||||
|
alert('任务创建成功!');
|
||||||
|
window.location.href = '/tasks';
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
const error = xhr.responseJSON?.error || '创建失败';
|
||||||
|
alert(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
157
templates/task_list.html
Normal file
157
templates/task_list.html
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% set show_nav = true %}
|
||||||
|
|
||||||
|
{% block title %}任务列表{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col">
|
||||||
|
<h2>发布组任务列表</h2>
|
||||||
|
</div>
|
||||||
|
<div class="col text-end admin-only" style="display:none;">
|
||||||
|
<a href="/tasks/create" class="btn btn-primary">
|
||||||
|
<i class="bi bi-plus-circle"></i> 创建任务
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 筛选器 -->
|
||||||
|
<div class="card mb-3">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row g-3">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<label class="form-label">状态</label>
|
||||||
|
<select id="filter-status" class="form-select">
|
||||||
|
<option value="">全部</option>
|
||||||
|
<option value="pending">待认领</option>
|
||||||
|
<option value="claimed">已认领</option>
|
||||||
|
<option value="completed">已完成</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<label class="form-label">查看范围</label>
|
||||||
|
<select id="filter-scope" class="form-select">
|
||||||
|
<option value="all">全部任务</option>
|
||||||
|
<option value="my">我的任务</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 d-flex align-items-end">
|
||||||
|
<button class="btn btn-primary" onclick="loadTasks()">
|
||||||
|
<i class="bi bi-search"></i> 查询
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-secondary ms-2" onclick="resetFilters()">
|
||||||
|
<i class="bi bi-arrow-clockwise"></i> 重置
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 任务表格 -->
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>剧集名称</th>
|
||||||
|
<th>更新日期</th>
|
||||||
|
<th>优先级</th>
|
||||||
|
<th>状态</th>
|
||||||
|
<th>认领人</th>
|
||||||
|
<th>种子ID</th>
|
||||||
|
<th>创建时间</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="task-list">
|
||||||
|
<tr>
|
||||||
|
<td colspan="9" class="text-center">加载中...</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 分页 -->
|
||||||
|
<nav>
|
||||||
|
<ul class="pagination justify-content-center" id="pagination">
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 认领任务模态框 -->
|
||||||
|
<div class="modal fade" id="claimModal" tabindex="-1">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">认领任务</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form id="claim-form">
|
||||||
|
<input type="hidden" id="claim-task-id">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">认领备注(可选)</label>
|
||||||
|
<textarea class="form-control" id="claim-note" rows="3"></textarea>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
||||||
|
<button type="button" class="btn btn-primary" onclick="submitClaim()">确认认领</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 完成任务模态框 -->
|
||||||
|
<div class="modal fade" id="completeModal" tabindex="-1">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">完成任务</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form id="complete-form">
|
||||||
|
<input type="hidden" id="complete-task-id">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">种子ID <span class="text-danger">*</span></label>
|
||||||
|
<input type="text" class="form-control" id="torrent-id" required placeholder="例如:12345">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">完成备注(可选)</label>
|
||||||
|
<textarea class="form-control" id="complete-note" rows="3"></textarea>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
||||||
|
<button type="button" class="btn btn-success" onclick="submitComplete()">确认完成</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 任务详情模态框 -->
|
||||||
|
<div class="modal fade" id="detailModal" tabindex="-1">
|
||||||
|
<div class="modal-dialog modal-lg">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">任务详情</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body" id="task-detail">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_js %}
|
||||||
|
<script src="{{ url_for('static', filename='js/task_list.js') }}"></script>
|
||||||
|
{% endblock %}
|
||||||
98
templates/users.html
Normal file
98
templates/users.html
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% set show_nav = true %}
|
||||||
|
|
||||||
|
{% block title %}用户管理{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container-fluid">
|
||||||
|
<h2 class="mb-4">用户管理</h2>
|
||||||
|
|
||||||
|
<ul class="nav nav-tabs mb-3">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" data-status="" href="#">全部</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" data-status="pending" href="#">待审核</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" data-status="active" href="#">已激活</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" data-status="disabled" href="#">已禁用</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>用户名</th>
|
||||||
|
<th>邮箱</th>
|
||||||
|
<th>UID</th>
|
||||||
|
<th>角色</th>
|
||||||
|
<th>状态</th>
|
||||||
|
<th>标签</th>
|
||||||
|
<th>注册时间</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="users-table"></tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 编辑用户模态框 -->
|
||||||
|
<div class="modal fade" id="editModal">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">编辑用户</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<input type="hidden" id="edit-user-id">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">邮箱</label>
|
||||||
|
<input type="email" class="form-control" id="edit-email">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">UID</label>
|
||||||
|
<input type="text" class="form-control" id="edit-uid">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">角色</label>
|
||||||
|
<select class="form-select" id="edit-role">
|
||||||
|
<option value="user">普通用户</option>
|
||||||
|
<option value="admin">管理员</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">状态</label>
|
||||||
|
<select class="form-select" id="edit-status">
|
||||||
|
<option value="active">已激活</option>
|
||||||
|
<option value="disabled">已禁用</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">标签</label>
|
||||||
|
<input type="text" class="form-control" id="edit-tags" placeholder="多个标签用逗号分隔">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">备注</label>
|
||||||
|
<textarea class="form-control" id="edit-note" rows="3"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
||||||
|
<button type="button" class="btn btn-primary" onclick="saveUser()">保存</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_js %}
|
||||||
|
<script src="{{ url_for('static', filename='js/users.js') }}"></script>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user