From 0529c2747a6cb074db497889dfdbca99d5898eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BB=A7=E9=A3=8E?= <1914007838@qq.com> Date: Tue, 25 Jun 2024 10:16:11 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[fix]=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/.gitignore | 3 ++- web/src/utils/upgrade.ts | 13 +++++++------ web/vite.config.ts | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/web/.gitignore b/web/.gitignore index 455b61368..8cef91868 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -21,4 +21,5 @@ pnpm-debug.log* *.njsproj *.sln *.sw? -public/version +# 构建版本文件,无需上传git +public/version-build diff --git a/web/src/utils/upgrade.ts b/web/src/utils/upgrade.ts index 6ca9e6796..a571863db 100644 --- a/web/src/utils/upgrade.ts +++ b/web/src/utils/upgrade.ts @@ -5,8 +5,9 @@ import {ElNotification} from "element-plus"; import fs from "fs"; // 是否显示升级提示信息框 -export const IS_SHOW_UPGRADE_SESSION_KEY = 'isShowUpgrade'; -const versionKey = 'DVADMIN3_VERSION' +const IS_SHOW_UPGRADE_SESSION_KEY = 'isShowUpgrade'; +const VERSION_KEY = 'DVADMIN3_VERSION' +const VERSION_FILE_NAME = 'version-build' export function showUpgrade () { const isShowUpgrade = Session.get(IS_SHOW_UPGRADE_SESSION_KEY) ?? false @@ -28,13 +29,13 @@ export async function checkVersion(){ return } // 获取线上版本号 t为时间戳,防止缓存 - await axios.get(`/version?t=${new Date().getTime()}`).then(res => { + await axios.get(`/${VERSION_FILE_NAME}?t=${new Date().getTime()}`).then(res => { const {status, data} = res || {} if (status === 200) { // 获取当前版本号 - const localVersion = Local.get(versionKey) + const localVersion = Local.get(VERSION_KEY) // 将当前版本号持久缓存至本地 - Local.set(versionKey, data) + Local.set(VERSION_KEY, data) // 当用户本地存在版本号并且和线上版本号不一致时,进行页面刷新操作 if (localVersion && localVersion !== data) { // 本地缓存版本号和线上版本号不一致,弹出升级提示框 @@ -50,5 +51,5 @@ export async function checkVersion(){ export function generateVersionFile (){ // 生成版本文件到public目录下version文件中 const version = `${process.env.npm_package_version}.${new Date().getTime()}`; - fs.writeFileSync('public/version', version); + fs.writeFileSync(`public/${VERSION_FILE_NAME}`, version); } diff --git a/web/vite.config.ts b/web/vite.config.ts index d91057f5f..ed6dec257 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -3,7 +3,7 @@ import { resolve } from 'path'; import { defineConfig, loadEnv, ConfigEnv } from 'vite'; import vueSetupExtend from 'vite-plugin-vue-setup-extend'; import vueJsx from '@vitejs/plugin-vue-jsx' -import { generateVersionFile } from "./src/utils/upgrade"; +import { generateVersionFile } from "/@/utils/upgrade"; const pathResolve = (dir: string) => { return resolve(__dirname, '.', dir); -- Gitee From 38ad2db7a75250550e9972c481eede14ef8d4ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BB=A7=E9=A3=8E?= <1914007838@qq.com> Date: Tue, 25 Jun 2024 10:17:36 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[feat]=E5=A2=9E=E5=8A=A0nginx=E4=B8=8D?= =?UTF-8?q?=E7=BC=93=E5=AD=98index.html=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E6=90=AD=E9=85=8D=E5=89=8D=E7=AB=AF=E7=89=88=E6=9C=AC=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8D=87=E7=BA=A7=E5=8A=9F=E8=83=BD=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=EF=BC=88=E4=B8=8D=E5=8A=A0=E6=AD=A4=E9=85=8D=E7=BD=AE=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E4=BC=9A=E5=AF=BC=E8=87=B4=E7=94=A8=E6=88=B7=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E5=90=8E=E8=BF=98=E6=98=AF=E6=97=A7=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker_env/nginx/my-80.conf | 4 ++++ docker_env/nginx/my.conf | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docker_env/nginx/my-80.conf b/docker_env/nginx/my-80.conf index e50bdc469..98d33bd98 100644 --- a/docker_env/nginx/my-80.conf +++ b/docker_env/nginx/my-80.conf @@ -7,6 +7,10 @@ server { index index.html index.htm; root /usr/share/nginx/html; try_files $uri $uri/ /index.html; + # 禁止缓存html文件,避免前端页面不及时更新,需要用户手动刷新的情况 + if ($request_uri ~* "^/$|^/index.html|^/index.htm") { + add_header Cache-Control "no-store"; + } } location ~ ^/api/ { diff --git a/docker_env/nginx/my.conf b/docker_env/nginx/my.conf index 178d9793e..dd6b3337a 100644 --- a/docker_env/nginx/my.conf +++ b/docker_env/nginx/my.conf @@ -11,6 +11,10 @@ server { real_ip_header X-Forwarded-For; root /usr/share/nginx/html; index index.html index.php index.htm; + # 禁止缓存html文件,避免前端页面不及时更新,需要用户手动刷新的情况 + if ($request_uri ~* "^/$|^/index.html|^/index.htm") { + add_header Cache-Control "no-store"; + } } location /api/ { -- Gitee From 5b60f60b7053b451b8c8152657de5d6394d53108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BB=A7=E9=A3=8E?= <1914007838@qq.com> Date: Tue, 25 Jun 2024 23:53:54 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[fix]=E6=9B=B4=E6=96=B0django-cors-headers?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E8=87=B34.4.0,=20=E7=8E=B0=E5=9C=A84.3.0?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=9A=84CorsMiddleware=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E4=BB=B6=E4=BC=9A=E5=AF=BC=E8=87=B4SessionMiddleware=E4=B8=AD?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=AE=BE=E7=BD=AEsession?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index 6309e7c11..2e7c6cb61 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,6 +1,6 @@ Django==4.2.7 django-comment-migrate==0.1.7 -django-cors-headers==4.3.0 +django-cors-headers==4.4.0 django-filter==23.3 django-ranged-response==0.2.0 djangorestframework==3.14.0 -- Gitee