实现知识库两级分类树与完整 CRUD

支持父子分类、展开侧栏与改删校验;选中父分类可筛子级条目;对齐左右顶栏并更新种子树形数据。
This commit is contained in:
yml2213
2026-07-15 13:23:23 +08:00
parent 2cfdacacb3
commit 4c298fc38d
5 changed files with 560 additions and 91 deletions
+25 -13
View File
@@ -125,20 +125,32 @@ func seed() {
}
model.DB.Create(&messages)
// Knowledge categories & entries
cats := []model.Category{
{TenantID: tenants[0].ID, Name: "产品常见问题"},
{TenantID: tenants[0].ID, Name: "售后服务"},
{TenantID: tenants[0].ID, Name: "技术支持"},
{TenantID: tenants[0].ID, Name: "快捷回复模板"},
}
model.DB.Create(&cats)
// Knowledge categories(两级树,对齐设计稿)
tid := tenants[0].ID
rootFAQ := model.Category{TenantID: tid, Name: "产品常见问题"}
rootAfter := model.Category{TenantID: tid, Name: "售后服务"}
rootTech := model.Category{TenantID: tid, Name: "技术支持"}
rootPolicy := model.Category{TenantID: tid, Name: "政策条款"}
rootQuick := model.Category{TenantID: tid, Name: "快捷回复模板"}
model.DB.Create(&rootFAQ)
model.DB.Create(&rootAfter)
model.DB.Create(&rootTech)
model.DB.Create(&rootPolicy)
model.DB.Create(&rootQuick)
subAccount := model.Category{TenantID: tid, Name: "账户相关", ParentID: &rootFAQ.ID}
subFeature := model.Category{TenantID: tid, Name: "功能使用", ParentID: &rootFAQ.ID}
subBilling := model.Category{TenantID: tid, Name: "计费问题", ParentID: &rootFAQ.ID}
model.DB.Create(&subAccount)
model.DB.Create(&subFeature)
model.DB.Create(&subBilling)
entries := []model.KnowledgeEntry{
{TenantID: tenants[0].ID, CategoryID: cats[0].ID, Title: "如何修改登录密码", Content: "登录后在右上角头像→个人设置→修改密码", Status: "published", UsageCount: 156},
{TenantID: tenants[0].ID, CategoryID: cats[0].ID, Title: "支持哪些支付方式", Content: "支持微信支付、支付宝、银行转账", Status: "published", UsageCount: 98},
{TenantID: tenants[0].ID, CategoryID: cats[1].ID, Title: "退货流程说明", Content: "在线申请→审核→寄回→退款,全程3-5个工作日", Status: "published", UsageCount: 45},
{TenantID: tenants[0].ID, CategoryID: cats[2].ID, Title: "API接口文档", Content: "开发者文档请访问 docs.example.com/api", Status: "draft", UsageCount: 0},
{TenantID: tenants[0].ID, CategoryID: cats[3].ID, Title: "欢迎语模板", Content: "您好!欢迎来到客服云,请问有什么可以帮您的?", Status: "published", UsageCount: 230},
{TenantID: tid, CategoryID: subAccount.ID, Title: "如何修改登录密码", Content: "登录后在右上角头像→个人设置→修改密码。也可通过手机验证码或邮箱链接重置。", Status: "published", UsageCount: 156},
{TenantID: tid, CategoryID: subBilling.ID, Title: "支持哪些支付方式", Content: "支持微信支付、支付宝、银行转账", Status: "published", UsageCount: 98},
{TenantID: tid, CategoryID: subFeature.ID, Title: "如何升级为高级会员", Content: "进入账户设置页面,选择会员升级选项,支持月付和年付两种方式,年付享8折优惠", Status: "published", UsageCount: 88},
{TenantID: tid, CategoryID: rootAfter.ID, Title: "退货流程说明", Content: "在线申请→审核→寄回→退款,全程3-5个工作日", Status: "published", UsageCount: 45},
{TenantID: tid, CategoryID: rootTech.ID, Title: "API接口文档", Content: "开发者文档请访问 docs.example.com/api", Status: "draft", UsageCount: 0},
{TenantID: tid, CategoryID: rootPolicy.ID, Title: "隐私政策更新说明", Content: "我们会定期更新隐私政策,重大变更将通过站内信通知", Status: "published", UsageCount: 12},
{TenantID: tid, CategoryID: rootQuick.ID, Title: "欢迎语模板", Content: "您好!欢迎来到客服云,请问有什么可以帮您的?", Status: "published", UsageCount: 230},
}
model.DB.Create(&entries)