login.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view>
  3. <view class="remain">
  4. <h1>账号登录</h1>
  5. </view>
  6. <view class="form">
  7. <u-form :model="form" ref="uForm" label-width="100px" label-position="top">
  8. <u-form-item label="手机号" prop="phone">
  9. <view class="form-input">
  10. <u-input v-model="form.phone" type="number" border="surround" maxlength='11'
  11. placeholder='请输入手机号码' :clearable='false' />
  12. </view>
  13. </u-form-item>
  14. <u-form-item label="密码" prop="password">
  15. <view class="form-input">
  16. <u-input v-model="form.password" type="password" placeholder='请输入密码' :clearable='false' />
  17. </view>
  18. </u-form-item>
  19. </u-form>
  20. <view style="font-size: 13px;">忘记密码?</view>
  21. <view class="btn">
  22. <view style="margin-bottom: 20rpx;font-size: 28rpx;">
  23. <u-checkbox-group v-model="value" :wrap="true">
  24. <u-checkbox name="1"></u-checkbox>登录同意<text class="blue-class">《用户协议》</text>和<text
  25. class="blue-class">《隐私政策》</text>
  26. </u-checkbox-group>
  27. </view>
  28. <view>
  29. <u-button type="error" shape="circle" text="登录" @click="submit()"></u-button>
  30. </view>
  31. <view class="tip" @click="toRegister()">还没有账号?马上<text class="register_btn blue-class">注册</text></view>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. sliderVerifyFLag: false, //滑块验证
  41. form: {
  42. phone: '',
  43. password: ''
  44. },
  45. rules: {
  46. phone: [{
  47. required: true,
  48. message: '请输入手机号',
  49. trigger: 'blur,change'
  50. },
  51. {
  52. // 自定义验证函数,见上说明
  53. validator: (rule, value, callback) => {
  54. // 上面有说,返回true表示校验通过,返回false表示不通过
  55. // uni.$u.test.mobile()就是返回true或者false的
  56. return uni.$u.test.mobile(value);
  57. },
  58. message: '手机号码不正确',
  59. // 触发器可以同时用blur和change
  60. trigger: ['change', 'blur'],
  61. }
  62. ],
  63. password: [{
  64. required: true,
  65. message: '请输入密码',
  66. trigger: 'blur,change'
  67. }]
  68. },
  69. radioLabel: "",
  70. value: ["1"],
  71. }
  72. },
  73. onReady() {
  74. this.$refs.uForm.setRules(this.rules);
  75. },
  76. methods: {
  77. submit() {
  78. this.$refs.uForm.validate().then(res => {
  79. let value = this.value;
  80. if (value.length == 0) {
  81. this.$common.toast('请先同意协议');
  82. return;
  83. }
  84. this.$api.doLogin(this.form).then(resp => {
  85. if (resp.code == 200) {
  86. let data = resp.data;
  87. uni.setStorageSync('token', data.tokenInfo.tokenValue);
  88. uni.setStorageSync('info',data.appUser)
  89. this.$common.toBar('/pages/index/index')
  90. }
  91. })
  92. }).catch(errors => {
  93. uni.$u.toast('校验失败')
  94. })
  95. },
  96. toRegister() {
  97. this.$common.to('/pages/login/chooseRole')
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss">
  103. page {
  104. background-color: #fff;
  105. padding: 30px;
  106. }
  107. .remain {
  108. margin: 30rpx 150rpx 0;
  109. text-align: center;
  110. }
  111. .wel {
  112. margin-top: 10px;
  113. }
  114. .form {
  115. // margin: 0 30px;
  116. height: 200px;
  117. // display: flex;
  118. // align-items: center;
  119. // justify-content: center;
  120. }
  121. .form-input {
  122. width: 100%;
  123. background-color: #f5f5f5;
  124. margin-top: 10rpx;
  125. border-radius: 20rpx;
  126. border: none;
  127. }
  128. .btn {
  129. margin: 25px 10px;
  130. }
  131. .tip {
  132. margin-top: 30px;
  133. text-align: center;
  134. font-size: 14px;
  135. }
  136. .blue-class {
  137. color: #55aaff;
  138. cursor: pointer;
  139. }
  140. .register_btn {
  141. text-decoration: underline;
  142. margin-left: 0.5em;
  143. }
  144. </style>