3
0
刘洋 6 ماه پیش
والد
کامیت
808dc5c35c

+ 2 - 1
package.json

@@ -17,6 +17,7 @@
     "js-md5": "^0.7.3",
     "qs": "^6.11.0",
     "vue": "^2.6.11",
+    "vue-json-editor": "^1.4.3",
     "vue-json-viewer": "^2.2.22",
     "vue-ls": "^3.2.1",
     "vue-router": "^3.5.1",
@@ -49,4 +50,4 @@
       "git add"
     ]
   }
-}
+}

+ 43 - 8
src/components/UploadButton.vue

@@ -4,11 +4,16 @@
     :action="uploadUrl"
     :max-size="maxSize"
     :before-upload="handleBeforeUpload"
-    :show-file-list="false"
+    :show-file-list="showFileList"
+    :auto-upload="autoUpload"
     :disabled="disabled"
     ref="UploadComp"
+    :onChange="onChange"
+    :onRemove="onRemove"
+    :multiple="false"
+    :fileList="fileList"
   >
-    <el-button type="primary" :disabled="disabled" :loading="loading">{{
+    <el-button :type="theme" :disabled="disabled" :loading="loading">{{
       btnContent
     }}</el-button>
   </el-upload>
@@ -38,12 +43,25 @@ export default {
       type: Boolean,
       default: false,
     },
+    theme: {
+      type: String,
+      default: "primary",
+    },
+    showFileList: {
+      type: Boolean,
+      default: false,
+    },
+    autoUpload: {
+      type: Boolean,
+      default: true,
+    },
   },
   data() {
     return {
       loading: false,
       uploadUrl: "",
       res: {},
+      fileList: [],
     };
   },
   methods: {
@@ -69,12 +87,7 @@ export default {
         return Promise.reject();
       }
 
-      const md5 = await fileMD5(file);
-      this.$emit("file-change", {
-        file,
-        md5,
-      });
-      return false;
+      return true;
     },
     handleFormatError() {
       const content = "只支持文件格式为" + this.format.join("/");
@@ -95,6 +108,28 @@ export default {
       this.loading = false;
       this.$emit("upload-error", this.res);
     },
+    async onChange(file, fileList) {
+      console.log("onChange", file, fileList);
+      this.fileList = [file];
+      const md5 = await fileMD5(file.raw);
+      this.$emit("file-change", {
+        file: file.raw,
+        md5,
+      });
+    },
+    onRemove(file, fileList) {
+      console.log("remove", file, fileList);
+      if (!fileList.length) {
+        this.$emit("file-change", { file: null, md5: null });
+      }
+    },
   },
 };
 </script>
+<style lang="scss">
+.upload-button {
+  .el-upload {
+    width: auto !important;
+  }
+}
+</style>

+ 1 - 1
src/components/VersionSelect.vue

@@ -77,7 +77,7 @@ export default {
   methods: {
     async search() {
       this.optionList = [];
-      if (!this.appId) return;
+      // if (!this.appId) return;
 
       const res = await appVersionList({
         appId: this.appId,

+ 13 - 0
src/modules/admin/api.js

@@ -357,3 +357,16 @@ export const orgSetAddCount = (datas) => {
 export const promptDelete = (datas) => {
   return $postParam("/api/admin/llm/model/prompt_template/delete", datas);
 };
+
+export const authorizeFileDownload = (datas) => {
+  return $post("/api/admin/deploy/license/encrypt", datas, {
+    responseType: "blob",
+  });
+};
+export const appDeployDeviceView = (datas) => {
+  let formData = new FormData();
+  Object.keys(datas).forEach((key) => {
+    formData.append(key, datas[key]);
+  });
+  return $post("/api/admin/deploy/license/decrypt", formData);
+};

+ 13 - 0
src/modules/admin/app/AppManage.vue

@@ -22,6 +22,7 @@
             @click="toAdd"
             >新增</el-button
           >
+          <el-button v-if="showSQCS" @click="sqcs">授权测试</el-button>
         </el-form-item>
       </el-form>
     </div>
@@ -153,6 +154,8 @@
       ref="AppNginxManage"
       :app="curRow"
     ></app-nginx-manage>
+
+    <AuthorizeFileTest ref="authorizeFileTest"></AuthorizeFileTest>
   </div>
 </template>
 
@@ -165,10 +168,12 @@ import AppVersionManage from "../app-version/AppVersionManage.vue";
 import AppEnvManage from "../app-env/AppEnvManage.vue";
 import AppConfigManage from "../app-config/AppConfigManage.vue";
 import AppNginxManage from "../app-nginx/AppNginxManage.vue";
+import AuthorizeFileTest from "./AuthorizeFileTest.vue";
 
 export default {
   name: "app-manage",
   components: {
+    AuthorizeFileTest,
     ModifyApp,
     AppDeployManage,
     AppModuleManage,
@@ -177,6 +182,11 @@ export default {
     AppConfigManage,
     AppNginxManage,
   },
+  computed: {
+    showSQCS() {
+      return this.$ls.get("user")?.role?.includes("ADMIN");
+    },
+  },
   data() {
     return {
       filter: {
@@ -212,6 +222,9 @@ export default {
       this.current = page;
       this.getList();
     },
+    sqcs() {
+      this.$refs.authorizeFileTest.open();
+    },
     toAdd() {
       this.curRow = {};
       this.$refs.ModifyApp.open();

+ 183 - 0
src/modules/admin/app/AuthorizeFileTest.vue

@@ -0,0 +1,183 @@
+<template>
+  <el-dialog
+    class="page-dialog"
+    :visible.sync="modalIsShow"
+    width="800px"
+    top="10px"
+    :close-on-click-modal="false"
+    :close-on-press-escape="false"
+    append-to-body
+    title="授权测试"
+    @open="visibleChange"
+  >
+    <el-tabs v-model="tabType" type="card" v-loading="loading">
+      <el-tab-pane label="授权文件解密查看" name="tab1">
+        <div class="tab1-wrap">
+          <el-form>
+            <el-form-item>
+              <div style="display: flex; align-items: flex-start">
+                <span style="color: #f56c6c; font-size: 14px; margin-right: 4px"
+                  >*</span
+                >
+                <UploadButton
+                  theme="success"
+                  btnContent="选择文件"
+                  @file-change="getFile"
+                  showFileList
+                  :autoUpload="false"
+                  style="margin-right: 10px"
+                />
+              </div>
+            </el-form-item>
+            <el-form-item>
+              <version-select
+                v-model="version"
+                placeholder="版本号,非必填"
+              ></version-select>
+              <el-button
+                type="primary"
+                style="margin-left: 10px"
+                :disabled="!file"
+                @click="see"
+                >解密查看</el-button
+              >
+            </el-form-item>
+          </el-form>
+          <json-viewer
+            v-if="info"
+            :value="info"
+            :expand-depth="9"
+          ></json-viewer>
+        </div>
+      </el-tab-pane>
+      <el-tab-pane label="授权信息加密下载" name="tab2">
+        <vue-json-editor
+          v-model="resultInfo"
+          :showBtns="false"
+          :mode="'code'"
+          @json-change="onJsonChange"
+          @json-save="onJsonSave"
+          @has-error="onError"
+          :format="['lic']"
+        />
+        <br />
+        <div style="text-align: right">
+          <el-button type="primary" :disabled="!hasJsonFlag" @click="createFile"
+            >确定</el-button
+          >
+        </div>
+      </el-tab-pane>
+    </el-tabs>
+  </el-dialog>
+</template>
+
+<script>
+import {
+  orgQuery,
+  appDeployOrgList,
+  appDeployOrgUpdate,
+  authorizeFileDownload,
+  appDeployDeviceView,
+} from "../api";
+import vueJsonEditor from "vue-json-editor";
+import { downloadBlob } from "@/plugins/utils";
+import UploadButton from "@/components/UploadButton";
+
+export default {
+  name: "authorize-file-test",
+  components: { vueJsonEditor, UploadButton },
+  data() {
+    return {
+      modalIsShow: false,
+      tabType: "tab1",
+      info: "",
+      resultInfo: {},
+      hasJsonFlag: true,
+      loading: false,
+      version: "",
+      file: null,
+    };
+  },
+  methods: {
+    getFile(obj) {
+      this.file = obj.file;
+    },
+    see() {
+      this.loading = true;
+      appDeployDeviceView({
+        file: this.file,
+        version: this.version,
+      })
+        .then((res) => {
+          console.log("rrr", res);
+          this.info = res || "";
+        })
+        .finally(() => {
+          this.loading = false;
+        });
+    },
+    onJsonChange(value) {
+      // 实时保存
+      this.onJsonSave(value);
+    },
+    onJsonSave(value) {
+      this.resultInfo = value;
+      this.hasJsonFlag = true;
+    },
+    onError(value) {
+      this.hasJsonFlag = false;
+    },
+    // 检查json
+    async createFile() {
+      this.loading = true;
+      const res = await downloadBlob(() => {
+        return authorizeFileDownload(this.resultInfo || {});
+      }).catch(() => {});
+      this.loading = false;
+      if (res) {
+        this.$message.success("文件下载成功!");
+      } else {
+        this.$message.error("文件下载失败,请重新尝试!");
+      }
+    },
+    visibleChange() {
+      this.tabType = "tab1";
+      this.resultInfo = {};
+      this.hasJsonFlag = true;
+      this.loading = false;
+      this.version = "";
+      this.file = null;
+    },
+    cancel() {
+      this.modalIsShow = false;
+    },
+    open() {
+      this.modalIsShow = true;
+    },
+  },
+};
+</script>
+<style scoped lang="scss">
+.tab1-wrap {
+  min-height: 300px;
+}
+.tab1-form {
+  display: flex;
+  align-items: center;
+}
+</style>
+<style lang="scss">
+.jsoneditor-vue {
+  height: calc(100vh - 280px);
+  .jsoneditor-outer {
+    margin: 0;
+    padding: 0;
+  }
+}
+.jsoneditor-mode-code {
+  .jsoneditor-menu {
+    display: none;
+    // opacity: 0;
+  }
+}
+</style>