login.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <div class="login-layout">
  3. <div class="login-content">
  4. <div class="header">
  5. <!-- <img src="/favicon.ico" /> -->
  6. <p>登录多元融合</p>
  7. </div>
  8. <div class="body">
  9. <ui-input
  10. type="text"
  11. placeholder="请输入账号"
  12. v-model="username"
  13. style="width: 100%"
  14. />
  15. <br />
  16. <ui-input
  17. :type="showPwd ? 'text' : 'password'"
  18. placeholder="请输入密码"
  19. v-model="password"
  20. style="width: 100%; margin-top: 20px"
  21. >
  22. <template #icon>
  23. <ui-icon
  24. style="cursor: pointer"
  25. class="ctrl-pwd"
  26. :type="showPwd ? 'eye-s' : 'eye-n'"
  27. @click="showPwd = !showPwd"
  28. ></ui-icon>
  29. </template>
  30. </ui-input>
  31. <br />
  32. <div class="code-row">
  33. <ui-input
  34. class="code-input"
  35. type="text"
  36. placeholder="请输入验证码"
  37. v-model="code"
  38. />
  39. <img :src="codeImg" class="code-img" @click="refer" />
  40. </div>
  41. <br />
  42. <ui-input
  43. type="checkbox"
  44. @click.stop
  45. label="记住密码"
  46. style="margin-top: 20px"
  47. :modelValue="mark"
  48. @update:modelValue="(select: any) => mark = select"
  49. />
  50. </div>
  51. <div class="bottom">
  52. <ui-button type="submit" @click="login(username, password, code)">登录</ui-button>
  53. </div>
  54. </div>
  55. </div>
  56. </template>
  57. <script lang="ts" setup>
  58. import { ref, computed } from "vue";
  59. import { encodePwd } from "@/utils";
  60. import GAxios from "axios";
  61. import { setToken } from "@/api";
  62. import { Message } from "bill/expose-common";
  63. import { params } from "@/env";
  64. import { GET_SETTING, getCode } from "@/api/constant";
  65. import { currentLayout, RoutesName } from "@/router";
  66. const username = ref(localStorage.getItem("fuse-username") || "");
  67. const password = ref(localStorage.getItem("fuse-password") || "");
  68. const code = ref("");
  69. const mark = ref(!!localStorage.getItem("fuse-mark"));
  70. const showPwd = ref(false);
  71. const guid = () => {
  72. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
  73. let r = (Math.random() * 16) | 0,
  74. v = c == "x" ? r : (r & 0x3) | 0x8;
  75. return v.toString(16);
  76. });
  77. };
  78. // 图片验证码
  79. let baseURL = "https://test-mix3d.4dkankan.com";
  80. const imgKey = ref(guid());
  81. const refer = () => (imgKey.value = guid());
  82. if (window.location.href.indexOf("localhost") !== -1) {
  83. baseURL = "https://test-mix3d.4dkankan.com";
  84. } else if (window.location.href.indexOf("test") !== -1) {
  85. baseURL = "https://test-mix3d.4dkankan.com";
  86. } else {
  87. baseURL = "https://mix3d.4dkankan.com";
  88. }
  89. const codeImg = computed(() => baseURL + getCode + "?key=" + imgKey.value);
  90. const getDeptId = () => {
  91. const fromRoute = params.fromRoute;
  92. if (fromRoute === "fire") return "1";
  93. if (fromRoute === "cjzfire") return "DEP000011734134901809483776";
  94. if (fromRoute === "xmfire") return "3";
  95. if (fromRoute === "criminal") return "2";
  96. return "";
  97. };
  98. const login = (username: string, password: string, code: string) => {
  99. if (!username) {
  100. return Message.error("账号不能为空");
  101. }
  102. if (!password) {
  103. return Message.error("密码不能为空");
  104. }
  105. if (!code && !import.meta.env.DEV) {
  106. return Message.error("验证码不能为空");
  107. }
  108. const isView = [RoutesName.show, RoutesName.signModel, RoutesName.error].includes(
  109. currentLayout.value!
  110. );
  111. const type = isView ? "view" : "edit";
  112. const headers = { fusionId: params.caseId, "page-type": type };
  113. GAxios.post(
  114. "/fusion/fdLogin",
  115. {
  116. password: encodePwd(password),
  117. userName: username,
  118. phoneNum: username,
  119. code: code,
  120. deptId: getDeptId(),
  121. },
  122. { headers }
  123. ).then(async (res) => {
  124. if (res.data.code !== 0) {
  125. return Message.error(res.data.message);
  126. }
  127. const res1 = await GAxios.get(GET_SETTING, {
  128. params: { fusionId: params.caseId },
  129. headers: { ...headers, token: res.data.data.token },
  130. });
  131. if (res1.data.code === 40111) {
  132. return Message.error("您没有权限,请联系管理员开通");
  133. }
  134. setToken(res.data.data.token);
  135. setTimeout(() => {
  136. const p = new URLSearchParams(location.search);
  137. p.delete("token");
  138. location.search = "?" + p.toString();
  139. setTimeout(() => location.reload(), 100);
  140. }, 100);
  141. if (mark.value) {
  142. localStorage.setItem("fuse-username", username);
  143. localStorage.setItem("fuse-password", password);
  144. localStorage.setItem("fuse-mark", "1");
  145. } else {
  146. localStorage.removeItem("fuse-username");
  147. localStorage.removeItem("fuse-password");
  148. localStorage.removeItem("fuse-mark");
  149. }
  150. });
  151. };
  152. // if (import.meta.env.DEV) {
  153. // login("super-admin", "Aa123456", "");
  154. // }
  155. </script>
  156. <style lang="scss" scoped>
  157. .login-layout {
  158. position: fixed;
  159. inset: 0;
  160. z-index: 99;
  161. background: url("/images/login-backimage.png") no-repeat center center;
  162. background-size: cover;
  163. display: flex;
  164. align-items: center;
  165. justify-content: center;
  166. }
  167. .login-content {
  168. width: 400px;
  169. .header {
  170. display: flex;
  171. flex-direction: column;
  172. align-items: center;
  173. justify-content: center;
  174. margin-bottom: 64px;
  175. img {
  176. width: 80px;
  177. height: 80px;
  178. margin-bottom: 10px;
  179. }
  180. p {
  181. font-weight: bold;
  182. font-size: 32px;
  183. color: #000000;
  184. line-height: 48px;
  185. letter-spacing: 12px;
  186. text-align: center;
  187. font-style: normal;
  188. text-transform: none;
  189. }
  190. }
  191. .body {
  192. margin-bottom: 48px;
  193. }
  194. }
  195. </style>
  196. <style lang="scss" scoped>
  197. .login-content {
  198. .ui-input,
  199. .ui-button {
  200. --colors-color: #d9d9d9;
  201. --base-border-color: #d9d9d9;
  202. --colors-content-color: #000000;
  203. --colors-primary-base: #d9d9d9;
  204. --colors-normal-back: #ffffff;
  205. --colors-primary-base: #0960bd;
  206. --color-main-normal: #0960bd;
  207. }
  208. .ui-button {
  209. color: #fff !important;
  210. border: 1px solid var(--color-main-normal) !important;
  211. background: var(--color-main-normal) !important;
  212. }
  213. .code-row {
  214. display: flex;
  215. align-items: center;
  216. gap: 12px;
  217. margin-top: 20px;
  218. }
  219. .code-input {
  220. flex: 1;
  221. }
  222. .code-img {
  223. width: 120px;
  224. height: 40px;
  225. cursor: pointer;
  226. user-select: none;
  227. flex: none;
  228. }
  229. }
  230. </style>