code.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view class="top">
  3. <view class="back-btn cuIcon-back" @click="navBack"></view>
  4. <!-- 文字 -->
  5. <view class="top_one">请输入验证码</view>
  6. <view class="top_two">验证码已发送到<text class="text">{{phone}}</text></view>
  7. <!-- 六个显示框 -->
  8. <view class="top_three">
  9. <view :class="[ !inputList[0]||inputList.length>0 ? 'inb' : '' ]" class="input">
  10. <text>{{inputList[0]}}</text>
  11. <view v-if="!inputList[0]" class="fours"></view>
  12. </view>
  13. <view :class="[ inputList[0] && !inputList[1]||inputList.length>1 ? 'inb' : '' ]" class="input">
  14. <text>{{inputList[1]}}</text>
  15. <view v-if="inputList[0] && !inputList[1]" class="fours"></view>
  16. </view>
  17. <view :class="[ inputList[1] && !inputList[2]||inputList.length>2 ? 'inb' : '' ]" class="input">
  18. <text>{{inputList[2]}}</text>
  19. <view v-if="inputList[1] && !inputList[2]" class="fours"></view>
  20. </view>
  21. <view :class="[ inputList[2] && !inputList[3]||inputList.length>3 ? 'inb' : '' ]" class="input">
  22. <text>{{inputList[3]}}</text>
  23. <view v-if="inputList[2] && !inputList[3]" class="fours"></view>
  24. </view>
  25. <view :class="[ inputList[3] && !inputList[4]||inputList.length>4 ? 'inb' : '' ]" class="input">
  26. <text>{{inputList[4]}}</text>
  27. <view v-if="inputList[3] && !inputList[4]" class="fours"></view>
  28. </view>
  29. <view :class="[ inputList[4] && !inputList[5]||inputList.length>5 ? 'inb' : '' ]" class="input">
  30. <text>{{inputList[5]}}</text>
  31. <view v-if="inputList[4] && !inputList[5]" class="fours"></view>
  32. </view>
  33. </view>
  34. <!-- 隐藏的input -->
  35. <view class="top_four">
  36. <input type="number" class="input_show" maxlength="6" @input='submit' v-model="inputList" focus="true" />
  37. </view>
  38. <!-- 重新获取 -->
  39. <view class="top_five" @click='regain' :class="!status ? 'active' : '' "><text v-if="!status">重新发送</text><text
  40. v-if="status">{{count_down}}秒后重新发送</text></view>
  41. </view>
  42. </template>
  43. <script>
  44. import helper from '@/common/helper.js';
  45. export default {
  46. data() {
  47. return {
  48. // 电话
  49. phone: '',
  50. // 跟隐藏input绑定的数组
  51. inputList: [],
  52. //计时器
  53. count_down: 60,
  54. status: false
  55. }
  56. },
  57. onLoad(options) {
  58. console.log("options", options.phone)
  59. this.phone = options.phone
  60. console.log("phone:", this.phone);
  61. if (this.phone) {
  62. this.regain()
  63. } else {
  64. uni.showToast({
  65. title: '请输入正确的手机号',
  66. icon: 'none',
  67. duration: 2000
  68. })
  69. }
  70. },
  71. methods: {
  72. navBack() {
  73. uni.navigateBack();
  74. },
  75. regain() {
  76. console.log("regain", this.phone);
  77. this.status = true
  78. // console.log(e)150500
  79. // 设定一个定时器 1000是1秒的意思
  80. var interval = setInterval(() => {
  81. --this.count_down
  82. }, 1000)
  83. if (this.count_down == 0) {
  84. this.count_down = 60
  85. this.status = false
  86. }
  87. // 设定一个定时器 60000就是六十秒
  88. setTimeout(() => {
  89. this.status = false
  90. clearInterval(interval) //括号里面的名字要与setInterval定义的相同
  91. }, 60000)
  92. this.$request.baseRequest('get', '/commonUser/sendVerifyCode', {
  93. phone: this.phone
  94. }).then(res => {
  95. // 获得数据
  96. if (res.code != 200) {
  97. uni.showToast({
  98. title: res.message,
  99. icon: 'none',
  100. duration: 2000
  101. })
  102. }
  103. console.log(res);
  104. })
  105. .catch(res => {
  106. uni.showToast({
  107. title: res.errMsg,
  108. icon: 'none',
  109. duration: 2000
  110. })
  111. });
  112. },
  113. submit(e) {
  114. if (e.detail.value.length == 6) {
  115. var that = this
  116. uni.showLoading({
  117. title: '登录中',
  118. mask: true
  119. })
  120. console.log("----------------------------")
  121. console.log(this.phone)
  122. console.log(this.inputList)
  123. this.$request.baseRequest('get', '/commonUser/loginVerifyCode', {
  124. phone: this.phone,
  125. verifyCode: this.inputList,
  126. loginFlag: 1,
  127. identification: 2
  128. }).then(res => {
  129. console.log("res",res)
  130. if (res.code == 200) {
  131. console.log("res",res)
  132. uni.setStorageSync('userInfo', res.data)
  133. helper.getListByUserId()
  134. that.$store.commit('login', res.data)
  135. uni.switchTab({
  136. url: '/pages/order/index'
  137. });
  138. uni.hideLoading()
  139. } else {
  140. uni.hideLoading()
  141. uni.showToast({
  142. title: res1.message,
  143. icon: 'none',
  144. duration: 2000
  145. })
  146. }
  147. })
  148. .catch(res => {
  149. uni.hideLoading()
  150. uni.showToast({
  151. title: res.message,
  152. icon: 'none',
  153. duration: 2000
  154. })
  155. });
  156. }
  157. }
  158. }
  159. }
  160. </script>
  161. <style>
  162. .top {
  163. padding-top: 85px;
  164. position: relative;
  165. width: 100vw;
  166. height: calc(100vh - 85px);
  167. overflow: hidden;
  168. background: url('~@/static/images/mine/bg@2x.png');
  169. background-size: 100%;
  170. }
  171. .back-btn {
  172. position: absolute;
  173. left: 40upx;
  174. z-index: 9999;
  175. padding-top: var(--status-bar-height);
  176. top: 40upx;
  177. font-size: 40upx;
  178. color: $font-color-dark;
  179. }
  180. /* 文字 */
  181. .top_one {
  182. /* margin-top: 85px; */
  183. width: 90%;
  184. height: 90rpx;
  185. line-height: 90rpx;
  186. font-size: 44rpx;
  187. margin: auto;
  188. font-weight: bold;
  189. }
  190. .top_two {
  191. width: 90%;
  192. height: 40rpx;
  193. line-height: 40rpx;
  194. font-size: 24rpx;
  195. margin: auto;
  196. color: #545454;
  197. }
  198. .text {
  199. font-weight: bold;
  200. }
  201. /* 六个显示框容器 */
  202. .top_three {
  203. width: 80%;
  204. height: 200rpx;
  205. margin: auto;
  206. display: flex;
  207. align-items: center;
  208. justify-content: center;
  209. }
  210. /* 六个框显示框 */
  211. .input {
  212. width: 14%;
  213. height: 80rpx;
  214. background-color: #F5F5F5;
  215. margin-right: 12rpx;
  216. text-align: center;
  217. line-height: 80rpx;
  218. font-size: 50rpx;
  219. border-radius: 3px;
  220. color: #181818;
  221. }
  222. /* 模拟的焦点 */
  223. .inb {
  224. background: #FFFFFF;
  225. box-shadow: 0px 9px 10px 4px rgba(0, 0, 0, 0.07);
  226. }
  227. .fours {
  228. width: 5rpx;
  229. height: 40rpx;
  230. margin: auto;
  231. background-color: #000000;
  232. margin-top: 20rpx;
  233. animation: show .8s linear infinite;
  234. }
  235. /* 模拟焦点动画 更改animation以更改动画样式*/
  236. @keyframes show {
  237. from {
  238. background-color: #000000;
  239. }
  240. to {
  241. background-color: #ffffff;
  242. }
  243. }
  244. /* 隐藏的inpit容器 */
  245. .top_four {
  246. width: 80%;
  247. height: 100rpx;
  248. margin: auto;
  249. margin-top: -140rpx;
  250. }
  251. .input_show {
  252. width: 100%;
  253. height: 100rpx;
  254. border-bottom: 2rpx solid #000000;
  255. margin: auto;
  256. opacity: 0;
  257. background-color: #c6c6c6;
  258. }
  259. /* 重新获取 */
  260. .top_five {
  261. width: 100%;
  262. height: 60rpx;
  263. margin-top: 180rpx;
  264. text-align: center;
  265. line-height: 60rpx;
  266. color: #959595;
  267. }
  268. /* 定时器结束的字体样式 */
  269. .active {
  270. color: #22C572;
  271. }
  272. .button {
  273. width: 80%;
  274. height: 100rpx;
  275. line-height: 100rpx;
  276. background-color: #5473E8;
  277. border-radius: 60rpx;
  278. }
  279. </style>