修复切换<视频智能分析>与<蚕茧仪评分析>Tab页后其他页面无法正常加载的问题

This commit is contained in:
BBIT-Kai
2025-08-22 09:57:27 +08:00
parent cdce90bb27
commit 10ca219970
7 changed files with 335 additions and 229 deletions
+22
View File
@@ -8,6 +8,12 @@ export namespace AuthApi {
account?: string;
password?: string;
}
/** 注册 */
export interface RegisterParams {
account?: string;
code?: string;
password?: string;
}
export interface Token {
token: string;
@@ -39,6 +45,22 @@ export async function loginApi(data: AuthApi.LoginParams) {
return requestClient.post<AuthApi.LoginResult>('/user/login', data);
}
/**
* 发送验证码
*/
export async function sendCodeApi(str: string) {
return requestClient.post<any>('/user/sendCode', { str });
}
/**
* 注册
*/
export async function registerApi(data: AuthApi.RegisterParams) {
// 密码加密
data.password = sha256(data.password?.toString() || '');
return requestClient.post<any>('/user/register', data);
}
/**
* 刷新accessToken
*/
+1
View File
@@ -46,5 +46,6 @@ export const overridesPreferences = defineOverridesPreferences({
},
tabbar: {
middleClickToClose: true,
keepAlive: false,
},
});
@@ -22,7 +22,7 @@ const routes: RouteRecordRaw[] = [
authority: ['iva'],
icon: 'mdi:video',
title: $t('ai.intelligence_video_analysis'),
keepAlive: false,
keepAlive: true,
},
component: () => import('#/views/ai/iva/index.vue'),
},
@@ -33,6 +33,7 @@ const routes: RouteRecordRaw[] = [
authority: ['sca'],
icon: 'mdi:ice-cream',
title: $t('ai.silkworm_cocoon_analysis'),
keepAlive: false,
},
component: () => import('#/views/ai/sca/index.vue'),
},
@@ -43,6 +44,7 @@ const routes: RouteRecordRaw[] = [
authority: ['ysa'],
icon: 'mdi:account-key-outline',
title: $t('ai.young_silkworm_analysis'),
keepAlive: false,
},
component: () => import('#/views/ai/ysa/index.vue'),
},
@@ -53,7 +55,7 @@ const routes: RouteRecordRaw[] = [
meta: {
icon: 'mdi:wall-fire',
iframeSrc: 'http://171.212.101.199:13010/',
keepAlive: true,
keepAlive: false,
title: '检索增强生成',
},
},
@@ -2,25 +2,72 @@
import type { VbenFormSchema } from '@vben/common-ui';
import type { Recordable } from '@vben/types';
import { computed, h, ref } from 'vue';
import { computed, h, ref, useTemplateRef } from 'vue';
import { AuthenticationRegister, z } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { registerApi, sendCodeApi } from '#/api';
import { useAuthStore } from '#/store';
defineOptions({ name: 'Register' });
const loading = ref(false);
const CODE_LENGTH = 4;
const registerRef =
useTemplateRef<InstanceType<typeof AuthenticationRegister>>('registerRef');
const sending = ref(false);
const formSchema = computed((): VbenFormSchema[] => {
return [
{
component: 'VbenInput',
componentProps: {
placeholder: $t('authentication.usernameTip'),
placeholder: $t('authentication.emailTip'),
},
fieldName: 'username',
label: $t('authentication.username'),
rules: z.string().min(1, { message: $t('authentication.usernameTip') }),
fieldName: 'account',
label: $t('authentication.email'),
rules: z
.string()
.min(1, { message: $t('authentication.emailTip') })
.refine((v) => /^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(v), {
message: $t('邮箱格式错误'),
}),
},
{
component: 'VbenPinInput',
componentProps: {
codeLength: CODE_LENGTH,
createText(countdown: number) {
if (sending.value) {
return $t('正在发送中');
}
return countdown > 0
? $t('authentication.sendText', [countdown])
: $t('authentication.sendCode');
},
placeholder: $t('authentication.code'),
async handleSendCode() {
sending.value = true;
try {
const formApi = registerRef.value?.getFormApi();
if (!formApi) throw new Error('formApi is not ready');
await formApi.validateField('account');
const isPhoneReady = await formApi.isFieldValid('account');
if (!isPhoneReady) throw new Error('邮箱不可为空');
const { account } = await formApi.getValues();
await sendCodeApi(account);
} finally {
sending.value = false;
}
},
},
fieldName: 'code',
label: $t('authentication.code'),
rules: z.string().length(CODE_LENGTH, {
message: $t('authentication.codeTip', [CODE_LENGTH]),
}),
},
{
component: 'VbenInputPassword',
@@ -80,15 +127,32 @@ const formSchema = computed((): VbenFormSchema[] => {
},
];
});
async function handleSubmit(value: Recordable<any>) {
loading.value = true;
try {
const params = {
account: value.account,
code: value.code,
password: value.password,
};
const { accessToken } = await registerApi(params);
function handleSubmit(value: Recordable<any>) {
// eslint-disable-next-line no-console
console.log('register submit:', value);
if (accessToken) {
// 注册成功后,把 token 交给 authStore 走统一流程
const authStore = useAuthStore();
authStore.authLogin({ account: value.account, password: value.password });
}
} catch (error) {
console.error('注册失败', error);
} finally {
loading.value = false;
}
}
</script>
<template>
<AuthenticationRegister
ref="registerRef"
:form-schema="formSchema"
:loading="loading"
@submit="handleSubmit"
@@ -345,6 +345,7 @@ function onListItemClick(video: any) {
</script>
<template>
<div class="flex h-full w-full flex-col">
<BaseModal />
<CreateVideoTaskModal />
<div class="flex h-full w-full bg-gray-50">
@@ -494,4 +495,5 @@ function onListItemClick(video: any) {
</div>
</div>
</div>
</div>
</template>
+17 -2
View File
@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref, watch } from 'vue';
import { onActivated, onDeactivated, onMounted, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
@@ -144,9 +144,21 @@ function refreshLineChart() {
},
});
}
onDeactivated(() => {
// 离开路由时清理状态
selectedItem.value = null;
showInfoStr.value = {};
});
onActivated(() => {
// 回来的时候重新刷新一次列表
loadList();
});
</script>
<template>
<div class="flex h-full w-full flex-col">
<BaseModal />
<CreateYSATaskModal />
<div class="flex h-full w-full bg-gray-50">
@@ -204,7 +216,9 @@ function refreshLineChart() {
:key="key"
class="mb-2 flex text-sm text-gray-700"
>
<div class="w-32 font-medium text-gray-900">{{ key }}</div>
<div class="w-32 font-medium text-gray-900">
{{ key }}
</div>
<div class="flex-1 break-all text-gray-600">
{{ value || '—' }}
</div>
@@ -252,4 +266,5 @@ function refreshLineChart() {
</template>
</div>
</div>
</div>
</template>
@@ -46,7 +46,7 @@
"sendResetLink": "发送重置链接",
"sendText": "{0}秒后重新获取",
"signUp": "注册",
"signUpSubtitle": "让您的应用程序管理变得简单而有趣",
"signUpSubtitle": "让您的人工智能体验变得简单而有趣",
"terms": "条款",
"thirdPartyLogin": "其他登录方式",
"username": "账号",