zhangjie 1 рік тому
батько
коміт
298fda8fd7

+ 1 - 3
src/api/loginPage.ts

@@ -7,9 +7,7 @@ export function loginByUsername(loginInfo: {
   password: string;
   rootOrgId: number;
 }) {
-  return httpApp.post("/api/ess/auth/login", loginInfo, {
-    noErrorMessage: true,
-  });
+  return httpApp.post("/api/ess/auth/login", loginInfo);
 }
 
 /** 登出 */

+ 24 - 18
src/features/login/Login.vue

@@ -50,6 +50,8 @@ import { loginByUsername } from "@/api/loginPage";
 import { useRouteQuery } from "@vueuse/router";
 import { useRouter } from "vue-router";
 import { useMainStore } from "@/store";
+import useLoading from "@/hooks/loading";
+
 import { reactive } from "vue";
 import type { Rule } from "ant-design-vue/es/form";
 import type { FormInstance } from "ant-design-vue";
@@ -61,8 +63,6 @@ if (!rootOrgId) {
   void router.push("/?rootOrgId=1");
 }
 
-let errorInfo = $ref("");
-let loading = $ref(false);
 const formRef = $ref<FormInstance>();
 const formData = reactive({
   accountValue: "",
@@ -75,23 +75,29 @@ const rules: Record<string, Rule[]> = {
   ],
   password: [{ required: true, message: "请输入你的密码", trigger: "change" }],
 };
+
+const { loading, setLoading } = useLoading();
 async function submit() {
-  try {
-    const res = await loginByUsername({
-      accountValue: formData.accountValue,
-      password: formData.password,
-      rootOrgId: parseInt(rootOrgId?.toString() ?? "1"),
-    });
-    console.log(res);
-    store.setUserInfo(res.data);
-    if (rootOrgId === "1") {
-      void router.push("/basic/rootOrg");
-    } else {
-      void router.push("/project/projectManagement");
-    }
-  } catch (error) {
-    console.log(error);
-    errorInfo = (<any>error).response.data.desc;
+  const valid = await formRef?.validate().catch(() => {});
+  console.log(valid);
+  if (!valid) return;
+
+  if (loading.value) return;
+  setLoading(true);
+  const res = await loginByUsername({
+    accountValue: formData.accountValue,
+    password: formData.password,
+    rootOrgId: parseInt(rootOrgId?.toString() ?? "1"),
+  }).catch(() => {});
+  setLoading(false);
+  if (!res) return;
+
+  console.log(res);
+  store.setUserInfo(res.data);
+  if (rootOrgId === "1") {
+    void router.push("/basic/rootOrg");
+  } else {
+    void router.push("/project/projectManagement");
   }
 }
 </script>

+ 16 - 0
src/hooks/loading.ts

@@ -0,0 +1,16 @@
+import { ref } from "vue";
+
+export default function useLoading(initValue = false) {
+  const loading = ref(initValue);
+  const setLoading = (value: boolean) => {
+    loading.value = value;
+  };
+  const toggle = () => {
+    loading.value = !loading.value;
+  };
+  return {
+    loading,
+    setLoading,
+    toggle,
+  };
+}

+ 0 - 3
src/main.ts

@@ -6,14 +6,11 @@ if (!validUA) {
   location.href = "about:blank";
 }
 
-// import "./styles/tailwind.css";
 import "./styles/index.less";
 import "./features/report/assets/report.css";
 
 import { createApp } from "vue";
 import App from "./App.vue";
-// import Antd from "ant-design-vue";
-// import "ant-design-vue/dist/reset.css";
 
 import router from "@/router";
 import filters from "@/filters";

+ 6 - 6
src/plugins/axiosApp.ts

@@ -67,7 +67,7 @@ _axiosApp.interceptors.request.use(
     if (error.config.setGlobalMask) {
       store.globalMask = false;
     }
-    void message.error({ content: error, duration: 10 });
+    void message.error({ content: error, duration: 5 });
     console.log(error);
     return Promise.reject(error);
   }
@@ -91,7 +91,7 @@ _axiosApp.interceptors.response.use(
         // "Network Error" 网络不通,直接返回
         void message.error({
           content: "网络连接异常,请检查网络设置。",
-          duration: 10,
+          duration: 5,
         });
       }
       return Promise.reject(error);
@@ -108,12 +108,12 @@ _axiosApp.interceptors.response.use(
       return Promise.reject(error);
     } else if (status == 405) {
       if (showErrorMessage) {
-        void message.error({ content: "没有权限!", duration: 10 });
+        void message.error({ content: "没有权限!", duration: 5 });
       }
       return Promise.reject(error);
     } else if (status == 502) {
       if (showErrorMessage) {
-        void message.error({ content: "服务器异常(502)!", duration: 10 });
+        void message.error({ content: "服务器异常(502)!", duration: 5 });
       }
       return Promise.reject(error);
     }
@@ -124,14 +124,14 @@ _axiosApp.interceptors.response.use(
         if (showErrorMessage) {
           void message.error({
             content: data.message || data.desc,
-            duration: 10,
+            duration: 5,
           });
         }
       } else {
         if (showErrorMessage) {
           void message.error({
             content: "未定义异常: " + JSON.stringify(data, null, 2),
-            duration: 10,
+            duration: 5,
           });
         }
       }

+ 22 - 0
src/styles/ant-custom.less

@@ -0,0 +1,22 @@
+// ant-message-notice
+.ant-message-notice {
+  .ant-message-notice-content {
+    padding: 0;
+  }
+  .ant-message-custom-content {
+    padding: 11px 15px;
+    border: 1px solid #fff;
+    border-radius: 8px;
+    color: var(--app-main-text-color);
+  }
+  .ant-message-error {
+    border-color: var(--color-danger);
+    background-color: var(--color-danger-light);
+    color: var(--color-danger);
+  }
+  .ant-message-success {
+    border-color: var(--color-success);
+    background-color: var(--color-success-light);
+    color: var(--color-success);
+  }
+}

+ 0 - 48
src/styles/global.less

@@ -19,54 +19,6 @@ body {
   font-size: var(--app-secondary-font-size);
 }
 
-.ant-message {
-  z-index: 6001 !important;
-  font-size: 16px !important;
-}
-
-.ant-pagination-item-link span[role="img"],
-.ant-message-custom-content span[role="img"] {
-  vertical-align: 0.2em !important;
-}
-
-// button.ant-btn {
-//   height: 32px;
-//   padding: 4px 16px;
-//   font-size: 14px;
-//   border-radius: 8px;
-// }
-
-button.ant-btn span[role="img"] {
-  display: inline-flex !important;
-}
-
-// button.ant-btn-primary {
-//   background-color: var(--app-primary-button-bg-color);
-// }
-
-// button.ant-btn.query-btn {
-//   background-color: #fe8398;
-//   color: white;
-// }
-
-button.ant-btn.download-tpl-btn {
-  background-color: #fe8398;
-  color: white;
-}
-
-// .ant-select .ant-select-selector {
-//   border-radius: 5px !important;
-// }
-
-// .ant-input-affix-wrapper {
-//   border-radius: 5px !important;
-// }
-
-// .ant-input,
-// .ant-input-number {
-//   border-radius: 5px !important;
-// }
-
 /* modal 不要“取消按钮” */
 .ant-modal-content .ant-modal-footer button:first-child {
   display: none;

+ 1 - 0
src/styles/index.less

@@ -1,5 +1,6 @@
 @import "./global.less";
 @import "./nprogress.less";
+@import "./ant-custom.less";
 
 @import "./login.less";
 @import "./home.less";

+ 0 - 3
src/styles/tailwind.css

@@ -1,3 +0,0 @@
-@tailwind base;
-@tailwind components;
-@tailwind utilities;