Password.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <uni-popup ref="popup" type="center">
  3. <view class="pass-wrap">
  4. <IconText class="close" :size="10" :code="`\ue847`" @click.native="close"></IconText>
  5. <view class="title">请输入安全密码</view>
  6. <!-- <text class="sub-title" id="sub-title">输入安全密码</text> -->
  7. <!-- <text class="sub-title">查看钱包数据</text> -->
  8. <view class="tip" v-if="money">金额</view>
  9. <view class="money" v-if="money">{{money | moneyFormat}}</view>
  10. <view class="line"></view>
  11. <view class="pass-main">
  12. <view class="rect-wrap">
  13. <view class="rect" v-for="(item, i) in new Array(6).fill(0)" :key="i">
  14. <view class="circle" v-if="num>i"></view>
  15. </view>
  16. </view>
  17. <input :focus="focusValue" :maxlength="6" v-model="password" class="input" type="number"
  18. @input="changeInput">
  19. </view>
  20. <text class="forget" @click="forget">忘记密码?</text>
  21. </view>
  22. </uni-popup>
  23. </template>
  24. <script lang="ts">
  25. /**
  26. * Icons 图标
  27. * @emit {String} finish 输入满6位向父组件传递输入内容
  28. * 可配合ref调用open()和close()方法
  29. */
  30. import {
  31. Component,
  32. Prop,
  33. Vue,
  34. Emit,
  35. // Ref,
  36. Watch
  37. } from 'vue-property-decorator';
  38. import pubKey from '@/packages/login/pubKey';
  39. // @ts-ignore
  40. import JSEncrypt from '@/common/jsencrypt.js';
  41. @Component({
  42. filters: {
  43. moneyFormat(val: any) {
  44. if (!+val) return '0.00';
  45. return (+val).toFixed(2);
  46. }
  47. }
  48. })
  49. export default class Password extends Vue {
  50. @Prop({
  51. default: 0
  52. })
  53. money ? : any
  54. code: string = '\ue76b';
  55. password: string = "";
  56. num: number = 0;
  57. flag: boolean = false;
  58. focusValue: boolean = false
  59. open(): void {
  60. this.num = 0;
  61. this.password = '';
  62. (this.$refs.popup as any).open('center')
  63. this.$nextTick(() => {
  64. this.focusValue = true
  65. })
  66. }
  67. close(): void {
  68. (this.$refs.popup as any).close()
  69. this.focusValue = false
  70. }
  71. @Emit('finish')
  72. emitDone(val: string) {
  73. console.log(val)
  74. let timeStamp = (+new Date() + '').substr(0, 10);
  75. let pass = this.rsa(`${val}\\n${timeStamp}\\n`);
  76. return {
  77. timeStamp,
  78. pass
  79. }
  80. }
  81. @Watch('password')
  82. getPassword(val: string) {
  83. this.num = val.length
  84. if (this.num == 6) {
  85. // 密码已填写完成
  86. !this.flag && this.emitDone(val);
  87. this.flag = true;
  88. this.empty();
  89. this.close();
  90. }
  91. }
  92. empty() {
  93. this.num = 0;
  94. this.password = '';
  95. this.flag = false;
  96. }
  97. changeInput(event: any) {
  98. // const value: string = event.target.value
  99. // this.num = value.length
  100. // if (this.num == 6) {
  101. // // 密码已填写完成
  102. // this.emitDone(value);
  103. // }
  104. }
  105. forget() {
  106. this.$Router.push({
  107. path: '/packages/user/code',
  108. query: {
  109. type: 'update',
  110. name: 'pay'
  111. }
  112. })
  113. }
  114. rsa(pass: string) {
  115. console.log('加密前', pass)
  116. var encryptor = new JSEncrypt() // 创建加密对象实例
  117. encryptor.setPublicKey(pubKey) //设置公钥
  118. return encryptor.encrypt(pass) || '加密失败'
  119. }
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. .pass-wrap {
  124. width: vw(300);
  125. // height: vw(180);
  126. border-radius: vw(10);
  127. background: white;
  128. @include flex-y();
  129. position: relative;
  130. .close {
  131. position: absolute;
  132. top: vw(10);
  133. right: vw(10);
  134. }
  135. .title {
  136. margin: vw(27) auto vw(16);
  137. @include word-vw(16, #333);
  138. }
  139. .sub-title {
  140. @include word-vw(14)
  141. }
  142. .tip{
  143. @include word-vw(14, #333);
  144. }
  145. .money{
  146. @include word-vw(30, #333);
  147. font-weight: 600;
  148. margin-top: vw(6);
  149. }
  150. .line{
  151. width: vw(280);
  152. border-bottom: vw(1) solid #F5F5F5;
  153. margin-top: vw(10);
  154. }
  155. .pass-main {
  156. margin-top: vw(12);
  157. position: relative;
  158. width: vw(240);
  159. height: vw(32);
  160. text-align: center;
  161. .input {
  162. position: absolute;
  163. left: -100vw;
  164. top: 0;
  165. width: 200vw;
  166. height: vw(32);
  167. text-align: left;
  168. }
  169. .rect-wrap {
  170. width: 100%;
  171. @include flex-x(space-between);
  172. text-align: center;
  173. position: absolute;
  174. left: 0;
  175. top: 0;
  176. .rect {
  177. width: vw(32);
  178. height: vw(32);
  179. border-radius: vw(5);
  180. background-color: #F5F5F5;
  181. @include flex-x(center, center);
  182. .circle {
  183. width: vw(6);
  184. height: vw(6);
  185. border-radius: vw(6);
  186. background: #333;
  187. ;
  188. // line-height: vw(8);
  189. // transform: scale(4);
  190. // @include flex-x(center, center);
  191. // height: vw(60);
  192. // line-height: vw(1);
  193. }
  194. }
  195. }
  196. }
  197. .forget {
  198. width: 100%;
  199. text-align: center;
  200. // padding-right: vw(28);
  201. @include word-vw(14, $gray3);
  202. box-sizing: border-box;
  203. margin-top: vw(32);
  204. margin-bottom: vw(16);
  205. }
  206. }
  207. </style>