随着城市化进程的加快,社区文化活动在提升居民生活质量、促进邻里和谐方面发挥着越来越重要的作用。传统的社区文化活动管理方式存在信息传递不及时、活动组织效率低、参与度统计困难等问题。因此,开发一套现代化的社区文化活动管理系统具有重要的现实意义。
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Vue 3 前端 │ │ FastAPI 后端 │ │ PostgreSQL │
│ │ │ │ │ │
│ - 用户界面 │◄──►│ - REST API │◄──►│ - 用户数据 │
│ - 状态管理 │ │ - 业务逻辑 │ │ - 活动数据 │
│ - 路由管理 │ │ - 数据验证 │ │ - 系统配置 │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ Redis │
│ │
│ - 会话缓存 │
│ - 数据缓存 │
└─────────────────┘
功能模块 | 超级管理员 | 社区管理员 | 活动组织者 | 普通用户 |
---|---|---|---|---|
用户管理 | ✓ | ✓ | ✗ | ✗ |
活动管理 | ✓ | ✓ | ✓ | ✗ |
活动参与 | ✓ | ✓ | ✓ | ✓ |
数据统计 | ✓ | ✓ | ✗ | ✗ |
系统设置 | ✓ | ✗ | ✗ | ✗ |
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
full_name VARCHAR(100) NOT NULL,
phone VARCHAR(20),
avatar_url VARCHAR(255),
role_id INTEGER REFERENCES roles(id),
community_id INTEGER REFERENCES communities(id),
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE roles (
id SERIAL PRIMARY KEY,
name VARCHAR(50) UNIQUE NOT NULL,
description TEXT,
permissions JSONB,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE communities (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description TEXT,
address TEXT,
contact_person VARCHAR(100),
contact_phone VARCHAR(20),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE activities (
id SERIAL PRIMARY KEY,
title VARCHAR(200) NOT NULL,
description TEXT,
category_id INTEGER REFERENCES categories(id),
organizer_id INTEGER REFERENCES users(id),
community_id INTEGER REFERENCES communities(id),
location VARCHAR(255),
start_time TIMESTAMP NOT NULL,
end_time TIMESTAMP NOT NULL,
max_participants INTEGER,
current_participants INTEGER DEFAULT 0,
status VARCHAR(20) DEFAULT 'draft',
cover_image VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE categories (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description TEXT,
icon VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE registrations (
id SERIAL PRIMARY KEY,
activity_id INTEGER REFERENCES activities(id),
user_id INTEGER REFERENCES users(id),
status VARCHAR(20) DEFAULT 'pending',
registration_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
check_in_time TIMESTAMP,
notes TEXT
);
CREATE TABLE reviews (
id SERIAL PRIMARY KEY,
activity_id INTEGER REFERENCES activities(id),
user_id INTEGER REFERENCES users(id),
rating INTEGER CHECK (rating >= 1 AND rating <= 5),
comment TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
users ─────┐
├── registrations ─── activities ─── categories
│ │
└── reviews ────────────────┘
│
communities ────┘
backend/
├── app/
│ ├── __init__.py
│ ├── main.py
│ ├── config.py
│ ├── database.py
│ ├── models/
│ │ ├── __init__.py
│ │ ├── user.py
│ │ ├── activity.py
│ │ ├── community.py
│ │ └── review.py
│ ├── schemas/
│ │ ├── __init__.py
│ │ ├── user.py
│ │ ├── activity.py
│ │ └── review.py
│ ├── api/
│ │ ├── __init__.py
│ │ ├── v1/
│ │ │ ├── __init__.py
│ │ │ ├── auth.py
│ │ │ ├── users.py
│ │ │ ├── activities.py
│ │ │ └── reviews.py
│ ├── core/
│ │ ├── __init__.py
│ │ ├── security.py
│ │ └── config.py
│ └── utils/
│ ├── __init__.py
│ └── helpers.py
├── requirements.txt
└── alembic/
├── versions/
└── alembic.ini
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.v1 import auth, users, activities, reviews
from app.database import engine
from app.models import Base
# 创建数据库表
Base.metadata.create_all(bind=engine)
app = FastAPI(
title="社区文化活动管理系统",
description="基于FastAPI和Vue3的社区文化活动管理系统",
version="1.0.0"
)
# 配置CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:3000"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 注册路由
app.include_router(auth.router, prefix="/api/v1/auth", tags=["认证"])
app.include_router(users.router, prefix="/api/v1/users", tags=["用户"])
app.include_router(activities.router, prefix="/api/v1/activities", tags=["活动"])
app.include_router(reviews.router, prefix="/api/v1/reviews", tags=["评价"])
@app.get("/")
async def root():
return {
"message": "社区文化活动管理系统API"}
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from app.database import Base
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
username = Column(String, unique=True, index=True)
email = Column(String, unique=True, index=