Quellcode durchsuchen

feat: 清空数据三次确认

zhangjie vor 11 Monaten
Ursprung
Commit
6c4a55048a

+ 141 - 0
src/modules/admin/components/school/DataClearTipsDialog.vue

@@ -0,0 +1,141 @@
+<template>
+  <el-dialog
+    class="danger-tips-dialog"
+    :visible.sync="modalIsShow"
+    width="400px"
+    :close-on-click-modal="false"
+    :close-on-press-escape="false"
+    :show-close="false"
+    append-to-body
+    destroy-on-close
+    @opened="visibleChange"
+  >
+    <p class="tips-info tips-error mb-2">确定要清除当前学校的基础数据集吗?</p>
+    <el-form
+      ref="modalFormComp"
+      :model="modalForm"
+      :rules="rules"
+      label-width="80px"
+    >
+      <el-form-item prop="loginName" label="用户名:">
+        <el-input
+          v-model.trim="modalForm.loginName"
+          placeholder="请输入你的用户名"
+          clearable
+        >
+        </el-input>
+      </el-form-item>
+      <el-form-item prop="password" label="密码:">
+        <el-input
+          v-model.trim="modalForm.password"
+          type="password"
+          placeholder="请输入你的密码"
+          show-password
+          clearable
+        >
+        </el-input>
+      </el-form-item>
+    </el-form>
+
+    <template slot="footer">
+      <template v-if="confirmTime % 2">
+        <el-button type="primary" :loading="loading" @click="submit"
+          >确认</el-button
+        >
+        <el-button @click="cancel">取消</el-button>
+      </template>
+      <template v-else>
+        <el-button @click="cancel">取消</el-button>
+        <el-button type="primary" :loading="loading" @click="submit"
+          >确认</el-button
+        >
+      </template>
+    </template>
+  </el-dialog>
+</template>
+
+<script>
+import { schoolSetDataBackup } from "../../api";
+import { MD5 } from "@/plugins/md5";
+
+export default {
+  name: "data-clear-tips-dialog",
+  props: {
+    school: {
+      type: Object,
+      default() {
+        return {};
+      },
+    },
+  },
+  data() {
+    return {
+      modalIsShow: false,
+      loading: false,
+      confirmTime: 0,
+      maxConfirmTime: 3,
+      modalForm: { loginName: "", password: "" },
+      rules: {
+        password: [
+          {
+            required: true,
+            message: "请输入密码",
+            trigger: "change",
+          },
+        ],
+        loginName: [
+          {
+            required: true,
+            message: "请输入用户名",
+            trigger: "change",
+          },
+        ],
+      },
+    };
+  },
+  methods: {
+    visibleChange() {
+      this.modalForm = { loginName: "", password: "" };
+      this.confirmTime = 0;
+
+      this.$nextTick(() => {
+        this.$refs.modalFormComp.resetFields();
+      });
+    },
+    cancel() {
+      this.modalIsShow = false;
+    },
+    open() {
+      this.modalIsShow = true;
+    },
+    async submit() {
+      const valid = await this.$refs.modalFormComp.validate().catch(() => {});
+      if (!valid) return;
+
+      const user = this.$ls.get("user", {});
+      if (
+        this.modalForm.loginName !== user.loginName ||
+        MD5(this.modalForm.password) !== user.pwd
+      ) {
+        this.$message.error("用户名或密码输入错误!");
+        return;
+      }
+
+      this.confirmTime += 1;
+      if (this.confirmTime < this.maxConfirmTime) {
+        this.modalForm = { loginName: "", password: "" };
+        return;
+      }
+
+      if (this.loading) return;
+      this.loading = true;
+      const res = await schoolSetDataBackup(this.school.id).catch(() => {});
+      this.loading = false;
+      if (!res) return;
+
+      this.$message.success("操作成功!");
+      this.cancel();
+    },
+  },
+};
+</script>

+ 14 - 33
src/modules/admin/components/school/SchoolSetData.vue

@@ -1,19 +1,26 @@
 <template>
   <div class="school-set-data">
-    <el-button type="primary" :loading="loading" @click="confirm"
-      >清除基础数据</el-button
-    >
-    <p class="tips-info tips-error">
+    <el-button type="primary" @click="toClear">清除基础数据</el-button>
+    <p class="tips-info tips-error mt-1">
       注意:执行该操作,会将该单位下配置的基础数据全部清除,进入初始状态,请谨慎操作,该操作不可恢复!
     </p>
+
+    <!-- DataClearTipsDialog -->
+    <data-clear-tips-dialog
+      ref="DataClearTipsDialog"
+      :school="school"
+    ></data-clear-tips-dialog>
   </div>
 </template>
 
 <script>
-import { schoolSetDataBackup } from "../../api";
+import DataClearTipsDialog from "./DataClearTipsDialog.vue";
 
 export default {
   name: "school-set-data",
+  components: {
+    DataClearTipsDialog,
+  },
   props: {
     school: {
       type: Object,
@@ -28,34 +35,8 @@ export default {
     };
   },
   methods: {
-    async confirm() {
-      let confirm = await this.$confirm(
-        `确定要清除当前学校的基础数据集吗?`,
-        "提示",
-        {
-          type: "warning",
-        }
-      ).catch(() => {});
-      if (confirm !== "confirm") return;
-
-      confirm = await this.$confirm(
-        `确定要清除当前学校的基础数据集吗?`,
-        "提示",
-        {
-          type: "warning",
-        }
-      ).catch(() => {});
-      if (confirm !== "confirm") return;
-
-      if (this.loading) return;
-      this.loading = true;
-
-      const res = await schoolSetDataBackup(this.school.id).catch(() => {});
-      this.loading = false;
-
-      if (!res) return;
-
-      this.$message.success("操作成功!");
+    toClear() {
+      this.$refs.DataClearTipsDialog.open();
     },
   },
 };

+ 12 - 3
src/modules/login/views/Login.vue

@@ -128,7 +128,8 @@
 import { phone, smscode } from "@/plugins/formRules";
 import { login, getSmsCode, getSchoolInfo, getAccountSmsCode } from "../api";
 import { Base64 } from "@/plugins/crypto";
-import ResetPwd from "@/modules/base/components/ResetPwd";
+import { MD5 } from "@/plugins/md5";
+import ResetPwd from "@/modules/base/components/ResetPwd.vue";
 import { getOrgCode } from "@/constants/app";
 import fetchSmsMixins from "../fetchSmsMixins";
 
@@ -256,7 +257,11 @@ export default {
           this.$ls.set("schoolName", curSchool.name, this.GLOBAL.authTimeout);
         }
       }
-      this.$ls.set("user", data, this.GLOBAL.authTimeout);
+      this.$ls.set(
+        "user",
+        { ...data, pwd: MD5(this.loginModel.password) },
+        this.GLOBAL.authTimeout
+      );
 
       this.$ls.set("token", data.accessToken, this.GLOBAL.authTimeout);
 
@@ -298,7 +303,11 @@ export default {
           this.$ls.set("schoolName", curSchool.name, this.GLOBAL.authTimeout);
         }
       }
-      this.$ls.set("user", data, this.GLOBAL.authTimeout);
+      this.$ls.set(
+        "user",
+        { ...data, pwd: MD5(this.loginModel.password) },
+        this.GLOBAL.authTimeout
+      );
 
       this.$ls.set("token", data.accessToken, this.GLOBAL.authTimeout);
 

+ 6 - 2
src/modules/mark/views/MarkSetting.vue

@@ -185,7 +185,7 @@
       :download-handle="() => downloadTemplate('subjectiveStruct')"
       download-filename="主观题导入模板.xlsx"
       :format="['xls', 'xlsx']"
-      @upload-success="getList"
+      @upload-success="uploadSuccess"
     >
     </import-file>
     <!-- 客观题导入 -->
@@ -198,7 +198,7 @@
       :download-handle="() => downloadTemplate('objectiveStruct')"
       download-filename="客观题导入模板.xlsx"
       :format="['xls', 'xlsx']"
-      @upload-success="getList"
+      @upload-success="uploadSuccess"
     >
     </import-file>
     <!-- data-task-dialog -->
@@ -302,6 +302,10 @@ export default {
     toImportObjective() {
       this.$refs.ImportObjectiveFile.open();
     },
+    uploadSuccess() {
+      this.$message.success("文件上传成功,后台正在导入!");
+      this.getList();
+    },
     toDataTask(type) {
       this.questionType = type;
       this.$refs.DataTaskDialog.open();