login.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <view>
  3. <view class="remain">
  4. <h1>欢迎回来</h1>
  5. <view class="wel">请登录您的账号</view>
  6. </view>
  7. <view class="form">
  8. <u-form :model="form" ref="uForm" label-width="100px" label-position="top">
  9. <u-form-item label="手机号" prop="phone">
  10. <view class="form-input">
  11. <u-input v-model="form.phone" type="number" border="surround" maxlength='11'
  12. placeholder='请输入手机号码' :clearable='false' />
  13. </view>
  14. </u-form-item>
  15. <u-form-item label="密码" prop="password">
  16. <view class="form-input">
  17. <u-input v-model="form.password" type="password" placeholder='请输入密码' :clearable='false' />
  18. </view>
  19. </u-form-item>
  20. </u-form>
  21. <view style="font-size: 13px;">忘记密码?</view>
  22. <view class="btn">
  23. <view style="margin-bottom: 10px;">
  24. <u-radio-group v-model="value" :wrap="true">
  25. <u-radio :label="radioLabel"></u-radio>
  26. </u-radio-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()">还没有账号?马上注册</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: '',
  71. }
  72. },
  73. onReady() {
  74. this.$refs.uForm.setRules(this.rules);
  75. },
  76. methods: {
  77. loginFn() {
  78. if (!this.form.key) {
  79. this.$common.toast('请输入登录名');
  80. return;
  81. }
  82. if (!this.form.password) {
  83. this.$common.toast('请输入密码');
  84. return;
  85. }
  86. let openid = uni.getStorageSync('openid');
  87. if (!openid) {
  88. openid = uni.getStorageSync('login_openid');
  89. }
  90. this.form.openid = openid
  91. this.$api.doLogin(this.form).then(resp => {
  92. let data = resp.data;
  93. })
  94. },
  95. submit() {
  96. this.$refs.uForm.validate().then(res => {
  97. this.$api.doLogin(this.form).then(resp => {
  98. console.log(resp)
  99. let data = resp.data;
  100. if(resp.code==200){
  101. let data = resp.data;
  102. uni.$u.toast('登录成功,欢迎你'+data.appUser.name)
  103. localStorage.setItem('token',data.tokenInfo.tokenValue)
  104. uni.navigateTo({
  105. url: '/pages/login/chooseRole'
  106. });
  107. }
  108. })
  109. }).catch(errors => {
  110. uni.$u.toast('校验失败')
  111. })
  112. },
  113. radioChange() {
  114. console.log("1111")
  115. },
  116. toRegister() {
  117. uni.navigateTo({
  118. url: '/pages/login/register'
  119. });
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="scss">
  125. page {
  126. background-color: #fff;
  127. padding: 30px;
  128. }
  129. .remain {
  130. margin: 40px 50px 0;
  131. text-align: center;
  132. }
  133. .wel {
  134. margin-top: 10px;
  135. }
  136. .form {
  137. // margin: 0 30px;
  138. height: 200px;
  139. // display: flex;
  140. // align-items: center;
  141. // justify-content: center;
  142. }
  143. .form-input {
  144. width: 100%;
  145. background-color: #E8E8E8;
  146. border-radius: 5px;
  147. margin-top: 5px;
  148. }
  149. .btn {
  150. margin: 25px 10px;
  151. }
  152. .tip {
  153. margin-top: 30px;
  154. text-align: center;
  155. font-size: 14px;
  156. }
  157. </style>