用户消息系统:消息列表、订单群聊、联系对方入口

- 新增消息列表页和聊天详情页,支持 SSE 实时推送
- 订单详情页新增"联系对方"按钮,一键进入订单群聊
- 导航栏新增"消息"入口
- 修复 mobileHost 路径匹配 bug,避免 /m 前缀误匹配
- 优化 dev.sh:提取 mysql 辅助函数、修复空 PID 处理、条件检查依赖

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
yml
2026-05-27 09:46:34 +08:00
co-authored by Claude Opus 4.7
parent 8cbd06dca4
commit 6fb5de204c
7 changed files with 792 additions and 14 deletions
+34 -10
View File
@@ -102,6 +102,10 @@ cleanup() {
fi
CLEANED_UP=1
if [[ -z "${FRONTEND_PID}" && -z "${BACKEND_PID}" ]]; then
return
fi
log "正在停止前后端开发进程..."
if [[ -n "${FRONTEND_PID}" ]] && kill -0 "${FRONTEND_PID}" >/dev/null 2>&1; then
kill "${FRONTEND_PID}" >/dev/null 2>&1 || true
@@ -131,16 +135,24 @@ wait_container_healthy() {
exit 1
}
mysql_root() {
docker exec -i -e MYSQL_PWD=rootsecret hfb-mysql mysql -uroot "$@"
}
mysql_hfb() {
docker exec -i -e MYSQL_PWD=secret hfb-mysql mysql -uhfb "$@"
}
init_database() {
if [[ "${RESET_DB}" == "1" ]]; then
log_warn "重置数据库..."
docker exec hfb-mysql mysql -uroot -prootsecret -e \
mysql_root -e \
"DROP DATABASE IF EXISTS hfb_sys; CREATE DATABASE hfb_sys CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
fi
local table_count
table_count="$(
docker exec hfb-mysql mysql -uhfb -psecret -N -s -e \
mysql_hfb -N -s -e \
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'hfb_sys' AND table_name = 'users';" 2>/dev/null
)"
@@ -149,12 +161,12 @@ init_database() {
local migration
for migration in "${ROOT_DIR}"/backend/migrations/*.sql; do
log "执行迁移:$(basename "${migration}")"
docker exec -i hfb-mysql mysql -uhfb -psecret --default-character-set=utf8mb4 hfb_sys < "${migration}"
mysql_hfb --default-character-set=utf8mb4 hfb_sys < "${migration}"
done
log_success "数据库初始化完成"
elif [[ "${SEED_ONLY}" == "1" ]]; then
log "重新加载种子数据..."
docker exec -i hfb-mysql mysql -uhfb -psecret --default-character-set=utf8mb4 hfb_sys < "${ROOT_DIR}/backend/migrations/000002_seed.sql"
mysql_hfb --default-character-set=utf8mb4 hfb_sys < "${ROOT_DIR}/backend/migrations/000002_seed.sql"
log_success "种子数据加载完成"
else
log "数据库已存在,跳过迁移(使用 --reset-db 重建)"
@@ -206,12 +218,12 @@ start_frontend() {
watch_processes() {
while true; do
if ! kill -0 "${BACKEND_PID}" >/dev/null 2>&1; then
if [[ -n "${BACKEND_PID}" ]] && ! kill -0 "${BACKEND_PID}" >/dev/null 2>&1; then
wait "${BACKEND_PID}" || true
printf "后端进程已退出\n" >&2
exit 1
fi
if ! kill -0 "${FRONTEND_PID}" >/dev/null 2>&1; then
if [[ -n "${FRONTEND_PID}" ]] && ! kill -0 "${FRONTEND_PID}" >/dev/null 2>&1; then
wait "${FRONTEND_PID}" || true
printf "前端进程已退出\n" >&2
exit 1
@@ -222,8 +234,12 @@ watch_processes() {
main() {
need_cmd docker
need_cmd go
need_cmd npm
if [[ "${SEED_ONLY}" != "1" && "${NO_BACKEND}" == "0" ]]; then
need_cmd go
fi
if [[ "${SEED_ONLY}" != "1" && "${NO_FRONTEND}" == "0" ]]; then
need_cmd npm
fi
trap cleanup EXIT
trap 'cleanup; exit 130' INT TERM
@@ -252,8 +268,16 @@ main() {
fi
log_success "开发环境已启动"
log "前台:http://localhost:5173"
log "台:http://localhost:5173/admin/loginadmin / admin123456"
if [[ "${NO_FRONTEND}" == "0" ]]; then
log "台:http://localhost:5173"
log "后台:http://localhost:5173/admin/loginadmin / admin123456"
fi
if [[ -z "${BACKEND_PID}" && -z "${FRONTEND_PID}" ]]; then
log "仅启动 Docker 开发依赖,前后端未启动"
return 0
fi
log "按 Ctrl+C 停止前后端;Docker 依赖会保留运行"
watch_processes