login.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div class="login-view">
  3. <div class="logo space-x-[10px]">
  4. <img src="@/assets/images/logo/logo.png" alt=""></img>
  5. <img src="@/assets/images/logo/logo-text.svg" alt=""></img>
  6. </div>
  7. <div class="login-text">
  8. <img src="@/assets/images/login/bg-text.svg" alt=""></img>
  9. </div>
  10. <el-form ref="loginRef" :model="loginForm" class="login-form">
  11. <h3 class="title">账号登录</h3>
  12. <div class="main">
  13. <el-form-item prop="username">
  14. <el-input
  15. v-model="loginForm.username"
  16. type="text"
  17. size="large"
  18. auto-complete="off"
  19. placeholder="请输入登录账号"
  20. ></el-input>
  21. </el-form-item>
  22. <el-form-item prop="password">
  23. <el-input
  24. v-model="loginForm.password"
  25. type="password"
  26. size="large"
  27. auto-complete="off"
  28. placeholder="请输入登录密码"
  29. @keyup.enter="handleLogin"
  30. ></el-input>
  31. </el-form-item>
  32. <el-form-item style="width:100%;">
  33. <div class="w-full h-[116px]">
  34. <div class="error-tips space-x-[4px]" v-show="errorMsg">
  35. <el-icon><Warning /></el-icon>
  36. <span>{{ errorMsg }}</span>
  37. </div>
  38. </div>
  39. <el-button
  40. :loading="loading"
  41. size="large"
  42. type="primary"
  43. style="width:100%;"
  44. @click.prevent="handleLogin"
  45. >
  46. <span v-if="!loading">登 录</span>
  47. <span v-else>登 录 中...</span>
  48. </el-button>
  49. </el-form-item>
  50. </div>
  51. </el-form>
  52. <!-- 底部
  53. -->
  54. <div class="el-login-footer">
  55. <span>哈尔滨跃渊环保智能装备有限责任公司 技术支持</span>
  56. </div>
  57. </div>
  58. </template>
  59. <script setup>
  60. import { getCodeImg } from "@/api/login";
  61. import Cookies from "js-cookie";
  62. import { encrypt, decrypt } from "@/utils/jsencrypt";
  63. import useUserStore from '@/store/modules/user'
  64. import usePermissionStore from '@/store/modules/permission'
  65. import { removeToken } from '@/utils/auth'
  66. const userStore = useUserStore()
  67. const route = useRoute();
  68. const router = useRouter();
  69. const { proxy } = getCurrentInstance();
  70. const loginForm = ref({
  71. username: "",
  72. password: "",
  73. rememberMe: false,
  74. code: "",
  75. uuid: ""
  76. });
  77. const loginRules = {
  78. username: [{ required: true, trigger: "blur", message: "请输入您的账号" }],
  79. password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
  80. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  81. };
  82. const errorMsg = ref("");
  83. const codeUrl = ref("");
  84. const loading = ref(false);
  85. // 验证码开关
  86. const captchaEnabled = ref(true);
  87. // 注册开关
  88. const register = ref(false);
  89. const redirect = ref(undefined);
  90. watch(route, (newRoute) => {
  91. redirect.value = newRoute.query && newRoute.query.redirect;
  92. }, { immediate: true });
  93. function handleLogin() {
  94. const { username, password } = unref(loginForm);
  95. if (!username) {
  96. return errorMsg.value = '请输入用户名称'
  97. }
  98. if (!password) {
  99. return errorMsg.value = '请输入登录密码'
  100. }
  101. errorMsg.value = '';
  102. loading.value = true;
  103. // 调用action的登录方法
  104. userStore.login(loginForm.value).then(() => {
  105. const query = route.query;
  106. const otherQueryParams = Object.keys(query).reduce((acc, cur) => {
  107. if (cur !== "redirect") {
  108. acc[cur] = query[cur];
  109. }
  110. return acc;
  111. }, {});
  112. usePermissionStore().generateRoutes().then(accessRoutes => {
  113. if ( accessRoutes.length ) {
  114. const path = accessRoutes[0]?.children[0]?.path;
  115. router.push({ path });
  116. // let isOff = false;
  117. // accessRoutes.forEach(({ children }) => {
  118. // children?.forEach(item => {
  119. // if ( item.path === 'voice/workbench' ) {
  120. // isOff = true;
  121. // }
  122. // })
  123. // });
  124. // if ( isOff ) {
  125. // router.push({ path: "/voice/workbench", query: otherQueryParams });
  126. // } else {
  127. // const path = accessRoutes[0]?.children[0]?.path;
  128. // router.push({ path });
  129. // }
  130. } else {
  131. loading.value = false;
  132. proxy.$modal.msgError("当前账号未分配权限");
  133. removeToken();
  134. }
  135. })
  136. // router.push({ path: "/voice/workbench", query: otherQueryParams });
  137. }).catch(() => {
  138. loading.value = false;
  139. });
  140. }
  141. function getCode() {
  142. getCodeImg().then(res => {
  143. captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled;
  144. if (captchaEnabled.value) {
  145. codeUrl.value = "data:image/gif;base64," + res.img;
  146. loginForm.value.uuid = res.uuid;
  147. }
  148. });
  149. }
  150. function getCookie() {
  151. const username = Cookies.get("username");
  152. const password = Cookies.get("password");
  153. const rememberMe = Cookies.get("rememberMe");
  154. loginForm.value = {
  155. username: username === undefined ? loginForm.value.username : username,
  156. password: password === undefined ? loginForm.value.password : decrypt(password),
  157. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  158. };
  159. }
  160. // getCode();
  161. getCookie();
  162. </script>
  163. <style lang='scss' scoped>
  164. .login-view {
  165. position: relative;
  166. display: flex;
  167. justify-content: flex-end;
  168. align-items: center;
  169. height: 100%;
  170. background-image: url("../assets/images/login/bg-login-text.png");
  171. background-size: cover;
  172. }
  173. .login-text {
  174. position: absolute;
  175. left: 180px;
  176. top: 240px;
  177. }
  178. .logo {
  179. position: absolute;
  180. left: 38px;
  181. top: 38px;
  182. display: flex;
  183. align-items: center;
  184. }
  185. .login-form {
  186. width: 440px;
  187. margin-right: 100px;
  188. border-radius: 12px;
  189. border: 2px solid #FFF;
  190. background: rgba(255, 255, 255, 0.8);
  191. box-shadow: 0px 2px 80px 5px rgba(19, 29, 107, 0.06);
  192. position: relative;
  193. z-index: 11;
  194. .title {
  195. padding: 20px 0 20px 60px;
  196. border-bottom: 1px solid #EDEFF2;
  197. text-align: left;
  198. font-size: 24px;
  199. font-weight: bold;
  200. color: #1D2129;
  201. }
  202. .main {
  203. padding: 60px 60px 66px 60px;
  204. :deep(.el-input__wrapper) {
  205. border: 1px solid #F2F4F9;
  206. border-radius: 8px;
  207. box-shadow: none;
  208. }
  209. .error-tips {
  210. display: flex;
  211. align-items: center;
  212. justify-content: center;
  213. height: 32px;
  214. border-radius: 8px;
  215. background: #FFF1F0;
  216. text-align: center;
  217. font-size: 12px;
  218. color: #FF7152;
  219. }
  220. .el-button {
  221. height: 54px;
  222. border-radius: 8px;
  223. background: linear-gradient(91deg, #165DFF 0.41%, #00A6FF 97.92%);
  224. font-size: 18px;
  225. }
  226. }
  227. .el-input {
  228. height: 54px;
  229. input {
  230. height: 54px;
  231. }
  232. }
  233. .input-icon {
  234. height: 39px;
  235. width: 14px;
  236. margin-left: 0px;
  237. }
  238. }
  239. .login-tip {
  240. font-size: 13px;
  241. text-align: center;
  242. color: #bfbfbf;
  243. }
  244. .login-code {
  245. width: 33%;
  246. height: 40px;
  247. float: right;
  248. img {
  249. cursor: pointer;
  250. vertical-align: middle;
  251. }
  252. }
  253. .el-login-footer {
  254. position: absolute;
  255. height: 40px;
  256. line-height: 40px;
  257. position: fixed;
  258. bottom: 20px;
  259. width: 100%;
  260. text-align: center;
  261. color: #989EA7;
  262. font-family: Arial;
  263. font-size: 12px;
  264. letter-spacing: 1px;
  265. }
  266. .login-code-img {
  267. height: 40px;
  268. padding-left: 12px;
  269. }
  270. </style>