login.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view class="">
  3. <!-- 顶部导航 -->
  4. <fa-navbar title="登录"></fa-navbar>
  5. <view class="login">
  6. <!-- <view class="u-text-center"><u-avatar :size="150"></u-avatar></view> -->
  7. <view class="u-m-t-50">
  8. <u-form :model="form" :rules="rules" ref="uForm" :errorType="errorType">
  9. <u-form-item :label-position="labelPosition" label="账号:" prop="account" left-icon="account" label-width="120">
  10. <u-input :border="border" placeholder="邮箱/手机/用户名" v-model="form.account" />
  11. </u-form-item>
  12. <u-form-item :label-position="labelPosition" label="密码:" prop="password" left-icon="lock" label-width="120" v-if="!border">
  13. <u-input :password-icon="true" :border="border" type="password" v-model="form.password" placeholder="请输入密码"></u-input>
  14. </u-form-item>
  15. </u-form>
  16. </view>
  17. <view class="u-m-t-80">
  18. <u-button type="primary" hover-class="none" :custom-style="{ backgroundColor: theme.bgColor, color: theme.color }" shape="circle" @click="goLogin">登录</u-button>
  19. </view>
  20. <view class="u-flex u-row-between u-tips-color u-m-t-10 u-p-20">
  21. <view class="" @click="goPage(0)">忘记密码</view>
  22. <view class="" @click="goPage(1)">注册账号</view>
  23. </view>
  24. <view class="u-text-center other" v-if="isThreeLogin">
  25. <u-grid :col="1" :border="false">
  26. <u-grid-item @click="goThreeLogin">
  27. <u-icon name="weixin-fill" color="#53c240" :size="50"></u-icon>
  28. <view class="grid-text">微信</view>
  29. </u-grid-item>
  30. </u-grid>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import {loginfunc} from '@/common/fa.mixin.js'
  37. export default {
  38. mixins:[loginfunc],
  39. onLoad() {
  40. // #ifdef MP-WEIXIN || APP-PLUS
  41. this.isThreeLogin = true;
  42. // #endif
  43. // #ifdef H5
  44. if (this.$util.isWeiXinBrowser()) {
  45. this.isThreeLogin = true;
  46. }
  47. // #endif
  48. },
  49. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  50. onReady() {
  51. this.$refs.uForm.setRules(this.rules);
  52. },
  53. data() {
  54. return {
  55. labelPosition: 'top',
  56. border: false,
  57. errorType: ['message'],
  58. form: {
  59. account: '',
  60. password: ''
  61. },
  62. rules: {
  63. account: [
  64. {
  65. required: true,
  66. message: '请输入账号',
  67. // 可以单个或者同时写两个触发验证方式
  68. trigger: ['change', 'blur']
  69. }
  70. ],
  71. password: [
  72. {
  73. required: true,
  74. message: '请输入密码',
  75. trigger: 'change'
  76. }
  77. ]
  78. },
  79. isThreeLogin: false
  80. };
  81. },
  82. methods: {
  83. goPage(index) {
  84. let p = ['/pages/login/forgetpwd', '/pages/login/register'];
  85. this.$Router.push(p[index]);
  86. },
  87. goThreeLogin: async function() {
  88. // #ifdef MP-WEIXIN
  89. this.$Router.push('/pages/login/wxlogin?index=3');
  90. // #endif
  91. // #ifdef H5
  92. this.goAuth();
  93. // #endif
  94. // #ifdef APP-PLUS
  95. this.goAppLogin(2);
  96. // #endif
  97. },
  98. goLogin: function() {
  99. this.$refs.uForm.validate(async valid => {
  100. if (valid) {
  101. if (this.vuex_wx_uid) {
  102. this.form.wx_user_id = this.vuex_wx_uid;
  103. }
  104. let res = await this.$api.goLogin(this.form);
  105. if (!res.code) {
  106. this.$u.toast(res.msg);
  107. return;
  108. }
  109. this.$u.vuex('vuex_token', res.data.token);
  110. this.success(2);
  111. } else {
  112. this.$u.toast('验证失败');
  113. }
  114. });
  115. }
  116. }
  117. };
  118. </script>
  119. <style>
  120. page {
  121. background-color: #ffffff;
  122. }
  123. .login {
  124. padding: 80rpx 100rpx 0 100rpx;
  125. }
  126. .other {
  127. position: absolute;
  128. width: 100%;
  129. left: 0;
  130. bottom: 40rpx;
  131. }
  132. </style>