添加nginx相关配置,首页系统概览添加用户id查询

This commit is contained in:
2025-07-24 09:42:39 +08:00
parent 8800e982ab
commit 913702ea10
8 changed files with 1204 additions and 135 deletions
+112 -113
View File
@@ -1,4 +1,4 @@
import { postgrestGet, type PostgrestParams } from "../postgrest-client";
import { postgrestGet, postgrestPost, type PostgrestParams } from "../postgrest-client";
import dayjs from 'dayjs';
/**
@@ -96,7 +96,7 @@ function buildTypeFilter(reviewType: string | null): string {
* @param reviewType 从客户端传入的 reviewType 值
* @returns 主页数据
*/
export async function getHomeData(reviewType?: string | null): Promise<HomeStatistics> {
export async function getHomeData(reviewType?: string | null,userId?: string | number): Promise<HomeStatistics> {
try {
// 获取当前日期和时间相关值
const startOfToday = dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss');
@@ -105,7 +105,8 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
const startOfLastMonth = dayjs().subtract(1, 'month').startOf('month').format('YYYY-MM-DD HH:mm:ss');
const endOfLastMonth = dayjs().subtract(1, 'month').endOf('month').format('YYYY-MM-DD HH:mm:ss');
// console.log('传入的 reviewType', reviewType);
console.log('传入的 reviewType', reviewType);
console.log('传入的 userId', userId);
// 基于 reviewType 构建类型过滤条件
const typeFilter = buildTypeFilter(reviewType || null);
@@ -146,7 +147,8 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
filter: {
or: `(audit_status.eq.0,audit_status.eq.2,audit_status.is.null)`,
created_at: `gte.${startOfToday}`,
is_test_document: `eq.false`
is_test_document: `eq.false`,
user_id: `eq.${userId}`
}
};
@@ -180,7 +182,8 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
filter: {
and: `(audit_status.neq.0,audit_status.neq.2)`,
updated_at: `gte.${startOfThisMonth}`,
is_test_document: `eq.false`
is_test_document: `eq.false`,
user_id: `eq.${userId}`
}
};
@@ -211,7 +214,8 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
filter: {
or: `(audit_status.eq.1,audit_status.eq.-1)`,
and: `(updated_at.gte.${startOfLastMonth},updated_at.lte.${endOfLastMonth})`,
is_test_document: `eq.false`
is_test_document: `eq.false`,
user_id: `eq.${userId}`
}
};
@@ -258,7 +262,8 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
filter: {
audit_status: `eq.1`,
created_at: `gte.${startOfThisMonth}`,
is_test_document: `eq.false`
is_test_document: `eq.false`,
user_id: `eq.${userId}`
}
};
@@ -294,7 +299,8 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
filter: {
audit_status: `eq.1`,
and: `(updated_at.gte.${startOfLastMonth},updated_at.lte.${endOfLastMonth})`,
is_test_document: `eq.false`
is_test_document: `eq.false`,
user_id: `eq.${userId}`
}
};
@@ -352,15 +358,18 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
// 根据 reviewType 设置要查询的文档类型
if (reviewType === 'contract') {
// 合同类型 - 直接查询类型 1
const typeToQuery = 1;
const typeToQuery = [1];
// 调用数据库函数获取本月指定类型的问题数量
const thisMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
postgrestGet(`rpc/count_evaluation_results_by_type?type_val=${typeToQuery}&start_time=${startOfThisMonth}&end_time=${endOfThisMonth}`, {
select: '*',
filter: {}
postgrestPost('rpc/count_evaluation_results_by_type', {
start_time: startOfThisMonth,
end_time: endOfThisMonth,
type_val: typeToQuery,
userid: parseInt(userId as string)
}),
'获取本月问题数据失败',
'获取合同本月问题数据失败',
[]
);
@@ -369,9 +378,11 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
// 调用数据库函数获取上月指定类型的问题数量
const lastMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
postgrestGet(`rpc/count_evaluation_results_by_type?type_val=${typeToQuery}&start_time=${startOfLastMonth}&end_time=${endOfLastMonth}`, {
select: '*',
filter: {}
postgrestPost('rpc/count_evaluation_results_by_type', {
start_time: startOfLastMonth,
end_time: endOfLastMonth,
type_val: typeToQuery,
userid: parseInt(userId as string)
}),
'获取上月问题数据失败',
[]
@@ -382,120 +393,108 @@ export async function getHomeData(reviewType?: string | null): Promise<HomeStati
} else if (reviewType === 'record') {
// 记录类型 - 需要查询类型 2 和类型 3,并合并结果
const typeToQuery = [2,3];
// 查询类型 2 的本月问题数量
const thisMonthType2Response = await handleApiResponse<{ count: number }[]>(
postgrestGet(`rpc/count_evaluation_results_by_type?type_val=2&start_time=${startOfThisMonth}&end_time=${endOfThisMonth}`, {
select: '*',
filter: {}
postgrestPost('rpc/count_evaluation_results_by_type', {
start_time: startOfThisMonth,
end_time: endOfThisMonth,
type_val: typeToQuery,
userid: parseInt(userId as string)
}),
'获取本月类型2问题数据失败',
'获取本月许可卷宗类型2问题数据失败',
[]
);
// 查询类型 3 的本月问题数量
const thisMonthType3Response = await handleApiResponse<{ count: number }[]>(
postgrestGet(`rpc/count_evaluation_results_by_type?type_val=3&start_time=${startOfThisMonth}&end_time=${endOfThisMonth}`, {
select: '*',
filter: {}
}),
'获取本月类型3问题数据失败',
[]
);
// 合并本月两种类型的问题数量
// 本月两种类型的问题数量
const thisMonthType2Count = thisMonthType2Response[0]?.count || 0;
const thisMonthType3Count = thisMonthType3Response[0]?.count || 0;
thisMonthIssuesCount = thisMonthType2Count + thisMonthType3Count;
thisMonthIssuesCount = thisMonthType2Count
// 查询类型 2 的上月问题数量
// 上月两种类型的问题数量
const lastMonthType2Response = await handleApiResponse<{ count: number }[]>(
postgrestGet(`rpc/count_evaluation_results_by_type?type_val=2&start_time=${startOfLastMonth}&end_time=${endOfLastMonth}`, {
select: '*',
filter: {}
postgrestPost('rpc/count_evaluation_results_by_type', {
start_time: startOfLastMonth,
end_time: endOfLastMonth,
type_val: typeToQuery,
userid: parseInt(userId as string)
}),
'获取上月类型2问题数据失败',
'获取上月许可卷宗类型2问题数据失败',
[]
);
// 查询类型 3 的上月问题数量
const lastMonthType3Response = await handleApiResponse<{ count: number }[]>(
postgrestGet(`rpc/count_evaluation_results_by_type?type_val=3&start_time=${startOfLastMonth}&end_time=${endOfLastMonth}`, {
select: '*',
filter: {}
}),
'获取上月类型3问题数据失败',
[]
);
// 合并上月两种类型的问题数量
// 上月两种类型的问题数量
const lastMonthType2Count = lastMonthType2Response[0]?.count || 0;
const lastMonthType3Count = lastMonthType3Response[0]?.count || 0;
lastMonthIssuesCount = lastMonthType2Count + lastMonthType3Count;
lastMonthIssuesCount = lastMonthType2Count
} else {
// 如果没有指定类型,则使用原来的查询方式获取所有类型的问题数量
const thisMonthIssuesParams: PostgrestParams = {
select: 'count',
filter: {
and: `(created_at.gte.${startOfThisMonth},created_at.lte.${endOfThisMonth})`,
'evaluated_results->result': 'eq.false' // 使用->操作符访问JSONB字段
}
};
// 添加类型过滤条件
if (typeFilter) {
if (typeFilter.startsWith('(')) {
thisMonthIssuesParams.or = typeFilter;
} else {
const [field, op, value] = typeFilter.split('.');
if (!thisMonthIssuesParams.filter) {
thisMonthIssuesParams.filter = {};
}
thisMonthIssuesParams.filter[field] = `${op}.${value}`;
}
}
const thisMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
postgrestGet('evaluation_results', thisMonthIssuesParams),
'获取本月问题数据失败',
[]
);
// 本月问题数量
thisMonthIssuesCount = thisMonthIssuesResponse[0]?.count || 0;
// 上月问题数量
const lastMonthIssuesParams: PostgrestParams = {
select: 'count',
filter: {
and: `(created_at.gte.${startOfLastMonth},created_at.lte.${endOfLastMonth})`,
'evaluated_results->result': 'eq.false' // 使用->操作符访问JSONB字段
}
};
// 添加类型过滤条件
if (typeFilter) {
if (typeFilter.startsWith('(')) {
lastMonthIssuesParams.or = typeFilter;
} else {
const [field, op, value] = typeFilter.split('.');
if (!lastMonthIssuesParams.filter) {
lastMonthIssuesParams.filter = {};
}
lastMonthIssuesParams.filter[field] = `${op}.${value}`;
}
}
const lastMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
postgrestGet('evaluation_results', lastMonthIssuesParams),
'获取上月问题数据失败',
[]
);
// 上月问题数量
lastMonthIssuesCount = lastMonthIssuesResponse[0]?.count || 0;
}
// 暂时不会存在没有指定类型得情况,暂不实现。
// else {
// // 如果没有指定类型,则使用原来的查询方式获取所有类型的问题数量
// const thisMonthIssuesParams: PostgrestParams = {
// select: 'count',
// filter: {
// and: `(created_at.gte.${startOfThisMonth},created_at.lte.${endOfThisMonth})`,
// 'evaluated_results->result': 'eq.false',
// user_id: `eq.${userId}`
// }
// };
// // 添加类型过滤条件
// if (typeFilter) {
// if (typeFilter.startsWith('(')) {
// thisMonthIssuesParams.or = typeFilter;
// } else {
// const [field, op, value] = typeFilter.split('.');
// if (!thisMonthIssuesParams.filter) {
// thisMonthIssuesParams.filter = {};
// }
// thisMonthIssuesParams.filter[field] = `${op}.${value}`;
// }
// }
// const thisMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
// postgrestGet('evaluation_results', thisMonthIssuesParams),
// '获取本月问题数据失败',
// []
// );
// // 本月问题数量
// thisMonthIssuesCount = thisMonthIssuesResponse[0]?.count || 0;
// // 上月问题数量
// const lastMonthIssuesParams: PostgrestParams = {
// select: 'count',
// filter: {
// and: `(created_at.gte.${startOfLastMonth},created_at.lte.${endOfLastMonth})`,
// 'evaluated_results->result': 'eq.false',
// user_id: `eq.${userId}`
// }
// };
// // 添加类型过滤条件
// if (typeFilter) {
// if (typeFilter.startsWith('(')) {
// lastMonthIssuesParams.or = typeFilter;
// } else {
// const [field, op, value] = typeFilter.split('.');
// if (!lastMonthIssuesParams.filter) {
// lastMonthIssuesParams.filter = {};
// }
// lastMonthIssuesParams.filter[field] = `${op}.${value}`;
// }
// }
// const lastMonthIssuesResponse = await handleApiResponse<{ count: number }[]>(
// postgrestGet('evaluation_results', lastMonthIssuesParams),
// '获取上月问题数据失败',
// []
// );
// // 上月问题数量
// lastMonthIssuesCount = lastMonthIssuesResponse[0]?.count || 0;
// }
// 计算问题数量同比增长
let issuesGrowthValue = 0;
+110 -6
View File
@@ -44,7 +44,7 @@ const configs: Record<string, ApiConfig> = {
serverUrl: 'http://10.79.112.85', // IDaaS服务器地址
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb', // 需要替换为实际的Client Secret
redirectUri: 'http://10.79.97.17/', // 回调地址
redirectUri: 'http://10.79.97.17/callback', // 回调地址
appId: 'idaasoauth2' // 应用ID,用于登出
}
},
@@ -75,7 +75,8 @@ const configs: Record<string, ApiConfig> = {
serverUrl: 'http://10.79.112.85', // IDaaS服务器地址
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb', // 需要替换为实际的Client Secret
redirectUri: 'http://10.79.97.17/', // 回调地址
redirectUri: 'http://10.79.97.17/callback', // 回调地址
appId: 'idaasoauth2' // 应用ID,用于登出
}
},
@@ -95,12 +96,97 @@ const configs: Record<string, ApiConfig> = {
}
};
// 客户端特定配置 - 支持多客户端部署
// 根据环境自动选择配置
const getClientConfigs = (env: string): Record<string, Partial<ApiConfig>> => {
if (env === 'development') {
// 开发环境 - 本地nginx代理配置
return {
'client-a': {
baseUrl: 'http://localhost:8001',
uploadUrl: 'http://localhost:8001/admin/documents',
oauth: {
serverUrl: 'http://10.79.112.85',
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
redirectUri: 'http://localhost:8001/callback',
appId: 'idaasoauth2'
}
},
'client-b': {
baseUrl: 'http://localhost:8002',
uploadUrl: 'http://localhost:8002/admin/documents',
oauth: {
serverUrl: 'http://10.79.112.85',
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
redirectUri: 'http://localhost:8002/callback',
appId: 'idaasoauth2'
}
},
'client-c': {
baseUrl: 'http://localhost:8003',
uploadUrl: 'http://localhost:8003/admin/documents',
oauth: {
serverUrl: 'http://10.79.112.85',
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
redirectUri: 'http://localhost:8003/callback',
appId: 'idaasoauth2'
}
}
};
} else {
// 生产环境 - 服务器配置
return {
'client-a': {
baseUrl: 'http://10.79.97.17:51701',
uploadUrl: 'http://10.79.97.17:51701/admin/documents',
oauth: {
serverUrl: 'http://10.79.112.85',
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
redirectUri: 'http://10.79.97.17:51701/callback',
appId: 'idaasoauth2'
}
},
'client-b': {
baseUrl: 'http://10.79.97.17:51702',
uploadUrl: 'http://10.79.97.17:51702/admin/documents',
oauth: {
serverUrl: 'http://10.79.112.85',
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
redirectUri: 'http://10.79.97.17:51702/callback',
appId: 'idaasoauth2'
}
},
'client-c': {
baseUrl: 'http://10.79.97.17:51704',
uploadUrl: 'http://10.79.97.17:51704/admin/documents',
oauth: {
serverUrl: 'http://10.79.112.85',
clientId: '54d2a619fe5c81ae1250434c441fccccqMtKwh7H4fO',
clientSecret: 'VYk1AC5XIJEfnEXwyq0u9JEY3fi3byCfSD58zANGeb',
redirectUri: 'http://10.79.97.17:51704/callback',
appId: 'idaasoauth2'
}
}
};
}
};
// 获取当前环境,默认为development
const getCurrentEnvironment = (): string => {
// 优先使用环境变量,然后使用 NODE_ENV
return process.env.NEXT_PUBLIC_API_ENV || process.env.NODE_ENV || 'development';
};
// 获取客户端ID
const getClientId = (): string => {
return process.env.CLIENT_ID || process.env.NEXT_PUBLIC_CLIENT_ID || 'main';
};
// 从环境变量获取配置,如果环境变量不存在则使用默认配置
const getConfigFromEnv = (defaultConfig: ApiConfig): ApiConfig => {
return {
@@ -117,17 +203,35 @@ const getConfigFromEnv = (defaultConfig: ApiConfig): ApiConfig => {
};
};
// 获取当前配置
// 获取当前配置 - 支持客户端特定配置
const getCurrentConfig = (): ApiConfig => {
const env = getCurrentEnvironment();
const clientId = getClientId();
const defaultConfig = configs[env] || configs.development;
// 获取当前环境的客户端特定配置
const clientConfigs = getClientConfigs(env);
const clientConfig = clientConfigs[clientId];
// 合并默认配置和客户端特定配置
let finalConfig = defaultConfig;
if (clientConfig) {
finalConfig = {
...defaultConfig,
...clientConfig,
oauth: {
...defaultConfig.oauth,
...clientConfig.oauth
}
};
}
// 如果是浏览器环境,尝试从环境变量覆盖配置
if (typeof window !== 'undefined' || process.env.NEXT_PUBLIC_API_BASE_URL) {
return getConfigFromEnv(defaultConfig);
return getConfigFromEnv(finalConfig);
}
return defaultConfig;
return finalConfig;
};
// 导出当前环境的配置
@@ -155,4 +259,4 @@ export const setEnvironment = (env: string): ApiConfig => {
// environment: getCurrentEnvironment(),
// config: apiConfig
// });
// }
// }
+18 -11
View File
@@ -11,7 +11,7 @@ import { getDocuments, type DocumentUI, type DocumentSearchParams } from "~/api/
import { useState, useEffect } from "react";
import { getHomeData } from "~/api/home/home";
import dayjs from 'dayjs';
import type { UserRole } from '~/api/login/auth.server';
// import type { UserRole } from '~/api/login/auth.server';
import { type ActionFunctionArgs, type LoaderFunctionArgs } from "@remix-run/node";
import { logout, getUserSession } from "~/api/login/auth.server";
@@ -48,7 +48,8 @@ export const meta: MetaFunction = () => {
export async function loader({ request }: LoaderFunctionArgs) {
try {
// 从根loader获取用户角色
const { userRole } = await getUserSession(request);
const { userRole, userInfo, frontendJWT } = await getUserSession(request);
// 返回默认值,实际数据将在客户端根据 sessionStorage 加载
return Response.json({
@@ -63,7 +64,9 @@ export async function loader({ request }: LoaderFunctionArgs) {
},
recentFiles: [],
reviewType: null,
userRole: userRole
userRole: userRole,
userInfo,
frontendJWT
});
} catch (error) {
// 错误处理
@@ -89,7 +92,7 @@ export async function action({ request }: ActionFunctionArgs) {
export default function Home() {
const navigate = useNavigate();
const { homeData: initialHomeData, recentFiles: initialRecentFiles, userRole: serverUserRole } = useLoaderData<typeof loader>();
const { homeData: initialHomeData, recentFiles: initialRecentFiles, userRole: serverUserRole, userInfo } = useLoaderData<typeof loader>();
const [recentFiles, setRecentFiles] = useState<DocumentUI[]>(initialRecentFiles || []);
const [homeData, setHomeData] = useState(initialHomeData);
const [currentDateTime, setCurrentDateTime] = useState({
@@ -97,7 +100,7 @@ export default function Home() {
time: ''
});
const [isLoading, setIsLoading] = useState(true);
const userRole = serverUserRole as UserRole;
// const userRole = serverUserRole as UserRole;
// 打印服务器端传递的用户角色
useEffect(() => {
@@ -155,7 +158,7 @@ export default function Home() {
const reviewType = sessionStorage.getItem('reviewType');
// 加载主页数据
const newHomeData = await getHomeData(reviewType || undefined);
const newHomeData = await getHomeData(reviewType || undefined,userInfo.user_id);
setHomeData(newHomeData);
// 加载文档数据
@@ -177,7 +180,8 @@ export default function Home() {
try {
const documentSearchParams: DocumentSearchParams = {
page: 1,
pageSize: 10
pageSize: 10,
userId: userInfo.user_id
};
// 根据 reviewType 添加过滤条件
@@ -186,6 +190,7 @@ export default function Home() {
const response = await getDocuments(documentSearchParams);
if (!response.error && response.data) {
// console.log('合同文档数据',response.data.documents);
return response.data.documents;
}
} else if (reviewType === 'record') {
@@ -209,6 +214,7 @@ export default function Home() {
);
// 限制数量
// console.log('卷宗文档数据',mergedDocs);
return mergedDocs.slice(0, documentSearchParams.pageSize);
}
} else {
@@ -236,7 +242,7 @@ export default function Home() {
setIsLoading(true);
// 更新主页数据
const newHomeData = await getHomeData(currentReviewType || undefined);
const newHomeData = await getHomeData(currentReviewType || undefined,userInfo.user_id);
setHomeData(newHomeData);
// 更新文档数据
@@ -301,14 +307,15 @@ export default function Home() {
</div>
<div className="user-profile p-4 border-b border-gray-100 flex items-center">
<div className="avatar w-10 h-10 rounded-full bg-primary text-white flex items-center justify-center">
<span>{userRole === 'developer' ? '管' : '用'}</span>
<span>{userInfo.nick_name.charAt(userInfo.nick_name.length-1)}</span>
</div>
<div className="ml-1">
<p className="text-sm font-medium mb-0">{userRole === 'developer' ? '系统管理员' : '普通用户'}</p>
{/* <p className="text-sm font-medium mb-0">{userRole === 'developer' ? '系统管理员' : '普通用户'}</p> */}
<p className="text-sm font-medium mb-0">{userInfo.nick_name}</p>
{/* <p className="text-xs text-gray-500 mb-0">{userRole === 'developer' ? '超级管理员' : '标准权限'}</p> */}
</div>
</div>
{/* 登出操作 */}
{/* 登出操作 */}
<Button
type="default"
size="small"