You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
6.1 KiB

6 months ago
  1. <template>
  2. <view class="login-box">
  3. <image src="https://m2.chinause.cn/mini/baixmini/img/logo.jpg" mode='aspectFit' class="login-logo"></image>
  4. <view class="login-title">农配领航</view>
  5. <view class="login-form">
  6. <input class="login-input" v-model="phone" placeholder-class placeholder="请输入手机号码" />
  7. <view class="login-input-btn">
  8. <input class="login-input" v-model="code" placeholder-class placeholder="验证码"/>
  9. <view class="login-checking" @click="checking" v-if="state===false">获取验证码</view>
  10. <view class="login-checking login-time" v-if="state===true">倒计时{{ currentTime }}s</view>
  11. </view>
  12. <input class="login-input" v-model="psw" placeholder-class password placeholder="请输入新密码"/>
  13. <input class="login-input" v-model="surepsw" placeholder-class password placeholder="再次输入密码"/>
  14. <button class="login-btn" @click="dopost()">立即提交</button>
  15. <navigator url="/pages/user/login" open-type='navigateBack' hover-class="none" class="login-label">已有账号点此去登录.</navigator>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. data() {
  22. return {
  23. state: false, //是否开启倒计时
  24. totalTime: 60, //总时间,单位秒
  25. recordingTime: 0, //记录时间变量
  26. currentTime: 0, //显示时间变量,
  27. code:'',
  28. psw:'',
  29. surepsw:'',
  30. phone:'',
  31. }
  32. },
  33. onLoad() {
  34. },
  35. methods: {
  36. async sendcode(phone) {
  37. let reinfo=await this.$api.sendcode({action:'sendcode',phone:phone});
  38. this.getinfo=reinfo.data;
  39. if(reinfo.code==1){
  40. //执行倒计时
  41. this.checkingTime();
  42. }
  43. uni.showToast({
  44. title:reinfo.msg,icon:'none'
  45. })
  46. },
  47. async updatepsw(phone,code,psw) {
  48. let reinfo=await this.$api.updatepsw({action:'updatepsw',phone:phone,psw:psw,code:code});
  49. this.getinfo=reinfo.data;
  50. if(reinfo.code==1){
  51. uni.showToast({
  52. title:reinfo.msg
  53. })
  54. setTimeout(function(e){
  55. uni.navigateBack({
  56. delta:1
  57. })
  58. },1500)
  59. }else{
  60. uni.showToast({
  61. title:reinfo.msg,icon:'none'
  62. })
  63. }
  64. },
  65. checking() {
  66. let phoneReg = /(^1\d{10}$)|(^[0-9]\d{7}$)/;
  67. if(!phoneReg.test(this.phone)) {
  68. uni.showToast({title: '请输入合法手机号!',icon: 'none'})
  69. return false;
  70. }
  71. //把显示时间设为总时间
  72. this.currentTime = this.totalTime;
  73. //开始倒计时
  74. this.state = true;
  75. this.sendcode(this.phone)
  76. },
  77. checkingTime(){
  78. let that = this;
  79. //判断是否开启
  80. if(this.state){
  81. //判断显示时间是否已到0,判断记录时间是否已到总时间
  82. if(this.currentTime > 0 && this.recordingTime <= this.totalTime){
  83. //记录时间增加 1
  84. this.recordingTime = this.recordingTime + 1;
  85. //显示时间,用总时间 - 记录时间
  86. this.currentTime = this.totalTime - this.recordingTime;
  87. //1秒钟后,再次执行本方法
  88. setTimeout(() => {
  89. //定时器内,this指向外部,找不到vue的方法,所以,需要用that变量。
  90. that.checkingTime();
  91. }, 1000)
  92. }else{
  93. //时间已完成,还原相关变量
  94. this.state = false; //关闭倒计时
  95. this.recordingTime = 0; //记录时间为0
  96. this.currentTime = this.totalTime; //显示时间为总时间
  97. }
  98. }else{
  99. //倒计时未开启,初始化默认变量
  100. this.state = false;
  101. this.recordingTime = 0;
  102. this.currentTime = this.totalTime;
  103. }
  104. },
  105. dopost(){
  106. //正则表达式验证手机号
  107. let phoneReg = /(^1\d{10}$)|(^[0-9]\d{7}$)/;
  108. if(!phoneReg.test(this.phone)) {
  109. uni.showToast({title: '请输入合法手机号!',icon: 'none'})
  110. return false;
  111. }
  112. if(this.code==''){
  113. uni.showToast({title: '请输入验证码!',icon: 'none'})
  114. return false;
  115. }
  116. if(this.pwd==''||this.psw.length<6) {
  117. uni.showToast({title: '密码不少于6位!',icon: 'none'})
  118. return false;
  119. }
  120. if(this.psw!=this.surepsw) {
  121. uni.showToast({title: '两次输入密码不一致!',icon: 'none'})
  122. return false;
  123. }
  124. this.updatepsw(this.phone,this.code,this.psw)
  125. }
  126. }
  127. }
  128. </script>
  129. <style>
  130. .login-box{
  131. padding: 0 100upx;
  132. position: relative;
  133. }
  134. .login-logo{
  135. width: 100%;
  136. width: 100%;
  137. height: 310upx;
  138. }
  139. .login-title{
  140. position: absolute;
  141. top: 215upx;
  142. line-height: 260upx;
  143. font-size: 35upx;
  144. color: #a7b6d0;
  145. text-align: center;
  146. width: 100%;
  147. margin-left: -110upx;
  148. }
  149. .login-form{
  150. margin-top: 100upx;
  151. }
  152. .login-input{
  153. background: #e2f5fc;
  154. margin-top: 30upx;
  155. border-radius: 100upx;
  156. padding: 20upx 40upx;
  157. font-size: 36upx;
  158. height: auto;
  159. }
  160. .input-placeholder, .login-input{
  161. color: #94afce;
  162. line-height: 30upx;
  163. }
  164. .login-label{
  165. padding: 60upx 0;
  166. text-align: center;
  167. font-size: 30upx;
  168. color: #a7b6d0;
  169. }
  170. .login-btn{
  171. background: #348143;
  172. color: #fff;
  173. border: 0;
  174. border-radius: 100upx;
  175. font-size: 36upx;
  176. margin-top: 80upx;
  177. }
  178. .login-btn:after{
  179. border: 0;
  180. }
  181. .login-input{
  182. background: #e2f5fc;
  183. margin-top: 30upx;
  184. border-radius: 100upx;
  185. padding: 20upx 40upx;
  186. font-size: 36upx;
  187. }
  188. .input-placeholder, .login-input{
  189. color: #94afce;
  190. }
  191. .login-label{
  192. padding: 60upx 0;
  193. text-align: center;
  194. font-size: 30upx;
  195. color: #a7b6d0;
  196. }
  197. .login-btn{
  198. background: #348143;
  199. color: #fff;
  200. border: 0;
  201. border-radius: 100upx;
  202. font-size: 36upx;
  203. margin-top: 60upx;
  204. }
  205. .login-btn:after{
  206. border: 0;
  207. }
  208. /*验证码输入框*/
  209. .login-input-btn{
  210. position: relative;
  211. }
  212. .login-input-btn .login-input{
  213. padding-right: 260upx;
  214. }
  215. .login-checking{
  216. position: absolute;
  217. right: 0;
  218. top: 0;
  219. background: #348143;
  220. color: #fff;
  221. border: 0;
  222. border-radius: 110upx;
  223. font-size: 36upx;
  224. margin-left: auto;
  225. margin-right: auto;
  226. padding-left: 28upx;
  227. padding-right: 28upx;
  228. box-sizing: border-box;
  229. text-align: center;
  230. text-decoration: none;
  231. line-height: 2.22555556;
  232. -webkit-tap-highlight-color: transparent;
  233. overflow: hidden;
  234. padding-top: 2upx;
  235. padding-bottom: 2upx;
  236. margin-top: 4upx;
  237. }
  238. .login-checking.login-time{
  239. background: #a7b6d0;
  240. }
  241. /*按钮点击效果*/
  242. .login-btn.button-hover{
  243. transform: translate(1upx, 1upx);
  244. }
  245. </style>