Merge branch 'master' of ssh://git.swordlost.top:222/SikongJueluo/FPGA_WebLab
This commit is contained in:
		@@ -9,7 +9,10 @@
 | 
			
		||||
      forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
 | 
			
		||||
        pkgs = import nixpkgs {
 | 
			
		||||
          inherit system;
 | 
			
		||||
          config.permittedInsecurePackages = ["dotnet-sdk-6.0.428"];
 | 
			
		||||
          config.permittedInsecurePackages = [
 | 
			
		||||
            "dotnet-sdk-6.0.428"
 | 
			
		||||
            "beekeeper-studio-5.2.9"
 | 
			
		||||
          ];
 | 
			
		||||
        };
 | 
			
		||||
      });
 | 
			
		||||
    in
 | 
			
		||||
@@ -21,7 +24,7 @@
 | 
			
		||||
            nodejs
 | 
			
		||||
            sqlite
 | 
			
		||||
            sqls
 | 
			
		||||
            sql-studio
 | 
			
		||||
            beekeeper-studio
 | 
			
		||||
            zlib
 | 
			
		||||
            bash
 | 
			
		||||
            # Backend
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										800
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										800
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@@ -18,12 +18,12 @@
 | 
			
		||||
        "axios": "^1.11.0",
 | 
			
		||||
        "echarts": "^5.6.0",
 | 
			
		||||
        "highlight.js": "^11.11.1",
 | 
			
		||||
        "konva": "^9.3.20",
 | 
			
		||||
        "lodash": "^4.17.21",
 | 
			
		||||
        "log-symbols": "^7.0.0",
 | 
			
		||||
        "lucide-vue-next": "^0.525.0",
 | 
			
		||||
        "marked": "^12.0.0",
 | 
			
		||||
        "mathjs": "^14.4.0",
 | 
			
		||||
        "md-editor-v3": "^5.8.4",
 | 
			
		||||
        "pinia": "^3.0.1",
 | 
			
		||||
        "reka-ui": "^2.3.1",
 | 
			
		||||
        "ts-log": "^2.2.7",
 | 
			
		||||
@@ -549,6 +549,390 @@
 | 
			
		||||
        "node": ">=6.9.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/autocomplete": {
 | 
			
		||||
      "version": "6.18.6",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/autocomplete/-/autocomplete-6.18.6.tgz",
 | 
			
		||||
      "integrity": "sha512-PHHBXFomUs5DF+9tCOM/UoW6XQ4R44lLNNhRaW9PKPTU0D7lIjRg3ElxaJnTwsl/oHiR93WSXDBrekhoUGCPtg==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@codemirror/view": "^6.17.0",
 | 
			
		||||
        "@lezer/common": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/commands": {
 | 
			
		||||
      "version": "6.8.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.8.1.tgz",
 | 
			
		||||
      "integrity": "sha512-KlGVYufHMQzxbdQONiLyGQDUW0itrLZwq3CcY7xpv9ZLRHqzkBSoteocBHtMCoY7/Ci4xhzSrToIeLg7FxHuaw==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@codemirror/state": "^6.4.0",
 | 
			
		||||
        "@codemirror/view": "^6.27.0",
 | 
			
		||||
        "@lezer/common": "^1.1.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-angular": {
 | 
			
		||||
      "version": "0.1.4",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-angular/-/lang-angular-0.1.4.tgz",
 | 
			
		||||
      "integrity": "sha512-oap+gsltb/fzdlTQWD6BFF4bSLKcDnlxDsLdePiJpCVNKWXSTAbiiQeYI3UmES+BLAdkmIC1WjyztC1pi/bX4g==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/lang-html": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-javascript": "^6.1.2",
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.3.3"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-cpp": {
 | 
			
		||||
      "version": "6.0.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-cpp/-/lang-cpp-6.0.3.tgz",
 | 
			
		||||
      "integrity": "sha512-URM26M3vunFFn9/sm6rzqrBzDgfWuDixp85uTY49wKudToc2jTHUrKIGGKs+QWND+YLofNNZpxcNGRynFJfvgA==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@lezer/cpp": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-css": {
 | 
			
		||||
      "version": "6.3.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-css/-/lang-css-6.3.1.tgz",
 | 
			
		||||
      "integrity": "sha512-kr5fwBGiGtmz6l0LSJIbno9QrifNMUusivHbnA1H6Dmqy4HZFte3UAICix1VuKo0lMPKQr2rqB+0BkKi/S3Ejg==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/autocomplete": "^6.0.0",
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.0.2",
 | 
			
		||||
        "@lezer/css": "^1.1.7"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-go": {
 | 
			
		||||
      "version": "6.0.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-go/-/lang-go-6.0.1.tgz",
 | 
			
		||||
      "integrity": "sha512-7fNvbyNylvqCphW9HD6WFnRpcDjr+KXX/FgqXy5H5ZS0eC5edDljukm/yNgYkwTsgp2busdod50AOTIy6Jikfg==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/autocomplete": "^6.0.0",
 | 
			
		||||
        "@codemirror/language": "^6.6.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.0.0",
 | 
			
		||||
        "@lezer/go": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-html": {
 | 
			
		||||
      "version": "6.4.9",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-html/-/lang-html-6.4.9.tgz",
 | 
			
		||||
      "integrity": "sha512-aQv37pIMSlueybId/2PVSP6NPnmurFDVmZwzc7jszd2KAF8qd4VBbvNYPXWQq90WIARjsdVkPbw29pszmHws3Q==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/autocomplete": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-css": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-javascript": "^6.0.0",
 | 
			
		||||
        "@codemirror/language": "^6.4.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@codemirror/view": "^6.17.0",
 | 
			
		||||
        "@lezer/common": "^1.0.0",
 | 
			
		||||
        "@lezer/css": "^1.1.0",
 | 
			
		||||
        "@lezer/html": "^1.3.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-java": {
 | 
			
		||||
      "version": "6.0.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-java/-/lang-java-6.0.2.tgz",
 | 
			
		||||
      "integrity": "sha512-m5Nt1mQ/cznJY7tMfQTJchmrjdjQ71IDs+55d1GAa8DGaB8JXWsVCkVT284C3RTASaY43YknrK2X3hPO/J3MOQ==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@lezer/java": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-javascript": {
 | 
			
		||||
      "version": "6.2.4",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-javascript/-/lang-javascript-6.2.4.tgz",
 | 
			
		||||
      "integrity": "sha512-0WVmhp1QOqZ4Rt6GlVGwKJN3KW7Xh4H2q8ZZNGZaP6lRdxXJzmjm4FqvmOojVj6khWJHIb9sp7U/72W7xQgqAA==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/autocomplete": "^6.0.0",
 | 
			
		||||
        "@codemirror/language": "^6.6.0",
 | 
			
		||||
        "@codemirror/lint": "^6.0.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@codemirror/view": "^6.17.0",
 | 
			
		||||
        "@lezer/common": "^1.0.0",
 | 
			
		||||
        "@lezer/javascript": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-json": {
 | 
			
		||||
      "version": "6.0.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-json/-/lang-json-6.0.2.tgz",
 | 
			
		||||
      "integrity": "sha512-x2OtO+AvwEHrEwR0FyyPtfDUiloG3rnVTSZV1W8UteaLL8/MajQd8DpvUb2YVzC+/T18aSDv0H9mu+xw0EStoQ==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@lezer/json": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-less": {
 | 
			
		||||
      "version": "6.0.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-less/-/lang-less-6.0.2.tgz",
 | 
			
		||||
      "integrity": "sha512-EYdQTG22V+KUUk8Qq582g7FMnCZeEHsyuOJisHRft/mQ+ZSZ2w51NupvDUHiqtsOy7It5cHLPGfHQLpMh9bqpQ==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/lang-css": "^6.2.0",
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-liquid": {
 | 
			
		||||
      "version": "6.2.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-liquid/-/lang-liquid-6.2.3.tgz",
 | 
			
		||||
      "integrity": "sha512-yeN+nMSrf/lNii3FJxVVEGQwFG0/2eDyH6gNOj+TGCa0hlNO4bhQnoO5ISnd7JOG+7zTEcI/GOoyraisFVY7jQ==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/autocomplete": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-html": "^6.0.0",
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@codemirror/view": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.0.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.3.1"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-markdown": {
 | 
			
		||||
      "version": "6.3.4",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-markdown/-/lang-markdown-6.3.4.tgz",
 | 
			
		||||
      "integrity": "sha512-fBm0BO03azXnTAsxhONDYHi/qWSI+uSEIpzKM7h/bkIc9fHnFp9y7KTMXKON0teNT97pFhc1a9DQTtWBYEZ7ug==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/autocomplete": "^6.7.1",
 | 
			
		||||
        "@codemirror/lang-html": "^6.0.0",
 | 
			
		||||
        "@codemirror/language": "^6.3.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@codemirror/view": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.2.1",
 | 
			
		||||
        "@lezer/markdown": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-php": {
 | 
			
		||||
      "version": "6.0.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-php/-/lang-php-6.0.2.tgz",
 | 
			
		||||
      "integrity": "sha512-ZKy2v1n8Fc8oEXj0Th0PUMXzQJ0AIR6TaZU+PbDHExFwdu+guzOA4jmCHS1Nz4vbFezwD7LyBdDnddSJeScMCA==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/lang-html": "^6.0.0",
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.0.0",
 | 
			
		||||
        "@lezer/php": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-python": {
 | 
			
		||||
      "version": "6.2.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-python/-/lang-python-6.2.1.tgz",
 | 
			
		||||
      "integrity": "sha512-IRjC8RUBhn9mGR9ywecNhB51yePWCGgvHfY1lWN/Mrp3cKuHr0isDKia+9HnvhiWNnMpbGhWrkhuWOc09exRyw==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/autocomplete": "^6.3.2",
 | 
			
		||||
        "@codemirror/language": "^6.8.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.2.1",
 | 
			
		||||
        "@lezer/python": "^1.1.4"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-rust": {
 | 
			
		||||
      "version": "6.0.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-rust/-/lang-rust-6.0.2.tgz",
 | 
			
		||||
      "integrity": "sha512-EZaGjCUegtiU7kSMvOfEZpaCReowEf3yNidYu7+vfuGTm9ow4mthAparY5hisJqOHmJowVH3Upu+eJlUji6qqA==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@lezer/rust": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-sass": {
 | 
			
		||||
      "version": "6.0.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-sass/-/lang-sass-6.0.2.tgz",
 | 
			
		||||
      "integrity": "sha512-l/bdzIABvnTo1nzdY6U+kPAC51czYQcOErfzQ9zSm9D8GmNPD0WTW8st/CJwBTPLO8jlrbyvlSEcN20dc4iL0Q==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/lang-css": "^6.2.0",
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.0.2",
 | 
			
		||||
        "@lezer/sass": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-sql": {
 | 
			
		||||
      "version": "6.9.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-sql/-/lang-sql-6.9.1.tgz",
 | 
			
		||||
      "integrity": "sha512-ecSk3gm/mlINcURMcvkCZmXgdzPSq8r/yfCtTB4vgqGGIbBC2IJIAy7GqYTy5pgBEooTVmHP2GZK6Z7h63CDGg==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/autocomplete": "^6.0.0",
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-vue": {
 | 
			
		||||
      "version": "0.1.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-vue/-/lang-vue-0.1.3.tgz",
 | 
			
		||||
      "integrity": "sha512-QSKdtYTDRhEHCfo5zOShzxCmqKJvgGrZwDQSdbvCRJ5pRLWBS7pD/8e/tH44aVQT6FKm0t6RVNoSUWHOI5vNug==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/lang-html": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-javascript": "^6.1.2",
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.3.1"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-wast": {
 | 
			
		||||
      "version": "6.0.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-wast/-/lang-wast-6.0.2.tgz",
 | 
			
		||||
      "integrity": "sha512-Imi2KTpVGm7TKuUkqyJ5NRmeFWF7aMpNiwHnLQe0x9kmrxElndyH0K6H/gXtWwY6UshMRAhpENsgfpSwsgmC6Q==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-xml": {
 | 
			
		||||
      "version": "6.1.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-xml/-/lang-xml-6.1.0.tgz",
 | 
			
		||||
      "integrity": "sha512-3z0blhicHLfwi2UgkZYRPioSgVTo9PV5GP5ducFH6FaHy0IAJRg+ixj5gTR1gnT/glAIC8xv4w2VL1LoZfs+Jg==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/autocomplete": "^6.0.0",
 | 
			
		||||
        "@codemirror/language": "^6.4.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@codemirror/view": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.0.0",
 | 
			
		||||
        "@lezer/xml": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lang-yaml": {
 | 
			
		||||
      "version": "6.1.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lang-yaml/-/lang-yaml-6.1.2.tgz",
 | 
			
		||||
      "integrity": "sha512-dxrfG8w5Ce/QbT7YID7mWZFKhdhsaTNOYjOkSIMt1qmC4VQnXSDSYVHHHn8k6kJUfIhtLo8t1JJgltlxWdsITw==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/autocomplete": "^6.0.0",
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.2.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0",
 | 
			
		||||
        "@lezer/yaml": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/language": {
 | 
			
		||||
      "version": "6.11.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.11.2.tgz",
 | 
			
		||||
      "integrity": "sha512-p44TsNArL4IVXDTbapUmEkAlvWs2CFQbcfc0ymDsis1kH2wh0gcY96AS29c/vp2d0y2Tquk1EDSaawpzilUiAw==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@codemirror/view": "^6.23.0",
 | 
			
		||||
        "@lezer/common": "^1.1.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0",
 | 
			
		||||
        "style-mod": "^4.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/language-data": {
 | 
			
		||||
      "version": "6.5.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/language-data/-/language-data-6.5.1.tgz",
 | 
			
		||||
      "integrity": "sha512-0sWxeUSNlBr6OmkqybUTImADFUP0M3P0IiSde4nc24bz/6jIYzqYSgkOSLS+CBIoW1vU8Q9KUWXscBXeoMVC9w==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/lang-angular": "^0.1.0",
 | 
			
		||||
        "@codemirror/lang-cpp": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-css": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-go": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-html": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-java": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-javascript": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-json": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-less": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-liquid": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-markdown": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-php": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-python": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-rust": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-sass": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-sql": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-vue": "^0.1.1",
 | 
			
		||||
        "@codemirror/lang-wast": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-xml": "^6.0.0",
 | 
			
		||||
        "@codemirror/lang-yaml": "^6.0.0",
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@codemirror/legacy-modes": "^6.4.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/legacy-modes": {
 | 
			
		||||
      "version": "6.5.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/legacy-modes/-/legacy-modes-6.5.1.tgz",
 | 
			
		||||
      "integrity": "sha512-DJYQQ00N1/KdESpZV7jg9hafof/iBNp9h7TYo1SLMk86TWl9uDsVdho2dzd81K+v4retmK6mdC7WpuOQDytQqw==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/language": "^6.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/lint": {
 | 
			
		||||
      "version": "6.8.5",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.8.5.tgz",
 | 
			
		||||
      "integrity": "sha512-s3n3KisH7dx3vsoeGMxsbRAgKe4O1vbrnKBClm99PU0fWxmxsx5rR2PfqQgIt+2MMJBHbiJ5rfIdLYfB9NNvsA==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@codemirror/view": "^6.35.0",
 | 
			
		||||
        "crelt": "^1.0.5"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/search": {
 | 
			
		||||
      "version": "6.5.11",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.5.11.tgz",
 | 
			
		||||
      "integrity": "sha512-KmWepDE6jUdL6n8cAAqIpRmLPBZ5ZKnicE8oGU/s3QrAVID+0VhLFrzUucVKHG5035/BSykhExDL/Xm7dHthiA==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@codemirror/view": "^6.0.0",
 | 
			
		||||
        "crelt": "^1.0.5"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/state": {
 | 
			
		||||
      "version": "6.5.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.5.2.tgz",
 | 
			
		||||
      "integrity": "sha512-FVqsPqtPWKVVL3dPSxy8wEF/ymIEuVzF1PK3VbUgrxXpJUSHQWWZz4JMToquRxnkw+36LTamCZG2iua2Ptq0fA==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@marijn/find-cluster-break": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@codemirror/view": {
 | 
			
		||||
      "version": "6.38.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.38.1.tgz",
 | 
			
		||||
      "integrity": "sha512-RmTOkE7hRU3OVREqFVITWHz6ocgBjv08GoePscAakgVQfciA3SGCEk7mb9IzwW61cKKmlTpHXG6DUE5Ubx+MGQ==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/state": "^6.5.0",
 | 
			
		||||
        "crelt": "^1.0.6",
 | 
			
		||||
        "style-mod": "^4.1.0",
 | 
			
		||||
        "w3c-keyname": "^2.2.4"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@cspotcode/source-map-support": {
 | 
			
		||||
      "version": "0.8.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz",
 | 
			
		||||
@@ -1130,6 +1514,189 @@
 | 
			
		||||
        "@jridgewell/sourcemap-codec": "^1.4.14"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/common": {
 | 
			
		||||
      "version": "1.2.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.2.3.tgz",
 | 
			
		||||
      "integrity": "sha512-w7ojc8ejBqr2REPsWxJjrMFsA/ysDCFICn8zEOR9mrqzOu2amhITYuLD8ag6XZf0CFXDrhKqw7+tW8cX66NaDA==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/cpp": {
 | 
			
		||||
      "version": "1.1.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/cpp/-/cpp-1.1.3.tgz",
 | 
			
		||||
      "integrity": "sha512-ykYvuFQKGsRi6IcE+/hCSGUhb/I4WPjd3ELhEblm2wS2cOznDFzO+ubK2c+ioysOnlZ3EduV+MVQFCPzAIoY3w==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/css": {
 | 
			
		||||
      "version": "1.3.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/css/-/css-1.3.0.tgz",
 | 
			
		||||
      "integrity": "sha512-pBL7hup88KbI7hXnZV3PQsn43DHy6TWyzuyk2AO9UyoXcDltvIdqWKE1dLL/45JVZ+YZkHe1WVHqO6wugZZWcw==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.3.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/go": {
 | 
			
		||||
      "version": "1.0.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/go/-/go-1.0.1.tgz",
 | 
			
		||||
      "integrity": "sha512-xToRsYxwsgJNHTgNdStpcvmbVuKxTapV0dM0wey1geMMRc9aggoVyKgzYp41D2/vVOx+Ii4hmE206kvxIXBVXQ==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.3.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/highlight": {
 | 
			
		||||
      "version": "1.2.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.2.1.tgz",
 | 
			
		||||
      "integrity": "sha512-Z5duk4RN/3zuVO7Jq0pGLJ3qynpxUVsh7IbUbGj88+uV2ApSAn6kWg2au3iJb+0Zi7kKtqffIESgNcRXWZWmSA==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/html": {
 | 
			
		||||
      "version": "1.3.10",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/html/-/html-1.3.10.tgz",
 | 
			
		||||
      "integrity": "sha512-dqpT8nISx/p9Do3AchvYGV3qYc4/rKr3IBZxlHmpIKam56P47RSHkSF5f13Vu9hebS1jM0HmtJIwLbWz1VIY6w==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/java": {
 | 
			
		||||
      "version": "1.1.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/java/-/java-1.1.3.tgz",
 | 
			
		||||
      "integrity": "sha512-yHquUfujwg6Yu4Fd1GNHCvidIvJwi/1Xu2DaKl/pfWIA2c1oXkVvawH3NyXhCaFx4OdlYBVX5wvz2f7Aoa/4Xw==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/javascript": {
 | 
			
		||||
      "version": "1.5.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.5.1.tgz",
 | 
			
		||||
      "integrity": "sha512-ATOImjeVJuvgm3JQ/bpo2Tmv55HSScE2MTPnKRMRIPx2cLhHGyX2VnqpHhtIV1tVzIjZDbcWQm+NCTF40ggZVw==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.1.3",
 | 
			
		||||
        "@lezer/lr": "^1.3.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/json": {
 | 
			
		||||
      "version": "1.0.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/json/-/json-1.0.3.tgz",
 | 
			
		||||
      "integrity": "sha512-BP9KzdF9Y35PDpv04r0VeSTKDeox5vVr3efE7eBbx3r4s3oNLfunchejZhjArmeieBH+nVOpgIiBJpEAv8ilqQ==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/lr": {
 | 
			
		||||
      "version": "1.4.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.2.tgz",
 | 
			
		||||
      "integrity": "sha512-pu0K1jCIdnQ12aWNaAVU5bzi7Bd1w54J3ECgANPmYLtQKP0HBj2cE/5coBD66MT10xbtIuUr7tg0Shbsvk0mDA==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/markdown": {
 | 
			
		||||
      "version": "1.4.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/markdown/-/markdown-1.4.3.tgz",
 | 
			
		||||
      "integrity": "sha512-kfw+2uMrQ/wy/+ONfrH83OkdFNM0ye5Xq96cLlaCy7h5UT9FO54DU4oRoIc0CSBh5NWmWuiIJA7NGLMJbQ+Oxg==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.0.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/php": {
 | 
			
		||||
      "version": "1.0.4",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/php/-/php-1.0.4.tgz",
 | 
			
		||||
      "integrity": "sha512-D2dJ0t8Z28/G1guztRczMFvPDUqzeMLSQbdWQmaiHV7urc8NlEOnjYk9UrZ531OcLiRxD4Ihcbv7AsDpNKDRaQ==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.1.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/python": {
 | 
			
		||||
      "version": "1.1.18",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/python/-/python-1.1.18.tgz",
 | 
			
		||||
      "integrity": "sha512-31FiUrU7z9+d/ElGQLJFXl+dKOdx0jALlP3KEOsGTex8mvj+SoE1FgItcHWK/axkxCHGUSpqIHt6JAWfWu9Rhg==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/rust": {
 | 
			
		||||
      "version": "1.0.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/rust/-/rust-1.0.2.tgz",
 | 
			
		||||
      "integrity": "sha512-Lz5sIPBdF2FUXcWeCu1//ojFAZqzTQNRga0aYv6dYXqJqPfMdCAI0NzajWUd4Xijj1IKJLtjoXRPMvTKWBcqKg==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/sass": {
 | 
			
		||||
      "version": "1.1.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/sass/-/sass-1.1.0.tgz",
 | 
			
		||||
      "integrity": "sha512-3mMGdCTUZ/84ArHOuXWQr37pnf7f+Nw9ycPUeKX+wu19b7pSMcZGLbaXwvD2APMBDOGxPmpK/O6S1v1EvLoqgQ==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/xml": {
 | 
			
		||||
      "version": "1.0.6",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/xml/-/xml-1.0.6.tgz",
 | 
			
		||||
      "integrity": "sha512-CdDwirL0OEaStFue/66ZmFSeppuL6Dwjlk8qk153mSQwiSH/Dlri4GNymrNWnUmPl2Um7QfV1FO9KFUyX3Twww==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@lezer/yaml": {
 | 
			
		||||
      "version": "1.0.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@lezer/yaml/-/yaml-1.0.3.tgz",
 | 
			
		||||
      "integrity": "sha512-GuBLekbw9jDBDhGur82nuwkxKQ+a3W5H0GfaAthDXcAu+XdpS43VlnxA9E9hllkpSP5ellRDKjLLj7Lu9Wr6xA==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@lezer/common": "^1.2.0",
 | 
			
		||||
        "@lezer/highlight": "^1.0.0",
 | 
			
		||||
        "@lezer/lr": "^1.4.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@marijn/find-cluster-break": {
 | 
			
		||||
      "version": "1.0.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.2.tgz",
 | 
			
		||||
      "integrity": "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@microsoft/signalr": {
 | 
			
		||||
      "version": "9.0.6",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@microsoft/signalr/-/signalr-9.0.6.tgz",
 | 
			
		||||
@@ -1889,12 +2456,34 @@
 | 
			
		||||
        "@types/sizzle": "*"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@types/linkify-it": {
 | 
			
		||||
      "version": "5.0.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz",
 | 
			
		||||
      "integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@types/lodash": {
 | 
			
		||||
      "version": "4.17.16",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.16.tgz",
 | 
			
		||||
      "integrity": "sha512-HX7Em5NYQAXKW+1T+FiuG27NGwzJfCX3s1GjOa7ujxZa52kjJLOr4FUxT+giF6Tgxv1e+/czV/iTtBw27WTU9g==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@types/markdown-it": {
 | 
			
		||||
      "version": "14.1.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.1.2.tgz",
 | 
			
		||||
      "integrity": "sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@types/linkify-it": "^5",
 | 
			
		||||
        "@types/mdurl": "^2"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@types/mdurl": {
 | 
			
		||||
      "version": "2.0.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz",
 | 
			
		||||
      "integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@types/node": {
 | 
			
		||||
      "version": "22.14.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@types/node/-/node-22.14.1.tgz",
 | 
			
		||||
@@ -1926,6 +2515,18 @@
 | 
			
		||||
      "integrity": "sha512-oIQLCGWtcFZy2JW77j9k8nHzAOpqMHLQejDA48XXMWH6tjCQHz5RCFz1bzsmROyL6PUm+LLnUiI4BCn221inxA==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@vavt/copy2clipboard": {
 | 
			
		||||
      "version": "1.0.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@vavt/copy2clipboard/-/copy2clipboard-1.0.3.tgz",
 | 
			
		||||
      "integrity": "sha512-HtG48r2FBYp9eRvGB3QGmtRBH1zzRRAVvFbGgFstOwz4/DDaNiX0uZc3YVKPydqgOav26pibr9MtoCaWxn7aeA==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@vavt/util": {
 | 
			
		||||
      "version": "2.1.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@vavt/util/-/util-2.1.0.tgz",
 | 
			
		||||
      "integrity": "sha512-YIfAvArSFVXmWvoF+DEGD0FhkhVNcCtVWWkfYtj76eSrwHh/wuEEFhiEubg1XLNM3tChO8FH8xJCT/hnizjgFQ==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/@vitejs/plugin-vue": {
 | 
			
		||||
      "version": "5.2.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-5.2.3.tgz",
 | 
			
		||||
@@ -2408,6 +3009,12 @@
 | 
			
		||||
      "dev": true,
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/argparse": {
 | 
			
		||||
      "version": "2.0.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
 | 
			
		||||
      "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
 | 
			
		||||
      "license": "Python-2.0"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/aria-hidden": {
 | 
			
		||||
      "version": "1.2.6",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/aria-hidden/-/aria-hidden-1.2.6.tgz",
 | 
			
		||||
@@ -2644,6 +3251,21 @@
 | 
			
		||||
        "fsevents": "~2.3.2"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/codemirror": {
 | 
			
		||||
      "version": "6.0.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-6.0.2.tgz",
 | 
			
		||||
      "integrity": "sha512-VhydHotNW5w1UGK0Qj96BwSk/Zqbp9WbnyK2W/eVMv4QyF41INRGpjUhFJY7/uDNuudSc33a/PKr4iDqRduvHw==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/autocomplete": "^6.0.0",
 | 
			
		||||
        "@codemirror/commands": "^6.0.0",
 | 
			
		||||
        "@codemirror/language": "^6.0.0",
 | 
			
		||||
        "@codemirror/lint": "^6.0.0",
 | 
			
		||||
        "@codemirror/search": "^6.0.0",
 | 
			
		||||
        "@codemirror/state": "^6.0.0",
 | 
			
		||||
        "@codemirror/view": "^6.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/combined-stream": {
 | 
			
		||||
      "version": "1.0.8",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
 | 
			
		||||
@@ -2656,6 +3278,12 @@
 | 
			
		||||
        "node": ">= 0.8"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/commander": {
 | 
			
		||||
      "version": "2.20.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
 | 
			
		||||
      "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/complex.js": {
 | 
			
		||||
      "version": "2.4.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/complex.js/-/complex.js-2.4.2.tgz",
 | 
			
		||||
@@ -2705,6 +3333,12 @@
 | 
			
		||||
      "dev": true,
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/crelt": {
 | 
			
		||||
      "version": "1.0.6",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.6.tgz",
 | 
			
		||||
      "integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/cross-spawn": {
 | 
			
		||||
      "version": "7.0.6",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
 | 
			
		||||
@@ -2743,6 +3377,12 @@
 | 
			
		||||
        "node": ">= 8"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/cssfilter": {
 | 
			
		||||
      "version": "0.0.10",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/cssfilter/-/cssfilter-0.0.10.tgz",
 | 
			
		||||
      "integrity": "sha512-FAaLDaplstoRsDR8XGYH51znUN0UY7nMc6Z9/fvE8EXGwvJE9hu7W2vHwx1+bd6gCYnln9nLbzxFTrcO9YQDZw==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/csstype": {
 | 
			
		||||
      "version": "3.1.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
 | 
			
		||||
@@ -3738,7 +4378,8 @@
 | 
			
		||||
          "url": "https://github.com/sponsors/lavrton"
 | 
			
		||||
        }
 | 
			
		||||
      ],
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "peer": true
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/lightningcss": {
 | 
			
		||||
      "version": "1.29.2",
 | 
			
		||||
@@ -3979,6 +4620,15 @@
 | 
			
		||||
        "url": "https://opencollective.com/parcel"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/linkify-it": {
 | 
			
		||||
      "version": "5.0.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz",
 | 
			
		||||
      "integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "uc.micro": "^2.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/local-pkg": {
 | 
			
		||||
      "version": "1.1.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-1.1.1.tgz",
 | 
			
		||||
@@ -4054,6 +4704,47 @@
 | 
			
		||||
      "dev": true,
 | 
			
		||||
      "license": "ISC"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/markdown-it": {
 | 
			
		||||
      "version": "14.1.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.0.tgz",
 | 
			
		||||
      "integrity": "sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "argparse": "^2.0.1",
 | 
			
		||||
        "entities": "^4.4.0",
 | 
			
		||||
        "linkify-it": "^5.0.0",
 | 
			
		||||
        "mdurl": "^2.0.0",
 | 
			
		||||
        "punycode.js": "^2.3.1",
 | 
			
		||||
        "uc.micro": "^2.1.0"
 | 
			
		||||
      },
 | 
			
		||||
      "bin": {
 | 
			
		||||
        "markdown-it": "bin/markdown-it.mjs"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/markdown-it-image-figures": {
 | 
			
		||||
      "version": "2.1.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/markdown-it-image-figures/-/markdown-it-image-figures-2.1.1.tgz",
 | 
			
		||||
      "integrity": "sha512-mwXSQ2nPeVUzCMIE3HlLvjRioopiqyJLNph0pyx38yf9mpqFDhNGnMpAXF9/A2Xv0oiF2cVyg9xwfF0HNAz05g==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "engines": {
 | 
			
		||||
        "node": ">=12.0.0"
 | 
			
		||||
      },
 | 
			
		||||
      "peerDependencies": {
 | 
			
		||||
        "markdown-it": "*"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/markdown-it-sub": {
 | 
			
		||||
      "version": "2.0.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/markdown-it-sub/-/markdown-it-sub-2.0.0.tgz",
 | 
			
		||||
      "integrity": "sha512-iCBKgwCkfQBRg2vApy9vx1C1Tu6D8XYo8NvevI3OlwzBRmiMtsJ2sXupBgEA7PPxiDwNni3qIUkhZ6j5wofDUA==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/markdown-it-sup": {
 | 
			
		||||
      "version": "2.0.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/markdown-it-sup/-/markdown-it-sup-2.0.0.tgz",
 | 
			
		||||
      "integrity": "sha512-5VgmdKlkBd8sgXuoDoxMpiU+BiEt3I49GItBzzw7Mxq9CxvnhE/k09HFli09zgfFDRixDQDfDxi0mgBCXtaTvA==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/marked": {
 | 
			
		||||
      "version": "12.0.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/marked/-/marked-12.0.2.tgz",
 | 
			
		||||
@@ -4111,6 +4802,68 @@
 | 
			
		||||
        "url": "https://github.com/sponsors/rawify"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/md-editor-v3": {
 | 
			
		||||
      "version": "5.8.4",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/md-editor-v3/-/md-editor-v3-5.8.4.tgz",
 | 
			
		||||
      "integrity": "sha512-z7OOvr+Zt86kf0v46L47OHENNzdYeG8tVnfBSQdei7efVs4MWtWJk4ofv1KGutsNUA9q12h9aDZzjELeS+qCog==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@codemirror/autocomplete": "^6.18.6",
 | 
			
		||||
        "@codemirror/commands": "^6.8.1",
 | 
			
		||||
        "@codemirror/lang-markdown": "^6.3.0",
 | 
			
		||||
        "@codemirror/language": "^6.11.0",
 | 
			
		||||
        "@codemirror/language-data": "^6.5.1",
 | 
			
		||||
        "@codemirror/search": "^6.5.11",
 | 
			
		||||
        "@codemirror/state": "^6.5.2",
 | 
			
		||||
        "@codemirror/view": "^6.36.8",
 | 
			
		||||
        "@lezer/highlight": "^1.2.1",
 | 
			
		||||
        "@types/markdown-it": "^14.0.1",
 | 
			
		||||
        "@vavt/copy2clipboard": "^1.0.1",
 | 
			
		||||
        "@vavt/util": "^2.1.0",
 | 
			
		||||
        "codemirror": "^6.0.1",
 | 
			
		||||
        "lru-cache": "^11.0.1",
 | 
			
		||||
        "lucide-vue-next": "^0.453.0",
 | 
			
		||||
        "markdown-it": "^14.0.0",
 | 
			
		||||
        "markdown-it-image-figures": "^2.1.1",
 | 
			
		||||
        "markdown-it-sub": "^2.0.0",
 | 
			
		||||
        "markdown-it-sup": "^2.0.0",
 | 
			
		||||
        "medium-zoom": "^1.1.0",
 | 
			
		||||
        "xss": "^1.0.15"
 | 
			
		||||
      },
 | 
			
		||||
      "peerDependencies": {
 | 
			
		||||
        "vue": "^3.5.3"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/md-editor-v3/node_modules/lru-cache": {
 | 
			
		||||
      "version": "11.1.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.1.0.tgz",
 | 
			
		||||
      "integrity": "sha512-QIXZUBJUx+2zHUdQujWejBkcD9+cs94tLn0+YL8UrCh+D5sCXZ4c7LaEH48pNwRY3MLDgqUFyhlCyjJPf1WP0A==",
 | 
			
		||||
      "license": "ISC",
 | 
			
		||||
      "engines": {
 | 
			
		||||
        "node": "20 || >=22"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/md-editor-v3/node_modules/lucide-vue-next": {
 | 
			
		||||
      "version": "0.453.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/lucide-vue-next/-/lucide-vue-next-0.453.0.tgz",
 | 
			
		||||
      "integrity": "sha512-5zmv83vxAs9SVoe22veDBi8Dw0Fh2F+oTngWgKnKOkrZVbZjceXLQ3tescV2boB0zlaf9R2Sd9RuUP2766xvsQ==",
 | 
			
		||||
      "license": "ISC",
 | 
			
		||||
      "peerDependencies": {
 | 
			
		||||
        "vue": ">=3.0.1"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/mdurl": {
 | 
			
		||||
      "version": "2.0.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz",
 | 
			
		||||
      "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/medium-zoom": {
 | 
			
		||||
      "version": "1.1.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/medium-zoom/-/medium-zoom-1.1.0.tgz",
 | 
			
		||||
      "integrity": "sha512-ewyDsp7k4InCUp3jRmwHBRFGyjBimKps/AJLjRSox+2q/2H4p/PNpQf+pwONWlJiOudkBXtbdmVbFjqyybfTmQ==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/memorystream": {
 | 
			
		||||
      "version": "0.3.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/memorystream/-/memorystream-0.3.1.tgz",
 | 
			
		||||
@@ -4595,6 +5348,15 @@
 | 
			
		||||
        "node": ">=6"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/punycode.js": {
 | 
			
		||||
      "version": "2.3.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz",
 | 
			
		||||
      "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "engines": {
 | 
			
		||||
        "node": ">=6"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/quansync": {
 | 
			
		||||
      "version": "0.2.10",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/quansync/-/quansync-0.2.10.tgz",
 | 
			
		||||
@@ -4895,6 +5657,12 @@
 | 
			
		||||
        "url": "https://github.com/sponsors/sindresorhus"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/style-mod": {
 | 
			
		||||
      "version": "4.1.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.2.tgz",
 | 
			
		||||
      "integrity": "sha512-wnD1HyVqpJUI2+eKZ+eo1UwghftP6yuFheBqqe+bWCotBjC2K1YnteJILRMs3SM4V/0dLEW1SC27MWP5y+mwmw==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/superjson": {
 | 
			
		||||
      "version": "2.2.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/superjson/-/superjson-2.2.2.tgz",
 | 
			
		||||
@@ -5105,6 +5873,12 @@
 | 
			
		||||
        "node": ">=14.17"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/uc.micro": {
 | 
			
		||||
      "version": "2.1.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz",
 | 
			
		||||
      "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/ufo": {
 | 
			
		||||
      "version": "1.6.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.6.1.tgz",
 | 
			
		||||
@@ -5560,6 +6334,12 @@
 | 
			
		||||
        "typescript": ">=5.0.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/w3c-keyname": {
 | 
			
		||||
      "version": "2.2.8",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz",
 | 
			
		||||
      "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==",
 | 
			
		||||
      "license": "MIT"
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/web-streams-polyfill": {
 | 
			
		||||
      "version": "3.3.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz",
 | 
			
		||||
@@ -5630,6 +6410,22 @@
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/xss": {
 | 
			
		||||
      "version": "1.0.15",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/xss/-/xss-1.0.15.tgz",
 | 
			
		||||
      "integrity": "sha512-FVdlVVC67WOIPvfOwhoMETV72f6GbW7aOabBC3WxN/oUdoEMDyLz4OgRv5/gck2ZeNqEQu+Tb0kloovXOfpYVg==",
 | 
			
		||||
      "license": "MIT",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "commander": "^2.20.3",
 | 
			
		||||
        "cssfilter": "0.0.10"
 | 
			
		||||
      },
 | 
			
		||||
      "bin": {
 | 
			
		||||
        "xss": "bin/xss"
 | 
			
		||||
      },
 | 
			
		||||
      "engines": {
 | 
			
		||||
        "node": ">= 0.10.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/yallist": {
 | 
			
		||||
      "version": "3.1.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
 | 
			
		||||
 
 | 
			
		||||
@@ -22,12 +22,12 @@
 | 
			
		||||
    "axios": "^1.11.0",
 | 
			
		||||
    "echarts": "^5.6.0",
 | 
			
		||||
    "highlight.js": "^11.11.1",
 | 
			
		||||
    "konva": "^9.3.20",
 | 
			
		||||
    "lodash": "^4.17.21",
 | 
			
		||||
    "log-symbols": "^7.0.0",
 | 
			
		||||
    "lucide-vue-next": "^0.525.0",
 | 
			
		||||
    "marked": "^12.0.0",
 | 
			
		||||
    "mathjs": "^14.4.0",
 | 
			
		||||
    "md-editor-v3": "^5.8.4",
 | 
			
		||||
    "pinia": "^3.0.1",
 | 
			
		||||
    "reka-ui": "^2.3.1",
 | 
			
		||||
    "ts-log": "^2.2.7",
 | 
			
		||||
 
 | 
			
		||||
@@ -304,7 +304,7 @@ async function generateSignalRClient(): Promise<void> {
 | 
			
		||||
  console.log("Generating SignalR TypeScript client...");
 | 
			
		||||
  try {
 | 
			
		||||
    const { stdout, stderr } = await execAsync(
 | 
			
		||||
      "dotnet tsrts --project ./server/server.csproj --output ./src/",
 | 
			
		||||
      "dotnet tsrts --project ./server/server.csproj --output ./src/utils/signalR",
 | 
			
		||||
    );
 | 
			
		||||
    if (stdout) console.log(stdout);
 | 
			
		||||
    if (stderr) console.error(stderr);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								server/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								server/.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,5 +1,6 @@
 | 
			
		||||
# Generate
 | 
			
		||||
obj
 | 
			
		||||
bin
 | 
			
		||||
bitstream
 | 
			
		||||
bsdl
 | 
			
		||||
 | 
			
		||||
data
 | 
			
		||||
 
 | 
			
		||||
@@ -62,8 +62,39 @@ try
 | 
			
		||||
                IssuerSigningKey = new SymmetricSecurityKey(
 | 
			
		||||
                    Encoding.UTF8.GetBytes("my secret key 1234567890my secret key 1234567890")),
 | 
			
		||||
            };
 | 
			
		||||
            options.Authority = $"http://{Global.localhost}:5000";
 | 
			
		||||
            options.Authority = $"http://{Global.LocalHost}:5000";
 | 
			
		||||
            options.RequireHttpsMetadata = false;
 | 
			
		||||
 | 
			
		||||
            // We have to hook the OnMessageReceived event in order to
 | 
			
		||||
            // allow the JWT authentication handler to read the access
 | 
			
		||||
            // token from the query string when a WebSocket or
 | 
			
		||||
            // Server-Sent Events request comes in.
 | 
			
		||||
 | 
			
		||||
            // Sending the access token in the query string is required when using WebSockets or ServerSentEvents
 | 
			
		||||
            // due to a limitation in Browser APIs. We restrict it to only calls to the
 | 
			
		||||
            // SignalR hub in this code.
 | 
			
		||||
            // See https://docs.microsoft.com/aspnet/core/signalr/security#access-token-logging
 | 
			
		||||
            // for more information about security considerations when using
 | 
			
		||||
            // the query string to transmit the access token.
 | 
			
		||||
            options.Events = new JwtBearerEvents
 | 
			
		||||
            {
 | 
			
		||||
                OnMessageReceived = context =>
 | 
			
		||||
                {
 | 
			
		||||
                    var accessToken = context.Request.Query["access_token"];
 | 
			
		||||
 | 
			
		||||
                    // If the request is for our hub...
 | 
			
		||||
                    var path = context.HttpContext.Request.Path;
 | 
			
		||||
                    if (!string.IsNullOrEmpty(accessToken) && (
 | 
			
		||||
                            path.StartsWithSegments("/hubs/JtagHub") ||
 | 
			
		||||
                            path.StartsWithSegments("/hubs/ProgressHub")
 | 
			
		||||
                        ))
 | 
			
		||||
                    {
 | 
			
		||||
                        // Read the token out of the query string
 | 
			
		||||
                        context.Token = accessToken;
 | 
			
		||||
                    }
 | 
			
		||||
                    return Task.CompletedTask;
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
        });
 | 
			
		||||
    // Add JWT Token Authorization Policy
 | 
			
		||||
    builder.Services.AddAuthorization(options =>
 | 
			
		||||
@@ -71,7 +102,7 @@ try
 | 
			
		||||
        options.AddPolicy("Admin", policy =>
 | 
			
		||||
        {
 | 
			
		||||
            policy.RequireClaim(ClaimTypes.Role, new string[] {
 | 
			
		||||
                Database.User.UserPermission.Admin.ToString(),
 | 
			
		||||
                Database.UserPermission.Admin.ToString(),
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
@@ -141,6 +172,11 @@ try
 | 
			
		||||
        options.OperationProcessors.Add(new OperationSecurityScopeProcessor("Bearer"));
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    // 添加数据库资源管理器服务
 | 
			
		||||
    builder.Services.AddScoped<Database.AppDataConnection>();
 | 
			
		||||
    builder.Services.AddScoped<Database.UserManager>();
 | 
			
		||||
    builder.Services.AddScoped<Database.ResourceManager>();
 | 
			
		||||
    builder.Services.AddScoped<Database.ExamManager>();
 | 
			
		||||
 | 
			
		||||
    // 添加 HTTP 视频流服务
 | 
			
		||||
    builder.Services.AddSingleton<HttpVideoStreamService>();
 | 
			
		||||
@@ -209,7 +245,7 @@ try
 | 
			
		||||
        settings.PostProcess = (document, httpRequest) =>
 | 
			
		||||
        {
 | 
			
		||||
            document.Servers.Clear();
 | 
			
		||||
            document.Servers.Add(new NSwag.OpenApiServer { Url = $"http://{Global.localhost}:5000" });
 | 
			
		||||
            document.Servers.Add(new NSwag.OpenApiServer { Url = $"http://{Global.LocalHost}:5000" });
 | 
			
		||||
        };
 | 
			
		||||
    });
 | 
			
		||||
    app.UseSwaggerUi();
 | 
			
		||||
@@ -232,7 +268,7 @@ try
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var document = await OpenApiDocument.FromUrlAsync($"http://{Global.localhost}:5000/swagger/v1/swagger.json");
 | 
			
		||||
            var document = await OpenApiDocument.FromUrlAsync($"http://{Global.LocalHost}:5000/swagger/v1/swagger.json");
 | 
			
		||||
 | 
			
		||||
            var settings = new TypeScriptClientGeneratorSettings
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,8 @@ using System.Net.Sockets;
 | 
			
		||||
public static class Global
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    public static readonly string localhost = "127.0.0.1";
 | 
			
		||||
    public static readonly string LocalHost = "127.0.0.1";
 | 
			
		||||
    public static readonly string DataPath = Path.Combine(Environment.CurrentDirectory, "data");
 | 
			
		||||
 | 
			
		||||
    public static string GetLocalIPAddress()
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -17,38 +17,15 @@ namespace server.Controllers;
 | 
			
		||||
public class DataController : ControllerBase
 | 
			
		||||
{
 | 
			
		||||
    private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    private readonly Database.UserManager _userManager;
 | 
			
		||||
 | 
			
		||||
    // 固定的实验板IP,端口,MAC地址
 | 
			
		||||
    private const string BOARD_IP = "169.254.109.0";
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// [TODO:description]
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class UserInfo
 | 
			
		||||
    public DataController(Database.UserManager userManager)
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 用户的唯一标识符
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Guid ID { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 用户的名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 用户的电子邮箱
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string EMail { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 用户关联的板卡ID
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Guid BoardID { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 用户绑定板子的过期时间
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DateTime? BoardExpireTime { get; set; }
 | 
			
		||||
        _userManager = userManager;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
@@ -112,8 +89,7 @@ public class DataController : ControllerBase
 | 
			
		||||
    public IActionResult Login(string name, string password)
 | 
			
		||||
    {
 | 
			
		||||
        // 验证用户密码
 | 
			
		||||
        using var db = new Database.AppDataConnection();
 | 
			
		||||
        var ret = db.CheckUserPassword(name, password);
 | 
			
		||||
        var ret = _userManager.CheckUserPassword(name, password);
 | 
			
		||||
        if (!ret.IsSuccessful) return StatusCode(StatusCodes.Status500InternalServerError, "数据库操作失败");
 | 
			
		||||
        if (!ret.Value.HasValue) return BadRequest("用户名或密码错误");
 | 
			
		||||
        var user = ret.Value.Value;
 | 
			
		||||
@@ -188,8 +164,7 @@ public class DataController : ControllerBase
 | 
			
		||||
            return Unauthorized("未找到用户名信息");
 | 
			
		||||
 | 
			
		||||
        // Get User Info
 | 
			
		||||
        using var db = new Database.AppDataConnection();
 | 
			
		||||
        var ret = db.GetUserByName(userName);
 | 
			
		||||
        var ret = _userManager.GetUserByName(userName);
 | 
			
		||||
        if (!ret.IsSuccessful)
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, "数据库操作失败");
 | 
			
		||||
 | 
			
		||||
@@ -236,8 +211,7 @@ public class DataController : ControllerBase
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var ret = db.AddUser(name, email, password);
 | 
			
		||||
            var ret = _userManager.AddUser(name, email, password);
 | 
			
		||||
            return Ok(ret);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
@@ -265,15 +239,14 @@ public class DataController : ControllerBase
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return Unauthorized("未找到用户名信息");
 | 
			
		||||
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var userRet = db.GetUserByName(userName);
 | 
			
		||||
            var userRet = _userManager.GetUserByName(userName);
 | 
			
		||||
            if (!userRet.IsSuccessful || !userRet.Value.HasValue)
 | 
			
		||||
                return BadRequest("用户不存在");
 | 
			
		||||
 | 
			
		||||
            var user = userRet.Value.Value;
 | 
			
		||||
            var expireTime = DateTime.UtcNow.AddHours(durationHours);
 | 
			
		||||
 | 
			
		||||
            var boardOpt = db.GetAvailableBoard(user.ID, expireTime);
 | 
			
		||||
            var boardOpt = _userManager.GetAvailableBoard(user.ID, expireTime);
 | 
			
		||||
            if (!boardOpt.HasValue)
 | 
			
		||||
                return NotFound("没有可用的实验板");
 | 
			
		||||
 | 
			
		||||
@@ -309,13 +282,12 @@ public class DataController : ControllerBase
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return Unauthorized("未找到用户名信息");
 | 
			
		||||
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var userRet = db.GetUserByName(userName);
 | 
			
		||||
            var userRet = _userManager.GetUserByName(userName);
 | 
			
		||||
            if (!userRet.IsSuccessful || !userRet.Value.HasValue)
 | 
			
		||||
                return BadRequest("用户不存在");
 | 
			
		||||
 | 
			
		||||
            var user = userRet.Value.Value;
 | 
			
		||||
            var result = db.UnbindUserFromBoard(user.ID);
 | 
			
		||||
            var result = _userManager.UnbindUserFromBoard(user.ID);
 | 
			
		||||
            return Ok(result > 0);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
@@ -338,8 +310,7 @@ public class DataController : ControllerBase
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var ret = db.GetBoardByID(id);
 | 
			
		||||
            var ret = _userManager.GetBoardByID(id);
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, "数据库操作失败");
 | 
			
		||||
            if (!ret.Value.HasValue)
 | 
			
		||||
@@ -375,8 +346,7 @@ public class DataController : ControllerBase
 | 
			
		||||
            return BadRequest("板子名称不能为空");
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var ret = db.AddBoard(name);
 | 
			
		||||
            var ret = _userManager.AddBoard(name);
 | 
			
		||||
            return Ok(ret);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
@@ -402,8 +372,7 @@ public class DataController : ControllerBase
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var ret = db.DeleteBoardByID(id);
 | 
			
		||||
            var ret = _userManager.DeleteBoardByID(id);
 | 
			
		||||
            return Ok(ret);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
@@ -425,8 +394,7 @@ public class DataController : ControllerBase
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var boards = db.GetAllBoard();
 | 
			
		||||
            var boards = _userManager.GetAllBoard();
 | 
			
		||||
            return Ok(boards);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
@@ -453,8 +421,7 @@ public class DataController : ControllerBase
 | 
			
		||||
            return BadRequest("新名称不能为空");
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var result = db.UpdateBoardName(boardId, newName);
 | 
			
		||||
            var result = _userManager.UpdateBoardName(boardId, newName);
 | 
			
		||||
            return Ok(result);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
@@ -473,14 +440,13 @@ public class DataController : ControllerBase
 | 
			
		||||
    [ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult UpdateBoardStatus(Guid boardId, Database.Board.BoardStatus newStatus)
 | 
			
		||||
    public IActionResult UpdateBoardStatus(Guid boardId, Database.BoardStatus newStatus)
 | 
			
		||||
    {
 | 
			
		||||
        if (boardId == Guid.Empty)
 | 
			
		||||
            return BadRequest("板子Guid不能为空");
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var result = db.UpdateBoardStatus(boardId, newStatus);
 | 
			
		||||
            var result = _userManager.UpdateBoardStatus(boardId, newStatus);
 | 
			
		||||
            return Ok(result);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
@@ -489,4 +455,54 @@ public class DataController : ControllerBase
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, "更新失败,请稍后重试");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [HttpPost("AddEmptyBoard")]
 | 
			
		||||
    [EnableCors("Development")]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult AddEmptyBoard()
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var boardId = _userManager.AddBoard("Test");
 | 
			
		||||
            var result = _userManager.UpdateBoardStatus(boardId, Database.BoardStatus.Available);
 | 
			
		||||
            return Ok();
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error(ex, "新增板子时发生异常");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, "新增失败,请稍后重试");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// [TODO:description]
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class UserInfo
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 用户的唯一标识符
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Guid ID { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 用户的名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 用户的电子邮箱
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string EMail { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 用户关联的板卡ID
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Guid BoardID { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 用户绑定板子的过期时间
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DateTime? BoardExpireTime { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,77 +15,11 @@ public class DebuggerController : ControllerBase
 | 
			
		||||
{
 | 
			
		||||
    private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 表示单个信号通道的配置信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class ChannelConfig
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 通道名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public string name;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 通道显示颜色(如前端波形显示用)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public string color;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 通道信号线宽度(位数)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 wireWidth;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 信号线在父端口中的起始索引(bit)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 wireStartIndex;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 父端口编号
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 parentPort;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 捕获模式(如上升沿、下降沿等)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public CaptureMode mode;
 | 
			
		||||
    }
 | 
			
		||||
    private readonly Database.UserManager _userManager;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 调试器整体配置信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class DebuggerConfig
 | 
			
		||||
    public DebuggerController(Database.UserManager userManager)
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 时钟频率
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 clkFreq;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 总端口数量
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 totalPortNum;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 捕获深度(采样点数)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 captureDepth;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 触发器数量
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 triggerNum;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 所有信号通道的配置信息
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public ChannelConfig[] channelConfigs;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 单个通道的捕获数据
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class ChannelCaptureData
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 通道名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public string name;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 通道捕获到的数据(Base64编码的UInt32数组)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public string data;
 | 
			
		||||
        this._userManager = userManager;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
@@ -99,8 +33,7 @@ public class DebuggerController : ControllerBase
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var userRet = db.GetUserByName(userName);
 | 
			
		||||
            var userRet = _userManager.GetUserByName(userName);
 | 
			
		||||
            if (!userRet.IsSuccessful || !userRet.Value.HasValue)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
@@ -108,7 +41,7 @@ public class DebuggerController : ControllerBase
 | 
			
		||||
            if (user.BoardID == Guid.Empty)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
            var boardRet = db.GetBoardByID(user.BoardID);
 | 
			
		||||
            var boardRet = _userManager.GetBoardByID(user.BoardID);
 | 
			
		||||
            if (!boardRet.IsSuccessful || !boardRet.Value.HasValue)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
@@ -464,4 +397,77 @@ public class DebuggerController : ControllerBase
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, "操作失败,请稍后重试");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 表示单个信号通道的配置信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class ChannelConfig
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 通道名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public string name;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 通道显示颜色(如前端波形显示用)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public string color;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 通道信号线宽度(位数)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 wireWidth;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 信号线在父端口中的起始索引(bit)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 wireStartIndex;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 父端口编号
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 parentPort;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 捕获模式(如上升沿、下降沿等)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public CaptureMode mode;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 调试器整体配置信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class DebuggerConfig
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 时钟频率
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 clkFreq;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 总端口数量
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 totalPortNum;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 捕获深度(采样点数)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 captureDepth;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 触发器数量
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public UInt32 triggerNum;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 所有信号通道的配置信息
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public ChannelConfig[] channelConfigs;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 单个通道的捕获数据
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class ChannelCaptureData
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 通道名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public string name;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 通道捕获到的数据(Base64编码的UInt32数组)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        required public string data;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization;
 | 
			
		||||
using Microsoft.AspNetCore.Cors;
 | 
			
		||||
using Microsoft.AspNetCore.Mvc;
 | 
			
		||||
using DotNext;
 | 
			
		||||
using Database;
 | 
			
		||||
 | 
			
		||||
namespace server.Controllers;
 | 
			
		||||
 | 
			
		||||
@@ -14,127 +15,18 @@ public class ExamController : ControllerBase
 | 
			
		||||
{
 | 
			
		||||
    private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验信息类
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class ExamInfo
 | 
			
		||||
    private readonly ExamManager _examManager;
 | 
			
		||||
    private readonly ResourceManager _resourceManager;
 | 
			
		||||
    private readonly UserManager _userManager;
 | 
			
		||||
 | 
			
		||||
    public ExamController(
 | 
			
		||||
        ExamManager examManager,
 | 
			
		||||
        ResourceManager resourceManager,
 | 
			
		||||
        UserManager userManager)
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验的唯一标识符
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string ID { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验描述
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string Description { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验创建时间
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DateTime CreatedTime { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验最后更新时间
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DateTime UpdatedTime { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验标签
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string[] Tags { get; set; } = Array.Empty<string>();
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验难度(1-5)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int Difficulty { get; set; } = 1;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 普通用户是否可见
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool IsVisibleToUsers { get; set; } = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验简要信息类(用于列表显示)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class ExamSummary
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验的唯一标识符
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string ID { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验创建时间
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DateTime CreatedTime { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验最后更新时间
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DateTime UpdatedTime { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验标签
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string[] Tags { get; set; } = Array.Empty<string>();
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验难度(1-5)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int Difficulty { get; set; } = 1;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 普通用户是否可见
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool IsVisibleToUsers { get; set; } = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 创建实验请求类
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class CreateExamRequest
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验ID
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string ID { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验描述
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string Description { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验标签
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string[] Tags { get; set; } = Array.Empty<string>();
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实验难度(1-5)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int Difficulty { get; set; } = 1;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 普通用户是否可见
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool IsVisibleToUsers { get; set; } = true;
 | 
			
		||||
        _examManager = examManager;
 | 
			
		||||
        _resourceManager = resourceManager;
 | 
			
		||||
        _userManager = userManager;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
@@ -144,29 +36,19 @@ public class ExamController : ControllerBase
 | 
			
		||||
    [Authorize]
 | 
			
		||||
    [HttpGet("list")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(ExamSummary[]), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(typeof(ExamInfo[]), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult GetExamList()
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var exams = db.GetAllExams();
 | 
			
		||||
            var exams = _examManager.GetAllExams();
 | 
			
		||||
 | 
			
		||||
            var examSummaries = exams.Select(exam => new ExamSummary
 | 
			
		||||
            {
 | 
			
		||||
                ID = exam.ID,
 | 
			
		||||
                Name = exam.Name,
 | 
			
		||||
                CreatedTime = exam.CreatedTime,
 | 
			
		||||
                UpdatedTime = exam.UpdatedTime,
 | 
			
		||||
                Tags = exam.GetTagsList(),
 | 
			
		||||
                Difficulty = exam.Difficulty,
 | 
			
		||||
                IsVisibleToUsers = exam.IsVisibleToUsers
 | 
			
		||||
            }).ToArray();
 | 
			
		||||
            var examInfos = exams.Select(exam => new ExamInfo(exam)).ToArray();
 | 
			
		||||
 | 
			
		||||
            logger.Info($"成功获取实验列表,共 {examSummaries.Length} 个实验");
 | 
			
		||||
            return Ok(examSummaries);
 | 
			
		||||
            logger.Info($"成功获取实验列表,共 {examInfos.Length} 个实验");
 | 
			
		||||
            return Ok(examInfos);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
@@ -195,8 +77,7 @@ public class ExamController : ControllerBase
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var result = db.GetExamByID(examId);
 | 
			
		||||
            var result = _examManager.GetExamByID(examId);
 | 
			
		||||
 | 
			
		||||
            if (!result.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
@@ -211,17 +92,7 @@ public class ExamController : ControllerBase
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var exam = result.Value.Value;
 | 
			
		||||
            var examInfo = new ExamInfo
 | 
			
		||||
            {
 | 
			
		||||
                ID = exam.ID,
 | 
			
		||||
                Name = exam.Name,
 | 
			
		||||
                Description = exam.Description,
 | 
			
		||||
                CreatedTime = exam.CreatedTime,
 | 
			
		||||
                UpdatedTime = exam.UpdatedTime,
 | 
			
		||||
                Tags = exam.GetTagsList(),
 | 
			
		||||
                Difficulty = exam.Difficulty,
 | 
			
		||||
                IsVisibleToUsers = exam.IsVisibleToUsers
 | 
			
		||||
            };
 | 
			
		||||
            var examInfo = new ExamInfo(exam);
 | 
			
		||||
 | 
			
		||||
            logger.Info($"成功获取实验信息: {examId}");
 | 
			
		||||
            return Ok(examInfo);
 | 
			
		||||
@@ -239,7 +110,7 @@ public class ExamController : ControllerBase
 | 
			
		||||
    /// <param name="request">创建实验请求</param>
 | 
			
		||||
    /// <returns>创建结果</returns>
 | 
			
		||||
    [Authorize("Admin")]
 | 
			
		||||
    [HttpPost]
 | 
			
		||||
    [HttpPost("create")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(ExamInfo), StatusCodes.Status201Created)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | 
			
		||||
@@ -247,37 +118,26 @@ public class ExamController : ControllerBase
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status403Forbidden)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status409Conflict)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult CreateExam([FromBody] CreateExamRequest request)
 | 
			
		||||
    public IActionResult CreateExam([FromBody] ExamDto request)
 | 
			
		||||
    {
 | 
			
		||||
        if (string.IsNullOrWhiteSpace(request.ID) || string.IsNullOrWhiteSpace(request.Name) || string.IsNullOrWhiteSpace(request.Description))
 | 
			
		||||
            return BadRequest("实验ID、名称和描述不能为空");
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var result = db.CreateExam(request.ID, request.Name, request.Description, request.Tags, request.Difficulty, request.IsVisibleToUsers);
 | 
			
		||||
            var result = _examManager.CreateExam(request.ID, request.Name, request.Description, request.Tags, request.Difficulty, request.IsVisibleToUsers);
 | 
			
		||||
 | 
			
		||||
            if (!result.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                if (result.Error.Message.Contains("已存在"))
 | 
			
		||||
                    return Conflict(result.Error.Message);
 | 
			
		||||
                
 | 
			
		||||
 | 
			
		||||
                logger.Error($"创建实验时出错: {result.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"创建实验失败: {result.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var exam = result.Value;
 | 
			
		||||
            var examInfo = new ExamInfo
 | 
			
		||||
            {
 | 
			
		||||
                ID = exam.ID,
 | 
			
		||||
                Name = exam.Name,
 | 
			
		||||
                Description = exam.Description,
 | 
			
		||||
                CreatedTime = exam.CreatedTime,
 | 
			
		||||
                UpdatedTime = exam.UpdatedTime,
 | 
			
		||||
                Tags = exam.GetTagsList(),
 | 
			
		||||
                Difficulty = exam.Difficulty,
 | 
			
		||||
                IsVisibleToUsers = exam.IsVisibleToUsers
 | 
			
		||||
            };
 | 
			
		||||
            var examInfo = new ExamInfo(exam);
 | 
			
		||||
 | 
			
		||||
            logger.Info($"成功创建实验: {request.ID}");
 | 
			
		||||
            return CreatedAtAction(nameof(GetExam), new { examId = request.ID }, examInfo);
 | 
			
		||||
@@ -288,4 +148,385 @@ public class ExamController : ControllerBase
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"创建实验失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 更新实验信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="request">更新实验请求</param>
 | 
			
		||||
    /// <returns>更新结果</returns>
 | 
			
		||||
    [Authorize("Admin")]
 | 
			
		||||
    [HttpPost("update")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(ExamInfo), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status403Forbidden)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status404NotFound)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult UpdateExam([FromBody] ExamDto request)
 | 
			
		||||
    {
 | 
			
		||||
        var examId = request.ID;
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            // 首先检查实验是否存在
 | 
			
		||||
            var existingExamResult = _examManager.GetExamByID(examId);
 | 
			
		||||
            if (!existingExamResult.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"检查实验是否存在时出错: {existingExamResult.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"检查实验失败: {existingExamResult.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!existingExamResult.Value.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Warn($"要更新的实验不存在: {examId}");
 | 
			
		||||
                return NotFound($"实验 {examId} 不存在");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 执行更新
 | 
			
		||||
            var updateResult = _examManager.UpdateExam(
 | 
			
		||||
                examId,
 | 
			
		||||
                request.Name,
 | 
			
		||||
                request.Description,
 | 
			
		||||
                request.Tags,
 | 
			
		||||
                request.Difficulty,
 | 
			
		||||
                request.IsVisibleToUsers
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            if (!updateResult.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"更新实验时出错: {updateResult.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"更新实验失败: {updateResult.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 获取更新后的实验信息并返回
 | 
			
		||||
            var updatedExamResult = _examManager.GetExamByID(examId);
 | 
			
		||||
            if (!updatedExamResult.IsSuccessful || !updatedExamResult.Value.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"获取更新后的实验信息失败: {examId}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, "更新成功但获取更新后信息失败");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var updatedExam = updatedExamResult.Value.Value;
 | 
			
		||||
            var examInfo = new ExamInfo(updatedExam);
 | 
			
		||||
 | 
			
		||||
            logger.Info($"成功更新实验: {examId},更新记录数: {updateResult.Value}");
 | 
			
		||||
            return Ok(examInfo);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"更新实验 {examId} 时出错: {ex.Message}");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"更新实验失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 提交作业
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="examId">实验ID</param>
 | 
			
		||||
    /// <param name="file">提交的文件</param>
 | 
			
		||||
    /// <returns>提交结果</returns>
 | 
			
		||||
    [Authorize]
 | 
			
		||||
    [HttpPost("commit/{examId}")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(Resource), StatusCodes.Status201Created)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status404NotFound)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public async Task<IActionResult> SubmitHomework(string examId, IFormFile file)
 | 
			
		||||
    {
 | 
			
		||||
        if (string.IsNullOrWhiteSpace(examId))
 | 
			
		||||
            return BadRequest("实验ID不能为空");
 | 
			
		||||
 | 
			
		||||
        if (file == null || file.Length == 0)
 | 
			
		||||
            return BadRequest("文件不能为空");
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            // 获取当前用户信息
 | 
			
		||||
            var userName = User.Identity?.Name;
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return Unauthorized("无法获取用户信息");
 | 
			
		||||
 | 
			
		||||
            var userResult = _userManager.GetUserByName(userName);
 | 
			
		||||
            if (!userResult.IsSuccessful || !userResult.Value.HasValue)
 | 
			
		||||
                return Unauthorized("用户不存在");
 | 
			
		||||
 | 
			
		||||
            var user = userResult.Value.Value;
 | 
			
		||||
 | 
			
		||||
            // 检查实验是否存在
 | 
			
		||||
            var examResult = _examManager.GetExamByID(examId);
 | 
			
		||||
            if (!examResult.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"检查实验是否存在时出错: {examResult.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"检查实验失败: {examResult.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!examResult.Value.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Warn($"实验不存在: {examId}");
 | 
			
		||||
                return NotFound($"实验 {examId} 不存在");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 读取文件内容
 | 
			
		||||
            byte[] fileData;
 | 
			
		||||
            using (var memoryStream = new MemoryStream())
 | 
			
		||||
            {
 | 
			
		||||
                await file.CopyToAsync(memoryStream);
 | 
			
		||||
                fileData = memoryStream.ToArray();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 提交作业
 | 
			
		||||
            var commitResult = _resourceManager.AddResource(
 | 
			
		||||
                user.ID, ResourceTypes.Compression, ResourcePurpose.Homework,
 | 
			
		||||
                file.FileName, fileData, examId);
 | 
			
		||||
            if (!commitResult.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"提交作业时出错: {commitResult.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"提交作业失败: {commitResult.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var commit = commitResult.Value;
 | 
			
		||||
 | 
			
		||||
            logger.Info($"用户 {userName} 成功提交实验 {examId} 的作业,Commit ID: {commit.ID}");
 | 
			
		||||
            return CreatedAtAction(nameof(GetCommitsByExamId), new { examId = examId }, commit);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"提交实验 {examId} 作业时出错: {ex.Message}");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"提交作业失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 获取用户在指定实验中的提交记录
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="examId">实验ID</param>
 | 
			
		||||
    /// <returns>提交记录列表</returns>
 | 
			
		||||
    [Authorize]
 | 
			
		||||
    [HttpGet("commits/{examId}")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(Resource[]), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status404NotFound)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult GetCommitsByExamId(string examId)
 | 
			
		||||
    {
 | 
			
		||||
        if (string.IsNullOrWhiteSpace(examId))
 | 
			
		||||
            return BadRequest("实验ID不能为空");
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            // 获取当前用户信息
 | 
			
		||||
            var userName = User.Identity?.Name;
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return Unauthorized("无法获取用户信息");
 | 
			
		||||
 | 
			
		||||
            var userResult = _userManager.GetUserByName(userName);
 | 
			
		||||
            if (!userResult.IsSuccessful || !userResult.Value.HasValue)
 | 
			
		||||
                return Unauthorized("用户不存在");
 | 
			
		||||
 | 
			
		||||
            var user = userResult.Value.Value;
 | 
			
		||||
 | 
			
		||||
            // 检查实验是否存在
 | 
			
		||||
            var examResult = _examManager.GetExamByID(examId);
 | 
			
		||||
            if (!examResult.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"检查实验是否存在时出错: {examResult.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"检查实验失败: {examResult.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!examResult.Value.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Warn($"实验不存在: {examId}");
 | 
			
		||||
                return NotFound($"实验 {examId} 不存在");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 获取用户的提交记录
 | 
			
		||||
            var commitsResult = _resourceManager.GetResourceListByType(
 | 
			
		||||
                ResourceTypes.Compression, ResourcePurpose.Homework, examId);
 | 
			
		||||
            if (!commitsResult.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"获取提交记录时出错: {commitsResult.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"获取提交记录失败: {commitsResult.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var commits = commitsResult.Value;
 | 
			
		||||
 | 
			
		||||
            logger.Info($"成功获取用户 {userName} 在实验 {examId} 中的提交记录,共 {commits.Length} 条");
 | 
			
		||||
            return Ok(commits);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"获取实验 {examId} 提交记录时出错: {ex.Message}");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"获取提交记录失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 删除提交记录
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="commitId">提交记录ID</param>
 | 
			
		||||
    /// <returns>删除结果</returns>
 | 
			
		||||
    [Authorize]
 | 
			
		||||
    [HttpDelete("commit/{commitId}")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status403Forbidden)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status404NotFound)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult DeleteCommit(string commitId)
 | 
			
		||||
    {
 | 
			
		||||
        if (!Guid.TryParse(commitId, out _))
 | 
			
		||||
            return BadRequest("提交记录ID格式不正确");
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            // 获取当前用户信息
 | 
			
		||||
            var userName = User.Identity?.Name;
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return Unauthorized("无法获取用户信息");
 | 
			
		||||
 | 
			
		||||
            var userResult = _userManager.GetUserByName(userName);
 | 
			
		||||
            if (!userResult.IsSuccessful || !userResult.Value.HasValue)
 | 
			
		||||
                return Unauthorized("用户不存在");
 | 
			
		||||
 | 
			
		||||
            var user = userResult.Value.Value;
 | 
			
		||||
 | 
			
		||||
            // 检查是否是管理员
 | 
			
		||||
            var isAdmin = user.Permission == UserPermission.Admin;
 | 
			
		||||
 | 
			
		||||
            // 如果不是管理员,检查提交记录是否属于当前用户
 | 
			
		||||
            if (!isAdmin)
 | 
			
		||||
            {
 | 
			
		||||
                var commitResult = _resourceManager.GetResourceById(commitId);
 | 
			
		||||
                if (!commitResult.HasValue)
 | 
			
		||||
                {
 | 
			
		||||
                    logger.Warn($"提交记录不存在: {commitId}");
 | 
			
		||||
                    return NotFound($"提交记录 {commitId} 不存在");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                var commit = commitResult.Value;
 | 
			
		||||
                if (commit.UserID != user.ID)
 | 
			
		||||
                {
 | 
			
		||||
                    logger.Warn($"用户 {userName} 尝试删除不属于自己的提交记录: {commitId}");
 | 
			
		||||
                    return Forbid("您只能删除自己的提交记录");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 执行删除
 | 
			
		||||
            var deleteResult = _resourceManager.DeleteResource(commitId);
 | 
			
		||||
            if (!deleteResult)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Warn($"提交记录不存在: {commitId}");
 | 
			
		||||
                return NotFound($"提交记录 {commitId} 不存在");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            logger.Info($"用户 {userName} 成功删除提交记录: {commitId}");
 | 
			
		||||
            return Ok($"提交记录 {commitId} 已成功删除");
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"删除提交记录 {commitId} 时出错: {ex.Message}");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"删除提交记录失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// 实验信息
 | 
			
		||||
/// </summary>
 | 
			
		||||
public class ExamInfo
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验的唯一标识符
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public string ID { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验名称
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验描述
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public string Description { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验创建时间
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public DateTime CreatedTime { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验最后更新时间
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public DateTime UpdatedTime { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验标签
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public string[] Tags { get; set; } = Array.Empty<string>();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验难度(1-5)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public int Difficulty { get; set; } = 1;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 普通用户是否可见
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool IsVisibleToUsers { get; set; } = true;
 | 
			
		||||
 | 
			
		||||
    public ExamInfo(Exam exam)
 | 
			
		||||
    {
 | 
			
		||||
        ID = exam.ID;
 | 
			
		||||
        Name = exam.Name;
 | 
			
		||||
        Description = exam.Description;
 | 
			
		||||
        CreatedTime = exam.CreatedTime;
 | 
			
		||||
        UpdatedTime = exam.UpdatedTime;
 | 
			
		||||
        Tags = exam.GetTagsList();
 | 
			
		||||
        Difficulty = exam.Difficulty;
 | 
			
		||||
        IsVisibleToUsers = exam.IsVisibleToUsers;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// 统一的实验数据传输对象
 | 
			
		||||
/// </summary>
 | 
			
		||||
public class ExamDto
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验的唯一标识符
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public required string ID { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验名称
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public required string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验描述
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public required string Description { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验标签
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public string[] Tags { get; set; } = Array.Empty<string>();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验难度(1-5)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public int Difficulty { get; set; } = 1;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 普通用户是否可见
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool IsVisibleToUsers { get; set; } = true;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Cors;
 | 
			
		||||
using Microsoft.AspNetCore.Authorization;
 | 
			
		||||
using System.Security.Claims;
 | 
			
		||||
using server.Services;
 | 
			
		||||
using Database;
 | 
			
		||||
 | 
			
		||||
namespace server.Controllers;
 | 
			
		||||
 | 
			
		||||
@@ -12,12 +11,15 @@ namespace server.Controllers;
 | 
			
		||||
[EnableCors("Users")]
 | 
			
		||||
public class HdmiVideoStreamController : ControllerBase
 | 
			
		||||
{
 | 
			
		||||
    private readonly HttpHdmiVideoStreamService _videoStreamService;
 | 
			
		||||
    private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    public HdmiVideoStreamController(HttpHdmiVideoStreamService videoStreamService)
 | 
			
		||||
    private readonly HttpHdmiVideoStreamService _videoStreamService;
 | 
			
		||||
    private readonly Database.UserManager _userManager;
 | 
			
		||||
 | 
			
		||||
    public HdmiVideoStreamController(HttpHdmiVideoStreamService videoStreamService, Database.UserManager userManager)
 | 
			
		||||
    {
 | 
			
		||||
        _videoStreamService = videoStreamService;
 | 
			
		||||
        _userManager = userManager;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 管理员获取所有板子的 endpoints
 | 
			
		||||
@@ -40,11 +42,7 @@ public class HdmiVideoStreamController : ControllerBase
 | 
			
		||||
        if (string.IsNullOrEmpty(userName))
 | 
			
		||||
            return Unauthorized("User name not found in claims.");
 | 
			
		||||
 | 
			
		||||
        var db = new AppDataConnection();
 | 
			
		||||
        if (db == null)
 | 
			
		||||
            return NotFound("Database connection failed.");
 | 
			
		||||
 | 
			
		||||
        var userRet = db.GetUserByName(userName);
 | 
			
		||||
        var userRet = _userManager.GetUserByName(userName);
 | 
			
		||||
        if (!userRet.IsSuccessful || !userRet.Value.HasValue)
 | 
			
		||||
            return NotFound("User not found.");
 | 
			
		||||
 | 
			
		||||
@@ -53,7 +51,7 @@ public class HdmiVideoStreamController : ControllerBase
 | 
			
		||||
        if (boardId == Guid.Empty)
 | 
			
		||||
            return NotFound("No board bound to this user.");
 | 
			
		||||
 | 
			
		||||
        var boardRet = db.GetBoardByID(boardId);
 | 
			
		||||
        var boardRet = _userManager.GetBoardByID(boardId);
 | 
			
		||||
        if (!boardRet.IsSuccessful || !boardRet.Value.HasValue)
 | 
			
		||||
            return NotFound("Board not found.");
 | 
			
		||||
 | 
			
		||||
@@ -70,11 +68,7 @@ public class HdmiVideoStreamController : ControllerBase
 | 
			
		||||
        if (string.IsNullOrEmpty(userName))
 | 
			
		||||
            return Unauthorized("User name not found in claims.");
 | 
			
		||||
 | 
			
		||||
        var db = new AppDataConnection();
 | 
			
		||||
        if (db == null)
 | 
			
		||||
            return NotFound("Database connection failed.");
 | 
			
		||||
 | 
			
		||||
        var userRet = db.GetUserByName(userName);
 | 
			
		||||
        var userRet = _userManager.GetUserByName(userName);
 | 
			
		||||
        if (!userRet.IsSuccessful || !userRet.Value.HasValue)
 | 
			
		||||
            return NotFound("User not found.");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -17,12 +17,17 @@ public class JtagController : ControllerBase
 | 
			
		||||
    private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    private readonly ProgressTrackerService _tracker;
 | 
			
		||||
    private readonly UserManager _userManager;
 | 
			
		||||
    private readonly ResourceManager _resourceManager;
 | 
			
		||||
 | 
			
		||||
    private const string BITSTREAM_PATH = "bitstream/Jtag";
 | 
			
		||||
 | 
			
		||||
    public JtagController(ProgressTrackerService tracker)
 | 
			
		||||
    public JtagController(
 | 
			
		||||
        ProgressTrackerService tracker, UserManager userManager, ResourceManager resourceManager)
 | 
			
		||||
    {
 | 
			
		||||
        _tracker = tracker;
 | 
			
		||||
        _userManager = userManager;
 | 
			
		||||
        _resourceManager = resourceManager;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
@@ -127,6 +132,7 @@ public class JtagController : ControllerBase
 | 
			
		||||
    /// <param name="address">JTAG 设备地址</param>
 | 
			
		||||
    /// <param name="port">JTAG 设备端口</param>
 | 
			
		||||
    /// <param name="bitstreamId">比特流ID</param>
 | 
			
		||||
    /// <param name="cancelToken">取消令牌</param>
 | 
			
		||||
    /// <returns>进度跟踪TaskID</returns>
 | 
			
		||||
    [HttpPost("DownloadBitstream")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
@@ -134,7 +140,7 @@ public class JtagController : ControllerBase
 | 
			
		||||
    [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
 | 
			
		||||
    [ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
 | 
			
		||||
    public async ValueTask<IResult> DownloadBitstream(string address, int port, int bitstreamId, CancellationToken cancelToken)
 | 
			
		||||
    public IResult DownloadBitstream(string address, int port, string bitstreamId, CancellationToken cancelToken)
 | 
			
		||||
    {
 | 
			
		||||
        logger.Info($"User {User.Identity?.Name} initiating bitstream download to device {address}:{port} using bitstream ID: {bitstreamId}");
 | 
			
		||||
 | 
			
		||||
@@ -149,35 +155,33 @@ public class JtagController : ControllerBase
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 从数据库获取用户信息
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var userResult = db.GetUserByName(username);
 | 
			
		||||
            var userResult = _userManager.GetUserByName(username);
 | 
			
		||||
            if (!userResult.IsSuccessful || !userResult.Value.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"User {username} not found in database");
 | 
			
		||||
                return TypedResults.BadRequest("用户不存在");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var user = userResult.Value.Value;
 | 
			
		||||
 | 
			
		||||
            // 从数据库获取比特流
 | 
			
		||||
            var bitstreamResult = db.GetResourceById(bitstreamId);
 | 
			
		||||
            var user = userResult.Value.Value;
 | 
			
		||||
            var resourceRet = _resourceManager.GetResourceById(bitstreamId);
 | 
			
		||||
 | 
			
		||||
            if (!bitstreamResult.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"User {username} failed to get bitstream from database: {bitstreamResult.Error}");
 | 
			
		||||
                return TypedResults.InternalServerError($"数据库查询失败: {bitstreamResult.Error?.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!bitstreamResult.Value.HasValue)
 | 
			
		||||
            if (!resourceRet.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Warn($"User {username} attempted to download non-existent bitstream ID: {bitstreamId}");
 | 
			
		||||
                return TypedResults.BadRequest("比特流不存在");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var bitstream = bitstreamResult.Value.Value;
 | 
			
		||||
 | 
			
		||||
            // 处理比特流数据
 | 
			
		||||
            var fileBytes = bitstream.Data;
 | 
			
		||||
            var resource = resourceRet.Value;
 | 
			
		||||
            var bitstreamRet = _resourceManager.ReadBytesFromPath(resource.Path);
 | 
			
		||||
            if (!bitstreamRet.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"User {username} failed to read bitstream file: {bitstreamRet.Error}");
 | 
			
		||||
                return TypedResults.InternalServerError($"比特流读取失败: {bitstreamRet.Error?.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var fileBytes = bitstreamRet.Value;
 | 
			
		||||
            if (fileBytes == null || fileBytes.Length == 0)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Warn($"User {username} found empty bitstream data for ID: {bitstreamId}");
 | 
			
		||||
@@ -235,7 +239,7 @@ public class JtagController : ControllerBase
 | 
			
		||||
 | 
			
		||||
                    if (ret.IsSuccessful)
 | 
			
		||||
                    {
 | 
			
		||||
                        logger.Info($"User {username} successfully downloaded bitstream '{bitstream.ResourceName}' to device {address}");
 | 
			
		||||
                        logger.Info($"User {username} successfully downloaded bitstream '{resource.ResourceName}' to device {address}");
 | 
			
		||||
                        progress.Finish();
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
 
 | 
			
		||||
@@ -15,56 +15,11 @@ public class LogicAnalyzerController : ControllerBase
 | 
			
		||||
{
 | 
			
		||||
    private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 信号触发配置
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class SignalTriggerConfig
 | 
			
		||||
    private readonly Database.UserManager _userManager;
 | 
			
		||||
 | 
			
		||||
    public LogicAnalyzerController(Database.UserManager userManager)
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 信号索引 (0-7)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int SignalIndex { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 操作符
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public SignalOperator Operator { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 信号值
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public SignalValue Value { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 捕获配置
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class CaptureConfig
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 全局触发模式
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public GlobalCaptureMode GlobalMode { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 捕获深度
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int CaptureLength { get; set; } = 2048 * 32;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 预采样深度
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int PreCaptureLength { get; set; } = 2048;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 有效通道
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public AnalyzerChannelDiv ChannelDiv { get; set; } = AnalyzerChannelDiv.EIGHT;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 时钟分频系数
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public AnalyzerClockDiv ClockDiv { get; set; } = AnalyzerClockDiv.DIV1;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 信号触发配置列表
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public SignalTriggerConfig[] SignalConfigs { get; set; } = Array.Empty<SignalTriggerConfig>();
 | 
			
		||||
        _userManager = userManager;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
@@ -78,8 +33,7 @@ public class LogicAnalyzerController : ControllerBase
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var userRet = db.GetUserByName(userName);
 | 
			
		||||
            var userRet = _userManager.GetUserByName(userName);
 | 
			
		||||
            if (!userRet.IsSuccessful || !userRet.Value.HasValue)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
@@ -87,7 +41,7 @@ public class LogicAnalyzerController : ControllerBase
 | 
			
		||||
            if (user.BoardID == Guid.Empty)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
            var boardRet = db.GetBoardByID(user.BoardID);
 | 
			
		||||
            var boardRet = _userManager.GetBoardByID(user.BoardID);
 | 
			
		||||
            if (!boardRet.IsSuccessful || !boardRet.Value.HasValue)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
@@ -422,4 +376,57 @@ public class LogicAnalyzerController : ControllerBase
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, "操作失败,请稍后重试");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 信号触发配置
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class SignalTriggerConfig
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 信号索引 (0-7)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int SignalIndex { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 操作符
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public SignalOperator Operator { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 信号值
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public SignalValue Value { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 捕获配置
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class CaptureConfig
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 全局触发模式
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public GlobalCaptureMode GlobalMode { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 捕获深度
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int CaptureLength { get; set; } = 2048 * 32;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 预采样深度
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int PreCaptureLength { get; set; } = 2048;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 有效通道
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public AnalyzerChannelDiv ChannelDiv { get; set; } = AnalyzerChannelDiv.EIGHT;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 时钟分频系数
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public AnalyzerClockDiv ClockDiv { get; set; } = AnalyzerClockDiv.DIV1;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 信号触发配置列表
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public SignalTriggerConfig[] SignalConfigs { get; set; } = Array.Empty<SignalTriggerConfig>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,71 +15,11 @@ public class OscilloscopeApiController : ControllerBase
 | 
			
		||||
{
 | 
			
		||||
    private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 示波器完整配置
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class OscilloscopeFullConfig
 | 
			
		||||
    private readonly Database.UserManager _userManager;
 | 
			
		||||
 | 
			
		||||
    public OscilloscopeApiController(Database.UserManager userManager)
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 是否启动捕获
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool CaptureEnabled { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 触发电平(0-255)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public byte TriggerLevel { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 触发边沿(true为上升沿,false为下降沿)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool TriggerRisingEdge { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 水平偏移量(0-1023)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public ushort HorizontalShift { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 抽样率(0-1023)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public ushort DecimationRate { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 是否自动刷新RAM
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool AutoRefreshRAM { get; set; } = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 示波器状态和数据
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class OscilloscopeDataResponse
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// AD采样频率
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public uint ADFrequency { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// AD采样幅度
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public byte ADVpp { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// AD采样最大值
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public byte ADMax { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// AD采样最小值
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public byte ADMin { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 波形数据(Base64编码)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string WaveformData { get; set; } = string.Empty;
 | 
			
		||||
        _userManager = userManager;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
@@ -93,8 +33,7 @@ public class OscilloscopeApiController : ControllerBase
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var userRet = db.GetUserByName(userName);
 | 
			
		||||
            var userRet = _userManager.GetUserByName(userName);
 | 
			
		||||
            if (!userRet.IsSuccessful || !userRet.Value.HasValue)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
@@ -102,7 +41,7 @@ public class OscilloscopeApiController : ControllerBase
 | 
			
		||||
            if (user.BoardID == Guid.Empty)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
            var boardRet = db.GetBoardByID(user.BoardID);
 | 
			
		||||
            var boardRet = _userManager.GetBoardByID(user.BoardID);
 | 
			
		||||
            if (!boardRet.IsSuccessful || !boardRet.Value.HasValue)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
@@ -481,4 +420,72 @@ public class OscilloscopeApiController : ControllerBase
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, "操作失败,请稍后重试");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 示波器完整配置
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class OscilloscopeFullConfig
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 是否启动捕获
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool CaptureEnabled { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 触发电平(0-255)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public byte TriggerLevel { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 触发边沿(true为上升沿,false为下降沿)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool TriggerRisingEdge { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 水平偏移量(0-1023)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public ushort HorizontalShift { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 抽样率(0-1023)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public ushort DecimationRate { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 是否自动刷新RAM
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool AutoRefreshRAM { get; set; } = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 示波器状态和数据
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class OscilloscopeDataResponse
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// AD采样频率
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public uint ADFrequency { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// AD采样幅度
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public byte ADVpp { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// AD采样最大值
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public byte ADMax { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// AD采样最小值
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public byte ADMin { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 波形数据(Base64编码)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string WaveformData { get; set; } = string.Empty;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,309 @@ public class ResourceController : ControllerBase
 | 
			
		||||
{
 | 
			
		||||
    private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    private readonly UserManager _userManager;
 | 
			
		||||
    private readonly ResourceManager _resourceManager;
 | 
			
		||||
 | 
			
		||||
    public ResourceController(UserManager userManager, ResourceManager resourceManager)
 | 
			
		||||
    {
 | 
			
		||||
        _userManager = userManager;
 | 
			
		||||
        _resourceManager = resourceManager;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 添加资源(文件上传)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="request">添加资源请求</param>
 | 
			
		||||
    /// <param name="file">资源文件</param>
 | 
			
		||||
    /// <returns>添加结果</returns>
 | 
			
		||||
    [Authorize]
 | 
			
		||||
    [HttpPost]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(ResourceInfo), StatusCodes.Status201Created)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status404NotFound)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public async Task<IActionResult> AddResource([FromForm] AddResourceRequest request, IFormFile file)
 | 
			
		||||
    {
 | 
			
		||||
        if (string.IsNullOrWhiteSpace(request.ResourceType) || file == null)
 | 
			
		||||
            return BadRequest("资源类型、资源用途和文件不能为空");
 | 
			
		||||
 | 
			
		||||
        // 验证资源用途
 | 
			
		||||
        if (request.ResourcePurpose != ResourcePurpose.Template && request.ResourcePurpose != ResourcePurpose.User)
 | 
			
		||||
            return BadRequest($"无效的资源用途: {request.ResourcePurpose}");
 | 
			
		||||
 | 
			
		||||
        // 模板资源需要管理员权限
 | 
			
		||||
        if (request.ResourcePurpose == ResourcePurpose.Template && !User.IsInRole("Admin"))
 | 
			
		||||
            return Forbid("只有管理员可以添加模板资源");
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            // 获取当前用户ID
 | 
			
		||||
            var userName = User.Identity?.Name;
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return Unauthorized("无法获取用户信息");
 | 
			
		||||
 | 
			
		||||
            var userResult = _userManager.GetUserByName(userName);
 | 
			
		||||
            if (!userResult.IsSuccessful || !userResult.Value.HasValue)
 | 
			
		||||
                return Unauthorized("用户不存在");
 | 
			
		||||
 | 
			
		||||
            var user = userResult.Value.Value;
 | 
			
		||||
 | 
			
		||||
            // 读取文件数据
 | 
			
		||||
            using var memoryStream = new MemoryStream();
 | 
			
		||||
            await file.CopyToAsync(memoryStream);
 | 
			
		||||
            var fileData = memoryStream.ToArray();
 | 
			
		||||
 | 
			
		||||
            var result = _resourceManager.AddResource(
 | 
			
		||||
                user.ID, request.ResourceType, request.ResourcePurpose,
 | 
			
		||||
                file.FileName, fileData, request.ExamID);
 | 
			
		||||
 | 
			
		||||
            if (!result.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                if (result.Error.Message.Contains("不存在"))
 | 
			
		||||
                    return NotFound(result.Error.Message);
 | 
			
		||||
 | 
			
		||||
                logger.Error($"添加资源时出错: {result.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"添加资源失败: {result.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var resource = result.Value;
 | 
			
		||||
            var resourceInfo = new ResourceInfo
 | 
			
		||||
            {
 | 
			
		||||
                ID = resource.ID.ToString(),
 | 
			
		||||
                Name = resource.ResourceName,
 | 
			
		||||
                Type = resource.ResourceType,
 | 
			
		||||
                Purpose = resource.Purpose,
 | 
			
		||||
                UploadTime = resource.UploadTime,
 | 
			
		||||
                ExamID = resource.ExamID,
 | 
			
		||||
                MimeType = resource.MimeType
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            logger.Info($"成功添加资源: {request.ResourceType}/{request.ResourcePurpose}/{file.FileName}");
 | 
			
		||||
            return CreatedAtAction(nameof(GetResourceById), new { resourceId = resource.ID }, resourceInfo);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"添加资源 {request.ResourceType}/{request.ResourcePurpose}/{file.FileName} 时出错: {ex.Message}");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"添加资源失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 获取资源列表
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="examId">实验ID(可选)</param>
 | 
			
		||||
    /// <param name="resourceType">资源类型(可选)</param>
 | 
			
		||||
    /// <param name="resourcePurpose">资源用途(可选)</param>
 | 
			
		||||
    /// <returns>资源列表</returns>
 | 
			
		||||
    [Authorize]
 | 
			
		||||
    [HttpGet]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(ResourceInfo[]), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult GetResourceList(
 | 
			
		||||
        [FromQuery] string? examId = null,
 | 
			
		||||
        [FromQuery] string? resourceType = null,
 | 
			
		||||
        [FromQuery] ResourcePurpose? resourcePurpose = null)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            // 获取当前用户ID
 | 
			
		||||
            var userName = User.Identity?.Name;
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return Unauthorized("无法获取用户信息");
 | 
			
		||||
 | 
			
		||||
            var userResult = _userManager.GetUserByName(userName);
 | 
			
		||||
            if (!userResult.IsSuccessful || !userResult.Value.HasValue)
 | 
			
		||||
                return Unauthorized("用户不存在");
 | 
			
		||||
 | 
			
		||||
            var user = userResult.Value.Value;
 | 
			
		||||
 | 
			
		||||
            Result<List<Resource>> result;
 | 
			
		||||
            // 管理员
 | 
			
		||||
            if (user.Permission == UserPermission.Admin)
 | 
			
		||||
            {
 | 
			
		||||
                result = _resourceManager.GetFullResourceList(examId, resourceType, resourcePurpose);
 | 
			
		||||
            }
 | 
			
		||||
            // 用户
 | 
			
		||||
            else if (resourcePurpose == ResourcePurpose.User)
 | 
			
		||||
            {
 | 
			
		||||
                result = _resourceManager.GetFullResourceList(examId, resourceType, resourcePurpose, user.ID);
 | 
			
		||||
            }
 | 
			
		||||
            // 模板
 | 
			
		||||
            else if (resourcePurpose == ResourcePurpose.Template)
 | 
			
		||||
            {
 | 
			
		||||
                result = _resourceManager.GetFullResourceList(examId, resourceType, resourcePurpose);
 | 
			
		||||
            }
 | 
			
		||||
            // 其他
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                // 这种情况下需要分别查询并合并结果
 | 
			
		||||
                var userResourcesResult = _resourceManager.GetFullResourceList(
 | 
			
		||||
                    examId, resourceType, ResourcePurpose.User, user.ID);
 | 
			
		||||
                var templateResourcesResult = _resourceManager.GetFullResourceList(
 | 
			
		||||
                    examId, resourceType, ResourcePurpose.Template, null);
 | 
			
		||||
 | 
			
		||||
                if (!userResourcesResult.IsSuccessful || !templateResourcesResult.IsSuccessful)
 | 
			
		||||
                {
 | 
			
		||||
                    logger.Error($"获取资源列表时出错");
 | 
			
		||||
                    return StatusCode(StatusCodes.Status500InternalServerError, "获取资源列表失败");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                var allResources = userResourcesResult.Value.Concat(templateResourcesResult.Value)
 | 
			
		||||
                    .OrderByDescending(r => r.UploadTime);
 | 
			
		||||
                var mergedResourceInfos = allResources.Select(r => new ResourceInfo
 | 
			
		||||
                {
 | 
			
		||||
                    ID = r.ID.ToString(),
 | 
			
		||||
                    Name = r.ResourceName,
 | 
			
		||||
                    Type = r.ResourceType,
 | 
			
		||||
                    Purpose = r.Purpose,
 | 
			
		||||
                    UploadTime = r.UploadTime,
 | 
			
		||||
                    ExamID = r.ExamID,
 | 
			
		||||
                    MimeType = r.MimeType
 | 
			
		||||
                }).ToArray();
 | 
			
		||||
 | 
			
		||||
                logger.Info($"成功获取资源列表,共 {mergedResourceInfos.Length} 个资源");
 | 
			
		||||
                return Ok(mergedResourceInfos);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!result.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"获取资源列表时出错: {result.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"获取资源列表失败: {result.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var resources = result.Value.Select(r => new ResourceInfo
 | 
			
		||||
            {
 | 
			
		||||
                ID = r.ID.ToString(),
 | 
			
		||||
                Name = r.ResourceName,
 | 
			
		||||
                Type = r.ResourceType,
 | 
			
		||||
                Purpose = r.Purpose,
 | 
			
		||||
                UploadTime = r.UploadTime,
 | 
			
		||||
                ExamID = r.ExamID,
 | 
			
		||||
                MimeType = r.MimeType
 | 
			
		||||
            }).ToArray();
 | 
			
		||||
 | 
			
		||||
            logger.Info($"成功获取资源列表,共 {resources.Length} 个资源");
 | 
			
		||||
            return Ok(resources);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"获取资源列表时出错: {ex.Message}");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"获取资源列表失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 根据资源ID下载资源
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="resourceId">资源ID</param>
 | 
			
		||||
    /// <returns>资源文件</returns>
 | 
			
		||||
    [HttpGet("{resourceId}")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(FileResult), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status404NotFound)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult GetResourceById(string resourceId)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var result = _resourceManager.GetResourceById(resourceId);
 | 
			
		||||
 | 
			
		||||
            if (!result.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Warn($"资源不存在: {resourceId}");
 | 
			
		||||
                return NotFound($"资源 {resourceId} 不存在");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var resource = result.Value;
 | 
			
		||||
            logger.Info($"成功获取资源: {resourceId} ({resource.ResourceName})");
 | 
			
		||||
 | 
			
		||||
            var dataRet = _resourceManager.ReadBytesFromPath(resource.Path);
 | 
			
		||||
            if (!dataRet.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"读取资源数据时出错: {dataRet.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"读取资源数据失败: {dataRet.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return File(dataRet.Value, resource.MimeType ?? "application/octet-stream", resource.ResourceName);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"获取资源 {resourceId} 时出错: {ex.Message}");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"获取资源失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 删除资源
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="resourceId">资源ID</param>
 | 
			
		||||
    /// <returns>删除结果</returns>
 | 
			
		||||
    [Authorize]
 | 
			
		||||
    [HttpDelete("{resourceId}")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status204NoContent)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status403Forbidden)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status404NotFound)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult DeleteResource(string resourceId)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            // 获取当前用户信息
 | 
			
		||||
            var userName = User.Identity?.Name;
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return Unauthorized("无法获取用户信息");
 | 
			
		||||
 | 
			
		||||
            var userResult = _userManager.GetUserByName(userName);
 | 
			
		||||
            if (!userResult.IsSuccessful || !userResult.Value.HasValue)
 | 
			
		||||
                return Unauthorized("用户不存在");
 | 
			
		||||
 | 
			
		||||
            var user = userResult.Value.Value;
 | 
			
		||||
 | 
			
		||||
            // 先获取资源信息以验证权限
 | 
			
		||||
            var resourceResult = _resourceManager.GetResourceById(resourceId);
 | 
			
		||||
 | 
			
		||||
            if (!resourceResult.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Warn($"资源不存在: {resourceId}");
 | 
			
		||||
                return NotFound($"资源 {resourceId} 不存在");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var resource = resourceResult.Value;
 | 
			
		||||
 | 
			
		||||
            // 权限检查:管理员可以删除所有资源,普通用户只能删除自己的用户资源
 | 
			
		||||
            if (!User.IsInRole("Admin"))
 | 
			
		||||
            {
 | 
			
		||||
                if (resource.Purpose == ResourcePurpose.Template)
 | 
			
		||||
                    return Forbid("普通用户不能删除模板资源");
 | 
			
		||||
 | 
			
		||||
                if (resource.UserID != user.ID)
 | 
			
		||||
                    return Forbid("只能删除自己的资源");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var deleteResult = _resourceManager.DeleteResource(resourceId);
 | 
			
		||||
            if (!deleteResult.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"删除资源时出错: {deleteResult.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"删除资源失败: {deleteResult.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            logger.Info($"成功删除资源: {resourceId} ({resource.ResourceName})");
 | 
			
		||||
            return NoContent();
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"删除资源 {resourceId} 时出错: {ex.Message}");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"删除资源失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 资源信息类
 | 
			
		||||
    /// </summary>
 | 
			
		||||
@@ -23,7 +326,7 @@ public class ResourceController : ControllerBase
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 资源ID
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int ID { get; set; }
 | 
			
		||||
        public required string ID { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 资源名称
 | 
			
		||||
@@ -38,7 +341,7 @@ public class ResourceController : ControllerBase
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 资源用途(template/user)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string Purpose { get; set; }
 | 
			
		||||
        public required ResourcePurpose Purpose { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 上传时间
 | 
			
		||||
@@ -69,7 +372,7 @@ public class ResourceController : ControllerBase
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 资源用途(template/user)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public required string ResourcePurpose { get; set; }
 | 
			
		||||
        public required ResourcePurpose ResourcePurpose { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 所属实验ID(可选)
 | 
			
		||||
@@ -77,301 +380,4 @@ public class ResourceController : ControllerBase
 | 
			
		||||
        public string? ExamID { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 添加资源(文件上传)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="request">添加资源请求</param>
 | 
			
		||||
    /// <param name="file">资源文件</param>
 | 
			
		||||
    /// <returns>添加结果</returns>
 | 
			
		||||
    [Authorize]
 | 
			
		||||
    [HttpPost]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(ResourceInfo), StatusCodes.Status201Created)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status404NotFound)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public async Task<IActionResult> AddResource([FromForm] AddResourceRequest request, IFormFile file)
 | 
			
		||||
    {
 | 
			
		||||
        if (string.IsNullOrWhiteSpace(request.ResourceType) || string.IsNullOrWhiteSpace(request.ResourcePurpose) || file == null)
 | 
			
		||||
            return BadRequest("资源类型、资源用途和文件不能为空");
 | 
			
		||||
 | 
			
		||||
        // 验证资源用途
 | 
			
		||||
        if (request.ResourcePurpose != Resource.ResourcePurposes.Template && request.ResourcePurpose != Resource.ResourcePurposes.User)
 | 
			
		||||
            return BadRequest($"无效的资源用途: {request.ResourcePurpose}");
 | 
			
		||||
 | 
			
		||||
        // 模板资源需要管理员权限
 | 
			
		||||
        if (request.ResourcePurpose == Resource.ResourcePurposes.Template && !User.IsInRole("Admin"))
 | 
			
		||||
            return Forbid("只有管理员可以添加模板资源");
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            
 | 
			
		||||
            // 获取当前用户ID
 | 
			
		||||
            var userName = User.Identity?.Name;
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return Unauthorized("无法获取用户信息");
 | 
			
		||||
 | 
			
		||||
            var userResult = db.GetUserByName(userName);
 | 
			
		||||
            if (!userResult.IsSuccessful || !userResult.Value.HasValue)
 | 
			
		||||
                return Unauthorized("用户不存在");
 | 
			
		||||
 | 
			
		||||
            var user = userResult.Value.Value;
 | 
			
		||||
 | 
			
		||||
            // 读取文件数据
 | 
			
		||||
            using var memoryStream = new MemoryStream();
 | 
			
		||||
            await file.CopyToAsync(memoryStream);
 | 
			
		||||
            var fileData = memoryStream.ToArray();
 | 
			
		||||
 | 
			
		||||
            var result = db.AddResource(user.ID, request.ResourceType, request.ResourcePurpose, file.FileName, fileData, request.ExamID);
 | 
			
		||||
 | 
			
		||||
            if (!result.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                if (result.Error.Message.Contains("不存在"))
 | 
			
		||||
                    return NotFound(result.Error.Message);
 | 
			
		||||
                
 | 
			
		||||
                logger.Error($"添加资源时出错: {result.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"添加资源失败: {result.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var resource = result.Value;
 | 
			
		||||
            var resourceInfo = new ResourceInfo
 | 
			
		||||
            {
 | 
			
		||||
                ID = resource.ID,
 | 
			
		||||
                Name = resource.ResourceName,
 | 
			
		||||
                Type = resource.ResourceType,
 | 
			
		||||
                Purpose = resource.ResourcePurpose,
 | 
			
		||||
                UploadTime = resource.UploadTime,
 | 
			
		||||
                ExamID = resource.ExamID,
 | 
			
		||||
                MimeType = resource.MimeType
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            logger.Info($"成功添加资源: {request.ResourceType}/{request.ResourcePurpose}/{file.FileName}");
 | 
			
		||||
            return CreatedAtAction(nameof(GetResourceById), new { resourceId = resource.ID }, resourceInfo);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"添加资源 {request.ResourceType}/{request.ResourcePurpose}/{file.FileName} 时出错: {ex.Message}");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"添加资源失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 获取资源列表
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="examId">实验ID(可选)</param>
 | 
			
		||||
    /// <param name="resourceType">资源类型(可选)</param>
 | 
			
		||||
    /// <param name="resourcePurpose">资源用途(可选)</param>
 | 
			
		||||
    /// <returns>资源列表</returns>
 | 
			
		||||
    [Authorize]
 | 
			
		||||
    [HttpGet]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(ResourceInfo[]), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult GetResourceList([FromQuery] string? examId = null, [FromQuery] string? resourceType = null, [FromQuery] string? resourcePurpose = null)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            
 | 
			
		||||
            // 获取当前用户ID
 | 
			
		||||
            var userName = User.Identity?.Name;
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return Unauthorized("无法获取用户信息");
 | 
			
		||||
 | 
			
		||||
            var userResult = db.GetUserByName(userName);
 | 
			
		||||
            if (!userResult.IsSuccessful || !userResult.Value.HasValue)
 | 
			
		||||
                return Unauthorized("用户不存在");
 | 
			
		||||
 | 
			
		||||
            var user = userResult.Value.Value;
 | 
			
		||||
 | 
			
		||||
            // 普通用户只能查看自己的资源和模板资源
 | 
			
		||||
            Guid? userId = null;
 | 
			
		||||
            if (!User.IsInRole("Admin"))
 | 
			
		||||
            {
 | 
			
		||||
                // 如果指定了用户资源用途,则只查看自己的资源
 | 
			
		||||
                if (resourcePurpose == Resource.ResourcePurposes.User)
 | 
			
		||||
                {
 | 
			
		||||
                    userId = user.ID;
 | 
			
		||||
                }
 | 
			
		||||
                // 如果指定了模板资源用途,则不限制用户ID
 | 
			
		||||
                else if (resourcePurpose == Resource.ResourcePurposes.Template)
 | 
			
		||||
                {
 | 
			
		||||
                    userId = null;
 | 
			
		||||
                }
 | 
			
		||||
                // 如果没有指定用途,则查看自己的用户资源和所有模板资源
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    // 这种情况下需要分别查询并合并结果
 | 
			
		||||
                    var userResourcesResult = db.GetFullResourceList(examId, resourceType, Resource.ResourcePurposes.User, user.ID);
 | 
			
		||||
                    var templateResourcesResult = db.GetFullResourceList(examId, resourceType, Resource.ResourcePurposes.Template, null);
 | 
			
		||||
                    
 | 
			
		||||
                    if (!userResourcesResult.IsSuccessful || !templateResourcesResult.IsSuccessful)
 | 
			
		||||
                    {
 | 
			
		||||
                        logger.Error($"获取资源列表时出错");
 | 
			
		||||
                        return StatusCode(StatusCodes.Status500InternalServerError, "获取资源列表失败");
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    var allResources = userResourcesResult.Value.Concat(templateResourcesResult.Value)
 | 
			
		||||
                        .OrderByDescending(r => r.UploadTime);
 | 
			
		||||
                    var mergedResourceInfos = allResources.Select(r => new ResourceInfo
 | 
			
		||||
                    {
 | 
			
		||||
                        ID = r.ID,
 | 
			
		||||
                        Name = r.ResourceName,
 | 
			
		||||
                        Type = r.ResourceType,
 | 
			
		||||
                        Purpose = r.ResourcePurpose,
 | 
			
		||||
                        UploadTime = r.UploadTime,
 | 
			
		||||
                        ExamID = r.ExamID,
 | 
			
		||||
                        MimeType = r.MimeType
 | 
			
		||||
                    }).ToArray();
 | 
			
		||||
 | 
			
		||||
                    logger.Info($"成功获取资源列表,共 {mergedResourceInfos.Length} 个资源");
 | 
			
		||||
                    return Ok(mergedResourceInfos);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var result = db.GetFullResourceList(examId, resourceType, resourcePurpose, userId);
 | 
			
		||||
 | 
			
		||||
            if (!result.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"获取资源列表时出错: {result.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"获取资源列表失败: {result.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var resources = result.Value.Select(r => new ResourceInfo
 | 
			
		||||
            {
 | 
			
		||||
                ID = r.ID,
 | 
			
		||||
                Name = r.ResourceName,
 | 
			
		||||
                Type = r.ResourceType,
 | 
			
		||||
                Purpose = r.ResourcePurpose,
 | 
			
		||||
                UploadTime = r.UploadTime,
 | 
			
		||||
                ExamID = r.ExamID,
 | 
			
		||||
                MimeType = r.MimeType
 | 
			
		||||
            }).ToArray();
 | 
			
		||||
 | 
			
		||||
            logger.Info($"成功获取资源列表,共 {resources.Length} 个资源");
 | 
			
		||||
            return Ok(resources);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"获取资源列表时出错: {ex.Message}");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"获取资源列表失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 根据资源ID下载资源
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="resourceId">资源ID</param>
 | 
			
		||||
    /// <returns>资源文件</returns>
 | 
			
		||||
    [HttpGet("{resourceId}")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(FileResult), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status404NotFound)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult GetResourceById(int resourceId)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var result = db.GetResourceById(resourceId);
 | 
			
		||||
 | 
			
		||||
            if (!result.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"获取资源时出错: {result.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"获取资源失败: {result.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!result.Value.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Warn($"资源不存在: {resourceId}");
 | 
			
		||||
                return NotFound($"资源 {resourceId} 不存在");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var resource = result.Value.Value;
 | 
			
		||||
            logger.Info($"成功获取资源: {resourceId} ({resource.ResourceName})");
 | 
			
		||||
            return File(resource.Data, resource.MimeType ?? "application/octet-stream", resource.ResourceName);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"获取资源 {resourceId} 时出错: {ex.Message}");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"获取资源失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 删除资源
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="resourceId">资源ID</param>
 | 
			
		||||
    /// <returns>删除结果</returns>
 | 
			
		||||
    [Authorize]
 | 
			
		||||
    [HttpDelete("{resourceId}")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status204NoContent)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status403Forbidden)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status404NotFound)]
 | 
			
		||||
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IActionResult DeleteResource(int resourceId)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            
 | 
			
		||||
            // 获取当前用户信息
 | 
			
		||||
            var userName = User.Identity?.Name;
 | 
			
		||||
            if (string.IsNullOrEmpty(userName))
 | 
			
		||||
                return Unauthorized("无法获取用户信息");
 | 
			
		||||
 | 
			
		||||
            var userResult = db.GetUserByName(userName);
 | 
			
		||||
            if (!userResult.IsSuccessful || !userResult.Value.HasValue)
 | 
			
		||||
                return Unauthorized("用户不存在");
 | 
			
		||||
 | 
			
		||||
            var user = userResult.Value.Value;
 | 
			
		||||
 | 
			
		||||
            // 先获取资源信息以验证权限
 | 
			
		||||
            var resourceResult = db.GetResourceById(resourceId);
 | 
			
		||||
            if (!resourceResult.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"获取资源时出错: {resourceResult.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"获取资源失败: {resourceResult.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!resourceResult.Value.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Warn($"资源不存在: {resourceId}");
 | 
			
		||||
                return NotFound($"资源 {resourceId} 不存在");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var resource = resourceResult.Value.Value;
 | 
			
		||||
 | 
			
		||||
            // 权限检查:管理员可以删除所有资源,普通用户只能删除自己的用户资源
 | 
			
		||||
            if (!User.IsInRole("Admin"))
 | 
			
		||||
            {
 | 
			
		||||
                if (resource.ResourcePurpose == Resource.ResourcePurposes.Template)
 | 
			
		||||
                    return Forbid("普通用户不能删除模板资源");
 | 
			
		||||
                
 | 
			
		||||
                if (resource.UserID != user.ID)
 | 
			
		||||
                    return Forbid("只能删除自己的资源");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var deleteResult = db.DeleteResource(resourceId);
 | 
			
		||||
            if (!deleteResult.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"删除资源时出错: {deleteResult.Error.Message}");
 | 
			
		||||
                return StatusCode(StatusCodes.Status500InternalServerError, $"删除资源失败: {deleteResult.Error.Message}");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            logger.Info($"成功删除资源: {resourceId} ({resource.ResourceName})");
 | 
			
		||||
            return NoContent();
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"删除资源 {resourceId} 时出错: {ex.Message}");
 | 
			
		||||
            return StatusCode(StatusCodes.Status500InternalServerError, $"删除资源失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,39 +3,22 @@ using Microsoft.AspNetCore.Cors;
 | 
			
		||||
using Microsoft.AspNetCore.Mvc;
 | 
			
		||||
using Microsoft.AspNetCore.Authorization;
 | 
			
		||||
using System.Security.Claims;
 | 
			
		||||
using Database;
 | 
			
		||||
using DotNext;
 | 
			
		||||
using server.Services;
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// 视频流控制器,支持动态配置摄像头连接
 | 
			
		||||
/// </summary>
 | 
			
		||||
[ApiController]
 | 
			
		||||
[Authorize]
 | 
			
		||||
[EnableCors("Users")]
 | 
			
		||||
[Route("api/[controller]")]
 | 
			
		||||
public class VideoStreamController : ControllerBase
 | 
			
		||||
{
 | 
			
		||||
    private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
    private readonly server.Services.HttpVideoStreamService _videoStreamService;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 分辨率配置请求模型
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class ResolutionConfigRequest
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 宽度
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [Required]
 | 
			
		||||
        [Range(640, 1920, ErrorMessage = "宽度必须在640-1920范围内")]
 | 
			
		||||
        public int Width { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 高度
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [Required]
 | 
			
		||||
        [Range(480, 1080, ErrorMessage = "高度必须在480-1080范围内")]
 | 
			
		||||
        public int Height { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
    private readonly HttpVideoStreamService _videoStreamService;
 | 
			
		||||
    private readonly Database.UserManager _userManager;
 | 
			
		||||
 | 
			
		||||
    public class AvailableResolutionsResponse
 | 
			
		||||
    {
 | 
			
		||||
@@ -49,10 +32,40 @@ public class VideoStreamController : ControllerBase
 | 
			
		||||
    /// 初始化HTTP视频流控制器
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="videoStreamService">HTTP视频流服务</param>
 | 
			
		||||
    public VideoStreamController(server.Services.HttpVideoStreamService videoStreamService)
 | 
			
		||||
    /// <param name="userManager">用户管理服务</param>
 | 
			
		||||
    public VideoStreamController(
 | 
			
		||||
        HttpVideoStreamService videoStreamService, Database.UserManager userManager)
 | 
			
		||||
    {
 | 
			
		||||
        logger.Info("创建VideoStreamController,命名空间:{Namespace}", this.GetType().Namespace);
 | 
			
		||||
        _videoStreamService = videoStreamService;
 | 
			
		||||
        _userManager = userManager;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Optional<string> TryGetBoardId()
 | 
			
		||||
    {
 | 
			
		||||
        var userName = User.FindFirstValue(ClaimTypes.Name);
 | 
			
		||||
        if (string.IsNullOrEmpty(userName))
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error("User name not found in claims.");
 | 
			
		||||
            return Optional<string>.None;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var userRet = _userManager.GetUserByName(userName);
 | 
			
		||||
        if (!userRet.IsSuccessful || !userRet.Value.HasValue)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error("User not found.");
 | 
			
		||||
            return Optional<string>.None;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var user = userRet.Value.Value;
 | 
			
		||||
        var boardId = user.BoardID;
 | 
			
		||||
        if (boardId == Guid.Empty)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error("No board bound to this user.");
 | 
			
		||||
            return Optional<string>.None;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return boardId.ToString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Optional<string> TryGetBoardId()
 | 
			
		||||
@@ -93,11 +106,10 @@ public class VideoStreamController : ControllerBase
 | 
			
		||||
    /// 获取 HTTP 视频流服务状态
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns>服务状态信息</returns>
 | 
			
		||||
    [HttpGet("Status")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
 | 
			
		||||
    [HttpGet("ServiceStatus")]
 | 
			
		||||
    [ProducesResponseType(typeof(VideoStreamServiceStatus), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IResult GetStatus()
 | 
			
		||||
    public IResult GetServiceStatus()
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
@@ -115,8 +127,7 @@ public class VideoStreamController : ControllerBase
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [HttpGet("MyEndpoint")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(typeof(VideoStreamEndpoint), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IResult MyEndpoint()
 | 
			
		||||
    {
 | 
			
		||||
@@ -139,7 +150,6 @@ public class VideoStreamController : ControllerBase
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns>连接测试结果</returns>
 | 
			
		||||
    [HttpPost("TestConnection")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public async Task<IResult> TestConnection()
 | 
			
		||||
@@ -172,14 +182,16 @@ public class VideoStreamController : ControllerBase
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [HttpPost("DisableTransmission")]
 | 
			
		||||
    public async Task<IActionResult> DisableHdmiTransmission()
 | 
			
		||||
    [HttpPost("SetVideoStreamEnable")]
 | 
			
		||||
    [ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public async Task<IActionResult> SetVideoStreamEnable(bool enable)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var boardId = TryGetBoardId().OrThrow(() => new ArgumentException("Board ID is required"));
 | 
			
		||||
 | 
			
		||||
            await _videoStreamService.DisableHdmiTransmissionAsync(boardId.ToString());
 | 
			
		||||
            await _videoStreamService.SetVideoStreamEnableAsync(boardId.ToString(), enable);
 | 
			
		||||
            return Ok($"HDMI transmission for board {boardId} disabled.");
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
@@ -241,7 +253,7 @@ public class VideoStreamController : ControllerBase
 | 
			
		||||
    /// <returns>支持的分辨率列表</returns>
 | 
			
		||||
    [HttpGet("SupportedResolutions")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(typeof(AvailableResolutionsResponse[]), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public IResult GetSupportedResolutions()
 | 
			
		||||
    {
 | 
			
		||||
@@ -349,4 +361,65 @@ public class VideoStreamController : ControllerBase
 | 
			
		||||
            return TypedResults.InternalServerError($"执行自动对焦失败: {ex.Message}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 配置摄像头连接参数
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns>配置结果</returns>
 | 
			
		||||
    [HttpPost("ConfigureCamera")]
 | 
			
		||||
    [EnableCors("Users")]
 | 
			
		||||
    [ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
 | 
			
		||||
    [ProducesResponseType(typeof(object), StatusCodes.Status400BadRequest)]
 | 
			
		||||
    [ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
 | 
			
		||||
    public async Task<IResult> ConfigureCamera()
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var boardId = TryGetBoardId().OrThrow(() => new Exception("Board ID not found"));
 | 
			
		||||
 | 
			
		||||
            var ret = await _videoStreamService.ConfigureCameraAsync(boardId);
 | 
			
		||||
 | 
			
		||||
            if (ret)
 | 
			
		||||
            {
 | 
			
		||||
                return TypedResults.Ok(new { Message = "配置成功" });
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                return TypedResults.BadRequest(new { Message = "配置失败" });
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error(ex, "配置摄像头连接失败");
 | 
			
		||||
            return TypedResults.InternalServerError(ex.Message);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 分辨率配置请求模型
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class ResolutionConfigRequest
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 宽度
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [Required]
 | 
			
		||||
        [Range(640, 1920, ErrorMessage = "宽度必须在640-1920范围内")]
 | 
			
		||||
        public int Width { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 高度
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [Required]
 | 
			
		||||
        [Range(480, 1080, ErrorMessage = "高度必须在480-1080范围内")]
 | 
			
		||||
        public int Height { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class AvailableResolutionsResponse
 | 
			
		||||
    {
 | 
			
		||||
        public int Width { get; set; }
 | 
			
		||||
        public int Height { get; set; }
 | 
			
		||||
        public string Name { get; set; } = string.Empty;
 | 
			
		||||
        public string Value => $"{Width}x{Height}";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										98
									
								
								server/src/Database/Connection.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								server/src/Database/Connection.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,98 @@
 | 
			
		||||
using DotNext;
 | 
			
		||||
using LinqToDB;
 | 
			
		||||
using LinqToDB.Data;
 | 
			
		||||
 | 
			
		||||
namespace Database;
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// 应用程序数据连接类,用于与数据库交互
 | 
			
		||||
/// </summary>
 | 
			
		||||
public class AppDataConnection : DataConnection
 | 
			
		||||
{
 | 
			
		||||
    private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    static readonly string DATABASE_FILEPATH = $"{Global.DataPath}/Database.sqlite";
 | 
			
		||||
 | 
			
		||||
    static readonly LinqToDB.DataOptions options =
 | 
			
		||||
        new LinqToDB.DataOptions().UseSQLite($"Data Source={DATABASE_FILEPATH}");
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 用户表
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public ITable<User> UserTable => this.GetTable<User>();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// FPGA 板子表
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public ITable<Board> BoardTable => this.GetTable<Board>();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验表
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public ITable<Exam> ExamTable => this.GetTable<Exam>();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 资源表(统一管理实验资源、用户比特流等)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public ITable<Resource> ResourceTable => this.GetTable<Resource>();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 初始化应用程序数据连接
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public AppDataConnection() : base(options)
 | 
			
		||||
    {
 | 
			
		||||
        var filePath = Path.GetDirectoryName(DATABASE_FILEPATH);
 | 
			
		||||
        if (!string.IsNullOrEmpty(filePath) && !Directory.Exists(filePath))
 | 
			
		||||
        {
 | 
			
		||||
            Directory.CreateDirectory(filePath);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!Path.Exists(DATABASE_FILEPATH))
 | 
			
		||||
        {
 | 
			
		||||
            logger.Info($"数据库文件不存在,正在创建新数据库: {DATABASE_FILEPATH}");
 | 
			
		||||
            LinqToDB.DataProvider.SQLite.SQLiteTools.CreateDatabase(DATABASE_FILEPATH);
 | 
			
		||||
            this.CreateAllTables();
 | 
			
		||||
            var user = new User()
 | 
			
		||||
            {
 | 
			
		||||
                Name = "Admin",
 | 
			
		||||
                EMail = "selfconfusion@gmail.com",
 | 
			
		||||
                Password = "12345678",
 | 
			
		||||
                Permission = Database.UserPermission.Admin,
 | 
			
		||||
            };
 | 
			
		||||
            this.Insert(user);
 | 
			
		||||
            logger.Info("默认管理员用户已创建");
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            logger.Info($"数据库连接已建立: {DATABASE_FILEPATH}");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 创建所有数据库表
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public void CreateAllTables()
 | 
			
		||||
    {
 | 
			
		||||
        logger.Info("正在创建数据库表...");
 | 
			
		||||
        this.CreateTable<User>();
 | 
			
		||||
        this.CreateTable<Board>();
 | 
			
		||||
        this.CreateTable<Exam>();
 | 
			
		||||
        this.CreateTable<Resource>();
 | 
			
		||||
        logger.Info("数据库表创建完成");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 删除所有数据库表
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public void DropAllTables()
 | 
			
		||||
    {
 | 
			
		||||
        logger.Warn("正在删除所有数据库表...");
 | 
			
		||||
        this.DropTable<User>();
 | 
			
		||||
        this.DropTable<Board>();
 | 
			
		||||
        this.DropTable<Exam>();
 | 
			
		||||
        this.DropTable<Resource>();
 | 
			
		||||
        logger.Warn("所有数据库表已删除");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										154
									
								
								server/src/Database/ExamManager.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										154
									
								
								server/src/Database/ExamManager.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,154 @@
 | 
			
		||||
using DotNext;
 | 
			
		||||
using LinqToDB;
 | 
			
		||||
using LinqToDB.Data;
 | 
			
		||||
 | 
			
		||||
namespace Database;
 | 
			
		||||
 | 
			
		||||
public class ExamManager
 | 
			
		||||
{
 | 
			
		||||
    private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    private readonly AppDataConnection _db;
 | 
			
		||||
 | 
			
		||||
    public ExamManager(AppDataConnection db)
 | 
			
		||||
    {
 | 
			
		||||
        this._db = db;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 创建新实验
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="id">实验ID</param>
 | 
			
		||||
    /// <param name="name">实验名称</param>
 | 
			
		||||
    /// <param name="description">实验描述</param>
 | 
			
		||||
    /// <param name="tags">实验标签</param>
 | 
			
		||||
    /// <param name="difficulty">实验难度</param>
 | 
			
		||||
    /// <param name="isVisibleToUsers">普通用户是否可见</param>
 | 
			
		||||
    /// <returns>创建的实验</returns>
 | 
			
		||||
    public Result<Exam> CreateExam(string id, string name, string description, string[]? tags = null, int difficulty = 1, bool isVisibleToUsers = true)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            // 检查实验ID是否已存在
 | 
			
		||||
            var existingExam = _db.ExamTable.Where(e => e.ID.ToString() == id).FirstOrDefault();
 | 
			
		||||
            if (existingExam != null)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"实验ID已存在: {id}");
 | 
			
		||||
                return new(new Exception($"实验ID已存在: {id}"));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var exam = new Exam
 | 
			
		||||
            {
 | 
			
		||||
                ID = id,
 | 
			
		||||
                Name = name,
 | 
			
		||||
                Description = description,
 | 
			
		||||
                Difficulty = Math.Max(1, Math.Min(5, difficulty)),
 | 
			
		||||
                IsVisibleToUsers = isVisibleToUsers,
 | 
			
		||||
                CreatedTime = DateTime.Now,
 | 
			
		||||
                UpdatedTime = DateTime.Now
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            if (tags != null)
 | 
			
		||||
            {
 | 
			
		||||
                exam.SetTagsList(tags);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            _db.Insert(exam);
 | 
			
		||||
            logger.Info($"新实验已创建: {id} ({name})");
 | 
			
		||||
            return new(exam);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"创建实验时出错: {ex.Message}");
 | 
			
		||||
            return new(ex);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 更新实验信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="id">实验ID</param>
 | 
			
		||||
    /// <param name="name">实验名称</param>
 | 
			
		||||
    /// <param name="description">实验描述</param>
 | 
			
		||||
    /// <param name="tags">实验标签</param>
 | 
			
		||||
    /// <param name="difficulty">实验难度</param>
 | 
			
		||||
    /// <param name="isVisibleToUsers">普通用户是否可见</param>
 | 
			
		||||
    /// <returns>更新的记录数</returns>
 | 
			
		||||
    public Result<int> UpdateExam(string id, string? name = null, string? description = null, string[]? tags = null, int? difficulty = null, bool? isVisibleToUsers = null)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            int result = 0;
 | 
			
		||||
 | 
			
		||||
            if (name != null)
 | 
			
		||||
            {
 | 
			
		||||
                result += _db.ExamTable.Where(e => e.ID.ToString() == id).Set(e => e.Name, name).Update();
 | 
			
		||||
            }
 | 
			
		||||
            if (description != null)
 | 
			
		||||
            {
 | 
			
		||||
                result += _db.ExamTable.Where(e => e.ID.ToString() == id).Set(e => e.Description, description).Update();
 | 
			
		||||
            }
 | 
			
		||||
            if (tags != null)
 | 
			
		||||
            {
 | 
			
		||||
                var tagsString = string.Join(",", tags.Where(tag => !string.IsNullOrWhiteSpace(tag)).Select(tag => tag.Trim()));
 | 
			
		||||
                result += _db.ExamTable.Where(e => e.ID.ToString() == id).Set(e => e.Tags, tagsString).Update();
 | 
			
		||||
            }
 | 
			
		||||
            if (difficulty.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
                result += _db.ExamTable.Where(e => e.ID.ToString() == id).Set(e => e.Difficulty, Math.Max(1, Math.Min(5, difficulty.Value))).Update();
 | 
			
		||||
            }
 | 
			
		||||
            if (isVisibleToUsers.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
                result += _db.ExamTable.Where(e => e.ID.ToString() == id).Set(e => e.IsVisibleToUsers, isVisibleToUsers.Value).Update();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 更新时间
 | 
			
		||||
            _db.ExamTable.Where(e => e.ID.ToString() == id).Set(e => e.UpdatedTime, DateTime.Now).Update();
 | 
			
		||||
 | 
			
		||||
            logger.Info($"实验已更新: {id},更新记录数: {result}");
 | 
			
		||||
            return new(result);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"更新实验时出错: {ex.Message}");
 | 
			
		||||
            return new(ex);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 获取所有实验信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns>所有实验的数组</returns>
 | 
			
		||||
    public Exam[] GetAllExams()
 | 
			
		||||
    {
 | 
			
		||||
        var exams = _db.ExamTable.OrderBy(e => e.ID).ToArray();
 | 
			
		||||
        logger.Debug($"获取所有实验,共 {exams.Length} 个");
 | 
			
		||||
        return exams;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 根据实验ID获取实验信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="examId">实验ID</param>
 | 
			
		||||
    /// <returns>包含实验信息的结果,如果未找到则返回空</returns>
 | 
			
		||||
    public Result<Optional<Exam>> GetExamByID(string examId)
 | 
			
		||||
    {
 | 
			
		||||
        var exams = _db.ExamTable.Where(exam => exam.ID.ToString() == examId).ToArray();
 | 
			
		||||
 | 
			
		||||
        if (exams.Length > 1)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"数据库中存在多个相同ID的实验: {examId}");
 | 
			
		||||
            return new(new Exception($"数据库中存在多个相同ID的实验: {examId}"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (exams.Length == 0)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Info($"未找到ID对应的实验: {examId}");
 | 
			
		||||
            return new(Optional<Exam>.None);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        logger.Debug($"成功获取实验信息: {examId}");
 | 
			
		||||
        return new(exams[0]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										356
									
								
								server/src/Database/ResourceManager.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										356
									
								
								server/src/Database/ResourceManager.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,356 @@
 | 
			
		||||
using DotNext;
 | 
			
		||||
using LinqToDB;
 | 
			
		||||
using LinqToDB.Data;
 | 
			
		||||
using System.Security.Cryptography;
 | 
			
		||||
 | 
			
		||||
namespace Database;
 | 
			
		||||
 | 
			
		||||
public class ResourceManager
 | 
			
		||||
{
 | 
			
		||||
    private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    private readonly AppDataConnection _db;
 | 
			
		||||
 | 
			
		||||
    public ResourceManager(AppDataConnection db)
 | 
			
		||||
    {
 | 
			
		||||
        this._db = db;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 根据文件扩展名获取MIME类型
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="extension">文件扩展名</param>
 | 
			
		||||
    /// <param name="fileName">文件名(可选,用于特殊文件判断)</param>
 | 
			
		||||
    /// <returns>MIME类型</returns>
 | 
			
		||||
    private string GetMimeTypeFromExtension(string extension, string fileName = "")
 | 
			
		||||
    {
 | 
			
		||||
        // 特殊文件名处理
 | 
			
		||||
        if (!string.IsNullOrEmpty(fileName) && fileName.Equals("diagram.json", StringComparison.OrdinalIgnoreCase))
 | 
			
		||||
        {
 | 
			
		||||
            return "application/json";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return extension.ToLowerInvariant() switch
 | 
			
		||||
        {
 | 
			
		||||
            ".png" => "image/png",
 | 
			
		||||
            ".jpg" or ".jpeg" => "image/jpeg",
 | 
			
		||||
            ".gif" => "image/gif",
 | 
			
		||||
            ".bmp" => "image/bmp",
 | 
			
		||||
            ".svg" => "image/svg+xml",
 | 
			
		||||
            ".bit" => "application/octet-stream",
 | 
			
		||||
            ".sbit" => "application/octet-stream",
 | 
			
		||||
            ".bin" => "application/octet-stream",
 | 
			
		||||
            ".mcs" => "application/octet-stream",
 | 
			
		||||
            ".hex" => "text/plain",
 | 
			
		||||
            ".json" => "application/json",
 | 
			
		||||
            ".zip" => "application/zip",
 | 
			
		||||
            ".md" => "text/markdown",
 | 
			
		||||
            _ => "application/octet-stream"
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 将二进制数据写入指定路径
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="path">目标文件路径</param>
 | 
			
		||||
    /// <param name="data">要写入的二进制数据</param>
 | 
			
		||||
    /// <returns>写入是否成功</returns>
 | 
			
		||||
    public Result<bool> WriteBytesToPath(string path, byte[] data)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var filePath = Path.Combine(Global.DataPath, path);
 | 
			
		||||
            var directory = Path.GetDirectoryName(filePath);
 | 
			
		||||
            if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
 | 
			
		||||
            {
 | 
			
		||||
                Directory.CreateDirectory(directory);
 | 
			
		||||
            }
 | 
			
		||||
            File.WriteAllBytes(filePath, data);
 | 
			
		||||
            logger.Info($"成功写入文件: {filePath},大小: {data.Length} bytes");
 | 
			
		||||
            return new(true);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"写入文件时出错: {ex.Message}");
 | 
			
		||||
            return new(ex);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 从指定路径读取二进制数据
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="path">要读取的文件路径</param>
 | 
			
		||||
    /// <returns>读取到的二进制数据</returns>
 | 
			
		||||
    public Result<byte[]> ReadBytesFromPath(string path)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var filePath = Path.Combine(Global.DataPath, path);
 | 
			
		||||
            if (!File.Exists(filePath))
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"文件不存在: {filePath}");
 | 
			
		||||
                return new(new Exception($"文件不存在: {filePath}"));
 | 
			
		||||
            }
 | 
			
		||||
            var data = File.ReadAllBytes(filePath);
 | 
			
		||||
            logger.Info($"成功读取文件: {filePath},大小: {data.Length} bytes");
 | 
			
		||||
            return new(data);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"读取文件时出错: {ex.Message}");
 | 
			
		||||
            return new(ex);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 添加资源
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="userId">上传用户ID</param>
 | 
			
		||||
    /// <param name="resourceType">资源类型</param>
 | 
			
		||||
    /// <param name="resourcePurpose">资源用途(template 或 user)</param>
 | 
			
		||||
    /// <param name="resourceName">资源名称</param>
 | 
			
		||||
    /// <param name="data">资源二进制数据</param>
 | 
			
		||||
    /// <param name="examId">所属实验ID(可选)</param>
 | 
			
		||||
    /// <param name="mimeType">MIME类型(可选,将根据文件扩展名自动确定)</param>
 | 
			
		||||
    /// <returns>创建的资源</returns>
 | 
			
		||||
    public Result<Resource> AddResource(
 | 
			
		||||
        Guid userId, string resourceType, ResourcePurpose resourcePurpose,
 | 
			
		||||
        string resourceName, byte[] data, string? examId = null, string? mimeType = null)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            // 验证用户是否存在
 | 
			
		||||
            var user = _db.UserTable.Where(u => u.ID == userId).FirstOrDefault();
 | 
			
		||||
            if (user == null)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"用户不存在: {userId}");
 | 
			
		||||
                return new(new Exception($"用户不存在: {userId}"));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 如果指定了实验ID,验证实验是否存在
 | 
			
		||||
            if (!string.IsNullOrEmpty(examId))
 | 
			
		||||
            {
 | 
			
		||||
                var exam = _db.ExamTable.Where(e => e.ID.ToString() == examId).FirstOrDefault();
 | 
			
		||||
                if (exam == null)
 | 
			
		||||
                {
 | 
			
		||||
                    logger.Error($"实验不存在: {examId}");
 | 
			
		||||
                    return new(new Exception($"实验不存在: {examId}"));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 验证资源用途
 | 
			
		||||
            if (resourcePurpose != ResourcePurpose.Template &&
 | 
			
		||||
                resourcePurpose != ResourcePurpose.User)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"无效的资源用途: {resourcePurpose}");
 | 
			
		||||
                return new(new Exception($"无效的资源用途: {resourcePurpose}"));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 如果未指定MIME类型,根据文件扩展名自动确定
 | 
			
		||||
            if (string.IsNullOrEmpty(mimeType))
 | 
			
		||||
            {
 | 
			
		||||
                var extension = Path.GetExtension(resourceName).ToLowerInvariant();
 | 
			
		||||
                mimeType = GetMimeTypeFromExtension(extension, resourceName);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 计算数据的SHA256
 | 
			
		||||
            var sha256 = SHA256.HashData(data).ToString();
 | 
			
		||||
            if (string.IsNullOrEmpty(sha256))
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"SHA256计算失败");
 | 
			
		||||
                return new(new Exception("SHA256计算失败"));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var duplicateResource = _db.ResourceTable.Where(r => r.SHA256 == sha256).FirstOrDefault();
 | 
			
		||||
            if (duplicateResource != null && duplicateResource.ResourceName == resourceName)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Info($"资源已存在: {resourceName}");
 | 
			
		||||
                return duplicateResource;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var nowTime = DateTime.Now;
 | 
			
		||||
            var resource = new Resource
 | 
			
		||||
            {
 | 
			
		||||
                UserID = userId,
 | 
			
		||||
                ExamID = examId,
 | 
			
		||||
                ResourceType = resourceType,
 | 
			
		||||
                Purpose = resourcePurpose,
 | 
			
		||||
                ResourceName = resourceName,
 | 
			
		||||
                Path = duplicateResource == null ?
 | 
			
		||||
                    Path.Combine(resourceType, nowTime.ToString("yyyyMMddHH"), resourceName) :
 | 
			
		||||
                    duplicateResource.Path,
 | 
			
		||||
                SHA256 = sha256,
 | 
			
		||||
                MimeType = mimeType,
 | 
			
		||||
                UploadTime = nowTime
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var insertedId = _db.Insert(resource);
 | 
			
		||||
 | 
			
		||||
            var writeRet = WriteBytesToPath(resource.Path, data);
 | 
			
		||||
            if (writeRet.IsSuccessful && writeRet.Value)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Info($"新资源已添加: {userId}/{resourceType}/{resourcePurpose}/{resourceName} ({data.Length} bytes)" +
 | 
			
		||||
                           (examId != null ? $" [实验: {examId}]" : "") + $" [ID: {resource.ID}]");
 | 
			
		||||
                return new(resource);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                _db.ResourceTable.Where(r => r.ID == resource.ID).Delete();
 | 
			
		||||
 | 
			
		||||
                logger.Error($"写入资源文件时出错: {writeRet.Error}");
 | 
			
		||||
                return new(new Exception(writeRet.Error?.ToString() ?? $"写入失败"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"添加资源时出错: {ex.Message}");
 | 
			
		||||
            return new(ex);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 获取资源信息列表(返回ID和名称)
 | 
			
		||||
    /// <param name="resourceType">资源类型</param>
 | 
			
		||||
    /// <param name="examId">实验ID(可选)</param>
 | 
			
		||||
    /// <param name="resourcePurpose">资源用途(可选)</param>
 | 
			
		||||
    /// <param name="userId">用户ID(可选)</param>
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns>资源信息列表</returns>
 | 
			
		||||
    public Result<(string ID, string Name)[]> GetResourceListByType(
 | 
			
		||||
        string resourceType,
 | 
			
		||||
        ResourcePurpose? resourcePurpose = null,
 | 
			
		||||
        string? examId = null,
 | 
			
		||||
        Guid? userId = null)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var query = _db.ResourceTable.Where(r => r.ResourceType == resourceType);
 | 
			
		||||
 | 
			
		||||
            if (examId != null)
 | 
			
		||||
            {
 | 
			
		||||
                query = query.Where(r => r.ExamID == examId);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (resourcePurpose != null)
 | 
			
		||||
            {
 | 
			
		||||
                query = query.Where(r => r.Purpose == resourcePurpose);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (userId != null)
 | 
			
		||||
            {
 | 
			
		||||
                query = query.Where(r => r.UserID == userId);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var resources = query
 | 
			
		||||
                .Select(r => new { r.ID, r.ResourceName })
 | 
			
		||||
                .ToArray();
 | 
			
		||||
 | 
			
		||||
            var result = resources.Select(r => (r.ID.ToString(), r.ResourceName)).ToArray();
 | 
			
		||||
            logger.Info($"获取资源列表: {resourceType}" +
 | 
			
		||||
                       (examId != null ? $"/{examId}" : "") +
 | 
			
		||||
                       ($"/{resourcePurpose.ToString()}") +
 | 
			
		||||
                       (userId != null ? $"/{userId}" : "") +
 | 
			
		||||
                       $",共 {result.Length} 个资源");
 | 
			
		||||
            return new(result);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"获取资源列表时出错: {ex.Message}");
 | 
			
		||||
            return new(ex);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 获取完整的资源列表
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="examId">实验ID(可选)</param>
 | 
			
		||||
    /// <param name="resourceType">资源类型(可选)</param>
 | 
			
		||||
    /// <param name="resourcePurpose">资源用途(可选)</param>
 | 
			
		||||
    /// <param name="userId">用户ID(可选)</param>
 | 
			
		||||
    /// <returns>完整的资源对象列表</returns>
 | 
			
		||||
    public Result<List<Resource>> GetFullResourceList(
 | 
			
		||||
        string? examId = null,
 | 
			
		||||
        string? resourceType = null,
 | 
			
		||||
        ResourcePurpose? resourcePurpose = null,
 | 
			
		||||
        Guid? userId = null)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var query = _db.ResourceTable.AsQueryable();
 | 
			
		||||
 | 
			
		||||
            if (examId != null)
 | 
			
		||||
            {
 | 
			
		||||
                query = query.Where(r => r.ExamID == examId);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (resourceType != null)
 | 
			
		||||
            {
 | 
			
		||||
                query = query.Where(r => r.ResourceType == resourceType);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (resourcePurpose != null)
 | 
			
		||||
            {
 | 
			
		||||
                query = query.Where(r => r.Purpose == resourcePurpose);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (userId != null)
 | 
			
		||||
            {
 | 
			
		||||
                query = query.Where(r => r.UserID == userId);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var resources = query.OrderByDescending(r => r.UploadTime).ToList();
 | 
			
		||||
            logger.Info($"获取完整资源列表" +
 | 
			
		||||
                       (examId != null ? $" [实验: {examId}]" : "") +
 | 
			
		||||
                       (resourceType != null ? $" [类型: {resourceType}]" : "") +
 | 
			
		||||
                       ($" [用途: {resourcePurpose.ToString()}]") +
 | 
			
		||||
                       (userId != null ? $" [用户: {userId}]" : "") +
 | 
			
		||||
                       $",共 {resources.Count} 个资源");
 | 
			
		||||
            return new(resources);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"获取完整资源列表时出错: {ex.Message}");
 | 
			
		||||
            return new(ex);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 根据资源ID获取资源
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="resourceId">资源ID</param>
 | 
			
		||||
    /// <returns>资源数据</returns>
 | 
			
		||||
    public Optional<Resource> GetResourceById(string resourceId)
 | 
			
		||||
    {
 | 
			
		||||
        var resource = _db.ResourceTable.Where(r => r.ID.ToString() == resourceId).FirstOrDefault();
 | 
			
		||||
 | 
			
		||||
        if (resource == null)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Info($"未找到资源: {resourceId}");
 | 
			
		||||
            return new(null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        logger.Info($"成功获取资源: {resourceId} ({resource.ResourceName})");
 | 
			
		||||
        return new(resource);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 删除资源
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="resourceId">资源ID</param>
 | 
			
		||||
    /// <returns>删除的记录数</returns>
 | 
			
		||||
    public Result<int> DeleteResource(string resourceId)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var result = _db.ResourceTable.Where(r => r.ID.ToString() == resourceId).Delete();
 | 
			
		||||
            logger.Info($"资源已删除: {resourceId},删除记录数: {result}");
 | 
			
		||||
            return new(result);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"删除资源时出错: {ex.Message}");
 | 
			
		||||
            return new(ex);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										350
									
								
								server/src/Database/Type.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										350
									
								
								server/src/Database/Type.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,350 @@
 | 
			
		||||
using DotNext;
 | 
			
		||||
using LinqToDB;
 | 
			
		||||
using LinqToDB.Mapping;
 | 
			
		||||
 | 
			
		||||
namespace Database;
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// 用户权限枚举
 | 
			
		||||
/// </summary>
 | 
			
		||||
public enum UserPermission
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 管理员权限,可以管理用户和实验板
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    Admin,
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 普通用户权限,只能使用实验板
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    Normal,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// 用户类,表示用户信息
 | 
			
		||||
/// </summary>
 | 
			
		||||
public class User
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 用户的唯一标识符
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [PrimaryKey]
 | 
			
		||||
    public Guid ID { get; set; } = Guid.NewGuid();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 用户的名称
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 用户的电子邮箱
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required string EMail { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 用户的密码(应该进行哈希处理)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required string Password { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 用户权限等级
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required UserPermission Permission { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 绑定的实验板ID,如果未绑定则为空
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [Nullable]
 | 
			
		||||
    public Guid BoardID { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 用户绑定板子的过期时间
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [Nullable]
 | 
			
		||||
    public DateTime? BoardExpireTime { get; set; }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// FPGA 板子状态枚举
 | 
			
		||||
/// </summary>
 | 
			
		||||
public enum BoardStatus
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 未启用状态,无法被使用
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    Disabled,
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 繁忙状态,正在被用户使用
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    Busy,
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 可用状态,可以被分配给用户
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    Available,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// FPGA 板子类,表示板子信息
 | 
			
		||||
/// </summary>
 | 
			
		||||
public class Board
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// FPGA 板子的唯一标识符
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [PrimaryKey]
 | 
			
		||||
    public Guid ID { get; set; } = Guid.NewGuid();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// FPGA 板子的名称
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required string BoardName { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// FPGA 板子的IP地址
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required string IpAddr { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// FPGA 板子的MAC地址
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required string MacAddr { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// FPGA 板子的通信端口
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public int Port { get; set; } = 1234;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// FPGA 板子的当前状态
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required BoardStatus Status { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 占用该板子的用户的唯一标识符
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [Nullable]
 | 
			
		||||
    public Guid OccupiedUserID { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 占用该板子的用户的用户名
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [Nullable]
 | 
			
		||||
    public string? OccupiedUserName { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// FPGA 板子的固件版本号
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public string FirmVersion { get; set; } = "1.0.0";
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// 实验类,表示实验信息
 | 
			
		||||
/// </summary>
 | 
			
		||||
public class Exam
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验的唯一标识符
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [PrimaryKey]
 | 
			
		||||
    public required string ID { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验名称
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验描述
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required string Description { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验创建时间
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public DateTime CreatedTime { get; set; } = DateTime.Now;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验最后更新时间
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public DateTime UpdatedTime { get; set; } = DateTime.Now;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验标签(以逗号分隔的字符串)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public string Tags { get; set; } = "";
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 实验难度(1-5,1为最简单)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public int Difficulty { get; set; } = 1;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 普通用户是否可见
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public bool IsVisibleToUsers { get; set; } = true;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 获取标签列表
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns>标签数组</returns>
 | 
			
		||||
    public string[] GetTagsList()
 | 
			
		||||
    {
 | 
			
		||||
        if (string.IsNullOrWhiteSpace(Tags))
 | 
			
		||||
            return Array.Empty<string>();
 | 
			
		||||
 | 
			
		||||
        return Tags.Split(',', StringSplitOptions.RemoveEmptyEntries)
 | 
			
		||||
                   .Select(tag => tag.Trim())
 | 
			
		||||
                   .Where(tag => !string.IsNullOrEmpty(tag))
 | 
			
		||||
                   .ToArray();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 设置标签列表
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="tags">标签数组</param>
 | 
			
		||||
    public void SetTagsList(string[] tags)
 | 
			
		||||
    {
 | 
			
		||||
        Tags = string.Join(",", tags.Where(tag => !string.IsNullOrWhiteSpace(tag)).Select(tag => tag.Trim()));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// 资源类型枚举
 | 
			
		||||
/// </summary>
 | 
			
		||||
public static class ResourceTypes
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 图片资源类型
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public const string Images = "images";
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Markdown文档资源类型
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public const string Markdown = "markdown";
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 比特流文件资源类型
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public const string Bitstream = "bitstream";
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 原理图资源类型
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public const string Diagram = "diagram";
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 项目文件资源类型
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public const string Project = "project";
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 压缩文件资源类型
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public const string Compression = "compression";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public enum ResourcePurpose : int
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 模板资源,通常由管理员上传,供用户参考
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    Template,
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 用户上传的资源
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    User,
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 用户提交的作业
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    Homework
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// 资源类,统一管理实验资源、用户比特流等各类资源
 | 
			
		||||
/// </summary>
 | 
			
		||||
public class Resource
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 资源的唯一标识符
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [PrimaryKey]
 | 
			
		||||
    public Guid ID { get; set; } = Guid.NewGuid();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 上传资源的用户ID
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required Guid UserID { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 所属实验ID(可选,如果不属于特定实验则为空)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [Nullable]
 | 
			
		||||
    public string? ExamID { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 资源类型(images, markdown, bitstream, diagram, project等)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required string ResourceType { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 资源用途:template(模板)或 user(用户上传)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required ResourcePurpose Purpose { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 资源名称(包含文件扩展名)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required string ResourceName { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 资源路径(包含文件名和扩展名)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required string Path { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 资源SHA256哈希值
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public required string SHA256 { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 资源创建/上传时间
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public DateTime UploadTime { get; set; } = DateTime.Now;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 资源的MIME类型
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [NotNull]
 | 
			
		||||
    public string MimeType { get; set; } = "application/octet-stream";
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										458
									
								
								server/src/Database/UserManager.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										458
									
								
								server/src/Database/UserManager.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,458 @@
 | 
			
		||||
using DotNext;
 | 
			
		||||
using LinqToDB;
 | 
			
		||||
using LinqToDB.Data;
 | 
			
		||||
 | 
			
		||||
namespace Database;
 | 
			
		||||
 | 
			
		||||
public class UserManager
 | 
			
		||||
{
 | 
			
		||||
    private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    private readonly AppDataConnection _db;
 | 
			
		||||
 | 
			
		||||
    public UserManager(AppDataConnection db)
 | 
			
		||||
    {
 | 
			
		||||
        this._db = db;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 添加一个新的用户到数据库
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="name">用户的名称</param>
 | 
			
		||||
    /// <param name="email">用户的电子邮箱地址</param>
 | 
			
		||||
    /// <param name="password">用户的密码</param>
 | 
			
		||||
    /// <returns>插入的记录数</returns>
 | 
			
		||||
    public int AddUser(string name, string email, string password)
 | 
			
		||||
    {
 | 
			
		||||
        var user = new User()
 | 
			
		||||
        {
 | 
			
		||||
            Name = name,
 | 
			
		||||
            EMail = email,
 | 
			
		||||
            Password = password,
 | 
			
		||||
            Permission = UserPermission.Normal,
 | 
			
		||||
        };
 | 
			
		||||
        var result = _db.Insert(user);
 | 
			
		||||
        logger.Info($"新用户已添加: {name} ({email})");
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 根据用户名获取用户信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="name">用户名</param>
 | 
			
		||||
    /// <returns>包含用户信息的结果,如果未找到或出错则返回相应状态</returns>
 | 
			
		||||
    public Result<Optional<User>> GetUserByName(string name)
 | 
			
		||||
    {
 | 
			
		||||
        var user = _db.UserTable.Where((user) => user.Name == name).ToArray();
 | 
			
		||||
 | 
			
		||||
        if (user.Length > 1)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"数据库中存在多个同名用户: {name}");
 | 
			
		||||
            return new(new Exception($"数据库中存在多个同名用户: {name}"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (user.Length == 0)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Info($"未找到用户: {name}");
 | 
			
		||||
            return new(Optional<User>.None);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        logger.Debug($"成功获取用户信息: {name}");
 | 
			
		||||
        return new(user[0]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 根据电子邮箱获取用户信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="email">用户的电子邮箱地址</param>
 | 
			
		||||
    /// <returns>包含用户信息的结果,如果未找到或出错则返回相应状态</returns>
 | 
			
		||||
    public Result<Optional<User>> GetUserByEMail(string email)
 | 
			
		||||
    {
 | 
			
		||||
        var user = _db.UserTable.Where((user) => user.EMail == email).ToArray();
 | 
			
		||||
 | 
			
		||||
        if (user.Length > 1)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"数据库中存在多个相同邮箱的用户: {email}");
 | 
			
		||||
            return new(new Exception($"数据库中存在多个相同邮箱的用户: {email}"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (user.Length == 0)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Info($"未找到邮箱对应的用户: {email}");
 | 
			
		||||
            return new(Optional<User>.None);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        logger.Debug($"成功获取用户信息: {email}");
 | 
			
		||||
        return new(user[0]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 验证用户密码
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="name">用户名</param>
 | 
			
		||||
    /// <param name="password">用户密码</param>
 | 
			
		||||
    /// <returns>如果密码正确返回用户信息,否则返回空</returns>
 | 
			
		||||
    public Result<Optional<User>> CheckUserPassword(string name, string password)
 | 
			
		||||
    {
 | 
			
		||||
        var ret = GetUserByName(name);
 | 
			
		||||
        if (!ret.IsSuccessful)
 | 
			
		||||
            return new(ret.Error);
 | 
			
		||||
 | 
			
		||||
        if (!ret.Value.HasValue)
 | 
			
		||||
            return new(Optional<User>.None);
 | 
			
		||||
 | 
			
		||||
        var user = ret.Value.Value;
 | 
			
		||||
 | 
			
		||||
        if (user.Password == password)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Info($"用户 {name} 密码验证成功");
 | 
			
		||||
            return new(user);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            logger.Warn($"用户 {name} 密码验证失败");
 | 
			
		||||
            return new(Optional<User>.None);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 绑定用户与实验板
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="userId">用户的唯一标识符</param>
 | 
			
		||||
    /// <param name="boardId">实验板的唯一标识符</param>
 | 
			
		||||
    /// <param name="expireTime">绑定过期时间</param>
 | 
			
		||||
    /// <returns>更新的记录数</returns>
 | 
			
		||||
    public int BindUserToBoard(Guid userId, Guid boardId, DateTime expireTime)
 | 
			
		||||
    {
 | 
			
		||||
        // 获取用户信息
 | 
			
		||||
        var user = _db.UserTable.Where(u => u.ID == userId).FirstOrDefault();
 | 
			
		||||
        if (user == null)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"未找到用户: {userId}");
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 更新用户的板子绑定信息
 | 
			
		||||
        var userResult = _db.UserTable
 | 
			
		||||
            .Where(u => u.ID == userId)
 | 
			
		||||
            .Set(u => u.BoardID, boardId)
 | 
			
		||||
            .Set(u => u.BoardExpireTime, expireTime)
 | 
			
		||||
            .Update();
 | 
			
		||||
 | 
			
		||||
        // 更新板子的用户绑定信息
 | 
			
		||||
        var boardResult = _db.BoardTable
 | 
			
		||||
            .Where(b => b.ID == boardId)
 | 
			
		||||
            .Set(b => b.Status, BoardStatus.Busy)
 | 
			
		||||
            .Set(b => b.OccupiedUserID, userId)
 | 
			
		||||
            .Set(b => b.OccupiedUserName, user.Name)
 | 
			
		||||
            .Update();
 | 
			
		||||
 | 
			
		||||
        logger.Info($"用户 {userId} ({user.Name}) 已绑定到实验板 {boardId},过期时间: {expireTime}");
 | 
			
		||||
        return userResult + boardResult;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 解除用户与实验板的绑定
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="userId">用户的唯一标识符</param>
 | 
			
		||||
    /// <returns>更新的记录数</returns>
 | 
			
		||||
    public int UnbindUserFromBoard(Guid userId)
 | 
			
		||||
    {
 | 
			
		||||
        // 获取用户当前绑定的板子ID
 | 
			
		||||
        var user = _db.UserTable.Where(u => u.ID == userId).FirstOrDefault();
 | 
			
		||||
        Guid boardId = user?.BoardID ?? Guid.Empty;
 | 
			
		||||
 | 
			
		||||
        // 清空用户的板子绑定信息
 | 
			
		||||
        var userResult = _db.UserTable
 | 
			
		||||
            .Where(u => u.ID == userId)
 | 
			
		||||
            .Set(u => u.BoardID, Guid.Empty)
 | 
			
		||||
            .Set(u => u.BoardExpireTime, (DateTime?)null)
 | 
			
		||||
            .Update();
 | 
			
		||||
 | 
			
		||||
        // 如果用户原本绑定了板子,则清空板子的用户绑定信息
 | 
			
		||||
        int boardResult = 0;
 | 
			
		||||
        if (boardId != Guid.Empty)
 | 
			
		||||
        {
 | 
			
		||||
            boardResult = _db.BoardTable
 | 
			
		||||
                .Where(b => b.ID == boardId)
 | 
			
		||||
                .Set(b => b.Status, BoardStatus.Available)
 | 
			
		||||
                .Set(b => b.OccupiedUserID, Guid.Empty)
 | 
			
		||||
                .Set(b => b.OccupiedUserName, (string?)null)
 | 
			
		||||
                .Update();
 | 
			
		||||
            logger.Info($"实验板 {boardId} 状态已设置为空闲,用户绑定信息已清空");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        logger.Info($"用户 {userId} 已解除实验板绑定");
 | 
			
		||||
        return userResult + boardResult;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 自动分配一个未被占用的IP地址
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns>分配的IP地址字符串</returns>
 | 
			
		||||
    public string AllocateIpAddr()
 | 
			
		||||
    {
 | 
			
		||||
        var usedIps = _db.BoardTable.Select(b => b.IpAddr).ToArray();
 | 
			
		||||
        for (int i = 1; i <= 254; i++)
 | 
			
		||||
        {
 | 
			
		||||
            string ip = $"169.254.109.{i}";
 | 
			
		||||
            if (!usedIps.Contains(ip))
 | 
			
		||||
                return ip;
 | 
			
		||||
        }
 | 
			
		||||
        throw new Exception("没有可用的IP地址");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 自动分配一个未被占用的MAC地址
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns>分配的MAC地址字符串</returns>
 | 
			
		||||
    public string AllocateMacAddr()
 | 
			
		||||
    {
 | 
			
		||||
        var usedMacs = _db.BoardTable.Select(b => b.MacAddr).ToArray();
 | 
			
		||||
        // 以 02-00-00-xx-xx-xx 格式分配,02 表示本地管理地址
 | 
			
		||||
        for (int i = 1; i <= 0xFFFFFF; i++)
 | 
			
		||||
        {
 | 
			
		||||
            string mac = $"02-00-00-{(i >> 16) & 0xFF:X2}-{(i >> 8) & 0xFF:X2}-{i & 0xFF:X2}";
 | 
			
		||||
            if (!usedMacs.Contains(mac))
 | 
			
		||||
                return mac;
 | 
			
		||||
        }
 | 
			
		||||
        throw new Exception("没有可用的MAC地址");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 添加一块新的 FPGA 板子到数据库
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="name">FPGA 板子的名称</param>
 | 
			
		||||
    /// <returns>插入的记录数</returns>
 | 
			
		||||
    public Guid AddBoard(string name)
 | 
			
		||||
    {
 | 
			
		||||
        if (string.IsNullOrWhiteSpace(name) || name.Contains('\'') || name.Contains(';'))
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error("实验板名称非法,包含不允许的字符");
 | 
			
		||||
            throw new ArgumentException("实验板名称非法");
 | 
			
		||||
        }
 | 
			
		||||
        var board = new Board()
 | 
			
		||||
        {
 | 
			
		||||
            BoardName = name,
 | 
			
		||||
            IpAddr = AllocateIpAddr(),
 | 
			
		||||
            MacAddr = AllocateMacAddr(),
 | 
			
		||||
            Status = BoardStatus.Disabled,
 | 
			
		||||
        };
 | 
			
		||||
        var result = _db.Insert(board);
 | 
			
		||||
        logger.Info($"新实验板已添加: {name} ({board.IpAddr}:{board.MacAddr})");
 | 
			
		||||
        return board.ID;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 根据名称删除实验板
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="name">实验板的名称</param>
 | 
			
		||||
    /// <returns>删除的记录数</returns>
 | 
			
		||||
    public int DeleteBoardByName(string name)
 | 
			
		||||
    {
 | 
			
		||||
        // 先获取要删除的板子信息
 | 
			
		||||
        var board = _db.BoardTable.Where(b => b.BoardName == name).FirstOrDefault();
 | 
			
		||||
        if (board == null)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Warn($"未找到名称为 {name} 的实验板");
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 如果板子被占用,先解除绑定
 | 
			
		||||
        if (board.OccupiedUserID != Guid.Empty)
 | 
			
		||||
        {
 | 
			
		||||
            _db.UserTable
 | 
			
		||||
                .Where(u => u.ID == board.OccupiedUserID)
 | 
			
		||||
                .Set(u => u.BoardID, Guid.Empty)
 | 
			
		||||
                .Set(u => u.BoardExpireTime, (DateTime?)null)
 | 
			
		||||
                .Update();
 | 
			
		||||
            logger.Info($"已解除用户 {board.OccupiedUserID} 与实验板 {name} 的绑定");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var result = _db.BoardTable.Where(b => b.BoardName == name).Delete();
 | 
			
		||||
        logger.Info($"实验板已删除: {name},删除记录数: {result}");
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 根据ID删除实验板
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="id">实验板的唯一标识符</param>
 | 
			
		||||
    /// <returns>删除的记录数</returns>
 | 
			
		||||
    public int DeleteBoardByID(Guid id)
 | 
			
		||||
    {
 | 
			
		||||
        // 先获取要删除的板子信息
 | 
			
		||||
        var board = _db.BoardTable.Where(b => b.ID == id).FirstOrDefault();
 | 
			
		||||
        if (board == null)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Warn($"未找到ID为 {id} 的实验板");
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 如果板子被占用,先解除绑定
 | 
			
		||||
        if (board.OccupiedUserID != Guid.Empty)
 | 
			
		||||
        {
 | 
			
		||||
            _db.UserTable
 | 
			
		||||
                .Where(u => u.ID == board.OccupiedUserID)
 | 
			
		||||
                .Set(u => u.BoardID, Guid.Empty)
 | 
			
		||||
                .Set(u => u.BoardExpireTime, (DateTime?)null)
 | 
			
		||||
                .Update();
 | 
			
		||||
            logger.Info($"已解除用户 {board.OccupiedUserID} 与实验板 {id} 的绑定");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var result = _db.BoardTable.Where(b => b.ID == id).Delete();
 | 
			
		||||
        logger.Info($"实验板已删除: {id},删除记录数: {result}");
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 根据实验板ID获取实验板信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="id">实验板的唯一标识符</param>
 | 
			
		||||
    /// <returns>包含实验板信息的结果,如果未找到则返回空</returns>
 | 
			
		||||
    public Result<Optional<Board>> GetBoardByID(Guid id)
 | 
			
		||||
    {
 | 
			
		||||
        var boards = _db.BoardTable.Where(board => board.ID == id).ToArray();
 | 
			
		||||
 | 
			
		||||
        if (boards.Length > 1)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"数据库中存在多个相同ID的实验板: {id}");
 | 
			
		||||
            return new(new Exception($"数据库中存在多个相同ID的实验板: {id}"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (boards.Length == 0)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Info($"未找到ID对应的实验板: {id}");
 | 
			
		||||
            return new(Optional<Board>.None);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        logger.Debug($"成功获取实验板信息: {id}");
 | 
			
		||||
        return new(boards[0]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 根据用户名获取实验板信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="userName">用户名</param>
 | 
			
		||||
    /// <returns>包含实验板信息的结果,如果未找到则返回空</returns>
 | 
			
		||||
    public Result<Optional<Board>> GetBoardByUserName(string userName)
 | 
			
		||||
    {
 | 
			
		||||
        var boards = _db.BoardTable.Where(board => board.OccupiedUserName == userName).ToArray();
 | 
			
		||||
 | 
			
		||||
        if (boards.Length > 1)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"数据库中存在多个相同用户名的实验板: {userName}");
 | 
			
		||||
            return new(new Exception($"数据库中存在多个相同用户名的实验板: {userName}"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (boards.Length == 0)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Info($"未找到用户名对应的实验板: {userName}");
 | 
			
		||||
            return new(Optional<Board>.None);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        logger.Debug($"成功获取实验板信息: {userName}");
 | 
			
		||||
        return new(boards[0]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 获取所有实验板信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns>所有实验板的数组</returns>
 | 
			
		||||
    public Board[] GetAllBoard()
 | 
			
		||||
    {
 | 
			
		||||
        var boards = _db.BoardTable.ToArray();
 | 
			
		||||
        logger.Debug($"获取所有实验板,共 {boards.Length} 块");
 | 
			
		||||
        return boards;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 获取一块可用的实验板并将其状态设置为繁忙
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="userId">要分配板子的用户ID</param>
 | 
			
		||||
    /// <param name="expireTime">绑定过期时间</param>
 | 
			
		||||
    /// <returns>可用的实验板,如果没有可用的板子则返回空</returns>
 | 
			
		||||
    public Optional<Board> GetAvailableBoard(Guid userId, DateTime expireTime)
 | 
			
		||||
    {
 | 
			
		||||
        var boards = _db.BoardTable.Where(
 | 
			
		||||
                (board) => board.Status == BoardStatus.Available
 | 
			
		||||
            ).ToArray();
 | 
			
		||||
 | 
			
		||||
        if (boards.Length == 0)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Warn("没有可用的实验板");
 | 
			
		||||
            return new(null);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            var board = boards[0];
 | 
			
		||||
            var user = _db.UserTable.Where(u => u.ID == userId).FirstOrDefault();
 | 
			
		||||
 | 
			
		||||
            if (user == null)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"未找到用户: {userId}");
 | 
			
		||||
                return new(null);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 更新板子状态和用户绑定信息
 | 
			
		||||
            _db.BoardTable
 | 
			
		||||
                .Where(target => target.ID == board.ID)
 | 
			
		||||
                .Set(target => target.Status, BoardStatus.Busy)
 | 
			
		||||
                .Set(target => target.OccupiedUserID, userId)
 | 
			
		||||
                .Set(target => target.OccupiedUserName, user.Name)
 | 
			
		||||
                .Update();
 | 
			
		||||
 | 
			
		||||
            // 更新用户的板子绑定信息
 | 
			
		||||
            _db.UserTable
 | 
			
		||||
                .Where(u => u.ID == userId)
 | 
			
		||||
                .Set(u => u.BoardID, board.ID)
 | 
			
		||||
                .Set(u => u.BoardExpireTime, expireTime)
 | 
			
		||||
                .Update();
 | 
			
		||||
 | 
			
		||||
            board.Status = BoardStatus.Busy;
 | 
			
		||||
            board.OccupiedUserID = userId;
 | 
			
		||||
            board.OccupiedUserName = user.Name;
 | 
			
		||||
 | 
			
		||||
            logger.Info($"实验板 {board.BoardName} ({board.ID}) 已分配给用户 {user.Name} ({userId}),过期时间: {expireTime}");
 | 
			
		||||
            return new(board);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// [TODO:description]
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="boardId">[TODO:parameter]</param>
 | 
			
		||||
    /// <param name="newName">[TODO:parameter]</param>
 | 
			
		||||
    /// <returns>[TODO:return]</returns>
 | 
			
		||||
    public int UpdateBoardName(Guid boardId, string newName)
 | 
			
		||||
    {
 | 
			
		||||
        if (string.IsNullOrWhiteSpace(newName) || newName.Contains('\'') || newName.Contains(';'))
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error("实验板名称非法,包含不允许的字符");
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        var result = _db.BoardTable
 | 
			
		||||
            .Where(b => b.ID == boardId)
 | 
			
		||||
            .Set(b => b.BoardName, newName)
 | 
			
		||||
            .Update();
 | 
			
		||||
        logger.Info($"实验板名称已更新: {boardId} -> {newName}");
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// [TODO:description]
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="boardId">[TODO:parameter]</param>
 | 
			
		||||
    /// <param name="newStatus">[TODO:parameter]</param>
 | 
			
		||||
    /// <returns>[TODO:return]</returns>
 | 
			
		||||
    public int UpdateBoardStatus(Guid boardId, BoardStatus newStatus)
 | 
			
		||||
    {
 | 
			
		||||
        var result = _db.BoardTable
 | 
			
		||||
            .Where(b => b.ID == boardId)
 | 
			
		||||
            .Set(b => b.Status, newStatus)
 | 
			
		||||
            .Update();
 | 
			
		||||
        logger.Info($"TODO");
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -28,22 +28,24 @@ public interface IJtagReceiver
 | 
			
		||||
public class JtagHub : Hub<IJtagReceiver>, IJtagHub
 | 
			
		||||
{
 | 
			
		||||
    private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    private readonly IHubContext<JtagHub, IJtagReceiver> _hubContext;
 | 
			
		||||
    private readonly Database.UserManager _userManager;
 | 
			
		||||
 | 
			
		||||
    private static ConcurrentDictionary<string, int> FreqTable = new();
 | 
			
		||||
    private static ConcurrentDictionary<string, CancellationTokenSource> CancellationTokenSourceTable = new();
 | 
			
		||||
 | 
			
		||||
    private readonly IHubContext<JtagHub, IJtagReceiver> _hubContext;
 | 
			
		||||
 | 
			
		||||
    public JtagHub(IHubContext<JtagHub, IJtagReceiver> hubContext)
 | 
			
		||||
    public JtagHub(IHubContext<JtagHub, IJtagReceiver> hubContext, Database.UserManager userManager)
 | 
			
		||||
    {
 | 
			
		||||
        _hubContext = hubContext;
 | 
			
		||||
        _userManager = userManager;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Optional<Peripherals.JtagClient.Jtag> GetJtagClient(string userName)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var db = new Database.AppDataConnection();
 | 
			
		||||
            var board = db.GetBoardByUserName(userName);
 | 
			
		||||
            var board = _userManager.GetBoardByUserName(userName);
 | 
			
		||||
            if (!board.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Find Board {board.Value.Value.ID} failed because {board.Error}");
 | 
			
		||||
@@ -97,7 +99,7 @@ public class JtagHub : Hub<IJtagReceiver>, IJtagHub
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            await SetBoundaryScanFreq(freq);
 | 
			
		||||
            SetBoundaryScanFreq(freq);
 | 
			
		||||
            var cts = new CancellationTokenSource();
 | 
			
		||||
            CancellationTokenSourceTable.AddOrUpdate(userName, cts, (key, value) => cts);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ static class HdmiInAddr
 | 
			
		||||
    public const UInt32 HdmiIn_READFIFO = BASE + 0x1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class HdmiIn
 | 
			
		||||
public class HdmiIn
 | 
			
		||||
{
 | 
			
		||||
    private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,14 +7,28 @@ namespace Peripherals.JpegClient;
 | 
			
		||||
static class JpegAddr
 | 
			
		||||
{
 | 
			
		||||
    const UInt32 BASE = 0x0000_0000;
 | 
			
		||||
    public const UInt32 ENABLE = BASE + 0x0;
 | 
			
		||||
    public const UInt32 FRAME_NUM = BASE + 0x1;
 | 
			
		||||
    public const UInt32 FRAME_INFO = BASE + 0x2;
 | 
			
		||||
    public const UInt32 FRAME_SAMPLE_RATE = BASE + 0x3;
 | 
			
		||||
    public const UInt32 FRAME_DATA_MAX_POINTER = BASE + 0x4;
 | 
			
		||||
 | 
			
		||||
    public const UInt32 DDR_FRAME_DATA_ADDR = 0x0000_0000;
 | 
			
		||||
    public const UInt32 DDR_FRAME_DATA_MAX_ADDR = 0x8000_0000;
 | 
			
		||||
    public const UInt32 CAPTURE_RD_CTRL = BASE + 0x0;
 | 
			
		||||
    public const UInt32 CAPTURE_WR_CTRL = BASE + 0x1;
 | 
			
		||||
 | 
			
		||||
    public const UInt32 START_WR_ADDR0 = BASE + 0x2;
 | 
			
		||||
    public const UInt32 END_WR_ADDR0 = BASE + 0x3;
 | 
			
		||||
    public const UInt32 START_WR_ADDR1 = BASE + 0x4;
 | 
			
		||||
    public const UInt32 END_WR_ADDR1 = BASE + 0x5;
 | 
			
		||||
    public const UInt32 START_RD_ADDR0 = BASE + 0x6;
 | 
			
		||||
    public const UInt32 END_RD_ADDR0 = BASE + 0x7;
 | 
			
		||||
 | 
			
		||||
    public const UInt32 HDMI_NOT_READY = BASE + 0x8;
 | 
			
		||||
    public const UInt32 HDMI_HEIGHT_WIDTH = BASE + 0x9;
 | 
			
		||||
 | 
			
		||||
    public const UInt32 JPEG_HEIGHT_WIDTH = BASE + 0xA;
 | 
			
		||||
    public const UInt32 JPEG_ADD_NEED_FRAME_NUM = BASE + 0xB;
 | 
			
		||||
    public const UInt32 JPEG_FRAME_SAVE_NUM = BASE + 0xC;
 | 
			
		||||
    public const UInt32 JPEG_FIFO_FRAME_INFO = BASE + 0xD;
 | 
			
		||||
 | 
			
		||||
    public const UInt32 ADDR_HDMI_WD_START = 0x4000_0000;
 | 
			
		||||
    public const UInt32 ADDR_JPEG_START = 0x8000_0000;
 | 
			
		||||
    public const UInt32 ADDR_JPEG_END = 0xA000_0000;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public class JpegInfo
 | 
			
		||||
@@ -79,39 +93,248 @@ public class Jpeg
 | 
			
		||||
        this.timeout = timeout;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async ValueTask<Result<bool>> Init(bool enable = true)
 | 
			
		||||
    {
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await CheckHdmiIsReady();
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to check HDMI ready: {ret.Error}");
 | 
			
		||||
                return new(ret.Error);
 | 
			
		||||
            }
 | 
			
		||||
            if (!ret.Value)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error("HDMI not ready");
 | 
			
		||||
                return new(false);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int width = -1, height = -1;
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await GetHdmiResolution();
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to get HDMI resolution: {ret.Error}");
 | 
			
		||||
                return new(ret.Error);
 | 
			
		||||
            }
 | 
			
		||||
            (width, height) = ret.Value;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await ConnectJpeg2Hdmi(width, height);
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to connect JPEG to HDMI: {ret.Error}");
 | 
			
		||||
                return new(ret.Error);
 | 
			
		||||
            }
 | 
			
		||||
            if (!ret.Value)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error("Failed to connect JPEG to HDMI");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (enable)
 | 
			
		||||
            return await SetEnable(true);
 | 
			
		||||
        else return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async ValueTask<bool> SetEnable(bool enable)
 | 
			
		||||
    {
 | 
			
		||||
        var ret = await UDPClientPool.WriteAddr(
 | 
			
		||||
            this.ep, this.taskID, JpegAddr.ENABLE, Convert.ToUInt32(enable), this.timeout);
 | 
			
		||||
        if (enable)
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await UDPClientPool.WriteAddrSeq(
 | 
			
		||||
                this.ep,
 | 
			
		||||
                this.taskID,
 | 
			
		||||
                [JpegAddr.CAPTURE_RD_CTRL, JpegAddr.CAPTURE_WR_CTRL],
 | 
			
		||||
                [0b11, 0b01],
 | 
			
		||||
                this.timeout
 | 
			
		||||
            );
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set JPEG enable: {ret.Error}");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            return ret.Value;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await UDPClientPool.WriteAddrSeq(
 | 
			
		||||
                this.ep,
 | 
			
		||||
                this.taskID,
 | 
			
		||||
                [JpegAddr.CAPTURE_RD_CTRL, JpegAddr.CAPTURE_WR_CTRL],
 | 
			
		||||
                [0b00, 0b00],
 | 
			
		||||
                this.timeout
 | 
			
		||||
            );
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set JPEG disable: {ret.Error}");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            return ret.Value;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async ValueTask<Result<bool>> CheckHdmiIsReady()
 | 
			
		||||
    {
 | 
			
		||||
        var ret = await UDPClientPool.ReadAddrWithWait(
 | 
			
		||||
            this.ep, this.taskID, JpegAddr.HDMI_NOT_READY, 0b01, 0b01, 100, this.timeout);
 | 
			
		||||
        if (!ret.IsSuccessful)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"Failed to set JPEG enable: {ret.Error}");
 | 
			
		||||
            return false;
 | 
			
		||||
            logger.Error($"Failed to check HDMI status: {ret.Error}");
 | 
			
		||||
            return new(ret.Error);
 | 
			
		||||
        }
 | 
			
		||||
        return ret.Value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async ValueTask<bool> SetSampleRate(uint rate)
 | 
			
		||||
    public async ValueTask<Result<(int, int)>> GetHdmiResolution()
 | 
			
		||||
    {
 | 
			
		||||
        var ret = await UDPClientPool.WriteAddr(
 | 
			
		||||
            this.ep, this.taskID, JpegAddr.FRAME_SAMPLE_RATE, rate, this.timeout);
 | 
			
		||||
        var ret = await UDPClientPool.ReadAddr(
 | 
			
		||||
            this.ep, this.taskID, JpegAddr.HDMI_HEIGHT_WIDTH, 0, this.timeout);
 | 
			
		||||
        if (!ret.IsSuccessful)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"Failed to set JPEG sample rate: {ret.Error}");
 | 
			
		||||
            return false;
 | 
			
		||||
            logger.Error($"Failed to get HDMI resolution: {ret.Error}");
 | 
			
		||||
            return new(ret.Error);
 | 
			
		||||
        }
 | 
			
		||||
        return ret.Value;
 | 
			
		||||
 | 
			
		||||
        var data = ret.Value.Options.Data;
 | 
			
		||||
        if (data == null || data.Length != 4)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"Invalid HDMI resolution data length: {data?.Length ?? 0}");
 | 
			
		||||
            return new(new Exception("Invalid HDMI resolution data length"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var width = data[0] | (data[1] << 8);
 | 
			
		||||
        var height = data[2] | (data[3] << 8);
 | 
			
		||||
        return new((width, height));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async ValueTask<bool> SetSampleRate(JpegSampleRate rate)
 | 
			
		||||
    public async ValueTask<Result<bool>> ConnectJpeg2Hdmi(int width, int height)
 | 
			
		||||
    {
 | 
			
		||||
        return await SetSampleRate((uint)rate);
 | 
			
		||||
        if (width <= 0 || height <= 0)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"Invalid HDMI resolution: {width}x{height}");
 | 
			
		||||
            return new(new ArgumentException("Invalid HDMI resolution"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var frameSize = (UInt32)(width * height / 4);
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await UDPClientPool.WriteAddr(
 | 
			
		||||
                this.ep, this.taskID, JpegAddr.START_WR_ADDR0, JpegAddr.ADDR_HDMI_WD_START, this.timeout);
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set HDMI output start address: {ret.Error}");
 | 
			
		||||
                return new(ret.Error);
 | 
			
		||||
            }
 | 
			
		||||
            if (!ret.Value)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set HDMI output start address");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await UDPClientPool.WriteAddr(
 | 
			
		||||
                this.ep, this.taskID, JpegAddr.END_WR_ADDR0,
 | 
			
		||||
                JpegAddr.ADDR_HDMI_WD_START + frameSize, this.timeout);
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set HDMI output end address: {ret.Error}");
 | 
			
		||||
                return new(ret.Error);
 | 
			
		||||
            }
 | 
			
		||||
            if (!ret.Value)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set HDMI output address");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await UDPClientPool.WriteAddr(
 | 
			
		||||
                this.ep, this.taskID, JpegAddr.START_RD_ADDR0, JpegAddr.ADDR_HDMI_WD_START, this.timeout);
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set jpeg input start address: {ret.Error}");
 | 
			
		||||
                return new(ret.Error);
 | 
			
		||||
            }
 | 
			
		||||
            if (!ret.Value)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set jpeg input address");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await UDPClientPool.WriteAddr(
 | 
			
		||||
                this.ep, this.taskID, JpegAddr.END_RD_ADDR0,
 | 
			
		||||
                JpegAddr.ADDR_HDMI_WD_START + frameSize, this.timeout);
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set jpeg input end address: {ret.Error}");
 | 
			
		||||
                return new(ret.Error);
 | 
			
		||||
            }
 | 
			
		||||
            if (!ret.Value)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set jpeg input end address");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await UDPClientPool.WriteAddr(
 | 
			
		||||
                this.ep, this.taskID, JpegAddr.START_WR_ADDR1, JpegAddr.ADDR_JPEG_START, this.timeout);
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set jpeg output start address: {ret.Error}");
 | 
			
		||||
                return new(ret.Error);
 | 
			
		||||
            }
 | 
			
		||||
            if (!ret.Value)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set jpeg output start address");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await UDPClientPool.WriteAddr(
 | 
			
		||||
                this.ep, this.taskID, JpegAddr.END_WR_ADDR1, JpegAddr.ADDR_JPEG_END, this.timeout);
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set jpeg output end address: {ret.Error}");
 | 
			
		||||
                return new(ret.Error);
 | 
			
		||||
            }
 | 
			
		||||
            if (!ret.Value)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to set jpeg output end address");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // public async ValueTask<bool> SetSampleRate(uint rate)
 | 
			
		||||
    // {
 | 
			
		||||
    //     var ret = await UDPClientPool.WriteAddr(
 | 
			
		||||
    //         this.ep, this.taskID, JpegAddr.FRAME_SAMPLE_RATE, rate, this.timeout);
 | 
			
		||||
    //     if (!ret.IsSuccessful)
 | 
			
		||||
    //     {
 | 
			
		||||
    //         logger.Error($"Failed to set JPEG sample rate: {ret.Error}");
 | 
			
		||||
    //         return false;
 | 
			
		||||
    //     }
 | 
			
		||||
    //     return ret.Value;
 | 
			
		||||
    // }
 | 
			
		||||
 | 
			
		||||
    // public async ValueTask<bool> SetSampleRate(JpegSampleRate rate)
 | 
			
		||||
    // {
 | 
			
		||||
    //     return await SetSampleRate((uint)rate);
 | 
			
		||||
    // }
 | 
			
		||||
 | 
			
		||||
    public async ValueTask<uint> GetFrameNumber()
 | 
			
		||||
    {
 | 
			
		||||
        var ret = await UDPClientPool.ReadAddrByte(
 | 
			
		||||
            this.ep, this.taskID, JpegAddr.FRAME_NUM, this.timeout);
 | 
			
		||||
            this.ep, this.taskID, JpegAddr.JPEG_FRAME_SAVE_NUM, this.timeout);
 | 
			
		||||
        if (!ret.IsSuccessful)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"Failed to get JPEG frame number: {ret.Error}");
 | 
			
		||||
@@ -122,7 +345,7 @@ public class Jpeg
 | 
			
		||||
 | 
			
		||||
    public async ValueTask<Optional<List<JpegInfo>>> GetFrameInfo(int num)
 | 
			
		||||
    {
 | 
			
		||||
        var ret = await UDPClientPool.ReadAddr(this.ep, this.taskID, JpegAddr.FRAME_INFO, num, this.timeout);
 | 
			
		||||
        var ret = await UDPClientPool.ReadAddr(this.ep, this.taskID, JpegAddr.JPEG_FIFO_FRAME_INFO, num, this.timeout);
 | 
			
		||||
        if (!ret.IsSuccessful)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"Failed to get JPEG frame info: {ret.Error}");
 | 
			
		||||
@@ -150,10 +373,10 @@ public class Jpeg
 | 
			
		||||
        return new(infos);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async ValueTask<bool> UpdatePointer(uint cnt)
 | 
			
		||||
    public async ValueTask<bool> AddFrameNum2Process(uint cnt)
 | 
			
		||||
    {
 | 
			
		||||
        var ret = await UDPClientPool.WriteAddr(
 | 
			
		||||
            this.ep, this.taskID, JpegAddr.FRAME_DATA_MAX_POINTER, cnt, this.timeout);
 | 
			
		||||
            this.ep, this.taskID, JpegAddr.JPEG_ADD_NEED_FRAME_NUM, cnt, this.timeout);
 | 
			
		||||
        if (!ret.IsSuccessful)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"Failed to update pointer: {ret.Error}");
 | 
			
		||||
@@ -171,13 +394,16 @@ public class Jpeg
 | 
			
		||||
        }
 | 
			
		||||
        MsgBus.UDPServer.ClearUDPData(this.ep.Address.ToString(), this.ep.Port);
 | 
			
		||||
 | 
			
		||||
        var firstReadLength = (int)(Math.Min(length, JpegAddr.DDR_FRAME_DATA_MAX_ADDR - offset));
 | 
			
		||||
        var firstReadLength = (int)(Math.Min(
 | 
			
		||||
            length,
 | 
			
		||||
            JpegAddr.ADDR_JPEG_END - JpegAddr.ADDR_JPEG_START - offset
 | 
			
		||||
        ));
 | 
			
		||||
        var secondReadLength = (int)(length - firstReadLength);
 | 
			
		||||
        var dataBytes = new byte[length];
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await UDPClientPool.ReadAddr4Bytes(
 | 
			
		||||
                this.ep, this.taskID, JpegAddr.DDR_FRAME_DATA_ADDR + offset, firstReadLength, this.timeout);
 | 
			
		||||
                this.ep, this.taskID, JpegAddr.ADDR_JPEG_START + offset, firstReadLength, this.timeout);
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to get JPEG frame data: {ret.Error}");
 | 
			
		||||
@@ -194,7 +420,7 @@ public class Jpeg
 | 
			
		||||
        if (secondReadLength > 0)
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await UDPClientPool.ReadAddr4Bytes(
 | 
			
		||||
                this.ep, this.taskID, JpegAddr.DDR_FRAME_DATA_ADDR, secondReadLength, this.timeout);
 | 
			
		||||
                this.ep, this.taskID, JpegAddr.ADDR_JPEG_START, secondReadLength, this.timeout);
 | 
			
		||||
            if (!ret.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to get JPEG frame data: {ret.Error}");
 | 
			
		||||
@@ -239,7 +465,7 @@ public class Jpeg
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            var ret = await UpdatePointer((uint)sizes.Length);
 | 
			
		||||
            var ret = await AddFrameNum2Process((uint)sizes.Length);
 | 
			
		||||
            if (!ret) logger.Error($"Failed to update pointer");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
using System.Net;
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using Peripherals.HdmiInClient;
 | 
			
		||||
using Peripherals.JpegClient;
 | 
			
		||||
 | 
			
		||||
namespace server.Services;
 | 
			
		||||
 | 
			
		||||
@@ -12,18 +13,34 @@ public class HdmiVideoStreamEndpoint
 | 
			
		||||
    public string SnapshotUrl { get; set; } = "";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public class HdmiVideoStreamClient
 | 
			
		||||
{
 | 
			
		||||
    public required HdmiIn HdmiInClient { get; set; }
 | 
			
		||||
 | 
			
		||||
    public required Jpeg JpegClient { get; set; }
 | 
			
		||||
 | 
			
		||||
    public required CancellationTokenSource CTS { get; set; }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
{
 | 
			
		||||
    private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    private readonly IServiceProvider _serviceProvider;
 | 
			
		||||
 | 
			
		||||
    private HttpListener? _httpListener;
 | 
			
		||||
    private readonly int _serverPort = 4322;
 | 
			
		||||
    private readonly ConcurrentDictionary<string, HdmiIn> _hdmiInDict = new();
 | 
			
		||||
    private readonly ConcurrentDictionary<string, CancellationTokenSource> _hdmiInCtsDict = new();
 | 
			
		||||
    private readonly ConcurrentDictionary<string, HdmiVideoStreamClient> _clientDict = new();
 | 
			
		||||
 | 
			
		||||
    public HttpHdmiVideoStreamService(IServiceProvider serviceProvider)
 | 
			
		||||
    {
 | 
			
		||||
        _serviceProvider = serviceProvider;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public override async Task StartAsync(CancellationToken cancellationToken)
 | 
			
		||||
    {
 | 
			
		||||
        _httpListener = new HttpListener();
 | 
			
		||||
        _httpListener.Prefixes.Add($"http://{Global.localhost}:{_serverPort}/");
 | 
			
		||||
        _httpListener.Prefixes.Add($"http://{Global.LocalHost}:{_serverPort}/");
 | 
			
		||||
        _httpListener.Start();
 | 
			
		||||
        logger.Info($"HDMI Video Stream Service started on port {_serverPort}");
 | 
			
		||||
 | 
			
		||||
@@ -67,7 +84,7 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
 | 
			
		||||
        // 禁用所有活跃的HDMI传输
 | 
			
		||||
        var disableTasks = new List<Task>();
 | 
			
		||||
        foreach (var hdmiKey in _hdmiInDict.Keys)
 | 
			
		||||
        foreach (var hdmiKey in _clientDict.Keys)
 | 
			
		||||
        {
 | 
			
		||||
            disableTasks.Add(DisableHdmiTransmissionAsync(hdmiKey));
 | 
			
		||||
        }
 | 
			
		||||
@@ -76,8 +93,7 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
        await Task.WhenAll(disableTasks);
 | 
			
		||||
 | 
			
		||||
        // 清空字典
 | 
			
		||||
        _hdmiInDict.Clear();
 | 
			
		||||
        _hdmiInCtsDict.Clear();
 | 
			
		||||
        _clientDict.Clear();
 | 
			
		||||
 | 
			
		||||
        _httpListener?.Close(); // 立即关闭监听器,唤醒阻塞
 | 
			
		||||
        await base.StopAsync(cancellationToken);
 | 
			
		||||
@@ -87,11 +103,10 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var cts = _hdmiInCtsDict[key];
 | 
			
		||||
            cts.Cancel();
 | 
			
		||||
            var client = _clientDict[key];
 | 
			
		||||
            client.CTS.Cancel();
 | 
			
		||||
 | 
			
		||||
            var hdmiIn = _hdmiInDict[key];
 | 
			
		||||
            var disableResult = await hdmiIn.EnableTrans(false);
 | 
			
		||||
            var disableResult = await client.HdmiInClient.EnableTrans(false);
 | 
			
		||||
            if (disableResult.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Info("Successfully disabled HDMI transmission");
 | 
			
		||||
@@ -107,40 +122,14 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 获取/创建 HdmiIn 实例
 | 
			
		||||
    private async Task<HdmiIn?> GetOrCreateHdmiInAsync(string boardId)
 | 
			
		||||
    private async Task<HdmiVideoStreamClient?> GetOrCreateClientAsync(string boardId)
 | 
			
		||||
    {
 | 
			
		||||
        if (_hdmiInDict.TryGetValue(boardId, out var hdmiIn))
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                var enableResult = await hdmiIn.EnableTrans(true);
 | 
			
		||||
                if (!enableResult.IsSuccessful)
 | 
			
		||||
                {
 | 
			
		||||
                    logger.Error($"Failed to enable HDMI transmission for board {boardId}: {enableResult.Error}");
 | 
			
		||||
                    return null;
 | 
			
		||||
                }
 | 
			
		||||
                logger.Info($"Successfully enabled HDMI transmission for board {boardId}");
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error(ex, $"Exception occurred while enabling HDMI transmission for board {boardId}");
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
        if (_clientDict.TryGetValue(boardId, out var client)) return client;
 | 
			
		||||
 | 
			
		||||
            _hdmiInDict[boardId] = hdmiIn;
 | 
			
		||||
            _hdmiInCtsDict[boardId] = new CancellationTokenSource();
 | 
			
		||||
            return hdmiIn;
 | 
			
		||||
        }
 | 
			
		||||
        using var scope = _serviceProvider.CreateScope();
 | 
			
		||||
        var userManager = scope.ServiceProvider.GetRequiredService<Database.UserManager>();
 | 
			
		||||
 | 
			
		||||
        var db = new Database.AppDataConnection();
 | 
			
		||||
        if (db == null)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error("Failed to create HdmiIn instance");
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var boardRet = db.GetBoardByID(Guid.Parse(boardId));
 | 
			
		||||
        var boardRet = userManager.GetBoardByID(Guid.Parse(boardId));
 | 
			
		||||
        if (!boardRet.IsSuccessful || !boardRet.Value.HasValue)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"Failed to get board with ID {boardId}");
 | 
			
		||||
@@ -149,18 +138,31 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
 | 
			
		||||
        var board = boardRet.Value.Value;
 | 
			
		||||
 | 
			
		||||
        hdmiIn = new HdmiIn(board.IpAddr, board.Port, 0); // taskID 可根据实际需求调整
 | 
			
		||||
        client = new HdmiVideoStreamClient()
 | 
			
		||||
        {
 | 
			
		||||
            HdmiInClient = new HdmiIn(board.IpAddr, board.Port, 1),
 | 
			
		||||
            JpegClient = new Jpeg(board.IpAddr, board.Port, 1),
 | 
			
		||||
            CTS = new CancellationTokenSource()
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        // 启用HDMI传输
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var enableResult = await hdmiIn.EnableTrans(true);
 | 
			
		||||
            if (!enableResult.IsSuccessful)
 | 
			
		||||
            var hdmiEnableRet = await client.HdmiInClient.EnableTrans(true);
 | 
			
		||||
            if (!hdmiEnableRet.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to enable HDMI transmission for board {boardId}: {enableResult.Error}");
 | 
			
		||||
                logger.Error($"Failed to enable HDMI transmission for board {boardId}: {hdmiEnableRet.Error}");
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
            logger.Info($"Successfully enabled HDMI transmission for board {boardId}");
 | 
			
		||||
 | 
			
		||||
            var jpegEnableRet = await client.JpegClient.Init(true);
 | 
			
		||||
            if (!jpegEnableRet.IsSuccessful)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error($"Failed to enable JPEG transmission for board {boardId}: {jpegEnableRet.Error}");
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
            logger.Info($"Successfully enabled JPEG transmission for board {boardId}");
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
@@ -168,9 +170,8 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        _hdmiInDict[boardId] = hdmiIn;
 | 
			
		||||
        _hdmiInCtsDict[boardId] = new CancellationTokenSource();
 | 
			
		||||
        return hdmiIn;
 | 
			
		||||
        _clientDict[boardId] = client;
 | 
			
		||||
        return client;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async Task HandleRequestAsync(HttpListenerContext context, CancellationToken cancellationToken)
 | 
			
		||||
@@ -183,14 +184,14 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var hdmiIn = await GetOrCreateHdmiInAsync(boardId);
 | 
			
		||||
        if (hdmiIn == null)
 | 
			
		||||
        var client = await GetOrCreateClientAsync(boardId);
 | 
			
		||||
        if (client == null)
 | 
			
		||||
        {
 | 
			
		||||
            await SendErrorAsync(context.Response, "Invalid boardId or board not available");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var hdmiInToken = _hdmiInCtsDict[boardId].Token;
 | 
			
		||||
        var hdmiInToken = _clientDict[boardId].CTS.Token;
 | 
			
		||||
        if (hdmiInToken == null)
 | 
			
		||||
        {
 | 
			
		||||
            await SendErrorAsync(context.Response, "HDMI input is not available");
 | 
			
		||||
@@ -199,11 +200,11 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
 | 
			
		||||
        if (path == "/snapshot")
 | 
			
		||||
        {
 | 
			
		||||
            await HandleSnapshotRequestAsync(context.Response, hdmiIn, hdmiInToken);
 | 
			
		||||
            await HandleSnapshotRequestAsync(context.Response, client, hdmiInToken);
 | 
			
		||||
        }
 | 
			
		||||
        else if (path == "/mjpeg")
 | 
			
		||||
        {
 | 
			
		||||
            await HandleMjpegStreamAsync(context.Response, hdmiIn, hdmiInToken);
 | 
			
		||||
            await HandleMjpegStreamAsync(context.Response, client, hdmiInToken);
 | 
			
		||||
        }
 | 
			
		||||
        else if (path == "/video")
 | 
			
		||||
        {
 | 
			
		||||
@@ -215,14 +216,15 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async Task HandleSnapshotRequestAsync(HttpListenerResponse response, HdmiIn hdmiIn, CancellationToken cancellationToken)
 | 
			
		||||
    private async Task HandleSnapshotRequestAsync(
 | 
			
		||||
        HttpListenerResponse response, HdmiVideoStreamClient client, CancellationToken cancellationToken)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            logger.Debug("处理HDMI快照请求");
 | 
			
		||||
 | 
			
		||||
            // 从HDMI读取RGB565数据
 | 
			
		||||
            var frameResult = await hdmiIn.ReadFrame();
 | 
			
		||||
            var frameResult = await client.HdmiInClient.ReadFrame();
 | 
			
		||||
            if (!frameResult.IsSuccessful || frameResult.Value == null)
 | 
			
		||||
            {
 | 
			
		||||
                logger.Error("HDMI快照获取失败");
 | 
			
		||||
@@ -256,7 +258,8 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async Task HandleMjpegStreamAsync(HttpListenerResponse response, HdmiIn hdmiIn, CancellationToken cancellationToken)
 | 
			
		||||
    private async Task HandleMjpegStreamAsync(
 | 
			
		||||
        HttpListenerResponse response, HdmiVideoStreamClient client, CancellationToken cancellationToken)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
@@ -276,7 +279,7 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
                {
 | 
			
		||||
                    var frameStartTime = DateTime.UtcNow;
 | 
			
		||||
 | 
			
		||||
                    var ret = await hdmiIn.GetMJpegFrame();
 | 
			
		||||
                    var ret = await client.HdmiInClient.GetMJpegFrame();
 | 
			
		||||
                    if (ret == null) continue;
 | 
			
		||||
                    var frame = ret.Value;
 | 
			
		||||
 | 
			
		||||
@@ -311,7 +314,7 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                // 停止传输时禁用HDMI传输
 | 
			
		||||
                await hdmiIn.EnableTrans(false);
 | 
			
		||||
                await client.HdmiInClient.EnableTrans(false);
 | 
			
		||||
                logger.Info("已禁用HDMI传输");
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
@@ -366,8 +369,10 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
    /// <returns>返回所有可用的HDMI视频流终端点列表</returns>
 | 
			
		||||
    public List<HdmiVideoStreamEndpoint>? GetAllVideoEndpoints()
 | 
			
		||||
    {
 | 
			
		||||
        var db = new Database.AppDataConnection();
 | 
			
		||||
        var boards = db?.GetAllBoard();
 | 
			
		||||
        using var scope = _serviceProvider.CreateScope();
 | 
			
		||||
        var userManager = scope.ServiceProvider.GetRequiredService<Database.UserManager>();
 | 
			
		||||
 | 
			
		||||
        var boards = userManager.GetAllBoard();
 | 
			
		||||
        if (boards == null)
 | 
			
		||||
            return null;
 | 
			
		||||
 | 
			
		||||
@@ -377,9 +382,9 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
            endpoints.Add(new HdmiVideoStreamEndpoint
 | 
			
		||||
            {
 | 
			
		||||
                BoardId = board.ID.ToString(),
 | 
			
		||||
                MjpegUrl = $"http://{Global.localhost}:{_serverPort}/mjpeg?boardId={board.ID}",
 | 
			
		||||
                VideoUrl = $"http://{Global.localhost}:{_serverPort}/video?boardId={board.ID}",
 | 
			
		||||
                SnapshotUrl = $"http://{Global.localhost}:{_serverPort}/snapshot?boardId={board.ID}"
 | 
			
		||||
                MjpegUrl = $"http://{Global.LocalHost}:{_serverPort}/mjpeg?boardId={board.ID}",
 | 
			
		||||
                VideoUrl = $"http://{Global.LocalHost}:{_serverPort}/video?boardId={board.ID}",
 | 
			
		||||
                SnapshotUrl = $"http://{Global.LocalHost}:{_serverPort}/snapshot?boardId={board.ID}"
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
        return endpoints;
 | 
			
		||||
@@ -395,9 +400,9 @@ public class HttpHdmiVideoStreamService : BackgroundService
 | 
			
		||||
        return new HdmiVideoStreamEndpoint
 | 
			
		||||
        {
 | 
			
		||||
            BoardId = boardId,
 | 
			
		||||
            MjpegUrl = $"http://{Global.localhost}:{_serverPort}/mjpeg?boardId={boardId}",
 | 
			
		||||
            VideoUrl = $"http://{Global.localhost}:{_serverPort}/video?boardId={boardId}",
 | 
			
		||||
            SnapshotUrl = $"http://{Global.localhost}:{_serverPort}/snapshot?boardId={boardId}"
 | 
			
		||||
            MjpegUrl = $"http://{Global.LocalHost}:{_serverPort}/mjpeg?boardId={boardId}",
 | 
			
		||||
            VideoUrl = $"http://{Global.LocalHost}:{_serverPort}/video?boardId={boardId}",
 | 
			
		||||
            SnapshotUrl = $"http://{Global.LocalHost}:{_serverPort}/snapshot?boardId={boardId}"
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,7 @@ namespace server.Services;
 | 
			
		||||
public class VideoStreamClient
 | 
			
		||||
{
 | 
			
		||||
    public string? ClientId { get; set; } = string.Empty;
 | 
			
		||||
    public bool IsEnabled { get; set; } = true;
 | 
			
		||||
    public int FrameWidth { get; set; }
 | 
			
		||||
    public int FrameHeight { get; set; }
 | 
			
		||||
    public int FrameRate { get; set; }
 | 
			
		||||
@@ -35,28 +36,35 @@ public class VideoStreamClient
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// 表示摄像头连接状态信息
 | 
			
		||||
/// </summary>
 | 
			
		||||
public class VideoEndpoint
 | 
			
		||||
public class VideoStreamEndpoint
 | 
			
		||||
{
 | 
			
		||||
    public string BoardId { get; set; } = "";
 | 
			
		||||
    public string MjpegUrl { get; set; } = "";
 | 
			
		||||
    public string VideoUrl { get; set; } = "";
 | 
			
		||||
    public string SnapshotUrl { get; set; } = "";
 | 
			
		||||
    public required string BoardId { get; set; } = "";
 | 
			
		||||
    public required string MjpegUrl { get; set; } = "";
 | 
			
		||||
    public required string VideoUrl { get; set; } = "";
 | 
			
		||||
    public required string SnapshotUrl { get; set; } = "";
 | 
			
		||||
    public required string HtmlUrl { get; set; } = "";
 | 
			
		||||
    public required string UsbCameraUrl { get; set; } = "";
 | 
			
		||||
 | 
			
		||||
    public required bool IsEnabled { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 视频流的帧率(FPS)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public int FrameRate { get; set; }
 | 
			
		||||
    public required int FrameRate { get; set; }
 | 
			
		||||
 | 
			
		||||
    public int FrameWidth { get; set; }
 | 
			
		||||
    public int FrameHeight { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 视频分辨率(如 640x480)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public string Resolution { get; set; } = string.Empty;
 | 
			
		||||
    public string Resolution => $"{FrameWidth}x{FrameHeight}";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// 表示视频流服务的运行状态
 | 
			
		||||
/// </summary>
 | 
			
		||||
public class ServiceStatus
 | 
			
		||||
public class VideoStreamServiceStatus
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 服务是否正在运行
 | 
			
		||||
@@ -71,7 +79,7 @@ public class ServiceStatus
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 当前连接的客户端端点列表
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public List<VideoEndpoint> ClientEndpoints { get; set; } = new();
 | 
			
		||||
    public List<VideoStreamEndpoint> ClientEndpoints { get; set; } = new();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 当前连接的客户端数量
 | 
			
		||||
@@ -87,6 +95,8 @@ public class HttpVideoStreamService : BackgroundService
 | 
			
		||||
{
 | 
			
		||||
    private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
 | 
			
		||||
 | 
			
		||||
    private readonly IServiceProvider _serviceProvider;
 | 
			
		||||
 | 
			
		||||
    private HttpListener? _httpListener;
 | 
			
		||||
    private readonly int _serverPort = 4321;
 | 
			
		||||
 | 
			
		||||
@@ -99,13 +109,60 @@ public class HttpVideoStreamService : BackgroundService
 | 
			
		||||
    private readonly object _usbCameraLock = new object();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    public HttpVideoStreamService(IServiceProvider serviceProvider)
 | 
			
		||||
    {
 | 
			
		||||
        _serviceProvider = serviceProvider;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Optional<VideoStreamClient> TryGetClient(string boardId)
 | 
			
		||||
    {
 | 
			
		||||
        if (_clientDict.TryGetValue(boardId, out var client))
 | 
			
		||||
        {
 | 
			
		||||
            return client;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async Task<VideoStreamClient?> GetOrCreateClientAsync(string boardId, int initWidth, int initHeight)
 | 
			
		||||
    {
 | 
			
		||||
        if (_clientDict.TryGetValue(boardId, out var client))
 | 
			
		||||
        {
 | 
			
		||||
            // 可在此处做分辨率/Camera等配置更新
 | 
			
		||||
            return client;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        using var scope = _serviceProvider.CreateScope();
 | 
			
		||||
        var userManager = scope.ServiceProvider.GetRequiredService<Database.UserManager>();
 | 
			
		||||
 | 
			
		||||
        var boardRet = userManager.GetBoardByID(Guid.Parse(boardId));
 | 
			
		||||
        if (!boardRet.IsSuccessful || !boardRet.Value.HasValue)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"Failed to get board with ID {boardId}");
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var board = boardRet.Value.Value;
 | 
			
		||||
 | 
			
		||||
        var camera = new Peripherals.CameraClient.Camera(board.IpAddr, board.Port);
 | 
			
		||||
        var ret = await camera.Init();
 | 
			
		||||
        if (!ret.IsSuccessful || !ret.Value)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error("Camera Init Failed!");
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        client = new VideoStreamClient(boardId, initWidth, initHeight, camera);
 | 
			
		||||
        _clientDict[boardId] = client;
 | 
			
		||||
        return client;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 初始化 HttpVideoStreamService
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public override async Task StartAsync(CancellationToken cancellationToken)
 | 
			
		||||
    {
 | 
			
		||||
        _httpListener = new HttpListener();
 | 
			
		||||
        _httpListener.Prefixes.Add($"http://{Global.localhost}:{_serverPort}/");
 | 
			
		||||
        _httpListener.Prefixes.Add($"http://{Global.LocalHost}:{_serverPort}/");
 | 
			
		||||
        _httpListener.Start();
 | 
			
		||||
        logger.Info($"Video Stream Service started on port {_serverPort}");
 | 
			
		||||
 | 
			
		||||
@@ -130,53 +187,6 @@ public class HttpVideoStreamService : BackgroundService
 | 
			
		||||
        await base.StopAsync(cancellationToken);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Optional<VideoStreamClient> TryGetClient(string boardId)
 | 
			
		||||
    {
 | 
			
		||||
        if (_clientDict.TryGetValue(boardId, out var client))
 | 
			
		||||
        {
 | 
			
		||||
            return client;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async Task<VideoStreamClient?> GetOrCreateClientAsync(string boardId, int initWidth, int initHeight)
 | 
			
		||||
    {
 | 
			
		||||
        if (_clientDict.TryGetValue(boardId, out var client))
 | 
			
		||||
        {
 | 
			
		||||
            // 可在此处做分辨率/Camera等配置更新
 | 
			
		||||
            return client;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var db = new Database.AppDataConnection();
 | 
			
		||||
        if (db == null)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error("Failed to create HdmiIn instance");
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var boardRet = db.GetBoardByID(Guid.Parse(boardId));
 | 
			
		||||
        if (!boardRet.IsSuccessful || !boardRet.Value.HasValue)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error($"Failed to get board with ID {boardId}");
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var board = boardRet.Value.Value;
 | 
			
		||||
 | 
			
		||||
        var camera = new Peripherals.CameraClient.Camera(board.IpAddr, board.Port);
 | 
			
		||||
        var ret = await camera.Init();
 | 
			
		||||
        if (!ret.IsSuccessful || !ret.Value)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error("Camera Init Failed!");
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        client = new VideoStreamClient(boardId, initWidth, initHeight, camera);
 | 
			
		||||
        _clientDict[boardId] = client;
 | 
			
		||||
        return client;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 执行 HTTP 视频流服务
 | 
			
		||||
    /// </summary>
 | 
			
		||||
@@ -254,6 +264,11 @@ public class HttpVideoStreamService : BackgroundService
 | 
			
		||||
                // 单帧图像请求
 | 
			
		||||
                await HandleSnapshotRequestAsync(context.Response, client, cancellationToken);
 | 
			
		||||
            }
 | 
			
		||||
            else if (path == "/html")
 | 
			
		||||
            {
 | 
			
		||||
                // HTML页面请求
 | 
			
		||||
                await SendIndexHtmlPageAsync(context.Response);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                // 默认返回简单的HTML页面,提供链接到视频页面
 | 
			
		||||
@@ -668,42 +683,12 @@ public class HttpVideoStreamService : BackgroundService
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public VideoEndpoint GetVideoEndpoint(string boardId)
 | 
			
		||||
    {
 | 
			
		||||
        var client = TryGetClient(boardId).OrThrow(() => new Exception($"无法获取摄像头客户端: {boardId}"));
 | 
			
		||||
 | 
			
		||||
        return new VideoEndpoint
 | 
			
		||||
        {
 | 
			
		||||
            BoardId = boardId,
 | 
			
		||||
            MjpegUrl = $"http://{Global.localhost}:{_serverPort}/mjpeg?boardId={boardId}",
 | 
			
		||||
            VideoUrl = $"http://{Global.localhost}:{_serverPort}/video?boardId={boardId}",
 | 
			
		||||
            SnapshotUrl = $"http://{Global.localhost}:{_serverPort}/snapshot?boardId={boardId}",
 | 
			
		||||
            Resolution = $"{client.FrameWidth}x{client.FrameHeight}",
 | 
			
		||||
            FrameRate = client.FrameRate
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<VideoEndpoint> GetAllVideoEndpoints()
 | 
			
		||||
    {
 | 
			
		||||
        var endpoints = new List<VideoEndpoint>();
 | 
			
		||||
 | 
			
		||||
        foreach (var boardId in _clientDict.Keys)
 | 
			
		||||
            endpoints.Add(GetVideoEndpoint(boardId));
 | 
			
		||||
 | 
			
		||||
        return endpoints;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ServiceStatus GetServiceStatus()
 | 
			
		||||
    {
 | 
			
		||||
        return new ServiceStatus
 | 
			
		||||
        {
 | 
			
		||||
            IsRunning = true,
 | 
			
		||||
            ServerPort = _serverPort,
 | 
			
		||||
            ClientEndpoints = GetAllVideoEndpoints()
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async Task DisableHdmiTransmissionAsync(string boardId)
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 配置摄像头连接参数
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="boardId">板卡ID</param>
 | 
			
		||||
    /// <returns>配置是否成功</returns>
 | 
			
		||||
    public async Task<bool> ConfigureCameraAsync(string boardId)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
@@ -711,8 +696,67 @@ public class HttpVideoStreamService : BackgroundService
 | 
			
		||||
 | 
			
		||||
            using (await client.Lock.AcquireWriteLockAsync())
 | 
			
		||||
            {
 | 
			
		||||
                var ret = await client.Camera.Init();
 | 
			
		||||
                if (!ret.IsSuccessful)
 | 
			
		||||
                {
 | 
			
		||||
                    logger.Error(ret.Error);
 | 
			
		||||
                    throw ret.Error;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (!ret.Value)
 | 
			
		||||
                {
 | 
			
		||||
                    logger.Error($"Camera Init Failed!");
 | 
			
		||||
                    throw new Exception($"Camera Init Failed!");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            using (await client.Lock.AcquireWriteLockAsync())
 | 
			
		||||
            {
 | 
			
		||||
                var ret = await client.Camera.ChangeResolution(client.FrameWidth, client.FrameHeight);
 | 
			
		||||
                if (!ret.IsSuccessful)
 | 
			
		||||
                {
 | 
			
		||||
                    logger.Error(ret.Error);
 | 
			
		||||
                    throw ret.Error;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (!ret.Value)
 | 
			
		||||
                {
 | 
			
		||||
                    logger.Error($"Camera Resolution Change Failed!");
 | 
			
		||||
                    throw new Exception($"Camera Resolution Change Failed!");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            logger.Error(ex, "配置摄像头连接时发生错误");
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async Task SetVideoStreamEnableAsync(string boardId, bool enable)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var client = TryGetClient(boardId).OrThrow(() => new Exception($"无法获取摄像头客户端: {boardId}"));
 | 
			
		||||
 | 
			
		||||
            if (client.IsEnabled == enable)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            using (await client.Lock.AcquireWriteLockAsync())
 | 
			
		||||
            {
 | 
			
		||||
                if (enable)
 | 
			
		||||
                {
 | 
			
		||||
                    client.CTS = new CancellationTokenSource();
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    client.CTS.Cancel();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                var camera = client.Camera;
 | 
			
		||||
                var disableResult = await camera.EnableHardwareTrans(false);
 | 
			
		||||
                var disableResult = await camera.EnableHardwareTrans(enable);
 | 
			
		||||
                if (disableResult.IsSuccessful && disableResult.Value)
 | 
			
		||||
                    logger.Info($"Successfully disabled camera {boardId} hardware transmission");
 | 
			
		||||
                else
 | 
			
		||||
@@ -743,4 +787,41 @@ public class HttpVideoStreamService : BackgroundService
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public VideoStreamEndpoint GetVideoEndpoint(string boardId)
 | 
			
		||||
    {
 | 
			
		||||
        var client = TryGetClient(boardId).OrThrow(() => new Exception($"无法获取摄像头客户端: {boardId}"));
 | 
			
		||||
 | 
			
		||||
        return new VideoStreamEndpoint
 | 
			
		||||
        {
 | 
			
		||||
            BoardId = boardId,
 | 
			
		||||
            MjpegUrl = $"http://{Global.LocalHost}:{_serverPort}/mjpeg?boardId={boardId}",
 | 
			
		||||
            VideoUrl = $"http://{Global.LocalHost}:{_serverPort}/video?boardId={boardId}",
 | 
			
		||||
            SnapshotUrl = $"http://{Global.LocalHost}:{_serverPort}/snapshot?boardId={boardId}",
 | 
			
		||||
            UsbCameraUrl = $"http://{Global.LocalHost}:{_serverPort}/usbCamera?boardId={boardId}",
 | 
			
		||||
            HtmlUrl = $"http://{Global.LocalHost}:{_serverPort}/html?boardId={boardId}",
 | 
			
		||||
            IsEnabled = client.IsEnabled,
 | 
			
		||||
            FrameRate = client.FrameRate
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<VideoStreamEndpoint> GetAllVideoEndpoints()
 | 
			
		||||
    {
 | 
			
		||||
        var endpoints = new List<VideoStreamEndpoint>();
 | 
			
		||||
 | 
			
		||||
        foreach (var boardId in _clientDict.Keys)
 | 
			
		||||
            endpoints.Add(GetVideoEndpoint(boardId));
 | 
			
		||||
 | 
			
		||||
        return endpoints;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public VideoStreamServiceStatus GetServiceStatus()
 | 
			
		||||
    {
 | 
			
		||||
        return new VideoStreamServiceStatus
 | 
			
		||||
        {
 | 
			
		||||
            IsRunning = true,
 | 
			
		||||
            ServerPort = _serverPort,
 | 
			
		||||
            ClientEndpoints = GetAllVideoEndpoints()
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -331,7 +331,9 @@ public class UDPClientPool
 | 
			
		||||
    /// <param name="timeout">超时时间(毫秒)</param>
 | 
			
		||||
    /// <returns>校验结果,true表示在超时前数据匹配期望值</returns>
 | 
			
		||||
    public static async ValueTask<Result<bool>> ReadAddrWithWait(
 | 
			
		||||
            IPEndPoint endPoint, int taskID, uint devAddr, UInt32 result, UInt32 resultMask, int waittime = 100, int timeout = 1000)
 | 
			
		||||
            IPEndPoint endPoint, int taskID, uint devAddr,
 | 
			
		||||
            UInt32 result, UInt32 resultMask,
 | 
			
		||||
            int waittime = 100, int timeout = 1000)
 | 
			
		||||
    {
 | 
			
		||||
        var address = endPoint.Address.ToString();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										906
									
								
								src/APIClient.ts
									
									
									
									
									
								
							
							
						
						
									
										906
									
								
								src/APIClient.ts
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -4,13 +4,13 @@ import Dialog from "./components/Dialog.vue";
 | 
			
		||||
import { Alert, useAlertProvider } from "./components/Alert";
 | 
			
		||||
import { ref, provide, computed, onMounted } from "vue";
 | 
			
		||||
import { useRouter } from "vue-router";
 | 
			
		||||
import { useThemeStore } from "./stores/theme";
 | 
			
		||||
 | 
			
		||||
const router = useRouter();
 | 
			
		||||
const theme = useThemeStore();
 | 
			
		||||
 | 
			
		||||
// 主题切换状态管理
 | 
			
		||||
const isDarkMode = ref(
 | 
			
		||||
  window.matchMedia("(prefers-color-scheme: dark)").matches,
 | 
			
		||||
);
 | 
			
		||||
const isDarkMode = ref(theme.isDarkTheme());
 | 
			
		||||
 | 
			
		||||
// Navbar显示状态管理
 | 
			
		||||
const showNavbar = ref(true);
 | 
			
		||||
@@ -46,6 +46,7 @@ const applyTheme = () => {
 | 
			
		||||
// 切换主题
 | 
			
		||||
const toggleTheme = () => {
 | 
			
		||||
  isDarkMode.value = !isDarkMode.value;
 | 
			
		||||
  theme.toggleTheme();
 | 
			
		||||
  applyTheme();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										33
									
								
								src/components/MarkdownEditor.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/components/MarkdownEditor.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import { ref } from "vue";
 | 
			
		||||
import { MdEditor } from "md-editor-v3";
 | 
			
		||||
import "md-editor-v3/lib/style.css";
 | 
			
		||||
import { useThemeStore } from "@/stores/theme";
 | 
			
		||||
 | 
			
		||||
const theme = useThemeStore();
 | 
			
		||||
 | 
			
		||||
const text = ref("# Hello Editor");
 | 
			
		||||
 | 
			
		||||
async function handleSaveEvent(v: string, h: Promise<string>) {}
 | 
			
		||||
 | 
			
		||||
async function loadMarkdownFromString(markdown: string) {
 | 
			
		||||
  text.value = markdown;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function loadMarkdownFromUrl(url: string) {
 | 
			
		||||
  const response = await fetch(url);
 | 
			
		||||
  const markdown = await response.text();
 | 
			
		||||
  text.value = markdown;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
defineExpose({
 | 
			
		||||
  loadMarkdownFromString,
 | 
			
		||||
  loadMarkdownFromUrl,
 | 
			
		||||
});
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<template>
 | 
			
		||||
  <MdEditor v-model="text" :theme="theme.currentMode" />
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<style lang="postcss" scoped></style>
 | 
			
		||||
@@ -44,7 +44,7 @@
 | 
			
		||||
            </router-link>
 | 
			
		||||
          </li>
 | 
			
		||||
          <li class="my-1 hover:translate-x-1 transition-all duration-300">
 | 
			
		||||
            <router-link to="/markdown-test" class="text-base font-medium">
 | 
			
		||||
            <router-link to="/markdown" class="text-base font-medium">
 | 
			
		||||
              <FileText class="icon" />
 | 
			
		||||
              Markdown测试
 | 
			
		||||
            </router-link>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,325 +1,356 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div 
 | 
			
		||||
    class="tutorial-carousel relative"
 | 
			
		||||
    @wheel.prevent="handleWheel"
 | 
			
		||||
    @mouseenter="pauseAutoRotation"
 | 
			
		||||
    @mouseleave="resumeAutoRotation"
 | 
			
		||||
  >    <!-- 例程卡片堆叠 -->
 | 
			
		||||
    <div class="card-stack relative mx-auto">
 | 
			
		||||
      <div 
 | 
			
		||||
        v-for="(tutorial, index) in tutorials" 
 | 
			
		||||
        :key="index" 
 | 
			
		||||
        class="tutorial-card absolute transition-all duration-500 ease-in-out rounded-2xl shadow-2xl border-4 border-base-300 overflow-hidden"
 | 
			
		||||
        :class="getCardClass(index)"
 | 
			
		||||
        :style="getCardStyle(index)"
 | 
			
		||||
        @click="handleCardClick(index, tutorial.id)"
 | 
			
		||||
      >
 | 
			
		||||
        <!-- 卡片内容 -->
 | 
			
		||||
        <div class="relative">
 | 
			
		||||
          <!-- 图片 -->          <img 
 | 
			
		||||
            :src="tutorial.thumbnail || `https://placehold.co/600x400?text=${tutorial.title}`" 
 | 
			
		||||
            class="w-full object-contain"
 | 
			
		||||
            :alt="tutorial.title"
 | 
			
		||||
            style="width: 600px; height: 400px;"
 | 
			
		||||
          />
 | 
			
		||||
          
 | 
			
		||||
          <!-- 卡片蒙层 -->
 | 
			
		||||
          <div 
 | 
			
		||||
            class="absolute inset-0 bg-primary opacity-20 transition-opacity duration-300"
 | 
			
		||||
            :class="{'opacity-10': index === currentIndex}"
 | 
			
		||||
          ></div>
 | 
			
		||||
          
 | 
			
		||||
          <!-- 标题覆盖层 -->
 | 
			
		||||
          <div class="absolute bottom-0 left-0 right-0 p-4 bg-gradient-to-t from-base-300 to-transparent">
 | 
			
		||||
            <div class="flex flex-col gap-2">
 | 
			
		||||
              <h3 class="text-lg font-bold text-base-content">{{ tutorial.title }}</h3>
 | 
			
		||||
              <p class="text-sm opacity-80 truncate">{{ tutorial.description }}</p>
 | 
			
		||||
              <!-- 标签显示 -->
 | 
			
		||||
              <div v-if="tutorial.tags && tutorial.tags.length > 0" class="flex flex-wrap gap-1">
 | 
			
		||||
                <span 
 | 
			
		||||
                  v-for="tag in tutorial.tags.slice(0, 3)" 
 | 
			
		||||
                  :key="tag" 
 | 
			
		||||
                  class="badge badge-outline badge-xs text-xs"
 | 
			
		||||
                >
 | 
			
		||||
                  {{ tag }}
 | 
			
		||||
                </span>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
    
 | 
			
		||||
    <!-- 导航指示器 -->
 | 
			
		||||
    <div class="indicators flex justify-center gap-2 mt-4">
 | 
			
		||||
      <button 
 | 
			
		||||
        v-for="(_, index) in tutorials" 
 | 
			
		||||
        :key="index"
 | 
			
		||||
        @click="setActiveCard(index)"
 | 
			
		||||
        class="w-3 h-3 rounded-full transition-all duration-300"
 | 
			
		||||
        :class="index === currentIndex ? 'bg-primary scale-125' : 'bg-base-300'"
 | 
			
		||||
      ></button>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import { ref, onMounted, onUnmounted } from 'vue';
 | 
			
		||||
import { useRouter } from 'vue-router';
 | 
			
		||||
import { AuthManager } from '@/utils/AuthManager';
 | 
			
		||||
import type { ExamSummary } from '@/APIClient';
 | 
			
		||||
 | 
			
		||||
// 接口定义
 | 
			
		||||
interface Tutorial {
 | 
			
		||||
  id: string;
 | 
			
		||||
  title: string;
 | 
			
		||||
  description: string;
 | 
			
		||||
  thumbnail?: string;
 | 
			
		||||
  tags: string[];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Props
 | 
			
		||||
const props = defineProps<{
 | 
			
		||||
  autoRotationInterval?: number;
 | 
			
		||||
}>();
 | 
			
		||||
 | 
			
		||||
// 配置默认值
 | 
			
		||||
const autoRotationInterval = props.autoRotationInterval || 5000; // 默认5秒
 | 
			
		||||
 | 
			
		||||
// 状态管理
 | 
			
		||||
const tutorials = ref<Tutorial[]>([]);
 | 
			
		||||
const currentIndex = ref(0);
 | 
			
		||||
const router = useRouter();
 | 
			
		||||
let autoRotationTimer: number | null = null;
 | 
			
		||||
 | 
			
		||||
// 处理卡片点击
 | 
			
		||||
const handleCardClick = (index: number, tutorialId: string) => {
 | 
			
		||||
  if (index === currentIndex.value) {
 | 
			
		||||
    goToExam(tutorialId);
 | 
			
		||||
  } else {
 | 
			
		||||
    setActiveCard(index);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 从数据库加载实验数据
 | 
			
		||||
onMounted(async () => {
 | 
			
		||||
  try {
 | 
			
		||||
    console.log('正在从数据库加载实验数据...');
 | 
			
		||||
    
 | 
			
		||||
    // 创建认证客户端
 | 
			
		||||
    const client = AuthManager.createAuthenticatedExamClient();
 | 
			
		||||
    
 | 
			
		||||
    // 获取实验列表
 | 
			
		||||
    const examList: ExamSummary[] = await client.getExamList();
 | 
			
		||||
    
 | 
			
		||||
    // 筛选可见的实验并转换为Tutorial格式
 | 
			
		||||
    const visibleExams = examList
 | 
			
		||||
      .filter(exam => exam.isVisibleToUsers)
 | 
			
		||||
      .slice(0, 6); // 限制轮播显示最多6个实验
 | 
			
		||||
    
 | 
			
		||||
    if (visibleExams.length === 0) {
 | 
			
		||||
      console.warn('没有找到可见的实验');
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // 转换数据格式并获取封面图片
 | 
			
		||||
    const tutorialPromises = visibleExams.map(async (exam) => {
 | 
			
		||||
      let thumbnail: string | undefined;
 | 
			
		||||
      
 | 
			
		||||
      try {
 | 
			
		||||
        // 获取实验的封面资源(模板资源)
 | 
			
		||||
        const resourceClient = AuthManager.createAuthenticatedResourceClient();
 | 
			
		||||
        const resourceList = await resourceClient.getResourceList(exam.id, 'cover', 'template');
 | 
			
		||||
        if (resourceList && resourceList.length > 0) {
 | 
			
		||||
          // 使用第一个封面资源
 | 
			
		||||
          const coverResource = resourceList[0];
 | 
			
		||||
          const fileResponse = await resourceClient.getResourceById(coverResource.id);
 | 
			
		||||
          // 创建Blob URL作为缩略图
 | 
			
		||||
          thumbnail = URL.createObjectURL(fileResponse.data);
 | 
			
		||||
        }
 | 
			
		||||
      } catch (error) {
 | 
			
		||||
        console.warn(`无法获取实验${exam.id}的封面图片:`, error);
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      return {
 | 
			
		||||
        id: exam.id,
 | 
			
		||||
        title: exam.name,
 | 
			
		||||
        description: '点击查看实验详情',
 | 
			
		||||
        thumbnail,
 | 
			
		||||
        tags: exam.tags || []
 | 
			
		||||
      };
 | 
			
		||||
    });
 | 
			
		||||
    
 | 
			
		||||
    tutorials.value = await Promise.all(tutorialPromises);
 | 
			
		||||
    
 | 
			
		||||
    console.log('成功加载实验数据:', tutorials.value.length, '个实验');
 | 
			
		||||
    
 | 
			
		||||
    // 启动自动旋转
 | 
			
		||||
    startAutoRotation();
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    console.error('加载实验数据失败:', error);
 | 
			
		||||
    
 | 
			
		||||
    // 如果加载失败,显示默认的占位内容
 | 
			
		||||
    tutorials.value = [{
 | 
			
		||||
      id: 'placeholder',
 | 
			
		||||
      title: '实验数据加载中...',
 | 
			
		||||
      description: '请稍后或刷新页面重试',
 | 
			
		||||
      thumbnail: undefined,
 | 
			
		||||
      tags: []
 | 
			
		||||
    }];
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// 在组件销毁时清除计时器和Blob URLs
 | 
			
		||||
onUnmounted(() => {
 | 
			
		||||
  if (autoRotationTimer) {
 | 
			
		||||
    clearInterval(autoRotationTimer);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  // 清理创建的Blob URLs
 | 
			
		||||
  tutorials.value.forEach(tutorial => {
 | 
			
		||||
    if (tutorial.thumbnail && tutorial.thumbnail.startsWith('blob:')) {
 | 
			
		||||
      URL.revokeObjectURL(tutorial.thumbnail);
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// 鼠标滚轮处理
 | 
			
		||||
const handleWheel = (event: WheelEvent) => {
 | 
			
		||||
  if (event.deltaY > 0) {
 | 
			
		||||
    nextCard();
 | 
			
		||||
  } else {
 | 
			
		||||
    prevCard();
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 下一张卡片
 | 
			
		||||
const nextCard = () => {
 | 
			
		||||
  currentIndex.value = (currentIndex.value + 1) % tutorials.value.length;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 上一张卡片
 | 
			
		||||
const prevCard = () => {
 | 
			
		||||
  currentIndex.value = (currentIndex.value - 1 + tutorials.value.length) % tutorials.value.length;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 设置活动卡片
 | 
			
		||||
const setActiveCard = (index: number) => {
 | 
			
		||||
  currentIndex.value = index;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 自动旋转
 | 
			
		||||
const startAutoRotation = () => {
 | 
			
		||||
  autoRotationTimer = window.setInterval(() => {
 | 
			
		||||
    nextCard();
 | 
			
		||||
  }, autoRotationInterval);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 暂停自动旋转
 | 
			
		||||
const pauseAutoRotation = () => {
 | 
			
		||||
  if (autoRotationTimer) {
 | 
			
		||||
    clearInterval(autoRotationTimer);
 | 
			
		||||
    autoRotationTimer = null;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 恢复自动旋转
 | 
			
		||||
const resumeAutoRotation = () => {
 | 
			
		||||
  if (!autoRotationTimer) {
 | 
			
		||||
    startAutoRotation();
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 前往实验
 | 
			
		||||
const goToExam = (examId: string) => {
 | 
			
		||||
  // 跳转到实验列表页面并传递examId参数,页面将自动打开对应的实验详情模态框
 | 
			
		||||
  router.push({
 | 
			
		||||
    path: '/exam',
 | 
			
		||||
    query: { examId: examId }
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 计算卡片类和样式
 | 
			
		||||
const getCardClass = (index: number) => {
 | 
			
		||||
  const isActive = index === currentIndex.value;
 | 
			
		||||
  const isPrev = (index === currentIndex.value - 1) || (currentIndex.value === 0 && index === tutorials.value.length - 1);
 | 
			
		||||
  const isNext = (index === currentIndex.value + 1) || (currentIndex.value === tutorials.value.length - 1 && index === 0);
 | 
			
		||||
  
 | 
			
		||||
  return {
 | 
			
		||||
    'z-30': isActive,
 | 
			
		||||
    'z-20': isPrev || isNext,
 | 
			
		||||
    'z-10': !isActive && !isPrev && !isNext,
 | 
			
		||||
    'hover:scale-105': isActive,
 | 
			
		||||
    'cursor-pointer': true
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const getCardStyle = (index: number) => {
 | 
			
		||||
  const isActive = index === currentIndex.value;
 | 
			
		||||
  const isPrev = (index === currentIndex.value - 1) || (currentIndex.value === 0 && index === tutorials.value.length - 1);
 | 
			
		||||
  const isNext = (index === currentIndex.value + 1) || (currentIndex.value === tutorials.value.length - 1 && index === 0);
 | 
			
		||||
  
 | 
			
		||||
  // 基本样式
 | 
			
		||||
  let style = {
 | 
			
		||||
    transform: 'scale(1) translateY(0) rotate(0deg)',
 | 
			
		||||
    opacity: '1',
 | 
			
		||||
    filter: 'blur(0)'
 | 
			
		||||
  };
 | 
			
		||||
  
 | 
			
		||||
  // 活动卡片
 | 
			
		||||
  if (isActive) {
 | 
			
		||||
    return style;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  // 上一张卡片
 | 
			
		||||
  if (isPrev) {
 | 
			
		||||
    style.transform = 'scale(0.85) translateY(-10%) rotate(-5deg)';
 | 
			
		||||
    style.opacity = '0.7';
 | 
			
		||||
    style.filter = 'blur(1px)';
 | 
			
		||||
    return style;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  // 下一张卡片
 | 
			
		||||
  if (isNext) {
 | 
			
		||||
    style.transform = 'scale(0.85) translateY(10%) rotate(5deg)';
 | 
			
		||||
    style.opacity = '0.7';
 | 
			
		||||
    style.filter = 'blur(1px)';
 | 
			
		||||
    return style;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  // 其他卡片
 | 
			
		||||
  style.transform = 'scale(0.7) translateY(0) rotate(0deg)';
 | 
			
		||||
  style.opacity = '0.4';
 | 
			
		||||
  style.filter = 'blur(2px)';
 | 
			
		||||
  return style;
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style scoped>
 | 
			
		||||
.tutorial-carousel {
 | 
			
		||||
  width: 100%;
 | 
			
		||||
  height: 500px;
 | 
			
		||||
  perspective: 1000px;
 | 
			
		||||
  display: flex;
 | 
			
		||||
  flex-direction: column;
 | 
			
		||||
  align-items: center;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.card-stack {
 | 
			
		||||
  width: 600px;
 | 
			
		||||
  height: 440px;
 | 
			
		||||
  position: relative;
 | 
			
		||||
  transform-style: preserve-3d;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.tutorial-card {
 | 
			
		||||
  width: 600px;
 | 
			
		||||
  height: 400px;
 | 
			
		||||
  background-color: hsl(var(--b2));
 | 
			
		||||
  will-change: transform, opacity;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.tutorial-card:hover {
 | 
			
		||||
  box-shadow: 0 0 15px rgba(var(--p), 0.5);
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
<template>
 | 
			
		||||
  <div
 | 
			
		||||
    class="tutorial-carousel relative"
 | 
			
		||||
    @wheel.prevent="handleWheel"
 | 
			
		||||
    @mouseenter="pauseAutoRotation"
 | 
			
		||||
    @mouseleave="resumeAutoRotation"
 | 
			
		||||
  >
 | 
			
		||||
    <!-- 例程卡片堆叠 -->
 | 
			
		||||
    <div class="card-stack relative mx-auto">
 | 
			
		||||
      <div
 | 
			
		||||
        v-for="(tutorial, index) in tutorials"
 | 
			
		||||
        :key="index"
 | 
			
		||||
        class="tutorial-card absolute transition-all duration-500 ease-in-out rounded-2xl shadow-2xl border-4 border-base-300 overflow-hidden"
 | 
			
		||||
        :class="getCardClass(index)"
 | 
			
		||||
        :style="getCardStyle(index)"
 | 
			
		||||
        @click="handleCardClick(index, tutorial.id)"
 | 
			
		||||
      >
 | 
			
		||||
        <!-- 卡片内容 -->
 | 
			
		||||
        <div class="relative">
 | 
			
		||||
          <!-- 图片 -->
 | 
			
		||||
          <img
 | 
			
		||||
            :src="
 | 
			
		||||
              tutorial.thumbnail ||
 | 
			
		||||
              `https://kaifage.com/api/placeholder/600/400?text=${tutorial.title}&color=000000&bgColor=ffffff&fontSize=72`
 | 
			
		||||
            "
 | 
			
		||||
            class="w-full object-contain"
 | 
			
		||||
            :alt="tutorial.title"
 | 
			
		||||
            style="width: 600px; height: 400px"
 | 
			
		||||
          />
 | 
			
		||||
 | 
			
		||||
          <!-- 卡片蒙层 -->
 | 
			
		||||
          <div
 | 
			
		||||
            class="absolute inset-0 bg-primary opacity-20 transition-opacity duration-300"
 | 
			
		||||
            :class="{ 'opacity-10': index === currentIndex }"
 | 
			
		||||
          ></div>
 | 
			
		||||
 | 
			
		||||
          <!-- 标题覆盖层 -->
 | 
			
		||||
          <div
 | 
			
		||||
            class="absolute bottom-0 left-0 right-0 p-4 bg-gradient-to-t from-base-300 to-transparent"
 | 
			
		||||
          >
 | 
			
		||||
            <div class="flex flex-col gap-2">
 | 
			
		||||
              <h3 class="text-lg font-bold text-base-content">
 | 
			
		||||
                {{ tutorial.title }}
 | 
			
		||||
              </h3>
 | 
			
		||||
              <p class="text-sm opacity-80 truncate">
 | 
			
		||||
                {{ tutorial.description }}
 | 
			
		||||
              </p>
 | 
			
		||||
              <!-- 标签显示 -->
 | 
			
		||||
              <div
 | 
			
		||||
                v-if="tutorial.tags && tutorial.tags.length > 0"
 | 
			
		||||
                class="flex flex-wrap gap-1"
 | 
			
		||||
              >
 | 
			
		||||
                <span
 | 
			
		||||
                  v-for="tag in tutorial.tags.slice(0, 3)"
 | 
			
		||||
                  :key="tag"
 | 
			
		||||
                  class="badge badge-outline badge-xs text-xs"
 | 
			
		||||
                >
 | 
			
		||||
                  {{ tag }}
 | 
			
		||||
                </span>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <!-- 导航指示器 -->
 | 
			
		||||
    <div class="indicators flex justify-center gap-2 mt-4">
 | 
			
		||||
      <button
 | 
			
		||||
        v-for="(_, index) in tutorials"
 | 
			
		||||
        :key="index"
 | 
			
		||||
        @click="setActiveCard(index)"
 | 
			
		||||
        class="w-3 h-3 rounded-full transition-all duration-300"
 | 
			
		||||
        :class="index === currentIndex ? 'bg-primary scale-125' : 'bg-base-300'"
 | 
			
		||||
      ></button>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import { ref, onMounted, onUnmounted } from "vue";
 | 
			
		||||
import { useRouter } from "vue-router";
 | 
			
		||||
import { AuthManager } from "@/utils/AuthManager";
 | 
			
		||||
import type { ExamInfo } from "@/APIClient";
 | 
			
		||||
 | 
			
		||||
// 接口定义
 | 
			
		||||
interface Tutorial {
 | 
			
		||||
  id: string;
 | 
			
		||||
  title: string;
 | 
			
		||||
  description: string;
 | 
			
		||||
  thumbnail?: string;
 | 
			
		||||
  tags: string[];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Props
 | 
			
		||||
const props = defineProps<{
 | 
			
		||||
  autoRotationInterval?: number;
 | 
			
		||||
}>();
 | 
			
		||||
 | 
			
		||||
// 配置默认值
 | 
			
		||||
const autoRotationInterval = props.autoRotationInterval || 5000; // 默认5秒
 | 
			
		||||
 | 
			
		||||
// 状态管理
 | 
			
		||||
const tutorials = ref<Tutorial[]>([]);
 | 
			
		||||
const currentIndex = ref(0);
 | 
			
		||||
const router = useRouter();
 | 
			
		||||
let autoRotationTimer: number | null = null;
 | 
			
		||||
 | 
			
		||||
// 处理卡片点击
 | 
			
		||||
const handleCardClick = (index: number, tutorialId: string) => {
 | 
			
		||||
  if (index === currentIndex.value) {
 | 
			
		||||
    goToExam(tutorialId);
 | 
			
		||||
  } else {
 | 
			
		||||
    setActiveCard(index);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 从数据库加载实验数据
 | 
			
		||||
onMounted(async () => {
 | 
			
		||||
  try {
 | 
			
		||||
    console.log("正在从数据库加载实验数据...");
 | 
			
		||||
 | 
			
		||||
    // 创建认证客户端
 | 
			
		||||
    const client = AuthManager.createAuthenticatedExamClient();
 | 
			
		||||
 | 
			
		||||
    // 获取实验列表
 | 
			
		||||
    const examList: ExamInfo[] = await client.getExamList();
 | 
			
		||||
 | 
			
		||||
    // 筛选可见的实验并转换为Tutorial格式
 | 
			
		||||
    const visibleExams = examList
 | 
			
		||||
      .filter((exam) => exam.isVisibleToUsers)
 | 
			
		||||
      .slice(0, 6); // 限制轮播显示最多6个实验
 | 
			
		||||
 | 
			
		||||
    if (visibleExams.length === 0) {
 | 
			
		||||
      console.warn("没有找到可见的实验");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 转换数据格式并获取封面图片
 | 
			
		||||
    const tutorialPromises = visibleExams.map(async (exam) => {
 | 
			
		||||
      let thumbnail: string | undefined;
 | 
			
		||||
 | 
			
		||||
      try {
 | 
			
		||||
        // 获取实验的封面资源(模板资源)
 | 
			
		||||
        const resourceClient = AuthManager.createAuthenticatedResourceClient();
 | 
			
		||||
        const resourceList = await resourceClient.getResourceList(
 | 
			
		||||
          exam.id,
 | 
			
		||||
          "cover",
 | 
			
		||||
          "template",
 | 
			
		||||
        );
 | 
			
		||||
        if (resourceList && resourceList.length > 0) {
 | 
			
		||||
          // 使用第一个封面资源
 | 
			
		||||
          const coverResource = resourceList[0];
 | 
			
		||||
          const fileResponse = await resourceClient.getResourceById(
 | 
			
		||||
            coverResource.id,
 | 
			
		||||
          );
 | 
			
		||||
          // 创建Blob URL作为缩略图
 | 
			
		||||
          thumbnail = URL.createObjectURL(fileResponse.data);
 | 
			
		||||
        }
 | 
			
		||||
      } catch (error) {
 | 
			
		||||
        console.warn(`无法获取实验${exam.id}的封面图片:`, error);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      return {
 | 
			
		||||
        id: exam.id,
 | 
			
		||||
        title: exam.name,
 | 
			
		||||
        description: "点击查看实验详情",
 | 
			
		||||
        thumbnail,
 | 
			
		||||
        tags: exam.tags || [],
 | 
			
		||||
      };
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    tutorials.value = await Promise.all(tutorialPromises);
 | 
			
		||||
 | 
			
		||||
    console.log("成功加载实验数据:", tutorials.value.length, "个实验");
 | 
			
		||||
 | 
			
		||||
    // 启动自动旋转
 | 
			
		||||
    startAutoRotation();
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    console.error("加载实验数据失败:", error);
 | 
			
		||||
 | 
			
		||||
    // 如果加载失败,显示默认的占位内容
 | 
			
		||||
    tutorials.value = [
 | 
			
		||||
      {
 | 
			
		||||
        id: "placeholder",
 | 
			
		||||
        title: "实验数据加载中...",
 | 
			
		||||
        description: "请稍后或刷新页面重试",
 | 
			
		||||
        thumbnail: undefined,
 | 
			
		||||
        tags: [],
 | 
			
		||||
      },
 | 
			
		||||
    ];
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// 在组件销毁时清除计时器和Blob URLs
 | 
			
		||||
onUnmounted(() => {
 | 
			
		||||
  if (autoRotationTimer) {
 | 
			
		||||
    clearInterval(autoRotationTimer);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // 清理创建的Blob URLs
 | 
			
		||||
  tutorials.value.forEach((tutorial) => {
 | 
			
		||||
    if (tutorial.thumbnail && tutorial.thumbnail.startsWith("blob:")) {
 | 
			
		||||
      URL.revokeObjectURL(tutorial.thumbnail);
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// 鼠标滚轮处理
 | 
			
		||||
const handleWheel = (event: WheelEvent) => {
 | 
			
		||||
  if (event.deltaY > 0) {
 | 
			
		||||
    nextCard();
 | 
			
		||||
  } else {
 | 
			
		||||
    prevCard();
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 下一张卡片
 | 
			
		||||
const nextCard = () => {
 | 
			
		||||
  currentIndex.value = (currentIndex.value + 1) % tutorials.value.length;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 上一张卡片
 | 
			
		||||
const prevCard = () => {
 | 
			
		||||
  currentIndex.value =
 | 
			
		||||
    (currentIndex.value - 1 + tutorials.value.length) % tutorials.value.length;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 设置活动卡片
 | 
			
		||||
const setActiveCard = (index: number) => {
 | 
			
		||||
  currentIndex.value = index;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 自动旋转
 | 
			
		||||
const startAutoRotation = () => {
 | 
			
		||||
  autoRotationTimer = window.setInterval(() => {
 | 
			
		||||
    nextCard();
 | 
			
		||||
  }, autoRotationInterval);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 暂停自动旋转
 | 
			
		||||
const pauseAutoRotation = () => {
 | 
			
		||||
  if (autoRotationTimer) {
 | 
			
		||||
    clearInterval(autoRotationTimer);
 | 
			
		||||
    autoRotationTimer = null;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 恢复自动旋转
 | 
			
		||||
const resumeAutoRotation = () => {
 | 
			
		||||
  if (!autoRotationTimer) {
 | 
			
		||||
    startAutoRotation();
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 前往实验
 | 
			
		||||
const goToExam = (examId: string) => {
 | 
			
		||||
  // 跳转到实验列表页面并传递examId参数,页面将自动打开对应的实验详情模态框
 | 
			
		||||
  router.push({
 | 
			
		||||
    path: "/exam",
 | 
			
		||||
    query: { examId: examId },
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 计算卡片类和样式
 | 
			
		||||
const getCardClass = (index: number) => {
 | 
			
		||||
  const isActive = index === currentIndex.value;
 | 
			
		||||
  const isPrev =
 | 
			
		||||
    index === currentIndex.value - 1 ||
 | 
			
		||||
    (currentIndex.value === 0 && index === tutorials.value.length - 1);
 | 
			
		||||
  const isNext =
 | 
			
		||||
    index === currentIndex.value + 1 ||
 | 
			
		||||
    (currentIndex.value === tutorials.value.length - 1 && index === 0);
 | 
			
		||||
 | 
			
		||||
  return {
 | 
			
		||||
    "z-30": isActive,
 | 
			
		||||
    "z-20": isPrev || isNext,
 | 
			
		||||
    "z-10": !isActive && !isPrev && !isNext,
 | 
			
		||||
    "hover:scale-105": isActive,
 | 
			
		||||
    "cursor-pointer": true,
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const getCardStyle = (index: number) => {
 | 
			
		||||
  const isActive = index === currentIndex.value;
 | 
			
		||||
  const isPrev =
 | 
			
		||||
    index === currentIndex.value - 1 ||
 | 
			
		||||
    (currentIndex.value === 0 && index === tutorials.value.length - 1);
 | 
			
		||||
  const isNext =
 | 
			
		||||
    index === currentIndex.value + 1 ||
 | 
			
		||||
    (currentIndex.value === tutorials.value.length - 1 && index === 0);
 | 
			
		||||
 | 
			
		||||
  // 基本样式
 | 
			
		||||
  let style = {
 | 
			
		||||
    transform: "scale(1) translateY(0) rotate(0deg)",
 | 
			
		||||
    opacity: "1",
 | 
			
		||||
    filter: "blur(0)",
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  // 活动卡片
 | 
			
		||||
  if (isActive) {
 | 
			
		||||
    return style;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // 上一张卡片
 | 
			
		||||
  if (isPrev) {
 | 
			
		||||
    style.transform = "scale(0.85) translateY(-10%) rotate(-5deg)";
 | 
			
		||||
    style.opacity = "0.7";
 | 
			
		||||
    style.filter = "blur(1px)";
 | 
			
		||||
    return style;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // 下一张卡片
 | 
			
		||||
  if (isNext) {
 | 
			
		||||
    style.transform = "scale(0.85) translateY(10%) rotate(5deg)";
 | 
			
		||||
    style.opacity = "0.7";
 | 
			
		||||
    style.filter = "blur(1px)";
 | 
			
		||||
    return style;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // 其他卡片
 | 
			
		||||
  style.transform = "scale(0.7) translateY(0) rotate(0deg)";
 | 
			
		||||
  style.opacity = "0.4";
 | 
			
		||||
  style.filter = "blur(2px)";
 | 
			
		||||
  return style;
 | 
			
		||||
};
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style scoped>
 | 
			
		||||
.tutorial-carousel {
 | 
			
		||||
  width: 100%;
 | 
			
		||||
  height: 500px;
 | 
			
		||||
  perspective: 1000px;
 | 
			
		||||
  display: flex;
 | 
			
		||||
  flex-direction: column;
 | 
			
		||||
  align-items: center;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.card-stack {
 | 
			
		||||
  width: 600px;
 | 
			
		||||
  height: 440px;
 | 
			
		||||
  position: relative;
 | 
			
		||||
  transform-style: preserve-3d;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.tutorial-card {
 | 
			
		||||
  width: 600px;
 | 
			
		||||
  height: 400px;
 | 
			
		||||
  background-color: hsl(var(--b2));
 | 
			
		||||
  will-change: transform, opacity;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.tutorial-card:hover {
 | 
			
		||||
  box-shadow: 0 0 15px rgba(var(--p), 0.5);
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
 
 | 
			
		||||
@@ -87,9 +87,12 @@ import type { HubConnection } from "@microsoft/signalr";
 | 
			
		||||
import type {
 | 
			
		||||
  IProgressHub,
 | 
			
		||||
  IProgressReceiver,
 | 
			
		||||
} from "@/TypedSignalR.Client/server.Hubs";
 | 
			
		||||
import { getHubProxyFactory, getReceiverRegister } from "@/TypedSignalR.Client";
 | 
			
		||||
import { ProgressStatus } from "@/server.Hubs";
 | 
			
		||||
} from "@/utils/signalR/TypedSignalR.Client/server.Hubs";
 | 
			
		||||
import {
 | 
			
		||||
  getHubProxyFactory,
 | 
			
		||||
  getReceiverRegister,
 | 
			
		||||
} from "@/utils/signalR/TypedSignalR.Client";
 | 
			
		||||
import { ProgressStatus } from "@/utils/signalR/server.Hubs";
 | 
			
		||||
import { useRequiredInjection } from "@/utils/Common";
 | 
			
		||||
import { useAlertStore } from "./Alert";
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								src/main.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/main.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
import "./assets/main.css";
 | 
			
		||||
 | 
			
		||||
import { createApp } from "vue";
 | 
			
		||||
import { createPinia } from "pinia";
 | 
			
		||||
 | 
			
		||||
import App from "@/App.vue";
 | 
			
		||||
import router from "./router";
 | 
			
		||||
 | 
			
		||||
const app = createApp(App).use(router).use(createPinia()).mount("#app");
 | 
			
		||||
@@ -4,7 +4,8 @@ import AuthView from "../views/AuthView.vue";
 | 
			
		||||
import ProjectView from "../views/Project/Index.vue";
 | 
			
		||||
import TestView from "../views/TestView.vue";
 | 
			
		||||
import UserView from "@/views/User/Index.vue";
 | 
			
		||||
import ExamView from "@/views/ExamView.vue";
 | 
			
		||||
import ExamView from "@/views/Exam/Index.vue";
 | 
			
		||||
import MarkdownEditor from "@/components/MarkdownEditor.vue";
 | 
			
		||||
 | 
			
		||||
const router = createRouter({
 | 
			
		||||
  history: createWebHistory(import.meta.env.BASE_URL),
 | 
			
		||||
@@ -15,6 +16,7 @@ const router = createRouter({
 | 
			
		||||
    { path: "/test", name: "test", component: TestView },
 | 
			
		||||
    { path: "/user", name: "user", component: UserView },
 | 
			
		||||
    { path: "/exam", name: "exam", component: ExamView },
 | 
			
		||||
    { path: "/markdown", name: "markdown", component: MarkdownEditor },
 | 
			
		||||
  ],
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,9 +10,12 @@ import { useDialogStore } from "./dialog";
 | 
			
		||||
import { toFileParameterOrUndefined } from "@/utils/Common";
 | 
			
		||||
import { AuthManager } from "@/utils/AuthManager";
 | 
			
		||||
import { HubConnection, HubConnectionBuilder } from "@microsoft/signalr";
 | 
			
		||||
import { getHubProxyFactory, getReceiverRegister } from "@/TypedSignalR.Client";
 | 
			
		||||
import {
 | 
			
		||||
  getHubProxyFactory,
 | 
			
		||||
  getReceiverRegister,
 | 
			
		||||
} from "@/utils/signalR/TypedSignalR.Client";
 | 
			
		||||
import type { ResourceInfo } from "@/APIClient";
 | 
			
		||||
import type { IJtagHub } from "@/TypedSignalR.Client/server.Hubs";
 | 
			
		||||
import type { IJtagHub } from "@/utils/signalR/TypedSignalR.Client/server.Hubs";
 | 
			
		||||
 | 
			
		||||
export const useEquipments = defineStore("equipments", () => {
 | 
			
		||||
  // Global Stores
 | 
			
		||||
@@ -126,7 +129,7 @@ export const useEquipments = defineStore("equipments", () => {
 | 
			
		||||
  async function jtagUploadBitstream(
 | 
			
		||||
    bitstream: File,
 | 
			
		||||
    examId?: string,
 | 
			
		||||
  ): Promise<number | null> {
 | 
			
		||||
  ): Promise<string | null> {
 | 
			
		||||
    try {
 | 
			
		||||
      // 自动开启电源
 | 
			
		||||
      await powerSetOnOff(true);
 | 
			
		||||
@@ -152,7 +155,7 @@ export const useEquipments = defineStore("equipments", () => {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async function jtagDownloadBitstream(bitstreamId?: number): Promise<string> {
 | 
			
		||||
  async function jtagDownloadBitstream(bitstreamId?: string): Promise<string> {
 | 
			
		||||
    if (bitstreamId === null || bitstreamId === undefined) {
 | 
			
		||||
      dialog.error("请先选择要下载的比特流");
 | 
			
		||||
      return "";
 | 
			
		||||
 
 | 
			
		||||
@@ -1,67 +1,73 @@
 | 
			
		||||
import { ref, computed, watch } from 'vue'
 | 
			
		||||
import { defineStore } from 'pinia'
 | 
			
		||||
import { ref, computed, watch } from "vue";
 | 
			
		||||
import { defineStore } from "pinia";
 | 
			
		||||
 | 
			
		||||
// 本地存储主题的键名
 | 
			
		||||
const THEME_STORAGE_KEY = 'fpga-weblab-theme'
 | 
			
		||||
const THEME_STORAGE_KEY = "fpga-weblab-theme";
 | 
			
		||||
 | 
			
		||||
export const useThemeStore = defineStore('theme', () => {
 | 
			
		||||
  const allTheme = ["winter", "night"]
 | 
			
		||||
export const useThemeStore = defineStore("theme", () => {
 | 
			
		||||
  const allTheme = ["winter", "night"];
 | 
			
		||||
  const darkTheme = "night";
 | 
			
		||||
  const lightTheme = "winter";
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  // 尝试从本地存储中获取保存的主题
 | 
			
		||||
  const getSavedTheme = (): string | null => {
 | 
			
		||||
    return localStorage.getItem(THEME_STORAGE_KEY)
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
    return localStorage.getItem(THEME_STORAGE_KEY);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  // 检测系统主题偏好
 | 
			
		||||
  const getPreferredTheme = (): string => {
 | 
			
		||||
    const savedTheme = getSavedTheme()
 | 
			
		||||
    const savedTheme = getSavedTheme();
 | 
			
		||||
    // 如果有保存的主题设置,优先使用
 | 
			
		||||
    if (savedTheme && allTheme.includes(savedTheme)) {
 | 
			
		||||
      return savedTheme
 | 
			
		||||
      return savedTheme;
 | 
			
		||||
    }
 | 
			
		||||
    // 否则检测系统主题模式
 | 
			
		||||
    return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches 
 | 
			
		||||
      ? darkTheme : lightTheme
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
    return window.matchMedia &&
 | 
			
		||||
      window.matchMedia("(prefers-color-scheme: dark)").matches
 | 
			
		||||
      ? darkTheme
 | 
			
		||||
      : lightTheme;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  // 初始化主题为首选主题
 | 
			
		||||
  const currentTheme = ref(getPreferredTheme())
 | 
			
		||||
  const currentTheme = ref(getPreferredTheme());
 | 
			
		||||
  const currentMode = computed(() =>
 | 
			
		||||
    currentTheme.value === darkTheme ? "dark" : "light",
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  // 保存主题到本地存储
 | 
			
		||||
  const saveTheme = (theme: string) => {
 | 
			
		||||
    localStorage.setItem(THEME_STORAGE_KEY, theme)
 | 
			
		||||
  }
 | 
			
		||||
    localStorage.setItem(THEME_STORAGE_KEY, theme);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  // 当主题变化时,保存到本地存储
 | 
			
		||||
  watch(currentTheme, (newTheme) => {
 | 
			
		||||
    saveTheme(newTheme)
 | 
			
		||||
  })
 | 
			
		||||
    saveTheme(newTheme);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  // 添加系统主题变化的监听
 | 
			
		||||
  const setupThemeListener = () => {
 | 
			
		||||
    if (window.matchMedia) {
 | 
			
		||||
      const colorSchemeQuery = window.matchMedia('(prefers-color-scheme: dark)')
 | 
			
		||||
      const colorSchemeQuery = window.matchMedia(
 | 
			
		||||
        "(prefers-color-scheme: dark)",
 | 
			
		||||
      );
 | 
			
		||||
      const handler = (e: MediaQueryListEvent) => {
 | 
			
		||||
        // 只有当用户没有手动设置过主题时,才跟随系统变化
 | 
			
		||||
        if (!getSavedTheme()) {
 | 
			
		||||
          currentTheme.value = e.matches ? darkTheme : lightTheme
 | 
			
		||||
          currentTheme.value = e.matches ? darkTheme : lightTheme;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      // 添加主题变化监听器
 | 
			
		||||
      colorSchemeQuery.addEventListener('change', handler)
 | 
			
		||||
      colorSchemeQuery.addEventListener("change", handler);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  };
 | 
			
		||||
  function setTheme(theme: string) {
 | 
			
		||||
    const isContained: boolean = allTheme.includes(theme)
 | 
			
		||||
    const isContained: boolean = allTheme.includes(theme);
 | 
			
		||||
    if (isContained) {
 | 
			
		||||
      currentTheme.value = theme
 | 
			
		||||
      saveTheme(theme) // 保存主题到本地存储
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      console.error(`Not have such theme: ${theme}`)
 | 
			
		||||
      currentTheme.value = theme;
 | 
			
		||||
      saveTheme(theme); // 保存主题到本地存储
 | 
			
		||||
    } else {
 | 
			
		||||
      console.error(`Not have such theme: ${theme}`);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -77,26 +83,26 @@ export const useThemeStore = defineStore('theme', () => {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function isDarkTheme(): boolean {
 | 
			
		||||
    return currentTheme.value == darkTheme
 | 
			
		||||
    return currentTheme.value == darkTheme;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function isLightTheme(): boolean {
 | 
			
		||||
    return currentTheme.value == lightTheme
 | 
			
		||||
    return currentTheme.value == lightTheme;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // 初始化时设置系统主题变化监听器
 | 
			
		||||
  if (typeof window !== 'undefined') {
 | 
			
		||||
    setupThemeListener()
 | 
			
		||||
  if (typeof window !== "undefined") {
 | 
			
		||||
    setupThemeListener();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return {
 | 
			
		||||
    allTheme,
 | 
			
		||||
    currentTheme,
 | 
			
		||||
    currentMode,
 | 
			
		||||
    setTheme,
 | 
			
		||||
    toggleTheme,
 | 
			
		||||
    isDarkTheme,
 | 
			
		||||
    isLightTheme,
 | 
			
		||||
    setupThemeListener
 | 
			
		||||
  }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
    setupThemeListener,
 | 
			
		||||
  };
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
@@ -212,30 +212,18 @@ export class AuthManager {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static createAuthenticatedJtagHubConnection() {
 | 
			
		||||
    const token = this.getToken();
 | 
			
		||||
    if (isNull(token)) {
 | 
			
		||||
      router.push("/login");
 | 
			
		||||
      throw Error("Token Null!");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return new HubConnectionBuilder()
 | 
			
		||||
      .withUrl("http://127.0.0.1:5000/hubs/JtagHub", {
 | 
			
		||||
        accessTokenFactory: () => token,
 | 
			
		||||
        accessTokenFactory: () => this.getToken() ?? "",
 | 
			
		||||
      })
 | 
			
		||||
      .withAutomaticReconnect()
 | 
			
		||||
      .build();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static createAuthenticatedProgressHubConnection() {
 | 
			
		||||
    const token = this.getToken();
 | 
			
		||||
    if (isNull(token)) {
 | 
			
		||||
      router.push("/login");
 | 
			
		||||
      throw Error("Token Null!");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return new HubConnectionBuilder()
 | 
			
		||||
      .withUrl("http://127.0.0.1:5000/hubs/ProgressHub", {
 | 
			
		||||
        accessTokenFactory: () => token,
 | 
			
		||||
        accessTokenFactory: () => this.getToken() ?? "",
 | 
			
		||||
      })
 | 
			
		||||
      .withAutomaticReconnect()
 | 
			
		||||
      .build();
 | 
			
		||||
 
 | 
			
		||||
@@ -48,3 +48,14 @@ export function useOptionalInjection<T>(
 | 
			
		||||
  const value = useFn();
 | 
			
		||||
  return value ?? defaultValue;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function formatDate(date: Date | string) {
 | 
			
		||||
  const dateObj = typeof date === "string" ? new Date(date) : date;
 | 
			
		||||
  return dateObj.toLocaleString("zh-CN", {
 | 
			
		||||
    year: "numeric",
 | 
			
		||||
    month: "2-digit",
 | 
			
		||||
    day: "2-digit",
 | 
			
		||||
    hour: "2-digit",
 | 
			
		||||
    minute: "2-digit",
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,10 @@
 | 
			
		||||
  <div class="flex items-center justify-center min-h-screen bg-base-200">
 | 
			
		||||
    <div class="relative w-full max-w-md">
 | 
			
		||||
      <!-- Login Card -->
 | 
			
		||||
      <div v-if="!showSignUp" class="card card-dash h-80 w-100 shadow-xl bg-base-100">
 | 
			
		||||
      <div
 | 
			
		||||
        v-if="!showSignUp"
 | 
			
		||||
        class="card card-dash h-80 w-100 shadow-xl bg-base-100"
 | 
			
		||||
      >
 | 
			
		||||
        <div class="card-body">
 | 
			
		||||
          <h1 class="card-title place-self-center my-3 text-2xl">用户登录</h1>
 | 
			
		||||
          <div class="flex flex-col w-full h-full">
 | 
			
		||||
@@ -44,7 +47,10 @@
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
      <!-- Sign Up Card -->
 | 
			
		||||
      <div v-if="showSignUp" class="card card-dash h-96 w-100 shadow-xl bg-base-100">
 | 
			
		||||
      <div
 | 
			
		||||
        v-if="showSignUp"
 | 
			
		||||
        class="card card-dash h-96 w-100 shadow-xl bg-base-100"
 | 
			
		||||
      >
 | 
			
		||||
        <div class="card-body">
 | 
			
		||||
          <h1 class="card-title place-self-center my-3 text-2xl">用户注册</h1>
 | 
			
		||||
          <div class="flex flex-col w-full h-full">
 | 
			
		||||
@@ -122,7 +128,7 @@ const isSignUpLoading = ref(false);
 | 
			
		||||
const signUpData = ref({
 | 
			
		||||
  username: "",
 | 
			
		||||
  email: "",
 | 
			
		||||
  password: ""
 | 
			
		||||
  password: "",
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// 登录处理函数
 | 
			
		||||
@@ -149,7 +155,7 @@ const handleLogin = async () => {
 | 
			
		||||
 | 
			
		||||
    // 短暂延迟后跳转到project页面
 | 
			
		||||
    setTimeout(async () => {
 | 
			
		||||
      await router.push("/project");
 | 
			
		||||
      router.go(-1);
 | 
			
		||||
    }, 1000);
 | 
			
		||||
  } catch (error: any) {
 | 
			
		||||
    console.error("Login error:", error);
 | 
			
		||||
@@ -180,7 +186,7 @@ const handleRegister = () => {
 | 
			
		||||
  signUpData.value = {
 | 
			
		||||
    username: "",
 | 
			
		||||
    email: "",
 | 
			
		||||
    password: ""
 | 
			
		||||
    password: "",
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -227,13 +233,13 @@ const handleSignUp = async () => {
 | 
			
		||||
    const result = await dataClient.signUpUser(
 | 
			
		||||
      signUpData.value.username.trim(),
 | 
			
		||||
      signUpData.value.email.trim(),
 | 
			
		||||
      signUpData.value.password.trim()
 | 
			
		||||
      signUpData.value.password.trim(),
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    if (result) {
 | 
			
		||||
      // 注册成功
 | 
			
		||||
      alertStore?.show("注册成功!请登录", "success", 2000);
 | 
			
		||||
      
 | 
			
		||||
 | 
			
		||||
      // 延迟后返回登录页面
 | 
			
		||||
      setTimeout(() => {
 | 
			
		||||
        backToLogin();
 | 
			
		||||
@@ -271,7 +277,7 @@ const checkExistingToken = async () => {
 | 
			
		||||
    const isValid = await AuthManager.verifyToken();
 | 
			
		||||
    if (isValid) {
 | 
			
		||||
      // 如果token仍然有效,直接跳转到project页面
 | 
			
		||||
      await router.push("/project");
 | 
			
		||||
      router.go(-1);
 | 
			
		||||
    }
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    // token无效或验证失败,继续显示登录页面
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										0
									
								
								src/views/Exam/ExamCard.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/views/Exam/ExamCard.vue
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										776
									
								
								src/views/Exam/ExamEditModal.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										776
									
								
								src/views/Exam/ExamEditModal.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,776 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div v-if="isShowModal" class="modal modal-open overflow-hidden">
 | 
			
		||||
    <div class="modal-box w-full max-w-7xl max-h-[90vh] p-0 overflow-hidden">
 | 
			
		||||
      <div
 | 
			
		||||
        class="flex justify-between items-center p-6 border-b border-base-300"
 | 
			
		||||
      >
 | 
			
		||||
        <h2 class="text-2xl font-bold text-base-content">
 | 
			
		||||
          {{ mode === "create" ? "新建实验" : "编辑实验" }}
 | 
			
		||||
        </h2>
 | 
			
		||||
        <button @click="close" class="btn btn-sm btn-circle btn-ghost">
 | 
			
		||||
          <svg
 | 
			
		||||
            class="w-6 h-6"
 | 
			
		||||
            fill="none"
 | 
			
		||||
            stroke="currentColor"
 | 
			
		||||
            viewBox="0 0 24 24"
 | 
			
		||||
          >
 | 
			
		||||
            <path
 | 
			
		||||
              stroke-linecap="round"
 | 
			
		||||
              stroke-linejoin="round"
 | 
			
		||||
              stroke-width="2"
 | 
			
		||||
              d="M6 18L18 6M6 6l12 12"
 | 
			
		||||
            />
 | 
			
		||||
          </svg>
 | 
			
		||||
        </button>
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
      <form @submit.prevent="submitCreateExam" class="flex h-[calc(90vh-5rem)]">
 | 
			
		||||
        <!-- 左侧:基本信息 -->
 | 
			
		||||
        <div class="w-110 p-6 overflow-y-auto border-r border-base-300">
 | 
			
		||||
          <div class="space-y-6">
 | 
			
		||||
            <h3 class="text-xl font-semibold text-base-content mb-4">
 | 
			
		||||
              基本信息
 | 
			
		||||
            </h3>
 | 
			
		||||
 | 
			
		||||
            <!-- 实验ID -->
 | 
			
		||||
            <div class="form-control">
 | 
			
		||||
              <label class="label">
 | 
			
		||||
                <span class="label-text font-medium">实验ID *</span>
 | 
			
		||||
              </label>
 | 
			
		||||
              <input
 | 
			
		||||
                type="text"
 | 
			
		||||
                v-model="editExamInfo.id"
 | 
			
		||||
                class="input input-bordered w-full"
 | 
			
		||||
                placeholder="例如: EXP001"
 | 
			
		||||
                required
 | 
			
		||||
              />
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <!-- 实验名称 -->
 | 
			
		||||
            <div class="form-control">
 | 
			
		||||
              <label class="label">
 | 
			
		||||
                <span class="label-text font-medium">实验名称 *</span>
 | 
			
		||||
              </label>
 | 
			
		||||
              <input
 | 
			
		||||
                type="text"
 | 
			
		||||
                v-model="editExamInfo.name"
 | 
			
		||||
                class="input input-bordered w-full"
 | 
			
		||||
                placeholder="实验名称"
 | 
			
		||||
                required
 | 
			
		||||
              />
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <!-- 实验描述 -->
 | 
			
		||||
            <div class="form-control">
 | 
			
		||||
              <label class="label">
 | 
			
		||||
                <span class="label-text font-medium">实验描述 *</span>
 | 
			
		||||
              </label>
 | 
			
		||||
              <textarea
 | 
			
		||||
                v-model="editExamInfo.description"
 | 
			
		||||
                class="textarea textarea-bordered w-full h-32"
 | 
			
		||||
                placeholder="详细描述实验内容、目标和要求..."
 | 
			
		||||
                required
 | 
			
		||||
              ></textarea>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <!-- 标签 -->
 | 
			
		||||
            <div class="form-control">
 | 
			
		||||
              <div class="flex flex-wrap gap-2 mb-3 min-h-[2rem]">
 | 
			
		||||
                <span
 | 
			
		||||
                  v-for="(tag, index) in editExamInfo.tags"
 | 
			
		||||
                  :key="index"
 | 
			
		||||
                  class="badge badge-primary gap-2"
 | 
			
		||||
                >
 | 
			
		||||
                  {{ tag }}
 | 
			
		||||
                  <button
 | 
			
		||||
                    type="button"
 | 
			
		||||
                    @click="removeTag(index)"
 | 
			
		||||
                    class="text-primary-content hover:text-error"
 | 
			
		||||
                  >
 | 
			
		||||
                    <svg
 | 
			
		||||
                      class="w-3 h-3"
 | 
			
		||||
                      fill="none"
 | 
			
		||||
                      stroke="currentColor"
 | 
			
		||||
                      viewBox="0 0 24 24"
 | 
			
		||||
                    >
 | 
			
		||||
                      <path
 | 
			
		||||
                        stroke-linecap="round"
 | 
			
		||||
                        stroke-linejoin="round"
 | 
			
		||||
                        stroke-width="2"
 | 
			
		||||
                        d="M6 18L18 6M6 6l12 12"
 | 
			
		||||
                      />
 | 
			
		||||
                    </svg>
 | 
			
		||||
                  </button>
 | 
			
		||||
                </span>
 | 
			
		||||
              </div>
 | 
			
		||||
              <div class="flex gap-2">
 | 
			
		||||
                <input
 | 
			
		||||
                  type="text"
 | 
			
		||||
                  v-model="newTagInput"
 | 
			
		||||
                  @keydown.enter.prevent="addTag"
 | 
			
		||||
                  class="input input-bordered flex-1"
 | 
			
		||||
                  placeholder="输入标签按回车添加"
 | 
			
		||||
                />
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <!-- 难度等级 -->
 | 
			
		||||
            <div class="form-control">
 | 
			
		||||
              <div class="flex items-center justify-between p-4 rounded-lg">
 | 
			
		||||
                <span class="label-text font-medium">难度等级 *</span>
 | 
			
		||||
                <div class="flex items-center gap-4">
 | 
			
		||||
                  <div class="rating rating-lg">
 | 
			
		||||
                    <input
 | 
			
		||||
                      v-for="i in 5"
 | 
			
		||||
                      :key="i"
 | 
			
		||||
                      type="radio"
 | 
			
		||||
                      :value="i"
 | 
			
		||||
                      v-model="editExamInfo.difficulty"
 | 
			
		||||
                      class="mask mask-star-2 bg-orange-400"
 | 
			
		||||
                    />
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <span class="text-lg font-medium text-base-content"
 | 
			
		||||
                    >({{ editExamInfo.difficulty }}/5)</span
 | 
			
		||||
                  >
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <!-- 可见性 -->
 | 
			
		||||
            <div class="form-control">
 | 
			
		||||
              <div class="p-4 rounded-lg">
 | 
			
		||||
                <label class="label cursor-pointer justify-start gap-4">
 | 
			
		||||
                  <input
 | 
			
		||||
                    type="checkbox"
 | 
			
		||||
                    v-model="editExamInfo.isVisibleToUsers"
 | 
			
		||||
                    class="checkbox checkbox-primary"
 | 
			
		||||
                  />
 | 
			
		||||
                  <div>
 | 
			
		||||
                    <span class="label-text font-medium">对学生可见</span>
 | 
			
		||||
                    <div class="text-sm text-base-content/70">
 | 
			
		||||
                      开启后学生可以在实验列表中看到此实验
 | 
			
		||||
                    </div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                </label>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <!-- 提交按钮 -->
 | 
			
		||||
            <div class="pt-4 border-t border-base-300">
 | 
			
		||||
              <div class="space-y-3">
 | 
			
		||||
                <button
 | 
			
		||||
                  type="submit"
 | 
			
		||||
                  :disabled="isUpdating || !canCreateExam"
 | 
			
		||||
                  class="btn btn-primary w-full"
 | 
			
		||||
                >
 | 
			
		||||
                  <span
 | 
			
		||||
                    v-if="isUpdating"
 | 
			
		||||
                    class="loading loading-spinner loading-sm mr-2"
 | 
			
		||||
                  ></span>
 | 
			
		||||
                  {{
 | 
			
		||||
                    mode === "create"
 | 
			
		||||
                      ? isUpdating
 | 
			
		||||
                        ? "创建中..."
 | 
			
		||||
                        : "创建实验"
 | 
			
		||||
                      : isUpdating
 | 
			
		||||
                        ? "更新中..."
 | 
			
		||||
                        : "更新实验"
 | 
			
		||||
                  }}
 | 
			
		||||
                </button>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <!-- 右侧:文件上传 -->
 | 
			
		||||
        <div class="flex-1 p-6 overflow-y-auto">
 | 
			
		||||
          <div class="space-y-6">
 | 
			
		||||
            <h3 class="text-xl font-semibold text-base-content mb-4">
 | 
			
		||||
              资源文件
 | 
			
		||||
            </h3>
 | 
			
		||||
 | 
			
		||||
            <!-- 第一行:MD文档 和 图片资源 -->
 | 
			
		||||
            <div class="grid grid-cols-2 gap-4">
 | 
			
		||||
              <!-- MD文档 -->
 | 
			
		||||
              <div class="space-y-2">
 | 
			
		||||
                <label class="text-sm font-medium text-base-content"
 | 
			
		||||
                  >MD文档 (必需)</label
 | 
			
		||||
                >
 | 
			
		||||
                <div
 | 
			
		||||
                  class="border-2 border-dashed border-base-300 rounded-lg p-6 text-center cursor-pointer hover:border-primary hover:bg-primary/5 transition-colors aspect-square flex items-center justify-center"
 | 
			
		||||
                  @click="mdFileInput?.click()"
 | 
			
		||||
                  @dragover.prevent
 | 
			
		||||
                  @dragenter.prevent
 | 
			
		||||
                  @drop.prevent="(e) => handleFileDrop(e, 'md')"
 | 
			
		||||
                >
 | 
			
		||||
                  <div
 | 
			
		||||
                    v-if="!uploadFiles.mdFile"
 | 
			
		||||
                    class="flex flex-col items-center gap-3"
 | 
			
		||||
                  >
 | 
			
		||||
                    <FileTextIcon
 | 
			
		||||
                      class="w-12 h-12 text-base-content opacity-40"
 | 
			
		||||
                    />
 | 
			
		||||
                    <div class="text-sm text-base-content/70 text-center">
 | 
			
		||||
                      <div class="font-medium mb-1">点击或拖拽上传</div>
 | 
			
		||||
                      <div class="text-xs">支持 .md 文件</div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div v-else class="flex flex-col items-center gap-2">
 | 
			
		||||
                    <FileTextIcon class="w-8 h-8 text-success" />
 | 
			
		||||
                    <div class="text-xs font-medium text-success text-center">
 | 
			
		||||
                      {{ uploadFiles.mdFile.name }}
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <div class="text-xs text-base-content/50">点击重新选择</div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                </div>
 | 
			
		||||
                <input
 | 
			
		||||
                  type="file"
 | 
			
		||||
                  ref="mdFileInput"
 | 
			
		||||
                  @change="(e) => handleFileChange(e, 'md')"
 | 
			
		||||
                  accept=".md"
 | 
			
		||||
                  class="hidden"
 | 
			
		||||
                />
 | 
			
		||||
              </div>
 | 
			
		||||
 | 
			
		||||
              <!-- 图片资源 -->
 | 
			
		||||
              <div class="space-y-2">
 | 
			
		||||
                <label class="text-sm font-medium text-base-content"
 | 
			
		||||
                  >图片资源 (可选)</label
 | 
			
		||||
                >
 | 
			
		||||
                <div
 | 
			
		||||
                  class="border-2 border-dashed border-base-300 rounded-lg p-6 text-center cursor-pointer hover:border-primary hover:bg-primary/5 transition-colors aspect-square flex items-center justify-center"
 | 
			
		||||
                  @click="imageFilesInput?.click()"
 | 
			
		||||
                  @dragover.prevent
 | 
			
		||||
                  @dragenter.prevent
 | 
			
		||||
                  @drop.prevent="(e) => handleFileDrop(e, 'image')"
 | 
			
		||||
                >
 | 
			
		||||
                  <div
 | 
			
		||||
                    v-if="uploadFiles.imageFiles.length === 0"
 | 
			
		||||
                    class="flex flex-col items-center gap-3"
 | 
			
		||||
                  >
 | 
			
		||||
                    <ImageIcon class="w-12 h-12 text-base-content opacity-40" />
 | 
			
		||||
                    <div class="text-sm text-base-content/70 text-center">
 | 
			
		||||
                      <div class="font-medium mb-1">点击或拖拽上传</div>
 | 
			
		||||
                      <div class="text-xs">支持 PNG, JPG, GIF 等图片格式</div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div v-else class="flex flex-col items-center gap-2">
 | 
			
		||||
                    <ImageIcon class="w-8 h-8 text-success" />
 | 
			
		||||
                    <div class="text-xs font-medium text-success">
 | 
			
		||||
                      {{ uploadFiles.imageFiles.length }} 个文件
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <div class="text-xs text-base-content/50">点击重新选择</div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                </div>
 | 
			
		||||
                <input
 | 
			
		||||
                  type="file"
 | 
			
		||||
                  ref="imageFilesInput"
 | 
			
		||||
                  @change="(e) => handleFileChange(e, 'image')"
 | 
			
		||||
                  accept="image/*"
 | 
			
		||||
                  multiple
 | 
			
		||||
                  class="hidden"
 | 
			
		||||
                />
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <!-- 第二行:示例比特流 和 画布模板 -->
 | 
			
		||||
            <div class="grid grid-cols-2 gap-4">
 | 
			
		||||
              <!-- 示例比特流 -->
 | 
			
		||||
              <div class="space-y-2">
 | 
			
		||||
                <label class="text-sm font-medium text-base-content"
 | 
			
		||||
                  >示例比特流 (可选)</label
 | 
			
		||||
                >
 | 
			
		||||
                <div
 | 
			
		||||
                  class="border-2 border-dashed border-base-300 rounded-lg p-6 text-center cursor-pointer hover:border-primary hover:bg-primary/5 transition-colors aspect-square flex items-center justify-center"
 | 
			
		||||
                  @click="bitstreamFilesInput?.click()"
 | 
			
		||||
                  @dragover.prevent
 | 
			
		||||
                  @dragenter.prevent
 | 
			
		||||
                  @drop.prevent="(e) => handleFileDrop(e, 'bitstream')"
 | 
			
		||||
                >
 | 
			
		||||
                  <div
 | 
			
		||||
                    v-if="uploadFiles.bitstreamFiles.length === 0"
 | 
			
		||||
                    class="flex flex-col items-center gap-3"
 | 
			
		||||
                  >
 | 
			
		||||
                    <BinaryIcon
 | 
			
		||||
                      class="w-12 h-12 text-base-content opacity-40"
 | 
			
		||||
                    />
 | 
			
		||||
                    <div class="text-sm text-base-content/70 text-center">
 | 
			
		||||
                      <div class="font-medium mb-1">点击或拖拽上传</div>
 | 
			
		||||
                      <div class="text-xs">支持 .sbit, .bit, .bin 文件</div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div v-else class="flex flex-col items-center gap-2">
 | 
			
		||||
                    <BinaryIcon class="w-8 h-8 text-success" />
 | 
			
		||||
                    <div class="text-xs font-medium text-success">
 | 
			
		||||
                      {{ uploadFiles.bitstreamFiles.length }} 个文件
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <div class="text-xs text-base-content/50">点击重新选择</div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                </div>
 | 
			
		||||
                <input
 | 
			
		||||
                  type="file"
 | 
			
		||||
                  ref="bitstreamFilesInput"
 | 
			
		||||
                  @change="(e) => handleFileChange(e, 'bitstream')"
 | 
			
		||||
                  accept=".sbit,.bit,.bin"
 | 
			
		||||
                  multiple
 | 
			
		||||
                  class="hidden"
 | 
			
		||||
                />
 | 
			
		||||
              </div>
 | 
			
		||||
 | 
			
		||||
              <!-- 画布模板 -->
 | 
			
		||||
              <div class="space-y-2">
 | 
			
		||||
                <label class="text-sm font-medium text-base-content"
 | 
			
		||||
                  >画布模板 (可选)</label
 | 
			
		||||
                >
 | 
			
		||||
                <div
 | 
			
		||||
                  class="border-2 border-dashed border-base-300 rounded-lg p-6 text-center cursor-pointer hover:border-primary hover:bg-primary/5 transition-colors aspect-square flex items-center justify-center"
 | 
			
		||||
                  @click="canvasFilesInput?.click()"
 | 
			
		||||
                  @dragover.prevent
 | 
			
		||||
                  @dragenter.prevent
 | 
			
		||||
                  @drop.prevent="(e) => handleFileDrop(e, 'canvas')"
 | 
			
		||||
                >
 | 
			
		||||
                  <div
 | 
			
		||||
                    v-if="uploadFiles.canvasFiles.length === 0"
 | 
			
		||||
                    class="flex flex-col items-center gap-3"
 | 
			
		||||
                  >
 | 
			
		||||
                    <FileJsonIcon
 | 
			
		||||
                      class="w-12 h-12 text-base-content opacity-40"
 | 
			
		||||
                    />
 | 
			
		||||
                    <div class="text-sm text-base-content/70 text-center">
 | 
			
		||||
                      <div class="font-medium mb-1">点击或拖拽上传</div>
 | 
			
		||||
                      <div class="text-xs">支持 .json 文件</div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div v-else class="flex flex-col items-center gap-2">
 | 
			
		||||
                    <FileJsonIcon class="w-8 h-8 text-success" />
 | 
			
		||||
                    <div class="text-xs font-medium text-success">
 | 
			
		||||
                      {{ uploadFiles.canvasFiles.length }} 个文件
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <div class="text-xs text-base-content/50">点击重新选择</div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                </div>
 | 
			
		||||
                <input
 | 
			
		||||
                  type="file"
 | 
			
		||||
                  ref="canvasFilesInput"
 | 
			
		||||
                  @change="(e) => handleFileChange(e, 'canvas')"
 | 
			
		||||
                  accept=".json"
 | 
			
		||||
                  multiple
 | 
			
		||||
                  class="hidden"
 | 
			
		||||
                />
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <!-- 第三行:资源包 (单独一个,居中) -->
 | 
			
		||||
            <div class="flex justify-center">
 | 
			
		||||
              <div class="w-1/2 space-y-2">
 | 
			
		||||
                <label class="text-sm font-medium text-base-content"
 | 
			
		||||
                  >资源包 (可选)</label
 | 
			
		||||
                >
 | 
			
		||||
                <div
 | 
			
		||||
                  class="border-2 border-dashed border-base-300 rounded-lg p-6 text-center cursor-pointer hover:border-primary hover:bg-primary/5 transition-colors aspect-square flex items-center justify-center"
 | 
			
		||||
                  @click="resourceFileInput?.click()"
 | 
			
		||||
                  @dragover.prevent
 | 
			
		||||
                  @dragenter.prevent
 | 
			
		||||
                  @drop.prevent="(e) => handleFileDrop(e, 'resource')"
 | 
			
		||||
                >
 | 
			
		||||
                  <div
 | 
			
		||||
                    v-if="!uploadFiles.resourceFile"
 | 
			
		||||
                    class="flex flex-col items-center gap-3"
 | 
			
		||||
                  >
 | 
			
		||||
                    <FileArchiveIcon
 | 
			
		||||
                      class="w-12 h-12 text-base-content opacity-40"
 | 
			
		||||
                    />
 | 
			
		||||
                    <div class="text-sm text-base-content/70 text-center">
 | 
			
		||||
                      <div class="font-medium mb-1">点击或拖拽上传</div>
 | 
			
		||||
                      <div class="text-xs">支持 .zip, .rar, .7z 文件</div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div v-else class="flex flex-col items-center gap-2">
 | 
			
		||||
                    <FileArchiveIcon class="w-8 h-8 text-success" />
 | 
			
		||||
                    <div class="text-xs font-medium text-success text-center">
 | 
			
		||||
                      {{ uploadFiles.resourceFile.name }}
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <div class="text-xs text-base-content/50">点击重新选择</div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                </div>
 | 
			
		||||
                <input
 | 
			
		||||
                  type="file"
 | 
			
		||||
                  ref="resourceFileInput"
 | 
			
		||||
                  @change="(e) => handleFileChange(e, 'resource')"
 | 
			
		||||
                  accept=".zip,.rar,.7z"
 | 
			
		||||
                  class="hidden"
 | 
			
		||||
                />
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
      </form>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="modal-backdrop" @click="close"></div>
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import {
 | 
			
		||||
  FileTextIcon,
 | 
			
		||||
  ImageIcon,
 | 
			
		||||
  BinaryIcon,
 | 
			
		||||
  FileArchiveIcon,
 | 
			
		||||
  FileJsonIcon,
 | 
			
		||||
} from "lucide-vue-next";
 | 
			
		||||
import { ExamDto, type FileParameter } from "@/APIClient";
 | 
			
		||||
import { useAlertStore } from "@/components/Alert";
 | 
			
		||||
import { AuthManager } from "@/utils/AuthManager";
 | 
			
		||||
import { useRequiredInjection } from "@/utils/Common";
 | 
			
		||||
import { defineModel, ref, computed } from "vue";
 | 
			
		||||
import { mod } from "mathjs";
 | 
			
		||||
import type { ExamInfo } from "@/APIClient";
 | 
			
		||||
 | 
			
		||||
type Mode = "create" | "edit";
 | 
			
		||||
 | 
			
		||||
const isShowModal = defineModel<boolean>("isShowModal", {
 | 
			
		||||
  default: false,
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const emits = defineEmits<{
 | 
			
		||||
  editFinished: [examId: string];
 | 
			
		||||
}>();
 | 
			
		||||
 | 
			
		||||
const alert = useRequiredInjection(useAlertStore);
 | 
			
		||||
 | 
			
		||||
const editExamInfo = ref({
 | 
			
		||||
  id: "",
 | 
			
		||||
  name: "",
 | 
			
		||||
  description: "",
 | 
			
		||||
  tags: [] as string[],
 | 
			
		||||
  difficulty: 1,
 | 
			
		||||
  isVisibleToUsers: true,
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const isUpdating = ref(false);
 | 
			
		||||
const mode = ref<Mode>("create");
 | 
			
		||||
const newTagInput = ref("");
 | 
			
		||||
 | 
			
		||||
// 文件上传相关
 | 
			
		||||
const uploadFiles = ref({
 | 
			
		||||
  mdFile: null as File | null,
 | 
			
		||||
  imageFiles: [] as File[],
 | 
			
		||||
  bitstreamFiles: [] as File[],
 | 
			
		||||
  canvasFiles: [] as File[],
 | 
			
		||||
  resourceFile: null as File | null,
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// 文件输入引用
 | 
			
		||||
const mdFileInput = ref<HTMLInputElement>();
 | 
			
		||||
const imageFilesInput = ref<HTMLInputElement>();
 | 
			
		||||
const bitstreamFilesInput = ref<HTMLInputElement>();
 | 
			
		||||
const canvasFilesInput = ref<HTMLInputElement>();
 | 
			
		||||
const resourceFileInput = ref<HTMLInputElement>();
 | 
			
		||||
 | 
			
		||||
// 计算属性
 | 
			
		||||
const canCreateExam = computed(() => {
 | 
			
		||||
  return (
 | 
			
		||||
    editExamInfo.value.id.trim() !== "" &&
 | 
			
		||||
    editExamInfo.value.name.trim() !== "" &&
 | 
			
		||||
    editExamInfo.value.description.trim() !== "" &&
 | 
			
		||||
    (uploadFiles.value.mdFile !== null || mode.value === "edit")
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// 文件类型定义
 | 
			
		||||
type FileType = "md" | "image" | "bitstream" | "canvas" | "resource";
 | 
			
		||||
 | 
			
		||||
// 统一文件处理方法
 | 
			
		||||
const handleFileChange = (event: Event, fileType: FileType) => {
 | 
			
		||||
  const target = event.target as HTMLInputElement;
 | 
			
		||||
  if (!target.files) return;
 | 
			
		||||
 | 
			
		||||
  switch (fileType) {
 | 
			
		||||
    case "md":
 | 
			
		||||
      if (target.files.length > 0) {
 | 
			
		||||
        uploadFiles.value.mdFile = target.files[0];
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case "image":
 | 
			
		||||
      uploadFiles.value.imageFiles = Array.from(target.files);
 | 
			
		||||
      break;
 | 
			
		||||
    case "bitstream":
 | 
			
		||||
      uploadFiles.value.bitstreamFiles = Array.from(target.files);
 | 
			
		||||
      break;
 | 
			
		||||
    case "canvas":
 | 
			
		||||
      uploadFiles.value.canvasFiles = Array.from(target.files);
 | 
			
		||||
      break;
 | 
			
		||||
    case "resource":
 | 
			
		||||
      if (target.files.length > 0) {
 | 
			
		||||
        uploadFiles.value.resourceFile = target.files[0];
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const handleFileDrop = (event: DragEvent, fileType: FileType) => {
 | 
			
		||||
  const files = event.dataTransfer?.files;
 | 
			
		||||
  if (!files || files.length === 0) return;
 | 
			
		||||
 | 
			
		||||
  switch (fileType) {
 | 
			
		||||
    case "md":
 | 
			
		||||
      const mdFile = files[0];
 | 
			
		||||
      if (mdFile.name.endsWith(".md")) {
 | 
			
		||||
        uploadFiles.value.mdFile = mdFile;
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case "image":
 | 
			
		||||
      const imageFiles = Array.from(files).filter((file) =>
 | 
			
		||||
        file.type.startsWith("image/"),
 | 
			
		||||
      );
 | 
			
		||||
      uploadFiles.value.imageFiles = imageFiles;
 | 
			
		||||
      break;
 | 
			
		||||
    case "bitstream":
 | 
			
		||||
      const bitstreamFiles = Array.from(files).filter(
 | 
			
		||||
        (file) =>
 | 
			
		||||
          file.name.endsWith(".sbit") ||
 | 
			
		||||
          file.name.endsWith(".bit") ||
 | 
			
		||||
          file.name.endsWith(".bin"),
 | 
			
		||||
      );
 | 
			
		||||
      uploadFiles.value.bitstreamFiles = bitstreamFiles;
 | 
			
		||||
      break;
 | 
			
		||||
    case "canvas":
 | 
			
		||||
      const canvasFiles = Array.from(files).filter((file) =>
 | 
			
		||||
        file.name.endsWith(".json"),
 | 
			
		||||
      );
 | 
			
		||||
      uploadFiles.value.canvasFiles = canvasFiles;
 | 
			
		||||
      break;
 | 
			
		||||
    case "resource":
 | 
			
		||||
      const resourceFile = files[0];
 | 
			
		||||
      if (
 | 
			
		||||
        resourceFile.name.endsWith(".zip") ||
 | 
			
		||||
        resourceFile.name.endsWith(".rar") ||
 | 
			
		||||
        resourceFile.name.endsWith(".7z")
 | 
			
		||||
      ) {
 | 
			
		||||
        uploadFiles.value.resourceFile = resourceFile;
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 标签管理
 | 
			
		||||
const addTag = (event?: Event) => {
 | 
			
		||||
  if (event) {
 | 
			
		||||
    event.preventDefault();
 | 
			
		||||
    event.stopPropagation();
 | 
			
		||||
  }
 | 
			
		||||
  const tag = newTagInput.value.trim();
 | 
			
		||||
  if (tag && !editExamInfo.value.tags.includes(tag)) {
 | 
			
		||||
    editExamInfo.value.tags.push(tag);
 | 
			
		||||
    newTagInput.value = "";
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const removeTag = (index: number) => {
 | 
			
		||||
  editExamInfo.value.tags.splice(index, 1);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const resetCreateForm = () => {
 | 
			
		||||
  editExamInfo.value = {
 | 
			
		||||
    id: "",
 | 
			
		||||
    name: "",
 | 
			
		||||
    description: "",
 | 
			
		||||
    tags: [],
 | 
			
		||||
    difficulty: 1,
 | 
			
		||||
    isVisibleToUsers: true,
 | 
			
		||||
  };
 | 
			
		||||
  newTagInput.value = "";
 | 
			
		||||
  uploadFiles.value = {
 | 
			
		||||
    mdFile: null,
 | 
			
		||||
    imageFiles: [],
 | 
			
		||||
    bitstreamFiles: [],
 | 
			
		||||
    canvasFiles: [],
 | 
			
		||||
    resourceFile: null,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  // 重置文件输入
 | 
			
		||||
  if (mdFileInput.value) mdFileInput.value.value = "";
 | 
			
		||||
  if (imageFilesInput.value) imageFilesInput.value.value = "";
 | 
			
		||||
  if (bitstreamFilesInput.value) bitstreamFilesInput.value.value = "";
 | 
			
		||||
  if (canvasFilesInput.value) canvasFilesInput.value.value = "";
 | 
			
		||||
  if (resourceFileInput.value) resourceFileInput.value.value = "";
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 提交创建实验
 | 
			
		||||
const submitCreateExam = async () => {
 | 
			
		||||
  if (isUpdating.value) return;
 | 
			
		||||
 | 
			
		||||
  // 验证必填字段
 | 
			
		||||
  if (
 | 
			
		||||
    !editExamInfo.value.id ||
 | 
			
		||||
    !editExamInfo.value.name ||
 | 
			
		||||
    !editExamInfo.value.description
 | 
			
		||||
  ) {
 | 
			
		||||
    alert?.error("请填写所有必填字段");
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (!uploadFiles.value.mdFile) {
 | 
			
		||||
    alert.error("请上传MD文档");
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  isUpdating.value = true;
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    const client = AuthManager.createAuthenticatedExamClient();
 | 
			
		||||
 | 
			
		||||
    let exam: ExamInfo;
 | 
			
		||||
    if (mode.value === "create") {
 | 
			
		||||
      // 创建实验请求
 | 
			
		||||
      const createRequest = new ExamDto({
 | 
			
		||||
        id: editExamInfo.value.id,
 | 
			
		||||
        name: editExamInfo.value.name,
 | 
			
		||||
        description: editExamInfo.value.description,
 | 
			
		||||
        tags: editExamInfo.value.tags,
 | 
			
		||||
        difficulty: editExamInfo.value.difficulty,
 | 
			
		||||
        isVisibleToUsers: editExamInfo.value.isVisibleToUsers,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      // 创建实验
 | 
			
		||||
      exam = await client.createExam(createRequest);
 | 
			
		||||
      console.log("实验创建成功:", exam);
 | 
			
		||||
    } else if (mode.value === "edit") {
 | 
			
		||||
      // 编辑实验请求
 | 
			
		||||
      const editRequest = new ExamDto({
 | 
			
		||||
        id: editExamInfo.value.id,
 | 
			
		||||
        name: editExamInfo.value.name,
 | 
			
		||||
        description: editExamInfo.value.description,
 | 
			
		||||
        tags: editExamInfo.value.tags,
 | 
			
		||||
        difficulty: editExamInfo.value.difficulty,
 | 
			
		||||
        isVisibleToUsers: editExamInfo.value.isVisibleToUsers,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      // 编辑实验
 | 
			
		||||
      exam = await client.updateExam(editRequest);
 | 
			
		||||
      console.log("实验编辑成功:", exam);
 | 
			
		||||
    } else {
 | 
			
		||||
      // 处理其他模式
 | 
			
		||||
      console.error("未知的模式:", mode.value);
 | 
			
		||||
      throw new Error("未知的模式");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 上传文件
 | 
			
		||||
    await uploadExamResources(exam.id);
 | 
			
		||||
 | 
			
		||||
    alert.success("实验创建成功");
 | 
			
		||||
    close();
 | 
			
		||||
    emits("editFinished", exam.id);
 | 
			
		||||
  } catch (err: any) {
 | 
			
		||||
    console.error("创建实验失败:", err);
 | 
			
		||||
    alert.error(err.message || "创建实验失败");
 | 
			
		||||
  } finally {
 | 
			
		||||
    isUpdating.value = false;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 上传实验资源
 | 
			
		||||
async function uploadExamResources(examId: string) {
 | 
			
		||||
  const client = AuthManager.createAuthenticatedResourceClient();
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    // 上传MD文档
 | 
			
		||||
    if (uploadFiles.value.mdFile) {
 | 
			
		||||
      const mdFileParam: FileParameter = {
 | 
			
		||||
        data: uploadFiles.value.mdFile,
 | 
			
		||||
        fileName: uploadFiles.value.mdFile.name,
 | 
			
		||||
      };
 | 
			
		||||
      await client.addResource("doc", "template", examId, mdFileParam);
 | 
			
		||||
      console.log("MD文档上传成功");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 上传图片资源
 | 
			
		||||
    for (const imageFile of uploadFiles.value.imageFiles) {
 | 
			
		||||
      const imageFileParam: FileParameter = {
 | 
			
		||||
        data: imageFile,
 | 
			
		||||
        fileName: imageFile.name,
 | 
			
		||||
      };
 | 
			
		||||
      await client.addResource("image", "template", examId, imageFileParam);
 | 
			
		||||
      console.log("图片上传成功:", imageFile.name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 上传比特流文件
 | 
			
		||||
    for (const bitstreamFile of uploadFiles.value.bitstreamFiles) {
 | 
			
		||||
      const bitstreamFileParam: FileParameter = {
 | 
			
		||||
        data: bitstreamFile,
 | 
			
		||||
        fileName: bitstreamFile.name,
 | 
			
		||||
      };
 | 
			
		||||
      await client.addResource(
 | 
			
		||||
        "bitstream",
 | 
			
		||||
        "template",
 | 
			
		||||
        examId,
 | 
			
		||||
        bitstreamFileParam,
 | 
			
		||||
      );
 | 
			
		||||
      console.log("比特流文件上传成功:", bitstreamFile.name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 上传画布模板
 | 
			
		||||
    for (const canvasFile of uploadFiles.value.canvasFiles) {
 | 
			
		||||
      const canvasFileParam: FileParameter = {
 | 
			
		||||
        data: canvasFile,
 | 
			
		||||
        fileName: canvasFile.name,
 | 
			
		||||
      };
 | 
			
		||||
      await client.addResource("canvas", "template", examId, canvasFileParam);
 | 
			
		||||
      console.log("画布模板上传成功:", canvasFile.name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 上传资源包
 | 
			
		||||
    if (uploadFiles.value.resourceFile) {
 | 
			
		||||
      const resourceFileParam: FileParameter = {
 | 
			
		||||
        data: uploadFiles.value.resourceFile,
 | 
			
		||||
        fileName: uploadFiles.value.resourceFile.name,
 | 
			
		||||
      };
 | 
			
		||||
      await client.addResource(
 | 
			
		||||
        "resource",
 | 
			
		||||
        "template",
 | 
			
		||||
        examId,
 | 
			
		||||
        resourceFileParam,
 | 
			
		||||
      );
 | 
			
		||||
      console.log("资源包上传成功");
 | 
			
		||||
    }
 | 
			
		||||
  } catch (err: any) {
 | 
			
		||||
    console.error("资源上传失败:", err);
 | 
			
		||||
    alert?.error("部分资源上传失败: " + (err.message || "未知错误"));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function show() {
 | 
			
		||||
  isShowModal.value = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function close() {
 | 
			
		||||
  isShowModal.value = false;
 | 
			
		||||
  mode.value = "create";
 | 
			
		||||
  resetCreateForm();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function editExam(examId: string) {
 | 
			
		||||
  const client = AuthManager.createAuthenticatedExamClient();
 | 
			
		||||
  const examInfo = await client.getExam(examId);
 | 
			
		||||
 | 
			
		||||
  editExamInfo.value = {
 | 
			
		||||
    id: examInfo.id,
 | 
			
		||||
    name: examInfo.name,
 | 
			
		||||
    description: examInfo.description,
 | 
			
		||||
    tags: examInfo.tags,
 | 
			
		||||
    difficulty: examInfo.difficulty,
 | 
			
		||||
    isVisibleToUsers: examInfo.isVisibleToUsers,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  mode.value = "edit";
 | 
			
		||||
  show();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
defineExpose({
 | 
			
		||||
  show,
 | 
			
		||||
  close,
 | 
			
		||||
  editExam,
 | 
			
		||||
});
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="postcss" scoped></style>
 | 
			
		||||
							
								
								
									
										352
									
								
								src/views/Exam/ExamInfoModal.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										352
									
								
								src/views/Exam/ExamInfoModal.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,352 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div v-if="show" class="modal modal-open overflow-hidden">
 | 
			
		||||
    <div
 | 
			
		||||
      class="modal-box w-full max-w-6xl h-[90vh] max-h-[90vh] p-0 overflow-hidden"
 | 
			
		||||
    >
 | 
			
		||||
      <div
 | 
			
		||||
        class="flex justify-between items-center p-6 border-b border-base-300"
 | 
			
		||||
      >
 | 
			
		||||
        <h2 class="text-2xl font-bold text-base-content">
 | 
			
		||||
          {{ selectedExam.id }} - {{ selectedExam.name }}
 | 
			
		||||
        </h2>
 | 
			
		||||
        <button
 | 
			
		||||
          @click="closeExamDetail"
 | 
			
		||||
          class="btn btn-sm btn-circle btn-ghost"
 | 
			
		||||
        >
 | 
			
		||||
          <svg
 | 
			
		||||
            class="w-6 h-6"
 | 
			
		||||
            fill="none"
 | 
			
		||||
            stroke="currentColor"
 | 
			
		||||
            viewBox="0 0 24 24"
 | 
			
		||||
          >
 | 
			
		||||
            <path
 | 
			
		||||
              stroke-linecap="round"
 | 
			
		||||
              stroke-linejoin="round"
 | 
			
		||||
              stroke-width="2"
 | 
			
		||||
              d="M6 18L18 6M6 6l12 12"
 | 
			
		||||
            />
 | 
			
		||||
          </svg>
 | 
			
		||||
        </button>
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
      <div class="flex h-[calc(90vh-5rem)]">
 | 
			
		||||
        <!-- 左侧:实验信息和描述 -->
 | 
			
		||||
        <div class="flex-1 p-6 overflow-y-auto border-r border-base-300">
 | 
			
		||||
          <div class="space-y-6">
 | 
			
		||||
            <!-- 实验信息 -->
 | 
			
		||||
            <div class="card bg-base-200">
 | 
			
		||||
              <div class="card-body">
 | 
			
		||||
                <h3 class="card-title text-lg mb-4">实验信息</h3>
 | 
			
		||||
                <div class="space-y-3">
 | 
			
		||||
                  <div class="flex">
 | 
			
		||||
                    <span class="font-medium text-base-content w-24"
 | 
			
		||||
                      >实验ID:</span
 | 
			
		||||
                    >
 | 
			
		||||
                    <span class="text-base-content/70">{{
 | 
			
		||||
                      selectedExam.id
 | 
			
		||||
                    }}</span>
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div class="flex">
 | 
			
		||||
                    <span class="font-medium text-base-content w-24"
 | 
			
		||||
                      >实验名称:</span
 | 
			
		||||
                    >
 | 
			
		||||
                    <span class="text-base-content/70">{{
 | 
			
		||||
                      selectedExam.name
 | 
			
		||||
                    }}</span>
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div class="flex">
 | 
			
		||||
                    <span class="font-medium text-base-content w-24"
 | 
			
		||||
                      >难度等级:</span
 | 
			
		||||
                    >
 | 
			
		||||
                    <div class="flex items-center gap-2">
 | 
			
		||||
                      <div class="rating rating-sm">
 | 
			
		||||
                        <span
 | 
			
		||||
                          v-for="i in 5"
 | 
			
		||||
                          :key="i"
 | 
			
		||||
                          class="mask mask-star-2"
 | 
			
		||||
                          :class="
 | 
			
		||||
                            i <= selectedExam.difficulty
 | 
			
		||||
                              ? 'bg-orange-400'
 | 
			
		||||
                              : 'bg-base-300'
 | 
			
		||||
                          "
 | 
			
		||||
                        ></span>
 | 
			
		||||
                      </div>
 | 
			
		||||
                      <span class="text-sm text-base-content/50"
 | 
			
		||||
                        >({{ selectedExam.difficulty }}/5)</span
 | 
			
		||||
                      >
 | 
			
		||||
                    </div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div
 | 
			
		||||
                    v-if="selectedExam.tags && selectedExam.tags.length > 0"
 | 
			
		||||
                    class="flex"
 | 
			
		||||
                  >
 | 
			
		||||
                    <span class="font-medium text-base-content w-24"
 | 
			
		||||
                      >标签:</span
 | 
			
		||||
                    >
 | 
			
		||||
                    <div class="flex flex-wrap gap-1">
 | 
			
		||||
                      <span
 | 
			
		||||
                        v-for="tag in selectedExam.tags"
 | 
			
		||||
                        :key="tag"
 | 
			
		||||
                        class="badge badge-outline badge-sm"
 | 
			
		||||
                        >{{ tag }}</span
 | 
			
		||||
                      >
 | 
			
		||||
                    </div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div class="flex">
 | 
			
		||||
                    <span class="font-medium text-base-content w-24"
 | 
			
		||||
                      >创建时间:</span
 | 
			
		||||
                    >
 | 
			
		||||
                    <span class="text-base-content/70">{{
 | 
			
		||||
                      formatDate(selectedExam.createdTime)
 | 
			
		||||
                    }}</span>
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div class="flex">
 | 
			
		||||
                    <span class="font-medium text-base-content w-24"
 | 
			
		||||
                      >更新时间:</span
 | 
			
		||||
                    >
 | 
			
		||||
                    <span class="text-base-content/70">{{
 | 
			
		||||
                      formatDate(selectedExam.updatedTime)
 | 
			
		||||
                    }}</span>
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div class="flex">
 | 
			
		||||
                    <span class="font-medium text-base-content w-24"
 | 
			
		||||
                      >可见性:</span
 | 
			
		||||
                    >
 | 
			
		||||
                    <span class="text-base-content/70">{{
 | 
			
		||||
                      selectedExam.isVisibleToUsers
 | 
			
		||||
                        ? "对学生可见"
 | 
			
		||||
                        : "仅管理员可见"
 | 
			
		||||
                    }}</span>
 | 
			
		||||
                  </div>
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <!-- 实验描述 -->
 | 
			
		||||
            <div class="card bg-base-200">
 | 
			
		||||
              <div class="card-body">
 | 
			
		||||
                <h3 class="card-title text-lg mb-4">实验描述</h3>
 | 
			
		||||
                <div class="prose prose-sm max-w-none">
 | 
			
		||||
                  <p class="text-base-content/70">
 | 
			
		||||
                    {{ selectedExam.description }}
 | 
			
		||||
                  </p>
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <!-- 右侧:完成情况和控制 -->
 | 
			
		||||
        <div class="w-80 p-6 bg-base-200 overflow-y-auto">
 | 
			
		||||
          <div class="space-y-6">
 | 
			
		||||
            <!-- 完成情况 -->
 | 
			
		||||
            <div class="card bg-base-100">
 | 
			
		||||
              <div class="card-body">
 | 
			
		||||
                <h3 class="card-title text-lg mb-4">完成情况</h3>
 | 
			
		||||
 | 
			
		||||
                <div class="space-y-4">
 | 
			
		||||
                  <div class="flex justify-between items-center">
 | 
			
		||||
                    <span class="text-base-content/70">当前状态</span>
 | 
			
		||||
                    <div class="badge badge-error">未完成</div>
 | 
			
		||||
                  </div>
 | 
			
		||||
 | 
			
		||||
                  <div class="flex justify-between items-center">
 | 
			
		||||
                    <span class="text-base-content/70">批阅状态</span>
 | 
			
		||||
                    <div class="badge badge-ghost">待提交</div>
 | 
			
		||||
                  </div>
 | 
			
		||||
 | 
			
		||||
                  <div class="flex justify-between items-center">
 | 
			
		||||
                    <span class="text-base-content/70">成绩</span>
 | 
			
		||||
                    <span class="text-base-content/50">未评分</span>
 | 
			
		||||
                  </div>
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
                <div class="divider"></div>
 | 
			
		||||
 | 
			
		||||
                <!-- 提交历史 -->
 | 
			
		||||
                <div class="space-y-3">
 | 
			
		||||
                  <h4 class="font-medium text-base-content">提交历史</h4>
 | 
			
		||||
                  <div
 | 
			
		||||
                    v-if="isUndefined(commitsList)"
 | 
			
		||||
                    class="text-sm text-base-content/50 text-center py-4"
 | 
			
		||||
                  >
 | 
			
		||||
                    暂无提交记录
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div v-else class="overflow-y-auto">
 | 
			
		||||
                    <ul class="steps steps-vertical">
 | 
			
		||||
                      <li class="step step-primary">Register</li>
 | 
			
		||||
                      <li class="step step-primary">Choose plan</li>
 | 
			
		||||
                      <li class="step">Purchase</li>
 | 
			
		||||
                      <li class="step">Receive Product</li>
 | 
			
		||||
                    </ul>
 | 
			
		||||
                  </div>
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <!-- 操作按钮 -->
 | 
			
		||||
            <div class="space-y-3">
 | 
			
		||||
              <button @click="startExam" class="btn btn-primary w-full">
 | 
			
		||||
                <svg
 | 
			
		||||
                  class="w-5 h-5 mr-2"
 | 
			
		||||
                  fill="none"
 | 
			
		||||
                  stroke="currentColor"
 | 
			
		||||
                  viewBox="0 0 24 24"
 | 
			
		||||
                >
 | 
			
		||||
                  <path
 | 
			
		||||
                    stroke-linecap="round"
 | 
			
		||||
                    stroke-linejoin="round"
 | 
			
		||||
                    stroke-width="2"
 | 
			
		||||
                    d="M14.828 14.828a4 4 0 01-5.656 0M9 10h1m4 0h1m-6 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
 | 
			
		||||
                  />
 | 
			
		||||
                </svg>
 | 
			
		||||
                开始实验
 | 
			
		||||
              </button>
 | 
			
		||||
 | 
			
		||||
              <button
 | 
			
		||||
                @click="downloadResources"
 | 
			
		||||
                class="btn btn-outline w-full"
 | 
			
		||||
                :disabled="downloadingResources"
 | 
			
		||||
              >
 | 
			
		||||
                <svg
 | 
			
		||||
                  class="w-5 h-5 mr-2"
 | 
			
		||||
                  fill="none"
 | 
			
		||||
                  stroke="currentColor"
 | 
			
		||||
                  viewBox="0 0 24 24"
 | 
			
		||||
                >
 | 
			
		||||
                  <path
 | 
			
		||||
                    stroke-linecap="round"
 | 
			
		||||
                    stroke-linejoin="round"
 | 
			
		||||
                    stroke-width="2"
 | 
			
		||||
                    d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"
 | 
			
		||||
                  />
 | 
			
		||||
                </svg>
 | 
			
		||||
                <span v-if="downloadingResources">下载中...</span>
 | 
			
		||||
                <span v-else>下载资源包</span>
 | 
			
		||||
              </button>
 | 
			
		||||
 | 
			
		||||
              <button class="btn btn-outline w-full">
 | 
			
		||||
                <svg
 | 
			
		||||
                  class="w-5 h-5 mr-2"
 | 
			
		||||
                  fill="none"
 | 
			
		||||
                  stroke="currentColor"
 | 
			
		||||
                  viewBox="0 0 24 24"
 | 
			
		||||
                >
 | 
			
		||||
                  <path
 | 
			
		||||
                    stroke-linecap="round"
 | 
			
		||||
                    stroke-linejoin="round"
 | 
			
		||||
                    stroke-width="2"
 | 
			
		||||
                    d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"
 | 
			
		||||
                  />
 | 
			
		||||
                </svg>
 | 
			
		||||
                查看记录
 | 
			
		||||
              </button>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="modal-backdrop" @click="closeExamDetail"></div>
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import type { Commit, ExamInfo } from "@/APIClient";
 | 
			
		||||
import { useAlertStore } from "@/components/Alert";
 | 
			
		||||
import { AuthManager } from "@/utils/AuthManager";
 | 
			
		||||
import { useRequiredInjection } from "@/utils/Common";
 | 
			
		||||
import { defineModel, ref } from "vue";
 | 
			
		||||
import { useRouter } from "vue-router";
 | 
			
		||||
import { formatDate } from "@/utils/Common";
 | 
			
		||||
import { computed } from "vue";
 | 
			
		||||
import { watch } from "vue";
 | 
			
		||||
import { isNull, isUndefined } from "lodash";
 | 
			
		||||
 | 
			
		||||
const alertStore = useRequiredInjection(useAlertStore);
 | 
			
		||||
const router = useRouter();
 | 
			
		||||
 | 
			
		||||
const show = defineModel<boolean>("show", {
 | 
			
		||||
  default: false,
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const props = defineProps<{
 | 
			
		||||
  selectedExam: ExamInfo;
 | 
			
		||||
}>();
 | 
			
		||||
 | 
			
		||||
const commitsList = ref<Commit[]>();
 | 
			
		||||
async function updateCommits() {
 | 
			
		||||
  const client = AuthManager.createAuthenticatedExamClient();
 | 
			
		||||
  const list = await client.getCommitsByExamId(props.selectedExam.id);
 | 
			
		||||
  commitsList.value = list;
 | 
			
		||||
}
 | 
			
		||||
watch(() => props.selectedExam, updateCommits);
 | 
			
		||||
 | 
			
		||||
// Download resources
 | 
			
		||||
const downloadingResources = ref(false);
 | 
			
		||||
const downloadResources = async () => {
 | 
			
		||||
  if (!props.selectedExam || downloadingResources.value) return;
 | 
			
		||||
 | 
			
		||||
  downloadingResources.value = true;
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    const resourceClient = AuthManager.createAuthenticatedResourceClient();
 | 
			
		||||
 | 
			
		||||
    // 获取资源包列表(模板资源)
 | 
			
		||||
    const resourceList = await resourceClient.getResourceList(
 | 
			
		||||
      props.selectedExam.id,
 | 
			
		||||
      "resource",
 | 
			
		||||
      "template",
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    if (resourceList && resourceList.length > 0) {
 | 
			
		||||
      // 使用新的ResourceClient API获取第一个资源包
 | 
			
		||||
      const resourceId = resourceList[0].id;
 | 
			
		||||
      const fileResponse = await resourceClient.getResourceById(resourceId);
 | 
			
		||||
 | 
			
		||||
      // 创建Blob URL
 | 
			
		||||
      const blobUrl = URL.createObjectURL(fileResponse.data);
 | 
			
		||||
 | 
			
		||||
      // 创建下载链接
 | 
			
		||||
      const link = document.createElement("a");
 | 
			
		||||
      link.href = blobUrl;
 | 
			
		||||
      link.download =
 | 
			
		||||
        fileResponse.fileName ||
 | 
			
		||||
        resourceList[0].name ||
 | 
			
		||||
        `${props.selectedExam.name}_资源包`;
 | 
			
		||||
      document.body.appendChild(link);
 | 
			
		||||
      link.click();
 | 
			
		||||
      document.body.removeChild(link);
 | 
			
		||||
 | 
			
		||||
      // 清理Blob URL
 | 
			
		||||
      URL.revokeObjectURL(blobUrl);
 | 
			
		||||
 | 
			
		||||
      alertStore.success("资料下载成功");
 | 
			
		||||
      console.log("资料下载成功:", props.selectedExam.id);
 | 
			
		||||
    } else {
 | 
			
		||||
      alertStore.error("该实验暂无资料包");
 | 
			
		||||
    }
 | 
			
		||||
  } catch (err: any) {
 | 
			
		||||
    alertStore.error(err.message || "下载资料失败");
 | 
			
		||||
    console.error("下载资料失败:", err);
 | 
			
		||||
  } finally {
 | 
			
		||||
    downloadingResources.value = false;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 开始实验
 | 
			
		||||
const startExam = () => {
 | 
			
		||||
  if (props.selectedExam) {
 | 
			
		||||
    // 跳转到项目页面,传递实验ID
 | 
			
		||||
    console.log("开始实验:", props.selectedExam.id);
 | 
			
		||||
    router.push({
 | 
			
		||||
      name: "project",
 | 
			
		||||
      query: { examId: props.selectedExam.id },
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const closeExamDetail = () => {
 | 
			
		||||
  show.value = false;
 | 
			
		||||
};
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="postcss" scoped></style>
 | 
			
		||||
							
								
								
									
										312
									
								
								src/views/Exam/Index.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										312
									
								
								src/views/Exam/Index.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,312 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div class="min-h-screen bg-base-100 p-5">
 | 
			
		||||
    <div class="max-w-7xl mx-auto">
 | 
			
		||||
      <div
 | 
			
		||||
        class="flex justify-between items-center mb-8 pb-6 border-b border-base-300"
 | 
			
		||||
      >
 | 
			
		||||
        <h1 class="text-3xl font-bold text-base-content">实验列表</h1>
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
      <div
 | 
			
		||||
        v-if="loading"
 | 
			
		||||
        class="flex flex-col items-center justify-center min-h-[300px]"
 | 
			
		||||
      >
 | 
			
		||||
        <div class="loading loading-spinner loading-lg text-primary mb-4"></div>
 | 
			
		||||
        <p class="text-base-content/70">正在加载实验列表...</p>
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
      <div
 | 
			
		||||
        v-else-if="error"
 | 
			
		||||
        class="flex flex-col items-center justify-center min-h-[300px]"
 | 
			
		||||
      >
 | 
			
		||||
        <div class="alert alert-error max-w-md">
 | 
			
		||||
          <svg
 | 
			
		||||
            xmlns="http://www.w3.org/2000/svg"
 | 
			
		||||
            class="stroke-current shrink-0 h-6 w-6"
 | 
			
		||||
            fill="none"
 | 
			
		||||
            viewBox="0 0 24 24"
 | 
			
		||||
          >
 | 
			
		||||
            <path
 | 
			
		||||
              stroke-linecap="round"
 | 
			
		||||
              stroke-linejoin="round"
 | 
			
		||||
              stroke-width="2"
 | 
			
		||||
              d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
 | 
			
		||||
            />
 | 
			
		||||
          </svg>
 | 
			
		||||
          <div>
 | 
			
		||||
            <h3 class="font-bold">加载失败</h3>
 | 
			
		||||
            <div class="text-xs">{{ error }}</div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
        <button @click="refreshExams" class="btn btn-primary mt-4">重试</button>
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
      <div v-else class="space-y-6">
 | 
			
		||||
        <div
 | 
			
		||||
          v-if="exams.length === 0 && !isAdmin"
 | 
			
		||||
          class="flex flex-col items-center justify-center min-h-[300px] text-center"
 | 
			
		||||
        >
 | 
			
		||||
          <h3 class="text-xl font-semibold text-base-content/70 mb-2">
 | 
			
		||||
            暂无实验
 | 
			
		||||
          </h3>
 | 
			
		||||
          <p class="text-base-content/50">
 | 
			
		||||
            当前没有可用的实验,请联系管理员添加实验内容。
 | 
			
		||||
          </p>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <div
 | 
			
		||||
          v-else
 | 
			
		||||
          class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"
 | 
			
		||||
        >
 | 
			
		||||
          <!-- 管理员添加实验卡片 -->
 | 
			
		||||
          <div
 | 
			
		||||
            v-if="isAdmin"
 | 
			
		||||
            class="card bg-base-200 shadow-lg hover:shadow-xl transition-all duration-200 cursor-pointer hover:scale-[1.02]"
 | 
			
		||||
            @click="() => examEditModalRef?.show()"
 | 
			
		||||
          >
 | 
			
		||||
            <div class="card-body flex items-center justify-center text-center">
 | 
			
		||||
              <div class="text-primary text-6xl mb-4">+</div>
 | 
			
		||||
              <h3 class="text-lg font-semibold text-primary">添加新实验</h3>
 | 
			
		||||
              <p class="text-sm text-primary/70">点击创建新的实验</p>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
 | 
			
		||||
          <div
 | 
			
		||||
            v-for="exam in exams"
 | 
			
		||||
            :key="exam.id"
 | 
			
		||||
            class="card bg-base-200 shadow-lg hover:shadow-xl transition-all duration-200 cursor-pointer hover:scale-[1.02] relative overflow-hidden"
 | 
			
		||||
            @click="handleCardClicked($event, exam.id)"
 | 
			
		||||
          >
 | 
			
		||||
            <div class="card-body">
 | 
			
		||||
              <div class="flex justify-between items-start mb-4">
 | 
			
		||||
                <h3 class="card-title text-base-content">{{ exam.name }}</h3>
 | 
			
		||||
                <div class="flex flex-row items-center gap-2">
 | 
			
		||||
                  <button
 | 
			
		||||
                    class="btn btn-ghost text-error hover:underline group"
 | 
			
		||||
                    @click="handleEditExamClicked($event, exam.id)"
 | 
			
		||||
                  >
 | 
			
		||||
                    <EditIcon
 | 
			
		||||
                      class="w-4 h-4 transition-transform duration-200 group-hover:scale-110"
 | 
			
		||||
                    />
 | 
			
		||||
                    编辑
 | 
			
		||||
                  </button>
 | 
			
		||||
                  <span
 | 
			
		||||
                    class="card-title text-sm text-blue-600/50 dark:text-sky-400/50"
 | 
			
		||||
                    >{{ exam.id }}</span
 | 
			
		||||
                  >
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
 | 
			
		||||
              <!-- 实验标签 -->
 | 
			
		||||
              <div
 | 
			
		||||
                v-if="exam.tags && exam.tags.length > 0"
 | 
			
		||||
                class="flex flex-wrap gap-1 mb-3"
 | 
			
		||||
              >
 | 
			
		||||
                <span
 | 
			
		||||
                  v-for="tag in exam.tags"
 | 
			
		||||
                  :key="tag"
 | 
			
		||||
                  class="badge badge-outline badge-sm"
 | 
			
		||||
                  >{{ tag }}</span
 | 
			
		||||
                >
 | 
			
		||||
              </div>
 | 
			
		||||
 | 
			
		||||
              <div class="space-y-2 text-sm text-base-content/70">
 | 
			
		||||
                <div class="flex items-center gap-2">
 | 
			
		||||
                  <svg
 | 
			
		||||
                    class="w-4 h-4"
 | 
			
		||||
                    fill="none"
 | 
			
		||||
                    stroke="currentColor"
 | 
			
		||||
                    viewBox="0 0 24 24"
 | 
			
		||||
                  >
 | 
			
		||||
                    <path
 | 
			
		||||
                      stroke-linecap="round"
 | 
			
		||||
                      stroke-linejoin="round"
 | 
			
		||||
                      stroke-width="2"
 | 
			
		||||
                      d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
 | 
			
		||||
                    />
 | 
			
		||||
                  </svg>
 | 
			
		||||
                  <span>创建:{{ formatDate(exam.createdTime) }}</span>
 | 
			
		||||
                </div>
 | 
			
		||||
                <div class="flex items-center gap-2">
 | 
			
		||||
                  <svg
 | 
			
		||||
                    class="w-4 h-4"
 | 
			
		||||
                    fill="none"
 | 
			
		||||
                    stroke="currentColor"
 | 
			
		||||
                    viewBox="0 0 24 24"
 | 
			
		||||
                  >
 | 
			
		||||
                    <path
 | 
			
		||||
                      stroke-linecap="round"
 | 
			
		||||
                      stroke-linejoin="round"
 | 
			
		||||
                      stroke-width="2"
 | 
			
		||||
                      d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"
 | 
			
		||||
                    />
 | 
			
		||||
                  </svg>
 | 
			
		||||
                  <span>更新:{{ formatDate(exam.updatedTime) }}</span>
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <!-- 难度书角标识 -->
 | 
			
		||||
            <div
 | 
			
		||||
              class="difficulty-corner"
 | 
			
		||||
              :class="{
 | 
			
		||||
                'difficulty-1': exam.difficulty === 1,
 | 
			
		||||
                'difficulty-2': exam.difficulty === 2,
 | 
			
		||||
                'difficulty-3': exam.difficulty === 3,
 | 
			
		||||
                'difficulty-4': exam.difficulty === 4,
 | 
			
		||||
                'difficulty-5': exam.difficulty === 5,
 | 
			
		||||
              }"
 | 
			
		||||
            ></div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <!-- 实验详情模态框 -->
 | 
			
		||||
    <ExamInfoModal
 | 
			
		||||
      v-if="selectedExam"
 | 
			
		||||
      v-model:show="showInfoModal"
 | 
			
		||||
      :selectedExam="selectedExam"
 | 
			
		||||
    />
 | 
			
		||||
 | 
			
		||||
    <!-- 创建实验模态框 -->
 | 
			
		||||
    <ExamEditModal
 | 
			
		||||
      ref="examEditModalRef"
 | 
			
		||||
      @edit-finished="handleEditExamFinished"
 | 
			
		||||
    />
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import { ref, onMounted, computed } from "vue";
 | 
			
		||||
import { useRoute } from "vue-router";
 | 
			
		||||
import { AuthManager } from "@/utils/AuthManager";
 | 
			
		||||
import { type ExamInfo } from "@/APIClient";
 | 
			
		||||
import { formatDate } from "@/utils/Common";
 | 
			
		||||
import ExamInfoModal from "./ExamInfoModal.vue";
 | 
			
		||||
import ExamEditModal from "./ExamEditModal.vue";
 | 
			
		||||
import router from "@/router";
 | 
			
		||||
import { EditIcon } from "lucide-vue-next";
 | 
			
		||||
import { templateRef } from "@vueuse/core";
 | 
			
		||||
 | 
			
		||||
// 响应式数据
 | 
			
		||||
const route = useRoute();
 | 
			
		||||
const exams = ref<ExamInfo[]>([]);
 | 
			
		||||
const selectedExam = ref<ExamInfo | null>(null);
 | 
			
		||||
const loading = ref(false);
 | 
			
		||||
const error = ref<string>("");
 | 
			
		||||
const isAdmin = ref(false);
 | 
			
		||||
 | 
			
		||||
// Modal
 | 
			
		||||
const examEditModalRef = templateRef("examEditModalRef");
 | 
			
		||||
const showInfoModal = ref(false);
 | 
			
		||||
 | 
			
		||||
async function refreshExams() {
 | 
			
		||||
  loading.value = true;
 | 
			
		||||
  error.value = "";
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    const client = AuthManager.createAuthenticatedExamClient();
 | 
			
		||||
    exams.value = await client.getExamList();
 | 
			
		||||
  } catch (err: any) {
 | 
			
		||||
    error.value = err.message || "获取实验列表失败";
 | 
			
		||||
    console.error("获取实验列表失败:", err);
 | 
			
		||||
  } finally {
 | 
			
		||||
    loading.value = false;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function viewExam(examId: string) {
 | 
			
		||||
  try {
 | 
			
		||||
    const client = AuthManager.createAuthenticatedExamClient();
 | 
			
		||||
    selectedExam.value = await client.getExam(examId);
 | 
			
		||||
    showInfoModal.value = true;
 | 
			
		||||
  } catch (err: any) {
 | 
			
		||||
    error.value = err.message || "获取实验详情失败";
 | 
			
		||||
    console.error("获取实验详情失败:", err);
 | 
			
		||||
    showInfoModal.value = false;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function handleEditExamFinished() {
 | 
			
		||||
  await refreshExams();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function handleCardClicked(event: MouseEvent, examId: string) {
 | 
			
		||||
  if (event.target instanceof HTMLButtonElement) return;
 | 
			
		||||
  await viewExam(examId);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function handleEditExamClicked(event: MouseEvent, examId: string) {
 | 
			
		||||
  examEditModalRef?.value?.editExam(examId);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 生命周期
 | 
			
		||||
onMounted(async () => {
 | 
			
		||||
  const isAuthenticated = await AuthManager.isAuthenticated();
 | 
			
		||||
  if (!isAuthenticated) {
 | 
			
		||||
    router.push("/login");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  isAdmin.value = await AuthManager.verifyAdminAuth();
 | 
			
		||||
 | 
			
		||||
  await refreshExams();
 | 
			
		||||
 | 
			
		||||
  // 处理路由参数,如果有examId则自动打开该实验的详情模态框
 | 
			
		||||
  const examId = route.query.examId as string;
 | 
			
		||||
  if (examId) {
 | 
			
		||||
    await viewExam(examId);
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style scoped>
 | 
			
		||||
/* 难度书角样式 */
 | 
			
		||||
.difficulty-corner {
 | 
			
		||||
  position: absolute;
 | 
			
		||||
  bottom: 0;
 | 
			
		||||
  left: 0;
 | 
			
		||||
  width: 0;
 | 
			
		||||
  height: 0;
 | 
			
		||||
  pointer-events: none;
 | 
			
		||||
  z-index: 10;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.difficulty-corner::before {
 | 
			
		||||
  content: "";
 | 
			
		||||
  position: absolute;
 | 
			
		||||
  bottom: 0;
 | 
			
		||||
  left: 0;
 | 
			
		||||
  width: 0;
 | 
			
		||||
  height: 0;
 | 
			
		||||
  border-style: solid;
 | 
			
		||||
  border-width: 0 48px 48px 0;
 | 
			
		||||
  transition: all 0.3s ease;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* 难度颜色渐变:绿色到红色 */
 | 
			
		||||
.difficulty-1::before {
 | 
			
		||||
  border-color: transparent transparent rgba(6, 199, 77, 0.6) transparent; /* 绿色 80% 透明度 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.difficulty-2::before {
 | 
			
		||||
  border-color: transparent transparent rgba(127, 204, 11, 0.6) transparent; /* 黄绿色 80% 透明度 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.difficulty-3::before {
 | 
			
		||||
  border-color: transparent transparent rgba(255, 191, 0, 0.6) transparent; /* 黄色 80% 透明度 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.difficulty-4::before {
 | 
			
		||||
  border-color: transparent transparent rgba(255, 106, 0, 0.6) transparent; /* 橙色 80% 透明度 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.difficulty-5::before {
 | 
			
		||||
  border-color: transparent transparent rgba(245, 35, 35, 0.6) transparent; /* 红色 80% 透明度 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* 悬停效果 */
 | 
			
		||||
.card:hover .difficulty-corner::before {
 | 
			
		||||
  filter: brightness(1.1);
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -8,20 +8,31 @@
 | 
			
		||||
          控制面板
 | 
			
		||||
        </h2>
 | 
			
		||||
 | 
			
		||||
        <div class="grid grid-cols-1  gap-4"
 | 
			
		||||
          :class="{ 'md:grid-cols-3': streamType === 'usbCamera', 'md:grid-cols-4': streamType === 'videoStream' }">
 | 
			
		||||
        <div
 | 
			
		||||
          class="grid grid-cols-1 gap-4"
 | 
			
		||||
          :class="{
 | 
			
		||||
            'md:grid-cols-3': streamType === 'usbCamera',
 | 
			
		||||
            'md:grid-cols-4': streamType === 'videoStream',
 | 
			
		||||
          }"
 | 
			
		||||
        >
 | 
			
		||||
          <!-- 服务状态 -->
 | 
			
		||||
          <div class="stats shadow">
 | 
			
		||||
            <div class="stat bg-base-100">
 | 
			
		||||
              <div class="stat-figure text-primary">
 | 
			
		||||
                <div class="badge" :class="statusInfo.isRunning ? 'badge-success' : 'badge-error'
 | 
			
		||||
                  ">
 | 
			
		||||
                  {{ statusInfo.isRunning ? "运行中" : "已停止" }}
 | 
			
		||||
                <div
 | 
			
		||||
                  class="badge"
 | 
			
		||||
                  :class="
 | 
			
		||||
                    videoStreamInfo.isRunning ? 'badge-success' : 'badge-error'
 | 
			
		||||
                  "
 | 
			
		||||
                >
 | 
			
		||||
                  {{ videoStreamInfo.isRunning ? "运行中" : "已停止" }}
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
              <div class="stat-title">服务状态</div>
 | 
			
		||||
              <div class="stat-value text-primary">HTTP</div>
 | 
			
		||||
              <div class="stat-desc">端口: {{ statusInfo.serverPort }}</div>
 | 
			
		||||
              <div class="stat-desc">
 | 
			
		||||
                端口: {{ videoStreamInfo.serverPort }}
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
 | 
			
		||||
@@ -33,9 +44,11 @@
 | 
			
		||||
              </div>
 | 
			
		||||
              <div class="stat-title">视频规格</div>
 | 
			
		||||
              <div class="stat-value text-secondary">
 | 
			
		||||
                {{ streamInfo.frameWidth }}×{{ streamInfo.frameHeight }}
 | 
			
		||||
                {{ videoStreamInfo.frameWidth }}×{{
 | 
			
		||||
                  videoStreamInfo.frameHeight
 | 
			
		||||
                }}
 | 
			
		||||
              </div>
 | 
			
		||||
              <div class="stat-desc">{{ streamInfo.frameRate }} FPS</div>
 | 
			
		||||
              <div class="stat-desc">{{ videoStreamInfo.frameRate }} FPS</div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
 | 
			
		||||
@@ -47,17 +60,31 @@
 | 
			
		||||
              </div>
 | 
			
		||||
              <div class="stat-title">分辨率设置</div>
 | 
			
		||||
              <div class="stat-value text-sm">
 | 
			
		||||
                <select class="select select-sm select-bordered max-w-xs" v-model="selectedResolution"
 | 
			
		||||
                  @change="changeResolution" :disabled="changingResolution">
 | 
			
		||||
                  <option v-for="res in supportedResolutions" :key="`${res.width}x${res.height}`" :value="res">
 | 
			
		||||
                <select
 | 
			
		||||
                  class="select select-sm select-bordered max-w-xs"
 | 
			
		||||
                  v-model="selectedResolution"
 | 
			
		||||
                  @change="changeResolution"
 | 
			
		||||
                  :disabled="changingResolution"
 | 
			
		||||
                >
 | 
			
		||||
                  <option
 | 
			
		||||
                    v-for="res in supportedResolutions"
 | 
			
		||||
                    :key="`${res.width}x${res.height}`"
 | 
			
		||||
                    :value="res"
 | 
			
		||||
                  >
 | 
			
		||||
                    {{ res.width }}×{{ res.height }}
 | 
			
		||||
                  </option>
 | 
			
		||||
                </select>
 | 
			
		||||
              </div>
 | 
			
		||||
              <div class="stat-desc">
 | 
			
		||||
                <button class="btn btn-xs btn-outline btn-info mt-1" @click="refreshResolutions"
 | 
			
		||||
                  :disabled="loadingResolutions">
 | 
			
		||||
                  <RefreshCw v-if="loadingResolutions" class="animate-spin h-3 w-3" />
 | 
			
		||||
                <button
 | 
			
		||||
                  class="btn btn-xs btn-outline btn-info mt-1"
 | 
			
		||||
                  @click="refreshResolutions"
 | 
			
		||||
                  :disabled="loadingResolutions"
 | 
			
		||||
                >
 | 
			
		||||
                  <RefreshCw
 | 
			
		||||
                    v-if="loadingResolutions"
 | 
			
		||||
                    class="animate-spin h-3 w-3"
 | 
			
		||||
                  />
 | 
			
		||||
                  {{ loadingResolutions ? "刷新中..." : "刷新" }}
 | 
			
		||||
                </button>
 | 
			
		||||
              </div>
 | 
			
		||||
@@ -72,22 +99,34 @@
 | 
			
		||||
              </div>
 | 
			
		||||
              <div class="stat-title">连接数</div>
 | 
			
		||||
              <div class="stat-value text-accent">
 | 
			
		||||
                {{ statusInfo.connectedClients }}
 | 
			
		||||
                {{ videoStreamInfo.connectedClients }}
 | 
			
		||||
              </div>
 | 
			
		||||
              <div class="stat-desc">
 | 
			
		||||
                <div class="dropdown dropdown-hover dropdown-top">
 | 
			
		||||
                  <div tabindex="0" role="button" class="text-xs underline cursor-help">
 | 
			
		||||
                  <div
 | 
			
		||||
                    tabindex="0"
 | 
			
		||||
                    role="button"
 | 
			
		||||
                    class="text-xs underline cursor-help"
 | 
			
		||||
                  >
 | 
			
		||||
                    查看客户端
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <ul tabindex="0"
 | 
			
		||||
                    class="dropdown-content z-20 menu p-2 shadow bg-base-200 rounded-box w-64 max-h-48 overflow-y-auto">
 | 
			
		||||
                    <li v-for="(client, index) in statusInfo.clientEndpoints" :key="index" class="text-xs">
 | 
			
		||||
                  <ul
 | 
			
		||||
                    tabindex="0"
 | 
			
		||||
                    class="dropdown-content z-20 menu p-2 shadow bg-base-200 rounded-box w-64 max-h-48 overflow-y-auto"
 | 
			
		||||
                  >
 | 
			
		||||
                    <li
 | 
			
		||||
                      v-for="(client, index) in videoStreamInfo.clientEndpoints"
 | 
			
		||||
                      :key="index"
 | 
			
		||||
                      class="text-xs"
 | 
			
		||||
                    >
 | 
			
		||||
                      <a class="break-all">{{ client }}</a>
 | 
			
		||||
                    </li>
 | 
			
		||||
                    <li v-if="
 | 
			
		||||
                      !statusInfo.clientEndpoints ||
 | 
			
		||||
                      statusInfo.clientEndpoints.length === 0
 | 
			
		||||
                    ">
 | 
			
		||||
                    <li
 | 
			
		||||
                      v-if="
 | 
			
		||||
                        !videoStreamInfo.clientEndpoints ||
 | 
			
		||||
                        videoStreamInfo.clientEndpoints.length === 0
 | 
			
		||||
                      "
 | 
			
		||||
                    >
 | 
			
		||||
                      <a class="text-xs opacity-50">无活跃连接</a>
 | 
			
		||||
                    </li>
 | 
			
		||||
                  </ul>
 | 
			
		||||
@@ -99,21 +138,41 @@
 | 
			
		||||
 | 
			
		||||
        <!-- 操作按钮 -->
 | 
			
		||||
        <div class="card-actions justify-end mt-4">
 | 
			
		||||
          <button class="btn btn-outline btn-warning mr-2" @click="toggleStreamType" :disabled="isSwitchingStreamType">
 | 
			
		||||
          <button
 | 
			
		||||
            class="btn btn-outline btn-warning mr-2"
 | 
			
		||||
            @click="toggleStreamType"
 | 
			
		||||
            :disabled="isSwitchingStreamType"
 | 
			
		||||
          >
 | 
			
		||||
            <SwitchCamera class="h-4 w-4 mr-2" />
 | 
			
		||||
            {{ streamType === 'usbCamera' ? '切换到视频流' : '切换到USB摄像头' }}
 | 
			
		||||
            {{
 | 
			
		||||
              streamType === "usbCamera" ? "切换到视频流" : "切换到USB摄像头"
 | 
			
		||||
            }}
 | 
			
		||||
          </button>
 | 
			
		||||
          <button v-show="streamType === 'videoStream'" class="btn btn-outline btn-primary" @click="configCamera" :disabled="configing">
 | 
			
		||||
          <button
 | 
			
		||||
            v-show="streamType === 'videoStream'"
 | 
			
		||||
            class="btn btn-outline btn-primary"
 | 
			
		||||
            @click="configCamera"
 | 
			
		||||
            :disabled="configing"
 | 
			
		||||
          >
 | 
			
		||||
            <RefreshCw v-if="configing" class="animate-spin h-4 w-4 mr-2" />
 | 
			
		||||
            <CogIcon v-else class="h-4 w-4 mr-2" />
 | 
			
		||||
            {{ configing ? "配置中..." : "配置摄像头" }}
 | 
			
		||||
          </button>
 | 
			
		||||
          <button class="btn btn-outline btn-primary" @click="refreshStatus" :disabled="loading">
 | 
			
		||||
          <button
 | 
			
		||||
            class="btn btn-outline btn-primary"
 | 
			
		||||
            @click="refreshStatus"
 | 
			
		||||
            :disabled="loading"
 | 
			
		||||
          >
 | 
			
		||||
            <RefreshCw v-if="loading" class="animate-spin h-4 w-4 mr-2" />
 | 
			
		||||
            <RefreshCw v-else class="h-4 w-4 mr-2" />
 | 
			
		||||
            {{ loading ? "刷新中..." : "刷新状态" }}
 | 
			
		||||
          </button>
 | 
			
		||||
          <button v-show="streamType === 'videoStream'" class="btn btn-primary" @click="testConnection" :disabled="testing">
 | 
			
		||||
          <button
 | 
			
		||||
            v-show="streamType === 'videoStream'"
 | 
			
		||||
            class="btn btn-primary"
 | 
			
		||||
            @click="testConnection"
 | 
			
		||||
            :disabled="testing"
 | 
			
		||||
          >
 | 
			
		||||
            <RefreshCw v-if="testing" class="animate-spin h-4 w-4 mr-2" />
 | 
			
		||||
            <TestTube v-else class="h-4 w-4 mr-2" />
 | 
			
		||||
            {{ testing ? "测试中..." : "测试连接" }}
 | 
			
		||||
@@ -130,24 +189,42 @@
 | 
			
		||||
          视频预览
 | 
			
		||||
        </h2>
 | 
			
		||||
 | 
			
		||||
        <div class="relative bg-black rounded-lg overflow-hidden cursor-pointer" :class="[
 | 
			
		||||
          focusAnimationClass,
 | 
			
		||||
          { 'cursor-not-allowed': !isPlaying || hasVideoError }
 | 
			
		||||
        ]" style="aspect-ratio: 4/3" @click="handleVideoClick">
 | 
			
		||||
        <div
 | 
			
		||||
          class="relative bg-black rounded-lg overflow-hidden cursor-pointer"
 | 
			
		||||
          :class="[
 | 
			
		||||
            focusAnimationClass,
 | 
			
		||||
            { 'cursor-not-allowed': !isPlaying || hasVideoError },
 | 
			
		||||
          ]"
 | 
			
		||||
          style="aspect-ratio: 4/3"
 | 
			
		||||
          @click="handleVideoClick"
 | 
			
		||||
        >
 | 
			
		||||
          <!-- 视频播放器 - 使用img标签直接显示MJPEG流 -->
 | 
			
		||||
          <div v-show="isPlaying" class="w-full h-full flex items-center justify-center">
 | 
			
		||||
            <img :src="currentVideoSource" alt="视频流" class="max-w-full max-h-full object-contain"
 | 
			
		||||
              @error="handleVideoError" @load="handleVideoLoad" />
 | 
			
		||||
          <div
 | 
			
		||||
            v-show="isPlaying"
 | 
			
		||||
            class="w-full h-full flex items-center justify-center"
 | 
			
		||||
          >
 | 
			
		||||
            <img
 | 
			
		||||
              :src="currentVideoSource"
 | 
			
		||||
              alt="视频流"
 | 
			
		||||
              class="max-w-full max-h-full object-contain"
 | 
			
		||||
              @error="handleVideoError"
 | 
			
		||||
              @load="handleVideoLoad"
 | 
			
		||||
            />
 | 
			
		||||
          </div>
 | 
			
		||||
 | 
			
		||||
          <!-- 对焦提示 -->
 | 
			
		||||
          <div v-if="isPlaying && !hasVideoError"
 | 
			
		||||
            class="absolute top-4 right-4 text-white text-sm bg-black bg-opacity-50 px-2 py-1 rounded">
 | 
			
		||||
            {{ isFocusing ? '对焦中...' : '点击画面对焦' }}
 | 
			
		||||
          <div
 | 
			
		||||
            v-if="isPlaying && !hasVideoError"
 | 
			
		||||
            class="absolute top-4 right-4 text-white text-sm bg-black bg-opacity-50 px-2 py-1 rounded"
 | 
			
		||||
          >
 | 
			
		||||
            {{ isFocusing ? "对焦中..." : "点击画面对焦" }}
 | 
			
		||||
          </div>
 | 
			
		||||
 | 
			
		||||
          <!-- 错误信息显示 -->
 | 
			
		||||
          <div v-if="hasVideoError" class="absolute inset-0 flex items-center justify-center bg-black bg-opacity-70">
 | 
			
		||||
          <div
 | 
			
		||||
            v-if="hasVideoError"
 | 
			
		||||
            class="absolute inset-0 flex items-center justify-center bg-black bg-opacity-70"
 | 
			
		||||
          >
 | 
			
		||||
            <div class="card bg-error text-white shadow-lg w-full max-w-lg">
 | 
			
		||||
              <div class="card-body">
 | 
			
		||||
                <h3 class="card-title flex items-center gap-2">
 | 
			
		||||
@@ -158,10 +235,13 @@
 | 
			
		||||
                <ul class="list-disc list-inside">
 | 
			
		||||
                  <li>视频流服务是否已启动</li>
 | 
			
		||||
                  <li>网络连接是否正常</li>
 | 
			
		||||
                  <li>端口 {{ statusInfo.serverPort }} 是否可访问</li>
 | 
			
		||||
                  <li>端口 {{ videoStreamInfo.serverPort }} 是否可访问</li>
 | 
			
		||||
                </ul>
 | 
			
		||||
                <div class="card-actions justify-end mt-2">
 | 
			
		||||
                  <button class="btn btn-sm btn-outline btn-primary" @click="tryReconnect">
 | 
			
		||||
                  <button
 | 
			
		||||
                    class="btn btn-sm btn-outline btn-primary"
 | 
			
		||||
                    @click="tryReconnect"
 | 
			
		||||
                  >
 | 
			
		||||
                    重试连接
 | 
			
		||||
                  </button>
 | 
			
		||||
                </div>
 | 
			
		||||
@@ -170,8 +250,10 @@
 | 
			
		||||
          </div>
 | 
			
		||||
 | 
			
		||||
          <!-- 占位符 -->
 | 
			
		||||
          <div v-show="!isPlaying && !hasVideoError"
 | 
			
		||||
            class="absolute inset-0 flex items-center justify-center text-white">
 | 
			
		||||
          <div
 | 
			
		||||
            v-show="!isPlaying && !hasVideoError"
 | 
			
		||||
            class="absolute inset-0 flex items-center justify-center text-white"
 | 
			
		||||
          >
 | 
			
		||||
            <div class="text-center">
 | 
			
		||||
              <Video class="w-16 h-16 mx-auto mb-4 opacity-50" />
 | 
			
		||||
              <p class="text-lg opacity-75">{{ videoStatus }}</p>
 | 
			
		||||
@@ -187,18 +269,25 @@
 | 
			
		||||
          <div class="text-sm text-base-content/70">
 | 
			
		||||
            流地址:
 | 
			
		||||
            <code class="bg-base-300 px-2 py-1 rounded">{{
 | 
			
		||||
              streamInfo.mjpegUrl
 | 
			
		||||
              videoStreamInfo.mjpegUrl
 | 
			
		||||
            }}</code>
 | 
			
		||||
          </div>
 | 
			
		||||
          <div class="space-x-2">
 | 
			
		||||
            <div class="dropdown dropdown-hover dropdown-top dropdown-end">
 | 
			
		||||
              <div tabindex="0" role="button" class="btn btn-sm btn-outline btn-accent">
 | 
			
		||||
              <div
 | 
			
		||||
                tabindex="0"
 | 
			
		||||
                role="button"
 | 
			
		||||
                class="btn btn-sm btn-outline btn-accent"
 | 
			
		||||
              >
 | 
			
		||||
                <MoreHorizontal class="w-4 h-4 mr-1" />
 | 
			
		||||
                更多功能
 | 
			
		||||
              </div>
 | 
			
		||||
              <ul tabindex="0" class="dropdown-content z-[1] menu p-2 shadow bg-base-200 rounded-box w-52">
 | 
			
		||||
              <ul
 | 
			
		||||
                tabindex="0"
 | 
			
		||||
                class="dropdown-content z-[1] menu p-2 shadow bg-base-200 rounded-box w-52"
 | 
			
		||||
              >
 | 
			
		||||
                <li>
 | 
			
		||||
                  <a @click="openInNewTab(streamInfo.htmlUrl)">
 | 
			
		||||
                  <a @click="openInNewTab(videoStreamInfo.htmlUrl)">
 | 
			
		||||
                    <ExternalLink class="w-4 h-4" />
 | 
			
		||||
                    在新标签打开视频页面
 | 
			
		||||
                  </a>
 | 
			
		||||
@@ -210,18 +299,26 @@
 | 
			
		||||
                  </a>
 | 
			
		||||
                </li>
 | 
			
		||||
                <li>
 | 
			
		||||
                  <a @click="copyToClipboard(streamInfo.mjpegUrl)">
 | 
			
		||||
                  <a @click="copyToClipboard(videoStreamInfo.mjpegUrl)">
 | 
			
		||||
                    <Copy class="w-4 h-4" />
 | 
			
		||||
                    复制MJPEG地址
 | 
			
		||||
                  </a>
 | 
			
		||||
                </li>
 | 
			
		||||
              </ul>
 | 
			
		||||
            </div>
 | 
			
		||||
            <button class="btn btn-success btn-sm" @click="startStream" :disabled="isPlaying">
 | 
			
		||||
            <button
 | 
			
		||||
              class="btn btn-success btn-sm"
 | 
			
		||||
              @click="startStream"
 | 
			
		||||
              :disabled="isPlaying"
 | 
			
		||||
            >
 | 
			
		||||
              <Play class="w-4 h-4 mr-1" />
 | 
			
		||||
              播放视频流
 | 
			
		||||
            </button>
 | 
			
		||||
            <button class="btn btn-error btn-sm" @click="stopStream" :disabled="!isPlaying">
 | 
			
		||||
            <button
 | 
			
		||||
              class="btn btn-error btn-sm"
 | 
			
		||||
              @click="stopStream"
 | 
			
		||||
              :disabled="!isPlaying"
 | 
			
		||||
            >
 | 
			
		||||
              <Square class="w-4 h-4 mr-1" />
 | 
			
		||||
              停止视频流
 | 
			
		||||
            </button>
 | 
			
		||||
@@ -239,11 +336,20 @@
 | 
			
		||||
        </h2>
 | 
			
		||||
 | 
			
		||||
        <div class="bg-base-300 rounded-lg p-4 h-48 overflow-y-auto">
 | 
			
		||||
          <div v-for="(log, index) in logs" :key="index" class="text-sm font-mono mb-1">
 | 
			
		||||
            <span class="text-base-content/50">[{{ formatTime(log.time) }}]</span>
 | 
			
		||||
          <div
 | 
			
		||||
            v-for="(log, index) in logs"
 | 
			
		||||
            :key="index"
 | 
			
		||||
            class="text-sm font-mono mb-1"
 | 
			
		||||
          >
 | 
			
		||||
            <span class="text-base-content/50"
 | 
			
		||||
              >[{{ formatTime(log.time) }}]</span
 | 
			
		||||
            >
 | 
			
		||||
            <span :class="getLogClass(log.level)">{{ log.message }}</span>
 | 
			
		||||
          </div>
 | 
			
		||||
          <div v-if="logs.length === 0" class="text-base-content/50 text-center py-8">
 | 
			
		||||
          <div
 | 
			
		||||
            v-if="logs.length === 0"
 | 
			
		||||
            class="text-base-content/50 text-center py-8"
 | 
			
		||||
          >
 | 
			
		||||
            暂无日志记录
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
@@ -277,8 +383,9 @@ import {
 | 
			
		||||
  MoreHorizontal,
 | 
			
		||||
  SwitchCamera,
 | 
			
		||||
} from "lucide-vue-next";
 | 
			
		||||
import { VideoStreamClient, CameraConfigRequest, ResolutionConfigRequest, StreamInfoResult } from "@/APIClient";
 | 
			
		||||
import { VideoStreamClient, ResolutionConfigRequest } from "@/APIClient";
 | 
			
		||||
import { useEquipments } from "@/stores/equipments";
 | 
			
		||||
import { AuthManager } from "@/utils/AuthManager";
 | 
			
		||||
 | 
			
		||||
const eqps = useEquipments();
 | 
			
		||||
 | 
			
		||||
@@ -291,12 +398,12 @@ const hasVideoError = ref(false);
 | 
			
		||||
const videoStatus = ref('点击"播放视频流"按钮开始查看实时视频');
 | 
			
		||||
 | 
			
		||||
// 视频流类型切换相关
 | 
			
		||||
const streamType = ref<'usbCamera' | 'videoStream'>('videoStream');
 | 
			
		||||
const streamType = ref<"usbCamera" | "videoStream">("videoStream");
 | 
			
		||||
const isSwitchingStreamType = ref(false);
 | 
			
		||||
 | 
			
		||||
// 对焦相关状态
 | 
			
		||||
const isFocusing = ref(false);
 | 
			
		||||
const focusAnimationClass = ref('');
 | 
			
		||||
const focusAnimationClass = ref("");
 | 
			
		||||
 | 
			
		||||
// 分辨率相关状态
 | 
			
		||||
const changingResolution = ref(false);
 | 
			
		||||
@@ -304,36 +411,29 @@ const loadingResolutions = ref(false);
 | 
			
		||||
const selectedResolution = ref({ width: 640, height: 480 });
 | 
			
		||||
const supportedResolutions = ref([
 | 
			
		||||
  { width: 640, height: 480 },
 | 
			
		||||
  { width: 1280, height: 720 }
 | 
			
		||||
  { width: 1280, height: 720 },
 | 
			
		||||
]);
 | 
			
		||||
 | 
			
		||||
// 数据
 | 
			
		||||
const statusInfo = ref({
 | 
			
		||||
const videoStreamInfo = ref({
 | 
			
		||||
  frameWidth: 640,
 | 
			
		||||
  frameHeight: 480,
 | 
			
		||||
  frameRate: 30,
 | 
			
		||||
  isRunning: false,
 | 
			
		||||
  serverPort: 8080,
 | 
			
		||||
  streamUrl: "",
 | 
			
		||||
  mjpegUrl: "",
 | 
			
		||||
  snapshotUrl: "",
 | 
			
		||||
  htmlUrl: "",
 | 
			
		||||
  usbCameraUrl: "",
 | 
			
		||||
  connectedClients: 0,
 | 
			
		||||
  clientEndpoints: [] as string[],
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const streamInfo = ref<StreamInfoResult>(new StreamInfoResult({
 | 
			
		||||
  frameRate: 30,
 | 
			
		||||
  frameWidth: 640,
 | 
			
		||||
  frameHeight: 480,
 | 
			
		||||
  format: "MJPEG",
 | 
			
		||||
  htmlUrl: "",
 | 
			
		||||
  mjpegUrl: "",
 | 
			
		||||
  snapshotUrl: "",
 | 
			
		||||
  usbCameraUrl: "",
 | 
			
		||||
}));
 | 
			
		||||
 | 
			
		||||
const currentVideoSource = ref("");
 | 
			
		||||
const logs = ref<Array<{ time: Date; level: string; message: string }>>([]);
 | 
			
		||||
 | 
			
		||||
// API 客户端
 | 
			
		||||
const videoClient = new VideoStreamClient();
 | 
			
		||||
const videoClient = AuthManager.createAuthenticatedVideoStreamClient();
 | 
			
		||||
 | 
			
		||||
// 添加日志
 | 
			
		||||
const addLog = (level: string, message: string) => {
 | 
			
		||||
@@ -397,16 +497,23 @@ const toggleStreamType = async () => {
 | 
			
		||||
  isSwitchingStreamType.value = true;
 | 
			
		||||
  try {
 | 
			
		||||
    // 这里假设后端有API: setStreamType(type: string)
 | 
			
		||||
    addLog('info', `正在切换视频流类型到${streamType.value === 'usbCamera' ? '视频流' : 'USB摄像头'}...`);
 | 
			
		||||
    addLog(
 | 
			
		||||
      "info",
 | 
			
		||||
      `正在切换视频流类型到${streamType.value === "usbCamera" ? "视频流" : "USB摄像头"}...`,
 | 
			
		||||
    );
 | 
			
		||||
    refreshStatus();
 | 
			
		||||
 | 
			
		||||
    // 设置视频源
 | 
			
		||||
    streamType.value = streamType.value === 'usbCamera' ? 'videoStream' : 'usbCamera';
 | 
			
		||||
    addLog('success', `已切换到${streamType.value === 'usbCamera' ? 'USB摄像头' : '视频流'}`);
 | 
			
		||||
    streamType.value =
 | 
			
		||||
      streamType.value === "usbCamera" ? "videoStream" : "usbCamera";
 | 
			
		||||
    addLog(
 | 
			
		||||
      "success",
 | 
			
		||||
      `已切换到${streamType.value === "usbCamera" ? "USB摄像头" : "视频流"}`,
 | 
			
		||||
    );
 | 
			
		||||
    stopStream();
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    addLog('error', `切换视频流类型失败: ${error}`);
 | 
			
		||||
    console.error('切换视频流类型失败:', error);
 | 
			
		||||
    addLog("error", `切换视频流类型失败: ${error}`);
 | 
			
		||||
    console.error("切换视频流类型失败:", error);
 | 
			
		||||
  } finally {
 | 
			
		||||
    isSwitchingStreamType.value = false;
 | 
			
		||||
  }
 | 
			
		||||
@@ -418,7 +525,7 @@ const takeSnapshot = async () => {
 | 
			
		||||
    addLog("info", "正在获取快照...");
 | 
			
		||||
 | 
			
		||||
    // 使用当前的快照URL
 | 
			
		||||
    const snapshotUrl = streamInfo.value.snapshotUrl;
 | 
			
		||||
    const snapshotUrl = videoStreamInfo.value.snapshotUrl;
 | 
			
		||||
    if (!snapshotUrl) {
 | 
			
		||||
      addLog("error", "快照URL不可用");
 | 
			
		||||
      return;
 | 
			
		||||
@@ -446,17 +553,14 @@ async function configCamera() {
 | 
			
		||||
  configing.value = true;
 | 
			
		||||
  try {
 | 
			
		||||
    addLog("info", "正在配置并初始化摄像头...");
 | 
			
		||||
    const boardconfig = new CameraConfigRequest({
 | 
			
		||||
      address: eqps.boardAddr,
 | 
			
		||||
      port: eqps.boardPort,
 | 
			
		||||
    });
 | 
			
		||||
    await videoClient.configureCamera(boardconfig);
 | 
			
		||||
    await videoClient.configureCamera();
 | 
			
		||||
 | 
			
		||||
    const status = await videoClient.getCameraConfig();
 | 
			
		||||
    if (status.isConfigured) {
 | 
			
		||||
    const ret = await videoClient.testConnection();
 | 
			
		||||
 | 
			
		||||
    if (ret) {
 | 
			
		||||
      addLog("success", "摄像头已配置并初始化");
 | 
			
		||||
    } else {
 | 
			
		||||
      addLog("error", "摄像头配置失败,请检查地址和端口");
 | 
			
		||||
      addLog("error", "摄像头配置失败");
 | 
			
		||||
    }
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    addLog("error", `摄像头配置失败: ${error}`);
 | 
			
		||||
@@ -473,11 +577,23 @@ const refreshStatus = async () => {
 | 
			
		||||
    addLog("info", "正在获取服务状态...");
 | 
			
		||||
 | 
			
		||||
    // 使用新的API方法名称
 | 
			
		||||
    const status = await videoClient.getStatus();
 | 
			
		||||
    statusInfo.value = status;
 | 
			
		||||
 | 
			
		||||
    const info = await videoClient.getStreamInfo();
 | 
			
		||||
    streamInfo.value = info;
 | 
			
		||||
    const serviceStatus = await videoClient.getServiceStatus();
 | 
			
		||||
    const endpointInfo = await videoClient.myEndpoint();
 | 
			
		||||
    videoStreamInfo.value = {
 | 
			
		||||
      frameWidth: endpointInfo.frameWidth,
 | 
			
		||||
      frameHeight: endpointInfo.frameHeight,
 | 
			
		||||
      frameRate: endpointInfo.frameRate,
 | 
			
		||||
      isRunning: serviceStatus.isRunning,
 | 
			
		||||
      serverPort: serviceStatus.serverPort,
 | 
			
		||||
      mjpegUrl: endpointInfo.mjpegUrl,
 | 
			
		||||
      snapshotUrl: endpointInfo.snapshotUrl,
 | 
			
		||||
      htmlUrl: endpointInfo.htmlUrl,
 | 
			
		||||
      usbCameraUrl: endpointInfo.usbCameraUrl,
 | 
			
		||||
      connectedClients: serviceStatus.connectedClientsNum,
 | 
			
		||||
      clientEndpoints: serviceStatus.clientEndpoints.map(
 | 
			
		||||
        (ep) => `${ep.boardId}`,
 | 
			
		||||
      ),
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    addLog("success", "服务状态获取成功");
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
@@ -527,9 +643,6 @@ const handleVideoLoad = () => {
 | 
			
		||||
const tryReconnect = () => {
 | 
			
		||||
  addLog("info", "尝试重新连接视频流...");
 | 
			
		||||
  hasVideoError.value = false;
 | 
			
		||||
 | 
			
		||||
  // 重新设置视频源,添加时间戳避免缓存问题
 | 
			
		||||
  currentVideoSource.value = `${streamInfo.value.mjpegUrl}?t=${new Date().getTime()}`;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 执行对焦
 | 
			
		||||
@@ -538,41 +651,41 @@ const performFocus = async () => {
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    isFocusing.value = true;
 | 
			
		||||
    focusAnimationClass.value = 'focus-starting';
 | 
			
		||||
    focusAnimationClass.value = "focus-starting";
 | 
			
		||||
    addLog("info", "正在执行自动对焦...");
 | 
			
		||||
 | 
			
		||||
    // 调用对焦API
 | 
			
		||||
    const response = await fetch('/api/VideoStream/Focus');
 | 
			
		||||
    const response = await fetch("/api/VideoStream/Focus");
 | 
			
		||||
    const result = await response.json();
 | 
			
		||||
 | 
			
		||||
    if (result.success) {
 | 
			
		||||
      // 对焦成功动画
 | 
			
		||||
      focusAnimationClass.value = 'focus-success';
 | 
			
		||||
      focusAnimationClass.value = "focus-success";
 | 
			
		||||
      addLog("success", "自动对焦执行成功");
 | 
			
		||||
 | 
			
		||||
      // 2秒后消失
 | 
			
		||||
      setTimeout(() => {
 | 
			
		||||
        focusAnimationClass.value = '';
 | 
			
		||||
        focusAnimationClass.value = "";
 | 
			
		||||
      }, 2000);
 | 
			
		||||
    } else {
 | 
			
		||||
      // 对焦失败动画
 | 
			
		||||
      focusAnimationClass.value = 'focus-error';
 | 
			
		||||
      addLog("error", `自动对焦执行失败: ${result.message || '未知错误'}`);
 | 
			
		||||
      focusAnimationClass.value = "focus-error";
 | 
			
		||||
      addLog("error", `自动对焦执行失败: ${result.message || "未知错误"}`);
 | 
			
		||||
 | 
			
		||||
      // 2秒后消失
 | 
			
		||||
      setTimeout(() => {
 | 
			
		||||
        focusAnimationClass.value = '';
 | 
			
		||||
        focusAnimationClass.value = "";
 | 
			
		||||
      }, 2000);
 | 
			
		||||
    }
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    // 对焦失败动画
 | 
			
		||||
    focusAnimationClass.value = 'focus-error';
 | 
			
		||||
    focusAnimationClass.value = "focus-error";
 | 
			
		||||
    addLog("error", `自动对焦执行失败: ${error}`);
 | 
			
		||||
    console.error("自动对焦执行失败:", error);
 | 
			
		||||
 | 
			
		||||
    // 2秒后消失
 | 
			
		||||
    setTimeout(() => {
 | 
			
		||||
      focusAnimationClass.value = '';
 | 
			
		||||
      focusAnimationClass.value = "";
 | 
			
		||||
    }, 2000);
 | 
			
		||||
  } finally {
 | 
			
		||||
    // 1秒后重置对焦状态
 | 
			
		||||
@@ -598,13 +711,16 @@ const startStream = async () => {
 | 
			
		||||
  try {
 | 
			
		||||
    addLog("info", "正在启动视频流...");
 | 
			
		||||
    videoStatus.value = "正在连接视频流...";
 | 
			
		||||
    videoClient.setEnabled(true);
 | 
			
		||||
    videoClient.setVideoStreamEnable(true);
 | 
			
		||||
 | 
			
		||||
    // 刷新状态
 | 
			
		||||
    await refreshStatus();
 | 
			
		||||
 | 
			
		||||
    // 设置视频源
 | 
			
		||||
    currentVideoSource.value = streamType.value === 'usbCamera' ? streamInfo.value.usbCameraUrl : streamInfo.value.mjpegUrl;
 | 
			
		||||
    currentVideoSource.value =
 | 
			
		||||
      streamType.value === "usbCamera"
 | 
			
		||||
        ? videoStreamInfo.value.usbCameraUrl
 | 
			
		||||
        : videoStreamInfo.value.mjpegUrl;
 | 
			
		||||
 | 
			
		||||
    // 设置播放状态
 | 
			
		||||
    isPlaying.value = true;
 | 
			
		||||
@@ -625,12 +741,18 @@ const refreshResolutions = async () => {
 | 
			
		||||
  try {
 | 
			
		||||
    addLog("info", "正在获取支持的分辨率列表...");
 | 
			
		||||
    const resolutions = await videoClient.getSupportedResolutions();
 | 
			
		||||
    supportedResolutions.value = resolutions.resolutions;
 | 
			
		||||
    supportedResolutions.value = resolutions.map((resolution) => ({
 | 
			
		||||
      width: resolution.width,
 | 
			
		||||
      height: resolution.height,
 | 
			
		||||
    }));
 | 
			
		||||
    console.log("支持的分辨率列表:", supportedResolutions.value);
 | 
			
		||||
 | 
			
		||||
    // 获取当前分辨率
 | 
			
		||||
    const currentRes = await videoClient.getCurrentResolution();
 | 
			
		||||
    selectedResolution.value = currentRes;
 | 
			
		||||
    const endpointInfo = await videoClient.myEndpoint();
 | 
			
		||||
    selectedResolution.value = {
 | 
			
		||||
      width: endpointInfo.frameWidth,
 | 
			
		||||
      height: endpointInfo.frameHeight,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    addLog("success", "分辨率列表获取成功");
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
@@ -649,18 +771,21 @@ const changeResolution = async () => {
 | 
			
		||||
  const wasPlaying = isPlaying.value;
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    addLog("info", `正在切换分辨率到 ${selectedResolution.value.width}×${selectedResolution.value.height}...`);
 | 
			
		||||
    addLog(
 | 
			
		||||
      "info",
 | 
			
		||||
      `正在切换分辨率到 ${selectedResolution.value.width}×${selectedResolution.value.height}...`,
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    // 如果正在播放,先停止视频流
 | 
			
		||||
    if (wasPlaying) {
 | 
			
		||||
      stopStream();
 | 
			
		||||
      await new Promise(resolve => setTimeout(resolve, 1000)); // 等待1秒
 | 
			
		||||
      await new Promise((resolve) => setTimeout(resolve, 1000)); // 等待1秒
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 设置新分辨率
 | 
			
		||||
    const resolutionRequest = new ResolutionConfigRequest({
 | 
			
		||||
      width: selectedResolution.value.width,
 | 
			
		||||
      height: selectedResolution.value.height
 | 
			
		||||
      height: selectedResolution.value.height,
 | 
			
		||||
    });
 | 
			
		||||
    const success = await videoClient.setResolution(resolutionRequest);
 | 
			
		||||
 | 
			
		||||
@@ -670,11 +795,14 @@ const changeResolution = async () => {
 | 
			
		||||
 | 
			
		||||
      // 如果之前在播放,重新启动视频流
 | 
			
		||||
      if (wasPlaying) {
 | 
			
		||||
        await new Promise(resolve => setTimeout(resolve, 500)); // 短暂延迟
 | 
			
		||||
        await new Promise((resolve) => setTimeout(resolve, 500)); // 短暂延迟
 | 
			
		||||
        await startStream();
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      addLog("success", `分辨率已切换到 ${selectedResolution.value.width}×${selectedResolution.value.height}`);
 | 
			
		||||
      addLog(
 | 
			
		||||
        "success",
 | 
			
		||||
        `分辨率已切换到 ${selectedResolution.value.width}×${selectedResolution.value.height}`,
 | 
			
		||||
      );
 | 
			
		||||
    } else {
 | 
			
		||||
      addLog("error", "分辨率切换失败");
 | 
			
		||||
    }
 | 
			
		||||
@@ -690,7 +818,7 @@ const changeResolution = async () => {
 | 
			
		||||
const stopStream = () => {
 | 
			
		||||
  try {
 | 
			
		||||
    addLog("info", "正在停止视频流...");
 | 
			
		||||
    videoClient.setEnabled(false);
 | 
			
		||||
    videoClient.setVideoStreamEnable(false);
 | 
			
		||||
 | 
			
		||||
    // 清除视频源
 | 
			
		||||
    currentVideoSource.value = "";
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user