transaction.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="container">
  3. <view class="row b-b">
  4. <text class="tit">{{$t('set.a3')}}</text>
  5. <input class="input" disabled v-model="account" type="text" :placeholder="$t('reg.a3')"
  6. placeholder-class="placeholder" />
  7. </view>
  8. <view class="row b-b">
  9. <text class="tit">{{$t('reg.a8')}}</text>
  10. <input class="input" v-model="password" type="password" :placeholder="$t('reg.a9')"
  11. placeholder-class="placeholder" />
  12. </view>
  13. <view class="row b-b">
  14. <text class="tit">{{$t('reg.b0')}}</text>
  15. <input class="input" v-model="repeat" type="password" :placeholder="$t('reg.b1')"
  16. placeholder-class="placeholder" />
  17. </view>
  18. <!-- <view class="row b-b">
  19. <text class="tit">{{$t('reg.a6')}}</text>
  20. <input class="input" v-model="captcha" type="text" :placeholder="$t('reg.a7')" placeholder-class="placeholder" />
  21. <view class="code" @click="verification">{{ countDown == 0 ? $t('reg.c6') : countDown }}</view>
  22. </view> -->
  23. <button class="add-btn" :class="{'bg-gray':loding}"
  24. @click="loding?'':confirm()">{{$t('common.submit')}}</button>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. verify
  30. } from '@/api/login.js';
  31. import {
  32. mapState
  33. } from 'vuex';
  34. import {
  35. Reset
  36. } from '@/api/set.js';
  37. import detectEthereumProvider from '@metamask/detect-provider'
  38. export default {
  39. data() {
  40. return {
  41. time: '', //保存倒计时对象
  42. countDown: 0, //倒计时
  43. account: '', //手机号
  44. captcha: '', //验证码
  45. password: '', //密码
  46. repeat: '', //确认密码
  47. loding: false, //是否载入中
  48. };
  49. },
  50. computed: {
  51. ...mapState("user", ['userInfo'])
  52. },
  53. onLoad() {
  54. if (this.userInfo.account == null) {
  55. this.account = '';
  56. } else {
  57. this.account = this.userInfo.account;
  58. this.show = false;
  59. }
  60. uni.setNavigationBarTitle({
  61. title: this.$t("tab.b3"),
  62. });
  63. },
  64. watch: {
  65. // 监听倒计时
  66. countDown(i) {
  67. if (i == 0) {
  68. clearInterval(this.time);
  69. }
  70. }
  71. },
  72. methods: {
  73. //发送验证码
  74. verification() {
  75. let obj = this;
  76. if (this.account == '') {
  77. this.$api.msg(obj.$t("safe.b5"));
  78. return;
  79. }
  80. // if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.account)) {
  81. // this.$api.msg(obj.$t("safe.b8"));
  82. // return;
  83. // }
  84. // 判断是否在倒计时
  85. if (obj.countDown > 0) {
  86. return false;
  87. } else {
  88. obj.countDown = 60;
  89. obj.time = setInterval(() => {
  90. obj.countDown--;
  91. }, 1000);
  92. //调用验证码接口
  93. verify({
  94. phone: obj.account,
  95. type: ''
  96. })
  97. .then(({
  98. data
  99. }) => {})
  100. .catch(err => {
  101. console.log(err);
  102. });
  103. }
  104. },
  105. async confirm(e) {
  106. this.loding = true;
  107. uni.showLoading({
  108. title: this.$t("userinfo.u23"),
  109. mask: true
  110. });
  111. const provider = await detectEthereumProvider();
  112. // 链接到MetaMask
  113. ethereum.request({
  114. method: 'eth_requestAccounts'
  115. }).then((account) => {
  116. console.log(account, 'account');
  117. // this.$store.commit('accounts/connect_wallet', account[0]);
  118. // localStorage.setItem('accounts', account)
  119. const PKR_LOGIN = 'PKR_RESET' + (new Date()).getTime();
  120. ethereum.request({
  121. "method": "personal_sign",
  122. "params": [
  123. PKR_LOGIN,
  124. account[0]
  125. ]
  126. }).then((res) => {
  127. Reset({
  128. password: this.password,
  129. repeat: this.repeat,
  130. sign:res,
  131. account: account[0],
  132. msg:PKR_LOGIN
  133. })
  134. .then(() => {
  135. this.loding = false;
  136. uni.showToast({
  137. title: this.$t("safe.d3"),
  138. icon: "success",
  139. mask: true
  140. });
  141. })
  142. .catch(err => {
  143. this.loding = false;
  144. console.log(err);
  145. });
  146. });
  147. });
  148. }
  149. }
  150. };
  151. </script>
  152. <style lang="scss">
  153. page {
  154. background: #f3f3f3;
  155. }
  156. .row {
  157. display: flex;
  158. align-items: center;
  159. position: relative;
  160. padding: 0 30rpx;
  161. height: 110rpx;
  162. background: $font-color-white;
  163. .tit {
  164. min-width: 130rpx;
  165. flex-shrink: 0;
  166. font-size: 30rpx;
  167. }
  168. .input {
  169. flex: 1;
  170. font-size: 30rpx;
  171. color: $font-color-light;
  172. padding-left: 20rpx;
  173. }
  174. .iconlocation {
  175. font-size: 36rpx;
  176. color: $font-color-light;
  177. }
  178. }
  179. .add-btn {
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. height: 100rpx;
  184. margin: 60rpx auto;
  185. font-size: $font-lg;
  186. background-color: #FFF;
  187. border: none;
  188. }
  189. .bg-gray {
  190. background-color: $color-gray;
  191. }
  192. .code {
  193. color: #000s;
  194. font-size: 23rpx;
  195. border-left: 1px solid #eeeeee;
  196. width: 150rpx;
  197. flex-shrink: 0;
  198. text-align: center;
  199. }
  200. </style>