UNIAPP实战项目笔记61 注册成功后直接登录

今天药忘吃喽~ 2024-03-24 17:28 175阅读 0赞

UNIAPP实战项目笔记61 注册成功后直接登录

注册成功时,直接再去查询数据库成功注册的数据,并返回给前端
前端获取注册成功后的返回数据,直接写入登录状态

实际案例图片

195f699c1ae64855a9ed21de4e2f1549.png

后端接口文件 index.js

  1. var express = require('express');
  2. var router = express.Router();
  3. var connection = require('../db/sql.js');
  4. var user = require('../db/UserSql.js');
  5. // 验证码
  6. let code = '';
  7. // 接入短信的sdk
  8. // var QcloudSms = require('qcloudsms_js');
  9. //设置跨域访问(设置在所有的请求前面即可)
  10. router.all("*", function (req, res, next) {
  11. //设置允许跨域的域名,*代表允许任意域名跨域
  12. res.header("Access-Control-Allow-Origin", "*");
  13. //允许的header类型
  14. res.header("Access-Control-Allow-Headers", "content-type");
  15. //跨域允许的请求方式
  16. // res.header("Access-Control-Allow-Methods", "DELETE,PUT,POST,GET,OPTIONS");
  17. res.header("Access-Control-Allow-Methods", "*");
  18. res.header("Content-Type", "application/json;chartset=utf-8");
  19. // if (req.method == 'OPTIONS')
  20. // res.sendStatus(200); //让options尝试请求快速结束
  21. // else
  22. next();
  23. });
  24. /* GET home page. */
  25. router.get('/', function(req, res, next) {
  26. res.render('index', {
  27. title: 'Express' });
  28. });
  29. /* 测试token数据. */
  30. router.post('/api/ceshi', function(req, res, next) {
  31. console.log(111);
  32. res.send({
  33. data:{
  34. aaa:'1111'
  35. }
  36. });
  37. });
  38. /* 注册->增加一条数据. */
  39. router.post('/api/addUser', function(req, res, next) {
  40. // 前端给后端的数据
  41. let params = {
  42. userName:req.body.userName,
  43. userCode:req.body.code
  44. };
  45. if( params.userCode == code ){
  46. connection.query( user.insertData( params ),function(error,results, fields){
  47. // 再去查询手机号是否存在,用于注册成功后直接登录
  48. connection.query(user.queryUserName(params),function(er,result){
  49. if(results.length > 0){
  50. res.send({
  51. data:{
  52. success:true,
  53. msg:'注册成功',
  54. data:result[0]
  55. }
  56. });
  57. }
  58. });
  59. // res.send({
  60. // data:{
  61. // success:true,
  62. // msg:'注册成功'
  63. // }
  64. // });
  65. });
  66. }
  67. });
  68. /* 发送验证码 */
  69. router.post('/api/code', function(req, res, next) {
  70. // 前端给后端的数据
  71. let params = {
  72. userName : req.body.userName
  73. }
  74. // 短信SDK 可以使用阿里云或腾讯云的,具体接入方式以官方NodeJS代码案例
  75. // ....
  76. // 阿里云 官方代码 https://help.aliyun.com/document_detail/112185.html
  77. // 腾讯云 官方代码 https://cloud.tencent.com/developer/article/1987501
  78. // ....
  79. // ....
  80. var paramss = [ Math.floor( Math.random()*(9999-1000)+1000 ) ] // 要发送的验证码
  81. // 模拟以获取到验证码
  82. code = paramss[0];
  83. console.log(code);
  84. // 模拟成功返回验证码
  85. res.send({
  86. data:{
  87. success:true,
  88. code : paramss[0]
  89. }
  90. })
  91. })
  92. /* 注册验证手机号是否存在 */
  93. router.post('/api/registered', function(req, res, next) {
  94. // 前端给后端的数据
  95. let params = {
  96. userName : req.body.phone
  97. }
  98. // 查询手机号是否存在
  99. connection.query(user.queryUserName(params),function(error,results,fields){
  100. if(results.length > 0){
  101. res.send({
  102. data:{
  103. success:false,
  104. msg:"手机号已经存在!"
  105. }
  106. });
  107. }else{
  108. res.send({
  109. data:{
  110. success:true
  111. }
  112. });
  113. }
  114. })
  115. });
  116. /* 用户登录 */
  117. router.post('/api/login', function(req, res, next) {
  118. // 前端给后端的数据
  119. let params = {
  120. userName : req.body.userName,
  121. userPwd : req.body.userPwd
  122. }
  123. // 查询用户名或手机号是否存在
  124. connection.query(user.queryUserName(params),function(error,results,fields){
  125. if(results.length > 0){
  126. connection.query(user.queryUserPwd(params),function(erro,result){
  127. if(result.length > 0){
  128. res.send({
  129. data:{
  130. success:true,
  131. msg:"登录成功!",
  132. data:result[0]
  133. }
  134. });
  135. }else{
  136. res.send({
  137. data:{
  138. success:false,
  139. msg:"密码不正确!"
  140. }
  141. });
  142. }
  143. })
  144. }else{
  145. res.send({
  146. data:{
  147. success:false,
  148. msg:"用户名或手机号不存在!"
  149. }
  150. });
  151. }
  152. })
  153. });
  154. /* GET databases goods Detail. */
  155. router.get('/api/goods/id', function(req, res, next) {
  156. let id = req.query.id;
  157. connection.query("select * from goods_search where id='"+id+"'",function(error,result,fields){
  158. if(error) throw error;
  159. res.send({
  160. code:"0",
  161. data:result
  162. })
  163. })
  164. });
  165. /* GET List Page */
  166. router.get('/api/goods/list', function(req, res, next) {
  167. res.send({
  168. code:0,
  169. name:"家居家纺",
  170. data:[
  171. {
  172. id:1,
  173. name:"家纺",
  174. data:[
  175. {
  176. name:"家纺",
  177. list:[
  178. {
  179. id:1,
  180. name:"毛巾/浴巾",
  181. imgUrl:"/static/logo.png"
  182. },
  183. {
  184. id:2,
  185. name:"枕头",
  186. imgUrl:"/static/logo.png"
  187. }
  188. ]
  189. },
  190. {
  191. name:"生活用品",
  192. list:[
  193. {
  194. id:1,
  195. name:"浴室用品",
  196. imgUrl:"/static/logo.png"
  197. },
  198. {
  199. id:2,
  200. name:"洗晒",
  201. imgUrl:"/static/logo.png"
  202. }
  203. ]
  204. }
  205. ]
  206. },
  207. {
  208. id:2,
  209. name:"女装",
  210. data:[
  211. {
  212. name:"裙装",
  213. list:[
  214. {
  215. id:1,
  216. name:"连衣裙",
  217. imgUrl:"/static/logo.png"
  218. },
  219. {
  220. id:2,
  221. name:"半身裙",
  222. imgUrl:"/static/logo.png"
  223. }
  224. ]
  225. },
  226. {
  227. name:"上衣",
  228. list:[
  229. {
  230. id:1,
  231. name:"T恤",
  232. imgUrl:"/static/logo.png"
  233. },
  234. {
  235. id:2,
  236. name:"衬衫",
  237. imgUrl:"/static/logo.png"
  238. }
  239. ]
  240. }
  241. ]
  242. }
  243. ]
  244. });
  245. });
  246. /* GET databases goods. */
  247. router.get('/api/goods/search', function(req, res, next) {
  248. /*
  249. desc 降序 asc 升序
  250. */
  251. // 获取对象的key
  252. let [goodsName,orderName] = Object.keys(req.query);
  253. // name参数的值
  254. let name = req.query.name;
  255. // orderName的key值
  256. let order = req.query[orderName];
  257. let sql = "select * from goods_search";
  258. if(!(name == undefined || orderName == undefined || order == undefined)){
  259. sql = "select * from goods_search where name like '%"+name+"%' order by "+orderName+" "+order;
  260. }
  261. connection.query(sql,function(error,results,fields){
  262. res.send({
  263. code:"0",
  264. data:results
  265. });
  266. })
  267. });
  268. /* 首页第一次触底的数据 */
  269. router.get('/api/index_list/1/data/2', function(req, res, next) {
  270. res.send({
  271. code:"0",
  272. data:[
  273. {
  274. type:"commodityList",
  275. data:[
  276. {
  277. id:1,
  278. imgUrl:"../../static/logo.png",
  279. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  280. pprice:"299",
  281. oprice:"659",
  282. discount:"5.2"
  283. },
  284. {
  285. id:2,
  286. imgUrl:"../../static/logo.png",
  287. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  288. pprice:"299",
  289. oprice:"659",
  290. discount:"5.2"
  291. },{
  292. id:3,
  293. imgUrl:"../../static/logo.png",
  294. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  295. pprice:"299",
  296. oprice:"659",
  297. discount:"5.2"
  298. },
  299. {
  300. id:4,
  301. imgUrl:"../../static/logo.png",
  302. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  303. pprice:"299",
  304. oprice:"659",
  305. discount:"5.2"
  306. },
  307. ]
  308. },
  309. ]
  310. });
  311. });
  312. /* 运动户外第二次触底的数据 */
  313. router.get('/api/index_list/2/data/3', function(req, res, next) {
  314. res.send({
  315. code:"0",
  316. data:[
  317. {
  318. type:"commodityList",
  319. data:[
  320. {
  321. id:1,
  322. imgUrl:"../../static/logo.png",
  323. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  324. pprice:"299",
  325. oprice:"659",
  326. discount:"5.2"
  327. },
  328. {
  329. id:2,
  330. imgUrl:"../../static/logo.png",
  331. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  332. pprice:"299",
  333. oprice:"659",
  334. discount:"5.2"
  335. },{
  336. id:3,
  337. imgUrl:"../../static/logo.png",
  338. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  339. pprice:"299",
  340. oprice:"659",
  341. discount:"5.2"
  342. },
  343. {
  344. id:4,
  345. imgUrl:"../../static/logo.png",
  346. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  347. pprice:"299",
  348. oprice:"659",
  349. discount:"5.2"
  350. },
  351. ]
  352. },
  353. ]
  354. });
  355. });
  356. /* 运动户外第一次触底的数据 */
  357. router.get('/api/index_list/2/data/2', function(req, res, next) {
  358. res.send({
  359. code:"0",
  360. data:[
  361. {
  362. type:"commodityList",
  363. data:[
  364. {
  365. id:1,
  366. imgUrl:"../../static/logo.png",
  367. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  368. pprice:"299",
  369. oprice:"659",
  370. discount:"5.2"
  371. },
  372. {
  373. id:2,
  374. imgUrl:"../../static/logo.png",
  375. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  376. pprice:"299",
  377. oprice:"659",
  378. discount:"5.2"
  379. },{
  380. id:3,
  381. imgUrl:"../../static/logo.png",
  382. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  383. pprice:"299",
  384. oprice:"659",
  385. discount:"5.2"
  386. },
  387. {
  388. id:4,
  389. imgUrl:"../../static/logo.png",
  390. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  391. pprice:"299",
  392. oprice:"659",
  393. discount:"5.2"
  394. },
  395. ]
  396. },
  397. ]
  398. });
  399. });
  400. /* 运动户外第一次加载的数据 */
  401. router.get('/api/index_list/2/data/1', function(req, res, next) {
  402. res.send({
  403. code:"0",
  404. data:[
  405. {
  406. type:"bannerList",
  407. imgUrl:"../../static/img/b3.jpg",
  408. },
  409. {
  410. type:"iconsList",
  411. data:[
  412. {
  413. imgUrl:"../../static/logo.png",name:"运动户外"},
  414. {
  415. imgUrl:"../../static/logo.png",name:"运动户外"},
  416. {
  417. imgUrl:"../../static/logo.png",name:"运动户外"},
  418. {
  419. imgUrl:"../../static/logo.png",name:"运动户外"},
  420. {
  421. imgUrl:"../../static/logo.png",name:"运动户外"},
  422. {
  423. imgUrl:"../../static/logo.png",name:"运动户外"},
  424. {
  425. imgUrl:"../../static/logo.png",name:"运动户外"},
  426. {
  427. imgUrl:"../../static/logo.png",name:"运动户外"}
  428. ]
  429. },
  430. {
  431. type:"hotList",
  432. data:[
  433. {
  434. id:1,
  435. imgUrl:"../../static/logo.png",
  436. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  437. pprice:"299",
  438. oprice:"659",
  439. discount:"5.2"
  440. },
  441. {
  442. id:2,
  443. imgUrl:"../../static/logo.png",
  444. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  445. pprice:"299",
  446. oprice:"659",
  447. discount:"5.2"
  448. },{
  449. id:3,
  450. imgUrl:"../../static/logo.png",
  451. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  452. pprice:"299",
  453. oprice:"659",
  454. discount:"5.2"
  455. }
  456. ]
  457. },
  458. {
  459. type:"shopList",
  460. data:[
  461. {
  462. bigUrl:"../../static/img/b3.jpg",
  463. data:[
  464. {
  465. id:1,
  466. imgUrl:"../../static/logo.png",
  467. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  468. pprice:"299",
  469. oprice:"659",
  470. discount:"5.2"
  471. },
  472. {
  473. id:2,
  474. imgUrl:"../../static/logo.png",
  475. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  476. pprice:"299",
  477. oprice:"659",
  478. discount:"5.2"
  479. },{
  480. id:3,
  481. imgUrl:"../../static/logo.png",
  482. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  483. pprice:"299",
  484. oprice:"659",
  485. discount:"5.2"
  486. },
  487. {
  488. id:4,
  489. imgUrl:"../../static/logo.png",
  490. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  491. pprice:"299",
  492. oprice:"659",
  493. discount:"5.2"
  494. }
  495. ]
  496. }
  497. ],
  498. },
  499. {
  500. type:"commodityList",
  501. data:[
  502. {
  503. id:1,
  504. imgUrl:"../../static/logo.png",
  505. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  506. pprice:"299",
  507. oprice:"659",
  508. discount:"5.2"
  509. },
  510. {
  511. id:2,
  512. imgUrl:"../../static/logo.png",
  513. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  514. pprice:"299",
  515. oprice:"659",
  516. discount:"5.2"
  517. },{
  518. id:3,
  519. imgUrl:"../../static/logo.png",
  520. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  521. pprice:"299",
  522. oprice:"659",
  523. discount:"5.2"
  524. },
  525. {
  526. id:4,
  527. imgUrl:"../../static/logo.png",
  528. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  529. pprice:"299",
  530. oprice:"659",
  531. discount:"5.2"
  532. },
  533. ]
  534. },
  535. ]
  536. });
  537. });
  538. /* 服饰内衣第一次加载的数据 */
  539. router.get('/api/index_list/3/data/1', function(req, res, next) {
  540. res.send({
  541. code:"0",
  542. data:[
  543. {
  544. type:"bannerList",
  545. imgUrl:"../../static/img/b3.jpg",
  546. },
  547. {
  548. type:"iconsList",
  549. data:[
  550. {
  551. imgUrl:"../../static/logo.png",name:"服饰内衣"},
  552. {
  553. imgUrl:"../../static/logo.png",name:"服饰内衣"},
  554. {
  555. imgUrl:"../../static/logo.png",name:"服饰内衣"},
  556. {
  557. imgUrl:"../../static/logo.png",name:"服饰内衣"},
  558. {
  559. imgUrl:"../../static/logo.png",name:"服饰内衣"},
  560. {
  561. imgUrl:"../../static/logo.png",name:"服饰内衣"},
  562. {
  563. imgUrl:"../../static/logo.png",name:"服饰内衣"},
  564. {
  565. imgUrl:"../../static/logo.png",name:"服饰内衣"}
  566. ]
  567. },
  568. {
  569. type:"hotList",
  570. data:[
  571. {
  572. id:1,
  573. imgUrl:"../../static/logo.png",
  574. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  575. pprice:"299",
  576. oprice:"659",
  577. discount:"5.2"
  578. },
  579. {
  580. id:2,
  581. imgUrl:"../../static/logo.png",
  582. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  583. pprice:"299",
  584. oprice:"659",
  585. discount:"5.2"
  586. },{
  587. id:3,
  588. imgUrl:"../../static/logo.png",
  589. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  590. pprice:"299",
  591. oprice:"659",
  592. discount:"5.2"
  593. }
  594. ]
  595. },
  596. {
  597. type:"shopList",
  598. data:[
  599. {
  600. bigUrl:"../../static/img/b3.jpg",
  601. data:[
  602. {
  603. id:1,
  604. imgUrl:"../../static/logo.png",
  605. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  606. pprice:"299",
  607. oprice:"659",
  608. discount:"5.2"
  609. },
  610. {
  611. id:2,
  612. imgUrl:"../../static/logo.png",
  613. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  614. pprice:"299",
  615. oprice:"659",
  616. discount:"5.2"
  617. },{
  618. id:3,
  619. imgUrl:"../../static/logo.png",
  620. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  621. pprice:"299",
  622. oprice:"659",
  623. discount:"5.2"
  624. },
  625. {
  626. id:4,
  627. imgUrl:"../../static/logo.png",
  628. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  629. pprice:"299",
  630. oprice:"659",
  631. discount:"5.2"
  632. }
  633. ]
  634. }
  635. ],
  636. },
  637. {
  638. type:"commodityList",
  639. data:[
  640. {
  641. id:1,
  642. imgUrl:"../../static/logo.png",
  643. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  644. pprice:"299",
  645. oprice:"659",
  646. discount:"5.2"
  647. },
  648. {
  649. id:2,
  650. imgUrl:"../../static/logo.png",
  651. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  652. pprice:"299",
  653. oprice:"659",
  654. discount:"5.2"
  655. },{
  656. id:3,
  657. imgUrl:"../../static/logo.png",
  658. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  659. pprice:"299",
  660. oprice:"659",
  661. discount:"5.2"
  662. },
  663. {
  664. id:4,
  665. imgUrl:"../../static/logo.png",
  666. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  667. pprice:"299",
  668. oprice:"659",
  669. discount:"5.2"
  670. },
  671. ]
  672. },
  673. ]
  674. });
  675. });
  676. /* 首页推荐数据 */
  677. router.get('/api/index_list/data', function(req, res, next) {
  678. res.send({
  679. "code":0,
  680. "data":{
  681. topBar:[
  682. {
  683. id:1,name:'推荐'},
  684. {
  685. id:2,name:'运动户外'},
  686. {
  687. id:3,name:'服饰内衣'},
  688. {
  689. id:4,name:'鞋靴箱包'},
  690. {
  691. id:5,name:'美妆个护'},
  692. {
  693. id:6,name:'家居数码'},
  694. {
  695. id:7,name:'食品母婴'}
  696. ],
  697. data:[
  698. {
  699. type:"swiperList",
  700. data:[
  701. {
  702. imgUrl:'/static/img/b3.jpg'},
  703. {
  704. imgUrl:'/static/img/b3.jpg'},
  705. {
  706. imgUrl:'/static/img/b3.jpg'}
  707. ]
  708. },{
  709. type:"recommendList",
  710. data:[
  711. {
  712. bigUrl:"../../static/img/b3.jpg",
  713. data:[
  714. {
  715. imgUrl:'../../static/logo.png'},
  716. {
  717. imgUrl:'../../static/logo.png'},
  718. {
  719. imgUrl:'../../static/logo.png'}
  720. ]
  721. },{
  722. bigUrl:"../../static/img/b3.jpg",
  723. data:[
  724. {
  725. imgUrl:'../../static/logo.png'},
  726. {
  727. imgUrl:'../../static/logo.png'},
  728. {
  729. imgUrl:'../../static/logo.png'}
  730. ]
  731. }
  732. ]
  733. },{
  734. type:"commodityList",
  735. data:[
  736. {
  737. id:1,
  738. imgUrl:"../../static/logo.png",
  739. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  740. pprice:"299",
  741. oprice:"659",
  742. discount:"5.2"
  743. },
  744. {
  745. id:2,
  746. imgUrl:"../../static/logo.png",
  747. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  748. pprice:"299",
  749. oprice:"659",
  750. discount:"5.2"
  751. },{
  752. id:3,
  753. imgUrl:"../../static/logo.png",
  754. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  755. pprice:"299",
  756. oprice:"659",
  757. discount:"5.2"
  758. },
  759. {
  760. id:4,
  761. imgUrl:"../../static/logo.png",
  762. name:"迪奥绒毛大衣,今年必抢,错过瞬时不爽了,爆款疯狂销售",
  763. pprice:"299",
  764. oprice:"659",
  765. discount:"5.2"
  766. },
  767. ]
  768. },
  769. ]
  770. }
  771. })
  772. });
  773. module.exports = router;

手机号注册页面 login-code.vue

  1. <template>
  2. <view>
  3. <Lines></Lines>
  4. <view class="login-tel">
  5. <view class="tel-main">
  6. <view class="login-from">
  7. <view class="login-user">
  8. <text class="user-text">验证码</text>
  9. <input type="text" focus="true" v-model="userCode" placeholder="请输入验证码">
  10. <button plain="true" size="mini" :disabled="disabled" @tap="sendCode">{
  11. {
  12. codeMsg}}</button>
  13. </view>
  14. </view>
  15. <view class="tel" @click="getNextIndex">下一步</view>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import $http from '@/common/api/request.js'
  22. import Lines from '@/components/common/Lines.vue'
  23. import {
  24. mapMutations} from 'vuex'
  25. export default {
  26. data() {
  27. return {
  28. //用户输入的验证码
  29. userCode:"",
  30. // 倒计时时间
  31. codeNum:60,
  32. // 显示的文本
  33. codeMsg:"",
  34. // 按钮是否禁用
  35. disabled:false,
  36. // 手机号
  37. phone:'',
  38. // 得到的验证码
  39. getCode:"",
  40. };
  41. },
  42. components:{
  43. Lines
  44. },
  45. onReady() {
  46. this.codeMsg = '重新发送('+this.codeNum+')';
  47. this.sendCode();
  48. },
  49. onLoad(e) {
  50. this.phone = e.phone;
  51. },
  52. methods:{
  53. ...mapMutations(['login']),
  54. sendCode(){
  55. // 请求接口返回验证码
  56. $http.request({
  57. url:'/code',
  58. method:"POST",
  59. data:{
  60. userName: this.phone
  61. }
  62. }).then((res)=>{
  63. console.log(res.code);
  64. this.getCode = res.code;
  65. }).catch(()=>{
  66. uni.showToast({
  67. title:'请求失败',
  68. icon:'none'
  69. })
  70. })
  71. this.disabled = true;
  72. let timer = setInterval(()=>{
  73. --this.codeNum;
  74. this.codeMsg = '重新发送('+this.codeNum+')';
  75. },1000);
  76. setTimeout(()=>{
  77. clearInterval(timer);
  78. this.codeNum = 60;
  79. this.disabled = false;
  80. this.codeMsg = '重新发送';
  81. },60000)
  82. },
  83. // 点击下一步
  84. getNextIndex(){
  85. if( this.getCode == this.userCode ){
  86. // 请求后端接口 => 往数据库增加一条数据
  87. $http.request({
  88. url:'/addUser',
  89. method:"POST",
  90. data:{
  91. userName: this.phone,
  92. code:this.userCode
  93. }
  94. }).then((res)=>{
  95. console.log(res);
  96. // 注册成功
  97. if( res.success ){
  98. uni.showToast({
  99. title:res.msg,
  100. icon:'none'
  101. })
  102. // 获取数据,注册成功后直接登录
  103. this.login(res.data)
  104. setTimeout(()=>{
  105. uni.redirectTo({
  106. url:"../index/index"
  107. })
  108. },2000)
  109. }
  110. }).catch(()=>{
  111. uni.showToast({
  112. title:'请求失败',
  113. icon:'none'
  114. })
  115. })
  116. }else{
  117. uni.showToast({
  118. title:"验证码错误",
  119. icon:"none"
  120. })
  121. }
  122. // uni.switchTab({
  123. // url:'/pages/index/index'
  124. // })
  125. }
  126. },
  127. }
  128. </script>
  129. <style lang="scss">
  130. .login-tel{
  131. width: 100vw;
  132. height: 100vh;
  133. }
  134. .tel-main{
  135. padding: 0 20rpx;
  136. }
  137. .login-from{
  138. padding: 30rpx 0;
  139. }
  140. .tel{
  141. width: 100%;
  142. height: 80rpx;
  143. line-height: 80rpx;
  144. text-align: center;
  145. color: #fff;
  146. background-color: #40bde8;
  147. border-radius: 40rpx;
  148. }
  149. .login-user{
  150. font-size: 40rpx;
  151. padding: 10rpx 0 ;
  152. display: flex;
  153. align-items: center;
  154. border-bottom: 2rpx solid #f7f7f7;
  155. }
  156. .user-text{
  157. padding-right: 10rpx;
  158. }
  159. </style>

目录结构

前端目录结构
  • manifest.json 配置文件: appid、logo…
  • pages.json 配置文件: 导航、 tabbar、 路由
  • main.js vue初始化入口文件
  • App.vue 全局配置:样式、全局监视
  • static 静态资源:图片、字体图标
  • page 页面

    • index

      • index.vue
    • list

      • list.vue
    • my

      • my.vue
    • my-config

      • my-config.vue
    • my-config

      • my-config.vue
    • my-add-path

      • my-add-path.vue
    • my-path-list

      • my-path-list.vue
    • search

      • search.vue
    • search-list

      • search-list.vue
    • shopcart

      • shopcart.vue
    • details

      • details.vue
    • my-order

      • my-order.vue
    • confirm-order

      • confirm-order.vue
    • payment

      • payment.vue
    • payment-success

      • payment-success.vue
    • login

      • login.vue
    • login-tel

      • login-tel.vue
    • login-code

      • login-code.vue
  • components 组件

    • index

      • Banner.vue
      • Hot.vue
      • Icons.vue
      • indexSwiper.vue
      • Recommend.vue
      • Shop.vue
      • Tabbar.vue
    • common

      • Card.vue
      • Commondity.vue
      • CommondityList.vue
      • Line.vue
      • ShopList.vue
    • order

      • order-list.vue
    • uni

      • uni-number-box

        • uni-number-box.vue
      • uni-icons

        • uni-icons.vue
      • uni-nav-bar

        • uni-nav-bar.vue
      • mpvue-citypicker

        • mpvueCityPicker.vue
  • common 公共文件:全局css文件 || 全局js文件

    • api

      • request.js
    • common.css
    • uni.css
  • store vuex状态机文件

    • modules

      • cart.js
      • path.js
      • user.js
    • index.js

发表评论

表情:
评论列表 (有 0 条评论,175人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Android项目实战登录&注册

    由于项目中大部分界面都有一个后退键和一个标题栏,为避免代码冗杂以及便于利用,我们可以将后推荐和标题栏单独抽取出来定义一个标题栏布局,在 res/layout 目录下新建一个 L