You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

263 lines
6.4 KiB

3 months ago
  1. <template>
  2. <view :data-theme="theme" class="upda_pasd">
  3. <view class="ChangePassword">
  4. <form @submit="editPwd" report-submit='true'>
  5. <view class="phone">当前手机号{{phone}}</view>
  6. <view class="list">
  7. <view class="item">
  8. <input type='password' placeholder='6-8位字母加数字' placeholder-class='placeholder' name="password" v-model="password" maxlength="18"></input>
  9. </view>
  10. <view class="item">
  11. <input type='password' placeholder='确认新密码' placeholder-class='placeholder' name="qr_password" v-model="qr_password" maxlength="18"></input>
  12. </view>
  13. <view class="item acea-row row-between-wrapper">
  14. <input type='number' placeholder='填写验证码' placeholder-class='placeholder' class="codeIput" name="captcha" :value="captcha" maxlength="6"></input>
  15. <button class="code" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="clickCode">
  16. {{ text }}
  17. </button>
  18. </view>
  19. </view>
  20. <button form-type="submit" class="confirmBnt">确认修改</button>
  21. </form>
  22. </view>
  23. <Verify @success="handlerOnVerSuccess" :captchaType="'clickWord'" :imgSize="{ width: '330px', height: '155px' }"
  24. ref="verify"></Verify>
  25. </view>
  26. </template>
  27. <script>
  28. import sendVerifyCode from "@/mixins/SendVerifyCode";
  29. import Verify from '@/pages/users/components/verifition/verify.vue';
  30. import {
  31. phoneRegisterReset,
  32. registerVerify
  33. } from '@/api/api.js';
  34. import {
  35. getUserInfo
  36. } from '@/api/user.js';
  37. import {
  38. toLogin
  39. } from '@/libs/login.js';
  40. import {mapGetters} from "vuex";
  41. import {setThemeColor} from '@/utils/setTheme.js'
  42. const app = getApp();
  43. export default {
  44. mixins: [sendVerifyCode],
  45. components: {
  46. Verify,
  47. },
  48. data() {
  49. return {
  50. userInfo: {},
  51. phone: '',
  52. password: '',
  53. captcha: '',
  54. qr_password: '',
  55. isAuto: false, //没有授权的不会自动授权
  56. isShowAuth: false, //是否隐藏授权
  57. theme:app.globalData.theme,
  58. bgColor:''
  59. };
  60. },
  61. computed: mapGetters(['isLogin']),
  62. watch:{
  63. isLogin:{
  64. handler:function(newV,oldV){
  65. if(newV){
  66. this.getUserInfo();
  67. }
  68. },
  69. deep:true
  70. }
  71. },
  72. onLoad() {
  73. if (this.isLogin) {
  74. this.getUserInfo();
  75. } else {
  76. toLogin();
  77. }
  78. let that = this;
  79. that.bgColor = setThemeColor();
  80. uni.setNavigationBarColor({
  81. frontColor: '#ffffff',
  82. backgroundColor:that.bgColor,
  83. });
  84. },
  85. methods: {
  86. clickCode(){
  87. let that = this;
  88. if (that.qr_password != that.password) return that.$util.Tips({
  89. title: '两次输入的密码不一致!'
  90. });
  91. if (!/^[a-zA-Z]\w{5,17}$/i.test(that.password)) return that.$util.Tips({
  92. title: '密码格式错误,密码必须以字母开头,长度在6~18之间,只能包含字符、数字和下划线'
  93. });
  94. this.$refs.verify.show();
  95. },
  96. //滑块验证成功后
  97. handlerOnVerSuccess(data) {
  98. this.$refs.verify.hide();
  99. this.code();
  100. },
  101. /**
  102. * 授权回调
  103. */
  104. onLoadFun: function(e) {
  105. this.getUserInfo();
  106. },
  107. // 授权关闭
  108. authColse: function(e) {
  109. this.isShowAuth = e
  110. },
  111. /**
  112. * 获取个人用户信息
  113. */
  114. getUserInfo: function() {
  115. let that = this;
  116. getUserInfo().then(res => {
  117. let tel = res.data.phone;
  118. let phone = tel.substr(0, 3) + "****" + tel.substr(7);
  119. that.$set(that, 'userInfo', res.data);
  120. that.phone = phone;
  121. });
  122. },
  123. /**
  124. * 发送验证码
  125. *
  126. */
  127. async code() {
  128. let that = this;
  129. if (!that.userInfo.phone) return that.$util.Tips({
  130. title: '手机号码不存在,无法发送验证码!'
  131. });
  132. await registerVerify(that.userInfo.phone).then(res => {
  133. that.$util.Tips({
  134. title: res.message
  135. });
  136. that.sendCode();
  137. }).catch(err => {
  138. return that.$util.Tips({
  139. title: err
  140. });
  141. });
  142. },
  143. /**
  144. * H5登录 修改密码
  145. *
  146. */
  147. checkPasd(e){
  148. let that = this,password = e.detail.value;
  149. that.password = password;
  150. // if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,8}$/i.test(password)) return that.$util.Tips({
  151. if (!/^[a-zA-Z]\w{5,17}$/i.test(password)) return that.$util.Tips({
  152. title: '密码格式错误,密码必须以字母开头,长度在6~18之间,只能包含字符、数字和下划线'
  153. });
  154. },
  155. //校验2次密码是否一样
  156. checkPassword(e){
  157. let that = this,qr_password = e.detail.value;
  158. if (qr_password != that.password) return that.$util.Tips({
  159. title: '两次输入的密码不一致!'
  160. });
  161. },
  162. editPwd: function(e) {
  163. let that = this,
  164. password = e.detail.value.password,
  165. qr_password = e.detail.value.qr_password,
  166. captcha = e.detail.value.captcha;
  167. if (!password) return that.$util.Tips({
  168. title: '请输入新密码'
  169. });
  170. if (!qr_password) return that.$util.Tips({
  171. title: '请确认新密码'
  172. });
  173. if (!captcha) return that.$util.Tips({
  174. title: '请输入验证码'
  175. });
  176. if (qr_password != that.password) return that.$util.Tips({
  177. title: '两次输入的密码不一致!'
  178. });
  179. phoneRegisterReset({
  180. account: that.userInfo.phone,
  181. captcha: captcha,
  182. password: password
  183. }).then(res => {
  184. return that.$util.Tips({
  185. title: res.message
  186. }, {
  187. tab: 3,
  188. url: 1
  189. });
  190. }).catch(err => {
  191. return that.$util.Tips({
  192. title: err
  193. });
  194. });
  195. }
  196. }
  197. }
  198. </script>
  199. <style lang="scss">
  200. page {
  201. background-color: #fff !important;
  202. }
  203. .upda_pasd{
  204. background: #FFFFFF;
  205. height: 100vh;
  206. }
  207. .ChangePassword .phone {
  208. font-size: 32rpx;
  209. font-weight: bold;
  210. text-align: center;
  211. padding-top: 100rpx;
  212. }
  213. .ChangePassword .list {
  214. width: 580rpx;
  215. margin: 53rpx auto 0 auto;
  216. }
  217. .ChangePassword .list .item {
  218. width: 100%;
  219. height: 110rpx;
  220. border-bottom: 2rpx solid #f0f0f0;
  221. }
  222. .ChangePassword .list .item input {
  223. width: 100%;
  224. height: 100%;
  225. font-size: 32rpx;
  226. }
  227. .ChangePassword .list .item .placeholder {
  228. color: #b9b9bc;
  229. }
  230. .ChangePassword .list .item input.codeIput {
  231. width: 340rpx;
  232. }
  233. .ChangePassword .list .item .code {
  234. font-size: 32rpx;
  235. // background-color: #fff;
  236. @include main_color(theme);
  237. }
  238. .ChangePassword .list .item .code.on {
  239. color: #b9b9bc !important;
  240. }
  241. .ChangePassword .confirmBnt {
  242. font-size: 32rpx;
  243. width: 580rpx;
  244. height: 90rpx;
  245. border-radius: 45rpx;
  246. color: #fff;
  247. margin: 92rpx auto 0 auto;
  248. text-align: center;
  249. line-height: 90rpx;
  250. @include main_bg_color(theme);
  251. }
  252. </style>