|
|
@@ -2,6 +2,7 @@
|
|
|
import { computed, onMounted, reactive, ref, watch } from 'vue';
|
|
|
import { Crypto } from '@sa/utils';
|
|
|
import { fetchGetCaptcha } from '@/service/api/common';
|
|
|
+import { fetchGetTenantOptions } from '@/service/api/auth';
|
|
|
import { useAuthStore } from '@/store/modules/auth';
|
|
|
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
|
|
import { localStg } from '@/utils/storage';
|
|
|
@@ -15,6 +16,22 @@ const authStore = useAuthStore();
|
|
|
const { formRef, validate } = useNaiveForm();
|
|
|
const isRememberMe = ref(false);
|
|
|
const imgPath = ref('');
|
|
|
+
|
|
|
+// 租户选项
|
|
|
+const tenantOptions = ref<{ label: string; value: string }[]>([]);
|
|
|
+const selectedTenantCode = ref<string | null>(null);
|
|
|
+
|
|
|
+async function loadTenantOptions() {
|
|
|
+ const { data } = await fetchGetTenantOptions();
|
|
|
+ if (data) {
|
|
|
+ tenantOptions.value = (data as any[]).map((item: any) => ({
|
|
|
+ label: item.tenantName,
|
|
|
+ value: item.tenantCode
|
|
|
+ }));
|
|
|
+ }
|
|
|
+}
|
|
|
+loadTenantOptions();
|
|
|
+
|
|
|
interface FormModel {
|
|
|
userName: string;
|
|
|
password: string;
|
|
|
@@ -51,12 +68,16 @@ const rules = computed<Record<keyof FormModel, App.Global.FormRule[]>>(() => {
|
|
|
const captchaKey = ref('');
|
|
|
async function handleSubmit() {
|
|
|
await validate();
|
|
|
+ if (!selectedTenantCode.value) {
|
|
|
+ window.$message?.error('请选择租户');
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (isRememberMe.value) {
|
|
|
const pwd = pd.encrypt({ data: model.password });
|
|
|
localStg.set('userName', model.userName);
|
|
|
localStg.set('password', pwd);
|
|
|
}
|
|
|
- await authStore.login({ ...model, captchaKey: captchaKey.value });
|
|
|
+ await authStore.login({ ...model, captchaKey: captchaKey.value, tenantCode: selectedTenantCode.value || undefined });
|
|
|
}
|
|
|
async function getDataCode() {
|
|
|
const { data } = await fetchGetCaptcha();
|
|
|
@@ -77,6 +98,9 @@ watch(
|
|
|
|
|
|
<template>
|
|
|
<NForm ref="formRef" :model="model" :rules="rules" size="large" :show-label="false" @keyup.enter="handleSubmit">
|
|
|
+ <NFormItem :rule="{ required: true, message: '请选择租户', trigger: 'change' }">
|
|
|
+ <NSelect v-model:value="selectedTenantCode" :options="tenantOptions" placeholder="请选择租户" />
|
|
|
+ </NFormItem>
|
|
|
<NFormItem path="userName">
|
|
|
<NInput v-model:value="model.userName" :placeholder="$t('page.login.common.userNamePlaceholder')" />
|
|
|
</NFormItem>
|