123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <template>
- <div id="app">
- <keep-alive
- :include="user?.userId ? ['Home', 'ExamPaperPendingTrial'] : []"
- >
- <router-view />
- </keep-alive>
- <!-- check pwd -->
- <el-dialog
- :visible.sync="modalIsShow"
- title="安全校验 "
- width="500px"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- :show-close="false"
- append-to-body
- >
- <el-form ref="modalFormComp" :model="modalForm" :rules="rules">
- <el-form-item label="安全密码" prop="safePassword">
- <el-input
- v-model="modalForm.safePassword"
- type="password"
- class="dialog-input-width"
- auto-complete="off"
- placeholder="输入密码"
- />
- </el-form-item>
- </el-form>
- <div slot="footer">
- <el-button type="primary" @click="confirm">确定</el-button>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import timeMixin from "./mixins/timeMixin";
- import { QUESTION_API } from "@/constants/constants";
- import { questionSecurityCheckApi } from "./modules/question/api";
- import { USER_SIGNIN } from "./modules/portal/store/user";
- import { mapActions, mapMutations } from "vuex";
- import Vue from "vue";
- export default {
- name: "App",
- mixins: [timeMixin],
- created() {
- Vue.nextTick(() => {
- document
- .querySelectorAll("svg title")
- .forEach((v) => v.parentNode.removeChild(v)); //移除svg title
- });
- },
- data() {
- return {
- signalWaiting: false,
- // 安全校验
- modalIsShow: false,
- modalForm: { safePassword: "" },
- rules: {
- safePassword: [
- {
- required: true,
- message: "请输入密码",
- trigger: "change",
- },
- ],
- },
- };
- },
- computed: {
- user() {
- return this.$store.state.user;
- },
- },
- watch: {
- $route: {
- immediate: true,
- handler(val) {
- const unSignalRoutes = [
- "Root",
- "Login",
- "NotFound",
- "CardBuild",
- "LoginOpen",
- ];
- if (val.name && unSignalRoutes.includes(val.name)) {
- this.signalWaiting = false;
- this.clearSetTs();
- return;
- }
- this.onlineSignal();
- const safeRoutes = ["QuestionManage", "PaperManage"];
- if (
- this.user.safeEnable &&
- !this.user.questionUnlock &&
- val.name &&
- safeRoutes.includes(val.name)
- ) {
- this.modalIsShow = true;
- }
- },
- },
- },
- mounted() {
- this.getVersion();
- },
- beforeDestroy() {
- this.clearSetTs();
- },
- methods: {
- ...mapMutations(["setVersion"]),
- ...mapActions([USER_SIGNIN]),
- async onlineSignal() {
- if (this.signalWaiting) return;
- this.clearSetTs();
- this.signalWaiting = true;
- let result = true;
- await this.$httpWithoutBar
- .post(QUESTION_API + "/user/online/signal")
- .catch((error) => {
- result = false;
- console.log("signal error", error);
- });
- if (!result) {
- this.signalWaiting = false;
- return;
- }
- this.addSetTime(() => {
- this.signalWaiting = false;
- this.onlineSignal();
- }, 50 * 1000);
- },
- async confirm() {
- const valid = await this.$refs.modalFormComp.validate().catch(() => {});
- if (!valid) return;
- const res = await questionSecurityCheckApi(
- this.modalForm.safePassword
- ).catch(() => {});
- this.isSubmit = false;
- if (!res) return;
- this.USER_SIGNIN(Object.assign({}, this.user, { questionUnlock: true }));
- this.modalForm.safePassword = "";
- this.modalIsShow = false;
- },
- async getVersion() {
- const res = await this.$httpWithMsg
- .post(QUESTION_API + "/auth/version")
- .catch(() => {});
- if (!res) return;
- this.setVersion(res.data);
- },
- },
- };
- </script>
|