• uni-app 之 短信验证码登录


    uni-app 之 短信验证码登录

    image.png

    image.png

    1. <template>
    2. <view style="width: 100%; display: flex; flex-direction:column; align-items:center;">
    3. <view style="width: 300px; margin-top: 100px;">
    4. <!-- // -->
    5. <!-- 1,输入手机号码,获取验证码 -->
    6. <view style="display: flex; ">
    7. <u-input placeholder="请输入手机号码" v-model="logon_phone" />
    8. <button @click="getphoneurl">验证码</button>
    9. </view>
    10. <!-- // -->
    11. <!-- 2,输入验证码,登录 -->
    12. <u-input placeholder="请输入验证码" v-model="logon_code" />
    13. <button @click="getcodeurl">登录</button>
    14. </view>
    15. <!-- 返回参数 -->
    16. <text>retCode={{urlretCode}}; </text>
    17. <text>retMsg={{curlretMsg}}; </text>
    18. <text>retdata={{curlretdata}}; </text>
    19. </view>
    20. </template>
    21. <script>
    22. export default {
    23. data() {
    24. return {
    25. // 返回參數
    26. urlretCode: "",
    27. curlretMsg: "",
    28. curlretdata: "",
    29. // 輸入框内容
    30. logon_phone: "",
    31. logon_code: "",
    32. };
    33. },
    34. methods: {
    35. // 按钮点击后执行的方法
    36. ///
    37. // 1,输入手机号码,获取验证码
    38. getphoneurl() {
    39. // uni.showLoading({
    40. // title: "加载中" // 加个进度条
    41. // })
    42. console.log("111 111 logon_phone 打印", this.logon_phone)
    43. uni.request({
    44. url: "https://api.xxx.com/sms/SendSms/" + this.logon_phone,
    45. success: res => {
    46. console.log("111 111 res 打印", res) // log打印获取的数据
    47. this.urlretCode = res.data.retCode
    48. this.curlretMsg = res.data.retMsg
    49. // uni.hideLoading() // 加载出来后,关闭进度条
    50. }
    51. })
    52. },
    53. ///
    54. // 2,输入验证码,登录
    55. getcodeurl() {
    56. // uni.showLoading({
    57. // title: "加载中" // 加个进度条
    58. // })
    59. let params = {
    60. // "phone": "177128xxxxx",
    61. // "verificationCode": "5546",
    62. "phone": this.logon_phone,
    63. "verificationCode": this.logon_code,
    64. }
    65. console.log("222 222 params 打印", params) // log打印获取的数据
    66. uni.request({
    67. method: 'post',
    68. url: "https://api.xxx.com/cusInfo/login",
    69. data: params,
    70. success: res => {
    71. console.log("222 222 res 打印", res) // log打印获取的数据
    72. this.urlretCode = res.data.retCode
    73. this.curlretMsg = res.data.retMsg
    74. this.curlretdata = res.data.data
    75. // 存储返回的token
    76. uni.setStorageSync('s_token', res.data.data);
    77. uni.setStorageSync('s_retCode', res.data.retCode);
    78. // 打印存储的token
    79. const token = uni.getStorageSync('s_token'); //获取token
    80. const g_phone = uni.getStorageSync('s_phone'); //获取token
    81. console.log("333 333 token>>>", token, g_phone) // log打印获取的数据
    82. if (token) {
    83. //存在则关闭前页面
    84. uni.navigateBack({
    85. //关闭当前页面,返回上一页面或多级页面。
    86. delta: 1
    87. });
    88. } else {
    89. //不存在则跳转至登录页
    90. // uni.reLaunch({
    91. // url: "/pages/ldy_logon/ldy_logon",
    92. // success: () => {
    93. // plus.navigator.closeSplashscreen();
    94. // }
    95. // })
    96. }
    97. }
    98. })
    99. },
    100. },
    101. onLoad() {
    102. // 页面刚进去就初始化的方法
    103. // this.getphoneurl(),
    104. // this.getcodeurl()
    105. },
    106. }
    107. </script>
    108. <style lang="scss">
    109. </style>
  • 相关阅读:
    ElasticSearch RestHighLevClient 之聚合操作
    11.19 - 每日一题 - 408
    CKKS同态加密方案初步学习
    centos7安装mysql5.7步骤(图解版)
    课堂练习10 python数据库编程
    NPOI组件下载、引用、基本使用
    Python之zipfile模块
    day38
    rust -枚举和模式匹配学习(二)
    智慧工地源码 手册文档 app 数据大屏、硬件对接、萤石云
  • 原文地址:https://blog.csdn.net/jun_tong/article/details/133341999