AuthorizeFileTest.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <el-dialog
  3. class="page-dialog"
  4. :visible.sync="modalIsShow"
  5. width="800px"
  6. top="10px"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. title="授权测试"
  11. @open="visibleChange"
  12. >
  13. <el-tabs v-model="tabType" type="card" v-loading="loading">
  14. <el-tab-pane label="授权文件解密查看" name="tab1">
  15. <div class="tab1-wrap">
  16. <el-form>
  17. <el-form-item>
  18. <div style="display: flex; align-items: flex-start">
  19. <span style="color: #f56c6c; font-size: 14px; margin-right: 4px"
  20. >*</span
  21. >
  22. <UploadButton
  23. theme="success"
  24. btnContent="选择文件"
  25. @file-change="getFile"
  26. showFileList
  27. :autoUpload="false"
  28. style="margin-right: 10px"
  29. />
  30. </div>
  31. </el-form-item>
  32. <el-form-item>
  33. <version-select
  34. v-model="version"
  35. placeholder="版本号,非必填"
  36. ></version-select>
  37. <el-button
  38. type="primary"
  39. style="margin-left: 10px"
  40. :disabled="!file"
  41. @click="see"
  42. >解密查看</el-button
  43. >
  44. </el-form-item>
  45. </el-form>
  46. <json-viewer
  47. v-if="info"
  48. :value="info"
  49. :expand-depth="9"
  50. ></json-viewer>
  51. </div>
  52. </el-tab-pane>
  53. <el-tab-pane label="授权信息加密下载" name="tab2">
  54. <vue-json-editor
  55. v-model="resultInfo"
  56. :showBtns="false"
  57. :mode="'code'"
  58. @json-change="onJsonChange"
  59. @json-save="onJsonSave"
  60. @has-error="onError"
  61. :format="['lic']"
  62. />
  63. <br />
  64. <div style="text-align: right">
  65. <el-button type="primary" :disabled="!hasJsonFlag" @click="createFile"
  66. >确定</el-button
  67. >
  68. </div>
  69. </el-tab-pane>
  70. </el-tabs>
  71. </el-dialog>
  72. </template>
  73. <script>
  74. import {
  75. orgQuery,
  76. appDeployOrgList,
  77. appDeployOrgUpdate,
  78. authorizeFileDownload,
  79. appDeployDeviceView,
  80. } from "../api";
  81. import vueJsonEditor from "vue-json-editor";
  82. import { downloadBlob } from "@/plugins/utils";
  83. import UploadButton from "@/components/UploadButton";
  84. export default {
  85. name: "authorize-file-test",
  86. components: { vueJsonEditor, UploadButton },
  87. data() {
  88. return {
  89. modalIsShow: false,
  90. tabType: "tab1",
  91. info: "",
  92. resultInfo: {},
  93. hasJsonFlag: true,
  94. loading: false,
  95. version: "",
  96. file: null,
  97. };
  98. },
  99. methods: {
  100. getFile(obj) {
  101. this.file = obj.file;
  102. },
  103. see() {
  104. this.loading = true;
  105. appDeployDeviceView({
  106. file: this.file,
  107. version: this.version,
  108. })
  109. .then((res) => {
  110. console.log("rrr", res);
  111. this.info = res || "";
  112. })
  113. .finally(() => {
  114. this.loading = false;
  115. });
  116. },
  117. onJsonChange(value) {
  118. // 实时保存
  119. this.onJsonSave(value);
  120. },
  121. onJsonSave(value) {
  122. this.resultInfo = value;
  123. this.hasJsonFlag = true;
  124. },
  125. onError(value) {
  126. this.hasJsonFlag = false;
  127. },
  128. // 检查json
  129. async createFile() {
  130. this.loading = true;
  131. const res = await downloadBlob(() => {
  132. return authorizeFileDownload(this.resultInfo || {});
  133. }).catch(() => {});
  134. this.loading = false;
  135. if (res) {
  136. this.$message.success("文件下载成功!");
  137. } else {
  138. this.$message.error("文件下载失败,请重新尝试!");
  139. }
  140. },
  141. visibleChange() {
  142. this.tabType = "tab1";
  143. this.resultInfo = {};
  144. this.hasJsonFlag = true;
  145. this.loading = false;
  146. this.version = "";
  147. this.file = null;
  148. },
  149. cancel() {
  150. this.modalIsShow = false;
  151. },
  152. open() {
  153. this.modalIsShow = true;
  154. },
  155. },
  156. };
  157. </script>
  158. <style scoped lang="scss">
  159. .tab1-wrap {
  160. min-height: 300px;
  161. }
  162. .tab1-form {
  163. display: flex;
  164. align-items: center;
  165. }
  166. </style>
  167. <style lang="scss">
  168. .jsoneditor-vue {
  169. height: calc(100vh - 280px);
  170. .jsoneditor-outer {
  171. margin: 0;
  172. padding: 0;
  173. }
  174. }
  175. .jsoneditor-mode-code {
  176. .jsoneditor-menu {
  177. display: none;
  178. // opacity: 0;
  179. }
  180. }
  181. </style>