diff --git a/backend b/backend new file mode 160000 index 0000000..49917ae --- /dev/null +++ b/backend @@ -0,0 +1 @@ +Subproject commit 49917ae7c0de3c7c12de367b99b671321c3c304c diff --git a/backend-tp b/backend-tp new file mode 160000 index 0000000..49917ae --- /dev/null +++ b/backend-tp @@ -0,0 +1 @@ +Subproject commit 49917ae7c0de3c7c12de367b99b671321c3c304c diff --git a/backend-tp8 b/backend-tp8 new file mode 160000 index 0000000..49917ae --- /dev/null +++ b/backend-tp8 @@ -0,0 +1 @@ +Subproject commit 49917ae7c0de3c7c12de367b99b671321c3c304c diff --git a/composer.phar b/composer.phar new file mode 100644 index 0000000..43f4b99 Binary files /dev/null and b/composer.phar differ diff --git a/deploy/nginx.conf.example b/deploy/nginx.conf.example new file mode 100644 index 0000000..e037e44 --- /dev/null +++ b/deploy/nginx.conf.example @@ -0,0 +1,46 @@ +# AI Chat 生产环境 Nginx 配置示例 +# 网站根目录必须指向 backend/public +# phpstudy:网站 -> 设置 -> 配置文件,粘贴以下 server 块内容 + +server { + listen 80; + # listen 9998; # 若使用自定义端口 + server_name chat.zhenyangtang.com.cn; + + root D:/web/chat/backend/public; + index index.html index.php; + + client_max_body_size 100m; + + # ===== 1. API 必须优先走 PHP(不要走 SPA 的 index.html)===== + location ^~ /api { + rewrite ^ /index.php?s=$uri last; + } + + # ===== 2. PHP 处理 ===== + location ~ \.php$ { + fastcgi_pass 127.0.0.1:9000; # phpstudy 可能是 9000 或 9001,按实际修改 + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + + # ===== 3. 管理后台 SPA ===== + location ^~ /admin/ { + try_files $uri $uri/ /admin/index.html; + } + location = /admin { + return 301 /admin/; + } + + # ===== 4. 会员端 SPA ===== + location / { + try_files $uri $uri/ /index.html; + } + + # ===== 5. 静态资源缓存 ===== + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ { + expires 7d; + access_log off; + } +} diff --git a/deploy/phpstudy.md b/deploy/phpstudy.md new file mode 100644 index 0000000..c375ab8 --- /dev/null +++ b/deploy/phpstudy.md @@ -0,0 +1,107 @@ +# phpstudy 部署说明 + +## 1. 网站根目录 + +必须指向: + +``` +D:\web\chat\backend\public +``` + +**不能**指到 `backend/` 或项目根目录。 + +## 2. 编译前端 + +```powershell +cd D:\web\chat +npm run build +``` + +## 3. 伪静态 / 重写规则 + +### 若使用 Apache(phpstudy 默认) + +项目已自带 `backend/public/.htaccess`,确保 phpstudy 中: + +- 网站 → 设置 → **Apache** → 开启 `mod_rewrite` +- 允许 `.htaccess` 覆盖(AllowOverride All) + +### 若使用 Nginx + +phpstudy → 网站 → 设置 → **配置文件**,参考 `deploy/nginx.conf.example`。 + +**关键配置**(缺少会导致登录 404): + +```nginx +location ^~ /api { + rewrite ^ /index.php?s=$uri last; +} + +location ~ \.php$ { + fastcgi_pass 127.0.0.1:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; +} +``` + +注意:`location /` 的 `try_files ... /index.html` 不能拦截 `/api`,所以 `/api` 必须写在前面并使用 `^~` 前缀匹配。 + +## 4. 验证 API 是否正常 + +浏览器或 curl 测试: + +``` +POST http://你的域名/api/auth/login +Content-Type: application/json + +{"account":"admin","password":"admin123"} +``` + +应返回 JSON(`code: 0` 表示成功),**不应**是 nginx 404 页面。 + +## 5. 访问地址 + +| 功能 | 地址 | +|------|------| +| 会员端 | `http://域名/` | +| 管理后台 | `http://域名/admin/` | +| API | `http://域名/api/...` | + +## 6. 常见问题 + +| 现象 | 原因 | 处理 | +|------|------|------| +| 打开首页是 ThinkPHP 欢迎页 | 默认走了 index.php | 设置 `index index.html index.php`;勿用 ThinkPHP 全站伪静态;已内置兜底会输出 Vue 页面 | +| 登录 404 nginx | `/api` 未转发到 index.php | 按上文添加 Nginx/Apache 重写 | +| 页面空白 | 根目录指错或未编译 | 改为 `backend/public` 并执行 `npm run build` | +| 管理后台 404 | 未编译或未部署 admin | 执行 `npm run build` | +| 上传失败 | PHP 限制 / 目录权限 | php.ini 调大 upload_max_filesize;`chmod -R 775 backend/uploads` | + +### Linux 上传图片 500 错误 + +在服务器上执行: + +```bash +# 1. 创建并授权 uploads 目录(PHP 运行用户通常是 www-data 或 nginx) +mkdir -p /path/to/chat/backend/uploads +chmod -R 775 /path/to/chat/backend/uploads +chown -R www-data:www-data /path/to/chat/backend/uploads + +# 2. 确认 PHP 扩展已安装 +php -m | grep fileinfo + +# 3. 确认 php.ini 上传限制 +php -i | grep -E 'upload_max_filesize|post_max_size' +``` + +常见原因: +- `uploads/` 目录不存在或 PHP 进程无写权限 +- Linux 上 MIME 识别为 `application/octet-stream`(代码已做扩展名兜底) +- 未安装 `fileinfo` 扩展 + +### phpstudy 伪静态注意 + +**不要**选用「ThinkPHP」默认模板(会把所有请求转发到 index.php)。 + +请使用 `backend/public/nginx.htaccess` 中的规则,或完整配置见 `deploy/nginx.conf.example`。 diff --git a/frontend-admin/.env.development b/frontend-admin/.env.development new file mode 100644 index 0000000..0101d83 --- /dev/null +++ b/frontend-admin/.env.development @@ -0,0 +1,2 @@ +VITE_API_PROXY_TARGET=http://127.0.0.1:8080 +VITE_MEMBER_URL=http://localhost:5173 diff --git a/frontend-admin/.env.production b/frontend-admin/.env.production new file mode 100644 index 0000000..422a164 --- /dev/null +++ b/frontend-admin/.env.production @@ -0,0 +1,2 @@ +# 生产环境:会员端入口(同域根路径) +VITE_MEMBER_URL=/ diff --git a/frontend-admin/.gitignore b/frontend-admin/.gitignore new file mode 100644 index 0000000..f99f737 --- /dev/null +++ b/frontend-admin/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +dist/ +.DS_Store +*.local diff --git a/frontend-admin/index.html b/frontend-admin/index.html new file mode 100644 index 0000000..20fc575 --- /dev/null +++ b/frontend-admin/index.html @@ -0,0 +1,13 @@ + + +
+ + +选择左侧会话,查看用户与 AI 的完整对话
+← 请从左侧选择一条会话
+系统运行统计数据
+维护组织部门层级,上级部门可查看下级部门员工聊天记录
+| 部门名称 | +上级部门 | +排序 | +操作 | +
|---|---|---|---|
| + {{ dept.label || dept.name }} + | +{{ parentName(dept.parent_id) }} | +{{ dept.sort_order ?? 0 }} | ++ + + + | +
暂无部门
+请使用管理员账户登录
+配置会员权限与使用限制,支持新增、编辑、删除
+对接 OpenAI 格式 API 接口
+| 名称 | +接口类型 | +Model ID | +API 地址 | +Max Tokens | +默认 | +上下文 | +图片 | +状态 | +操作 | +
|---|---|---|---|---|---|---|---|---|---|
| {{ m.name }} | ++ + {{ m.provider === 'dify' ? 'Dify' : 'OpenAI 兼容' }} + + | +{{ m.model_id || '-' }} |
+ {{ m.api_base_url }} | +{{ m.provider === 'dify' ? '-' : m.max_tokens }} | +{{ m.is_default ? '✓' : '-' }} | ++ + {{ m.support_context ? '支持' : '不支持' }} + + | ++ + {{ m.support_image ? '支持' : '不支持' }} + + | ++ + {{ m.enabled ? '启用' : '禁用' }} + + | ++ + + + | +
维护目录、菜单、按钮节点,角色勾选后即可生效
+| 名称 | +类型 | +标识 | +路径 / 图标 | +系统 | +操作 | +
|---|---|---|---|---|---|
| + {{ row.name }} + | ++ {{ typeLabel(row.type) }} + | +{{ row.code }} |
+ + {{ row.path }} + {{ row.icon }} + - + | +{{ row.is_system ? '是' : '否' }} | ++ + + + | +
暂无权限节点,请先执行数据库迁移
+配置目录权限、菜单权限与按钮权限
+| 名称 | +标识 | +权限摘要 | +操作 | +
|---|---|---|---|
| {{ role.name }} | +{{ role.slug }} |
+ + + | ++ + + | +
控制前端功能开关与站点配置
+关闭后,会员端对应功能将不可用
+保存成功
+管理注册用户、密码、角色与会员套餐
+| ID | +用户名 | +邮箱 | +昵称 | +角色 | +部门 | +会员等级 | +状态 | +最后登录 | +注册时间 | +操作 | +
|---|---|---|---|---|---|---|---|---|---|---|
| {{ u.id }} | +{{ u.username }} | +{{ u.email }} | +{{ u.nickname || '-' }} | ++ + {{ u.role_name || roleLabel(u.role) }} + + | +{{ u.department_name || '-' }} | +{{ u.membership_name || '-' }} | ++ + {{ u.status === 'active' ? '正常' : '禁用' }} + + | +{{ formatDate(u.last_login_at) }} | +{{ formatDate(u.created_at) }} | ++ + + | +
暂无用户
+ +正在上传 {{ uploadingFiles.length }} 个文件…
+当前模型不支持图片识别,已隐藏图片上传
+AI 可能会犯错,请核实重要信息
+登录您的账户
+创建新账户
+