code.vue 6.6 KB

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