mobile.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <view class="container">
  3. <view class="form">
  4. <!-- 手机号 -->
  5. <view class="form-item">
  6. <text class="iconfont icon-shoujihao"></text>
  7. <text class="pre-mobile">+86</text>
  8. <input class="form-item--input" style="padding-left: 12rpx;" type="number" v-model="mobile" maxlength="11" placeholder="请输入手机号码" />
  9. </view>
  10. <!-- 图形验证码 -->
  11. <view class="form-item">
  12. <text class="iconfont icon-tuxingyanzhengma"></text>
  13. <input class="form-item--input" type="text" v-model="captchaCode" maxlength="5" placeholder="请输入图形验证码" />
  14. <view class="form-item--parts">
  15. <view class="captcha" @click="getCaptcha()">
  16. <image class="image" :src="captcha"></image>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 短信验证码 -->
  21. <view class="form-item">
  22. <text class="iconfont icon-yanzhengma"></text>
  23. <input class="form-item--input" type="number" v-model="smsCode" maxlength="6" placeholder="请输入短信验证码" />
  24. <view class="form-item--parts">
  25. <view class="captcha-sms" @click="handelSmsCaptcha()">
  26. <text v-if="!smsState" class="activate">获取验证码</text>
  27. <text v-else class="un-activate">重新发送({{ times }})秒</text>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 底部操作按钮 -->
  33. <view class="footer-fixed">
  34. <view class="btn-wrapper">
  35. <view class="btn-item btn-item-main" @click="doSubmit()">保存</view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import * as UserApi from '@/api/user'
  42. import * as LoginApi from '@/api/login'
  43. import * as Verify from '@/utils/verify'
  44. import store from '@/store'
  45. // 倒计时时长(秒)
  46. const times = 60
  47. export default {
  48. data() {
  49. return {
  50. // 正在加载
  51. isLoading: false,
  52. // 手机号
  53. mobile: '',
  54. // 图形验证码信息
  55. captcha: "",
  56. // 图形验证码uuid
  57. captchaUuid: "",
  58. // 图形验证码
  59. captchaCode: '',
  60. // 短信验证码发送状态
  61. smsState: false,
  62. // 短信验证码
  63. smsCode: '',
  64. // 倒计时
  65. times,
  66. }
  67. },
  68. /**
  69. * 生命周期函数--监听页面加载
  70. */
  71. created() {
  72. // 获取图形验证码
  73. this.getCaptcha();
  74. },
  75. methods: {
  76. // 获取图形验证码
  77. getCaptcha() {
  78. const app = this
  79. LoginApi.captcha()
  80. .then(result => {
  81. app.captcha = result.data.captcha;
  82. app.captchaUuid = result.data.uuid;
  83. app.captchaCode = "";
  84. })
  85. },
  86. // 点击发送短信验证码
  87. handelSmsCaptcha() {
  88. const app = this
  89. if (Verify.isEmpty(app.mobile)) {
  90. app.$toast("请填写手机号");
  91. return false;
  92. }
  93. if (Verify.isEmpty(app.captchaCode)) {
  94. app.$toast("请填写图形验证码");
  95. return false;
  96. }
  97. if (!app.isLoading && !app.smsState) {
  98. app.sendSmsCaptcha();
  99. }
  100. },
  101. // 请求发送短信验证码接口
  102. sendSmsCaptcha() {
  103. const app = this
  104. app.isLoading = true
  105. LoginApi.sendSmsCaptcha({
  106. captchaKey: app.captcha.key,
  107. captchaCode: app.captchaCode,
  108. mobile: app.mobile,
  109. uuid: app.captchaUuid
  110. })
  111. .then(result => {
  112. // 显示发送成功
  113. if (result.data) {
  114. app.$toast(result.message)
  115. // 执行定时器
  116. app.timer()
  117. } else {
  118. app.$error(result.message)
  119. }
  120. })
  121. .finally(() => app.isLoading = false)
  122. },
  123. // 执行定时器
  124. timer() {
  125. const app = this
  126. app.smsState = true
  127. const inter = setInterval(() => {
  128. app.times = app.times - 1
  129. if (app.times <= 0) {
  130. app.smsState = false;
  131. app.times = times;
  132. clearInterval(inter);
  133. }
  134. }, 1000)
  135. },
  136. // 提交保存
  137. doSubmit() {
  138. const app = this;
  139. if (Verify.isEmpty(app.mobile)) {
  140. this.$toast('请输入您的手机号')
  141. return false
  142. }
  143. if (Verify.isEmpty(app.smsCode)) {
  144. this.$toast('请输入短信验证码')
  145. return false
  146. }
  147. app.isLoading = true;
  148. UserApi.save({"mobile": app.mobile, "verifyCode": app.smsCode})
  149. .then(result => {
  150. app.isLoading = false;
  151. if (result.code == 200) {
  152. app.$success('保存成功!');
  153. } else {
  154. app.$error(result.message ? result.message : '保存失败!');
  155. }
  156. }).catch(err => {
  157. app.isLoading = false;
  158. })
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. .form {
  165. margin-top: 50rpx;
  166. }
  167. // 输入框元素
  168. .form-item {
  169. display: flex;
  170. padding: 18rpx;
  171. border-bottom: 2rpx solid #cccccc;
  172. margin-left: 20rpx;
  173. margin-right: 20rpx;
  174. margin-bottom: 25rpx;
  175. height: 110rpx;
  176. align-items: center;
  177. justify-content: center;
  178. .pre-mobile {
  179. line-height: 75rpx;
  180. color: #888888;
  181. }
  182. &--input {
  183. font-size: 26rpx;
  184. letter-spacing: 1rpx;
  185. flex: 1;
  186. height: 100%;
  187. padding-left: 5rpx;
  188. }
  189. &--parts {
  190. min-width: 100rpx;
  191. height: 100%;
  192. }
  193. // 图形验证码
  194. .captcha {
  195. height: 100%;
  196. .image {
  197. display: block;
  198. width: 192rpx;
  199. height: 80rpx;
  200. }
  201. }
  202. // 短信验证码
  203. .captcha-sms {
  204. font-size: 22rpx;
  205. line-height: 50rpx;
  206. padding-right: 20rpx;
  207. .activate {
  208. color: #cea26a;
  209. border: #ccc solid 1px;
  210. padding: 18rpx;
  211. border-radius: 8rpx;
  212. }
  213. .un-activate {
  214. color: #9e9e9e;
  215. }
  216. }
  217. }
  218. // 底部操作栏
  219. .footer-fixed {
  220. z-index: 11;
  221. box-shadow: 0 -4rpx 40rpx 0 rgba(144, 52, 52, 0.1);
  222. margin-top: 80rpx;
  223. .btn-wrapper {
  224. height: 100%;
  225. display: flex;
  226. text-align: center;
  227. align-items: center;
  228. padding: 0 30rpx;
  229. margin-bottom: 10rpx;
  230. }
  231. .btn-item {
  232. flex: 1;
  233. font-size: 28rpx;
  234. height: 80rpx;
  235. line-height: 80rpx;
  236. text-align: center;
  237. color: #fff;
  238. border-radius: 40rpx;
  239. }
  240. .btn-item-main {
  241. background: linear-gradient(to right, #f9211c, #ff6335);
  242. }
  243. .btn-item-back {
  244. margin-top: 20rpx;
  245. background: #FFFFFF;
  246. border: 1px solid $fuint-theme;
  247. color: #666666;
  248. }
  249. }
  250. </style>