index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view>
  3. <nut-dialog
  4. :title="title"
  5. :visible="isVisible"
  6. @ok-btn-click="sureClick"
  7. @cancel-btn-click="close"
  8. @close="close"
  9. :no-footer="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
  23. class="nut-shortpsd-li"
  24. v-for="(sublen, index) in new Array(comLen)"
  25. v-bind:key="index"
  26. >
  27. <view
  28. class="nut-shortpsd-icon"
  29. v-if="realInput.length > index"
  30. ></view>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="nut-shortpsd-message">
  35. <view class="nut-shortpsd-error">{{ errorMsg }}</view>
  36. <view class="nut-shortpsd-forget" v-if="showPasswordTips">
  37. <nut-icon class="icon" size="11px" name="tips"></nut-icon>
  38. <view @click="link">忘记密码</view>
  39. </view>
  40. </view>
  41. </nut-dialog>
  42. </view>
  43. </template>
  44. <script lang="ts">
  45. import { ref, watch, computed } from 'vue';
  46. import { createComponent } from '@/utils/create';
  47. const { create } = createComponent('shortpassword');
  48. import Icon from '@/packages/icon/index.vue';
  49. export default create({
  50. children: [Icon],
  51. props: {
  52. title: {
  53. type: String,
  54. default: '请输入密码'
  55. },
  56. isVisible: {
  57. type: Boolean,
  58. default: false
  59. },
  60. value: {
  61. type: String,
  62. default: ''
  63. },
  64. errorMsg: {
  65. type: String,
  66. default: ''
  67. },
  68. noButton: {
  69. type: Boolean,
  70. default: true
  71. },
  72. length: {
  73. type: [String, Number], //4~6
  74. default: 6
  75. },
  76. showPasswordTips: {
  77. type: Boolean,
  78. default: true
  79. },
  80. link: {
  81. type: String,
  82. default: ''
  83. }
  84. },
  85. emits: [
  86. 'sure-click',
  87. 'update:value',
  88. 'update:is-visible',
  89. 'complete',
  90. 'input'
  91. ],
  92. setup(props, { emit }) {
  93. const realInput = ref(props.value);
  94. const realpwd = ref();
  95. const comLen = computed(() => range(Number(props.length)));
  96. // 方法
  97. function sureClick() {
  98. emit('sure-click', realInput.value);
  99. }
  100. function focus() {
  101. realpwd.value.focus();
  102. }
  103. function changeValue(e: Event) {
  104. const input = e.target as HTMLInputElement;
  105. let val = input.value;
  106. if (val.length > comLen.value) {
  107. val = val.slice(0, comLen.value);
  108. realInput.value = val;
  109. }
  110. if (realInput.value.length === comLen.value) {
  111. emit('complete', val);
  112. }
  113. emit('input', val);
  114. emit('update:value', val);
  115. }
  116. function close() {
  117. emit('update:is-visible', false);
  118. }
  119. function range(val: number) {
  120. return Math.min(Math.max(4, val), 6);
  121. }
  122. function link() {
  123. if (props.link) window.location.href = props.link;
  124. }
  125. return {
  126. comLen,
  127. sureClick,
  128. realInput,
  129. realpwd,
  130. focus,
  131. range,
  132. changeValue,
  133. close,
  134. link
  135. };
  136. }
  137. });
  138. </script>
  139. <style scoped lang="scss">
  140. @import 'index.scss';
  141. </style>