login.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. sliderVerifyFLag: false, //滑块验证
  42. form: {
  43. phone: '',
  44. password: ''
  45. },
  46. rules: {
  47. phone: [{
  48. required: true,
  49. message: '请输入手机号',
  50. trigger: 'blur,change'
  51. },
  52. {
  53. // 自定义验证函数,见上说明
  54. validator: (rule, value, callback) => {
  55. // 上面有说,返回true表示校验通过,返回false表示不通过
  56. // uni.$u.test.mobile()就是返回true或者false的
  57. // return uni.$u.test.mobile(value);
  58. },
  59. message: '手机号码不正确',
  60. // 触发器可以同时用blur和change
  61. trigger: ['change', 'blur'],
  62. }
  63. ],
  64. password: [{
  65. required: true,
  66. message: '请输入密码',
  67. trigger: 'blur,change'
  68. }]
  69. },
  70. radioLabel: "",
  71. value: ["1"],
  72. }
  73. },
  74. onReady() {
  75. this.$refs.uForm.setRules(this.rules);
  76. },
  77. methods: {
  78. submit() {
  79. this.$refs.uForm.validate().then(res => {
  80. let value = this.value;
  81. if (value.length == 0) {
  82. this.$common.toast('请先同意协议');
  83. return;
  84. }
  85. this.$api.doLogin(this.form).then(resp => {
  86. if (resp.code == 200) {
  87. let data = resp.data;
  88. uni.setStorageSync('token', data.tokenInfo.tokenValue);
  89. uni.setStorageSync('info', data.appUser)
  90. uni.setStorageSync('menu', data.per_list)
  91. this.$common.toBar('/pages/index/index')
  92. }
  93. })
  94. }).catch(errors => {
  95. uni.$u.toast('校验失败')
  96. })
  97. },
  98. toRegister() {
  99. this.$common.to('/pages/login/chooseRole')
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss">
  105. page {
  106. background-color: #fff;
  107. padding: 30px;
  108. }
  109. .remain {
  110. margin: 30rpx 150rpx 0;
  111. text-align: center;
  112. }
  113. .wel {
  114. margin-top: 10px;
  115. }
  116. .form {
  117. // margin: 0 30px;
  118. height: 200px;
  119. // display: flex;
  120. // align-items: center;
  121. // justify-content: center;
  122. }
  123. .form-input {
  124. width: 100%;
  125. background-color: #f5f5f5;
  126. margin-top: 10rpx;
  127. border-radius: 20rpx;
  128. border: none;
  129. }
  130. .btn {
  131. margin: 25px 10px;
  132. }
  133. .tip {
  134. margin-top: 30px;
  135. text-align: center;
  136. font-size: 14px;
  137. }
  138. .blue-class {
  139. color: #55aaff;
  140. cursor: pointer;
  141. }
  142. .register_btn {
  143. text-decoration: underline;
  144. margin-left: 0.5em;
  145. }
  146. </style>