App.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <div id="app">
  3. <keep-alive
  4. :include="user?.userId ? ['Home', 'ExamPaperPendingTrial'] : []"
  5. >
  6. <router-view />
  7. </keep-alive>
  8. <!-- check pwd -->
  9. <el-dialog
  10. :visible.sync="modalIsShow"
  11. title="安全校验 "
  12. width="500px"
  13. :close-on-click-modal="false"
  14. :close-on-press-escape="false"
  15. :show-close="false"
  16. append-to-body
  17. >
  18. <el-form ref="modalFormComp" :model="modalForm" :rules="rules">
  19. <el-form-item label="安全密码" prop="safePassword">
  20. <el-input
  21. v-model="modalForm.safePassword"
  22. type="password"
  23. class="dialog-input-width"
  24. auto-complete="off"
  25. placeholder="输入密码"
  26. />
  27. </el-form-item>
  28. </el-form>
  29. <div slot="footer">
  30. <el-button type="primary" @click="confirm">确定</el-button>
  31. </div>
  32. </el-dialog>
  33. </div>
  34. </template>
  35. <script>
  36. import timeMixin from "./mixins/timeMixin";
  37. import { QUESTION_API } from "@/constants/constants";
  38. import { questionSecurityCheckApi } from "./modules/question/api";
  39. import { USER_SIGNIN } from "./modules/portal/store/user";
  40. import { mapActions, mapMutations } from "vuex";
  41. import Vue from "vue";
  42. export default {
  43. name: "App",
  44. mixins: [timeMixin],
  45. created() {
  46. Vue.nextTick(() => {
  47. document
  48. .querySelectorAll("svg title")
  49. .forEach((v) => v.parentNode.removeChild(v)); //移除svg title
  50. });
  51. },
  52. data() {
  53. return {
  54. signalWaiting: false,
  55. // 安全校验
  56. modalIsShow: false,
  57. modalForm: { safePassword: "" },
  58. rules: {
  59. safePassword: [
  60. {
  61. required: true,
  62. message: "请输入密码",
  63. trigger: "change",
  64. },
  65. ],
  66. },
  67. };
  68. },
  69. computed: {
  70. user() {
  71. return this.$store.state.user;
  72. },
  73. },
  74. watch: {
  75. $route: {
  76. immediate: true,
  77. handler(val) {
  78. const unSignalRoutes = [
  79. "Root",
  80. "Login",
  81. "NotFound",
  82. "CardBuild",
  83. "LoginOpen",
  84. ];
  85. if (val.name && unSignalRoutes.includes(val.name)) {
  86. this.signalWaiting = false;
  87. this.clearSetTs();
  88. return;
  89. }
  90. this.onlineSignal();
  91. const safeRoutes = ["QuestionManage", "PaperManage"];
  92. if (
  93. this.user.safeEnable &&
  94. !this.user.questionUnlock &&
  95. val.name &&
  96. safeRoutes.includes(val.name)
  97. ) {
  98. this.modalIsShow = true;
  99. }
  100. },
  101. },
  102. },
  103. mounted() {
  104. this.getVersion();
  105. },
  106. beforeDestroy() {
  107. this.clearSetTs();
  108. },
  109. methods: {
  110. ...mapMutations(["setVersion"]),
  111. ...mapActions([USER_SIGNIN]),
  112. async onlineSignal() {
  113. if (this.signalWaiting) return;
  114. this.clearSetTs();
  115. this.signalWaiting = true;
  116. let result = true;
  117. await this.$httpWithoutBar
  118. .post(QUESTION_API + "/user/online/signal")
  119. .catch((error) => {
  120. result = false;
  121. console.log("signal error", error);
  122. });
  123. if (!result) {
  124. this.signalWaiting = false;
  125. return;
  126. }
  127. this.addSetTime(() => {
  128. this.signalWaiting = false;
  129. this.onlineSignal();
  130. }, 50 * 1000);
  131. },
  132. async confirm() {
  133. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  134. if (!valid) return;
  135. const res = await questionSecurityCheckApi(
  136. this.modalForm.safePassword
  137. ).catch(() => {});
  138. this.isSubmit = false;
  139. if (!res) return;
  140. this.USER_SIGNIN(Object.assign({}, this.user, { questionUnlock: true }));
  141. this.modalForm.safePassword = "";
  142. this.modalIsShow = false;
  143. },
  144. async getVersion() {
  145. const res = await this.$httpWithMsg
  146. .post(QUESTION_API + "/auth/version")
  147. .catch(() => {});
  148. if (!res) return;
  149. this.setVersion(res.data);
  150. },
  151. },
  152. };
  153. </script>