zhangjie 2 rokov pred
rodič
commit
e93dcf7de7
2 zmenil súbory, kde vykonal 102 pridanie a 11 odobranie
  1. 3 0
      src/modules/admin/api.js
  2. 99 11
      src/modules/admin/views/AuthSet.vue

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

@@ -35,6 +35,9 @@ export const authSelect = () => {
 export const offlineActivation = datas => {
   return $post("/api/admin/auth/offline/activation", datas);
 };
+export const onlineActivation = datas => {
+  return $post("/api/admin/auth/online/activation", datas);
+};
 export const exportDeviceInfo = () => {
   return $post(
     "/api/admin/auth/export/device/info",

+ 99 - 11
src/modules/admin/views/AuthSet.vue

@@ -1,23 +1,34 @@
 <template>
   <div class="auth-set">
     <div class="part-box part-box-pad">
-      <el-form ref="modalFormComp" :model="modalForm" label-width="120px">
+      <el-form
+        ref="modalFormComp"
+        :model="modalForm"
+        :rules="rules"
+        label-width="120px"
+      >
         <el-form-item prop="loginName" label="当前信息:">
-          {{ modalForm.expireTime === null ? "未授权" : "已授权" }}
+          {{ expireTime === null ? "未授权" : "已授权" }}
         </el-form-item>
         <el-form-item label="过期时间:">
-          <span v-if="modalForm.expireTime === -1">不过期</span>
-          <span v-else-if="modalForm.expireTime">
-            {{ modalForm.expireTime | timestampFilter }}</span
+          <span v-if="expireTime === -1">不过期</span>
+          <span v-else-if="expireTime">
+            {{ expireTime | timestampFilter }}</span
           >
           <span v-else>--</span>
         </el-form-item>
-        <el-form-item prop="mobileNumber" label="导出:">
+        <el-form-item label="授权模式:">
+          <el-select v-model="mode" @change="modeChange">
+            <el-option value="OFFLINE" label="离线激活"></el-option>
+            <el-option value="ONLINE" label="在线激活"></el-option>
+          </el-select>
+        </el-form-item>
+        <el-form-item v-if="IS_OFFLINE_MODE" prop="mobileNumber" label="导出:">
           <el-button type="primary" :loading="downloading" @click="toExport">
             硬件信息
           </el-button>
         </el-form-item>
-        <el-form-item prop="code" label="导入授权文件:">
+        <el-form-item v-if="IS_OFFLINE_MODE" prop="code" label="导入授权文件:">
           <upload-button
             btn-content="选择文件"
             btn-type="primary"
@@ -30,6 +41,29 @@
           >
           </upload-button>
         </el-form-item>
+        <el-form-item
+          v-if="!IS_OFFLINE_MODE"
+          prop="accessSecret"
+          label="密匙:"
+        >
+          <el-input
+            v-model.trim="modalForm.accessSecret"
+            placeholder="请输入密匙"
+            clearable
+          ></el-input>
+        </el-form-item>
+        <el-form-item v-if="!IS_OFFLINE_MODE" prop="accessKey" label="秘钥:">
+          <el-input
+            v-model.trim="modalForm.accessKey"
+            placeholder="请输入秘钥"
+            clearable
+          ></el-input>
+        </el-form-item>
+        <el-form-item v-if="!IS_OFFLINE_MODE">
+          <el-button type="primary" :loading="loading" @click="confirm"
+            >保存</el-button
+          >
+        </el-form-item>
       </el-form>
     </div>
   </div>
@@ -37,7 +71,7 @@
 
 <script>
 import { downloadByApi } from "@/plugins/download";
-import { exportDeviceInfo, authSelect } from "../api";
+import { exportDeviceInfo, authSelect, onlineActivation } from "../api";
 import UploadButton from "@/components/UploadButton";
 
 export default {
@@ -45,22 +79,76 @@ export default {
   components: { UploadButton },
   data() {
     return {
+      mode: "OFFLINE",
+      expireTime: "",
       modalForm: {
-        expireTime: "",
-        authFile: null
+        accessKey: "",
+        accessSecret: ""
+      },
+      rules: {
+        accessKey: [
+          {
+            required: true,
+            message: "请输入秘钥",
+            trigger: "change"
+          },
+          {
+            message: "秘钥不能超过200个字符",
+            max: 200,
+            trigger: "change"
+          }
+        ],
+        accessSecret: [
+          {
+            required: true,
+            message: "请输入密匙",
+            trigger: "change"
+          },
+          {
+            message: "密匙不能超过200个字符",
+            max: 200,
+            trigger: "change"
+          }
+        ]
       },
+      loading: false,
       downloading: false,
       // import
       uploadUrl: "/api/admin/auth/offline/activation"
     };
   },
+  computed: {
+    IS_OFFLINE_MODE() {
+      return this.mode === "OFFLINE";
+    }
+  },
   created() {
     this.search();
   },
   methods: {
     async search() {
       const res = await authSelect();
-      this.modalForm.expireTime = res;
+      this.expireTime = res;
+    },
+    modeChange() {
+      this.$nextTick(() => {
+        this.$refs.modalFormComp.clearValidate();
+      });
+    },
+    async confirm() {
+      const valid = await this.$refs.modalFormComp.validate().catch(() => {});
+      if (!valid) return;
+
+      if (this.loading) return;
+      this.loading = true;
+      let datas = { ...this.modalForm };
+      const data = await onlineActivation(datas).catch(() => {});
+      this.loading = false;
+
+      if (!data) return;
+
+      this.$message.success("操作成功!");
+      this.search();
     },
     async toExport() {
       if (this.downloading) return;