Explorar o código

feat: 工具管理

zhangjie hai 6 meses
pai
achega
e09d361ed2

+ 6 - 0
src/constants/enumerate.js

@@ -434,3 +434,9 @@ export const MARK_TASK_STATUS = {
   ARBITRATED: "已仲裁",
   PROBLEM: "问题卷",
 };
+
+// admin
+export const TOOL_TYPE = {
+  TEACHCLOUD_CLIENT: "知学知考客户端",
+  PICTURE_DOWNLOAD: "图片下载工具",
+};

+ 4 - 7
src/modules/admin/api.js

@@ -156,8 +156,8 @@ export const schoolSetCourseTargetSave = (datas) => {
 };
 
 // package-manage
-export const packageInfo = () => {
-  return $postParam("/api/admin/sys/client/package/external", {});
+export const packageInfo = (datas) => {
+  return $postParam("/api/admin/sys/client/package/external", datas);
 };
 export const uploadPackage = (datas, config = {}) => {
   return $post("/api/admin/sys/client/package/upload", datas, config);
@@ -165,10 +165,7 @@ export const uploadPackage = (datas, config = {}) => {
 
 // tool-manage
 export const toolInfo = () => {
-  return $postParam("/api/admin/sys/tools/external", {
-    type: "PICTURE_DOWNLOAD",
+  return $postParam("/api/admin/sys/client/package/external", {
+    toolType: "PICTURE_DOWNLOAD",
   });
 };
-export const uploadTool = (datas, config = {}) => {
-  return $post("/api/admin/sys/tools/upload", datas, config);
-};

+ 3 - 1
src/modules/admin/views/PackageManage.vue

@@ -107,6 +107,7 @@ export default {
         install: {},
         upgrade: {},
       },
+      toolType: "TEACHCLOUD_CLIENT",
       fileType: "INSTALL",
       result: {
         message: "",
@@ -152,7 +153,7 @@ export default {
       this.uploadController = null;
     },
     async getInfo() {
-      const res = await packageInfo();
+      const res = await packageInfo({ toolType: this.toolType });
       this.info = res || {};
     },
     handleFileChange(file) {
@@ -165,6 +166,7 @@ export default {
       this.uploadController = new AbortController();
       this.loading = true;
       let formData = new FormData();
+      formData.append("toolType", this.toolType);
       formData.append("type", this.fileType);
       formData.append("file", options.file);
       const md5 = await fileMD5(options.file);

+ 5 - 3
src/modules/admin/views/ToolManage.vue

@@ -96,7 +96,7 @@
 </template>
 
 <script>
-import { toolInfo, uploadTool } from "../api";
+import { packageInfo, uploadPackage } from "../api";
 import { fileMD5 } from "@/plugins/md5";
 
 export default {
@@ -107,6 +107,7 @@ export default {
         install: {},
         upgrade: {},
       },
+      toolType: "PICTURE_DOWNLOAD",
       fileType: "INSTALL",
       result: {
         message: "",
@@ -152,7 +153,7 @@ export default {
       this.uploadController = null;
     },
     async getInfo() {
-      const res = await toolInfo();
+      const res = await packageInfo({ toolType: this.toolType });
       this.info = res || {};
     },
     handleFileChange(file) {
@@ -165,12 +166,13 @@ export default {
       this.uploadController = new AbortController();
       this.loading = true;
       let formData = new FormData();
+      formData.append("toolType", this.toolType);
       formData.append("type", this.fileType);
       formData.append("file", options.file);
       const md5 = await fileMD5(options.file);
       formData.append("md5", md5);
 
-      return uploadTool(formData, {
+      return uploadPackage(formData, {
         timeout: 60 * 60 * 1000,
         signal: this.uploadController.signal,
         onUploadProgress: ({ loaded, total }) => {

+ 2 - 9
src/modules/course/components/CourseDocumentDetail.vue

@@ -234,7 +234,7 @@ export default {
   methods: {
     async getToolInfo() {
       const res = await toolInfo();
-      const info = res || {};
+      const info = res.install || {};
       this.toolUrl = info.url || "";
     },
     cancel() {
@@ -358,14 +358,7 @@ export default {
         "http://test-school-1.teach-cloud-test.com"
       );
 
-      openApp(url, () => {
-        this.$notify.error({
-          title: "错误提示",
-          message: "请点击底部链接,先下载工具!",
-          duration: 5000,
-          showClose: true,
-        });
-      });
+      openApp(url);
     },
     toAdd() {
       this.$refs.AddDocumentDialog.open();

+ 17 - 2
src/plugins/imageExport.js

@@ -29,10 +29,22 @@ export function getDownloadURLScheme(downloadSet = null, apiUrl = null) {
       actionSession: `${Date.now()}${randomCode()}`,
     })
   );
-  return `trd://download?q=${key}`;
+  return `trd://download/?q=${key}`;
 }
 
-export function openApp(scheme, fallback, timeout = 2000) {
+export function openApp(scheme) {
+  // 创建 iframe 来尝试调用 URL Scheme
+  const iframe = document.createElement("iframe");
+  iframe.style.display = "none";
+  iframe.src = scheme;
+  document.body.appendChild(iframe);
+
+  setTimeout(() => {
+    document.body.removeChild(iframe);
+  }, 1000);
+}
+
+export function openAppWithCallback(scheme, timeout = 2000, fallback) {
   let isPageHidden = false;
 
   const onVisibilityChange = () => {
@@ -49,6 +61,9 @@ export function openApp(scheme, fallback, timeout = 2000) {
   iframe.src = scheme;
   document.body.appendChild(iframe);
 
+  // 这里是比较鸡肋的
+  // 在打开scheme,部分浏览器会提示用户是否打开,如果用户不点击确认,就会导致误判
+
   setTimeout(() => {
     document.removeEventListener("visibilitychange", onVisibilityChange);
     document.body.removeChild(iframe);