Ver Fonte

授权管理

zhangjie há 2 anos atrás
pai
commit
75442397ad

+ 19 - 0
src/api/authManagementPage.ts

@@ -0,0 +1,19 @@
+
+import { httpApp } from "@/plugins/axiosApp";
+
+export function getDeviceInfo() {
+  return httpApp.get(`/api/ess/system/auth/device/info`);
+}
+export function getAuthInfo() {
+  return httpApp.get(`/api/ess/system/auth/info`);
+}
+export function offlineAuth(params:FormData) {
+  return httpApp.post(`/api/ess/system/auth/offline`,params);
+}
+export function onlineAuth(params:{
+  accessKey:string,
+  accessSecret:string,
+  authType:string
+}) {
+  return httpApp.post(`/api/ess/system/auth/online`,params);
+}

+ 13 - 8
src/components/Layout.vue

@@ -10,31 +10,36 @@
           <template #title>基础管理</template>
           <a-menu-item v-if="store.isSuperAdmin" key="11">
             <router-link activeClass="active-route" to="/basic/rootOrg">
-              顶级机构管理
+              学校管理
             </router-link>
           </a-menu-item>
-          <a-menu-item v-if="store.isSuperAdmin" key="12">
+          <a-menu-item v-if="store.isSuperAdmin" key="16">
+            <router-link activeClass="active-route" to="/basic/auth">
+              授权管理
+            </router-link>
+          </a-menu-item>
+          <!-- <a-menu-item v-if="store.isSuperAdmin" key="12">
             <router-link activeClass="active-route" to="/basic/subOrg">
               机构管理
             </router-link>
-          </a-menu-item>
-          <a-menu-item v-if="store.isSuperAdmin" key="13">
+          </a-menu-item> -->
+          <!-- <a-menu-item v-if="store.isSuperAdmin" key="13">
             <router-link activeClass="active-route" to="/basic/role">
               角色管理
             </router-link>
-          </a-menu-item>
-          <a-menu-item v-if="store.isGreaterThanEqualOrgAdmin" key="14">
+          </a-menu-item> -->
+          <a-menu-item v-if="store.isRootOrgAdmin" key="14">
             <router-link activeClass="active-route" to="/basic/user">
               用户管理
             </router-link>
           </a-menu-item>
-          <a-menu-item key="15">
+          <a-menu-item v-if="!store.isSuperAdmin" key="15">
             <router-link activeClass="active-route" to="/basic/course">
               科目管理
             </router-link>
           </a-menu-item>
         </a-sub-menu>
-        <a-sub-menu key="sub2">
+        <a-sub-menu v-if="!store.isSuperAdmin" key="sub2">
           <template #icon> <span class="project-icon"></span> </template>
           <template #title>项目管理</template>
           <a-menu-item key="21">

+ 3 - 1
src/components/RootOrgSelect.vue

@@ -27,7 +27,9 @@ let optionList = $ref<{ id: number; name: string }[]>([]);
 
 onMounted(async () => {
   const res = await getRootOrgList({});
-  optionList = res.data.content;
+  optionList = res.data.content.filter(
+    (item) => item.id !== 1 && item.code !== "qmth"
+  );
 });
 
 const valueStr = computed(() => {

+ 151 - 0
src/features/authManagement/AuthManagement.vue

@@ -0,0 +1,151 @@
+<template>
+  <div>
+    <div class="tw-bg-white tw-p-5 tw-rounded-xl tw-mb-5">
+      <h3 class="section-title">授权信息</h3>
+      <div>
+        <a-form :labelCol="{ style: { width: '150px' } }">
+          <a-form-item label="当前信息" style="margin-bottom: 5px">
+            <span>{{ info.activation }}</span>
+          </a-form-item>
+          <a-form-item label="人数限制" style="margin-bottom: 5px">
+            <span>{{ info.maxCount }}</span>
+          </a-form-item>
+          <a-form-item label="当前人数" style="margin-bottom: 5px">
+            <span>{{ info.onlineCount }}</span>
+          </a-form-item>
+          <a-form-item label="过期时间" style="margin-bottom: 5px">
+            <span>{{ info.expire }}</span>
+          </a-form-item>
+          <a-form-item label="授权模式" style="margin-bottom: 5px">
+            <span>{{ info.type }}</span>
+          </a-form-item>
+        </a-form>
+      </div>
+    </div>
+
+    <div class="tw-bg-white tw-p-5 tw-rounded-xl">
+      <a-form :labelCol="{ style: { width: '150px' } }" style="width: 600px">
+        <a-form-item label="授权模式">
+          <a-select v-model:value="authForm.authType" style="width: 200px">
+            <a-select-option value="ONLINE">在线激活</a-select-option>
+            <a-select-option value="OFFLINE">离线激活</a-select-option>
+          </a-select>
+        </a-form-item>
+        <a-form-item
+          v-show="authForm.authType == 'ONLINE'"
+          label="密匙"
+          prop="accessKey"
+        >
+          <a-input
+            v-model:value="authForm.accessKey"
+            :maxlength="255"
+            allowClear
+          />
+        </a-form-item>
+        <a-form-item
+          v-show="authForm.authType == 'ONLINE'"
+          label="密钥"
+          prop="accessSecret"
+        >
+          <a-input
+            v-model:value="authForm.accessSecret"
+            :maxlength="255"
+            allowClear
+          />
+        </a-form-item>
+        <a-form-item
+          v-show="authForm.authType == 'OFFLINE'"
+          label="导入授权文件"
+        >
+          <a-upload
+            accept=".lic"
+            :action="uploadAction"
+            :showUploadList="false"
+            @change="uploadChange"
+          >
+            <a-button type="primary">选择文件</a-button>
+          </a-upload>
+        </a-form-item>
+        <a-form-item v-if="authForm.authType == 'OFFLINE'" label="硬件信息">
+          <a-button type="primary" @click="exportFile">导出硬件信息</a-button>
+        </a-form-item>
+        <a-button v-else type="primary" @click="submitForm">保存</a-button>
+      </a-form>
+    </div>
+  </div>
+</template>
+
+<script setup lang="ts">
+import { getAuthInfo, onlineAuth } from "../../api/authManagementPage";
+import { message } from "ant-design-vue";
+import { onMounted, reactive, ref } from "vue";
+
+interface InfoType {
+  activation: string;
+  expire: string;
+  type: string;
+  maxCount: string;
+  onlineCount: number;
+}
+
+interface AuthFormType {
+  authType: string;
+  accessKey: string;
+  accessSecret: string;
+}
+
+let info: InfoType = reactive({
+  activation: "",
+  expire: "",
+  type: "",
+  maxCount: "",
+  onlineCount: 0,
+});
+
+let authForm: AuthFormType = reactive({
+  authType: "OFFLINE",
+  accessKey: "",
+  accessSecret: "",
+});
+let uploadAction = ref("/api/ess/system/auth/offline");
+
+onMounted(async () => {
+  await fetchData();
+});
+
+async function fetchData() {
+  const res = await getAuthInfo();
+  info = res.data;
+}
+async function submitForm() {
+  await onlineAuth(authForm);
+  void message.success("操作成功");
+}
+
+// offline-auth
+interface FileItem {
+  uid: string;
+  name?: string;
+  status?: string;
+  response?: string;
+  url?: string;
+}
+interface FileInfo {
+  file: FileItem;
+  fileList: FileItem[];
+}
+const uploadChange = (info: FileInfo) => {
+  // if (info.file.status !== "uploading") {
+  //   console.log(info.file, info.fileList);
+  // }
+  if (info.file.status === "done") {
+    void message.success(`${info.file.name} 上传成功`);
+  } else if (info.file.status === "error") {
+    void message.error(`${info.file.name} 上传失败`);
+  }
+};
+
+function exportFile() {
+  window.open("/api/ess/system/auth/info");
+}
+</script>

+ 271 - 0
src/features/authManagement/lin.vue

@@ -0,0 +1,271 @@
+<template>
+  <div>
+    <div class="tw-bg-white tw-p-5 tw-rounded-xl">
+      <h3 class="section-title">授权信息</h3>
+      <div>
+        <a-form :labelCol="{ span: 4 }">
+          <a-form-item label="当前信息">
+            <span>{{ info.activation }}</span>
+          </a-form-item>
+          <a-form-item label="人数限制">
+            <span>{{ info.maxCount }}</span>
+          </a-form-item>
+          <a-form-item label="当前人数">
+            <span>{{ info.onlineCount }}</span>
+          </a-form-item>
+          <a-form-item label="过期时间">
+            <span>{{ info.expire }}</span>
+          </a-form-item>
+          <a-form-item label="授权模式">
+            <span>{{ info.type }}</span>
+          </a-form-item>
+        </a-form>
+      </div>
+    </div>
+
+    <div class="tw-bg-white tw-p-5 tw-rounded-xl">
+      <a-form
+        ref="form"
+        class="padding-tb-20 form-tight"
+        :rules="rules"
+        :model="form"
+        label-width="150px"
+      >
+        <a-form-item label="授权模式">
+          <a-select v-model="form.type" class="input">
+            <a-select-option label="在线激活" value="ONLINE"></a-select-option>
+            <a-select-option label="离线激活" value="OFFLINE"></a-select-option>
+          </a-select>
+        </a-form-item>
+        <a-form-item
+          v-show="form.type == 'ONLINE'"
+          label="密匙"
+          class="input"
+          maxlength="255"
+          prop="accessKey"
+        >
+          <a-input v-model="form.accessKey" maxlength="255" />
+        </a-form-item>
+        <a-form-item
+          v-show="form.type == 'ONLINE'"
+          label="密钥"
+          maxlength="255"
+          class="input"
+          prop="accessSecret"
+        >
+          <a-input v-model="form.accessSecret" maxlength="255" />
+        </a-form-item>
+        <a-form-item v-show="form.type == 'OFFLINE'" label="导入授权文件">
+          <a-upload
+            ref="upload"
+            class="form_left"
+            accept=".lic"
+            :action="uploadAction"
+            :headers="uploadHeaders"
+            :data="uploadData"
+            :on-success="uploadSuccess"
+            :on-error="uploadError"
+            :file-list="fileList"
+            :auto-upload="false"
+            :multiple="false"
+          >
+            <a-button
+              slot="trigger"
+              size="small"
+              type="primary"
+              icon="icon icon-search-white"
+            >
+              选择文件
+            </a-button>
+          </a-upload>
+        </a-form-item>
+        <a-form-item label=" ">
+          <el-button
+            v-show="form.type == 'OFFLINE'"
+            type="primary"
+            size="small"
+            @click="exportFile"
+            >导出硬件信息</el-button
+          >
+          <el-button type="primary" size="small" @click="submitForm"
+            >保存</el-button
+          >
+        </a-form-item>
+      </a-form>
+    </div>
+  </div>
+</template>
+
+<script>
+export default {
+  data() {
+    return {
+      uploadAction: QUESTION_API + "/system/auth/offline",
+      uploadHeaders: {},
+      uploadData: {},
+      fileList: [],
+      info: {
+        activation: "",
+        expire: "",
+        type: "",
+        maxCount: "",
+        onlineCount: 0,
+      },
+      form: {
+        type: "ONLINE",
+        accessKey: "",
+        accessSecret: "",
+      },
+      rules: {
+        accessKey: [
+          {
+            required: true,
+            message: "请输入密匙",
+            trigger: ["blur", "change"],
+          },
+        ],
+        accessSecret: [
+          {
+            required: true,
+            message: "请输入密钥",
+            trigger: ["blur", "change"],
+          },
+        ],
+      },
+      setForm: {
+        properties: {
+          LOGIN_CODE_CHECK: "false",
+          LOGIN_UD_CHECK: "false",
+          LOGIN_UD_CHECK_ONECE: "",
+        },
+      },
+    };
+  },
+  computed: {
+    ...mapState({ user: (state) => state.user }),
+  },
+  created() {
+    this.init();
+  },
+  methods: {
+    init() {
+      this.uploadHeaders = {
+        key: this.user.key,
+        token: this.user.token,
+      };
+      this.searchForm();
+    },
+    searchForm() {
+      var url = QUESTION_API + "/system/auth/info";
+      this.$httpWithMsg.get(url).then((response) => {
+        if (response.data.auth == true) {
+          this.info.activation = "已授权";
+          if (this.info.activation == "已授权" && !response.data.expireTime) {
+            this.info.expire = "不限制";
+          } else {
+            this.info.expire = response.data.expireTime;
+          }
+          if (
+            this.info.activation == "已授权" &&
+            !response.data.maxOnlineUserCount
+          ) {
+            this.info.maxCount = "不限制";
+          } else {
+            this.info.maxCount = response.data.maxOnlineUserCount;
+          }
+          this.info.onlineCount = response.data.onlineUserCount;
+          this.info.type =
+            response.data.type == "ONLINE" ? "在线激活" : "离线激活";
+        } else {
+          this.info.activation = "未授权";
+        }
+      });
+      this.initForm();
+    },
+    initForm() {
+      var url = QUESTION_API + "/org/all-sys-properties";
+      this.$httpWithMsg.get(url).then((response) => {
+        if (response.data) {
+          this.setForm.properties = response.data;
+        }
+      });
+    },
+    //提交
+    submitForm() {
+      if (this.form.type == "OFFLINE") {
+        this.submitUpload();
+      } else {
+        var url = QUESTION_API + "/system/auth/online";
+        this.$refs.form.validate((valid) => {
+          if (valid) {
+            this.$httpWithMsg.post(url, this.form).then(() => {
+              this.$notify({
+                type: "success",
+                message: "授权成功",
+              });
+              this.searchForm();
+              this.addingDialog = false;
+            });
+          } else {
+            return false;
+          }
+        });
+      }
+    },
+    submitSetForm() {
+      let url = QUESTION_API + "/org/save-sys-properties";
+      this.$httpWithMsg.put(url, this.setForm).then(() => {
+        this.$notify({
+          type: "success",
+          message: "保存成功!",
+        });
+      });
+    },
+    exportFile() {
+      window.open(
+        QUESTION_API +
+          "/system/auth/device/info?$key=" +
+          this.user.key +
+          "&$token=" +
+          this.user.token
+      );
+    },
+    submitUpload() {
+      var fileList = this.$refs.upload.uploadFiles;
+      if (fileList.length == 0) {
+        this.$notify({
+          message: "请选择授权文件",
+          type: "error",
+        });
+        return false;
+      }
+      if (fileList.length > 1) {
+        this.$notify({
+          message: "每次只能上传一个文件",
+          type: "error",
+        });
+        return false;
+      }
+      this.$refs.upload.submit();
+    },
+    uploadSuccess(response) {
+      if (!response.hasError) {
+        this.$notify({
+          message: "授权成功",
+          type: "success",
+        });
+        this.searchForm();
+      }
+    },
+    uploadError(response) {
+      var json = JSON.parse(response.message);
+      if (response.status == 500) {
+        this.$notify({
+          message: json.desc,
+          type: "error",
+        });
+      }
+    },
+  },
+};
+</script>

+ 4 - 2
src/features/rootOrg/RootOrg.vue

@@ -89,7 +89,7 @@ import { message } from "ant-design-vue";
 import { ref, onMounted, reactive } from "vue";
 
 const store = useMainStore();
-store.currentLocation = "基础管理 / 顶级机构管理";
+store.currentLocation = "基础管理 / 学校管理";
 
 let code = $ref("");
 let name = $ref("");
@@ -103,7 +103,9 @@ let totalElements = $ref(0);
 async function search() {
   const res = await getRootOrgList({ code, name, enable, pageSize, pageNo });
   // console.log(res);
-  data = res.data.content;
+  data = res.data.content.filter(
+    (item) => item.id !== 1 && item.code !== "qmth"
+  );
   pageNo = res.data.pageNo;
   pageSize = res.data.pageSize;
   totalElements = res.data.totalElements;

+ 4 - 0
src/router/index.ts

@@ -15,6 +15,10 @@ const routes = [
         path: "rootOrg",
         component: () => import("@/features/rootOrg/RootOrg.vue"),
       },
+      {
+        path: "auth",
+        component: () => import("@/features/authManagement/AuthManagement.vue"),
+      },
       {
         path: "rootOrg/edit/:orgId",
         component: () => import("@/features/rootOrg/RootOrgEdit.vue"),