login.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div id="login">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <div class="w_1200">
  6. <el-col :span="24" class="info">
  7. <el-col :span="24" class="title">
  8. 中科在线(长春)-平台用户登录
  9. </el-col>
  10. <el-col :span="24" class="form">
  11. <el-form :model="form" :rules="rules" ref="form" label-width="100px">
  12. <el-form-item label="账号" prop="phone">
  13. <el-input v-model="form.phone" placeholder="请输入账号"></el-input>
  14. </el-form-item>
  15. <el-form-item label="密码" prop="password">
  16. <el-input v-model="form.password" placeholder="请输入密码" show-password></el-input>
  17. </el-form-item>
  18. <el-form-item label="用户类别" prop="type">
  19. <el-radio-group v-model="form.type">
  20. <el-radio label="4">个人用户</el-radio>
  21. <el-radio label="5">企业用户</el-radio>
  22. </el-radio-group>
  23. </el-form-item>
  24. <el-col :span="24" class="loginBtn">
  25. <el-button type="danger" @click="resetForm()">取消登录</el-button>
  26. <el-button type="primary" @click="submitForm('form')">确认登录</el-button>
  27. </el-col>
  28. </el-form>
  29. </el-col>
  30. <el-col :span="24" class="btn">
  31. <el-link type="danger" @click="registerBtn">注册账号</el-link>
  32. </el-col>
  33. </el-col>
  34. </div>
  35. </el-col>
  36. </el-row>
  37. </div>
  38. </template>
  39. <script>
  40. import { mapState, createNamespacedHelpers } from 'vuex';
  41. const { mapActions: personal } = createNamespacedHelpers('personal');
  42. const { mapActions: organization } = createNamespacedHelpers('organization');
  43. export default {
  44. metaInfo() {
  45. return { title: this.$route.meta.title };
  46. },
  47. name: 'login',
  48. props: {},
  49. components: {},
  50. data: function() {
  51. return {
  52. form: {},
  53. rules: {
  54. phone: [{ required: true, message: '请输入账号', trigger: 'blur' }],
  55. password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
  56. type: [{ required: true, message: '请选择用户类别', trigger: 'change' }],
  57. },
  58. };
  59. },
  60. created() {},
  61. methods: {
  62. ...personal(['perLogin']),
  63. ...organization(['orgLogin']),
  64. // 确认登录
  65. submitForm(formName) {
  66. this.$refs[formName].validate(async valid => {
  67. if (valid) {
  68. let data = this.form;
  69. if (data.type == '4') {
  70. let res = await this.perLogin({ user: data });
  71. if (this.$checkRes(res)) {
  72. this.$message.success('登录成功');
  73. this.$router.push('/userCenter');
  74. }
  75. } else if (data.type == '5') {
  76. data.institution_code = data.phone;
  77. let res = await this.orgLogin({ user: data });
  78. if (this.$checkRes(res)) {
  79. this.$message.success('登录成功');
  80. this.$router.push('/userCenter');
  81. }
  82. }
  83. // 存储用户类别
  84. localStorage.setItem('type', data.type);
  85. } else {
  86. console.log('error submit!!');
  87. return false;
  88. }
  89. });
  90. },
  91. // 取消登录
  92. resetForm() {
  93. this.$router.push({ path: '/' });
  94. },
  95. // 注册
  96. registerBtn() {
  97. this.$router.push({ path: '/register' });
  98. },
  99. },
  100. computed: {
  101. ...mapState(['user']),
  102. },
  103. watch: {},
  104. };
  105. </script>
  106. <style lang="less" scoped>
  107. .main {
  108. background: url('~@common/src/assets/login.jpg');
  109. background-repeat: no-repeat;
  110. background-size: 100% 100%;
  111. height: 100%;
  112. .info {
  113. width: 40%;
  114. height: 430px;
  115. background: #ffffff;
  116. position: relative;
  117. margin: 21% 30%;
  118. border-radius: 10px;
  119. .title {
  120. text-align: center;
  121. font-family: fangsong;
  122. color: #409eff;
  123. font-size: 28px;
  124. text-shadow: -1px 0 #fff, 0 1px #fff, 1px 0 #fff, 0 -1px #fff;
  125. font-weight: 600;
  126. padding: 30px 0;
  127. }
  128. .form {
  129. padding: 0 25px;
  130. height: 300px;
  131. overflow: hidden;
  132. /deep/.el-form-item__label {
  133. font-size: 18px;
  134. }
  135. .loginBtn {
  136. text-align: center;
  137. padding: 20px 0;
  138. }
  139. }
  140. .btn {
  141. text-align: right;
  142. padding: 0 10px;
  143. .el-link {
  144. font-size: 18px;
  145. }
  146. }
  147. }
  148. }
  149. </style>