login.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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" @click="getAgreement(1)">《用户协议》</text>和<text
  25. class="blue-class" @click="getAgreement(2)">《隐私政策》</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. 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. uni.setStorageSync('menu', data.per_list)
  90. this.$common.toBar('/pages/index/index')
  91. }
  92. })
  93. }).catch(errors => {
  94. uni.$u.toast('校验失败')
  95. })
  96. },
  97. toRegister() {
  98. this.$common.to('/pages/login/chooseRole')
  99. },
  100. getAgreement(id) {
  101. this.$common.to('/pages/login/userAgreement?id='+id)
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss">
  107. page {
  108. background-color: #fff;
  109. padding: 30px;
  110. }
  111. .remain {
  112. margin: 30rpx 150rpx 0;
  113. text-align: center;
  114. }
  115. .wel {
  116. margin-top: 10px;
  117. }
  118. .form {
  119. // margin: 0 30px;
  120. height: 200px;
  121. // display: flex;
  122. // align-items: center;
  123. // justify-content: center;
  124. }
  125. .form-input {
  126. width: 100%;
  127. background-color: #f5f5f5;
  128. margin-top: 10rpx;
  129. border-radius: 20rpx;
  130. border: none;
  131. }
  132. .btn {
  133. margin: 25px 10px;
  134. }
  135. .tip {
  136. margin-top: 30px;
  137. text-align: center;
  138. font-size: 14px;
  139. }
  140. .blue-class {
  141. color: #55aaff;
  142. cursor: pointer;
  143. }
  144. .register_btn {
  145. text-decoration: underline;
  146. margin-left: 0.5em;
  147. }
  148. </style>