浏览代码

桌面启动

flower_bs 1 月之前
父节点
当前提交
5323634f69
共有 5 个文件被更改,包括 352 次插入1 次删除
  1. 14 1
      backend_start windows.ps1
  2. 45 0
      create_shortcut.ps1
  3. 39 0
      start_project.bat
  4. 51 0
      start_project.ps1
  5. 203 0
      打包说明.md

+ 14 - 1
backend_start windows.ps1

@@ -1,5 +1,18 @@
-#!/bin/bash
+# GreaterWMS 后端启动脚本 (Windows PowerShell版本)
+# 此脚本会启动Django后端服务
+
+Write-Host "启动GreaterWMS后端服务..." -ForegroundColor Cyan
+
+# 获取脚本所在目录
+$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
+Set-Location $ScriptDir
+
+# 执行数据库迁移
+Write-Host "执行数据库迁移..." -ForegroundColor Yellow
 python manage.py makemigrations
 python manage.py migrate
 
+# 启动Daphne服务器
+Write-Host "启动后端服务 (端口: 8008)..." -ForegroundColor Green
+Write-Host "服务地址: http://0.0.0.0:8008" -ForegroundColor Cyan
 daphne -b 0.0.0.0 -p 8008 greaterwms.asgi:application

+ 45 - 0
create_shortcut.ps1

@@ -0,0 +1,45 @@
+# 创建桌面快捷方式脚本
+# 运行此脚本将在桌面创建GreaterWMS的启动快捷方式
+
+Write-Host "正在创建桌面快捷方式..." -ForegroundColor Yellow
+
+# 获取脚本所在目录(项目根目录)
+$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
+
+# 桌面路径
+$DesktopPath = [Environment]::GetFolderPath("Desktop")
+$ShortcutPath = Join-Path $DesktopPath "GreaterWMS.lnk"
+
+# 启动脚本路径(优先使用.bat,兼容性更好)
+$StartScript = Join-Path $ScriptDir "start_project.bat"
+
+# 图标路径(如果有的话,可以指定一个图标文件)
+# $IconPath = Join-Path $ScriptDir "icon.ico"
+
+try {
+    # 创建快捷方式
+    $WshShell = New-Object -ComObject WScript.Shell
+    $Shortcut = $WshShell.CreateShortcut($ShortcutPath)
+    $Shortcut.TargetPath = $StartScript
+    $Shortcut.WorkingDirectory = $ScriptDir
+    $Shortcut.Description = "GreaterWMS 仓库管理系统"
+    # $Shortcut.IconLocation = $IconPath
+    $Shortcut.Save()
+
+    Write-Host "✓ 桌面快捷方式创建成功!" -ForegroundColor Green
+    Write-Host "  位置: $ShortcutPath" -ForegroundColor Cyan
+    Write-Host ""
+    Write-Host "现在您可以在桌面双击 'GreaterWMS' 快捷方式来启动项目了!" -ForegroundColor Yellow
+} catch {
+    Write-Host "✗ 创建快捷方式失败: $_" -ForegroundColor Red
+    Write-Host ""
+    Write-Host "请尝试以管理员身份运行此脚本,或者手动创建快捷方式:" -ForegroundColor Yellow
+    Write-Host "  1. 右键点击桌面 -> 新建 -> 快捷方式" -ForegroundColor Gray
+    Write-Host "  2. 输入: $StartScript" -ForegroundColor Gray
+    Write-Host "  3. 命名为: GreaterWMS" -ForegroundColor Gray
+}
+
+Write-Host ""
+Write-Host "按任意键退出..."
+$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
+

+ 39 - 0
start_project.bat

@@ -0,0 +1,39 @@
+@echo off
+chcp 65001 >nul
+title GreaterWMS WMS启动器
+
+echo =====================================
+echo     GreaterWMS WMS启动脚本
+echo =====================================
+echo.
+
+REM 获取脚本所在目录
+cd /d "%~dp0"
+
+REM 检查Python是否安装
+echo [1/2] 检查Python环境...
+python --version >nul 2>&1
+if errorlevel 1 (
+    echo ✗ 未找到Python,请先安装Python
+    pause
+    exit /b 1
+)
+echo ✓ Python已安装
+
+REM 启动WMS服务
+echo [2/2] 启动WMS服务...
+echo WMS服务将运行在: http://localhost:8008
+
+start "GreaterWMS-WMS服务" cmd /k "python manage.py makemigrations && python manage.py migrate && echo WMS服务启动中... && daphne -b 0.0.0.0 -p 8008 greaterwms.asgi:application"
+
+echo.
+echo =====================================
+echo ✓ WMS服务启动完成!
+echo =====================================
+echo.
+echo WMS服务: http://localhost:8008
+echo.
+echo 服务窗口已打开,请勿关闭。
+echo 按任意键退出此窗口(服务将继续运行)...
+pause >nul
+

+ 51 - 0
start_project.ps1

@@ -0,0 +1,51 @@
+# GreaterWMS 后端启动脚本
+# 此脚本会启动后端服务
+
+Write-Host "=====================================" -ForegroundColor Cyan
+Write-Host "    GreaterWMS 后端启动脚本" -ForegroundColor Cyan
+Write-Host "=====================================" -ForegroundColor Cyan
+Write-Host ""
+
+# 获取脚本所在目录
+$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
+Set-Location $ScriptDir
+
+# 检查Python是否安装
+Write-Host "[1/2] 检查Python环境..." -ForegroundColor Yellow
+try {
+    $pythonVersion = python --version
+    Write-Host "✓ Python已安装: $pythonVersion" -ForegroundColor Green
+} catch {
+    Write-Host "✗ 未找到Python,请先安装Python" -ForegroundColor Red
+    pause
+    exit 1
+}
+
+# 启动后端服务
+Write-Host "[2/2] 启动后端服务..." -ForegroundColor Yellow
+Write-Host "后端服务将运行在: http://0.0.0.0:8008" -ForegroundColor Cyan
+
+# 在新窗口中启动后端
+$backendScript = @"
+cd '$ScriptDir'
+python manage.py makemigrations
+python manage.py migrate
+Write-Host '后端服务启动中...' -ForegroundColor Green
+daphne -b 0.0.0.0 -p 8008 greaterwms.asgi:application
+pause
+"@
+
+Start-Process powershell -ArgumentList "-NoExit", "-Command", $backendScript
+
+Write-Host ""
+Write-Host "=====================================" -ForegroundColor Green
+Write-Host "✓ 后端服务启动完成!" -ForegroundColor Green
+Write-Host "=====================================" -ForegroundColor Green
+Write-Host ""
+Write-Host "后端服务: http://localhost:8008" -ForegroundColor Cyan
+Write-Host ""
+Write-Host "服务窗口已打开,请勿关闭。" -ForegroundColor Yellow
+Write-Host "按任意键退出此窗口(服务将继续运行)..." -ForegroundColor Gray
+
+pause
+

+ 203 - 0
打包说明.md

@@ -0,0 +1,203 @@
+# GreaterWMS 打包说明
+
+本项目提供了多种打包和部署方式,您可以根据需要选择合适的方式。
+
+## 方式一:创建桌面快捷方式(开发模式)
+
+这是最简单的方式,适合开发环境使用。
+
+### 步骤:
+
+1. **创建桌面快捷方式**
+   ```powershell
+   # 以管理员身份运行PowerShell,执行:
+   .\create_shortcut.ps1
+   ```
+   或者双击运行 `create_shortcut.ps1`
+
+2. **使用快捷方式启动**
+   - 双击桌面的 "GreaterWMS" 快捷方式
+   - 会自动启动后端服务(端口8008)和前端服务(端口8080)
+   - 访问 http://localhost:8080 使用系统
+
+### 手动创建快捷方式(如果脚本失败)
+
+1. 右键桌面 -> 新建 -> 快捷方式
+2. 输入路径:`D:\code\vue\greater_wms\start_project.bat`
+3. 命名为:`GreaterWMS`
+4. 可以右键快捷方式 -> 属性 -> 更改图标(如果有图标文件)
+
+---
+
+## 方式二:使用Quasar打包成桌面应用(Electron)
+
+项目已经配置好了Electron打包选项,可以打包成Windows安装包。
+
+### 前提条件
+
+1. 确保已安装Node.js和npm
+2. 在前端目录安装依赖:
+   ```bash
+   cd templates
+   npm install
+   ```
+
+### 打包步骤
+
+1. **安装Electron模式**
+   ```bash
+   cd templates
+   quasar mode add electron
+   ```
+
+2. **构建Electron应用**
+   ```bash
+   # 开发模式测试
+   quasar dev -m electron
+   
+   # 打包成安装程序
+   quasar build -m electron
+   ```
+
+3. **打包结果**
+   打包完成后,安装程序位于:
+   ```
+   templates/dist/electron/Packaged/GreaterWMS Setup x.x.x.exe
+   ```
+   
+   双击安装程序即可安装,安装后会自动在桌面和开始菜单创建快捷方式。
+
+### Electron配置说明
+
+项目已配置了以下内容(在 `templates/quasar.conf.js` 中):
+
+- **应用ID**: `com.electron.greaterwms`
+- **产品名称**: `GreaterWMS`
+- **Windows打包格式**: NSIS安装程序(.exe)
+- **自动创建桌面快捷方式**: ✅ 已启用
+- **允许自定义安装目录**: ✅ 已启用
+
+---
+
+## 方式三:打包前端为静态文件(生产部署)
+
+如果您想将前端打包成静态文件部署到Web服务器:
+
+### 步骤
+
+1. **构建前端**
+   ```bash
+   cd templates
+   npm run build
+   ```
+
+2. **构建结果**
+   静态文件位于:`templates/dist/spa/`
+   
+   可以将这些文件部署到Nginx、Apache等Web服务器。
+
+3. **配置后端**
+   确保Django设置中的 `ALLOWED_HOSTS` 包含您的域名。
+
+---
+
+## 方式四:使用Docker打包(推荐用于生产)
+
+如果需要完整的容器化部署,可以创建Docker配置:
+
+### Dockerfile示例
+
+**后端Dockerfile** (项目根目录):
+```dockerfile
+FROM python:3.8
+WORKDIR /app
+COPY requirements.txt .
+RUN pip install -r requirements.txt
+COPY . .
+EXPOSE 8008
+CMD ["daphne", "-b", "0.0.0.0", "-p", "8008", "greaterwms.asgi:application"]
+```
+
+**前端Dockerfile** (templates目录):
+```dockerfile
+FROM node:14 as build
+WORKDIR /app
+COPY package*.json ./
+RUN npm install
+COPY . .
+RUN npm run build
+
+FROM nginx:alpine
+COPY --from=build /app/dist/spa /usr/share/nginx/html
+EXPOSE 80
+CMD ["nginx", "-g", "daemon off;"]
+```
+
+### 使用Docker Compose
+
+创建 `docker-compose.yml`:
+```yaml
+version: '3'
+services:
+  backend:
+    build: .
+    ports:
+      - "8008:8008"
+  
+  frontend:
+    build: ./templates
+    ports:
+      - "80:80"
+    depends_on:
+      - backend
+```
+
+---
+
+## 推荐方案对比
+
+| 方案 | 适用场景 | 优点 | 缺点 |
+|------|---------|------|------|
+| 桌面快捷方式 | 开发/测试 | 简单快速,无需打包 | 需要手动启动服务 |
+| Electron打包 | 本地部署 | 一键启动,用户体验好 | 打包体积较大 |
+| 静态文件部署 | 生产环境 | 性能好,易部署 | 需要Web服务器 |
+| Docker | 生产环境 | 环境一致,易管理 | 需要Docker环境 |
+
+---
+
+## 注意事项
+
+1. **端口冲突**:确保8008和8080端口未被占用
+2. **数据库**:根据实际情况配置数据库(SQLite/PostgreSQL)
+3. **环境变量**:生产环境建议配置环境变量而非硬编码
+4. **安全设置**:生产环境应将 `DEBUG = False`
+
+---
+
+## 故障排除
+
+### 如果启动脚本无法运行
+
+1. **检查执行策略**(PowerShell)
+   ```powershell
+   Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
+   ```
+
+2. **使用批处理文件**:直接运行 `start_project.bat`
+
+### 如果Electron打包失败
+
+1. 确保已安装所有依赖:`npm install`
+2. 清理缓存:`npm cache clean --force`
+3. 删除 `node_modules` 重新安装
+
+### 如果端口被占用
+
+修改配置文件:
+- 后端端口:修改 `backend_start windows.ps1` 中的端口号
+- 前端端口:修改 `templates/quasar.conf.js` 中的 `devServer.port`
+
+---
+
+如有问题,请查看项目文档或提交Issue。
+