Login.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div class="login-par">
  3. <div class="changeLanguage">
  4. <span @click="changeLanguage" :class="$i18n.locale=='zh-CN'?'choseColor':'noColor'">中文</span>
  5. /
  6. <span @click="changeLanguage" :class="$i18n.locale=='zh-CN'?'noColor':'choseColor'">Engilsh</span>
  7. </div>
  8. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-position="left" label-width="0px" class="demo-ruleForm login-container">
  9. <div class="login-logo">
  10. <img src="../assets/image/login_logo.png" style="width:80px;height:80px;"/>
  11. </div>
  12. <h3 class="title">{{$t('base.title')}}</h3>
  13. <el-form-item class="login-input" prop="account">
  14. <el-input type="text" v-model="ruleForm.account" autocomplete="off" :placeholder="$t('base.account')" clearable prefix-icon="el-icon-user-solid"></el-input>
  15. </el-form-item>
  16. <el-form-item class="login-input" prop="password">
  17. <el-input type="password" v-model="ruleForm.password" @keyup.enter.native="handleSubmit" autocomplete="off" :placeholder="$t('base.password')" show-password prefix-icon="el-icon-lock"></el-input>
  18. </el-form-item>
  19. <el-form-item class="login-button" style="width:100%;">
  20. <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit" :loading="logining">{{$t('base.login')}}</el-button>
  21. </el-form-item>
  22. </el-form>
  23. <div class="login-backImg">
  24. <img src="../assets/image/login_center.png" />
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. const msg = (rule, value, callback) => {
  32. if (!value) {
  33. if(rule.field == "account") {
  34. return callback(new Error(this.$t('msg.loginAcc')));
  35. } else {
  36. return callback(new Error(this.$t('msg.loginPass')));
  37. }
  38. } else {
  39. callback();
  40. }
  41. };
  42. return {
  43. logining: false,
  44. // 登录信息
  45. ruleForm: {
  46. account: '',
  47. password: ''
  48. },
  49. rules: {
  50. account: [
  51. { required: true, validator: msg , trigger: 'blur' },
  52. ],
  53. password: [
  54. { required: true, validator: msg , trigger: 'blur' },
  55. ]
  56. }
  57. };
  58. },
  59. methods: {
  60. handleReset2() {
  61. this.$refs.ruleForm.resetFields();
  62. },
  63. changeLanguage() {
  64. this.$confirm(this.$t('msg.changeLanguage'), this.$t('el.messagebox.title'), {
  65. confirmButtonText: this.$t('el.messagebox.confirm'),
  66. cancelButtonText: this.$t('el.messagebox.cancel'),
  67. type: 'warning'
  68. }).then(() => {
  69. this.$router.go(0);
  70. if ( this.$i18n.locale === 'zh-CN' ) {
  71. this.$i18n.locale = 'en-US';
  72. localStorage.lang = 'en-US';
  73. }else {
  74. this.$i18n.locale = 'zh-CN';
  75. localStorage.lang = 'zh-CN';
  76. }
  77. }).catch(() => {});
  78. },
  79. handleSubmit() {
  80. this.$refs.ruleForm.validate((valid) => {
  81. if (valid) {
  82. var _this = this;
  83. this.logining = true;
  84. this.http.post(this.port.manage.login, this.ruleForm , res => {
  85. this.logining = false;
  86. if (res.code == "ok") {
  87. sessionStorage.setItem('user', JSON.stringify(res.data));
  88. this.$router.push({ path: '/map' });
  89. } else {
  90. this.$message({
  91. message: res.msg,
  92. type: 'error'
  93. });
  94. }
  95. }, error => {
  96. this.logining = false;
  97. this.$message({
  98. message: error,
  99. type: 'error'
  100. });
  101. })
  102. }
  103. });
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .login-par {
  110. position: relative;
  111. }
  112. .changeLanguage {
  113. position: absolute;
  114. right:30px;
  115. top:-160px;
  116. font-size: 17px;
  117. cursor: pointer;
  118. .choseColor {
  119. color: #409EFF;
  120. }
  121. .noColor {
  122. color: #cac6c6;
  123. }
  124. }
  125. .login-logo {
  126. text-align: center;
  127. margin: 0 0 20px 0;
  128. }
  129. .login-container {
  130. /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
  131. -webkit-border-radius: 5px;
  132. border-radius: 5px;
  133. -moz-border-radius: 5px;
  134. background-clip: padding-box;
  135. margin: 180px auto;
  136. // width: 350px;
  137. width: 315px;
  138. height: 365px;
  139. // padding: 35px 35px 15px 35px;
  140. padding: 25px 35px 25px 35px;
  141. background: #fff;
  142. border: 1px solid #eaeaea;
  143. box-shadow: 0 0 5px #cac6c6;
  144. border-top: 10px solid #409EFF;
  145. .title {
  146. font-size: 20px;
  147. margin: 0px auto 40px auto;
  148. text-align: center;
  149. color: #505458;
  150. }
  151. .remember {
  152. margin: 0px 0px 35px 0px;
  153. }
  154. .login-input {
  155. margin: 30px 0 0 0;
  156. }
  157. .login-button {
  158. margin: 30px 0 0 0;
  159. }
  160. .login-button .el-button {
  161. padding: 14px;
  162. }
  163. }
  164. .login-backImg {
  165. position: absolute;
  166. width: 100%;
  167. height: 350px;
  168. background-color: #409EFF;
  169. top: 110px;
  170. z-index: -1;
  171. img {
  172. width: 100%;
  173. height: 100%;
  174. }
  175. }
  176. </style>