index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <div class="login-container">
  3. <el-card class="form-container">
  4. <div class="login-title">
  5. <h2>{{ defaultSettings.title }}</h2>
  6. <div @click="showJobNumber = !showJobNumber">
  7. {{ showJobNumber ? "账号密码登录" : "扫码登录" }}
  8. </div>
  9. </div>
  10. <el-form
  11. ref="loginFormRef"
  12. :model="loginData"
  13. :rules="loginRules"
  14. class="login-form"
  15. size="default"
  16. >
  17. <el-form-item v-if="showJobNumber" prop="jobNumber">
  18. <div class="flex-y-center w-full">
  19. <svg-icon class="mx-2" icon-class="document" />
  20. <el-input
  21. ref="username"
  22. v-model="loginData.jobNumber"
  23. class="h-[48px]"
  24. name="jobNumber"
  25. placeholder="请扫码或输入工号"
  26. size="large"
  27. />
  28. </div>
  29. </el-form-item>
  30. <div v-else>
  31. <!-- 用户名 -->
  32. <el-form-item prop="userName">
  33. <div class="flex-y-center w-full">
  34. <svg-icon class="mx-2" icon-class="user" />
  35. <el-input
  36. ref="username"
  37. v-model="loginData.userName"
  38. class="h-[48px]"
  39. name="userName"
  40. placeholder="请输入用户名"
  41. size="large"
  42. />
  43. </div>
  44. </el-form-item>
  45. <!-- 密码 -->
  46. <el-tooltip
  47. :content="$t('login.capsLock')"
  48. :visible="isCapslock"
  49. placement="right"
  50. >
  51. <el-form-item prop="password">
  52. <div class="flex-y-center w-full">
  53. <svg-icon class="mx-2" icon-class="lock" />
  54. <el-input
  55. v-model="loginData.password"
  56. :placeholder="$t('login.password')"
  57. class="h-[48px] pr-2"
  58. name="password"
  59. show-password
  60. size="large"
  61. type="password"
  62. @keyup="checkCapslock"
  63. />
  64. </div>
  65. </el-form-item>
  66. </el-tooltip>
  67. </div>
  68. <!-- 组织 -->
  69. <el-form-item prop="orgId">
  70. <div class="flex-y-center w-full">
  71. <svg-icon class="mx-2" icon-class="captcha" />
  72. <el-select
  73. v-model="loginData.orgId"
  74. class="no-border"
  75. placeholder="请选择组织"
  76. size="large"
  77. >
  78. <el-option
  79. v-for="item in orgList"
  80. :key="item.id"
  81. :label="item.deptName"
  82. :value="item.id"
  83. />
  84. </el-select>
  85. </div>
  86. </el-form-item>
  87. <el-form-item prop="proCode">
  88. <div class="flex-y-center w-full">
  89. <svg-icon class="mx-2" icon-class="cascader" />
  90. <el-select
  91. v-model="loginData.proCode"
  92. class="no-border"
  93. placeholder="请选择产线"
  94. size="large"
  95. >
  96. <el-option
  97. v-for="item in productionList"
  98. :key="item.code"
  99. :label="item.name"
  100. :value="item.code"
  101. />
  102. </el-select>
  103. </div>
  104. </el-form-item>
  105. <el-form-item prop="stationId">
  106. <div class="flex-y-center w-full">
  107. <svg-icon class="mx-2" icon-class="client" />
  108. <el-select
  109. v-model="loginData.stationId"
  110. class="no-border"
  111. placeholder="请选择工位"
  112. size="large"
  113. @change="onStationChange"
  114. >
  115. <el-option
  116. v-for="item in stationList"
  117. :key="item.id"
  118. :label="item.name"
  119. :value="item.id"
  120. />
  121. </el-select>
  122. </div>
  123. </el-form-item>
  124. <!-- 登录按钮 -->
  125. <el-button
  126. :loading="loading"
  127. class="login-btn"
  128. size="large"
  129. type="primary"
  130. @click.prevent="handleLogin"
  131. >{{ $t("login.login") }}
  132. </el-button>
  133. </el-form>
  134. </el-card>
  135. <!-- ICP备案 -->
  136. <div v-show="icpVisible" class="absolute bottom-1 text-[10px] text-center">
  137. <p>Copyright © 2022-2025 jgai.com All Rights Reserved.</p>
  138. </div>
  139. </div>
  140. </template>
  141. <script lang="ts" setup>
  142. import { useSettingsStore, useUserStore } from "@/store";
  143. import {
  144. getCaptchaApi,
  145. getOrgListApi,
  146. getProductionList,
  147. stationListByCode,
  148. } from "@/api/auth";
  149. import { LoginData } from "@/api/auth/types";
  150. import { useRoute } from "vue-router";
  151. import defaultSettings from "@/settings";
  152. import { ThemeEnum } from "@/enums/ThemeEnum";
  153. import { watch } from "vue";
  154. import router from "@/router";
  155. // Stores
  156. const userStore = useUserStore();
  157. const settingsStore = useSettingsStore();
  158. // Internationalization
  159. const { t } = useI18n();
  160. // Reactive states
  161. const isDark = ref(settingsStore.theme === ThemeEnum.DARK);
  162. const icpVisible = ref(true);
  163. const showJobNumber = ref(false);
  164. const orgList = ref<any>([]);
  165. const productionList = ref<any>([]);
  166. const stationList = ref<any>([]);
  167. const loading = ref(false); // 按钮loading
  168. const isCapslock = ref(false); // 是否大写锁定
  169. const captchaBase64 = ref(); // 验证码图片Base64字符串
  170. const loginFormRef = ref(ElForm); // 登录表单ref
  171. const { height } = useWindowSize();
  172. const loginData = ref<LoginData>({
  173. userName: "",
  174. password: "",
  175. });
  176. const loginRules = computed?.(() => {
  177. return {
  178. userName: [
  179. {
  180. required: true,
  181. trigger: "blur",
  182. message: t("login.message.username.required"),
  183. },
  184. ],
  185. password: [
  186. {
  187. required: true,
  188. trigger: "blur",
  189. message: t("login.message.password.required"),
  190. },
  191. {
  192. min: 6,
  193. message: t("login.message.password.min"),
  194. trigger: "blur",
  195. },
  196. ],
  197. orgId: [
  198. {
  199. required: true,
  200. trigger: "blur",
  201. message: t("login.message.orgId.required"),
  202. },
  203. ],
  204. proCode: [
  205. {
  206. required: true,
  207. trigger: "blur",
  208. message: "请选择产线",
  209. },
  210. ],
  211. stationId: [
  212. {
  213. required: true,
  214. trigger: "blur",
  215. message: "请选择工位",
  216. },
  217. ],
  218. jobNumber: [
  219. {
  220. required: true,
  221. trigger: "blur",
  222. message: "请输入工号",
  223. },
  224. ],
  225. };
  226. });
  227. let stationType = ""; //工位类型
  228. let stationName = ""; //工位名称
  229. const onStationChange = (val: any) => {
  230. const stationArray = stationList.value.filter((item: any) => {
  231. return item.id === val;
  232. });
  233. stationType = stationArray[0].stationDictValue;
  234. stationName = stationArray[0].name;
  235. loginData.value.stationType = stationArray[0].stationDictValue;
  236. };
  237. /**
  238. * 获取验证码
  239. */
  240. function getCaptcha() {
  241. getCaptchaApi().then(({ data }) => {
  242. loginData.value.captchaKey = data.captchaKey;
  243. captchaBase64.value = data.captchaBase64;
  244. });
  245. }
  246. function getOrgList() {
  247. getOrgListApi().then((data: any) => {
  248. orgList.value = data.data;
  249. if (orgList.value) {
  250. loginData.value.orgId = orgList.value[0].id;
  251. }
  252. });
  253. }
  254. /**
  255. * 登录
  256. */
  257. const route = useRoute();
  258. function handleLogin() {
  259. loginFormRef.value.validate((valid: boolean) => {
  260. if (valid) {
  261. //保存用户名和密码
  262. localStorage.setItem("local_name", loginData.value.userName);
  263. localStorage.setItem("local_pwd", loginData.value.password);
  264. loading.value = true;
  265. let numberP = {
  266. proCode: loginData.value.proCode,
  267. orgId: loginData.value.orgId,
  268. jobNumber: loginData.value.jobNumber,
  269. stationId: loginData.value.stationId,
  270. stationType: loginData.value.stationType,
  271. };
  272. let acountP = {
  273. userName: loginData.value.userName,
  274. password: loginData.value.password,
  275. proCode: loginData.value.proCode,
  276. orgId: loginData.value.orgId,
  277. stationId: loginData.value.stationId,
  278. stationType: loginData.value.stationType,
  279. };
  280. userStore
  281. .login(showJobNumber.value ? numberP : acountP)
  282. .then(() => {
  283. userStore.user.station = stationName;
  284. userStore.user.proCode = loginData.value.proCode;
  285. // 捡选 装配 测试 维修站 预齐套
  286. // if (stationType == "5") {
  287. // router.replace({ name: "PrepareMain" });
  288. // } else {
  289. router.replace({ name: "ProcessMain" });
  290. // }
  291. })
  292. .catch(() => {
  293. // getCaptcha();
  294. console.log("catch");
  295. })
  296. .finally(() => {
  297. loading.value = false;
  298. });
  299. }
  300. });
  301. }
  302. /**
  303. * 主题切换
  304. */
  305. const toggleTheme = () => {
  306. //const newTheme = settingsStore.theme === ThemeEnum.DARK ? ThemeEnum.LIGHT : ThemeEnum.DARK;
  307. //settingsStore.changeTheme(newTheme);
  308. };
  309. /**
  310. * 根据屏幕宽度切换设备模式
  311. */
  312. watchEffect?.(() => {
  313. if (height.value < 600) {
  314. icpVisible.value = false;
  315. } else {
  316. icpVisible.value = true;
  317. }
  318. });
  319. watch(
  320. () => loginData.value.proCode,
  321. (newValue) => {
  322. if (newValue) {
  323. stationListByCode(newValue, 0).then((data: any) => {
  324. stationList.value = data.data;
  325. if (stationList.value && stationList.value.length > 0) {
  326. loginData.value.stationId = stationList.value[0].id;
  327. stationType = stationList.value[0].stationDictValue;
  328. stationName = stationList.value[0].name;
  329. loginData.value.stationType = stationList.value[0].stationDictValue;
  330. }
  331. });
  332. }
  333. }
  334. );
  335. /**
  336. * 检查输入大小写
  337. */
  338. function checkCapslock(e: any) {
  339. isCapslock.value = e.getModifierState("CapsLock");
  340. }
  341. onMounted?.(() => {
  342. getOrgList();
  343. toggleTheme();
  344. getProductionList().then((data: any) => {
  345. productionList.value = data.data;
  346. if (productionList.value) {
  347. loginData.value.proCode = productionList.value[0].code;
  348. }
  349. });
  350. if (
  351. localStorage.getItem("local_name") &&
  352. localStorage.getItem("local_name") !== "null"
  353. ) {
  354. loginData.value.userName = localStorage.getItem("local_name");
  355. loginData.value.password = localStorage.getItem("local_pwd");
  356. }
  357. });
  358. </script>
  359. <style lang="scss" scoped>
  360. .login-container {
  361. overflow-y: auto;
  362. background: url("@/assets/images/login-bg.png");
  363. background-position: center;
  364. background-size: cover;
  365. position: relative;
  366. @apply wh-full flex-center;
  367. .login-form {
  368. padding: 30px 10px;
  369. }
  370. .login-title {
  371. color: white;
  372. margin-left: 10px;
  373. display: flex;
  374. justify-content: space-between;
  375. align-items: center;
  376. }
  377. .form-container {
  378. background: #a0a8b2;
  379. border-radius: 16px;
  380. width: 500px;
  381. position: absolute;
  382. right: 10%;
  383. }
  384. .login-btn {
  385. width: 100%;
  386. height: 50px;
  387. border-radius: 25px;
  388. margin-top: 15px;
  389. }
  390. }
  391. .el-form-item {
  392. background: var(--el-input-bg-color);
  393. border: 1px solid var(--el-border-color);
  394. border-radius: 5px;
  395. }
  396. :deep(.el-input) {
  397. .el-input__wrapper {
  398. padding: 0;
  399. background-color: transparent;
  400. box-shadow: none;
  401. &.is-focus,
  402. &:hover {
  403. box-shadow: none !important;
  404. }
  405. input:-webkit-autofill {
  406. /* 通过延时渲染背景色变相去除背景颜色 */
  407. transition: background-color 1000s ease-in-out 0s;
  408. }
  409. }
  410. }
  411. :deep(.el-select__placeholder) {
  412. color: rgba(0, 0, 0, 0.9);
  413. }
  414. :deep(.el-select__placeholder.is-transparent) {
  415. color: rgba(0, 0, 0, 0.3);
  416. }
  417. :deep(.el-input__inner::placeholder) {
  418. color: rgba(0, 0, 0, 0.3);
  419. }
  420. :deep(.el-input__inner) {
  421. color: rgba(0, 0, 0, 0.9);
  422. }
  423. :deep(.el-select) {
  424. .el-select__wrapper {
  425. padding: 0;
  426. background-color: transparent;
  427. box-shadow: none;
  428. &.is-focus,
  429. &:hover {
  430. box-shadow: none !important;
  431. }
  432. input:-webkit-autofill {
  433. /* 通过延时渲染背景色变相去除背景颜色 */
  434. transition: background-color 1000s ease-in-out 0s;
  435. }
  436. }
  437. }
  438. </style>