login.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="icore-lg">
  3. <img
  4. style="width: 100%; height: 100%; position: absolute"
  5. src="../../../assets/img/icore-shown-all.png"
  6. />
  7. <section v-if="isJump === true">
  8. <div class="jumpText">正在为您跳转,请稍后...</div>
  9. </section>
  10. <section v-else>
  11. <div>
  12. <div class="frame-area">
  13. <div class="desc-area"></div>
  14. <div style="position: absolute; left: 30px; width: 346px; top: 105px">
  15. <el-form
  16. class="lg-form"
  17. :inline="false"
  18. ref="loginForm"
  19. :model="loginForm"
  20. :rules="loginFormRules"
  21. >
  22. <el-form-item style="margin-bottom: 20px" prop="loginName">
  23. <el-input v-model="loginForm.loginName" placeholder="用户名">
  24. <i class="oa-login-ibg oa-login-ibg1" slot="prefix"></i>
  25. </el-input>
  26. </el-form-item>
  27. <el-form-item style="margin-bottom: 20px" prop="password">
  28. <el-input
  29. v-model="loginForm.password"
  30. :type="pwdShow ? 'text' : 'password'"
  31. placeholder="密码"
  32. @keyup.enter.native="loginSubmit('loginForm')"
  33. >
  34. <i class="oa-login-ibg oa-login-ibg2" slot="prefix"></i>
  35. <i
  36. class="icore-icons icore-icons-see oa-login-ibg4"
  37. :class="{ 'icore-icons-see-reverse': !pwdShow }"
  38. @click="showPwd"
  39. slot="suffix"
  40. ></i>
  41. </el-input>
  42. </el-form-item>
  43. <el-form-item style="margin-bottom: 20px">
  44. <el-button
  45. type="primary"
  46. class="width100"
  47. @click="loginSubmit('loginForm')"
  48. :loading="loginBtnLoading"
  49. >登&nbsp;录</el-button
  50. >
  51. </el-form-item>
  52. </el-form>
  53. </div>
  54. </div>
  55. </div>
  56. </section>
  57. </div>
  58. </template>
  59. <script>
  60. import { cookieUserId, cookieTime, cookieUserName } from "@/config/config.js";
  61. import { setCookie, getCookie, formatDate } from "@/utils/util.js";
  62. import store from "@/store/index.js";
  63. import JsSHA from 'jssha'
  64. const shaObj = new JsSHA('SHA-1', 'TEXT', { encoding: 'UTF8' })
  65. export default {
  66. data() {
  67. return {
  68. store,
  69. loginBtnLoading: false,
  70. pwdShow: false,
  71. shaObj,
  72. loginForm: {
  73. loginName: "",
  74. password: "",
  75. },
  76. loginFormRules: {
  77. loginName: [
  78. { required: true, message: "请输入用户名", trigger: "blur" },
  79. ],
  80. password: [{ required: true, message: "请输入密码", trigger: "blur" }],
  81. },
  82. isJump: false,
  83. };
  84. },
  85. beforeCreate() {
  86. let token = getCookie("accessToken");
  87. if (token) {
  88. this.$router.push({ path: "default" });
  89. } else {
  90. window.top.localStorage.setItem("lockpwd", "");
  91. }
  92. window.top.localStorage.setItem("allPrivilege", "");
  93. window.top.localStorage.setItem("ownPrivilege", "");
  94. },
  95. mounted() {
  96. // 从cookie中获取上一次的登录用户名,赋值给用户名
  97. this.loginForm.loginName = getCookie("loginName")
  98. ? getCookie("loginName")
  99. : "";
  100. },
  101. methods: {
  102. loginSubmit(formName) {
  103. this.loginForm.loginName = this.loginForm.loginName.trim();
  104. this.$refs[formName].validate((valid) => {
  105. if (valid) {
  106. // 登陆中 登录按钮不可用
  107. this.loginBtnLoading = true;
  108. let form = JSON.parse(JSON.stringify(this.loginForm));
  109. form.app_code = 'web'; //终端code暂时写死
  110. this.shaObj.update(form.password)
  111. console.log(form.password)
  112. form.password = this.shaObj.getHash('HEX')
  113. console.log(form.password)
  114. this.store
  115. .dispatch("index/login/login", form)
  116. .then((res) => {
  117. if (res.code === "0") {
  118. console.log(res,"res")
  119. // 登录成功
  120. // 设置缓存信息
  121. setCookie("accessToken", res.data.accessToken, cookieTime, "/");
  122. setCookie(
  123. "refreshToken",
  124. res.data.refreshToken,
  125. cookieTime,
  126. "/"
  127. );
  128. setCookie("orgCode", res.data.user.orgCode);
  129. setCookie("userId", res.data.user.userId);
  130. setCookie("appId", res.data.appId);
  131. setCookie("loginId", res.data.user.userId); // 为配合bms取值添加
  132. setCookie("loginName", this.loginForm.loginName);
  133. let info = JSON.parse(JSON.stringify(res.data.user));
  134. for (let k in info) {
  135. if (
  136. k === "sysGroup" ||
  137. k === "sysCompanys" ||
  138. k === "sysRoles" || k === 'photo'
  139. ) {
  140. delete info[k];
  141. }
  142. }
  143. setCookie("userInfo", JSON.stringify(info));
  144. // 判断用户集团公司情况跳转
  145. let userInfo = res.data.user;
  146. let sRedirect = this.$route.query.redirect;
  147. // 超级管理员
  148. if (userInfo.userCode === "admin") {
  149. if (userInfo.sysCompanys) {
  150. // 公司列表过多时cookie存放失败,存至localStorage
  151. // setCookie('companys', JSON.stringify(userInfo.sysCompanys));
  152. window.top.localStorage.setItem(
  153. "sysGroup",
  154. JSON.stringify(userInfo.sysGroup)
  155. );
  156. window.top.localStorage.setItem(
  157. "companys",
  158. JSON.stringify(userInfo.sysCompanys)
  159. );
  160. if (userInfo.hasOwnProperty("sysCompanys")) {
  161. window.top.localStorage.setItem(
  162. "companyId",
  163. userInfo.sysCompanys[0].id
  164. );
  165. }
  166. }
  167. if (sRedirect) {
  168. this.$router.push({ name: sRedirect });
  169. } else {
  170. this.$router.push({ name: "default" }).catch(() => {});
  171. }
  172. // 普通用户
  173. } else {
  174. if (
  175. userInfo.hasOwnProperty("sysGroup") &&
  176. userInfo.sysGroup !== "" &&
  177. userInfo.sysGroup !== null &&
  178. JSON.stringify(userInfo.sysGroup) !== "{}" &&
  179. JSON.stringify(userInfo.sysGroup) !== "[]"
  180. ) {
  181. window.top.localStorage.setItem(
  182. "sysGroup",
  183. JSON.stringify(userInfo.sysGroup)
  184. );
  185. if (userInfo.hasOwnProperty("sysCompanys")) {
  186. window.top.localStorage.setItem(
  187. "companys",
  188. JSON.stringify(userInfo.sysCompanys)
  189. );
  190. window.top.localStorage.setItem(
  191. "companyId",
  192. userInfo.sysCompanys[0].id
  193. );
  194. if (userInfo.sysCompanys.length > 1) {
  195. // 跳转选择集团公司页面
  196. this.$router.push({ name: "selectCompany" });
  197. } else {
  198. if (sRedirect) {
  199. this.$router.push({ name: sRedirect });
  200. } else {
  201. this.$router
  202. .push({ name: "default" })
  203. .catch(() => {});
  204. }
  205. }
  206. } else {
  207. this.$message.error(
  208. "后台返回数据缺少company信息,请联系开发人员!"
  209. );
  210. }
  211. } else {
  212. this.$message.error(
  213. "必须隶属一个集团!请先联系管理员添加集团信息!"
  214. );
  215. }
  216. }
  217. } else {
  218. // 登录失败
  219. // 提示
  220. this.$message({
  221. message: res.message,
  222. type: "error",
  223. });
  224. }
  225. this.loginBtnLoading = false;
  226. setTimeout(() => {
  227. this.$router.go(0)
  228. }, 2000);
  229. })
  230. .catch(() => {
  231. this.loginBtnLoading = false;
  232. });
  233. } else {
  234. return false;
  235. }
  236. });
  237. },
  238. showPwd() {
  239. this.pwdShow = !this.pwdShow;
  240. },
  241. },
  242. };
  243. </script>
  244. <style lang="less" scoped>
  245. .jumpText {
  246. position: absolute;
  247. width: 100%;
  248. text-align: center;
  249. line-height: 500px;
  250. color: white;
  251. font-size: 24px;
  252. }
  253. </style>