Merge branch 'shiy-login' into Wren
# Conflicts: # .env
This commit is contained in:
@@ -3,7 +3,6 @@ node_modules
|
|||||||
/.cache
|
/.cache
|
||||||
/build
|
/build
|
||||||
/public/build/
|
/public/build/
|
||||||
.env
|
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
.history
|
.history
|
||||||
|
|||||||
+17
-33
@@ -27,6 +27,7 @@ export interface PromptTemplateUI {
|
|||||||
status: 'active' | 'inactive' | 'system';
|
status: 'active' | 'inactive' | 'system';
|
||||||
version: string;
|
version: string;
|
||||||
created_by: number;
|
created_by: number;
|
||||||
|
created_by_username?: string; // 创建者用户名
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
}
|
}
|
||||||
@@ -91,10 +92,10 @@ function mapStatusToAPI(status: string): number {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 将数据库模板转换为UI模板
|
* 将数据库模板转换为UI模板
|
||||||
* @param template 数据库模板
|
* @param template 数据库模板(可能包含关联的用户信息)
|
||||||
* @returns UI模板
|
* @returns UI模板
|
||||||
*/
|
*/
|
||||||
export function convertToUITemplate(template: PromptTemplate): PromptTemplateUI {
|
export function convertToUITemplate(template: PromptTemplate & { sso_users?: { username: string } }): PromptTemplateUI {
|
||||||
return {
|
return {
|
||||||
id: template.id ? template.id.toString() : '',
|
id: template.id ? template.id.toString() : '',
|
||||||
template_name: template.template_name,
|
template_name: template.template_name,
|
||||||
@@ -105,6 +106,7 @@ export function convertToUITemplate(template: PromptTemplate): PromptTemplateUI
|
|||||||
status: mapStatusToUI(template.status),
|
status: mapStatusToUI(template.status),
|
||||||
version: template.version,
|
version: template.version,
|
||||||
created_by: template.created_by,
|
created_by: template.created_by,
|
||||||
|
created_by_username: template.sso_users?.username, // 从关联的用户信息中提取用户名
|
||||||
created_at: formatDate(template.created_at),
|
created_at: formatDate(template.created_at),
|
||||||
updated_at: formatDate(template.updated_at)
|
updated_at: formatDate(template.updated_at)
|
||||||
};
|
};
|
||||||
@@ -127,21 +129,9 @@ export async function getPromptTemplates(searchParams: PromptSearchParams = {},
|
|||||||
const page = searchParams.page || 1;
|
const page = searchParams.page || 1;
|
||||||
const pageSize = searchParams.pageSize || 10;
|
const pageSize = searchParams.pageSize || 10;
|
||||||
|
|
||||||
// 构建查询参数
|
// 构建查询参数,包含对 sso_users 表的左连接
|
||||||
const params: PostgrestParams = {
|
const params: PostgrestParams = {
|
||||||
select: `
|
select: `id,template_name,template_type,description,template_content,variables,status,version,created_by,created_at,updated_at,sso_users!created_by(username)`,
|
||||||
id,
|
|
||||||
template_name,
|
|
||||||
template_type,
|
|
||||||
description,
|
|
||||||
template_content,
|
|
||||||
variables,
|
|
||||||
status,
|
|
||||||
version,
|
|
||||||
created_by,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
`,
|
|
||||||
order: 'updated_at.desc',
|
order: 'updated_at.desc',
|
||||||
headers: {
|
headers: {
|
||||||
'Prefer': 'count=exact'
|
'Prefer': 'count=exact'
|
||||||
@@ -242,19 +232,7 @@ export async function getPromptTemplate(id: string, frontendJWT?: string): Promi
|
|||||||
}
|
}
|
||||||
|
|
||||||
const params: PostgrestParams = {
|
const params: PostgrestParams = {
|
||||||
select: `
|
select: `id,template_name,template_type,description,template_content,variables,status,version,created_by,created_at,updated_at,sso_users!created_by(username)`,
|
||||||
id,
|
|
||||||
template_name,
|
|
||||||
template_type,
|
|
||||||
description,
|
|
||||||
template_content,
|
|
||||||
variables,
|
|
||||||
status,
|
|
||||||
version,
|
|
||||||
created_by,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
`,
|
|
||||||
filter: {
|
filter: {
|
||||||
'id': `eq.${id}`
|
'id': `eq.${id}`
|
||||||
},
|
},
|
||||||
@@ -286,10 +264,11 @@ export async function getPromptTemplate(id: string, frontendJWT?: string): Promi
|
|||||||
/**
|
/**
|
||||||
* 创建提示词模板
|
* 创建提示词模板
|
||||||
* @param template 提示词模板数据
|
* @param template 提示词模板数据
|
||||||
|
* @param userId 当前用户ID
|
||||||
* @param frontendJWT JWT token (可选)
|
* @param frontendJWT JWT token (可选)
|
||||||
* @returns 创建的提示词模板
|
* @returns 创建的提示词模板
|
||||||
*/
|
*/
|
||||||
export async function createPromptTemplate(template: Partial<PromptTemplateUI>, frontendJWT?: string): Promise<{
|
export async function createPromptTemplate(template: Partial<PromptTemplateUI>, userId: number, frontendJWT?: string): Promise<{
|
||||||
data?: PromptTemplateUI;
|
data?: PromptTemplateUI;
|
||||||
error?: string;
|
error?: string;
|
||||||
status?: number;
|
status?: number;
|
||||||
@@ -299,7 +278,12 @@ export async function createPromptTemplate(template: Partial<PromptTemplateUI>,
|
|||||||
if (!template.template_name || !template.template_type || !template.template_content) {
|
if (!template.template_name || !template.template_type || !template.template_content) {
|
||||||
return { error: '模板名称、类型和内容不能为空', status: 400 };
|
return { error: '模板名称、类型和内容不能为空', status: 400 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 验证用户ID
|
||||||
|
if (!userId) {
|
||||||
|
return { error: '用户ID不能为空', status: 400 };
|
||||||
|
}
|
||||||
|
|
||||||
// 准备变量数据
|
// 准备变量数据
|
||||||
let variablesData: Record<string, string> = {};
|
let variablesData: Record<string, string> = {};
|
||||||
if (typeof template.variables === 'string') {
|
if (typeof template.variables === 'string') {
|
||||||
@@ -311,7 +295,7 @@ export async function createPromptTemplate(template: Partial<PromptTemplateUI>,
|
|||||||
} else if (template.variables) {
|
} else if (template.variables) {
|
||||||
variablesData = template.variables;
|
variablesData = template.variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 准备API数据
|
// 准备API数据
|
||||||
const apiTemplate: Partial<PromptTemplate> = {
|
const apiTemplate: Partial<PromptTemplate> = {
|
||||||
template_name: template.template_name,
|
template_name: template.template_name,
|
||||||
@@ -321,7 +305,7 @@ export async function createPromptTemplate(template: Partial<PromptTemplateUI>,
|
|||||||
variables: variablesData,
|
variables: variablesData,
|
||||||
status: mapStatusToAPI(template.status || 'active'),
|
status: mapStatusToAPI(template.status || 'active'),
|
||||||
version: template.version || 'v1.0',
|
version: template.version || 'v1.0',
|
||||||
created_by: 1 // 固定创建者为1
|
created_by: userId // 使用当前登录用户ID
|
||||||
};
|
};
|
||||||
|
|
||||||
if(apiTemplate){
|
if(apiTemplate){
|
||||||
|
|||||||
@@ -72,9 +72,9 @@ const portConfigs: Record<string, Partial<ApiConfig>> = {
|
|||||||
// 主要
|
// 主要
|
||||||
// 梅州
|
// 梅州
|
||||||
'51703': {
|
'51703': {
|
||||||
baseUrl: 'http://nas.7bm.co:8073',
|
baseUrl: 'http://172.16.0.58:8073',
|
||||||
documentUrl: 'http://nas.7bm.co:8073/docauditai/',
|
documentUrl: 'http://172.16.0.58:8073/docauditai/',
|
||||||
uploadUrl: 'http://nas.7bm.co:8073/admin/documents'
|
uploadUrl: 'http://172.16.0.58:8073/admin/documents'
|
||||||
// baseUrl: 'http://nas.7bm.co:8873',
|
// baseUrl: 'http://nas.7bm.co:8873',
|
||||||
// documentUrl: 'http://nas.7bm.co:8873/docauditai/',
|
// documentUrl: 'http://nas.7bm.co:8873/docauditai/',
|
||||||
// uploadUrl: 'http://nas.7bm.co:8873/admin/documents'
|
// uploadUrl: 'http://nas.7bm.co:8873/admin/documents'
|
||||||
|
|||||||
@@ -334,7 +334,8 @@ export default function PromptsIndex() {
|
|||||||
key: "created_by",
|
key: "created_by",
|
||||||
width: "100px",
|
width: "100px",
|
||||||
render: (_: unknown, record: PromptTemplateUI) => (
|
render: (_: unknown, record: PromptTemplateUI) => (
|
||||||
<span className="text-secondary">用户 {record.created_by}</span>
|
// <span className="text-secondary">用户 {record.created_by}</span>
|
||||||
|
<span className="text-secondary">{record.created_by_username}</span>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -109,8 +109,9 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
|||||||
// Action函数 - 处理表单提交
|
// Action函数 - 处理表单提交
|
||||||
export async function action({ request }: ActionFunctionArgs) {
|
export async function action({ request }: ActionFunctionArgs) {
|
||||||
const { getUserSession } = await import("~/api/login/auth.server");
|
const { getUserSession } = await import("~/api/login/auth.server");
|
||||||
const { frontendJWT } = await getUserSession(request);
|
const { userInfo, frontendJWT } = await getUserSession(request);
|
||||||
|
|
||||||
|
const userId = userInfo.get('user_id')
|
||||||
const formData = await request.formData();
|
const formData = await request.formData();
|
||||||
const id = formData.get("id") as string;
|
const id = formData.get("id") as string;
|
||||||
const template_name = formData.get("template_name") as string;
|
const template_name = formData.get("template_name") as string;
|
||||||
@@ -168,7 +169,7 @@ export async function action({ request }: ActionFunctionArgs) {
|
|||||||
result = await updatePromptTemplate(id, apiTemplate, frontendJWT);
|
result = await updatePromptTemplate(id, apiTemplate, frontendJWT);
|
||||||
} else {
|
} else {
|
||||||
// 创建模板
|
// 创建模板
|
||||||
result = await createPromptTemplate(apiTemplate, frontendJWT);
|
result = await createPromptTemplate(apiTemplate, userId, frontendJWT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user