password.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="container bg-main pos-r" v-if="fetch && fetch.user">
  3. <use-tabbar :tabbar="false"></use-tabbar>
  4. <!-- 内容区域 -->
  5. <view class="padding-xl dflex-c dflex-flow-c">
  6. <!-- 头像 -->
  7. <view class="portrait-box margin-bottom">
  8. <image class="headimg border-radius-c" :src="fetch.user.avatar"/>
  9. </view>
  10. <!-- 手机号输入框(只读) -->
  11. <view class="w-full dflex padding-bottom-sm">
  12. <view class="iconfont iconshouji margin-right"></view>
  13. <view class="flex1 dflex">
  14. <input class="border-line padding-sm flex1" type="text" :disabled="disabled" placeholder="请输入手机号" maxlength="11" v-model="fetch.user.mobile"/>
  15. </view>
  16. </view>
  17. <!-- 密码输入框 -->
  18. <view class="w-full dflex padding-bottom-sm">
  19. <view class="iconfont iconmima margin-right"></view>
  20. <input class="border-line padding-sm flex1" type="password" placeholder="请输入新密码" maxlength="20" v-model="password"/>
  21. </view>
  22. <!-- 验证码输入框 -->
  23. <view class="w-full dflex padding-bottom-sm">
  24. <view class="iconfont iconyanzheng margin-right"></view>
  25. <view class="border-line flex1 dflex">
  26. <input class="padding-sm flex1" type="number" placeholder="请输入验证码" maxlength="6" v-model="code"/>
  27. <view class="padding-tb-sm ft-base" @tap="sendCode">{{ codeText }}</view>
  28. </view>
  29. </view>
  30. <!-- 提交按钮 -->
  31. <view class="w-full margin-top-xl" @click="act">
  32. <view class="dflex-b border-radius-lg">
  33. <view class="tac padding-tb-sm flex1 bg-base fs">确定</view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. data() {
  42. return {
  43. fetch: {
  44. user: {
  45. mobile: '',
  46. avatar: '',
  47. }
  48. },
  49. disabled:true,
  50. password: '',
  51. code: '',
  52. codeText: '发送验证码',
  53. countdown: 0,
  54. }
  55. },
  56. onLoad() {
  57. this.loadData();
  58. },
  59. methods: {
  60. loadData() {
  61. if (this.DeverApi.getToken()) {
  62. this.DeverApi.get(this, 'user.info');
  63. } else {
  64. this.disabled = false;
  65. this.Dever.config().then(config => {
  66. this.fetch.user.avatar = config.l;
  67. });
  68. }
  69. },
  70. act() {
  71. if (this.DeverApi.getToken()) {
  72. // 修改密码
  73. var url = 'user.pwd';
  74. } else {
  75. var url = 'main.reset';
  76. // 重置密码
  77. if (!/^1\d{10}$/.test(this.fetch.user.mobile)) {
  78. return this.Dever.alert('请输入有效手机号');
  79. }
  80. }
  81. if (!this.password) {
  82. return this.Dever.alert('密码不能为空');
  83. }
  84. if (this.password.length < 6) {
  85. return this.Dever.alert('密码长度不能少于6位');
  86. }
  87. if (this.password.length > 32) {
  88. return this.Dever.alert('密码长度不能超过32位');
  89. }
  90. if (!this.code) {
  91. return this.Dever.alert('请输入验证码');
  92. }
  93. this.DeverApi.post(url, {mobile:this.fetch.user.mobile,code:this.code,pwd:this.password}, r => {
  94. this.Dever.success('修改成功')
  95. if (url == 'user.pwd') {
  96. this.Dever.location('user/setting/security', 'go');
  97. } else {
  98. this.Dever.location('user/login', 'go');
  99. }
  100. });
  101. },
  102. sendCode() {
  103. if (this.countdown > 0) return
  104. if (this.DeverApi.getToken()) {
  105. var url = 'user.sms'
  106. } else {
  107. if (!/^1\d{10}$/.test(this.fetch.user.mobile)) {
  108. this.Dever.alert('请输入有效手机号')
  109. return
  110. }
  111. var url = 'main.sms'
  112. }
  113. this.DeverApi.post(url, {mobile:this.fetch.user.mobile}, r => {
  114. if (r.indexOf('::') != -1) {
  115. var t = r.split('::');
  116. r = t[0];
  117. this.code = t[1];
  118. }
  119. this.Dever.success(r)
  120. this.countdown = 60
  121. this.updateCodeText()
  122. });
  123. },
  124. updateCodeText() {
  125. if (this.countdown === 0) {
  126. this.codeText = '发送验证码'
  127. return
  128. }
  129. this.codeText = `${this.countdown}s`
  130. setTimeout(() => {
  131. this.countdown--
  132. this.updateCodeText()
  133. }, 1000)
  134. },
  135. }
  136. }
  137. </script>
  138. <style>
  139. .container {
  140. padding-top: 5vh;
  141. width: 100vw;
  142. min-height: 100vh;
  143. overflow: hidden;
  144. }
  145. uni-image {
  146. width: 62px;
  147. height: 62px;
  148. border: 2px solid #fff;
  149. }
  150. </style>