verification.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <view class="login">
  3. <navbar ref="navbar" :config="config" backColor="#666"></navbar>
  4. <form @submit="formSubmit">
  5. <view class="content">
  6. <view class="password">
  7. <view class="left">
  8. 验证码登录
  9. <text @click="goToForgetPass">忘记密码</text>
  10. </view>
  11. <view class="right" @click="goToLogin">
  12. 密码登录<text class="iconfont u-font24 u-999">&#xe6c7;</text>
  13. </view>
  14. </view>
  15. <view class="phone">
  16. <view class="number">
  17. 手机号
  18. </view>
  19. <input type="number" name="phone" value="" placeholder-style="color:#cccccc; font-size:28rpx; font-weight:500;" @input="onPhone" maxlength="11" placeholder="请输入手机号" />
  20. </view>
  21. <view class="passpwd">
  22. <view class="number">
  23. 验证码登录
  24. </view>
  25. <input type="text" value="" placeholder-style="color:#cccccc; font-size:28rpx; font-weight:500;" @input="onCode" name="code" maxlength="6" placeholder="请输入验证码"/>
  26. <button class="obtain" :disabled="disabled" @click="judgeLogin" :class="isPhone?'active':''">
  27. {{verificationCode}}
  28. </button>
  29. </view>
  30. <view class="agreement">
  31. <view class="whole">
  32. <view class="top" v-if="flag" @click="onFlag">
  33. <icon type="success" color="#FF0000" size="17" ></icon>
  34. </view>
  35. <view class="top" v-else style="width: 30rpx;height: 30rpx;border-radius: 50%;border: #ccc solid 1rpx;" @click="onFlag"></view>
  36. </view>
  37. <view class="agree">
  38. 我已阅读并同意<text @click="goToagreement">《会员注册协议》</text>
  39. </view>
  40. </view>
  41. <button class="login-button" form-type="submit">
  42. 登录
  43. </button>
  44. <view class="go-to-register" @click="goToregister">
  45. 去注册
  46. </view>
  47. </view>
  48. </form>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import {yzmLgoin,getVerfityCode} from "@/api/login.js"
  54. export default{
  55. data(){
  56. return{
  57. config: {
  58. back: false,
  59. title: '用户登录',
  60. color: '#1A1A1A',
  61. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  62. backgroundColor: [1, "#fff"],
  63. statusBarFontColor: '#1A1A1A',
  64. },
  65. flag:false,//协议
  66. phone:'', //手机号
  67. isPhone:false, //手机号正则
  68. code:'', //密码
  69. time:60, //倒计时
  70. disabled:false, //按钮
  71. verificationCode:"获取验证码"
  72. }
  73. },
  74. methods:{
  75. //忘记密码
  76. goToForgetPass(){
  77. uni.navigateTo({
  78. url:"../setup/forgetPass"
  79. })
  80. },
  81. //去登录
  82. goToLogin(){
  83. uni.redirectTo({
  84. url:"./login"
  85. })
  86. },
  87. //去注册
  88. goToregister(){
  89. uni.redirectTo({
  90. url:"./register"
  91. })
  92. },
  93. //去协议
  94. goToagreement(){
  95. console.log(666)
  96. uni.navigateTo({
  97. url:"./agreement"
  98. })
  99. },
  100. //倒计时
  101. countDown(){
  102. if(this.time<=0){
  103. this.disabled=false;
  104. this.verificationCode="重新获取";
  105. this.isPhone=true;
  106. this.time=60;
  107. clearInterval(this.clear)
  108. }else{
  109. --this.time;
  110. this.verificationCode=this.time+"s"
  111. }
  112. },
  113. //清楚计时器
  114. beforeDestroy(){
  115. clearInterval(this.clear)
  116. },
  117. judgeLogin(){
  118. if(this.isPhone){
  119. this.$http.get("/account/verify-mobile/"+this.phone).then(res=>{
  120. if(res&&res.code==200){
  121. if(res.data==false){
  122. this.$mUtil.toast("该手机号还未注册")
  123. }else if(res.data==true){
  124. this.obtainCode()
  125. }
  126. }
  127. })
  128. }
  129. },
  130. //获取验证码
  131. async obtainCode(){
  132. if(this.isPhone){
  133. await this.$http.post(getVerfityCode,this.phone)
  134. .then(res=>{
  135. if(res&&res.code==200){
  136. this.disabled=false;
  137. this.isPhone=false;
  138. this.verificationCode=this.time+"s";
  139. this.$mUtil.toast("发送成功")
  140. this.clear=setInterval(this.countDown,1000);
  141. }
  142. })
  143. }
  144. },
  145. //手机号
  146. onPhone(e){
  147. this.phone=e.detail.value
  148. if(this.phone.match(this.$mConfig.telRegex)){
  149. if(this.verificationCode=='获取验证码'||this.verificationCode=='重新获取'){
  150. this.isPhone=true
  151. }
  152. }else{
  153. this.isPhone=false
  154. }
  155. },
  156. //验证码
  157. onCode(e){
  158. this.code=e.detail.value
  159. // console.log(this.code)
  160. },
  161. //协议
  162. onFlag(){
  163. this.flag=!this.flag
  164. },
  165. formSubmit(e){
  166. console.log(666)
  167. let target = e.detail.value;
  168. if(!target.phone){
  169. this.$mUtil.toast('请输入手机号')
  170. return false
  171. }
  172. if(!(target.phone.match(this.$mConfig.telRegex))){
  173. this.$mUtil.toast("请输入正确的手机号")
  174. return false
  175. }
  176. if(!target.code){
  177. this.$mUtil.toast("请输入验证码")
  178. return false
  179. }
  180. if(this.flag==false){
  181. this.$mUtil.toast("请先同意协议")
  182. return false
  183. }
  184. let param={
  185. mobile:target.phone,
  186. captcha:target.code,
  187. cid: uni.getStorageSync('cid')
  188. }
  189. this.$http.post(yzmLgoin,param)
  190. .then(res=>{
  191. if(res.code==200){
  192. this.$mUtil.toast("登录成功")
  193. uni.setStorageSync("token",res.data.token)
  194. uni.setStorageSync("shop",res.data.shop)
  195. this.$http.get("/account/app-account-info").then(res=>{
  196. uni.setStorageSync("personal",res.data)
  197. })
  198. setTimeout(function(){
  199. uni.navigateBack({
  200. delta: 1
  201. })
  202. },1000)
  203. }
  204. })
  205. }
  206. }
  207. }
  208. </script>
  209. <style lang="scss" scoped>
  210. .go-to-register{
  211. padding: 22rpx 0;
  212. color: #FA6138;
  213. font-size: 32rpx;
  214. font-weight: Regular;
  215. width: 100%;
  216. text-align: center;
  217. margin-top: 24rpx;
  218. border: 1rpx solid #3775F6;
  219. border-radius: 20rpx;
  220. }
  221. .login-button{
  222. width: 100%;
  223. text-align: center;
  224. margin-top: 70rpx;
  225. color: #ffffff;
  226. font-size: 32rpx;
  227. font-weight: Regular;
  228. background-color: #FA6138;
  229. border-radius: 20rpx;
  230. }
  231. .agreement{
  232. margin-top: 40rpx;
  233. display: flex;
  234. }
  235. .agree{
  236. font-size: 28rpx;
  237. color: #999999;
  238. font-weight: Regular;
  239. margin-left: 10rpx;
  240. text{
  241. color: #0047B1;
  242. }
  243. }
  244. .top{
  245. display: flex;
  246. align-items: center;
  247. }
  248. .choice{
  249. margin: 0 50rpx;
  250. display: flex;
  251. align-items: center;
  252. .whole{
  253. display: flex;
  254. align-items: center;
  255. }
  256. }
  257. .passpwd{
  258. display: flex;
  259. align-items: center;
  260. margin-top: 40rpx;
  261. padding-bottom: 32rpx;
  262. border-bottom: 1rpx solid #E6E6E6;
  263. .number{
  264. font-size: 28rpx;
  265. font-weight: 500;
  266. color: #333333;
  267. }
  268. input{
  269. flex: 1;
  270. margin-left: 40rpx;
  271. }
  272. .obtain{
  273. // padding: 14rpx 30rpx;
  274. border: 1rpx solid #b3b3b3;
  275. font-size: 28rpx;
  276. padding: 0 30rpx;
  277. border-radius: 36rpx;
  278. background-color: #FFFFFF;
  279. color: #999999;
  280. }
  281. .active{
  282. background-color: #FA6138;
  283. color: #FFFFFF;
  284. border: none;
  285. }
  286. }
  287. .phone{
  288. display: flex;
  289. align-items: center;
  290. margin-top: 40rpx;
  291. padding-bottom: 32rpx;
  292. border-bottom: 1rpx solid #e6e6e6;
  293. .number{
  294. font-size: 28rpx;
  295. color: #333333;
  296. font-weight: 500;
  297. }
  298. input{
  299. flex: 1;
  300. margin-left: 70rpx;
  301. }
  302. }
  303. .password{
  304. display: flex;
  305. .left{
  306. font-size: 38rpx;
  307. font-weight: Bold;
  308. color: #333333;
  309. line-height: 28rpx;
  310. flex: 1;
  311. text{
  312. font-size: 28rpx;
  313. color: #666666;
  314. font-weight: 400;
  315. margin-left: 20rpx;
  316. }
  317. }
  318. .right{
  319. color: #666666;
  320. font-size: 28rpx;
  321. font-weight: Regular;
  322. }
  323. }
  324. .content{
  325. margin: 80rpx 50rpx;
  326. }
  327. </style>