userlogin.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 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-dialog title="用户信息选择"
  64. append-to-body
  65. :visible.sync="userBox"
  66. width="350px">
  67. <avue-form :option="userOption" v-model="userForm" @submit="submitLogin"/>
  68. </el-dialog>
  69. </el-form>
  70. </template>
  71. <script>
  72. import {mapGetters} from "vuex";
  73. import {info} from "@/api/system/tenant";
  74. import {getCaptcha} from "@/api/user";
  75. import {getTopUrl} from "@/util/util";
  76. export default {
  77. name: "userlogin",
  78. data() {
  79. return {
  80. tenantMode: this.website.tenantMode,
  81. loginForm: {
  82. //租户ID
  83. tenantId: "000000",
  84. //部门ID
  85. deptId: "",
  86. //角色ID
  87. roleId: "",
  88. //用户名
  89. username: "",
  90. //密码
  91. password: "",
  92. //账号类型
  93. type: "account",
  94. //验证码的值
  95. code: "",
  96. //验证码的索引
  97. key: "",
  98. //预加载白色背景
  99. image: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
  100. },
  101. loginRules: {
  102. tenantId: [
  103. {required: false, message: "请输入租户ID", trigger: "blur"}
  104. ],
  105. username: [
  106. {required: true, message: "请输入用户名", trigger: "blur"}
  107. ],
  108. password: [
  109. {required: true, message: "请输入密码", trigger: "blur"},
  110. {min: 1, message: "密码长度最少为6位", trigger: "blur"}
  111. ]
  112. },
  113. passwordType: "password",
  114. userBox: false,
  115. userForm: {
  116. deptId: '',
  117. roleId: ''
  118. },
  119. userOption: {
  120. labelWidth: 70,
  121. submitBtn: true,
  122. emptyBtn: false,
  123. submitText: '登录',
  124. column: [
  125. {
  126. label: '部门',
  127. prop: 'deptId',
  128. type: 'select',
  129. props: {
  130. label: 'deptName',
  131. value: 'id'
  132. },
  133. dicUrl: '/api/blade-system/dept/select',
  134. span: 24,
  135. display: false,
  136. rules: [{
  137. required: true,
  138. message: "请选择部门",
  139. trigger: "blur"
  140. }],
  141. },
  142. {
  143. label: '角色',
  144. prop: 'roleId',
  145. type: 'select',
  146. props: {
  147. label: 'roleName',
  148. value: 'id'
  149. },
  150. dicUrl: '/api/blade-system/role/select',
  151. span: 24,
  152. display: false,
  153. rules: [{
  154. required: true,
  155. message: "请选择角色",
  156. trigger: "blur"
  157. }],
  158. },
  159. ]
  160. }
  161. };
  162. },
  163. created() {
  164. this.getTenant();
  165. this.refreshCode();
  166. },
  167. mounted() {
  168. },
  169. watch: {
  170. 'loginForm.deptId'() {
  171. const column = this.findObject(this.userOption.column, "deptId");
  172. if (this.loginForm.deptId.includes(",")) {
  173. column.dicUrl = `/api/blade-system/dept/select?deptId=${this.loginForm.deptId}`;
  174. column.display = true;
  175. } else {
  176. column.dicUrl = '';
  177. }
  178. },
  179. 'loginForm.roleId'() {
  180. const column = this.findObject(this.userOption.column, "roleId");
  181. if (this.loginForm.roleId.includes(",")) {
  182. column.dicUrl = `/api/blade-system/role/select?roleId=${this.loginForm.roleId}`;
  183. column.display = true;
  184. } else {
  185. column.dicUrl = '';
  186. }
  187. }
  188. },
  189. computed: {
  190. ...mapGetters(["tagWel", "userInfo"])
  191. },
  192. props: [],
  193. methods: {
  194. refreshCode() {
  195. if (this.website.captchaMode) {
  196. getCaptcha().then(res => {
  197. const data = res.data;
  198. this.loginForm.key = data.key;
  199. this.loginForm.image = data.image;
  200. })
  201. }
  202. },
  203. showPassword() {
  204. this.passwordType === ""
  205. ? (this.passwordType = "password")
  206. : (this.passwordType = "");
  207. },
  208. submitLogin (form, done) {
  209. if (form.deptId !== '') {
  210. this.loginForm.deptId = form.deptId;
  211. }
  212. if (form.roleId !== '') {
  213. this.loginForm.roleId = form.roleId;
  214. }
  215. this.handleLogin();
  216. done();
  217. },
  218. handleLogin() {
  219. this.$refs.loginForm.validate(valid => {
  220. if (valid) {
  221. const loading = this.$loading({
  222. lock: true,
  223. text: '登录中,请稍后。。。',
  224. spinner: "el-icon-loading"
  225. });
  226. this.$store.dispatch("LoginByUsername", this.loginForm).then(() => {
  227. if (this.website.switchMode) {
  228. const deptId = this.userInfo.dept_id;
  229. const roleId = this.userInfo.role_id;
  230. if (deptId.includes(",") || roleId.includes(",")) {
  231. this.loginForm.deptId = deptId;
  232. this.loginForm.roleId = roleId;
  233. this.userBox = true;
  234. this.$store.dispatch("LogOut").then(() => {
  235. loading.close();
  236. });
  237. return false;
  238. }
  239. }
  240. this.$router.push({path: this.tagWel.value});
  241. loading.close();
  242. }).catch(() => {
  243. loading.close();
  244. this.refreshCode();
  245. });
  246. }
  247. });
  248. },
  249. getTenant() {
  250. let domain = getTopUrl();
  251. // 临时指定域名,方便测试
  252. //domain = "https://bladex.vip";
  253. info(domain).then(res => {
  254. const data = res.data;
  255. if (data.success && data.data.tenantId) {
  256. this.tenantMode = false;
  257. this.loginForm.tenantId = data.data.tenantId;
  258. this.$parent.$refs.login.style.backgroundImage = `url(${data.data.backgroundUrl})`;
  259. }
  260. })
  261. }
  262. }
  263. };
  264. </script>
  265. <style>
  266. </style>