From 3c62adab3c0c1547e07ba277a9a165256a8c3f48 Mon Sep 17 00:00:00 2001
From: hrz <1710360675@qq.com>
Date: Wed, 23 Apr 2025 23:23:25 +0800
Subject: [PATCH] =?UTF-8?q?fix:=E5=8F=96=E6=B6=88docker=E7=89=88=E4=B8=8A?=
=?UTF-8?q?=E4=BC=A0ota=E5=9B=BA=E4=BB=B6=E6=97=B6=E9=BB=98=E8=AE=A4?=
=?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F=E9=99=90=E5=88=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Dockerfile-web | 2 +-
README.md | 5 +-
docs/docker/nginx.conf | 67 ++++++++++++------
.../src/components/FirmwareDialog.vue | 68 ++++++++++++++++++-
4 files changed, 116 insertions(+), 26 deletions(-)
diff --git a/Dockerfile-web b/Dockerfile-web
index 0c4001f1..9e5da678 100644
--- a/Dockerfile-web
+++ b/Dockerfile-web
@@ -23,7 +23,7 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*
# 配置Nginx
-COPY docs/docker/nginx.conf /etc/nginx/conf.d/default.conf
+COPY docs/docker/nginx.conf /etc/nginx/nginx.conf
# 复制前端构建产物
COPY --from=web-builder /app/dist /usr/share/nginx/html
diff --git a/README.md b/README.md
index 2b6173c3..4f762d97 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
本项目为开源智能硬件项目
xiaozhi-esp32提供后端服务
-根据小智通信协议使用Python实现
+根据小智通信协议使用Python、Java、Vue实现
帮助您快速搭建小智服务器
@@ -15,7 +15,8 @@
· 简体中文
· 更新日志
· 部署文档
-· 反馈问题
+· 反馈问题
+· 常见问题
diff --git a/docs/docker/nginx.conf b/docs/docker/nginx.conf
index 6a746260..9b9c3889 100644
--- a/docs/docker/nginx.conf
+++ b/docs/docker/nginx.conf
@@ -1,26 +1,53 @@
-server {
- listen 8002;
- server_name localhost;
+user root;
+worker_processes 4;
- # 静态资源服务(Vue项目)
- location / {
- root /usr/share/nginx/html;
- try_files $uri $uri/ /index.html;
- }
+events {
+ worker_connections 1024;
+}
- # API反向代理(Java项目)
- location /xiaozhi/ {
- proxy_pass http://127.0.0.1:8003;
- proxy_set_header Host $host;
- proxy_cookie_path /api/ /;
- proxy_set_header Referer $http_referer;
- proxy_set_header Cookie $http_cookie;
+http {
+ include mime.types;
+ default_type application/octet-stream;
+ sendfile on;
+ keepalive_timeout 300;
+ client_header_timeout 180s;
+ client_body_timeout 180s;
+ client_max_body_size 1024M;
- proxy_connect_timeout 10;
- proxy_send_timeout 10;
- proxy_read_timeout 10;
+ gzip on;
+ gzip_buffers 32 4K;
+ gzip_comp_level 6;
+ gzip_min_length 100;
+ gzip_types application/javascript text/css text/xml image/jpeg image/gif image/png;
+ gzip_disable "MSIE [1-6]\.";
+ gzip_vary on;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ server {
+ # 无域名访问,就用localhost
+ server_name localhost;
+ # 80端口
+ listen 8002;
+
+ # 转发到编译后到web目录
+ location / {
+ root /usr/share/nginx/html;
+ try_files $uri $uri/ /index.html;
+ }
+
+ # 转发到manager-api
+ location /xiaozhi/ {
+ proxy_pass http://127.0.0.1:8003;
+ proxy_set_header Host $host;
+ proxy_cookie_path /manager/ /;
+ proxy_set_header Referer $http_referer;
+ proxy_set_header Cookie $http_cookie;
+
+ proxy_connect_timeout 10;
+ proxy_send_timeout 10;
+ proxy_read_timeout 10;
+
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ }
}
}
\ No newline at end of file
diff --git a/main/manager-web/src/components/FirmwareDialog.vue b/main/manager-web/src/components/FirmwareDialog.vue
index 9839f4a3..2cbf83a1 100644
--- a/main/manager-web/src/components/FirmwareDialog.vue
+++ b/main/manager-web/src/components/FirmwareDialog.vue
@@ -1,5 +1,5 @@
-
+
@@ -13,11 +13,14 @@
-
+
点击上传
只能上传固件文件(.bin/.apk),且不超过100MB
+
@@ -53,6 +56,9 @@ export default {
data() {
return {
firmwareTypes: FIRMWARE_TYPES,
+ uploadProgress: 0,
+ uploadStatus: '',
+ isUploading: false,
rules: {
firmwareName: [
{ required: true, message: '请输入固件名称(板子+版本号)', trigger: 'blur' }
@@ -108,16 +114,72 @@ export default {
},
handleUpload(options) {
const { file } = options
+ this.uploadProgress = 0
+ this.uploadStatus = ''
+ this.isUploading = true
+
+ // 使用setTimeout实现简单的0-50%过渡
+ const timer = setTimeout(() => {
+ if (this.uploadProgress < 50) { // 只有当进度小于50%时才设置
+ this.uploadProgress = 50
+ }
+ }, 1000)
+
Api.ota.uploadFirmware(file, (res) => {
+ clearTimeout(timer) // 清除定时器
res = res.data
if (res.code === 0) {
this.form.firmwarePath = res.data
this.form.size = file.size
+ this.uploadProgress = 100
+ this.uploadStatus = 'success'
this.$message.success('固件文件上传成功')
+ // 延迟2秒后隐藏进度条
+ setTimeout(() => {
+ this.isUploading = false
+ }, 2000)
} else {
+ this.uploadStatus = 'exception'
this.$message.error(res.msg || '文件上传失败')
+ this.isUploading = false
+ }
+ }, (progressEvent) => {
+ if (progressEvent.total) {
+ const progress = Math.round((progressEvent.loaded * 100) / progressEvent.total)
+ // 只有当进度大于50%时才更新
+ if (progress > 50) {
+ this.uploadProgress = progress
+ }
+ // 如果上传完成但还没收到成功响应,保持进度条显示
+ if (progress === 100) {
+ this.uploadStatus = ''
+ }
}
})
+ },
+ handleRemove() {
+ this.form.firmwarePath = ''
+ this.form.size = 0
+ this.uploadProgress = 0
+ this.uploadStatus = ''
+ this.isUploading = false
+ },
+ handleOpen() {
+ // 重置上传相关状态
+ this.uploadProgress = 0
+ this.uploadStatus = ''
+ this.isUploading = false
+ // 重置表单中的文件相关字段
+ if (!this.form.id) { // 只在新增时重置
+ this.form.firmwarePath = ''
+ this.form.size = 0
+ // 重置上传组件
+ this.$nextTick(() => {
+ if (this.$refs.upload) {
+ this.$refs.upload.clearFiles()
+ }
+ })
+ }
}
}
}