Password.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div class="ui-message ui-message-alert" v-if="show">
  3. <!-- <div class="ui-message-header">
  4. <span>{{title}}</span>
  5. </div> -->
  6. <div class="ui-message-main">
  7. <div class="ui-message-icon"></div>
  8. <div class="ui-message-content">
  9. <!-- <span>{{$t("show.password_title")}}</span> -->
  10. <input
  11. type="password"
  12. class="ui-input"
  13. maxlength="4"
  14. v-model.trim="password"
  15. :placeholder="$t('show.password_tips')"
  16. @keypress.enter="check"
  17. />
  18. <div class="ui-message-tips">
  19. <transition
  20. appear
  21. name="custom-classes-transition"
  22. enter-active-class="animated swing faster"
  23. >
  24. <div v-if="tips">{{tips}}</div>
  25. </transition>
  26. </div>
  27. </div>
  28. </div>
  29. <div class="ui-message-footer">
  30. <button class="ui-button submit" @click="check">{{okText}}</button>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import { mapGetters } from "vuex";
  36. import { PasswordDetector } from "@/core/starter";
  37. export default {
  38. name: "ui-password",
  39. data() {
  40. return {
  41. title: "提示",
  42. tips: "",
  43. okText: this.$t('common.set'),
  44. password: "",
  45. isValid: false
  46. };
  47. },
  48. computed: {
  49. ...mapGetters({
  50. metadata: "scene/metadata"
  51. }),
  52. show() {
  53. if (this.metadata.needKey == 1 && !this.isValid) {
  54. return true;
  55. }
  56. return false;
  57. }
  58. },
  59. created() {
  60. PasswordDetector.register(
  61. detector => new Promise(resolve => detector.resolve(resolve))
  62. );
  63. },
  64. methods: {
  65. check() {
  66. this.tips = "";
  67. this.$nextTick(() => {
  68. if (!this.password) {
  69. return (this.tips = this.$t("show.password_require"));
  70. }
  71. this.$api
  72. .checkPassword(this.password)
  73. .done(response => {
  74. if (response.code == 0) {
  75. this.isValid = true;
  76. PasswordDetector.valid();
  77. } else {
  78. this.tips = this.$t('tips.password_error');
  79. }
  80. })
  81. });
  82. }
  83. }
  84. };
  85. </script>
  86. <style lang="less" scoped>
  87. .ui-message-main {
  88. padding-top: 10px;
  89. .ui-message-content {
  90. input {
  91. width: 180px;
  92. color: #000;
  93. border: none;
  94. background-color: #f0faf9;
  95. }
  96. }
  97. .ui-message-icon {
  98. background: url(~@/assets/images/icons/icon-lock.png) no-repeat center
  99. center;
  100. background-size: contain;
  101. }
  102. .ui-message-tips {
  103. color: red;
  104. margin-top: 20px;
  105. height: 24px;
  106. }
  107. }
  108. .ui-message-footer .ui-button {
  109. width: 40%;
  110. }
  111. </style>