开始

image.png

  1. username:'',
  2. password:'',
  3. phone:'',
  4. checknum:''

双向绑定到菜单上
image.png

  1. v-model="username"
  2. v-model="password"
  3. v-model="phone"
  4. v-model="checknum"

写一个方法判断和改变按钮的状态。两个括号分别表示 账号密码登陆和手机验证码登陆。
image.png

image.png

image.png

  1. // 改变按钮状态
  2. OnBtnChange(){
  3. if((this.username && this.password) || (this.phone && this.checknum)){
  4. this.disabled=false;
  5. return;
  6. }
  7. this.disabled=true;
  8. },

起个监听。四个数值的变化都要调用这个方法。
image.png

  1. watch:{
  2. username(val){
  3. this.OnBtnChange();
  4. },
  5. password(val){
  6. this.OnBtnChange();
  7. },
  8. phone(val){
  9. this.OnBtnChange();
  10. },
  11. checknum(val){
  12. this.OnBtnChange();
  13. }
  14. },

登陆状态的切换清除当前表单的值

image.png

  1. // 初始化表单
  2. initInput(){
  3. this.username='';
  4. this.password='';
  5. this.phone='';
  6. this.checknum='';
  7. },

每次变化的时候清空表单
image.png

  1. // 切换登陆状态
  2. changeStatus() {
  3. this.initInput();
  4. this.status = !this.status;
  5. },

image.png
删除后,按钮禁用
image.png

image.png

本节代码

  1. <template>
  2. <view>
  3. <!-- 状态栏 -->
  4. <!-- <uni-status-bar></uni-status-bar> -->
  5. <uni-nav-bar background-color="#FFE933" status-bar />
  6. <!-- 关闭按钮 -->
  7. <view class="icon iconfont icon-guanbi" @tap="back"></view>
  8. <!-- 引入背景图 -->
  9. <image class="loginhead" src="../../static/common/loginhead.png" mode="widthFix" lazy-load></image>
  10. <view class="body">
  11. <!-- 账号密码登陆 -->
  12. <template v-if="!status">
  13. <view class="login-input-box">
  14. <!-- <view class="phone u-f-ajc">+86</view> -->
  15. <input type="text" v-model="username"
  16. class="uni-input common-input" placeholder="昵称/手机号/邮箱" />
  17. </view>
  18. <view class="login-input-box">
  19. <view class="login-input-box">
  20. <input type="text" v-model="password"
  21. class="uni-input common-input forget-input" placeholder="请输入密码" />
  22. <view class="forget u-f-ajc login-font-color">忘记密码</view>
  23. </view>
  24. </view>
  25. </template>
  26. <template v-else>
  27. <view class="login-input-box">
  28. <view class="phone u-f-ajc">+86</view>
  29. <input type="text" v-model="phone"
  30. class="uni-input common-input phone-input" placeholder="手机号" />
  31. </view>
  32. <view class="login-input-box">
  33. <input type="text" v-model="checknum"
  34. class="uni-input common-input forget-input" placeholder="验证码" />
  35. <view class="forget u-f-ajc login-font-color yanzhengma">
  36. <view class="u-f-ajc">
  37. 获取验证码
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <button class="user-set-btn" :class="{'user-set-btn-disable':disabled}" :loading="loading" @tap="submit"
  43. type="primary" :disabled="disabled">登陆</button>
  44. </view>
  45. <!-- 登陆状态切换 -->
  46. <view class="login-status u-f-ajc login-padding" @tap="changeStatus">
  47. {{status?'账号密码登陆':'验证码登陆'}}
  48. <view class="icon iconfont icon-jinru"></view>
  49. </view>
  50. <!-- 第三方登陆 -->
  51. <view class="other-login-title u-f-ajc login-padding">第三方登陆</view>
  52. <other-login></other-login>
  53. <!-- 协议 -->
  54. <view class="login-rule u-f-ajc login-padding login-font-color">
  55. 注册即代表您同意<view class="login-font-color">《XXXX协议》</view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import otherLogin from '@/components/home/other-login.vue';
  61. export default {
  62. components: {
  63. otherLogin
  64. },
  65. data() {
  66. return {
  67. status: false, // false代表账号密码登陆, true手机验证码登陆
  68. disabled: true,
  69. loading: false,
  70. username:'',
  71. password:'',
  72. phone:'',
  73. checknum:''
  74. }
  75. },
  76. watch:{
  77. username(val){
  78. this.OnBtnChange();
  79. },
  80. password(val){
  81. this.OnBtnChange();
  82. },
  83. phone(val){
  84. this.OnBtnChange();
  85. },
  86. checknum(val){
  87. this.OnBtnChange();
  88. }
  89. },
  90. methods: {
  91. // 初始化表单
  92. initInput(){
  93. this.username='';
  94. this.password='';
  95. this.phone='';
  96. this.checknum='';
  97. },
  98. // 改变按钮状态
  99. OnBtnChange(){
  100. if((this.username && this.password) || (this.phone && this.checknum)){
  101. this.disabled=false;
  102. return;
  103. }
  104. this.disabled=true;
  105. },
  106. // 切换登陆状态
  107. changeStatus() {
  108. this.initInput();
  109. this.status = !this.status;
  110. },
  111. back() {
  112. console.log('返回上一步');
  113. },
  114. submit() {
  115. console.log('提交登陆');
  116. }
  117. }
  118. }
  119. </script>
  120. <style>
  121. @import url('@/common/form.css');
  122. .login-padding {
  123. padding: 20upx;
  124. }
  125. .login-font-color {
  126. color: #BBBBBB;
  127. }
  128. .loginhead {
  129. width: 100%;
  130. margin-top: -5upx;
  131. }
  132. .icon-guanbi {
  133. position: fixed;
  134. top: 60upx;
  135. left: 30upx;
  136. font-size: 40upx;
  137. font-weight: bold;
  138. color: #332F0A;
  139. z-index: 100;
  140. }
  141. .other-login-title {
  142. position: relative;
  143. }
  144. .other-login-title::before,
  145. .other-login-title::after {
  146. content: '';
  147. position: absolute;
  148. background: #CCCCCC;
  149. height: 1upx;
  150. width: 100upx;
  151. top: 50%;
  152. }
  153. .other-login-title::before {
  154. left: 25%;
  155. }
  156. .other-login-title::after {
  157. right: 25%;
  158. }
  159. .login-input-box {
  160. position: relative;
  161. }
  162. .login-input-box .forget-input {
  163. padding-right: 150upx;
  164. }
  165. .login-input-box .forget {
  166. position: absolute;
  167. right: 0;
  168. top: 0;
  169. height: 100%;
  170. width: 150upx;
  171. /* background: yellow; */
  172. z-index: 100;
  173. }
  174. .login-input-box .phone {
  175. position: absolute;
  176. left: 0;
  177. top: 0;
  178. height: 100%;
  179. width: 100upx;
  180. z-index: 100;
  181. font-weight: bold;
  182. }
  183. .login-input-box .phone-input {
  184. padding-left: 100upx;
  185. }
  186. .yanzhengma view {
  187. background: #EEEEEE;
  188. border-radius: 10upx;
  189. font-size: 25upx;
  190. width: 150upx;
  191. padding: 10upx 0;
  192. }
  193. </style>

结束