index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view>
  3. <nut-dialog
  4. title="请输入密码"
  5. :visible="dialogShow"
  6. @ok-btn-click="sureClick"
  7. @cancel-btn-click="dialogShow = false"
  8. @close="close"
  9. :noFooter="noButton"
  10. >
  11. <view class="nut-shortpsd-subtitle">您使用了虚拟资产,请进行验证</view>
  12. <view class="nut-input-w">
  13. <input
  14. ref="realpwd"
  15. class="nut-input-real"
  16. type="number"
  17. maxlength="6"
  18. v-model="realInput"
  19. @input="changeValue"
  20. />
  21. <view class="nut-shortpsd-fake" @click="focus">
  22. <view class="nut-shortpsd-li"
  23. ><view class="nut-shortpsd-icon" v-if="realInput.length > 0"></view
  24. ></view>
  25. <view class="nut-shortpsd-li"
  26. ><view class="nut-shortpsd-icon" v-if="realInput.length > 1"></view
  27. ></view>
  28. <view class="nut-shortpsd-li"
  29. ><view class="nut-shortpsd-icon" v-if="realInput.length > 2"></view
  30. ></view>
  31. <view class="nut-shortpsd-li"
  32. ><view class="nut-shortpsd-icon" v-if="realInput.length > 3"></view
  33. ></view>
  34. <view v-if="length >= 5" class="nut-shortpsd-li"
  35. ><view class="nut-shortpsd-icon" v-if="realInput.length > 4"></view
  36. ></view>
  37. <view v-if="length == 6" class="nut-shortpsd-li"
  38. ><view class="nut-shortpsd-icon" v-if="realInput.length > 5"></view
  39. ></view>
  40. </view>
  41. </view>
  42. <view class="nut-shortpsd-message">
  43. <view class="nut-shortpsd-error">{{ errorMsg }}</view>
  44. <view class="nut-shortpsd-forget">
  45. <nut-icon class="icon" size="11px" name="tips"></nut-icon
  46. >忘记密码</view
  47. >
  48. </view>
  49. </nut-dialog>
  50. </view>
  51. </template>
  52. <script lang="ts">
  53. import { ref, onMounted, watch, reactive, watchEffect } from 'vue';
  54. import { createComponent } from '@/utils/create';
  55. const { create } = createComponent('shortpassword');
  56. export default create({
  57. props: {
  58. isVisible: {
  59. type: Boolean,
  60. default: false
  61. },
  62. value: {
  63. type: String,
  64. default: ''
  65. },
  66. errorMsg: {
  67. type: String,
  68. default: ''
  69. },
  70. noButton: {
  71. type: Boolean,
  72. default: true
  73. },
  74. length: {
  75. type: String || Number,
  76. default: 6
  77. }
  78. },
  79. setup(props, { emit }) {
  80. const dialogShow = ref(false);
  81. const realInput = ref(props.value);
  82. const realpwd = ref();
  83. // 方法
  84. function sureClick() {
  85. emit('sureClick');
  86. }
  87. function focus() {
  88. realpwd.value.focus();
  89. }
  90. function changeValue(e: Event) {
  91. const input = e.target as HTMLInputElement;
  92. let val = input.value;
  93. if (val.length > Number(props.length)) {
  94. val = val.slice(0, Number(props.length));
  95. }
  96. if (realInput.value.length > Number(props.length)) {
  97. realInput.value = realInput.value.slice(0, Number(props.length));
  98. }
  99. emit('input', val);
  100. emit('update:value', val);
  101. }
  102. function close() {
  103. emit('update:isVisible', false);
  104. }
  105. watch(
  106. () => props.isVisible,
  107. val => {
  108. if (val) {
  109. dialogShow.value = true;
  110. } else {
  111. dialogShow.value = false;
  112. }
  113. }
  114. );
  115. return {
  116. dialogShow,
  117. sureClick,
  118. realInput,
  119. realpwd,
  120. focus,
  121. changeValue,
  122. close
  123. };
  124. }
  125. });
  126. </script>
  127. <style lang="scss">
  128. @import 'index.scss';
  129. </style>