|
@@ -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>
|