From 2f16ff959b648456c2887d067a7c91ad324a1309 Mon Sep 17 00:00:00 2001 From: cloud370 Date: Wed, 24 Sep 2025 05:54:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=87=8D=E5=91=BD=E5=90=8Dpm2.sh?= =?UTF-8?q?=E4=B8=BAdeploy.sh=E5=B9=B6=E5=AE=9E=E7=8E=B0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重命名pm2.sh为deploy.sh - 实现自动从远程仓库拉取代码功能 - 添加自动构建功能 - 智能检测PM2进程状态,自动重载或创建进程 - 添加中文输出信息和错误处理 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- components/accounts/batch-operations.tsx | 19 ++++++- deploy.sh | 66 ++++++++++++++++++++++++ pm2.sh | 1 - 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 deploy.sh delete mode 100644 pm2.sh diff --git a/components/accounts/batch-operations.tsx b/components/accounts/batch-operations.tsx index 2f03dda..bd3b199 100644 --- a/components/accounts/batch-operations.tsx +++ b/components/accounts/batch-operations.tsx @@ -80,11 +80,28 @@ export function BatchOperations({ selectedCount, selectedAccounts, stats, onBatc }; const handleDownloadTxt = () => { + const platforms = Array.from(new Set(selectedAccounts.map(account => account.platform))); + const owners = Array.from(new Set(selectedAccounts.map(account => account.ownerId))); + + // 构建文件名部分 + const platformPart = platforms.length === 1 ? platforms[0] : `${platforms.length}个平台`; + const ownerPart = owners.length === 1 ? owners[0] : `${owners.length}个用户`; + const countPart = `${exportData.count}个账户`; + const datePart = new Date().toLocaleString('zh-CN', { + timeZone: 'Asia/Shanghai', + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + }).replace(/[\/\s:]/g, '-'); + const blob = new Blob([exportData.text], { type: 'text/plain;charset=utf-8' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; - link.download = `accounts_export_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.txt`; + link.download = `${platformPart}_${ownerPart}_${countPart}_${datePart}.txt`; document.body.appendChild(link); link.click(); document.body.removeChild(link); diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..63f8368 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# 部署脚本 - 自动拉取、构建、PM2重载/启动 +APP_NAME="accounts-manager-web" + +echo "==========================================" +echo " 开始部署 $APP_NAME" +echo "==========================================" + +# 1. 从远程仓库拉取最新代码 +echo "📦 正在从远程仓库拉取最新代码..." +git pull origin master +if [ $? -ne 0 ]; then + echo "❌ 拉取代码失败,请检查网络连接或仓库状态" + exit 1 +fi +echo "✅ 代码拉取成功" + +# 2. 安装依赖并构建项目 +echo "🔨 正在安装依赖并构建项目..." +npm install +if [ $? -ne 0 ]; then + echo "❌ 安装依赖失败" + exit 1 +fi + +npm run build +if [ $? -ne 0 ]; then + echo "❌ 项目构建失败" + exit 1 +fi +echo "✅ 项目构建成功" + +# 3. 检查PM2进程是否存在 +echo "🔍 正在检查PM2进程状态..." +PM2_STATUS=$(pm2 list | grep -c "$APP_NAME") + +if [ $PM2_STATUS -gt 0 ]; then + # PM2进程存在,执行重载 + echo "🔄 PM2进程已存在,正在重载应用..." + pm2 reload $APP_NAME + if [ $? -eq 0 ]; then + echo "✅ PM2应用重载成功" + else + echo "❌ PM2应用重载失败" + exit 1 + fi +else + # PM2进程不存在,创建新进程 + echo "🚀 PM2进程不存在,正在启动新应用..." + pm2 start npm --name $APP_NAME -- run start:prod + if [ $? -eq 0 ]; then + echo "✅ PM2应用启动成功" + else + echo "❌ PM2应用启动失败" + exit 1 + fi +fi + +# 4. 显示PM2状态 +echo "📊 当前PM2状态:" +pm2 list + +echo "==========================================" +echo " 🎉 部署完成!" +echo "==========================================" \ No newline at end of file diff --git a/pm2.sh b/pm2.sh deleted file mode 100644 index ced8ad9..0000000 --- a/pm2.sh +++ /dev/null @@ -1 +0,0 @@ -pm2 start npm --name accounts-manager-web -- run start:prod \ No newline at end of file