合并JWL,WZY,TRM代码
Change-Id: Ifb4fcad3c06733e1e005e7d8d9403e3561010fb4
diff --git a/Merge/back_trm/README.md b/Merge/back_trm/README.md
new file mode 100644
index 0000000..cef32ef
--- /dev/null
+++ b/Merge/back_trm/README.md
@@ -0,0 +1,70 @@
+# Back-end Flask Project
+
+## Overview
+This project is a basic Flask application structure designed to demonstrate the organization of a Flask project. It includes essential components such as routes, models, templates, and configuration files.
+
+## Project Structure
+```
+Back
+├── app
+│ ├── __init__.py
+│ ├── routes.py
+│ ├── models.py
+│ └── templates
+│ ├── base.html
+│ └── index.html
+├── tests
+│ └── test_app.py
+├── app.py
+├── config.py
+├── requirements.txt
+└── README.md
+```
+
+## Setup Instructions
+
+1. **Clone the repository**:
+ ```
+ git clone <repository-url>
+ cd Back
+ ```
+
+2. **Create a virtual environment**:
+ ```
+ python -m venv venv
+ ```
+
+3. **Activate the virtual environment**:
+ - On Windows:
+ ```
+ venv\Scripts\activate
+ ```
+ - On macOS/Linux:
+ ```
+ source venv/bin/activate
+ ```
+
+4. **Install dependencies**:
+ ```
+ pip install -r requirements.txt
+ ```
+
+5. **Run the application**:
+ ```
+ python app.py
+ ```
+
+## Usage
+Once the application is running, you can access it at `http://127.0.0.1:5000/`. The index page will be displayed.
+
+## Testing
+To run the tests, ensure the virtual environment is activated and execute:
+```
+pytest tests/test_app.py
+```
+
+## Contributing
+Feel free to submit issues or pull requests for improvements or bug fixes.
+
+## License
+This project is licensed under the MIT License.
\ No newline at end of file
diff --git a/Merge/back_trm/__pycache__/__init__.cpython-312.pyc b/Merge/back_trm/__pycache__/__init__.cpython-312.pyc
new file mode 100644
index 0000000..aad3f55
--- /dev/null
+++ b/Merge/back_trm/__pycache__/__init__.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/__pycache__/config.cpython-310.pyc b/Merge/back_trm/__pycache__/config.cpython-310.pyc
new file mode 100644
index 0000000..47d55f3
--- /dev/null
+++ b/Merge/back_trm/__pycache__/config.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_trm/app.py b/Merge/back_trm/app.py
new file mode 100644
index 0000000..3c7fb86
--- /dev/null
+++ b/Merge/back_trm/app.py
@@ -0,0 +1,8 @@
+from app import create_app
+from flask_cors import CORS
+
+app = create_app()
+CORS(app, resources={r"/*": {"origins": "*"}})
+
+if __name__ == "__main__":
+ app.run(debug=True,port=5713,host='0.0.0.0')
\ No newline at end of file
diff --git a/Merge/back_trm/app/__init__.py b/Merge/back_trm/app/__init__.py
new file mode 100644
index 0000000..5587d2a
--- /dev/null
+++ b/Merge/back_trm/app/__init__.py
@@ -0,0 +1,15 @@
+from flask import Flask
+
+def create_app():
+ app = Flask(__name__)
+
+ # Load configuration
+ app.config.from_object('config.Config')
+
+ # Register blueprints or routes
+ from .routes import main as main_blueprint
+ app.register_blueprint(main_blueprint)
+
+ return app
+
+app = create_app()
\ No newline at end of file
diff --git a/Merge/back_trm/app/__pycache__/__init__.cpython-310.pyc b/Merge/back_trm/app/__pycache__/__init__.cpython-310.pyc
new file mode 100644
index 0000000..f713fad
--- /dev/null
+++ b/Merge/back_trm/app/__pycache__/__init__.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_trm/app/__pycache__/__init__.cpython-312.pyc b/Merge/back_trm/app/__pycache__/__init__.cpython-312.pyc
new file mode 100644
index 0000000..ec28c7e
--- /dev/null
+++ b/Merge/back_trm/app/__pycache__/__init__.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/app/__pycache__/routes.cpython-310.pyc b/Merge/back_trm/app/__pycache__/routes.cpython-310.pyc
new file mode 100644
index 0000000..5166bf4
--- /dev/null
+++ b/Merge/back_trm/app/__pycache__/routes.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_trm/app/functions/Fpost.py b/Merge/back_trm/app/functions/Fpost.py
new file mode 100644
index 0000000..7d6ccd2
--- /dev/null
+++ b/Merge/back_trm/app/functions/Fpost.py
@@ -0,0 +1,102 @@
+from ..models.users import User as users
+from ..models.post import Post as post
+import secrets
+import hashlib
+from datetime import datetime, timedelta
+from sqlalchemy.orm import Session
+class Fpost:
+ def __init__(self,session:Session):
+ self.session=session
+ return
+
+
+ def getlist(self):
+ results = self.session.query(post.id, post.title,post.status)
+ return results
+
+ def getuserlist(self):
+ results= self.session.query(users.id, users.username, users.role)
+ return results
+
+ def giveadmin(self,userid):
+ res=self.session.query(users).filter(users.id==userid).first()
+ if not res:
+ return False
+ res.role='admin'
+ self.session.commit()
+ return True
+
+ def giveuser(self,userid):
+ res=self.session.query(users).filter(users.id==userid).first()
+ if not res:
+ return False
+ res.role='user'
+ self.session.commit()
+ return True
+
+ def givesuperadmin(self,userid):
+ res=self.session.query(users).filter(users.id==userid).first()
+ if not res:
+ return False
+ res.role='superadmin'
+ self.session.commit()
+ return True
+
+
+ def getpost(self,postid):
+ res=self.session.query(post).filter(post.id==postid).first()
+ return res
+ def checkid(self,userid,status=''):
+ res=self.session.query(users).filter(users.id==userid).first()
+ if(not res):
+ return False
+ if res.role !=status:
+ return False
+ return True
+
+ def review(self,postid,status):
+ print(status)
+ res=self.session.query(post).filter(post.id==postid).first()
+ if not res:
+ return False
+ res.status=status
+ self.session.commit()
+ return True
+
+ def createtoken(self, userid):
+ """
+ 根据userid创建token并插入到数据库
+ :param userid: 用户ID
+ :return: 生成的token字符串
+ """
+ # 生成随机盐值
+ salt = secrets.token_hex(16)
+
+ # 创建哈希值:userid + 当前时间戳 + 随机盐值
+ current_time = str(datetime.now().timestamp())
+ hash_input = f"{userid}_{current_time}_{salt}"
+
+ # 生成SHA256哈希值作为token
+ token = hashlib.sha256(hash_input.encode()).hexdigest()
+
+ # 设置时间
+ created_time = datetime.now()
+ expires_time = created_time + timedelta(days=1) # 一天后过期
+
+ try:
+ # 创建新的token记录
+ new_token = Token(
+ token=token,
+ expires_at=expires_time,
+ created_at=created_time
+ )
+
+ # 假设self.session是数据库会话对象
+ self.session.add(new_token)
+ self.session.commit()
+
+ return token
+
+ except Exception as e:
+ self.session.rollback()
+ raise Exception(f"创建token失败: {str(e)}")
\ No newline at end of file
diff --git a/Merge/back_trm/app/functions/__pycache__/Fpost.cpython-310.pyc b/Merge/back_trm/app/functions/__pycache__/Fpost.cpython-310.pyc
new file mode 100644
index 0000000..f9b1bc6
--- /dev/null
+++ b/Merge/back_trm/app/functions/__pycache__/Fpost.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_trm/app/models/__init__.py b/Merge/back_trm/app/models/__init__.py
new file mode 100644
index 0000000..f726a19
--- /dev/null
+++ b/Merge/back_trm/app/models/__init__.py
@@ -0,0 +1,8 @@
+from sqlalchemy.ext.declarative import declarative_base
+
+Base = declarative_base()
+
+# 先定义好 Base,再把所有 model import 进来,让 SQLAlchemy 一次性注册它们
+from .users import User
+from .topics import Topic
+from .post import Post
\ No newline at end of file
diff --git a/Merge/back_trm/app/models/__pycache__/__init__.cpython-310.pyc b/Merge/back_trm/app/models/__pycache__/__init__.cpython-310.pyc
new file mode 100644
index 0000000..015de51
--- /dev/null
+++ b/Merge/back_trm/app/models/__pycache__/__init__.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_trm/app/models/__pycache__/post.cpython-310.pyc b/Merge/back_trm/app/models/__pycache__/post.cpython-310.pyc
new file mode 100644
index 0000000..8d33351
--- /dev/null
+++ b/Merge/back_trm/app/models/__pycache__/post.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_trm/app/models/__pycache__/topics.cpython-310.pyc b/Merge/back_trm/app/models/__pycache__/topics.cpython-310.pyc
new file mode 100644
index 0000000..fba569b
--- /dev/null
+++ b/Merge/back_trm/app/models/__pycache__/topics.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_trm/app/models/__pycache__/users.cpython-310.pyc b/Merge/back_trm/app/models/__pycache__/users.cpython-310.pyc
new file mode 100644
index 0000000..155a86c
--- /dev/null
+++ b/Merge/back_trm/app/models/__pycache__/users.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_trm/app/models/post.py b/Merge/back_trm/app/models/post.py
new file mode 100644
index 0000000..041e263
--- /dev/null
+++ b/Merge/back_trm/app/models/post.py
@@ -0,0 +1,111 @@
+from .users import User
+from . import Base
+
+from sqlalchemy import (
+ Column, Integer, String, Text, JSON, Enum,
+ TIMESTAMP, ForeignKey, Index, func, text
+)
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.orm import relationship
+
+
+class Post(Base):
+ __tablename__ = 'posts'
+ __table_args__ = (
+ # 索引
+ Index('idx_posts_heat', 'heat'),
+ # MySQL 引擎、字符集、校对规则、表注释
+ {
+ 'mysql_engine': 'InnoDB',
+ 'mysql_charset': 'utf8mb4',
+ 'mysql_collate': 'utf8mb4_general_ci',
+ 'comment': '内容帖子表'
+ }
+ )
+
+ def to_dict(self):
+ return {
+ 'id': self.id if self.id else None,
+ 'user_id': self.user_id if self.user_id else None,
+ 'topic_id': self.topic_id if self.topic_id else None,
+ 'type': self.type if self.type else None,
+ 'title': self.title if self.title else None,
+ 'content': self.content if self.content else None,
+ 'media_urls': self.media_urls if self.media_urls else None,
+ 'status': self.status if self.status else None,
+ 'heat': self.heat if self.heat else None,
+ 'created_at': self.created_at.isoformat() if self.created_at else None,
+ 'updated_at': self.updated_at.isoformat() if self.updated_at else None
+ }
+
+
+ id = Column(
+ Integer,
+ primary_key=True,
+ autoincrement=True,
+ comment='帖子ID'
+ )
+ user_id = Column(
+ Integer,
+ ForeignKey('users.id', ondelete='CASCADE'),
+ nullable=False,
+ index=True,
+ comment='作者ID'
+ )
+ topic_id = Column(
+ Integer,
+ ForeignKey('topics.id', ondelete='SET NULL'),
+ nullable=True,
+ index=True,
+ comment='所属话题ID'
+ )
+ type = Column(
+ Enum('text', 'image', 'video', 'document', name='post_type'),
+ nullable=False,
+ server_default=text("'text'"),
+ comment='内容类型'
+ )
+ title = Column(
+ String(255),
+ nullable=False,
+ comment='标题'
+ )
+ content = Column(
+ Text,
+ nullable=False,
+ comment='正文内容'
+ )
+ media_urls = Column(
+ JSON,
+ nullable=True,
+ comment='媒体资源URL数组'
+ )
+ status = Column(
+ Enum('draft', 'pending', 'published', 'deleted', 'rejected', name='post_status'),
+ nullable=False,
+ server_default=text("'draft'"),
+ comment='状态'
+ )
+ heat = Column(
+ Integer,
+ nullable=False,
+ server_default=text('0'),
+ comment='热度值'
+ )
+ created_at = Column(
+ TIMESTAMP,
+ nullable=True,
+ server_default=func.current_timestamp(),
+ comment='创建时间'
+ )
+ updated_at = Column(
+ TIMESTAMP,
+ nullable=True,
+ server_default=func.current_timestamp(),
+ onupdate=func.current_timestamp(),
+ comment='更新时间'
+ )
+
+ # 可选:与 User/Topic 模型的关系(需要在 User、Topic 中也定义 back_populates)
+ # user = relationship('User', back_populates='posts')
+ # topic = relationship('Topic', back_populates='posts')
diff --git a/Merge/back_trm/app/models/token.py b/Merge/back_trm/app/models/token.py
new file mode 100644
index 0000000..cbe864b
--- /dev/null
+++ b/Merge/back_trm/app/models/token.py
@@ -0,0 +1,27 @@
+from sqlalchemy import Column, Integer, String, DateTime, TIMESTAMP, Index
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.sql import func
+from datetime import datetime
+
+Base = declarative_base()
+
+class Token(Base):
+ __tablename__ = 'tokens'
+
+ id = Column(Integer, primary_key=True, autoincrement=True)
+ token = Column(String(255), nullable=False, unique=True)
+ expires_at = Column(DateTime, nullable=False)
+ created_at = Column(TIMESTAMP, default=func.current_timestamp())
+ updated_at = Column(TIMESTAMP, default=func.current_timestamp(), onupdate=func.current_timestamp())
+
+ __table_args__ = (
+ Index('idx_token', 'token'),
+ Index('idx_expires_at', 'expires_at'),
+ )
+
+ def __repr__(self):
+ return f"<Token(id={self.id}, token='{self.token[:10]}...', expires_at={self.expires_at})>"
+
+ def is_expired(self):
+ """检查token是否已过期"""
+ return datetime.now() > self.expires_at
\ No newline at end of file
diff --git a/Merge/back_trm/app/models/topics.py b/Merge/back_trm/app/models/topics.py
new file mode 100644
index 0000000..1a35a38
--- /dev/null
+++ b/Merge/back_trm/app/models/topics.py
@@ -0,0 +1,26 @@
+from . import Base
+from sqlalchemy import Column, Integer, String, Text, Enum, TIMESTAMP
+from sqlalchemy.sql import func
+
+class Topic(Base):
+ __tablename__ = 'topics'
+ __table_args__ = {
+ 'mysql_engine': 'InnoDB',
+ 'mysql_charset': 'utf8mb4',
+ 'mysql_collate': 'utf8mb4_general_ci',
+ 'comment': '话题/超话表'
+ }
+
+ id = Column(Integer, primary_key=True, autoincrement=True, comment='话题ID')
+ name = Column(String(100, collation='utf8mb4_general_ci'), nullable=False, unique=True, comment='话题名称')
+ description = Column(Text(collation='utf8mb4_general_ci'), comment='话题描述')
+ status = Column(
+ Enum('active', 'archived', name='topic_status', collation='utf8mb4_general_ci'),
+ default='active',
+ comment='状态'
+ )
+ created_at = Column(
+ TIMESTAMP,
+ server_default=func.current_timestamp(),
+ comment='创建时间'
+ )
\ No newline at end of file
diff --git a/Merge/back_trm/app/models/users.py b/Merge/back_trm/app/models/users.py
new file mode 100644
index 0000000..0505e86
--- /dev/null
+++ b/Merge/back_trm/app/models/users.py
@@ -0,0 +1,51 @@
+from . import Base
+from sqlalchemy import (
+ Column, Integer, String, Enum, TIMESTAMP, text
+)
+from sqlalchemy.ext.declarative import declarative_base
+
+
+class User(Base):
+ __tablename__ = 'users'
+
+ def to_dict(self):
+ return {
+ 'id': self.id,
+ 'username': self.username if self.username else None,
+ 'email': self.email if self.email else None,
+ 'avatar': self.avatar if self.avatar else None,
+ 'role': self.role if self.role else None,
+ 'bio': self.bio if self.bio else None,
+ 'status': self.status if self.status else None,
+ 'created_at': self.created_at.isoformat() if self.created_at else None,
+ 'updated_at': self.updated_at.isoformat() if self.updated_at else None
+ }
+
+
+
+ id = Column(Integer, primary_key=True, autoincrement=True, comment='用户ID')
+ username = Column(String(50), nullable=False, unique=True, comment='用户名')
+ password = Column(String(255), nullable=False, comment='加密密码')
+ email = Column(String(100), nullable=False, unique=True, comment='邮箱')
+ avatar = Column(String(255), comment='头像URL')
+ role = Column(Enum('user', 'admin', 'superadmin', name='user_role'), comment='角色')
+ bio = Column(String(255), comment='个人简介')
+ status = Column(
+ Enum('active','banned','muted', name='user_status'),
+ nullable=False,
+ server_default=text("'active'"),
+ comment='账号状态'
+ )
+ created_at = Column(
+ TIMESTAMP,
+ nullable=True,
+ server_default=text('CURRENT_TIMESTAMP'),
+ comment='创建时间'
+ )
+ updated_at = Column(
+ TIMESTAMP,
+ nullable=True,
+ server_default=text('CURRENT_TIMESTAMP'),
+ onupdate=text('CURRENT_TIMESTAMP'),
+ comment='更新时间'
+ )
\ No newline at end of file
diff --git a/Merge/back_trm/app/routes.py b/Merge/back_trm/app/routes.py
new file mode 100644
index 0000000..41b022b
--- /dev/null
+++ b/Merge/back_trm/app/routes.py
@@ -0,0 +1,155 @@
+from flask import Blueprint, render_template
+from .functions.Fpost import Fpost;
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+from config import Config
+from flask import jsonify,request
+
+main = Blueprint('main', __name__)
+
+@main.route('/sgiveadmin',methods=['POST','GET'])
+def giveadmin():
+ data=request.get_json()
+ print(data)
+ engine=create_engine(Config.SQLURL)
+ SessionLocal = sessionmaker(bind=engine)
+ session = SessionLocal()
+ f=Fpost(session)
+ checres=f.checkid(data['userid'],'superadmin')
+ if(not checres):
+ return jsonify({'status': 'error', 'message': 'Unauthorized'})
+
+ res=f.giveadmin(data['targetid'])
+ if not res:
+ return jsonify({'status': 'error', 'message': 'User not found'})
+
+ return jsonify({'status': 'success', 'message': 'User role updated to admin'})
+
+@main.route('/sgiveuser',methods=['POST','GET'])
+def giveuser():
+ data=request.get_json()
+ print(data)
+ engine=create_engine(Config.SQLURL)
+ SessionLocal = sessionmaker(bind=engine)
+ session = SessionLocal()
+ f=Fpost(session)
+ checres=f.checkid(data['userid'],'superadmin')
+ if(not checres):
+ return jsonify({'status': 'error', 'message': 'Unauthorized'})
+
+ res=f.giveuser(data['targetid'])
+ if not res:
+ return jsonify({'status': 'error', 'message': 'User not found'})
+
+ return jsonify({'status': 'success', 'message': 'User role updated to user'})
+
+
+@main.route('/sgivesuperadmin',methods=['POST','GET'])
+def givesuperadmin():
+ data=request.get_json()
+ print(data)
+ engine=create_engine(Config.SQLURL)
+ SessionLocal = sessionmaker(bind=engine)
+ session = SessionLocal()
+ f=Fpost(session)
+ checres=f.checkid(data['userid'],'superadmin')
+ if(not checres):
+ return jsonify({'status': 'error', 'message': 'Unauthorized'})
+
+ res=f.givesuperadmin(data['targetid'])
+ if not res:
+ return jsonify({'status': 'error', 'message': 'User not found'})
+
+ return jsonify({'status': 'success', 'message': 'User role updated to superadmin'})
+
+@main.route('/sgetuserlist',methods=['POST','GET'])
+def userlist():
+ data=request.get_json()
+ print(data)
+ engine=create_engine(Config.SQLURL)
+ SessionLocal = sessionmaker(bind=engine)
+ session = SessionLocal()
+ f=Fpost(session)
+ checres=f.checkid(data['userid'],'superadmin')
+ if(not checres):
+ return jsonify({'status': 'error', 'message': 'Unauthorized'})
+ res=f.getuserlist()
+ respons=[]
+ for datai in res:
+ respons.append({
+ 'id': datai[0],
+ 'username': datai[1],
+ 'role': datai[2]
+ })
+ return jsonify(respons)
+
+@main.route('/apostlist',methods=['POST','GET'])
+def postlist():
+ data=request.get_json()
+ print(data)
+ engine=create_engine(Config.SQLURL)
+ SessionLocal = sessionmaker(bind=engine)
+ session = SessionLocal()
+ f=Fpost(session)
+ checres=f.checkid(data['userid'],'admin')
+ if(not checres):
+ return jsonify({'status': 'error', 'message': 'Unauthorized'})
+ res=f.getlist()
+ respons=[]
+ for datai in res:
+ respons.append({
+ 'id': datai[0],
+ 'title': datai[1],
+ 'status': datai[2]
+ })
+ return jsonify(respons)
+
+@main.route('/agetpost',methods=['POST','GET'])
+def post():
+ data=request.get_json()
+ engine=create_engine(Config.SQLURL)
+ SessionLocal = sessionmaker(bind=engine)
+ session = SessionLocal()
+ f=Fpost(session)
+ checres=f.checkid(data['userid'],'admin')
+ if(not checres):
+ return jsonify({'status': 'error', 'message': 'Unauthorized'})
+ res=f.getpost(data['postid'])
+
+ return jsonify(res.to_dict() if res else {})
+
+@main.route('/areview',methods=['POST','GET'])
+def review():
+ data=request.get_json()
+ engine=create_engine(Config.SQLURL)
+ SessionLocal = sessionmaker(bind=engine)
+ session = SessionLocal()
+ f=Fpost(session)
+ checres=f.checkid(data['userid'],'admin')
+ if(not checres):
+ return jsonify({'status': 'error', 'message': 'Unauthorized'})
+
+ res=f.review(data['postid'],data['status'])
+ if not res:
+ return jsonify({'status': 'error', 'message': 'Post not found'})
+
+ return jsonify({'status': 'success', 'message': 'Post reviewed successfully'})
+
+
+
+@main.route('/nginxauth',methods=['POST','GET'])
+def nginxauth():
+ data=request.get_json()
+ engine=create_engine(Config.SQLURL)
+ SessionLocal = sessionmaker(bind=engine)
+ session = SessionLocal()
+ f=Fpost(session)
+ checres=f.checkid(data['userid'],'admin')
+ if(not checres):
+ return jsonify({'status': 'error', 'message': 'Unauthorized'})
+
+ res=f.nginxauth(data['postid'],data['status'])
+ if not res:
+ return jsonify({'status': 'error', 'message': 'Post not found'})
+
+ return jsonify({'status': 'success', 'message': 'Nginx auth updated successfully'})
\ No newline at end of file
diff --git a/Merge/back_trm/app/templates/base.html b/Merge/back_trm/app/templates/base.html
new file mode 100644
index 0000000..3c6f3cb
--- /dev/null
+++ b/Merge/back_trm/app/templates/base.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>{% block title %}My Flask App{% endblock %}</title>
+ <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
+</head>
+<body>
+ <header>
+ <h1>Welcome to My Flask App</h1>
+ <nav>
+ <ul>
+ <li><a href="{{ url_for('index') }}">Home</a></li>
+ <!-- Add more navigation links here -->
+ </ul>
+ </nav>
+ </header>
+
+ <main>
+ {% block content %}
+ {% endblock %}
+ </main>
+
+ <footer>
+ <p>© 2023 My Flask App</p>
+ </footer>
+</body>
+</html>
\ No newline at end of file
diff --git a/Merge/back_trm/app/templates/index.html b/Merge/back_trm/app/templates/index.html
new file mode 100644
index 0000000..6631bea
--- /dev/null
+++ b/Merge/back_trm/app/templates/index.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Index Page</title>
+ <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
+</head>
+<body>
+ {% extends 'base.html' %}
+
+ {% block content %}
+ <h1>Welcome to the Index Page</h1>
+ <p>This is the main page of the application.</p>
+ {% endblock %}
+</body>
+</html>
\ No newline at end of file
diff --git a/Merge/back_trm/config.py b/Merge/back_trm/config.py
new file mode 100644
index 0000000..d4a2e88
--- /dev/null
+++ b/Merge/back_trm/config.py
@@ -0,0 +1,12 @@
+import os
+from dotenv import load_dotenv
+load_dotenv()
+class Config:
+ SECRET_KEY = os.environ.get('SECRET_KEY') or 'a_default_secret_key'
+ SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or 'sqlite:///site.db'
+ SQLALCHEMY_TRACK_MODIFICATIONS = False
+ SQLURL=os.getenv('SQLURL')
+ SQLPORT=os.getenv('SQLPORT')
+ SQLNAME=os.getenv('SQLNAME')
+ SQLUSER=os.getenv('SQLUSER')
+ SQLPWD=os.getenv('SQLPWD')
\ No newline at end of file
diff --git a/Merge/back_trm/requirements.txt b/Merge/back_trm/requirements.txt
new file mode 100644
index 0000000..8e65f82
--- /dev/null
+++ b/Merge/back_trm/requirements.txt
@@ -0,0 +1,6 @@
+Flask==2.2.2
+SQLAlchemy==1.4.36
+Flask-Migrate==3.1.0
+Flask-WTF==1.0.0
+pytest==7.1.2
+```
\ No newline at end of file
diff --git a/Merge/back_trm/tests/__init__.py b/Merge/back_trm/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Merge/back_trm/tests/__init__.py
diff --git a/Merge/back_trm/tests/__pycache__/__init__.cpython-312.pyc b/Merge/back_trm/tests/__pycache__/__init__.cpython-312.pyc
new file mode 100644
index 0000000..48c8068
--- /dev/null
+++ b/Merge/back_trm/tests/__pycache__/__init__.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_trm/tests/__pycache__/test_app.cpython-312-pytest-7.4.4.pyc b/Merge/back_trm/tests/__pycache__/test_app.cpython-312-pytest-7.4.4.pyc
new file mode 100644
index 0000000..9a2b7de
--- /dev/null
+++ b/Merge/back_trm/tests/__pycache__/test_app.cpython-312-pytest-7.4.4.pyc
Binary files differ
diff --git a/Merge/back_trm/tests/test_app.py b/Merge/back_trm/tests/test_app.py
new file mode 100644
index 0000000..3ed6bf9
--- /dev/null
+++ b/Merge/back_trm/tests/test_app.py
@@ -0,0 +1,41 @@
+import requests
+url = 'http://127.0.0.1:5713/'
+
+def test_get_postlist():
+ print()
+ urlx=url+'apostlist'
+ payload = {
+ 'userid': 3
+ }
+ headers = {'Content-Type': 'application/json'}
+
+ resp = requests.get(urlx, json=payload, headers=headers)
+ # print(resp.status_code)
+ print(resp.json())
+
+def test_get_post():
+ print()
+ urlx=url+'agetpost'
+ payload = {
+ 'userid': 3,
+ 'postid': 21
+ }
+ headers = {'Content-Type': 'application/json'}
+
+ resp = requests.get(urlx, json=payload, headers=headers)
+ # print(resp.status_code)
+ print(resp.json())
+
+def test_review_post():
+ print()
+ urlx=url+'areview'
+ payload = {
+ 'userid': 3,
+ 'postid': 21,
+ 'status': 'rejected'
+ }
+ headers = {'Content-Type': 'application/json'}
+
+ resp = requests.get(urlx, json=payload, headers=headers)
+ # print(resp.status_code)
+ print(resp.json())
\ No newline at end of file
diff --git a/Merge/back_wzy/__pycache__/app.cpython-312.pyc b/Merge/back_wzy/__pycache__/app.cpython-312.pyc
new file mode 100644
index 0000000..215bc7f
--- /dev/null
+++ b/Merge/back_wzy/__pycache__/app.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/__pycache__/config.cpython-310.pyc b/Merge/back_wzy/__pycache__/config.cpython-310.pyc
new file mode 100644
index 0000000..0d915b2
--- /dev/null
+++ b/Merge/back_wzy/__pycache__/config.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_wzy/__pycache__/config.cpython-312.pyc b/Merge/back_wzy/__pycache__/config.cpython-312.pyc
new file mode 100644
index 0000000..4e1a3be
--- /dev/null
+++ b/Merge/back_wzy/__pycache__/config.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/__pycache__/extensions.cpython-310.pyc b/Merge/back_wzy/__pycache__/extensions.cpython-310.pyc
new file mode 100644
index 0000000..ba72eec
--- /dev/null
+++ b/Merge/back_wzy/__pycache__/extensions.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_wzy/__pycache__/extensions.cpython-312.pyc b/Merge/back_wzy/__pycache__/extensions.cpython-312.pyc
new file mode 100644
index 0000000..27ba8c2
--- /dev/null
+++ b/Merge/back_wzy/__pycache__/extensions.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/all_tables.sql b/Merge/back_wzy/all_tables.sql
new file mode 100644
index 0000000..fd5d1e5
--- /dev/null
+++ b/Merge/back_wzy/all_tables.sql
@@ -0,0 +1,182 @@
+/*
+数据库设计说明:
+1. 核心表结构:
+ users:存储用户信息,包含角色管理和账号状态
+ posts:核心内容表,支持多模态内容(图文/视频/文档)
+ behaviors:记录用户互动行为(点赞/收藏/浏览等)
+ comments:评论系统,支持多级回复
+ follows:用户社交关系
+2. 推荐系统支持:
+ posts.heat 字段存储动态计算的热度值
+ behaviors 表记录用户行为用于协同过滤
+ user_tags 表构建用户兴趣画像
+ 通过 post_tags 实现内容标签分类
+3. 多模态内容处理:
+ posts.media_urls 使用 JSON 类型存储多个资源 URL
+ posts.type 区分不同类型的内容(图文/视频/文档)
+4. 审核与安全:
+ audits 表记录内容审核历史
+ posts.status 管理内容生命周期状态
+ logs 表记录系统操作和访问日志
+5. 性能优化:
+ 为查询频繁字段添加索引(热度/行为类型/时间)
+ 使用 JSON 类型存储灵活数据(通知内容/媒体资源)
+ 通过 heat 字段预计算支持热门排序
+6. 扩展性设计:
+ 用户画像系统通过 user_tags 表实现
+ 通知系统支持多种互动类型
+ 行为表设计支持未来扩展新行为类型
+*/
+
+DROP DATABASE IF EXISTS redbook;
+
+-- 创建数据库
+CREATE DATABASE IF NOT EXISTS redbook DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
+USE redbook;
+
+-- 用户表
+CREATE TABLE users (
+ id INT AUTO_INCREMENT PRIMARY KEY COMMENT '用户ID',
+ username VARCHAR(50) NOT NULL UNIQUE COMMENT '用户名',
+ password VARCHAR(255) NOT NULL COMMENT '加密密码',
+ email VARCHAR(100) NOT NULL UNIQUE COMMENT '邮箱',
+ avatar VARCHAR(255) COMMENT '头像URL',
+ role ENUM('user', 'admin') DEFAULT 'user' COMMENT '角色',
+ bio VARCHAR(255) COMMENT '个人简介',
+ status ENUM('active', 'banned', 'muted') DEFAULT 'active' COMMENT '账号状态',
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
+) ENGINE=InnoDB COMMENT='用户表';
+
+-- 标签表
+CREATE TABLE tags (
+ id INT AUTO_INCREMENT PRIMARY KEY COMMENT '标签ID',
+ name VARCHAR(50) NOT NULL UNIQUE COMMENT '标签名称',
+ description VARCHAR(255) COMMENT '标签描述',
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
+) ENGINE=InnoDB COMMENT='内容标签表';
+
+-- 话题/超话表
+CREATE TABLE topics (
+ id INT AUTO_INCREMENT PRIMARY KEY COMMENT '话题ID',
+ name VARCHAR(100) NOT NULL UNIQUE COMMENT '话题名称',
+ description TEXT COMMENT '话题描述',
+ status ENUM('active', 'archived') DEFAULT 'active' COMMENT '状态',
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
+) ENGINE=InnoDB COMMENT='话题/超话表';
+
+-- 内容帖子表
+CREATE TABLE posts (
+ id INT AUTO_INCREMENT PRIMARY KEY COMMENT '帖子ID',
+ user_id INT NOT NULL COMMENT '作者ID',
+ topic_id INT COMMENT '所属话题ID',
+ type ENUM('text', 'image', 'video', 'document') DEFAULT 'text' COMMENT '内容类型',
+ title VARCHAR(255) NOT NULL COMMENT '标题',
+ content TEXT NOT NULL COMMENT '正文内容',
+ media_urls JSON COMMENT '媒体资源URL数组',
+ status ENUM('draft', 'pending', 'published', 'deleted', 'rejected') DEFAULT 'draft' COMMENT '状态',
+ heat INT DEFAULT 0 COMMENT '热度值',
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY (topic_id) REFERENCES topics(id) ON DELETE SET NULL
+) ENGINE=InnoDB COMMENT='内容帖子表';
+
+-- 帖子标签关联表
+CREATE TABLE post_tags (
+ post_id INT NOT NULL COMMENT '帖子ID',
+ tag_id INT NOT NULL COMMENT '标签ID',
+ PRIMARY KEY (post_id, tag_id),
+ FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE,
+ FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
+) ENGINE=InnoDB COMMENT='帖子标签关联表';
+
+-- 用户行为表
+CREATE TABLE behaviors (
+ id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '行为ID',
+ user_id INT NOT NULL COMMENT '用户ID',
+ post_id INT NOT NULL COMMENT '帖子ID',
+ type ENUM('like', 'comment', 'favorite', 'view', 'share') NOT NULL COMMENT '行为类型',
+ value INT DEFAULT 1 COMMENT '行为值',
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '行为时间',
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE
+) ENGINE=InnoDB COMMENT='用户行为记录表';
+
+-- 评论表
+CREATE TABLE comments (
+ id INT AUTO_INCREMENT PRIMARY KEY COMMENT '评论ID',
+ post_id INT NOT NULL COMMENT '帖子ID',
+ user_id INT NOT NULL COMMENT '用户ID',
+ parent_id INT DEFAULT NULL COMMENT '父评论ID',
+ content TEXT NOT NULL COMMENT '评论内容',
+ status ENUM('active', 'deleted') DEFAULT 'active' COMMENT '状态',
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+ FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE,
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY (parent_id) REFERENCES comments(id) ON DELETE CASCADE
+) ENGINE=InnoDB COMMENT='评论表';
+
+-- 用户关注关系表
+CREATE TABLE follows (
+ follower_id INT NOT NULL COMMENT '关注者ID',
+ followee_id INT NOT NULL COMMENT '被关注者ID',
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '关注时间',
+ PRIMARY KEY (follower_id, followee_id),
+ FOREIGN KEY (follower_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY (followee_id) REFERENCES users(id) ON DELETE CASCADE
+) ENGINE=InnoDB COMMENT='用户关注关系表';
+
+-- 通知表
+CREATE TABLE notifications (
+ id INT AUTO_INCREMENT PRIMARY KEY COMMENT '通知ID',
+ user_id INT NOT NULL COMMENT '接收用户ID',
+ type ENUM('like', 'comment', 'follow', 'system', 'audit') NOT NULL COMMENT '通知类型',
+ content JSON NOT NULL COMMENT '通知内容',
+ is_read BOOLEAN DEFAULT FALSE COMMENT '是否已读',
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
+) ENGINE=InnoDB COMMENT='用户通知表';
+
+-- 审核记录表
+CREATE TABLE audits (
+ id INT AUTO_INCREMENT PRIMARY KEY COMMENT '审核ID',
+ post_id INT NOT NULL COMMENT '帖子ID',
+ admin_id INT NOT NULL COMMENT '管理员ID',
+ result ENUM('approved', 'rejected') NOT NULL COMMENT '审核结果',
+ reason VARCHAR(255) COMMENT '审核原因',
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '审核时间',
+ FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE,
+ FOREIGN KEY (admin_id) REFERENCES users(id) ON DELETE CASCADE
+) ENGINE=InnoDB COMMENT='内容审核记录表';
+
+-- 日志表
+CREATE TABLE logs (
+ id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '日志ID',
+ user_id INT DEFAULT NULL COMMENT '用户ID',
+ type ENUM('access', 'error', 'behavior', 'system') NOT NULL COMMENT '日志类型',
+ content TEXT NOT NULL COMMENT '日志内容',
+ ip VARCHAR(45) COMMENT 'IP地址',
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '记录时间',
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
+) ENGINE=InnoDB COMMENT='系统日志表';
+
+-- 用户兴趣标签表(用户画像)
+CREATE TABLE user_tags (
+ user_id INT NOT NULL COMMENT '用户ID',
+ tag_id INT NOT NULL COMMENT '标签ID',
+ weight FLOAT DEFAULT 1.0 COMMENT '兴趣权重',
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+ PRIMARY KEY (user_id, tag_id),
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
+) ENGINE=InnoDB COMMENT='用户兴趣标签表';
+
+-- 索引优化
+CREATE INDEX idx_posts_heat ON posts(heat);
+CREATE INDEX idx_behaviors_type ON behaviors(type);
+CREATE INDEX idx_notifications_read ON notifications(is_read);
+CREATE INDEX idx_logs_created ON logs(created_at);
+CREATE INDEX idx_comments_post ON comments(post_id);
\ No newline at end of file
diff --git a/Merge/back_wzy/app.py b/Merge/back_wzy/app.py
new file mode 100644
index 0000000..a90f62f
--- /dev/null
+++ b/Merge/back_wzy/app.py
@@ -0,0 +1,30 @@
+# app.py
+
+from flask import Flask
+from flask_cors import CORS
+from config import Config
+from extensions import db, migrate
+
+def create_app():
+ app = Flask(__name__)
+ app.config.from_object(Config)
+
+ # 启用 CORS:允许前端 http://localhost:5173 发起跨域请求
+ # 生产环境请根据实际域名调整 origins
+ CORS(app, resources={r"/*": {"origins": "*"}})
+ db.init_app(app)
+ migrate.init_app(app, db)
+
+ # 在工厂函数里再导入并注册蓝图
+ from routes.posts import posts_bp
+ from routes.comments import comments_bp
+
+ app.register_blueprint(posts_bp, url_prefix='/posts')
+ app.register_blueprint(comments_bp, url_prefix='/posts/<int:post_id>/comments')
+
+ return app
+
+# 只有直接用 python app.py 时,这段才会执行
+if __name__ == '__main__':
+ app = create_app()
+ app.run(host='0.0.0.0', port=5714, debug=True)
diff --git a/Merge/back_wzy/config.py b/Merge/back_wzy/config.py
new file mode 100644
index 0000000..e5bdb32
--- /dev/null
+++ b/Merge/back_wzy/config.py
@@ -0,0 +1,11 @@
+# config.py
+import os
+
+basedir = os.path.abspath(os.path.dirname(__file__))
+
+class Config:
+ SECRET_KEY = os.environ.get('SECRET_KEY', 'you-will-never-guess')
+ SQLALCHEMY_DATABASE_URI = os.environ.get(
+ 'SQLURL'
+ )
+ SQLALCHEMY_TRACK_MODIFICATIONS = False
diff --git a/Merge/back_wzy/extensions.py b/Merge/back_wzy/extensions.py
new file mode 100644
index 0000000..3563787
--- /dev/null
+++ b/Merge/back_wzy/extensions.py
@@ -0,0 +1,6 @@
+# extensions.py(根目录,同级于 app.py)
+from flask_sqlalchemy import SQLAlchemy
+from flask_migrate import Migrate
+
+db = SQLAlchemy()
+migrate = Migrate()
diff --git a/Merge/back_wzy/manage.py b/Merge/back_wzy/manage.py
new file mode 100644
index 0000000..15ab995
--- /dev/null
+++ b/Merge/back_wzy/manage.py
@@ -0,0 +1,12 @@
+# manage.py
+from flask_script import Manager
+from flask_migrate import MigrateCommand
+
+from app import app, db
+
+manager = Manager(app)
+# 添加 db 子命令: migrate, upgrade, downgrade 等
+manager.add_command('db', MigrateCommand)
+
+if __name__ == '__main__':
+ manager.run()
diff --git a/Merge/back_wzy/models/__init__.py b/Merge/back_wzy/models/__init__.py
new file mode 100644
index 0000000..f7cef7b
--- /dev/null
+++ b/Merge/back_wzy/models/__init__.py
@@ -0,0 +1,12 @@
+# models/__init__.py
+# --------------------------------------------------
+# 绝**对**不要**从** app.py 导入 db!
+# 改成:
+from extensions import db
+
+from .user import User
+from .topic import Topic
+from .tag import Tag
+from .post import Post, post_tags
+from .behavior import Behavior
+from .comment import Comment
diff --git a/Merge/back_wzy/models/__pycache__/__init__.cpython-310.pyc b/Merge/back_wzy/models/__pycache__/__init__.cpython-310.pyc
new file mode 100644
index 0000000..fa2d5c2
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/__init__.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/__init__.cpython-312.pyc b/Merge/back_wzy/models/__pycache__/__init__.cpython-312.pyc
new file mode 100644
index 0000000..fe53b2a
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/__init__.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/behavior.cpython-310.pyc b/Merge/back_wzy/models/__pycache__/behavior.cpython-310.pyc
new file mode 100644
index 0000000..bd2fdec
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/behavior.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/behavior.cpython-312.pyc b/Merge/back_wzy/models/__pycache__/behavior.cpython-312.pyc
new file mode 100644
index 0000000..71f3757
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/behavior.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/comment.cpython-310.pyc b/Merge/back_wzy/models/__pycache__/comment.cpython-310.pyc
new file mode 100644
index 0000000..550853e
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/comment.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/comment.cpython-312.pyc b/Merge/back_wzy/models/__pycache__/comment.cpython-312.pyc
new file mode 100644
index 0000000..393c6d3
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/comment.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/post.cpython-310.pyc b/Merge/back_wzy/models/__pycache__/post.cpython-310.pyc
new file mode 100644
index 0000000..3131d0b
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/post.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/post.cpython-312.pyc b/Merge/back_wzy/models/__pycache__/post.cpython-312.pyc
new file mode 100644
index 0000000..1d64737
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/post.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/tag.cpython-310.pyc b/Merge/back_wzy/models/__pycache__/tag.cpython-310.pyc
new file mode 100644
index 0000000..649f51e
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/tag.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/tag.cpython-312.pyc b/Merge/back_wzy/models/__pycache__/tag.cpython-312.pyc
new file mode 100644
index 0000000..d76c0e0
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/tag.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/topic.cpython-310.pyc b/Merge/back_wzy/models/__pycache__/topic.cpython-310.pyc
new file mode 100644
index 0000000..7fd8f9e
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/topic.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/topic.cpython-312.pyc b/Merge/back_wzy/models/__pycache__/topic.cpython-312.pyc
new file mode 100644
index 0000000..a779595
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/topic.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/user.cpython-310.pyc b/Merge/back_wzy/models/__pycache__/user.cpython-310.pyc
new file mode 100644
index 0000000..2fc98eb
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/user.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/__pycache__/user.cpython-312.pyc b/Merge/back_wzy/models/__pycache__/user.cpython-312.pyc
new file mode 100644
index 0000000..e3841c7
--- /dev/null
+++ b/Merge/back_wzy/models/__pycache__/user.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/models/behavior.py b/Merge/back_wzy/models/behavior.py
new file mode 100644
index 0000000..aed413f
--- /dev/null
+++ b/Merge/back_wzy/models/behavior.py
@@ -0,0 +1,13 @@
+# models/behavior.py
+from extensions import db
+from datetime import datetime
+
+class Behavior(db.Model):
+ __tablename__ = 'behaviors'
+
+ id = db.Column(db.BigInteger, primary_key=True)
+ user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='CASCADE'), nullable=False)
+ post_id = db.Column(db.Integer, db.ForeignKey('posts.id', ondelete='CASCADE'), nullable=False)
+ type = db.Column(db.Enum('like', 'comment', 'favorite', 'view', 'share'), nullable=False)
+ value = db.Column(db.Integer, default=1, nullable=False)
+ created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
diff --git a/Merge/back_wzy/models/comment.py b/Merge/back_wzy/models/comment.py
new file mode 100644
index 0000000..ce25287
--- /dev/null
+++ b/Merge/back_wzy/models/comment.py
@@ -0,0 +1,24 @@
+# models/comment.py
+from extensions import db
+from datetime import datetime
+
+class Comment(db.Model):
+ __tablename__ = 'comments'
+
+ id = db.Column(db.Integer, primary_key=True)
+ post_id = db.Column(db.Integer, db.ForeignKey('posts.id', ondelete='CASCADE'), nullable=False)
+ user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='CASCADE'), nullable=False)
+ parent_id = db.Column(db.Integer, db.ForeignKey('comments.id', ondelete='CASCADE'))
+ content = db.Column(db.Text, nullable=False)
+ status = db.Column(db.Enum('active', 'deleted'), default='active', nullable=False)
+ created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
+ updated_at = db.Column(db.DateTime, default=datetime.utcnow,
+ onupdate=datetime.utcnow, nullable=False)
+
+ # self-referential replies
+ replies = db.relationship(
+ 'Comment',
+ backref=db.backref('parent', remote_side=[id]),
+ lazy='dynamic',
+ cascade='all, delete-orphan'
+ )
diff --git a/Merge/back_wzy/models/post.py b/Merge/back_wzy/models/post.py
new file mode 100644
index 0000000..ab99191
--- /dev/null
+++ b/Merge/back_wzy/models/post.py
@@ -0,0 +1,32 @@
+# models/post.py
+from extensions import db
+from datetime import datetime
+
+# association table for Post <-> Tag
+post_tags = db.Table(
+ 'post_tags',
+ db.Column('post_id', db.Integer, db.ForeignKey('posts.id', ondelete='CASCADE'), primary_key=True),
+ db.Column('tag_id', db.Integer, db.ForeignKey('tags.id', ondelete='CASCADE'), primary_key=True)
+)
+
+class Post(db.Model):
+ __tablename__ = 'posts'
+
+ id = db.Column(db.Integer, primary_key=True)
+ user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='CASCADE'), nullable=False)
+ topic_id = db.Column(db.Integer, db.ForeignKey('topics.id', ondelete='SET NULL'))
+ type = db.Column(db.Enum('text', 'image', 'video', 'document'), default='text', nullable=False)
+ title = db.Column(db.String(255), nullable=False)
+ content = db.Column(db.Text, nullable=False)
+ media_urls = db.Column(db.JSON)
+ status = db.Column(db.Enum('draft', 'pending', 'published', 'deleted', 'rejected'),
+ default='draft', nullable=False)
+ heat = db.Column(db.Integer, default=0, nullable=False)
+ created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
+ updated_at = db.Column(db.DateTime, default=datetime.utcnow,
+ onupdate=datetime.utcnow, nullable=False)
+
+ # relationships
+ tags = db.relationship('Tag', secondary=post_tags, backref=db.backref('posts', lazy='dynamic'))
+ behaviors = db.relationship('Behavior', backref='post', lazy='dynamic', cascade='all, delete')
+ comments = db.relationship('Comment', backref='post', lazy='dynamic', cascade='all, delete')
diff --git a/Merge/back_wzy/models/tag.py b/Merge/back_wzy/models/tag.py
new file mode 100644
index 0000000..7753a38
--- /dev/null
+++ b/Merge/back_wzy/models/tag.py
@@ -0,0 +1,13 @@
+# models/tag.py
+from extensions import db
+from datetime import datetime
+
+class Tag(db.Model):
+ __tablename__ = 'tags'
+
+ id = db.Column(db.Integer, primary_key=True)
+ name = db.Column(db.String(50), unique=True, nullable=False)
+ description = db.Column(db.String(255))
+ created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
+
+ # posts relationship via association table defined in post.py
diff --git a/Merge/back_wzy/models/topic.py b/Merge/back_wzy/models/topic.py
new file mode 100644
index 0000000..d0e5a2e
--- /dev/null
+++ b/Merge/back_wzy/models/topic.py
@@ -0,0 +1,14 @@
+# models/topic.py
+from extensions import db
+from datetime import datetime
+
+class Topic(db.Model):
+ __tablename__ = 'topics'
+
+ id = db.Column(db.Integer, primary_key=True)
+ name = db.Column(db.String(100), unique=True, nullable=False)
+ description = db.Column(db.Text)
+ status = db.Column(db.Enum('active', 'archived'), default='active', nullable=False)
+ created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
+
+ posts = db.relationship('Post', backref='topic', lazy='dynamic', cascade='all, delete')
diff --git a/Merge/back_wzy/models/user.py b/Merge/back_wzy/models/user.py
new file mode 100644
index 0000000..f27e7d3
--- /dev/null
+++ b/Merge/back_wzy/models/user.py
@@ -0,0 +1,68 @@
+# models/user.py
+
+from datetime import datetime
+from extensions import db
+
+# 关联表:用户关注关系
+follows = db.Table(
+ 'follows',
+ db.Column('follower_id', db.Integer, db.ForeignKey('users.id', ondelete='CASCADE'), primary_key=True),
+ db.Column('followee_id', db.Integer, db.ForeignKey('users.id', ondelete='CASCADE'), primary_key=True),
+ db.Column('created_at', db.DateTime, default=datetime.utcnow, nullable=False)
+)
+
+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 = db.Column(db.String(255), nullable=False)
+ email = db.Column(db.String(100), unique=True, nullable=False)
+ avatar = db.Column(db.String(255))
+ role = db.Column(db.Enum('user', 'admin'), default='user', nullable=False)
+ bio = db.Column(db.String(255))
+ status = db.Column(db.Enum('active', 'banned', 'muted'), default='active', nullable=False)
+ created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
+ updated_at = db.Column(
+ db.DateTime,
+ default=datetime.utcnow,
+ onupdate=datetime.utcnow,
+ nullable=False
+ )
+
+ # 用户发布的帖子
+ posts = db.relationship(
+ 'Post',
+ backref='author',
+ lazy='dynamic',
+ cascade='all, delete-orphan'
+ )
+
+ # 用户的互动行为
+ behaviors = db.relationship(
+ 'Behavior',
+ backref='user',
+ lazy='dynamic',
+ cascade='all, delete-orphan'
+ )
+
+ # 用户发表的评论
+ comments = db.relationship(
+ 'Comment',
+ backref='user',
+ lazy='dynamic',
+ cascade='all, delete-orphan'
+ )
+
+ # 用户关注的对象列表
+ following = db.relationship(
+ 'User',
+ secondary=follows,
+ primaryjoin=(id == follows.c.follower_id),
+ secondaryjoin=(id == follows.c.followee_id),
+ backref=db.backref('followers', lazy='dynamic'),
+ lazy='dynamic'
+ )
+
+ def __repr__(self):
+ return f"<User {self.username!r} id={self.id}>"
diff --git a/Merge/back_wzy/readme.md b/Merge/back_wzy/readme.md
new file mode 100644
index 0000000..9fab23e
--- /dev/null
+++ b/Merge/back_wzy/readme.md
@@ -0,0 +1,400 @@
+## 2. 帖子(Post)
+
+### 2.1 发布新帖
+
+```
+POST /posts
+```
+
+- **描述**:创建一条帖子
+
+- **请求头**
+
+ ```
+ Content-Type: application/json
+ ```
+
+- **请求体**
+
+ ```json
+ {
+ "user_id": 1,
+ "topic_id": 1, // 可选,必须是已存在 topic 的 ID
+ "title": "帖子标题",
+ "content": "正文内容",
+ "media_urls": [ // 可选,字符串数组
+ "https://example.com/img1.jpg",
+ "https://example.com/vid1.mp4"
+ ],
+ "status": "published" // draft|pending|published|deleted|rejected
+ }
+ ```
+
+- **成功响应**
+
+ - **状态**:201 Created
+
+ - **Body**
+
+ ```json
+ { "id": 42 }
+ ```
+
+- **错误**
+
+ - 400 Bad Request: 缺少 user_id、title 或 content
+ - 400 Bad Request: topic_id 不存在
+ - 400 Bad Request: JSON 解析错误
+ - 422 Unprocessable Entity: media_urls 格式错误
+ - 500 Internal Server Error: 外键约束或其他数据库错误
+
+------
+
+### 2.2 获取帖子列表
+
+```
+GET /posts
+```
+
+- **描述**:拉取所有 `status=published` 的帖子
+
+- **响应**
+
+ - **状态**:200 OK
+
+ - **Body**
+
+ ```json
+ [
+ {
+ "id": 42,
+ "title": "帖子标题",
+ "heat": 5,
+ "created_at": "2025-06-12T16:00:00"
+ },
+ ...
+ ]
+ ```
+
+------
+
+### 2.3 查看帖子详情
+
+```
+GET /posts/{post_id}
+```
+
+- **描述**:查看单条帖子完整信息
+
+- **路径参数**
+
+ | 参数 | 描述 |
+ | ------- | ------- |
+ | post_id | 帖子 ID |
+
+- **响应**
+
+ - **状态**:200 OK
+
+ - **Body**
+
+ ```json
+ {
+ "id": 42,
+ "user_id": 1,
+ "topic_id": 1,
+ "title": "帖子标题",
+ "content": "正文内容",
+ "media_urls": ["…"],
+ "status": "published",
+ "heat": 5,
+ "created_at": "2025-06-12T16:00:00",
+ "updated_at": "2025-06-12T16:05:00"
+ }
+ ```
+
+- **错误**
+
+ - 404 Not Found: 帖子不存在
+
+------
+
+### 2.4 修改帖子
+
+```
+PUT /posts/{post_id}
+```
+
+- **描述**:更新帖子字段
+
+- **路径参数**
+
+ | 参数 | 描述 |
+ | ------- | ------- |
+ | post_id | 帖子 ID |
+
+- **请求头**
+
+ ```
+ Content-Type: application/json
+ ```
+
+- **请求体**(所有字段可选,依需更新)
+
+ ```json
+ {
+ "title": "新标题",
+ "content": "新内容",
+ "topic_id": 2,
+ "media_urls": ["…"],
+ "status": "draft"
+ }
+ ```
+
+- **响应**
+
+ - **状态**:204 No Content
+
+- **错误**
+
+ - 400 Bad Request: JSON 格式或字段值不合法
+ - 404 Not Found: 帖子不存在
+
+------
+
+### 2.5 删除帖子
+
+```
+DELETE /posts/{post_id}
+```
+
+- **描述**:删除帖子及其关联行为、评论
+
+- **路径参数**
+
+ | 参数 | 描述 |
+ | ------- | ------- |
+ | post_id | 帖子 ID |
+
+- **响应**
+
+ - **状态**:204 No Content
+
+- **错误**
+
+ - 404 Not Found: 帖子不存在
+
+------
+
+## 3. 互动行为(Behavior)
+
+> 支持四种操作:`like`、`favorite`、`view`、`share`。其中 `like` 和 `favorite` 限制每人每帖最多一次,可撤销;`view`/`share` 不限次数,不提供撤销。
+
+### 3.1 点赞
+
+```
+POST /posts/{post_id}/like
+```
+
+- **描述**:用户点赞,热度 +1
+
+- **请求头**
+
+ ```
+ Content-Type: application/json
+ ```
+
+- **请求体**
+
+ ```json
+ { "user_id": 1 }
+ ```
+
+- **响应**
+
+ - **状态**:201 Created
+
+- **错误**
+
+ - 400 Bad Request: 已点赞过 → `{"error":"already liked"}`
+ - 400 Bad Request: 缺少 user_id
+ - 404 Not Found: 帖子或用户不存在
+
+### 3.2 取消点赞
+
+```
+DELETE /posts/{post_id}/like
+```
+
+- **描述**:撤销点赞,热度 -1(底线 0)
+
+- **请求头**
+
+ ```
+ Content-Type: application/json
+ ```
+
+- **请求体**
+
+ ```json
+ { "user_id": 1 }
+ ```
+
+- **响应**
+
+ - **状态**:204 No Content
+
+- **错误**
+
+ - 400 Bad Request: 未点赞过 → `{"error":"not liked yet"}`
+ - 404 Not Found: 帖子或用户不存在
+
+------
+
+### 3.3 收藏
+
+```
+POST /posts/{post_id}/favorite
+```
+
+- **描述**:用户收藏,热度 +1
+- **请求头/体/响应/错误**
+ 与点赞接口完全一致,只把 `like` 换成 `favorite`,错误信息为 `already favorited` / `not favorited yet`。
+
+### 3.4 取消收藏
+
+```
+DELETE /posts/{post_id}/favorite
+```
+
+- **描述**:撤销收藏,热度 -1
+- **请求头/体/响应/错误**
+ 同上。
+
+------
+
+### 3.5 浏览
+
+```
+POST /posts/{post_id}/view
+```
+
+- **描述**:记录一次浏览,热度 +1
+
+- **请求体**
+
+ ```json
+ { "user_id": 1 }
+ ```
+
+- **响应**
+
+ - 201 Created
+
+不支持撤销;不做去重检查。
+
+------
+
+### 3.6 分享
+
+```
+POST /posts/{post_id}/share
+```
+
+- **描述**:记录一次分享,热度 +1
+- **请求体/响应**
+ 同浏览。
+
+------
+
+## 4. 评论(Comment)
+
+### 4.1 添加评论
+
+```
+POST /posts/{post_id}/comments
+```
+
+- **描述**:为帖子添加评论或回复
+
+- **请求头**
+
+ ```
+ Content-Type: application/json
+ ```
+
+- **请求体**
+
+ ```json
+ {
+ "user_id": 2,
+ "content": "这是评论内容",
+ "parent_id": 1 // 可选:回复某条评论时填,一级评论则省略
+ }
+ ```
+
+- **响应**
+
+ - **状态**:201 Created
+
+ - **Body**
+
+ ```json
+ { "id": 7 }
+ ```
+
+- **错误**
+
+ - 400 Bad Request: 缺少 user_id 或 content
+ - 404 Not Found: 帖子或 parent_id 不存在
+
+------
+
+### 4.2 获取评论列表
+
+```
+GET /posts/{post_id}/comments
+```
+
+- **描述**:拉取该帖所有一级评论及其完整回复树
+
+- **响应**
+
+ - **状态**:200 OK
+
+ - **Body**
+
+ ```json
+ [
+ {
+ "id": 1,
+ "user_id": 1,
+ "content": "一级评论",
+ "created_at": "…",
+ "replies": [
+ {
+ "id": 2,
+ "user_id": 2,
+ "content": "回复评论",
+ "created_at": "…",
+ "replies": [ … ]
+ }
+ ]
+ },
+ …
+ ]
+ ```
+
+- **错误**
+
+ - 404 Not Found: 帖子不存在
+
+------
+
+> **通用错误响应格式**
+>
+> ```json
+> {
+> "error": "描述信息"
+> }
+> ```
\ No newline at end of file
diff --git a/Merge/back_wzy/requirements.txt b/Merge/back_wzy/requirements.txt
new file mode 100644
index 0000000..4db9d23
--- /dev/null
+++ b/Merge/back_wzy/requirements.txt
@@ -0,0 +1,6 @@
+# requirements.txt
+Flask>=2.0
+Flask-SQLAlchemy>=2.5
+Flask-Migrate>=3.1
+Flask-Script>=2.0
+PyMySQL>=1.0
diff --git a/Merge/back_wzy/routes/__init__.py b/Merge/back_wzy/routes/__init__.py
new file mode 100644
index 0000000..5410dd3
--- /dev/null
+++ b/Merge/back_wzy/routes/__init__.py
@@ -0,0 +1,4 @@
+# routes/__init__.py
+from flask import Blueprint
+
+# 可以在这里统一注册蓝图,也可以直接在 app.py 中 import
diff --git a/Merge/back_wzy/routes/__pycache__/__init__.cpython-310.pyc b/Merge/back_wzy/routes/__pycache__/__init__.cpython-310.pyc
new file mode 100644
index 0000000..fd9f45b
--- /dev/null
+++ b/Merge/back_wzy/routes/__pycache__/__init__.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_wzy/routes/__pycache__/__init__.cpython-312.pyc b/Merge/back_wzy/routes/__pycache__/__init__.cpython-312.pyc
new file mode 100644
index 0000000..acde7ed
--- /dev/null
+++ b/Merge/back_wzy/routes/__pycache__/__init__.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/routes/__pycache__/comments.cpython-310.pyc b/Merge/back_wzy/routes/__pycache__/comments.cpython-310.pyc
new file mode 100644
index 0000000..087a126
--- /dev/null
+++ b/Merge/back_wzy/routes/__pycache__/comments.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_wzy/routes/__pycache__/comments.cpython-312.pyc b/Merge/back_wzy/routes/__pycache__/comments.cpython-312.pyc
new file mode 100644
index 0000000..4bd83ee
--- /dev/null
+++ b/Merge/back_wzy/routes/__pycache__/comments.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/routes/__pycache__/posts.cpython-310.pyc b/Merge/back_wzy/routes/__pycache__/posts.cpython-310.pyc
new file mode 100644
index 0000000..a22b03e
--- /dev/null
+++ b/Merge/back_wzy/routes/__pycache__/posts.cpython-310.pyc
Binary files differ
diff --git a/Merge/back_wzy/routes/__pycache__/posts.cpython-312.pyc b/Merge/back_wzy/routes/__pycache__/posts.cpython-312.pyc
new file mode 100644
index 0000000..a957747
--- /dev/null
+++ b/Merge/back_wzy/routes/__pycache__/posts.cpython-312.pyc
Binary files differ
diff --git a/Merge/back_wzy/routes/comments.py b/Merge/back_wzy/routes/comments.py
new file mode 100644
index 0000000..2d5b654
--- /dev/null
+++ b/Merge/back_wzy/routes/comments.py
@@ -0,0 +1,46 @@
+# routes/comments.py
+from flask import Blueprint, request, jsonify, abort
+from extensions import db
+from models.comment import Comment
+from models.behavior import Behavior
+
+comments_bp = Blueprint('comments', __name__)
+
+@comments_bp.route('', methods=['POST'])
+def add_comment(post_id):
+ data = request.get_json() or {}
+ user_id = data.get('user_id')
+ content = data.get('content')
+ if not user_id or not content:
+ return jsonify({'error': 'user_id and content required'}), 400
+
+ comment = Comment(
+ post_id=post_id,
+ user_id=user_id,
+ content=content,
+ parent_id=data.get('parent_id')
+ )
+ db.session.add(comment)
+ # 记录行为
+ beh = Behavior(user_id=user_id, post_id=post_id, type='comment')
+ db.session.add(beh)
+ db.session.commit()
+ return jsonify({'id': comment.id}), 201
+
+@comments_bp.route('', methods=['GET'])
+def list_comments(post_id):
+ def serialize(c):
+ return {
+ 'id': c.id,
+ 'user_id': c.user_id,
+ 'content': c.content,
+ 'created_at': c.created_at.isoformat(),
+ 'replies': [serialize(r) for r in c.replies]
+ }
+
+ comments = Comment.query.filter_by(
+ post_id=post_id,
+ status='active',
+ parent_id=None
+ ).order_by(Comment.created_at.asc()).all()
+ return jsonify([serialize(c) for c in comments])
diff --git a/Merge/back_wzy/routes/posts.py b/Merge/back_wzy/routes/posts.py
new file mode 100644
index 0000000..e01bdd8
--- /dev/null
+++ b/Merge/back_wzy/routes/posts.py
@@ -0,0 +1,150 @@
+# routes/posts.py
+from flask import Blueprint, request, jsonify, abort
+from extensions import db
+from models.post import Post
+from models.behavior import Behavior
+
+posts_bp = Blueprint('posts', __name__)
+
+@posts_bp.route('', methods=['POST'])
+def create_post():
+ data = request.get_json() or {}
+ post = Post(**data)
+ db.session.add(post)
+ db.session.commit()
+ return jsonify({'id': post.id}), 201
+
+@posts_bp.route('', methods=['GET'])
+def list_posts():
+ posts = Post.query.filter_by(status='published').all()
+ return jsonify([{
+ 'id': p.id,
+ 'title': p.title,
+ 'heat': p.heat,
+ 'created_at': p.created_at.isoformat()
+ } for p in posts])
+
+@posts_bp.route('/<int:post_id>', methods=['GET'])
+def get_post(post_id):
+ post = Post.query.get_or_404(post_id)
+ return jsonify({
+ 'id': post.id,
+ 'user_id': post.user_id,
+ 'title': post.title,
+ 'content': post.content,
+ 'media_urls': post.media_urls,
+ 'status': post.status,
+ 'heat': post.heat,
+ 'created_at': post.created_at.isoformat(),
+ 'updated_at': post.updated_at.isoformat()
+ })
+
+@posts_bp.route('/<int:post_id>', methods=['PUT'])
+def update_post(post_id):
+ """
+ 修改帖子
+ URL 参数:
+ post_id - 要修改的帖子 ID
+ JSON Body 可选字段:
+ title (string)
+ content (string)
+ topic_id (int) — 必须是 topics 表中已有的 ID
+ media_urls (list) — 字符串数组
+ status (string) — 'draft','pending','published','deleted','rejected'
+ """
+ post = Post.query.get_or_404(post_id)
+ data = request.get_json() or {}
+ # 只更新客户端传来的字段
+ for key in ('title','content','topic_id','media_urls','status'):
+ if key in data:
+ setattr(post, key, data[key])
+ db.session.commit()
+ return '', 204
+
+@posts_bp.route('/<int:post_id>', methods=['DELETE'])
+def delete_post(post_id):
+ post = Post.query.get_or_404(post_id)
+ db.session.delete(post)
+ db.session.commit()
+ return '', 204
+
+
+@posts_bp.route('/<int:post_id>/<action>', methods=['POST'])
+def post_action(post_id, action):
+ """
+ 支持的 action: like, favorite, view, share
+ 对于 like 和 favorite,保证每个用户每帖只做一次。
+ """
+ if action not in ('like', 'favorite', 'view', 'share'):
+ abort(400, 'Invalid action')
+
+ data = request.get_json() or {}
+ user_id = data.get('user_id')
+ if not user_id:
+ abort(400, 'user_id required')
+
+ # 对 like/favorite 做去重检查
+ if action in ('like', 'favorite'):
+ exists = Behavior.query.filter_by(
+ user_id=user_id,
+ post_id=post_id,
+ type=action
+ ).first()
+ if exists:
+ return jsonify({'error': f'already {action}d'}), 400
+
+ # 创建行为记录
+ beh = Behavior(user_id=user_id, post_id=post_id, type=action)
+ db.session.add(beh)
+
+ # 更新热度
+ post = Post.query.get_or_404(post_id)
+ post.heat += 1
+
+ db.session.commit()
+ return '', 201
+
+
+# 取消点赞
+@posts_bp.route('/<int:post_id>/like', methods=['DELETE'])
+def unlike(post_id):
+ user_id = request.get_json(silent=True) and request.get_json().get('user_id')
+ if not user_id:
+ abort(400, 'user_id required')
+ # 查找已有的 like 行为
+ beh = Behavior.query.filter_by(
+ user_id=user_id,
+ post_id=post_id,
+ type='like'
+ ).first()
+ if not beh:
+ return jsonify({'error': 'not liked yet'}), 400
+
+ db.session.delete(beh)
+ # 更新热度,确保不降到负数
+ post = Post.query.get_or_404(post_id)
+ post.heat = max(post.heat - 1, 0)
+ db.session.commit()
+ return '', 204
+
+# 取消收藏
+@posts_bp.route('/<int:post_id>/favorite', methods=['DELETE'])
+def unfavorite(post_id):
+ user_id = request.get_json(silent=True) and request.get_json().get('user_id')
+ if not user_id:
+ abort(400, 'user_id required')
+ # 查找已有的 favorite 行为
+ beh = Behavior.query.filter_by(
+ user_id=user_id,
+ post_id=post_id,
+ type='favorite'
+ ).first()
+ if not beh:
+ return jsonify({'error': 'not favorited yet'}), 400
+
+ db.session.delete(beh)
+ # 更新热度
+ post = Post.query.get_or_404(post_id)
+ post.heat = max(post.heat - 1, 0)
+ db.session.commit()
+ return '', 204
\ No newline at end of file
diff --git a/Merge/back_wzy/utils/auth.py b/Merge/back_wzy/utils/auth.py
new file mode 100644
index 0000000..24704d1
--- /dev/null
+++ b/Merge/back_wzy/utils/auth.py
@@ -0,0 +1,38 @@
+# utils/auth.py
+import os
+import jwt
+from functools import wraps
+from flask import request, jsonify, current_app
+from models.user import User
+from app import db
+
+def generate_token(user_id):
+ payload = {
+ 'user_id': user_id,
+ # you can add exp, iat here
+ }
+ token = jwt.encode(payload, current_app.config['SECRET_KEY'], algorithm='HS256')
+ return token
+
+def verify_token(token):
+ try:
+ payload = jwt.decode(token, current_app.config['SECRET_KEY'], algorithms=['HS256'])
+ user = User.query.get(payload['user_id'])
+ return user
+ except Exception:
+ return None
+
+def login_required(f):
+ @wraps(f)
+ def decorated(*args, **kwargs):
+ auth_header = request.headers.get('Authorization', None)
+ if not auth_header or not auth_header.startswith('Bearer '):
+ return jsonify({'error': 'Authorization header missing or invalid'}), 401
+ token = auth_header.split()[1]
+ user = verify_token(token)
+ if not user or user.status != 'active':
+ return jsonify({'error': 'Invalid or expired token'}), 401
+ # attach user to request context if needed
+ request.current_user = user
+ return f(*args, **kwargs)
+ return decorated
diff --git a/Merge/back_wzy/utils/serializers.py b/Merge/back_wzy/utils/serializers.py
new file mode 100644
index 0000000..1ed5445
--- /dev/null
+++ b/Merge/back_wzy/utils/serializers.py
@@ -0,0 +1,16 @@
+# utils/serializers.py
+from marshmallow import Schema, fields, validate, ValidationError
+
+class PostSchema(Schema):
+ user_id = fields.Int(required=True)
+ topic_id = fields.Int(required=False, allow_none=True)
+ type = fields.Str(validate=validate.OneOf(['text','image','video','document']), missing='text')
+ title = fields.Str(required=True, validate=validate.Length(min=1, max=255))
+ content = fields.Str(required=True)
+ media_urls = fields.List(fields.Url(), required=False)
+ status = fields.Str(validate=validate.OneOf(['draft','pending','published','deleted','rejected']), missing='draft')
+
+class CommentSchema(Schema):
+ user_id = fields.Int(required=True)
+ content = fields.Str(required=True, validate=validate.Length(min=1))
+ parent_id = fields.Int(required=False, allow_none=True)
diff --git a/Merge/front/.gitignore b/Merge/front/.gitignore
new file mode 100644
index 0000000..4d29575
--- /dev/null
+++ b/Merge/front/.gitignore
@@ -0,0 +1,23 @@
+# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
+
+# dependencies
+/node_modules
+/.pnp
+.pnp.js
+
+# testing
+/coverage
+
+# production
+/build
+
+# misc
+.DS_Store
+.env.local
+.env.development.local
+.env.test.local
+.env.production.local
+
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
diff --git a/Merge/front/README.md b/Merge/front/README.md
new file mode 100644
index 0000000..58beeac
--- /dev/null
+++ b/Merge/front/README.md
@@ -0,0 +1,70 @@
+# Getting Started with Create React App
+
+This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
+
+## Available Scripts
+
+In the project directory, you can run:
+
+### `npm start`
+
+Runs the app in the development mode.\
+Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
+
+The page will reload when you make changes.\
+You may also see any lint errors in the console.
+
+### `npm test`
+
+Launches the test runner in the interactive watch mode.\
+See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
+
+### `npm run build`
+
+Builds the app for production to the `build` folder.\
+It correctly bundles React in production mode and optimizes the build for the best performance.
+
+The build is minified and the filenames include the hashes.\
+Your app is ready to be deployed!
+
+See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
+
+### `npm run eject`
+
+**Note: this is a one-way operation. Once you `eject`, you can't go back!**
+
+If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
+
+Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
+
+You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
+
+## Learn More
+
+You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
+
+To learn React, check out the [React documentation](https://reactjs.org/).
+
+### Code Splitting
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
+
+### Analyzing the Bundle Size
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
+
+### Making a Progressive Web App
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
+
+### Advanced Configuration
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
+
+### Deployment
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
+
+### `npm run build` fails to minify
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
diff --git a/Merge/front/package.json b/Merge/front/package.json
new file mode 100644
index 0000000..f394aac
--- /dev/null
+++ b/Merge/front/package.json
@@ -0,0 +1,42 @@
+{
+ "name": "front",
+ "version": "0.1.0",
+ "private": true,
+ "dependencies": {
+ "@testing-library/dom": "^10.4.0",
+ "@testing-library/jest-dom": "^6.6.3",
+ "@testing-library/react": "^16.3.0",
+ "@testing-library/user-event": "^13.5.0",
+ "react": "^19.1.0",
+ "react-dom": "^19.1.0",
+ "react-router-dom": "^6.14.1",
+ "react-scripts": "^5.0.1",
+ "web-vitals": "^2.1.4",
+ "lucide-react": "^0.468.0",
+ "antd": "^4.24.0"
+ },
+ "scripts": {
+ "start": "react-scripts start",
+ "build": "react-scripts build",
+ "test": "react-scripts test",
+ "eject": "react-scripts eject"
+ },
+ "eslintConfig": {
+ "extends": [
+ "react-app",
+ "react-app/jest"
+ ]
+ },
+ "browserslist": {
+ "production": [
+ ">0.2%",
+ "not dead",
+ "not op_mini all"
+ ],
+ "development": [
+ "last 1 chrome version",
+ "last 1 firefox version",
+ "last 1 safari version"
+ ]
+ }
+}
diff --git a/Merge/front/public/favicon.ico b/Merge/front/public/favicon.ico
new file mode 100644
index 0000000..a11777c
--- /dev/null
+++ b/Merge/front/public/favicon.ico
Binary files differ
diff --git a/Merge/front/public/index.html b/Merge/front/public/index.html
new file mode 100644
index 0000000..aa069f2
--- /dev/null
+++ b/Merge/front/public/index.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta name="theme-color" content="#000000" />
+ <meta
+ name="description"
+ content="Web site created using create-react-app"
+ />
+ <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
+ <!--
+ manifest.json provides metadata used when your web app is installed on a
+ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
+ -->
+ <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
+ <!--
+ Notice the use of %PUBLIC_URL% in the tags above.
+ It will be replaced with the URL of the `public` folder during the build.
+ Only files inside the `public` folder can be referenced from the HTML.
+
+ Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
+ work correctly both with client-side routing and a non-root public URL.
+ Learn how to configure a non-root public URL by running `npm run build`.
+ -->
+ <title>React App</title>
+ </head>
+ <body>
+ <noscript>You need to enable JavaScript to run this app.</noscript>
+ <div id="root"></div>
+ <!--
+ This HTML file is a template.
+ If you open it directly in the browser, you will see an empty page.
+
+ You can add webfonts, meta tags, or analytics to this file.
+ The build step will place the bundled scripts into the <body> tag.
+
+ To begin the development, run `npm start` or `yarn start`.
+ To create a production bundle, use `npm run build` or `yarn build`.
+ -->
+ </body>
+</html>
diff --git a/Merge/front/public/logo192.png b/Merge/front/public/logo192.png
new file mode 100644
index 0000000..fc44b0a
--- /dev/null
+++ b/Merge/front/public/logo192.png
Binary files differ
diff --git a/Merge/front/public/logo512.png b/Merge/front/public/logo512.png
new file mode 100644
index 0000000..a4e47a6
--- /dev/null
+++ b/Merge/front/public/logo512.png
Binary files differ
diff --git a/Merge/front/public/manifest.json b/Merge/front/public/manifest.json
new file mode 100644
index 0000000..080d6c7
--- /dev/null
+++ b/Merge/front/public/manifest.json
@@ -0,0 +1,25 @@
+{
+ "short_name": "React App",
+ "name": "Create React App Sample",
+ "icons": [
+ {
+ "src": "favicon.ico",
+ "sizes": "64x64 32x32 24x24 16x16",
+ "type": "image/x-icon"
+ },
+ {
+ "src": "logo192.png",
+ "type": "image/png",
+ "sizes": "192x192"
+ },
+ {
+ "src": "logo512.png",
+ "type": "image/png",
+ "sizes": "512x512"
+ }
+ ],
+ "start_url": ".",
+ "display": "standalone",
+ "theme_color": "#000000",
+ "background_color": "#ffffff"
+}
diff --git a/Merge/front/public/robots.txt b/Merge/front/public/robots.txt
new file mode 100644
index 0000000..e9e57dc
--- /dev/null
+++ b/Merge/front/public/robots.txt
@@ -0,0 +1,3 @@
+# https://www.robotstxt.org/robotstxt.html
+User-agent: *
+Disallow:
diff --git a/Merge/front/public/vite.svg b/Merge/front/public/vite.svg
new file mode 100644
index 0000000..ee9fada
--- /dev/null
+++ b/Merge/front/public/vite.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
diff --git a/Merge/front/src/App.css b/Merge/front/src/App.css
new file mode 100644
index 0000000..8fdd8d7
--- /dev/null
+++ b/Merge/front/src/App.css
@@ -0,0 +1,585 @@
+.app {
+ display: flex;
+ min-height: 100vh;
+ background-color: #f5f7fa;
+}
+
+/* Header */
+.header {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ height: 60px;
+ background: #fff;
+ border-bottom: 1px solid #e8eaed;
+ display: flex;
+ align-items: center;
+ padding: 0 20px;
+ z-index: 1000;
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
+}
+
+.header-left {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+}
+
+.logo {
+ background: #ff4757;
+ color: white;
+ padding: 6px 12px;
+ border-radius: 6px;
+ font-size: 14px;
+ font-weight: bold;
+}
+
+.header-title {
+ font-size: 18px;
+ font-weight: 500;
+ color: #333;
+}
+
+.header-right {
+ margin-left: auto;
+ display: flex;
+ align-items: center;
+ gap: 12px;
+}
+
+.user-info {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ color: #666;
+ font-size: 14px;
+}
+
+/* Sidebar */
+.sidebar {
+ position: fixed;
+ left: 0;
+ top: 60px;
+ width: 200px;
+ height: calc(100vh - 60px);
+ background: #fff;
+ border-right: 1px solid #e8eaed;
+ overflow-y: auto;
+ z-index: 999;
+}
+
+.publish-btn {
+ margin: 16px;
+ background: #ff4757;
+ color: white;
+ padding: 10px 16px;
+ border-radius: 6px;
+ font-size: 14px;
+ font-weight: 500;
+ text-align: center;
+ transition: background 0.2s;
+}
+
+.publish-btn:hover {
+ background: #ff3742;
+}
+
+.nav-menu {
+ padding: 0;
+ list-style: none;
+}
+
+.nav-item {
+ border-bottom: 1px solid #f0f0f0;
+}
+
+.nav-link {
+ display: flex;
+ align-items: center;
+ padding: 12px 20px;
+ color: #333;
+ font-size: 14px;
+ transition: all 0.2s;
+ gap: 8px;
+}
+
+.nav-link:hover {
+ background: #f8f9fa;
+ color: #ff4757;
+}
+
+.nav-link.active {
+ background: linear-gradient(135deg, #ff4757, #ff6b7a);
+ color: white;
+ font-weight: 500;
+}
+
+.nav-link.active .lucide {
+ color: white;
+}
+
+.nav-submenu {
+ padding-left: 20px;
+ background: #fafafa;
+}
+
+.nav-submenu .nav-link {
+ padding: 8px 20px;
+ font-size: 13px;
+ color: #666;
+}
+
+.nav-submenu .nav-link:hover {
+ color: #ff4757;
+}
+
+/* Main Content */
+.main-content {
+ margin-left: 200px;
+ padding-top: 60px;
+ flex: 1;
+ min-height: 100vh;
+}
+
+.content-wrapper {
+ padding: 20px;
+ /* 原来是 max-width:1200px; */
+ max-width: none; /* 或者直接注释掉这一行 */
+ width: auto; /* 确保它能撑满父级 */
+ margin: 0; /* 取消水平 auto 居中 */
+}
+
+/* Upload Area */
+.upload-tabs {
+ display: flex;
+ gap: 20px;
+ margin-bottom: 30px;
+ border-bottom: 1px solid #e8eaed;
+}
+
+.upload-tab {
+ padding: 12px 0;
+ font-size: 16px;
+ color: #666;
+ cursor: pointer;
+ border-bottom: 2px solid transparent;
+ transition: all 0.2s;
+}
+
+.upload-tab.active {
+ color: #ff4757;
+ border-bottom-color: #ff4757;
+ font-weight: 500;
+}
+
+.upload-area {
+ background: #fff;
+ border-radius: 8px;
+ padding: 80px 40px;
+ text-align: center;
+ border: 2px dashed #ddd;
+ margin-bottom: 40px;
+ transition: all 0.2s;
+ min-height: 300px;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ position: relative;
+}
+
+.upload-area:hover {
+ border-color: #ff4757;
+ background: #fff8f8;
+}
+
+.upload-area.drag-over {
+ border-color: #ff4757;
+ background: #fff0f0;
+ transform: scale(1.02);
+}
+
+.upload-icon {
+ width: 100px;
+ height: 100px;
+ margin: 0 auto 30px;
+ background: #f8f9fa;
+ border-radius: 50%;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 40px;
+ color: #ccc;
+ transition: all 0.3s ease;
+}
+
+.upload-area:hover .upload-icon {
+ background: #ff475710;
+ color: #ff4757;
+ transform: scale(1.1);
+}
+
+.upload-area.drag-over .upload-icon {
+ background: #ff475720;
+ color: #ff4757;
+ transform: scale(1.2);
+}
+
+.upload-title {
+ font-size: 20px;
+ color: #333;
+ margin-bottom: 12px;
+ font-weight: 500;
+}
+
+.upload-subtitle {
+ font-size: 14px;
+ color: #999;
+ margin-bottom: 30px;
+}
+
+.upload-btn {
+ background: #ff4757;
+ color: white;
+ padding: 14px 28px;
+ border-radius: 6px;
+ font-size: 16px;
+ font-weight: 500;
+ transition: background 0.2s;
+ min-width: 120px;
+}
+
+.upload-btn:hover:not(:disabled) {
+ background: #ff3742;
+}
+
+.upload-btn:disabled {
+ background: #ccc;
+ cursor: not-allowed;
+}
+
+.upload-btn.uploading {
+ background: #ff4757;
+ opacity: 0.8;
+}
+
+/* File Preview */
+.file-preview-area {
+ background: #fff;
+ border-radius: 8px;
+ padding: 20px;
+ margin-bottom: 40px;
+ border: 1px solid #e8eaed;
+}
+
+/* Preview Header */
+.preview-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 16px;
+}
+
+.preview-title {
+ font-size: 16px;
+ color: #333;
+ margin-bottom: 16px;
+ font-weight: 500;
+}
+
+.clear-files-btn {
+ background: #ff4757;
+ color: white;
+ padding: 6px 12px;
+ border-radius: 4px;
+ font-size: 12px;
+ transition: background 0.2s;
+}
+
+.clear-files-btn:hover {
+ background: #ff3742;
+}
+
+.file-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
+ gap: 16px;
+}
+
+.file-item {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding: 12px;
+ border: 1px solid #f0f0f0;
+ border-radius: 6px;
+ transition: all 0.2s ease;
+ position: relative;
+}
+
+.file-item:hover {
+ border-color: #ff4757;
+ box-shadow: 0 2px 8px rgba(255, 71, 87, 0.1);
+}
+
+.file-item:hover .remove-file-btn {
+ opacity: 1;
+}
+
+.remove-file-btn {
+ position: absolute;
+ top: 4px;
+ right: 4px;
+ background: rgba(255, 71, 87, 0.8);
+ color: white;
+ border-radius: 50%;
+ width: 20px;
+ height: 20px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 14px;
+ font-weight: bold;
+ opacity: 0;
+ transition: all 0.2s;
+}
+
+.file-thumbnail {
+ width: 80px;
+ height: 80px;
+ border-radius: 6px;
+ overflow: hidden;
+ margin-bottom: 8px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background: #f8f9fa;
+}
+
+.file-thumbnail img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+}
+
+.video-thumbnail {
+ color: #666;
+}
+
+.file-info {
+ text-align: center;
+ width: 100%;
+}
+
+.file-name {
+ font-size: 12px;
+ color: #333;
+ margin-bottom: 4px;
+ font-weight: 500;
+}
+
+.file-size {
+ font-size: 11px;
+ color: #999;
+}
+
+/* Upload Progress */
+.progress-container {
+ margin-top: 20px;
+ width: 100%;
+ max-width: 400px;
+}
+
+.progress-bar {
+ width: 100%;
+ height: 8px;
+ background-color: #f0f0f0;
+ border-radius: 4px;
+ overflow: hidden;
+ margin-bottom: 8px;
+}
+
+.progress-fill {
+ height: 100%;
+ background: linear-gradient(90deg, #ff4757, #ff6b7a);
+ border-radius: 4px;
+ transition: width 0.3s ease;
+ position: relative;
+}
+
+.progress-fill::after {
+ content: '';
+ position: absolute;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
+ animation: shimmer 1.5s infinite;
+}
+
+@keyframes shimmer {
+ 0% { transform: translateX(-100%); }
+ 100% { transform: translateX(100%); }
+}
+
+.progress-text {
+ text-align: center;
+ font-size: 12px;
+ color: #666;
+ font-weight: 500;
+}
+
+/* Upload Info */
+.upload-info {
+ display: flex;
+ gap: 60px;
+ justify-content: center;
+ margin-top: 40px;
+ padding: 20px;
+ opacity: 1;
+ transition: opacity 0.3s ease;
+}
+
+.upload-info.fade-in {
+ animation: fadeIn 0.3s ease-in-out;
+}
+
+@keyframes fadeIn {
+ from {
+ opacity: 0;
+ transform: translateY(10px);
+ }
+ to {
+ opacity: 1;
+ transform: translateY(0);
+ }
+}
+
+.info-item {
+ text-align: center;
+ flex: 1;
+ max-width: 300px;
+}
+
+.info-title {
+ font-size: 16px;
+ color: #333;
+ margin-bottom: 12px;
+ font-weight: 500;
+}
+
+.info-desc {
+ font-size: 13px;
+ color: #666;
+ line-height: 1.6;
+}
+
+/* Page Content Styles */
+.page-content {
+ padding: 40px;
+ background: white;
+ border-radius: 12px;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
+ margin: 20px 0;
+ min-height: 500px;
+}
+
+.page-header {
+ margin-bottom: 40px;
+ padding-bottom: 20px;
+ border-bottom: 1px solid #e8eaed;
+}
+
+.page-title {
+ font-size: 24px;
+ font-weight: 600;
+ color: #333;
+ margin: 0;
+}
+
+.page-body {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ min-height: 400px;
+}
+
+.placeholder-content {
+ text-align: center;
+ max-width: 400px;
+}
+
+.placeholder-icon {
+ color: #ff4757;
+ margin-bottom: 20px;
+ display: flex;
+ justify-content: center;
+}
+
+.placeholder-title {
+ font-size: 20px;
+ font-weight: 500;
+ color: #333;
+ margin: 0 0 15px 0;
+}
+
+.placeholder-desc {
+ font-size: 14px;
+ color: #666;
+ line-height: 1.6;
+ margin: 0;
+}
+
+/* Responsive */
+@media (max-width: 768px) {
+ .sidebar {
+ transform: translateX(-100%);
+ transition: transform 0.3s;
+ }
+
+ .main-content {
+ margin-left: 0;
+ }
+
+ .header-title {
+ display: none;
+ }
+
+ .upload-area {
+ padding: 60px 20px;
+ margin: 0 10px 30px;
+ }
+
+ .upload-info {
+ flex-direction: column;
+ gap: 30px;
+ padding: 10px;
+ }
+
+ .content-wrapper {
+ padding: 15px;
+ }
+
+ .upload-tabs {
+ gap: 15px;
+ }
+
+ .page-content {
+ padding: 20px;
+ margin: 10px;
+ }
+
+ .page-title {
+ font-size: 20px;
+ }
+
+ .placeholder-title {
+ font-size: 18px;
+ }
+
+ .placeholder-desc {
+ font-size: 13px;
+ }
+}
diff --git a/Merge/front/src/App.jsx b/Merge/front/src/App.jsx
new file mode 100644
index 0000000..770bc0a
--- /dev/null
+++ b/Merge/front/src/App.jsx
@@ -0,0 +1,22 @@
+import React from 'react'
+import { BrowserRouter as Router } from 'react-router-dom'
+import Header from './components/Header'
+import Sidebar from './components/Sidebar'
+import AppRoutes from './router/App'
+import './App.css'
+
+export default function App() {
+ return (
+ <Router>
+ <div className="app">
+ <Header />
+ <Sidebar />
+ <main className="main-content">
+ <div className="content-wrapper">
+ <AppRoutes />
+ </div>
+ </main>
+ </div>
+ </Router>
+ )
+}
diff --git a/Merge/front/src/App.test.js b/Merge/front/src/App.test.js
new file mode 100644
index 0000000..1f03afe
--- /dev/null
+++ b/Merge/front/src/App.test.js
@@ -0,0 +1,8 @@
+import { render, screen } from '@testing-library/react';
+import App from './App';
+
+test('renders learn react link', () => {
+ render(<App />);
+ const linkElement = screen.getByText(/learn react/i);
+ expect(linkElement).toBeInTheDocument();
+});
diff --git a/Merge/front/src/api/posts.js b/Merge/front/src/api/posts.js
new file mode 100644
index 0000000..37acf43
--- /dev/null
+++ b/Merge/front/src/api/posts.js
@@ -0,0 +1,131 @@
+const BASE = 'http://10.126.59.25:5713' // 后端地址
+
+/**
+ * 获取待审核的帖子列表
+ * POST /apostlist
+ * @param {number|string} userId 平台管理员的用户 ID
+ * @returns Promise<[ {id, title, status}, … ]>
+ */
+export async function fetchPosts(userId) {
+ const res = await fetch(`${BASE}/apostlist`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ userid: userId })
+ })
+ if (!res.ok) throw new Error(`fetchPosts: ${res.status}`)
+
+ const json = await res.json()
+ console.log('fetchPosts response:', json) // debug: inspect shape
+
+ // handle unauthorized
+ if (json.status === 'error' && json.message === 'Unauthorized') {
+ throw new Error('Unauthorized')
+ }
+
+ // normalize response into an array
+ let list
+ if (Array.isArray(json)) {
+ list = json
+ } else if (Array.isArray(json.data)) {
+ list = json.data
+ } else if (Array.isArray(json.posts)) {
+ list = json.posts
+ } else if (Array.isArray(json.data?.posts)) {
+ list = json.data.posts
+ } else {
+ list = []
+ }
+ console.log('Normalized post list:', list) // debug: check final shape
+ return list
+}
+
+/**
+ * 审核通过
+ * POST /areview
+ */
+export async function approvePost(postId, userId) {
+ const res = await fetch(`${BASE}/areview`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ userid: userId, postid: postId, status: 'published' })
+ })
+ if (!res.ok) throw new Error(`approvePost: ${res.status}`)
+ return res.json()
+}
+
+/**
+ * 驳回
+ * POST /areview
+ */
+export async function rejectPost(postId, userId) {
+ const res = await fetch(`${BASE}/areview`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ userid: userId, postid: postId, status: 'rejected' })
+ })
+ if (!res.ok) throw new Error(`rejectPost: ${res.status}`)
+ return res.json()
+}
+
+/**
+ * 获取单个帖子详情
+ * POST /agetpost
+ * @param {number|string} postId 帖子 ID
+ * @param {number|string} userId 平台管理员的用户 ID
+ * @returns Promise<{id, title, content, status}>
+ */
+export async function fetchPost(postId, userId) {
+ const res = await fetch(`${BASE}/agetpost`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ userid: userId, postid: postId })
+ })
+ if (!res.ok) throw new Error(`fetchPost: ${res.status}`)
+ return res.json()
+}
+
+/**
+ * 获取超级管理员用户列表
+ * POST /sgetuserlist
+ * @param {number|string} userId 平台管理员的用户 ID
+ * @returns Promise<[ {id, name, role}, … ]>
+ */
+export async function fetchUserList(userId) {
+ const res = await fetch(`${BASE}/sgetuserlist`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ userid: userId })
+ })
+ if (!res.ok) throw new Error(`fetchUserList: ${res.status}`)
+ return res.json()
+}
+
+export async function giveAdmin(userId, targetId) {
+ const res = await fetch(`${BASE}/sgiveadmin`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ userid: userId, targetid: targetId })
+ })
+ if (!res.ok) throw new Error(`giveAdmin: ${res.status}`)
+ return res.json()
+}
+
+export async function giveSuperAdmin(userId, targetId) {
+ const res = await fetch(`${BASE}/sgivesuperadmin`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ userid: userId, targetid: targetId })
+ })
+ if (!res.ok) throw new Error(`giveSuperAdmin: ${res.status}`)
+ return res.json()
+}
+
+export async function giveUser(userId, targetId) {
+ const res = await fetch(`${BASE}/sgiveuser`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ userid: userId, targetid: targetId })
+ })
+ if (!res.ok) throw new Error(`giveUser: ${res.status}`)
+ return res.json()
+}
\ No newline at end of file
diff --git a/Merge/front/src/api/posts_wzy.js b/Merge/front/src/api/posts_wzy.js
new file mode 100644
index 0000000..ae65756
--- /dev/null
+++ b/Merge/front/src/api/posts_wzy.js
@@ -0,0 +1,130 @@
+// src/api/posts.js
+const BASE = 'http://127.0.0.1:5714/' // 如果有代理可以留空,否则填完整域名,如 'http://localhost:3000'
+
+/**
+ * 获取所有已发布的帖子列表
+ * GET /posts
+ */
+export async function fetchPosts() {
+ const res = await fetch(`${BASE}/posts`)
+ if (!res.ok) throw new Error(`fetchPosts: ${res.status}`)
+ console.log('fetchPosts response:', res) // debug: inspect response
+ return res.json() // 返回 [ { id, title, heat, created_at }, … ]
+}
+
+/**
+ * 查看单个帖子详情
+ * GET /posts/{postId}
+ */
+export async function fetchPost(postId) {
+ const res = await fetch(`${BASE}/posts/${postId}`)
+ if (!res.ok) throw new Error(`fetchPost(${postId}): ${res.status}`)
+ return res.json() // 返回完整的帖子对象
+}
+
+/**
+ * 发布新帖
+ * POST /posts
+ */
+export async function createPost(payload) {
+ const res = await fetch(`${BASE}/posts`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(payload)
+ })
+ if (!res.ok) {
+ const err = await res.json().catch(() => null)
+ throw new Error(err?.error || `createPost: ${res.status}`)
+ }
+ return res.json() // { id }
+}
+
+/**
+ * 修改帖子
+ * PUT /posts/{postId}
+ */
+export async function updatePost(postId, payload) {
+ const res = await fetch(`${BASE}/posts/${postId}`, {
+ method: 'PUT',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(payload)
+ })
+ if (!res.ok) throw new Error(`updatePost(${postId}): ${res.status}`)
+ // 204 No Content
+}
+
+/**
+ * 删除帖子
+ * DELETE /posts/{postId}
+ */
+export async function deletePost(postId) {
+ const res = await fetch(`${BASE}/posts/${postId}`, {
+ method: 'DELETE'
+ })
+ if (!res.ok) throw new Error(`deletePost(${postId}): ${res.status}`)
+}
+
+/**
+ * 点赞
+ * POST /posts/{postId}/like
+ */
+export async function likePost(postId, userId) {
+ const res = await fetch(`${BASE}/posts/${postId}/like`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ user_id: userId })
+ })
+ if (!res.ok) {
+ const err = await res.json().catch(() => null)
+ throw new Error(err?.error || `likePost: ${res.status}`)
+ }
+}
+
+/**
+ * 取消点赞
+ * DELETE /posts/{postId}/like
+ */
+export async function unlikePost(postId, userId) {
+ const res = await fetch(`${BASE}/posts/${postId}/like`, {
+ method: 'DELETE',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ user_id: userId })
+ })
+ if (!res.ok) {
+ const err = await res.json().catch(() => null)
+ throw new Error(err?.error || `unlikePost: ${res.status}`)
+ }
+}
+
+/**
+ * 收藏、取消收藏、浏览、分享 等接口:
+ * POST /posts/{postId}/favorite
+ * DELETE /posts/{postId}/favorite
+ * POST /posts/{postId}/view
+ * POST /posts/{postId}/share
+ * 用法同上,替换路径即可
+ */
+
+/**
+ * 添加评论
+ * POST /posts/{postId}/comments
+ */
+export async function addComment(postId, payload) {
+ const res = await fetch(`${BASE}/posts/${postId}/comments`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(payload)
+ })
+ if (!res.ok) throw new Error(`addComment: ${res.status}`)
+ return res.json() // { id }
+}
+
+/**
+ * 获取评论列表
+ * GET /posts/{postId}/comments
+ */
+export async function fetchComments(postId) {
+ const res = await fetch(`${BASE}/posts/${postId}/comments`)
+ if (!res.ok) throw new Error(`fetchComments: ${res.status}`)
+ return res.json()
+}
diff --git a/Merge/front/src/components/Admin.js b/Merge/front/src/components/Admin.js
new file mode 100644
index 0000000..da11100
--- /dev/null
+++ b/Merge/front/src/components/Admin.js
@@ -0,0 +1,283 @@
+import 'antd/dist/antd.css';
+import React, { useState, useEffect, useMemo, useCallback } from 'react';
+import { Layout, Tabs, Input, List, Card, Button, Tag, Spin, Typography, Divider } from 'antd';
+import '../style/Admin.css';
+import { fetchPosts, approvePost, rejectPost } from '../api/posts';
+
+export default function Admin() {
+ const ADMIN_USER_ID = 2;
+ const [posts, setPosts] = useState([]);
+ const [loading, setLoading] = useState(true);
+ const [hasPermission, setHasPermission] = useState(true);
+ const [activeTab, setActiveTab] = useState('all');
+ const [selectedPost, setSelectedPost] = useState(null);
+ const [searchTerm, setSearchTerm] = useState('');
+
+ // 新增:拖拽相关状态
+ const [leftPanelWidth, setLeftPanelWidth] = useState(300);
+ const [isResizing, setIsResizing] = useState(false);
+
+ const statusColors = {
+ draft: 'orange',
+ pending: 'blue',
+ published: 'green',
+ deleted: 'gray',
+ rejected: 'red'
+ };
+
+ useEffect(() => {
+ async function load() {
+ try {
+ const list = await fetchPosts(ADMIN_USER_ID)
+ setPosts(list)
+ } catch (e) {
+ if (e.message === 'Unauthorized') {
+ setHasPermission(false)
+ } else {
+ console.error(e)
+ }
+ } finally {
+ setLoading(false)
+ }
+ }
+ load()
+ }, [])
+
+ // 过滤并排序
+ const sortedPosts = useMemo(() => {
+ return [...posts].sort((a, b) => {
+ if (a.status === 'pending' && b.status !== 'pending') return -1
+ if (b.status === 'pending' && a.status !== 'pending') return 1
+ return 0
+ })
+ }, [posts])
+
+ // 调整:根据 activeTab 及搜索关键词过滤
+ const filteredPosts = useMemo(() => {
+ let list
+ switch (activeTab) {
+ case 'pending':
+ list = sortedPosts.filter(p => p.status === 'pending'); break
+ case 'published':
+ list = sortedPosts.filter(p => p.status === 'published'); break
+ case 'rejected':
+ list = sortedPosts.filter(p => p.status === 'rejected'); break
+ default:
+ list = sortedPosts
+ }
+ return list.filter(p =>
+ p.title.toLowerCase().includes(searchTerm.toLowerCase())
+ )
+ }, [sortedPosts, activeTab, searchTerm])
+
+ const handleApprove = async id => {
+ await approvePost(id, ADMIN_USER_ID)
+ setPosts(ps => ps.map(x => x.id === id ? { ...x, status: 'published' } : x))
+ // 同步更新选中的帖子状态
+ if (selectedPost?.id === id) {
+ setSelectedPost(prev => ({ ...prev, status: 'published' }));
+ }
+ }
+ const handleReject = async id => {
+ await rejectPost(id, ADMIN_USER_ID)
+ setPosts(ps => ps.map(x => x.id === id ? { ...x, status: 'rejected' } : x))
+ // 同步更新选中的帖子状态
+ if (selectedPost?.id === id) {
+ setSelectedPost(prev => ({ ...prev, status: 'rejected' }));
+ }
+ }
+ const handleSelect = post => setSelectedPost(post)
+
+ // 修复:拖拽处理函数
+ const handleMouseMove = useCallback((e) => {
+ if (!isResizing) return;
+
+ const newWidth = e.clientX;
+ const minWidth = 200;
+ const maxWidth = window.innerWidth - 300;
+
+ if (newWidth >= minWidth && newWidth <= maxWidth) {
+ setLeftPanelWidth(newWidth);
+ }
+ }, [isResizing]);
+
+ const handleMouseUp = useCallback(() => {
+ setIsResizing(false);
+ document.removeEventListener('mousemove', handleMouseMove);
+ document.removeEventListener('mouseup', handleMouseUp);
+ document.body.style.cursor = '';
+ document.body.style.userSelect = '';
+ }, [handleMouseMove]);
+
+ const handleMouseDown = useCallback((e) => {
+ e.preventDefault();
+ setIsResizing(true);
+ document.addEventListener('mousemove', handleMouseMove);
+ document.addEventListener('mouseup', handleMouseUp);
+ document.body.style.cursor = 'col-resize';
+ document.body.style.userSelect = 'none';
+ }, [handleMouseMove, handleMouseUp]);
+
+ // 新增:组件卸载时清理事件监听器
+ useEffect(() => {
+ return () => {
+ document.removeEventListener('mousemove', handleMouseMove);
+ document.removeEventListener('mouseup', handleMouseUp);
+ document.body.style.cursor = '';
+ document.body.style.userSelect = '';
+ };
+ }, [handleMouseMove, handleMouseUp]);
+
+ if (loading) return <Spin spinning tip="加载中…" style={{ width: '100%', marginTop: 100 }} />;
+ if (!hasPermission) return <div style={{ textAlign: 'center', marginTop: 100 }}>权限不足</div>;
+
+ const { Content } = Layout;
+ const { TabPane } = Tabs;
+ const { Title, Text } = Typography;
+
+ return (
+ <div style={{ height: '100vh', display: 'flex' }}>
+ {/* 左侧面板 */}
+ <div
+ style={{
+ width: leftPanelWidth,
+ background: '#fff',
+ padding: 16,
+ borderRight: '1px solid #f0f0f0',
+ overflow: 'hidden'
+ }}
+ >
+ <div style={{ marginBottom: 24 }}>
+ <Title level={3}>小红书</Title>
+ <Input.Search
+ placeholder="搜索帖子标题..."
+ value={searchTerm}
+ onChange={e => setSearchTerm(e.target.value)}
+ enterButton
+ />
+ </div>
+ <Tabs activeKey={activeTab} onChange={key => { setActiveTab(key); setSelectedPost(null); }}>
+ <TabPane tab="全部" key="all" />
+ <TabPane tab="待审核" key="pending" />
+ <TabPane tab="已通过" key="published" />
+ <TabPane tab="已驳回" key="rejected" />
+ </Tabs>
+ <div style={{ height: 'calc(100vh - 200px)', overflow: 'auto' }}>
+ <List
+ dataSource={filteredPosts}
+ pagination={{
+ pageSize: 5,
+ showSizeChanger: true,
+ pageSizeOptions: ['5','10','20'],
+ onChange: () => setSelectedPost(null)
+ }}
+ renderItem={p => (
+ <List.Item
+ key={p.id}
+ style={{
+ background: selectedPost?.id === p.id ? '#e6f7ff' : '',
+ cursor: 'pointer',
+ marginBottom: 8
+ }}
+ onClick={() => handleSelect(p)}
+ >
+ <List.Item.Meta
+ avatar={
+ p.thumbnail && (
+ <img
+ src={p.thumbnail}
+ alt=""
+ style={{ width: 64, height: 64, objectFit: 'cover' }}
+ />
+ )
+ }
+ title={p.title}
+ description={`${p.createdAt} · ${p.author} · ${p.likes || 0}赞`}
+ />
+ <Tag color={statusColors[p.status]}>{p.status}</Tag>
+ </List.Item>
+ )}
+ />
+ </div>
+ </div>
+
+ {/* 拖拽分割条 */}
+ <div
+ style={{
+ width: 5,
+ cursor: 'col-resize',
+ background: isResizing ? '#1890ff' : '#f0f0f0',
+ transition: isResizing ? 'none' : 'background-color 0.2s',
+ position: 'relative',
+ flexShrink: 0
+ }}
+ onMouseDown={handleMouseDown}
+ onSelectStart={(e) => e.preventDefault()}
+ >
+ <div
+ style={{
+ position: 'absolute',
+ top: '50%',
+ left: '50%',
+ transform: 'translate(-50%, -50%)',
+ width: 2,
+ height: 20,
+ background: '#999',
+ borderRadius: 1
+ }}
+ />
+ </div>
+
+ {/* 右侧内容区域 */}
+ <div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
+ <Content style={{ padding: 24, background: '#fff', overflow: 'auto' }}>
+ {selectedPost ? (
+ <Card
+ cover={selectedPost.image && <img alt="cover" src={selectedPost.image} />}
+ title={selectedPost.title}
+ extra={
+ <div>
+ {selectedPost.status === 'pending' && (
+ <>
+ <Button type="primary" onClick={() => handleApprove(selectedPost.id)}>通过</Button>
+ <Button danger onClick={() => handleReject(selectedPost.id)}>驳回</Button>
+ </>
+ )}
+ {selectedPost.status === 'published' && (
+ <Button danger onClick={() => handleReject(selectedPost.id)}>驳回</Button>
+ )}
+ {selectedPost.status === 'rejected' && (
+ <>
+ <Button onClick={() => {
+ setPosts(ps => ps.map(x => x.id === selectedPost.id ? { ...x, status: 'pending' } : x));
+ setSelectedPost(prev => ({ ...prev, status: 'pending' }));
+ }}>恢复待审</Button>
+ <Button onClick={() => {
+ setPosts(ps => ps.map(x => x.id === selectedPost.id ? { ...x, status: 'published' } : x));
+ setSelectedPost(prev => ({ ...prev, status: 'published' }));
+ }}>恢复已发</Button>
+ </>
+ )}
+ </div>
+ }
+ >
+ <Text type="secondary">
+ {`${selectedPost.createdAt} · ${selectedPost.author} · ${selectedPost.likes || 0}赞`}
+ </Text>
+ <Divider />
+ <p>{selectedPost.content}</p>
+ <Divider />
+ <Title level={4}>合规性指引</Title>
+ <ul>
+ <li>不含违法违规内容</li>
+ <li>不侵害他人合法权益</li>
+ </ul>
+ </Card>
+ ) : (
+ <Text type="secondary">请选择左侧列表中的帖子查看详情</Text>
+ )}
+ </Content>
+ </div>
+ </div>
+ );
+}
diff --git a/Merge/front/src/components/CreatePost.jsx b/Merge/front/src/components/CreatePost.jsx
new file mode 100644
index 0000000..7519d5b
--- /dev/null
+++ b/Merge/front/src/components/CreatePost.jsx
@@ -0,0 +1,168 @@
+// src/components/CreatePost.jsx
+
+import React, { useState } from 'react'
+import { useNavigate } from 'react-router-dom'
+import UploadPage from './UploadPage'
+import { createPost } from '../api/posts_wzy'
+import '../style/CreatePost.css'
+
+export default function CreatePost() {
+ const navigate = useNavigate()
+
+ const [step, setStep] = useState('upload') // 'upload' | 'detail'
+ const [files, setFiles] = useState([]) // 本地 File 对象列表
+ const [mediaUrls, setMediaUrls] = useState([]) // 上传后得到的 URL 列表
+
+ // 详情表单字段
+ const [title, setTitle] = useState('')
+ const [content, setContent] = useState('')
+ const [topicId, setTopicId] = useState('')
+ const [status, setStatus] = useState('published')
+
+ const [error, setError] = useState(null)
+
+ // 静态话题数据
+ const TOPICS = [
+ { id: 1, name: '世俱杯环球评大会' },
+ { id: 2, name: '我的REDmentor' },
+ { id: 3, name: '我染上了拼豆' },
+ // …更多静态话题…
+ ]
+
+ // 上传页面回调 —— 上传完成后切换到“填写详情”步骤
+ const handleUploadComplete = async uploadedFiles => {
+ setFiles(uploadedFiles)
+
+ // TODO: 改成真实上传逻辑,拿到真正的 media_urls
+ const urls = await Promise.all(
+ uploadedFiles.map(f => URL.createObjectURL(f))
+ )
+ setMediaUrls(urls)
+
+ setStep('detail')
+ }
+
+ // 发布按钮
+ const handleSubmit = async () => {
+ if (!title.trim() || !content.trim()) {
+ setError('标题和正文必填')
+ return
+ }
+ setError(null)
+ try {
+ await createPost({
+ user_id: 1,
+ topic_id: topicId || undefined,
+ title: title.trim(),
+ content: content.trim(),
+ media_urls: mediaUrls,
+ status
+ })
+ // 发布成功后跳转回首页
+ navigate('/home', { replace: true })
+ } catch (e) {
+ setError(e.message)
+ }
+ }
+
+ // 渲染上传页
+ if (step === 'upload') {
+ return <UploadPage onComplete={handleUploadComplete} />
+ }
+
+ // 渲染详情页
+ return (
+ <div className="create-post">
+ <h2>填写帖子内容</h2>
+ {error && <div className="error">{error}</div>}
+
+ {/* 已上传媒体预览 */}
+ <div className="preview-media">
+ {mediaUrls.map((url, i) => (
+ <div key={i} className="preview-item">
+ {files[i].type.startsWith('image/') ? (
+ <img src={url} alt={`预览 ${i}`} />
+ ) : (
+ <video src={url} controls />
+ )}
+ </div>
+ ))}
+ </div>
+
+ {/* 标题 */}
+ <label className="form-label">
+ 标题(最多20字)
+ <input
+ type="text"
+ maxLength={20}
+ value={title}
+ onChange={e => setTitle(e.target.value)}
+ placeholder="填写标题会有更多赞哦~"
+ />
+ <span className="char-count">{title.length}/20</span>
+ </label>
+
+ {/* 正文 */}
+ <label className="form-label">
+ 正文(最多1000字)
+ <textarea
+ maxLength={1000}
+ value={content}
+ onChange={e => setContent(e.target.value)}
+ placeholder="输入正文描述,真诚有价值的分享予人温暖"
+ />
+ <span className="char-count">{content.length}/1000</span>
+ </label>
+
+ {/* 话题选择 */}
+ <label className="form-label">
+ 选择话题(可选)
+ <select
+ value={topicId}
+ onChange={e => setTopicId(e.target.value)}
+ >
+ <option value="">不添加话题</option>
+ {TOPICS.map(t => (
+ <option key={t.id} value={t.id}>
+ #{t.name}
+ </option>
+ ))}
+ </select>
+ </label>
+
+ {/* 发布状态 */}
+ <div className="status-group">
+ <label>
+ <input
+ type="radio"
+ name="status"
+ value="published"
+ checked={status === 'published'}
+ onChange={() => setStatus('published')}
+ />
+ 立即发布
+ </label>
+ <label>
+ <input
+ type="radio"
+ name="status"
+ value="draft"
+ checked={status === 'draft'}
+ onChange={() => setStatus('draft')}
+ />
+ 存为草稿
+ </label>
+ </div>
+
+ {/* 操作按钮 */}
+ <div className="btn-group">
+ <button className="btn btn-primary" onClick={handleSubmit}>
+ 发布
+ </button>
+ <button className="btn btn-secondary" onClick={() => setStep('upload')}>
+ 上一步
+ </button>
+ </div>
+ </div>
+ )
+}
diff --git a/Merge/front/src/components/Header.jsx b/Merge/front/src/components/Header.jsx
new file mode 100644
index 0000000..60a50b7
--- /dev/null
+++ b/Merge/front/src/components/Header.jsx
@@ -0,0 +1,20 @@
+import React from 'react'
+import { User } from 'lucide-react'
+import '../App.css' // 或者单独的 Header.css
+
+export default function Header() {
+ return (
+ <header className="header">
+ <div className="header-left">
+ <div className="logo">小红书</div>
+ <h1 className="header-title">创作服务平台</h1>
+ </div>
+ <div className="header-right">
+ <div className="user-info">
+ <User size={16} />
+ <span>小红薯63081EA1</span>
+ </div>
+ </div>
+ </header>
+ )
+}
\ No newline at end of file
diff --git a/Merge/front/src/components/HomeFeed.jsx b/Merge/front/src/components/HomeFeed.jsx
new file mode 100644
index 0000000..39e0ca8
--- /dev/null
+++ b/Merge/front/src/components/HomeFeed.jsx
@@ -0,0 +1,90 @@
+// src/components/HomeFeed.jsx
+
+import React, { useState, useEffect } from 'react'
+import { ThumbsUp } from 'lucide-react'
+import { fetchPosts, fetchPost } from '../api/posts_wzy'
+import '../style/HomeFeed.css'
+
+const categories = [
+ '推荐','穿搭','美食','彩妆','影视',
+ '职场','情感','家居','游戏','旅行','健身'
+]
+
+export default function HomeFeed() {
+ const [activeCat, setActiveCat] = useState('推荐')
+ const [items, setItems] = useState([])
+ const [loading, setLoading] = useState(true)
+ const [error, setError] = useState(null)
+
+ useEffect(() => {
+ async function loadPosts() {
+ try {
+ const list = await fetchPosts() // [{id, title, heat, created_at}, …]
+ // 为了拿到 media_urls 和 user_id,这里再拉详情
+ const detailed = await Promise.all(
+ list.map(async p => {
+ const d = await fetchPost(p.id)
+ return {
+ id: d.id,
+ title: d.title,
+ author: `作者 ${d.user_id}`,
+ avatar: `https://i.pravatar.cc/40?img=${d.user_id}`,
+ img: d.media_urls?.[0] || '', // 用第一张媒体作为封面
+ likes: d.heat
+ }
+ })
+ )
+ setItems(detailed)
+ } catch (e) {
+ setError(e.message)
+ } finally {
+ setLoading(false)
+ }
+ }
+ loadPosts()
+ }, [])
+
+ return (
+ <div className="home-feed">
+ {/* 顶部分类 */}
+ <nav className="feed-tabs">
+ {categories.map(cat => (
+ <button
+ key={cat}
+ className={cat === activeCat ? 'tab active' : 'tab'}
+ onClick={() => setActiveCat(cat)}
+ >
+ {cat}
+ </button>
+ ))}
+ </nav>
+
+ {/* 状态提示 */}
+ {loading ? (
+ <div className="loading">加载中…</div>
+ ) : error ? (
+ <div className="error">加载失败:{error}</div>
+ ) : (
+ /* 瀑布流卡片区 */
+ <div className="feed-grid">
+ {items.map(item => (
+ <div key={item.id} className="feed-card">
+ <img className="card-img" src={item.img} alt={item.title} />
+ <h3 className="card-title">{item.title}</h3>
+ <div className="card-footer">
+ <div className="card-author">
+ <img className="avatar" src={item.avatar} alt={item.author} />
+ <span className="username">{item.author}</span>
+ </div>
+ <div className="card-likes">
+ <ThumbsUp size={16} />
+ <span className="likes-count">{item.likes}</span>
+ </div>
+ </div>
+ </div>
+ ))}
+ </div>
+ )}
+ </div>
+ )
+}
diff --git a/Merge/front/src/components/LogsDashboard.js b/Merge/front/src/components/LogsDashboard.js
new file mode 100644
index 0000000..1bd6cb7
--- /dev/null
+++ b/Merge/front/src/components/LogsDashboard.js
@@ -0,0 +1,45 @@
+import React, { useEffect, useState } from 'react';
+import '../style/Admin.css';
+
+function LogsDashboard() {
+ const [logs, setLogs] = useState([]);
+ const [stats, setStats] = useState({});
+
+ useEffect(() => {
+ fetch('/api/logs')
+ .then(res => res.json())
+ .then(setLogs)
+ .catch(console.error);
+ fetch('/api/stats')
+ .then(res => res.json())
+ .then(setStats)
+ .catch(console.error);
+ }, []);
+
+ return (
+ <div className="admin-container">
+ <h2>运行日志 & 性能 Dashboard</h2>
+ <section className="dashboard-stats">
+ <pre>{JSON.stringify(stats, null, 2)}</pre>
+ </section>
+ <section className="dashboard-logs">
+ <table className="admin-table">
+ <thead>
+ <tr><th>时间</th><th>级别</th><th>消息</th></tr>
+ </thead>
+ <tbody>
+ {logs.map((log, i) => (
+ <tr key={i}>
+ <td>{new Date(log.time).toLocaleString()}</td>
+ <td>{log.level}</td>
+ <td>{log.message}</td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ </section>
+ </div>
+ );
+}
+
+export default LogsDashboard;
diff --git a/Merge/front/src/components/PlaceholderPage.jsx b/Merge/front/src/components/PlaceholderPage.jsx
new file mode 100644
index 0000000..b290eb4
--- /dev/null
+++ b/Merge/front/src/components/PlaceholderPage.jsx
@@ -0,0 +1,55 @@
+import React from 'react'
+import {
+ Home,
+ BookOpen,
+ Activity,
+ Users
+} from 'lucide-react'
+import '../App.css' // 或 PlaceholderPage.css
+
+const icons = {
+ home: Home,
+ notebooks: BookOpen,
+ activity: Activity,
+ notes: BookOpen,
+ creator: Users,
+ journal: BookOpen,
+}
+
+const titles = {
+ home: '欢迎来到小红书创作平台',
+ notebooks: '笔记管理功能开发中',
+ activity: '活动中心功能开发中',
+ notes: '笔记灵感功能开发中',
+ creator: '创作学院功能开发中',
+ journal: '创作日刊功能开发中',
+}
+
+const descs = {
+ home: '在这里您可以管理您的创作内容,查看数据分析,获取创作灵感。',
+ notebooks: '这里将显示您的所有笔记,支持编辑、删除、分类等操作。',
+ activity: '这里将展示最新的平台活动,让您参与更多有趣的创作活动。',
+ notes: '这里将为您提供创作灵感和写作建议,帮助您创作更好的内容。',
+ creator: '这里将提供创作技巧教学和平台规则说明,助您成为优秀创作者。',
+ journal: '这里将展示创作相关的最新资讯和平台动态。',
+}
+
+export default function PlaceholderPage({ pageId }) {
+ const Icon = icons[pageId] || Home
+ return (
+ <div className="page-content">
+ <div className="page-header">
+ <h1 className="page-title">{titles[pageId]}</h1>
+ </div>
+ <div className="page-body">
+ <div className="placeholder-content">
+ <div className="placeholder-icon">
+ <Icon size={48} />
+ </div>
+ <h3 className="placeholder-title">{titles[pageId]}</h3>
+ <p className="placeholder-desc">{descs[pageId]}</p>
+ </div>
+ </div>
+ </div>
+ )
+}
\ No newline at end of file
diff --git a/Merge/front/src/components/Sidebar.jsx b/Merge/front/src/components/Sidebar.jsx
new file mode 100644
index 0000000..26118b2
--- /dev/null
+++ b/Merge/front/src/components/Sidebar.jsx
@@ -0,0 +1,103 @@
+import React, { useState, useEffect } from 'react'
+import { NavLink, useLocation, useNavigate } from 'react-router-dom'
+import {
+ Home,
+ BookOpen,
+ BarChart3,
+ Activity,
+ Users,
+ ChevronDown,
+} from 'lucide-react'
+import '../App.css'
+
+const menuItems = [
+ { id: 'home', label: '首页', icon: Home, path: '/home' },
+ { id: 'notebooks', label: '笔记管理', icon: BookOpen, path: '/notebooks' },
+ {
+ id: 'dashboard',
+ label: '数据看板',
+ icon: BarChart3,
+ path: '/dashboard',
+ submenu: [
+ { id: 'overview', label: '账号概况', path: '/dashboard/overview' },
+ { id: 'content', label: '内容分析', path: '/dashboard/content' },
+ { id: 'fans', label: '粉丝数据', path: '/dashboard/fans' },
+ ]
+ },
+ { id: 'activity', label: '活动中心', icon: Activity, path: '/activity' },
+ { id: 'notes', label: '笔记灵感', icon: BookOpen, path: '/notes' },
+ { id: 'creator', label: '创作学院', icon: Users, path: '/creator' },
+ { id: 'journal', label: '创作日刊', icon: BookOpen, path: '/journal' },
+]
+
+export default function Sidebar() {
+ const [expandedMenu, setExpandedMenu] = useState(null)
+ const location = useLocation()
+ const navigate = useNavigate()
+
+ // 打开 dashboard 下拉时保持展开
+ useEffect(() => {
+ if (location.pathname.startsWith('/dashboard')) {
+ setExpandedMenu('dashboard')
+ }
+ }, [location.pathname])
+
+ const toggleMenu = item => {
+ if (item.submenu) {
+ setExpandedMenu(expandedMenu === item.id ? null : item.id)
+ } else {
+ navigate(item.path)
+ setExpandedMenu(null)
+ }
+ }
+
+ return (
+ <aside className="sidebar">
+ {/* 发布笔记 按钮 */}
+ <button
+ className="publish-btn"
+ onClick={() => navigate('/posts/new')}
+ >
+ 发布笔记
+ </button>
+
+ <nav className="nav-menu">
+ {menuItems.map(item => (
+ <div key={item.id} className="nav-item">
+ <a
+ href="#"
+ className={`nav-link${location.pathname === item.path ? ' active' : ''}`}
+ onClick={e => { e.preventDefault(); toggleMenu(item) }}
+ >
+ <item.icon size={16} />
+ <span>{item.label}</span>
+ {item.submenu && (
+ <ChevronDown
+ size={16}
+ style={{
+ marginLeft: 'auto',
+ transform: expandedMenu === item.id ? 'rotate(180deg)' : 'rotate(0deg)',
+ transition: 'transform 0.3s ease'
+ }}
+ />
+ )}
+ </a>
+ {item.submenu && expandedMenu === item.id && (
+ <div className="nav-submenu">
+ {item.submenu.map(sub => (
+ <NavLink
+ key={sub.id}
+ to={sub.path}
+ className={({ isActive }) => `nav-link${isActive ? ' active' : ''}`}
+ >
+ {sub.label}
+ </NavLink>
+ ))}
+ </div>
+ )}
+ </div>
+ ))}
+ </nav>
+ </aside>
+ )
+}
diff --git a/Merge/front/src/components/SuperAdmin.js b/Merge/front/src/components/SuperAdmin.js
new file mode 100644
index 0000000..817b708
--- /dev/null
+++ b/Merge/front/src/components/SuperAdmin.js
@@ -0,0 +1,64 @@
+import React, { useState, useEffect } from 'react';
+import { NavLink, Outlet } from 'react-router-dom';
+import { Spin } from 'antd';
+import { fetchUserList } from '../api/posts';
+import '../style/SuperAdmin.css';
+
+export default function SuperAdmin() {
+ const SUPERADMIN_USER_ID = 3;
+ const [loading, setLoading] = useState(true);
+ const [hasPermission, setHasPermission] = useState(true);
+
+ useEffect(() => {
+ async function check() {
+ try {
+ await fetchUserList(SUPERADMIN_USER_ID);
+ } catch (e) {
+ if (e.message === 'Unauthorized') {
+ setHasPermission(false);
+ } else {
+ console.error(e);
+ }
+ } finally {
+ setLoading(false);
+ }
+ }
+ check();
+ }, []);
+
+ if (loading) return <Spin spinning tip="加载中…" style={{ width: '100%', marginTop: 100 }} />;
+ if (!hasPermission) return <div style={{ textAlign: 'center', marginTop: 100 }}>权限不足</div>;
+
+ return (
+ <div className="super-admin-container">
+ <aside className="super-admin-sidebar">
+ <h2>超级管理员</h2>
+ <nav>
+ <ul>
+ <li>
+ <NavLink
+ to="users"
+ end
+ className={({ isActive }) => isActive ? 'active' : ''}
+ >
+ 用户管理
+ </NavLink>
+ </li>
+ <li>
+ <NavLink
+ to="dashboard"
+ className={({ isActive }) => isActive ? 'active' : ''}
+ >
+ 平台运行监控
+ </NavLink>
+ </li>
+ </ul>
+ </nav>
+ </aside>
+
+ <main className="super-admin-content">
+ <Outlet />
+ </main>
+ </div>
+ );
+}
\ No newline at end of file
diff --git a/Merge/front/src/components/UploadPage.jsx b/Merge/front/src/components/UploadPage.jsx
new file mode 100644
index 0000000..817a210
--- /dev/null
+++ b/Merge/front/src/components/UploadPage.jsx
@@ -0,0 +1,230 @@
+// src/components/UploadPage.jsx
+
+import React, { useState } from 'react'
+import { Image, Video } from 'lucide-react'
+import '../style/UploadPage.css'
+
+
+/**
+ * @param {Object} props
+ * @param {(files: File[]) => void} [props.onComplete] 上传完成后回调,接收 File 数组
+ */
+export default function UploadPage({ onComplete }) {
+ const [activeTab, setActiveTab] = useState('image')
+ const [isDragOver, setIsDragOver] = useState(false)
+ const [isUploading, setIsUploading] = useState(false)
+ const [uploadedFiles, setUploadedFiles] = useState([])
+ const [uploadProgress, setUploadProgress] = useState(0)
+
+ const validateFiles = files => {
+ const imgTypes = ['image/jpeg','image/jpg','image/png','image/webp']
+ const vidTypes = ['video/mp4','video/mov','video/avi']
+ const types = activeTab === 'video' ? vidTypes : imgTypes
+ const max = activeTab === 'video'
+ ? 2 * 1024 * 1024 * 1024
+ : 32 * 1024 * 1024
+
+ const invalid = files.filter(f => !types.includes(f.type) || f.size > max)
+ if (invalid.length) {
+ alert(`发现 ${invalid.length} 个无效文件,请检查文件格式和大小`)
+ return false
+ }
+ return true
+ }
+
+ const simulateUpload = files => {
+ setIsUploading(true)
+ setUploadProgress(0)
+ setUploadedFiles(files)
+
+ const iv = setInterval(() => {
+ setUploadProgress(p => {
+ if (p >= 100) {
+ clearInterval(iv)
+ setIsUploading(false)
+ alert(`成功上传了 ${files.length} 个文件`)
+ // 上传完成后回调
+ if (typeof onComplete === 'function') {
+ onComplete(files)
+ }
+ return 100
+ }
+ return p + 10
+ })
+ }, 200)
+ }
+
+ const handleFileUpload = () => {
+ if (isUploading) return
+ const input = document.createElement('input')
+ input.type = 'file'
+ input.accept = activeTab === 'video' ? 'video/*' : 'image/*'
+ input.multiple = activeTab === 'image'
+ input.onchange = e => {
+ const files = Array.from(e.target.files)
+ if (files.length > 0 && validateFiles(files)) {
+ simulateUpload(files)
+ }
+ }
+ input.click()
+ }
+
+ const handleDragOver = e => { e.preventDefault(); e.stopPropagation(); setIsDragOver(true) }
+ const handleDragLeave = e => { e.preventDefault(); e.stopPropagation(); setIsDragOver(false) }
+ const handleDrop = e => {
+ e.preventDefault(); e.stopPropagation(); setIsDragOver(false)
+ if (isUploading) return
+ const files = Array.from(e.dataTransfer.files)
+ if (files.length > 0 && validateFiles(files)) {
+ simulateUpload(files)
+ }
+ }
+
+ const clearFiles = () => setUploadedFiles([])
+ const removeFile = idx => setUploadedFiles(prev => prev.filter((_, i) => i !== idx))
+
+ return (
+ <div className="upload-page">
+ {/* 上传类型切换 */}
+ <div className="upload-tabs">
+ <button
+ className={`upload-tab${activeTab === 'video' ? ' active' : ''}`}
+ onClick={() => setActiveTab('video')}
+ >
+ 上传视频
+ </button>
+ <button
+ className={`upload-tab${activeTab === 'image' ? ' active' : ''}`}
+ onClick={() => setActiveTab('image')}
+ >
+ 上传图文
+ </button>
+ </div>
+
+ {/* 拖拽/点击上传区域 */}
+ <div
+ className={`upload-area${isDragOver ? ' drag-over' : ''}`}
+ onDragOver={handleDragOver}
+ onDragLeave={handleDragLeave}
+ onDrop={handleDrop}
+ >
+ <div className="upload-icon">
+ {activeTab === 'video' ? <Video size={48} /> : <Image size={48} />}
+ </div>
+ <h2 className="upload-title">
+ {activeTab === 'video'
+ ? '拖拽视频到此处或点击上传'
+ : '拖拽图片到此处或点击上传'}
+ </h2>
+ <p className="upload-subtitle">(需支持上传格式)</p>
+ <button
+ className={`upload-btn${isUploading ? ' uploading' : ''}`}
+ onClick={handleFileUpload}
+ disabled={isUploading}
+ >
+ {isUploading
+ ? `上传中... ${uploadProgress}%`
+ : activeTab === 'video'
+ ? '上传视频'
+ : '上传图片'}
+ </button>
+
+ {isUploading && (
+ <div className="progress-container">
+ <div className="progress-bar">
+ <div
+ className="progress-fill"
+ style={{ width: `${uploadProgress}%` }}
+ />
+ </div>
+ <div className="progress-text">{uploadProgress}%</div>
+ </div>
+ )}
+ </div>
+
+ {/* 已上传文件预览 */}
+ {uploadedFiles.length > 0 && (
+ <div className="file-preview-area">
+ <div className="preview-header">
+ <h3 className="preview-title">
+ 已上传文件 ({uploadedFiles.length})
+ </h3>
+ <button
+ className="clear-files-btn"
+ onClick={clearFiles}
+ >
+ 清除所有
+ </button>
+ </div>
+ <div className="file-grid">
+ {uploadedFiles.map((file, i) => (
+ <div key={i} className="file-item">
+ <button
+ className="remove-file-btn"
+ onClick={() => removeFile(i)}
+ title="删除文件"
+ >
+ ×
+ </button>
+ {file.type.startsWith('image/') ? (
+ <div className="file-thumbnail">
+ <img src={URL.createObjectURL(file)} alt={file.name} />
+ </div>
+ ) : (
+ <div className="file-thumbnail video-thumbnail">
+ <Video size={24} />
+ </div>
+ )}
+ <div className="file-info">
+ <div className="file-name" title={file.name}>
+ {file.name.length > 20
+ ? file.name.slice(0, 17) + '...'
+ : file.name}
+ </div>
+ <div className="file-size">
+ {(file.size / 1024 / 1024).toFixed(2)} MB
+ </div>
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
+
+ {/* 上传说明信息 */}
+ <div className="upload-info fade-in">
+ {activeTab === 'image' ? (
+ <>
+ <div className="info-item">
+ <h3 className="info-title">图片大小</h3>
+ <p className="info-desc">最大32MB</p>
+ </div>
+ <div className="info-item">
+ <h3 className="info-title">图片格式</h3>
+ <p className="info-desc">png/jpg/jpeg/webp</p>
+ </div>
+ <div className="info-item">
+ <h3 className="info-title">分辨率</h3>
+ <p className="info-desc">建议720×960及以上</p>
+ </div>
+ </>
+ ) : (
+ <>
+ <div className="info-item">
+ <h3 className="info-title">视频大小</h3>
+ <p className="info-desc">最大2GB,时长≤5分钟</p>
+ </div>
+ <div className="info-item">
+ <h3 className="info-title">视频格式</h3>
+ <p className="info-desc">mp4/mov</p>
+ </div>
+ <div className="info-item">
+ <h3 className="info-title">分辨率</h3>
+ <p className="info-desc">建议720P及以上</p>
+ </div>
+ </>
+ )}
+ </div>
+ </div>
+ )
+}
diff --git a/Merge/front/src/components/UserManagement.js b/Merge/front/src/components/UserManagement.js
new file mode 100644
index 0000000..4bd05c5
--- /dev/null
+++ b/Merge/front/src/components/UserManagement.js
@@ -0,0 +1,76 @@
+import React, { useState, useEffect } from 'react';
+import '../style/Admin.css';
+import { Select, message, Table } from 'antd';
+import { fetchUserList, giveUser, giveAdmin, giveSuperAdmin } from '../api/posts';
+
+const { Option } = Select;
+const ROLE_LIST = ['用户', '管理员', '超级管理员'];
+
+function UserManagement({ superAdminId }) {
+ const [users, setUsers] = useState([]);
+
+ useEffect(() => {
+ async function load() {
+ try {
+ const data = superAdminId
+ ? await fetchUserList(superAdminId)
+ : await fetch('/api/users').then(res => res.json());
+ setUsers(data);
+ } catch (e) {
+ console.error(e);
+ }
+ }
+ load();
+ }, [superAdminId]);
+
+ // handle role changes
+ const handleRoleChange = async (userId, newRole) => {
+ try {
+ if (newRole === '用户') await giveUser(superAdminId, userId);
+ else if (newRole === '管理员') await giveAdmin(superAdminId, userId);
+ else if (newRole === '超级管理员') await giveSuperAdmin(superAdminId, userId);
+ setUsers(us => us.map(u => u.id === userId ? { ...u, role: newRole } : u));
+ message.success('修改成功');
+ } catch (e) {
+ console.error(e);
+ message.error('修改失败');
+ }
+ };
+
+ // define table columns
+ const columns = [
+ { title: '用户名', dataIndex: 'username', key: 'username' },
+ { title: '角色', dataIndex: 'role', key: 'role' },
+ {
+ title: '操作',
+ key: 'action',
+ render: (_, record) => {
+ const orderedRoles = [record.role, ...ROLE_LIST.filter(r => r !== record.role)];
+ return (
+ <Select
+ value={record.role}
+ style={{ width: 120 }}
+ onChange={value => handleRoleChange(record.id, value)}
+ >
+ {orderedRoles.map(r => (
+ <Option key={r} value={r}>{r}</Option>
+ ))}
+ </Select>
+ );
+ },
+ },
+ ];
+
+ return (
+ <div className="admin-container">
+ <Table
+ dataSource={users}
+ columns={columns}
+ rowKey="id"
+ pagination={false}
+ />
+ </div>
+ );
+}
+
+export default UserManagement;
diff --git a/Merge/front/src/index.css b/Merge/front/src/index.css
new file mode 100644
index 0000000..72c144a
--- /dev/null
+++ b/Merge/front/src/index.css
@@ -0,0 +1,29 @@
+* {
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+}
+
+body {
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+ background-color: #f5f7fa;
+}
+
+button {
+ border: none;
+ background: none;
+ cursor: pointer;
+ font-family: inherit;
+}
+
+a {
+ text-decoration: none;
+ color: inherit;
+}
+
+#root {
+ width: 100%;
+ min-height: 100vh;
+}
diff --git a/Merge/front/src/index.js b/Merge/front/src/index.js
new file mode 100644
index 0000000..1ce450d
--- /dev/null
+++ b/Merge/front/src/index.js
@@ -0,0 +1,15 @@
+import React from 'react';
+import ReactDOM from 'react-dom/client';
+import { BrowserRouter } from 'react-router-dom';
+import './style/index.css';
+import App from './App';
+
+
+const root = ReactDOM.createRoot(document.getElementById('root'));
+root.render(
+ <React.StrictMode>
+
+ <App />
+
+ </React.StrictMode>
+);
\ No newline at end of file
diff --git a/Merge/front/src/router/App.js b/Merge/front/src/router/App.js
new file mode 100644
index 0000000..1a7fe0e
--- /dev/null
+++ b/Merge/front/src/router/App.js
@@ -0,0 +1,50 @@
+import React from 'react';
+import {
+ Routes,
+ Route,
+ Navigate,
+} from 'react-router-dom';
+import AdminPage from '../components/Admin';
+import UserManagement from '../components/UserManagement';
+import LogsDashboard from '../components/LogsDashboard';
+import SuperAdmin from '../components/SuperAdmin';
+
+import CreatePost from '../components/CreatePost' // src/components/CreatePost.jsx
+import HomeFeed from '../components/HomeFeed' // src/components/HomeFeed.jsx
+import PlaceholderPage from '../components/PlaceholderPage'// src/components/PlaceholderPage.jsx
+import UploadPage from '../components/UploadPage' // src/components/UploadPage.jsx
+
+
+export default function AppRoutes() {
+ return (
+ <Routes>
+ <Route path="/posts/new" element={<CreatePost />} />
+
+ <Route path="/home" element={<HomeFeed />} />
+
+ <Route path="/notebooks" element={<PlaceholderPage pageId="notebooks" />} />
+ <Route path="/activity" element={<PlaceholderPage pageId="activity" />} />
+ <Route path="/notes" element={<PlaceholderPage pageId="notes" />} />
+ <Route path="/creator" element={<PlaceholderPage pageId="creator" />} />
+ <Route path="/journal" element={<PlaceholderPage pageId="journal" />} />
+
+ <Route path="/dashboard/*" element={<UploadPage />} />
+
+ {/* 根路径重定向到 dashboard */}
+ <Route path="/" element={<Navigate to="/dashboard/overview" replace />} />
+
+ {/* 最后一个兜底 */}
+ <Route path="*" element={<PlaceholderPage pageId="home" />} />
+
+ {/* 普通管理员,无 header */}
+ <Route path="admin" element={<AdminPage />} />
+
+ {/* 超级管理员,只用 SuperAdminLayout */}
+ <Route path="superadmin" element={<SuperAdmin />}>
+ <Route index element={<Navigate to="users" replace />} />
+ <Route path="users" element={<UserManagement superAdminId={3} />} />
+ <Route path="dashboard" element={<LogsDashboard />} />
+ </Route>
+ </Routes>
+ );
+}
\ No newline at end of file
diff --git a/Merge/front/src/style/Admin.css b/Merge/front/src/style/Admin.css
new file mode 100644
index 0000000..4a5bcb7
--- /dev/null
+++ b/Merge/front/src/style/Admin.css
@@ -0,0 +1,389 @@
+@import "~antd/dist/antd.css";
+
+/* 整体容器背景,弱化底层 */
+.admin-container {
+ background-color: #f5f6f8;
+}
+
+.admin-container {
+ padding: 24px;
+ background-color: #fff;
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
+}
+
+/* 页眉分层:白底 + 圆角 + 阴影 */
+.page-header {
+ background: #fff;
+ padding: 12px 24px;
+ border-radius: 8px;
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
+}
+
+.admin-title {
+ font-size: 24px;
+ color: #e61515;
+ margin-bottom: 16px;
+}
+
+.admin-table {
+ width: 100%;
+ border-collapse: collapse;
+}
+
+.admin-table th,
+.admin-table td {
+ border: 1px solid #f0f0f0;
+ padding: 12px 16px;
+ text-align: left;
+}
+
+.admin-table th {
+ background-color: #fafafa;
+ color: #333;
+ font-weight: 500;
+}
+
+.status {
+ font-weight: 500;
+ text-transform: capitalize;
+}
+
+.status.pending {
+ color: #f29900;
+}
+
+.status.approved {
+ color: #28a745;
+}
+
+.status.banned {
+ color: #d73a49;
+}
+
+.btn {
+ padding: 6px 12px;
+ margin-right: 8px;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+ font-size: 14px;
+}
+
+.btn-approve {
+ background-color: #e61515;
+ color: #fff;
+}
+
+.btn-ban {
+ background-color: #f5f5f5;
+ color: #333;
+}
+
+/* 1. 瀑布流容器 */
+.admin-grid {
+ display: grid;
+ grid-gap: 16px;
+ grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
+ margin-top: 16px;
+}
+
+/* 2. 卡片 */
+.admin-card {
+ display: flex;
+ flex-direction: column;
+ background: #fff;
+ border-radius: 8px;
+ box-shadow: 0 2px 6px rgba(0,0,0,0.08);
+ overflow: hidden;
+ transition: transform 0.2s;
+}
+.admin-card:hover {
+ transform: translateY(-4px);
+}
+
+/* 3. 头部:用户名 + 状态 */
+.card-header {
+ padding: 12px 16px;
+ border-bottom: 1px solid #f0f0f0;
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+}
+.card-header .username {
+ font-weight: 500;
+ color: #333;
+}
+.card-header .status {
+ font-weight: 500;
+ text-transform: capitalize;
+}
+.card-header .status.pending { color: #f29900; }
+.card-header .status.approved { color: #28a745; }
+.card-header .status.banned { color: #d73a49; }
+
+/* 4. 操作按钮区 */
+.card-actions {
+ display: flex;
+ padding: 12px 16px;
+ border-top: 1px solid #f0f0f0;
+ gap: 8px;
+}
+.card-actions .btn {
+ flex: 1;
+}
+.card-actions .btn-approve { background-color: #e61515; color: #fff; }
+.card-actions .btn-ban { background-color: #f5f5f5; color: #333; }
+
+/* —— Admin.js 专用布局 —— */
+.admin-layout {
+ display: flex;
+ gap: 16px;
+}
+
+/* 左侧列表区 */
+.list-panel {
+ width: 320px;
+ border-right: 1px solid #f0f0f0;
+ padding-right: 16px;
+ overflow-y: auto;
+ padding: 16px;
+}
+
+/* 顶部标签切换 */
+.tabs {
+ display: flex;
+ border-bottom: 1px solid #f0f0f0;
+ margin-bottom: 8px;
+ background: #fafafa;
+ padding: 0 16px;
+ border-radius: 8px 8px 0 0;
+}
+.tab-btn {
+ flex: 1;
+ padding: 8px 12px;
+ background: none;
+ border: none;
+ border-bottom: 2px solid transparent;
+ cursor: pointer;
+ font-size: 14px;
+}
+.tab-btn.active {
+ border-color: #e61515;
+ color: #e61515;
+}
+
+/* 帖子列表 */
+.post-list {
+ /* 可根据需要添加滚动或间距 */
+}
+.post-item {
+ display: flex;
+ align-items: center;
+ padding: 8px;
+ cursor: pointer;
+ border-bottom: 1px solid #f5f5f5;
+ background: #fff;
+ margin-bottom: 4px;
+ border-radius: 4px;
+ transition: background 0.2s;
+}
+.post-item:hover {
+ background-color: #fafafa;
+}
+.post-item.selected {
+ background: #e6f1ff;
+}
+.thumb {
+ width: 40px;
+ height: 40px;
+ object-fit: cover;
+ border-radius: 4px;
+ margin-right: 8px;
+}
+.info {
+ flex: 1;
+}
+.info .title {
+ font-weight: 500;
+ color: #333;
+}
+.info .meta {
+ font-size: 12px;
+ color: #888;
+}
+
+/* 状态标签 */
+.status-tag {
+ padding: 2px 6px;
+ border-radius: 4px;
+ font-size: 12px;
+ text-transform: capitalize;
+}
+.status-tag.pending {
+ background-color: #fff4e5;
+ color: #f29900;
+}
+.status-tag.approved {
+ background-color: #e6f9f0;
+ color: #28a745;
+}
+.status-tag.rejected {
+ background-color: #fceaea;
+ color: #d73a49;
+}
+
+/* 右侧详情面板 */
+.detail-panel {
+ flex: 1;
+ padding-left: 16px;
+ max-height: calc(100vh - 100px);
+ overflow-y: auto;
+ padding: 24px;
+ margin-left: 8px;
+}
+
+/* 卡片阴影微调 */
+.admin-card {
+ box-shadow: 0 2px 6px rgba(0,0,0,0.08);
+}
+
+.detail-meta {
+ font-size: 12px;
+ color: #888;
+ margin-bottom: 8px;
+}
+.detail-content {
+ margin-bottom: 16px;
+ line-height: 1.6;
+}
+.detail-actions {
+ margin-bottom: 16px;
+ background: #f9f9fb;
+ padding: 12px;
+ border-radius: 4px;
+}
+
+/* 操作按钮 */
+.btn-reject {
+ background-color: #f5f5f5;
+ color: #333;
+}
+.rejected-label {
+ color: #d73a49;
+ font-weight: 500;
+}
+
+/* 加载与空状态 */
+.loading,
+.empty-state {
+ text-align: center;
+ padding: 16px;
+ color: #888;
+}
+
+/* 合规性指引 */
+.compliance-guidelines {
+ border-top: 1px solid #f0f0f0;
+ padding-top: 12px;
+ margin-top: 12px;
+ background: #f9f9fb;
+ padding: 12px;
+ border-radius: 4px;
+}
+.compliance-guidelines h4 {
+ margin-bottom: 8px;
+ font-size: 16px;
+}
+.compliance-guidelines ul {
+ padding-left: 20px;
+}
+.compliance-guidelines li {
+ line-height: 1.4;
+ margin-bottom: 4px;
+}
+
+/* 管理员导航栏样式 */
+.admin-nav {
+ display: flex;
+ align-items: center;
+ gap: 1.5rem;
+ margin: 1rem 0 2rem;
+ border-bottom: 2px solid #e5e5e5;
+}
+
+.admin-nav button {
+ background: none;
+ border: none;
+ padding: 0.5rem 0;
+ font-size: 1rem;
+ color: #555;
+ cursor: pointer;
+ position: relative;
+ transition: color 0.3s ease;
+}
+
+.admin-nav button:hover {
+ color: #000;
+}
+
+.admin-nav button.active {
+ color: #0078d4;
+}
+
+.admin-nav button.active::after {
+ content: '';
+ position: absolute;
+ bottom: -2px;
+ left: 0;
+ width: 100%;
+ height: 3px;
+ background-color: #0078d4;
+ border-radius: 2px 2px 0 0;
+}
+
+/* 页面头部:标题 + 搜索框 */
+.page-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 16px;
+ background: #fff;
+ padding: 12px 24px;
+ border-radius: 8px;
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
+}
+.main-title {
+ font-size: 28px;
+ color: #e61515;
+ margin: 0;
+}
+.search-input {
+ width: 240px;
+ padding: 6px 12px;
+ font-size: 14px;
+ border: 1px solid #ddd;
+ border-radius: 4px;
+ transition: border-color 0.2s;
+ background: #fafafa;
+}
+.search-input:focus {
+ outline: none;
+ border-color: #e61515;
+}
+
+/* 小红书品牌红 */
+:root {
+ --xiaohongshu-red: #e2204f;
+}
+
+/* Antd 表格表头背景小红书红,文字白色 */
+.ant-table-thead > tr > th {
+ background-color: var(--xiaohongshu-red) !important;
+ color: #fff;
+}
+
+/* 侧栏前两项文字变小红书红 */
+.ant-layout-sider .ant-menu-item:nth-child(1),
+.ant-layout-sider .ant-menu-item:nth-child(2) {
+ color: var(--xiaohongshu-red) !important;
+}
\ No newline at end of file
diff --git a/Merge/front/src/style/CreatePost.css b/Merge/front/src/style/CreatePost.css
new file mode 100644
index 0000000..4868132
--- /dev/null
+++ b/Merge/front/src/style/CreatePost.css
@@ -0,0 +1,98 @@
+/* src/style/CreatePost.css */
+.create-post {
+ max-width: 600px;
+ margin: 0 auto;
+ padding: 20px;
+ background: #fff;
+ border-radius: 8px;
+}
+
+/* 预览区 */
+.preview-media {
+ display: flex;
+ gap: 12px;
+ flex-wrap: wrap;
+ margin-bottom: 20px;
+}
+.preview-item {
+ width: 100px;
+ height: 100px;
+ overflow: hidden;
+ border: 1px solid #eee;
+ border-radius: 4px;
+}
+.preview-item img,
+.preview-item video {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+}
+
+/* 表单项 */
+label {
+ display: block;
+ margin-bottom: 16px;
+ font-size: 14px;
+ color: #333;
+}
+label input[type="text"],
+label textarea,
+label select {
+ width: 100%;
+ padding: 8px;
+ margin-top: 6px;
+ border: 1px solid #ddd;
+ border-radius: 4px;
+ font-size: 14px;
+ box-sizing: border-box;
+}
+label textarea {
+ min-height: 120px;
+ resize: vertical;
+}
+.char-count {
+ float: right;
+ font-size: 12px;
+ color: #999;
+}
+
+/* 发布状态 */
+.status-group {
+ display: flex;
+ gap: 20px;
+ margin-bottom: 20px;
+}
+.status-group label {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ font-size: 14px;
+}
+
+/* 按钮组 */
+.btn-group {
+ display: flex;
+ gap: 12px;
+ justify-content: flex-end;
+}
+.btn {
+ padding: 8px 16px;
+ border-radius: 4px;
+ border: none;
+ cursor: pointer;
+ font-size: 14px;
+}
+.btn-primary {
+ background: #ff4757;
+ color: #fff;
+}
+.btn-secondary {
+ background: #f0f0f0;
+ color: #333;
+}
+
+/* 错误信息 */
+.error {
+ color: #d9534f;
+ margin-bottom: 12px;
+}
diff --git a/Merge/front/src/style/HomeFeed.css b/Merge/front/src/style/HomeFeed.css
new file mode 100644
index 0000000..f1bf75d
--- /dev/null
+++ b/Merge/front/src/style/HomeFeed.css
@@ -0,0 +1,116 @@
+/* --------- 容器 & Tabs --------- */
+.home-feed {
+ padding: 20px;
+}
+
+.feed-tabs {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 12px;
+ margin-bottom: 20px;
+}
+
+.feed-tabs .tab {
+ padding: 6px 12px;
+ border: none;
+ background: #f0f0f0;
+ border-radius: 16px;
+ cursor: pointer;
+ transition: background 0.2s;
+}
+
+.feed-tabs .tab.active {
+ background: #ff4757;
+ color: #fff;
+}
+
+/* --------- 瀑布流布局 --------- */
+.feed-grid {
+ display: grid;
+ grid-gap: 16px;
+ grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
+}
+
+/* --------- 卡片样式及最大高度限制 --------- */
+.feed-card {
+ display: flex;
+ flex-direction: column;
+ max-height: 360px; /* 卡片最大高度 */
+ overflow: hidden; /* 超出部分隐藏 */
+ background: #fff;
+ border-radius: 8px;
+ box-shadow: 0 1px 4px rgba(0,0,0,0.1);
+ transition: transform 0.2s;
+}
+
+.feed-card:hover {
+ transform: translateY(-4px);
+}
+
+/* 封面图固定高度 */
+.card-img {
+ width: 100%;
+ height: 180px; /* 固定图片区域高度 */
+ object-fit: cover;
+ flex-shrink: 0; /* 不随容器收缩 */
+}
+
+/* 标题填充剩余空间 */
+.card-title {
+ font-size: 14px;
+ color: #333;
+ margin: 12px;
+ line-height: 1.4;
+ flex: 1; /* 占满中间区域 */
+ overflow: hidden;
+ text-overflow: ellipsis;
+ display: -webkit-box;
+ -webkit-line-clamp: 2; /* 最多两行 */
+ -webkit-box-orient: vertical;
+}
+
+/* --------- 底部:作者 + 点赞 --------- */
+.card-footer {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 8px 12px;
+ border-top: 1px solid #f0f0f0;
+ background: #fff;
+ flex-shrink: 0; /* 保持在底部 */
+}
+
+/* 作者区域 */
+.card-author {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+}
+
+.card-author .avatar {
+ width: 24px;
+ height: 24px;
+ border-radius: 50%;
+ object-fit: cover;
+}
+
+.card-author .username {
+ font-size: 13px;
+ color: #333;
+}
+
+/* 点赞区域 */
+.card-likes {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+}
+
+.card-likes svg {
+ color: #ff4757;
+}
+
+.card-likes .likes-count {
+ font-size: 13px;
+ color: #666;
+}
\ No newline at end of file
diff --git a/Merge/front/src/style/SuperAdmin.css b/Merge/front/src/style/SuperAdmin.css
new file mode 100644
index 0000000..2295f8b
--- /dev/null
+++ b/Merge/front/src/style/SuperAdmin.css
@@ -0,0 +1,30 @@
+.super-admin-container {
+ display: flex;
+ height: 100vh;
+}
+
+.super-admin-sidebar {
+ width: 200px;
+ padding: 20px;
+ background: #f5f5f5;
+}
+
+.super-admin-sidebar ul {
+ list-style: none;
+ padding: 0;
+}
+
+.super-admin-sidebar li {
+ margin-bottom: 10px;
+}
+
+.super-admin-sidebar .active {
+ font-weight: bold;
+ color: #1890ff;
+}
+
+.super-admin-content {
+ flex: 1;
+ padding: 20px;
+ background: #fff;
+}
\ No newline at end of file
diff --git a/Merge/front/src/style/UploadPage.css b/Merge/front/src/style/UploadPage.css
new file mode 100644
index 0000000..138b0c1
--- /dev/null
+++ b/Merge/front/src/style/UploadPage.css
@@ -0,0 +1,70 @@
+.upload-page {
+ max-width: 800px;
+ margin: 0 auto;
+ padding: 16px;
+ font-family: sans-serif;
+ color: #333;
+}
+
+.upload-tabs {
+ display: flex;
+ margin-bottom: 16px;
+}
+
+.upload-tab {
+ flex: 1;
+ padding: 8px 16px;
+ border: 1px solid #ddd;
+ background: #f9f9f9;
+ cursor: pointer;
+ text-align: center;
+}
+
+.upload-tab.active {
+ background: #fff;
+ border-bottom: 2px solid #1890ff;
+ color: #1890ff;
+}
+
+.upload-area {
+ border: 2px dashed #ccc;
+ padding: 40px;
+ text-align: center;
+ transition: background 0.3s;
+}
+
+.upload-area.drag-over {
+ background: #eef6ff;
+}
+
+.upload-btn {
+ margin-top: 16px;
+ padding: 8px 24px;
+ border: none;
+ background: #1890ff;
+ color: #fff;
+ cursor: pointer;
+}
+
+.upload-btn:disabled {
+ background: #aaa;
+ cursor: not-allowed;
+}
+
+/* 如果有 upload-table 相关,用类似方式定义 */
+.upload-table {
+ width: 100%;
+ border-collapse: collapse;
+ margin-top: 24px;
+}
+
+.upload-table th,
+.upload-table td {
+ border: 1px solid #ddd;
+ padding: 8px;
+ text-align: left;
+}
+
+.upload-table th {
+ background: #f5f5f5;
+}
diff --git a/Merge/front/src/style/index.css b/Merge/front/src/style/index.css
new file mode 100644
index 0000000..ec2585e
--- /dev/null
+++ b/Merge/front/src/style/index.css
@@ -0,0 +1,13 @@
+body {
+ margin: 0;
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
+ 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
+ sans-serif;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+}
+
+code {
+ font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
+ monospace;
+}