mobile.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="page">
  3. <!-- 公共组件-每个页面必须引入 -->
  4. <public-module></public-module>
  5. <view class="form">
  6. <view class="phone d-flex">
  7. <view class="title">手机号码</view>
  8. <input placeholder="请输入手机号" v-model="phone" maxlength="11"/>
  9. </view>
  10. </view>
  11. <view class="main-text-color mx-3 my-4 mt-1">注:更改手机号码后,请用新的手机号码登录。</view>
  12. <view class="px-3">
  13. <button class="my-3 mt-4 d-flex a-center j-center main-bg-color" :loading="loading" :class="{'main-bf-hover-color':disabled}" type="primary" @tap="submit" :disabled="disabled">修改手机绑定</button>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import {mapState,mapMutations} from "vuex"
  19. export default {
  20. data() {
  21. return {
  22. phone:"",
  23. disabled:true,
  24. loading:false
  25. }
  26. },
  27. watch:{
  28. phone(val){
  29. this.OnBtnChange();
  30. }
  31. },
  32. computed:{
  33. ...mapState(['userInfo'])
  34. },
  35. methods: {
  36. ...mapMutations(['emptyUserInfo']),
  37. // 改变按钮状态
  38. OnBtnChange(){
  39. if(this.phone){
  40. this.disabled=false; return;
  41. }
  42. this.disabled=true;
  43. },
  44. // 提交注册
  45. async submit(){
  46. // 验证手机号合法性
  47. if (!this.$base.phoneRegular.test(this.phone)) {
  48. return uni.showToast({title: '请输入正确的手机号码',icon: 'none'});
  49. }
  50. // 请求服务器,发送验证码
  51. let res = await this.$http.post('/user/updateMobile?id='+this.userInfo.sysUser.id+'&mobile='+this.phone);
  52. this.phone="";
  53. uni.showToast({ title: '修改绑定手机成功,请重新登录', icon:"none",duration:2000 });
  54. setTimeout(() => {
  55. this.emptyUserInfo();
  56. uni.reLaunch({
  57. url:"/pages/login/login"
  58. })
  59. return true;
  60. }, 2000);
  61. }
  62. }
  63. }
  64. </script>
  65. <style>
  66. .page{
  67. background: #F5F5F5;
  68. height: 100vh;
  69. width: 100%;
  70. position: absolute;
  71. }
  72. .form{
  73. margin-top: 30upx;
  74. }
  75. .phone{
  76. position: relative;
  77. height: 90upx;
  78. display: flex;
  79. align-items: center;
  80. background-color: #FFFFFF;
  81. padding: 0 30upx;
  82. margin-bottom: 26upx;
  83. }
  84. .phone .title{
  85. width: 160upx;
  86. flex-shrink: 0;
  87. color: #666;
  88. }
  89. .phone input{
  90. width: 350upx;
  91. font-size: 28upx;
  92. }
  93. </style>