userlogin.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <el-form class="login-form"
  3. status-icon
  4. :rules="loginRules"
  5. ref="loginForm"
  6. :model="loginForm"
  7. label-width="0">
  8. <el-form-item v-if="tenantMode" prop="tenantId">
  9. <el-input size="small"
  10. @keyup.enter.native="handleLogin"
  11. v-model="loginForm.tenantId"
  12. auto-complete="off"
  13. :placeholder="$t('login.tenantId')">
  14. <i slot="prefix" class="icon-quanxian"/>
  15. </el-input>
  16. </el-form-item>
  17. <el-form-item prop="username">
  18. <el-input size="small"
  19. @keyup.enter.native="handleLogin"
  20. v-model="loginForm.username"
  21. auto-complete="off"
  22. :placeholder="$t('login.username')">
  23. <i slot="prefix" class="icon-yonghu"/>
  24. </el-input>
  25. </el-form-item>
  26. <el-form-item prop="password">
  27. <el-input size="small"
  28. @keyup.enter.native="handleLogin"
  29. :type="passwordType"
  30. v-model="loginForm.password"
  31. auto-complete="off"
  32. :placeholder="$t('login.password')">
  33. <i class="el-icon-view el-input__icon" slot="suffix" @click="showPassword"/>
  34. <i slot="prefix" class="icon-mima"/>
  35. </el-input>
  36. </el-form-item>
  37. <el-form-item v-if="this.website.captchaMode" prop="code">
  38. <el-row :span="24">
  39. <el-col :span="16">
  40. <el-input size="small"
  41. @keyup.enter.native="handleLogin"
  42. v-model="loginForm.code"
  43. auto-complete="off"
  44. :placeholder="$t('login.code')">
  45. <i slot="prefix" class="icon-yanzhengma"/>
  46. </el-input>
  47. </el-col>
  48. <el-col :span="8">
  49. <div class="login-code">
  50. <img :src="loginForm.image" class="login-code-img" @click="refreshCode"
  51. />
  52. </div>
  53. </el-col>
  54. </el-row>
  55. </el-form-item>
  56. <el-form-item>
  57. <el-button id="submit" type="primary"
  58. size="small"
  59. @click.native.prevent="handleLogin"
  60. class="login-submit">{{$t('login.submit')}}
  61. </el-button>
  62. </el-form-item>
  63. </el-form>
  64. </template>
  65. <script>
  66. import {mapGetters} from "vuex";
  67. import {info} from "@/api/system/tenant";
  68. import {getCaptcha} from "@/api/user";
  69. import {getTopUrl} from "@/util/util";
  70. import {getDetail, getList} from "../../api/grid/grid";
  71. import {Message} from "element-ui";
  72. export default {
  73. name: "userlogin",
  74. data() {
  75. return {
  76. tenantMode: this.website.tenantMode,
  77. loginForm: {
  78. //租户ID
  79. tenantId: "000000",
  80. //用户名
  81. username: "admin",
  82. //密码
  83. password: "admin",
  84. //账号类型
  85. type: "account",
  86. //验证码的值
  87. code: "",
  88. //验证码的索引
  89. key: "",
  90. //预加载白色背景
  91. image: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
  92. },
  93. loginRules: {
  94. tenantId: [
  95. {required: false, message: "请输入租户ID", trigger: "blur"}
  96. ],
  97. username: [
  98. {required: true, message: "请输入用户名", trigger: "blur"}
  99. ],
  100. password: [
  101. {required: true, message: "请输入密码", trigger: "blur"},
  102. {min: 1, message: "密码长度最少为6位", trigger: "blur"}
  103. ]
  104. },
  105. passwordType: "password"
  106. };
  107. },
  108. created() {
  109. this.getTenant();
  110. this.refreshCode();
  111. },
  112. mounted() {
  113. },
  114. computed: {
  115. ...mapGetters(["tagWel"])
  116. },
  117. props: [],
  118. methods: {
  119. refreshCode() {
  120. getCaptcha().then(res => {
  121. const data = res.data;
  122. this.loginForm.key = data.key;
  123. this.loginForm.image = data.image;
  124. })
  125. },
  126. showPassword() {
  127. this.passwordType === ""
  128. ? (this.passwordType = "password")
  129. : (this.passwordType = "");
  130. },
  131. async initMenu(){
  132. let menu = await this.$store.dispatch("GetMenu");
  133. this.$store.commit("SET_STATIC_ALL_MENU",menu);
  134. if (menu.length !== 0) {
  135. this.$router.$avueRouter.formatRoutes(menu,true);
  136. }
  137. },
  138. handleLogin() {
  139. this.$animateCss('#submit','animate__rotateIn')
  140. this.$refs.loginForm.validate(valid => {
  141. if (valid) {
  142. this.$store.dispatch("LoginByUsername", this.loginForm).then(() => {
  143. getList(1,100,{
  144. userCode: this.$store.state.user.userInfo['user_id']
  145. }).then( (res)=>{
  146. if(res.data.data.records.length==0){
  147. this.$store.dispatch("logOut");
  148. Message({
  149. message: "该账号暂未绑定相关网格区域,请绑定后登录!",
  150. type: 'error'
  151. })
  152. }else{
  153. this.$store.commit('SET_TAG_INDEX',0);
  154. this.$router.push({path: "/"});
  155. this.initMenu();
  156. }
  157. });
  158. }).catch((e) => {
  159. loading.close();
  160. Message({
  161. message: e,
  162. type: 'error'
  163. })
  164. this.refreshCode();
  165. });
  166. }
  167. });
  168. },
  169. getTenant() {
  170. let domain = getTopUrl();
  171. // 临时指定域名,方便测试
  172. //domain = "https://bladex.vip";
  173. info(domain).then(res => {
  174. const data = res.data;
  175. if (data.success && data.data.tenantId) {
  176. this.tenantMode = false;
  177. this.loginForm.tenantId = data.data.tenantId;
  178. this.$parent.$refs.login.style.backgroundImage = `url(${data.data.backgroundUrl})`;
  179. }
  180. })
  181. }
  182. }
  183. };
  184. </script>
  185. <style>
  186. </style>