App.vue 3.3 KB

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