Explorar o código

feat: 添加课程管理系统相关文件和配置

zhanghaijun hai 11 meses
pai
achega
0cf4594e6e

develop/nginx/html/403.html → develop/course/403.html


develop/nginx/html/404.html → develop/course/404.html


develop/nginx/html/50x.html → develop/course/50x.html


develop/nginx/html/index.html → develop/course/index.html


develop/course/device/device.json → develop/course/json/device/device.json


develop/course/device/menus.json → develop/course/json/device/menus.json


develop/course/dict.json → develop/course/json/dict.json


develop/lua/course_device_status.lua → develop/course/lua/course_device_status.lua


+ 26 - 3
develop/lua/course_query.lua

@@ -1,6 +1,13 @@
 -- =========================================
 -- json查询接口
 -- =========================================
+-- 仅允许 GET 请求
+if ngx.req.get_method() ~= "GET" then
+    ngx.status = ngx.HTTP_NOT_ALLOWED
+    ngx.header["Content-Type"] = "application/json"
+    ngx.say('{"error":"Method not allowed, only GET is supported."}')
+    return ngx.exit(ngx.HTTP_NOT_ALLOWED)
+end
 
 local cjson = require "cjson.safe"
 
@@ -8,8 +15,24 @@ ngx.header.content_type = "application/json; charset=utf-8"
 
 -- 获取请求路径
 local uri = ngx.var.uri
-local prefix = "/api/json/"
-local relative_path = uri:sub(#prefix + 1)
+-- 多个前缀匹配
+local prefixes = {
+    "/api/json/",
+    "/api/device/json/"
+}
+local matched_prefix = nil
+for _, prefix in ipairs(prefixes) do
+    if uri:find(prefix) == 1 then
+        matched_prefix = prefix
+        break
+    end
+end
+if not matched_prefix then
+    ngx.status = 404
+    ngx.say(cjson.encode({ code = 404, msg = "未找到匹配的前缀: " .. uri }))
+    return
+end
+local relative_path = uri:sub(#matched_prefix + 1)
 
 -- 默认 all.json
 if relative_path == "" then
@@ -18,7 +41,7 @@ elseif not relative_path:match("%.json$") then
     relative_path = relative_path .. ".json"
 end
 
-local filepath = "/opt/server_json/" .. relative_path
+local filepath = "/opt/course/json/" .. relative_path
 
 -- 打开文件
 local file, err = io.open(filepath, "r")

+ 2 - 2
develop/lua/course_upload.lua

@@ -6,7 +6,7 @@ local cjson = require "cjson.safe"
 
 ngx.header.content_type = "application/json; charset=utf-8"
 
-local upload_dir = "/opt/oss/upload/"
+local upload_dir = "/opt/course/oss/"
 local max_size = 20 * 1024 * 1024  -- 20MB
 
 -- 工具函数
@@ -92,7 +92,7 @@ ngx.say(cjson.encode({
     msg = "上传成功",
     data = {
         filename = filename,
-        url = "/oss/upload/" .. filename,
+        url = "/oss/" .. filename,
         size = filesize
     }
 }))

+ 3 - 81
develop/nginx/443.conf

@@ -35,15 +35,6 @@ server {
     location = / {
         rewrite ^/ /course break;
     }
-    # lua 文件上传接口
-    location = /api/upload {
-        content_by_lua_file /usr/local/openresty/lua/file_upload.lua;
-    }
-    # lua 读取json文件
-    location /api/json/ {
-        content_by_lua_file /usr/local/openresty/lua/query_json.lua;
-    }
-
     #-------------------------------------------------
     # 前端应用
     #-------------------------------------------------
@@ -63,90 +54,21 @@ server {
         add_header Cache-Control "public, max-age=2592000, immutable";
     }
 
-    #-------------------------------------------------
-    # OSS 静态目录(带目录索引)
-    #-------------------------------------------------
-    location ^~ /oss/ {
-        alias /opt/oss/;
-        index _;                       # 去掉默认的界面
-        autoindex on;                  # 开启目录索引
-        autoindex_exact_size off;      # 文件大小人性化显示
-        autoindex_localtime on;        # 显示本地时间
-        charset utf-8;
-        expires 30d;
-        add_header Cache-Control "public, max-age=2592000, immutable";
-        # 如果不做这个配置,点击目录下的txt文件,大部分浏览器默认是直接浏览的。这里通过添加响应头来控制。
-        if ($request_filename ~* ^.*?\.(html|txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx|conf)$){
-            add_header Content-Disposition 'attachment;';
-        }
-    }
-
     #-------------------------------------------------
     # 课程管理
     #-------------------------------------------------
     location ^~ /course/ {
-        alias /opt/course/;
-        index index.html;
-
-         # 安全头部配置
-        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
-        add_header X-Content-Type-Options nosniff;
-        add_header X-XSS-Protection "1; mode=block";
-        add_header Referrer-Policy "same-origin";
-
-        add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), interest-cohort=()";
-        add_header Content-Security-Policy "default-src 'self'; worker-src 'self' blob:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https:; style-src 'self' 'unsafe-inline' https:; img-src 'self' data: https:; connect-src 'self' https:; font-src 'self' data: https:; frame-ancestors 'self'";
-
-        try_files $uri $uri/ /course/index.html;
-    }
-    location = /course/api/device/status {
+        default_type application/json;
 
-        # 允许所有域名跨域
-        add_header 'Access-Control-Allow-Origin' '*';
+       add_header 'Access-Control-Allow-Origin' '*';
         add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
         add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
         add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
 
-        default_type application/json;
-        content_by_lua_file /usr/local/openresty/lua/course_device_status.lua;
-    }
-    location ^~ /course/api/ {
-        default_type application/json;
-
-        add_header 'Access-Control-Allow-Origin' '*' always;
-        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
-        add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, X-Requested-With' always;
-        add_header 'Access-Control-Allow-Credentials' 'true' always;
-
         # 移除 rewrite,改用 proxy_pass 直接处理
-        proxy_pass http://124.222.28.5:7213/;
-
-        proxy_set_header Host m1.apifoxmock.com;
-        proxy_set_header X-Real-IP $remote_addr;
-        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-        proxy_set_header X-Forwarded-Proto $scheme;
-
-        # 处理代理失败的情况(如404)
-        proxy_intercept_errors on;
-        error_page 404 = @course_api_fallback;
+        proxy_pass http://127.0.0.1:8082/;
     }
 
-    location @course_api_fallback {
-        default_type application/json;
-        content_by_lua_block {
-            local uri = ngx.var.uri
-
-            if uri:find("^/course/api/system/dict") then
-                -- 字典相关接口
-                local dict = require "course_dict"
-                dict.handle(uri)
-            else
-                -- 其他接口走 mock
-                local mock_router = require "course_mock"
-                mock_router("/course/api")
-            end
-        }
-    }
     #-------------------------------------------------
     # 健康检查
     #-------------------------------------------------

+ 93 - 0
develop/nginx/course.8082.conf

@@ -0,0 +1,93 @@
+server {
+    listen 8082;
+    server_name _;
+
+    # 安全 Header
+    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
+    add_header X-Frame-Options SAMEORIGIN;
+    add_header X-Content-Type-Options nosniff;
+    add_header X-XSS-Protection "1; mode=block";
+    add_header Content-Security-Policy "default-src 'self' data: blob: https:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https:; style-src 'self' 'unsafe-inline' https:; img-src 'self' data: https:; font-src 'self' data: https:;" always;
+
+    root /opt/course;
+    try_files $uri $uri/ /index.html;
+
+    #-------------------------------------------------
+    # 前端应用
+    #-------------------------------------------------
+    location = / {
+        rewrite ^/ /course break;
+    }
+    location / {
+        index index.html;
+        try_files $uri $uri/ /index.html;
+        expires 7d;
+        add_header Cache-Control "public, max-age=604800, immutable";
+    }
+    #-------------------------------------------------
+    # OSS 静态目录(带目录索引)
+    #-------------------------------------------------
+    location ^~ /oss/ {
+        alias /opt/course/oss/;
+        index _;                       # 去掉默认的界面
+        autoindex on;                  # 开启目录索引
+        autoindex_exact_size off;      # 文件大小人性化显示
+        autoindex_localtime on;        # 显示本地时间
+        charset utf-8;
+        expires 30d;
+        add_header Cache-Control "public, max-age=2592000, immutable";
+        # 如果不做这个配置,点击目录下的txt文件,大部分浏览器默认是直接浏览的。这里通过添加响应头来控制。
+        if ($request_filename ~* ^.*?\.(html|txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx|conf)$){
+            add_header Content-Disposition 'attachment;';
+        }
+    }
+    #-------------------------------------------------
+    # lua后端接口
+    #-------------------------------------------------
+    # lua 文件上传接口
+    location = /api/upload {
+        content_by_lua_file /opt/course/lua/course_upload.lua;
+    }
+    # lua 读取json文件
+    location ^~ /api/json/ {
+        content_by_lua_file /opt/course/lua/course_query.lua;
+    }
+    location = /api/device/status {
+        # 允许所有域名跨域
+        add_header 'Access-Control-Allow-Origin' '*';
+        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
+        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
+        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
+
+        default_type application/json;
+        content_by_lua_file /opt/course/lua/course_device_status.lua;
+    }
+    #-------------------------------------------------
+    # 后端接口代理
+    #-------------------------------------------------
+    location ^~ /api/ {
+        default_type application/json;
+
+        add_header 'Access-Control-Allow-Origin' '*' always;
+        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
+        add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, X-Requested-With' always;
+        add_header 'Access-Control-Allow-Credentials' 'true' always;
+
+        # 移除 rewrite,改用 proxy_pass 直接处理
+        proxy_pass http://124.222.28.5:7213/;
+
+        proxy_set_header Host m1.apifoxmock.com;
+        proxy_set_header X-Real-IP $remote_addr;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        proxy_set_header X-Forwarded-Proto $scheme;
+
+        # 处理代理失败的情况(如404)
+        proxy_intercept_errors on;
+        error_page 404 = @course_api_fallback;
+    }
+
+    location @course_api_fallback {
+        default_type application/json;
+        content_by_lua_file /opt/course/lua/course_query.lua;
+    }
+}

+ 0 - 0
src/views/train/evaluation/list-operation.vue


+ 0 - 0
src/views/train/evaluation/list-referee.vue


+ 12 - 0
src/views/train/fault/index.vue

@@ -19,6 +19,7 @@
   import { useDialog } from '@/components/dialog'
   import Meta2dView from '@/components/business/meta2d/Meta2dView.vue'
   import ArtTable from '@/components/core/tables/art-table/index.vue'
+  import request from '@/api'
   defineOptions({ name: 'Device' })
 
   import data from './devices.json'
@@ -53,6 +54,17 @@
     { name: '设备7', type: '类型7', status: '状态7', time: '2023-01-07 00:00:00' },
     { name: '设备8', type: '类型8', status: '状态8', time: '2023-01-08 00:00:00' }
   ])
+
+  onMounted(() => {
+    nextTick(() => {
+      request.get('/course/device/device').then((res) => {
+        console.log(res)
+      })
+      request.get('/course/device/menus').then((res) => {
+        console.log('menu:', res)
+      })
+    })
+  })
 </script>
 
 <style lang="scss" scoped></style>