当前位置:   article > 正文

微信小程序之登录功能的实现 (对表单的校验)_wx.showmodal密码

wx.showmodal密码

我的qq 2038373094

我做的是微信小程序、网站、手机app,后端java+前端vue、bootstrap框架、原生的html+css+js都会

做过律师在线咨询系统、共享农场手机app、在线心理咨询系统

 

 

效果图如下

wxml文件如下

  1. <view>
  2. <view class="frm">
  3. <view class="ui-row ui-row-border-top ui-row-border-bottom" style="margin-bottom: 20px;height:40px;">
  4. <view class="ui-col ui-col-border-right ui-col-align-center align-center valign-middle" style="flex:0 0 60px;">
  5. <view class="ui-col-content align-center valign-middle">
  6. </view>
  7. </view>
  8. <view class="ui-col" style="">
  9. <view class="ui-col-content">
  10. <view class="ui-row" style="height:40px;">
  11. <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;">
  12. <view class="ui-col-content align-center valign-middle">
  13. 教师用户名
  14. </view>
  15. </view>
  16. <view class="ui-col ui-col-8 ui-col-align-center align-center valign-middle" style="flex: 0 0 66.66666666666666%;">
  17. <view class="ui-col-content align-center valign-middle">
  18. <input name="input" placeholder="请输入用户名" bindinput="username"></input>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="ui-row ui-row-border-top ui-row-border-bottom" style="margin-bottom: 20px;height:40px;">
  26. <view class="ui-col ui-col-border-right ui-col-align-center align-center valign-middle" style="flex:0 0 60px;">
  27. <view class="ui-col-content align-center valign-middle">
  28. </view>
  29. </view>
  30. <view class="ui-col" style="">
  31. <view class="ui-col-content">
  32. <view class="ui-row" style="height:40px;">
  33. <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;">
  34. <view class="ui-col-content align-center valign-middle">
  35. 密码
  36. </view>
  37. </view>
  38. <view class="ui-col ui-col-8 ui-col-align-center align-center valign-middle" style="flex: 0 0 66.66666666666666%;">
  39. <view class="ui-col-content align-center valign-middle">
  40. <input placeholder="设置密码" password="true" bindinput="password"></input>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="ui-row ui-row-border-top ui-row-border-bottom" style="margin-bottom: 20px;height:40px;">
  48. <view class="ui-col ui-col-border-right ui-col-align-center align-center valign-middle" style="flex:0 0 60px;">
  49. <view class="ui-col-content align-center valign-middle">
  50. </view>
  51. </view>
  52. <view class="ui-col" style="">
  53. <view class="ui-col-content">
  54. <view class="ui-row" style="height:40px;">
  55. <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;">
  56. <view class="ui-col-content align-center valign-middle">
  57. <button type="primary" bindtap="submitHandler">教师登录</button>
  58. </view>
  59. </view>
  60. <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;">
  61. <view class="ui-col-content align-center valign-middle">
  62. <button bindtap="treg">教师注册</button>
  63. </view>
  64. </view>
  65. <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;">
  66. <view class="ui-col-content align-center valign-middle">
  67. <button bindtap="ulogin">用户登录</button>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>

 

js文件如下

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = Page({
  6. data: {
  7. name: "",
  8. pass: "",
  9. isname: false,
  10. ispass: false
  11. },
  12. treg: function treg() {
  13. wx.navigateTo({
  14. url: "./../teacher/tregdit"
  15. });
  16. },
  17. ulogin: function ulogin() {
  18. wx.navigateTo({
  19. url: "./../ulogin/ulogin"
  20. });
  21. },
  22. username: function username(e) {
  23. this.setData({ name: e.detail.value });
  24. },
  25. password: function password(e) {
  26. this.setData({ pass: e.detail.value });
  27. },
  28. submitHandler: function submitHandler() {
  29. var that = this;
  30. if (that.data.name == "") {
  31. wx.showModal({
  32. title: "错误",
  33. content: "用户名不能为空"
  34. });
  35. that.isname = false;
  36. } else {
  37. that.isname = true;
  38. }
  39. if (that.data.pass == "") {
  40. wx.showModal({
  41. title: "错误",
  42. content: "密码不能为空"
  43. });
  44. that.ispass = false;
  45. } else {
  46. that.ispass = true;
  47. }
  48. if (that.ispass && that.isname) {
  49. // 提交
  50. wx.request({
  51. url: "http://localhost:8080/Teacher/tlogin.action", //接口地址
  52. data: {
  53. username: that.data.name,
  54. password: that.data.pass
  55. },
  56. method: "get",
  57. header: {
  58. "content-type": "application/json"
  59. },
  60. success: function success(res) {
  61. var info = res.data;
  62. console.log(info);
  63. if (info == "fail") {
  64. wx.showModal({
  65. title: '错误',
  66. content: '用户名或者密码输入不正确'
  67. });
  68. } else {
  69. //存储数据
  70. wx.setStorage('uname', that.data.name);
  71. wx.setStorage('indentity', 'teacher');
  72. //页面跳转
  73. wx.navigateTo({
  74. url: "./../center/center"
  75. });
  76. //页面跳转
  77. }
  78. }
  79. });
  80. // 提交
  81. }
  82. }
  83. });

 

wxss文件如下

  1. .frm {
  2. margin-top: 200rpx;
  3. }

 

我的后台是用Java写的,采用的是ssh框架,在这里就不写出来了,没什么意思!

附上一份.wx的代码

  1. <template>
  2. <view>
  3. <view class="frm">
  4. <ui-row height="40" border-top border-bottom space-bottom="20">
  5. <ui-col width="60" border-right vertical-align="middle" align="center">
  6. </ui-col>
  7. <ui-col>
  8. <ui-row height="40">
  9. <ui-col span="4" border-right vertical-align="middle" align="center">
  10. 教师用户名
  11. </ui-col>
  12. <ui-col span="8" vertical-align="middle" align="center">
  13. <input name="input" placeholder="请输入用户名" bindinput="username"/>
  14. </ui-col>
  15. </ui-row>
  16. </ui-col>
  17. </ui-row>
  18. <ui-row height="40" border-top border-bottom space-bottom="20">
  19. <ui-col width="60" border-right vertical-align="middle" align="center">
  20. </ui-col>
  21. <ui-col>
  22. <ui-row height="40">
  23. <ui-col span="4" border-right vertical-align="middle" align="center">
  24. 密码
  25. </ui-col>
  26. <ui-col span="8" vertical-align="middle" align="center">
  27. <input placeholder="设置密码" password="true" bindinput="password"/>
  28. </ui-col>
  29. </ui-row>
  30. </ui-col>
  31. </ui-row>
  32. <ui-row height="40" border-top border-bottom space-bottom="20">
  33. <ui-col width="60" border-right vertical-align="middle" align="center">
  34. </ui-col>
  35. <ui-col>
  36. <ui-row height="40">
  37. <ui-col span="4" border-right vertical-align="middle" align="center">
  38. <button type="primary" bindtap="submitHandler" >教师登录</button>
  39. </ui-col>
  40. <ui-col span="4" border-right vertical-align="middle" align="center">
  41. <button bindtap="treg">教师注册</button>
  42. </ui-col>
  43. <ui-col span="4" border-right vertical-align="middle" align="center">
  44. <button bindtap="ulogin">用户登录</button>
  45. </ui-col>
  46. </ui-row>
  47. </ui-col>
  48. </ui-row>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. config: {
  54. navigationBarTitleText: "教师登录页面"
  55. },
  56. data: {
  57. name: "",
  58. pass: "",
  59. isname: false,
  60. ispass: false
  61. },
  62. treg: function() {
  63. wx.navigateTo({
  64. url: "./../teacher/tregdit"
  65. });
  66. },
  67. ulogin: function() {
  68. wx.navigateTo({
  69. url: "./../ulogin/ulogin"
  70. });
  71. },
  72. username: function(e) {
  73. this.setData({ name: e.detail.value });
  74. },
  75. password: function(e) {
  76. this.setData({ pass: e.detail.value });
  77. },
  78. submitHandler: function() {
  79. var that = this;
  80. if (that.data.name == "") {
  81. wx.showModal({
  82. title: "错误",
  83. content: "用户名不能为空"
  84. });
  85. that.isname = false;
  86. } else {
  87. that.isname = true;
  88. }
  89. if (that.data.pass == "") {
  90. wx.showModal({
  91. title: "错误",
  92. content: "密码不能为空"
  93. });
  94. that.ispass = false;
  95. } else {
  96. that.ispass = true;
  97. }
  98. if (that.ispass&&that.isname) {
  99. // 提交
  100. wx.request({
  101. url: "http://localhost:8080/Teacher/tlogin.action", //接口地址
  102. data: {
  103. username: that.data.name,
  104. password: that.data.pass
  105. },
  106. method: "get",
  107. header: {
  108. "content-type": "application/json"
  109. },
  110. success: res => {
  111. var info=res.data;
  112. console.log(info);
  113. if(info=="fail"){
  114. wx.showModal({
  115. title: '错误',
  116. content: '用户名或者密码输入不正确',
  117. })
  118. }else{
  119. //存储数据
  120. wx.setStorage('uname', that.data.name);
  121. wx.setStorage('indentity', 'teacher');
  122. //页面跳转
  123. wx.navigateTo({
  124. url: "./../center/center"
  125. });
  126. //页面跳转
  127. }
  128. }
  129. });
  130. // 提交
  131. }
  132. }
  133. };
  134. </script>
  135. <style lang="less">
  136. .frm {
  137. margin-top: 200rpx;
  138. }
  139. </style>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/131728
推荐阅读
相关标签