smsAlert.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <u-popup v-model="show" mode="center" width="80%" border-radius="15" :closeable="true">
  3. <view class="sms-alert-container">
  4. <view class="title">短信验证</view>
  5. <view class="info-msg">验证码已发送至{{phoneInfo}}</view>
  6. <view class="input-box">
  7. <u-input class="input-content" type="number" maxlength="6" placeholder="请输入验证码" v-model="code"/>
  8. <view class="code-button">
  9. <view v-if="sending==true">
  10. <u-loading mode="circle"></u-loading>
  11. </view>
  12. <view v-else-if="seconds > 0"><span class="text-red">{{seconds+'s '}} </span>可重发</view>
  13. <view v-else><u-button @click="$u.debounce(sendMessage, 500)" plain size="mini">重新发送</u-button></view>
  14. </view>
  15. </view>
  16. <u-button @click="$u.debounce(validateCode, 500)" :custom-style="customStyle" shape="circle" >确认</u-button>
  17. </view>
  18. </u-popup>
  19. </template>
  20. <script>
  21. export default {
  22. name:"smsAlert",
  23. data() {
  24. return {
  25. show: true,
  26. sending: true,
  27. phone: '13126058204',
  28. code: '',
  29. seconds: -1,
  30. customStyle: {
  31. color: 'white',
  32. background: "#E72226",
  33. width: '400rpx'
  34. }
  35. };
  36. },
  37. computed:{
  38. phoneInfo(){
  39. return this.phone.substr(0,4)+"****"+this.phone.substr(7,this.phone.length);
  40. }
  41. },
  42. methods: {
  43. async showSmsAndSend(phone){
  44. if(this.$u.test.mobile(phone)){
  45. uni.showToast({
  46. title: '手机号码格式错误',
  47. icon: 'none'
  48. });
  49. return;
  50. }
  51. this.phone = phone;
  52. await sendMessage();
  53. this.show = true;
  54. },
  55. hideSms(){
  56. this.show = false;
  57. },
  58. async sendMessage(){
  59. this.sending = true;
  60. //发送验证码
  61. this.sending= false;
  62. },
  63. validateCode(){
  64. this.$emit("validateResult",{result: true})
  65. },
  66. }
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. .sms-alert-container{
  71. padding: 50rpx;
  72. .title{
  73. width: 100%;
  74. text-align: center;
  75. padding: 0rpx 10rpx 50rpx 10rpx ;
  76. font-weight: 500;
  77. color: #353535;
  78. letter-spacing: 2rpx;
  79. font-size: 30rpx;
  80. }
  81. .info-msg{
  82. padding: 5rpx 5rpx 20rpx 5rpx;
  83. color: #353535;
  84. }
  85. .input-box{
  86. display: flex;
  87. align-items: center;
  88. justify-content: left;
  89. border: 1rpx solid #DDDDDD;
  90. border-radius: 10rpx;
  91. margin: 0 0 50rpx 0;
  92. padding: 5rpx 5rpx 5rpx 30rpx;
  93. }
  94. .input-content{
  95. width: 66%;
  96. }
  97. .code-button{
  98. width: 34%;
  99. border-left: 1rpx solid #DDDDDD;text-align: center;
  100. }
  101. }
  102. </style>