VerifyCode.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div style="display: flex; justify-content: space-between;">
  3. <img
  4. v-if="init || base64"
  5. style="display: inline-block; width: 100px; height: 40px;"
  6. :src="base64"
  7. />
  8. <span
  9. v-else
  10. style="display: inline-block; width: 100px; height: 40px; line-height: 40px"
  11. >等待获取图片</span
  12. >
  13. <span style="font-size: 20px; padding: 1px;">=</span>
  14. <input
  15. v-model="result"
  16. style="width: 40px; border: 1px solid #dcdee2; padding: 2px; text-align: center;"
  17. type="number"
  18. step="any"
  19. class="input-number"
  20. @input="notify"
  21. @focus="focused = true"
  22. @focusout="changeFocus"
  23. />
  24. <i-button
  25. class="qm-primary-button"
  26. style="height: 40px; width: 60px; padding: 0"
  27. :disabled="disabled"
  28. @click="getVerifyCode"
  29. >
  30. 看不清
  31. </i-button>
  32. </div>
  33. </template>
  34. <script>
  35. import { mapState as globalMapState } from "vuex";
  36. export default {
  37. name: "VerifyCode",
  38. props: {
  39. init: { type: Boolean, default: false },
  40. // rootOrgId: { type: Number, default: 0 },
  41. accountValue: { type: String, default: "" },
  42. },
  43. data() {
  44. return {
  45. clicked: false,
  46. focused: false,
  47. base64: "",
  48. uuid: "",
  49. result: "",
  50. };
  51. },
  52. computed: {
  53. ...globalMapState(["QECSConfig"]),
  54. disabled() {
  55. if (this.focused) {
  56. return false; // 优先处理focus的情况
  57. }
  58. return !this.init || this.clicked;
  59. },
  60. },
  61. watch: {
  62. init(val) {
  63. if (val) {
  64. this.getVerifyCode();
  65. }
  66. },
  67. },
  68. beforeDestroy() {
  69. clearTimeout(this.clickedTimeout);
  70. },
  71. methods: {
  72. changeFocus() {
  73. window.setTimeout(() => (this.focused = false), 300);
  74. },
  75. async getVerifyCode() {
  76. // console.log(this.accountValue);
  77. this.result = "";
  78. if (!this.accountValue) {
  79. this.$Message.warning({
  80. content: "请先填写登录账号",
  81. duration: 5,
  82. closable: true,
  83. });
  84. return;
  85. }
  86. this.clicked = true;
  87. clearTimeout(this.clickedTimeout);
  88. this.clickedTimeout = setTimeout(() => {
  89. this.clicked = false;
  90. }, 3000);
  91. // const params = new URLSearchParams();
  92. // params.append("rootOrgId", this.QECSConfig.ROOT_ORG_ID);
  93. // params.append("accountValue", this.accountValue);
  94. // const res = await this.$http.get(
  95. // "/api/ecs_core/verifyCode/generate?" + params
  96. // );
  97. const params = new URLSearchParams();
  98. params.append("rootOrgId", this.QECSConfig.ROOT_ORG_ID);
  99. params.append("accountValue", this.accountValue);
  100. const res = await this.$http.post(
  101. "/api/ecs_core/verifyCode/generate",
  102. params
  103. );
  104. // console.log(res);
  105. this.uuid = res.data.slice(0, 32);
  106. this.base64 = "data:image/jpeg;base64," + res.data.slice(32);
  107. this.$emit("calcVerify", {
  108. uuid: this.uuid,
  109. verifyCode: this.result,
  110. });
  111. },
  112. notify() {
  113. const p = window.parseInt(this.result);
  114. this.result = window.isNaN(p) ? "" : p;
  115. this.$emit("calcVerify", {
  116. uuid: this.uuid,
  117. verifyCode: this.result,
  118. });
  119. },
  120. },
  121. };
  122. </script>
  123. <style>
  124. .input-number::-webkit-inner-spin-button,
  125. .input-number::-webkit-inner-spin-button {
  126. -webkit-appearance: none;
  127. }
  128. </style>