feat: improve error handling and code quality

后端改进:
- 添加统一异常处理系统 (exceptions.py, response.py)
- 实现自定义异常类 (ValidationError, AuthorizationError, ResourceNotFoundError, BusinessLogicError)
- 配置全局异常处理器,统一 API 错误响应格式
- 迁移业务逻辑错误到自定义异常 (users.py, auth.py)
- 添加 SQL LIKE 通配符转义,防止通配符滥用
- 使用 EmailStr 进行邮箱格式验证
- 移除敏感字段暴露 (jwt_sub)

前端改进:
- 配置 ESLint 9 (flat config) 和 Prettier
- 修复所有 ESLint 错误和警告
- 移除未使用的变量和导入
- 为组件添加 PropTypes 默认值
- 统一代码格式和风格
This commit is contained in:
2026-01-03 19:01:15 +08:00
parent 523da50123
commit 5cdc8b2144
57 changed files with 4623 additions and 2754 deletions
+72 -72
View File
@@ -1,5 +1,5 @@
import { defineStore } from 'pinia'
import { templateAPI } from '@/api'
import { defineStore } from 'pinia';
import { templateAPI } from '@/api';
export const useTemplateStore = defineStore('template', {
state: () => ({
@@ -10,153 +10,153 @@ export const useTemplateStore = defineStore('template', {
}),
getters: {
activeTemplates: (state) => state.templates.filter((t) => t.is_active),
activeTemplates: state => state.templates.filter(t => t.is_active),
getTemplateById: (state) => (id) => {
return state.templates.find((t) => t.id === id)
getTemplateById: state => id => {
return state.templates.find(t => t.id === id);
},
},
actions: {
async fetchTemplates(isActive = null) {
this.loading = true
this.error = null
this.loading = true;
this.error = null;
try {
const params = {}
const params = {};
if (isActive !== null) {
params.is_active = isActive
params.is_active = isActive;
}
this.templates = await templateAPI.getTemplates(params)
return this.templates
this.templates = await templateAPI.getTemplates(params);
return this.templates;
} catch (error) {
this.error = error.message || '获取模板列表失败'
throw error
this.error = error.message || '获取模板列表失败';
throw error;
} finally {
this.loading = false
this.loading = false;
}
},
async fetchActiveTemplates() {
this.loading = true
this.error = null
this.loading = true;
this.error = null;
try {
this.templates = await templateAPI.getActiveTemplates()
return this.templates
this.templates = await templateAPI.getActiveTemplates();
return this.templates;
} catch (error) {
this.error = error.message || '获取启用模板失败'
throw error
this.error = error.message || '获取启用模板失败';
throw error;
} finally {
this.loading = false
this.loading = false;
}
},
async fetchTemplate(id) {
this.loading = true
this.error = null
this.loading = true;
this.error = null;
try {
this.currentTemplate = await templateAPI.getTemplate(id)
return this.currentTemplate
this.currentTemplate = await templateAPI.getTemplate(id);
return this.currentTemplate;
} catch (error) {
this.error = error.message || '获取模板详情失败'
throw error
this.error = error.message || '获取模板详情失败';
throw error;
} finally {
this.loading = false
this.loading = false;
}
},
async previewTemplate(id) {
this.loading = true
this.error = null
this.loading = true;
this.error = null;
try {
const preview = await templateAPI.previewTemplate(id)
return preview
const preview = await templateAPI.previewTemplate(id);
return preview;
} catch (error) {
this.error = error.message || '预览模板失败'
throw error
this.error = error.message || '预览模板失败';
throw error;
} finally {
this.loading = false
this.loading = false;
}
},
async createTemplate(templateData) {
this.loading = true
this.error = null
this.loading = true;
this.error = null;
try {
const newTemplate = await templateAPI.createTemplate(templateData)
this.templates.unshift(newTemplate)
return newTemplate
const newTemplate = await templateAPI.createTemplate(templateData);
this.templates.unshift(newTemplate);
return newTemplate;
} catch (error) {
this.error = error.message || '创建模板失败'
throw error
this.error = error.message || '创建模板失败';
throw error;
} finally {
this.loading = false
this.loading = false;
}
},
async updateTemplate(id, templateData) {
this.loading = true
this.error = null
this.loading = true;
this.error = null;
try {
const updatedTemplate = await templateAPI.updateTemplate(id, templateData)
const index = this.templates.findIndex((t) => t.id === id)
const updatedTemplate = await templateAPI.updateTemplate(id, templateData);
const index = this.templates.findIndex(t => t.id === id);
if (index !== -1) {
this.templates[index] = updatedTemplate
this.templates[index] = updatedTemplate;
}
if (this.currentTemplate && this.currentTemplate.id === id) {
this.currentTemplate = updatedTemplate
this.currentTemplate = updatedTemplate;
}
return updatedTemplate
return updatedTemplate;
} catch (error) {
this.error = error.message || '更新模板失败'
throw error
this.error = error.message || '更新模板失败';
throw error;
} finally {
this.loading = false
this.loading = false;
}
},
async deleteTemplate(id) {
this.loading = true
this.error = null
this.loading = true;
this.error = null;
try {
await templateAPI.deleteTemplate(id)
this.templates = this.templates.filter((t) => t.id !== id)
await templateAPI.deleteTemplate(id);
this.templates = this.templates.filter(t => t.id !== id);
if (this.currentTemplate && this.currentTemplate.id === id) {
this.currentTemplate = null
this.currentTemplate = null;
}
return true
return true;
} catch (error) {
this.error = error.message || '删除模板失败'
throw error
this.error = error.message || '删除模板失败';
throw error;
} finally {
this.loading = false
this.loading = false;
}
},
async createTaskFromTemplate(templateId, threadId, fieldValues, taskName = null) {
this.loading = true
this.error = null
this.loading = true;
this.error = null;
try {
const task = await templateAPI.createTaskFromTemplate({
template_id: templateId,
thread_id: threadId,
field_values: fieldValues,
task_name: taskName,
})
return task
});
return task;
} catch (error) {
this.error = error.message || '从模板创建任务失败'
throw error
this.error = error.message || '从模板创建任务失败';
throw error;
} finally {
this.loading = false
this.loading = false;
}
},
clearCurrentTemplate() {
this.currentTemplate = null
this.currentTemplate = null;
},
clearError() {
this.error = null
this.error = null;
},
},
})
});