Version: 0.9.81.dev.260506

后端:
1. Credit 价格规则补齐利润率与实际计费单价语义:新增 `profit_rate_bps` 与 `charge_*_price_micros` 展示字段,下沉共享价格推导 helper,tokenstore rpc/client/proto/model/default rule 全链路同步,LLM usage 扣费统一改按加价后的 charge 单价换算。
2. task-class 更新链路修正全量覆盖与归属校验:`runtime/conv` 保留 item id,DAO 更新前显式校验 task-class 与 item 归属,改用显式字段 map 落库 nil/空切片/零值,避免 `RowsAffected=0` 误判越权,同时补齐任务项可编辑字段更新。
3. GormCache task-class 失效补空 user_id 保护:更新语句缺少模型上下文时直接跳过失效,避免缓存插件因空指针影响主事务。

前端:
4. 课表中心补齐任务类编辑能力:新增 `updateTaskClass` API,创建弹窗支持编辑态回填与 item id 提交,日程页支持先拉详情再编辑并在保存后刷新任务类详情与列表。
5. 计划广场详情补点赞交互与奖励提示:详情页新增点赞/取消点赞按钮、奖励反馈文案与计数展示,论坛类型补 `reward_hint`,评论区与帖子作者头像统一接入兜底头像工具。
6. 品牌与展示细节收口:侧边栏与 favicon 切到项目 logo,首页标题改为 `SmartMate`,主面板缩放上限微调,论坛列表头像显示与整体品牌观感同步统一。
This commit is contained in:
Losita
2026-05-06 21:53:17 +08:00
parent 61db646805
commit 7b04b073ce
25 changed files with 594 additions and 123 deletions

View File

@@ -319,18 +319,23 @@ func creditPriceRuleFromPB(item *pb.CreditPriceRuleView) creditcontracts.CreditP
return creditcontracts.CreditPriceRuleView{} return creditcontracts.CreditPriceRuleView{}
} }
return creditcontracts.CreditPriceRuleView{ return creditcontracts.CreditPriceRuleView{
RuleID: item.RuleId, RuleID: item.RuleId,
Scene: item.Scene, Scene: item.Scene,
ProviderName: item.ProviderName, ProviderName: item.ProviderName,
ModelName: item.ModelName, ModelName: item.ModelName,
InputPriceMicros: item.InputPriceMicros, InputPriceMicros: item.InputPriceMicros,
OutputPriceMicros: item.OutputPriceMicros, OutputPriceMicros: item.OutputPriceMicros,
CachedPriceMicros: item.CachedPriceMicros, CachedPriceMicros: item.CachedPriceMicros,
ReasoningPriceMicros: item.ReasoningPriceMicros, ReasoningPriceMicros: item.ReasoningPriceMicros,
CreditPerYuan: item.CreditPerYuan, CreditPerYuan: item.CreditPerYuan,
Status: item.Status, ProfitRateBps: item.ProfitRateBps,
Priority: int(item.Priority), ChargeInputPriceMicros: item.ChargeInputPriceMicros,
Description: item.Description, ChargeOutputPriceMicros: item.ChargeOutputPriceMicros,
ChargeCachedPriceMicros: item.ChargeCachedPriceMicros,
ChargeReasoningPriceMicros: item.ChargeReasoningPriceMicros,
Status: item.Status,
Priority: int(item.Priority),
Description: item.Description,
} }
} }

View File

@@ -18,6 +18,7 @@ type CreditPriceRule struct {
CachedPriceMicros int64 `gorm:"column:cached_price_micros"` CachedPriceMicros int64 `gorm:"column:cached_price_micros"`
ReasoningPriceMicros int64 `gorm:"column:reasoning_price_micros"` ReasoningPriceMicros int64 `gorm:"column:reasoning_price_micros"`
CreditPerYuan int64 `gorm:"column:credit_per_yuan"` CreditPerYuan int64 `gorm:"column:credit_per_yuan"`
ProfitRateBps int64 `gorm:"column:profit_rate_bps"`
Status string `gorm:"column:status"` Status string `gorm:"column:status"`
Priority int `gorm:"column:priority"` Priority int `gorm:"column:priority"`
Description string `gorm:"column:description"` Description string `gorm:"column:description"`

View File

@@ -7,6 +7,7 @@ import (
"time" "time"
llmdao "github.com/LoveLosita/smartflow/backend/services/llm/dao" llmdao "github.com/LoveLosita/smartflow/backend/services/llm/dao"
creditcontracts "github.com/LoveLosita/smartflow/backend/shared/contracts/creditstore"
) )
const ( const (
@@ -152,19 +153,18 @@ func quoteUsagePrice(rule llmdao.CreditPriceRule, input UsagePricingInput) Usage
nonCachedInputTokens := inputTokens - cachedTokens nonCachedInputTokens := inputTokens - cachedTokens
nonReasoningOutputTokens := outputTokens - reasoningTokens nonReasoningOutputTokens := outputTokens - reasoningTokens
cachedPriceMicros := rule.CachedPriceMicros chargePrices := creditcontracts.DeriveChargePriceMicrosSet(
if cachedPriceMicros <= 0 { rule.InputPriceMicros,
cachedPriceMicros = rule.InputPriceMicros rule.OutputPriceMicros,
} rule.CachedPriceMicros,
reasoningPriceMicros := rule.ReasoningPriceMicros rule.ReasoningPriceMicros,
if reasoningPriceMicros <= 0 { rule.ProfitRateBps,
reasoningPriceMicros = rule.OutputPriceMicros )
}
totalMicrosScaled := nonCachedInputTokens*maxInt64(rule.InputPriceMicros, 0) + totalMicrosScaled := nonCachedInputTokens*maxInt64(chargePrices.InputChargePriceMicros, 0) +
cachedTokens*maxInt64(cachedPriceMicros, 0) + cachedTokens*maxInt64(chargePrices.CachedChargePriceMicros, 0) +
nonReasoningOutputTokens*maxInt64(rule.OutputPriceMicros, 0) + nonReasoningOutputTokens*maxInt64(chargePrices.OutputChargePriceMicros, 0) +
reasoningTokens*maxInt64(reasoningPriceMicros, 0) reasoningTokens*maxInt64(chargePrices.ReasoningChargePriceMicros, 0)
rmbCostMicros := ceilDivInt64(totalMicrosScaled, tokenPriceScalePer1K) rmbCostMicros := ceilDivInt64(totalMicrosScaled, tokenPriceScalePer1K)
creditCost := int64(0) creditCost := int64(0)

View File

@@ -67,6 +67,7 @@ func ProcessUserAddTaskClassRequest(req *model.UserAddTaskClassRequest, userID i
var items []model.TaskClassItem var items []model.TaskClassItem
for _, itemReq := range req.Items { for _, itemReq := range req.Items {
item := model.TaskClassItem{ //填充section 2 item := model.TaskClassItem{ //填充section 2
ID: itemReq.ID,
Order: &itemReq.Order, Order: &itemReq.Order,
Content: &itemReq.Content, Content: &itemReq.Content,
EmbeddedTime: itemReq.EmbeddedTime, EmbeddedTime: itemReq.EmbeddedTime,

View File

@@ -3,6 +3,7 @@ package dao
import ( import (
"context" "context"
"errors" "errors"
"time"
"github.com/LoveLosita/smartflow/backend/services/runtime/model" "github.com/LoveLosita/smartflow/backend/services/runtime/model"
"github.com/LoveLosita/smartflow/backend/shared/respond" "github.com/LoveLosita/smartflow/backend/shared/respond"
@@ -40,17 +41,23 @@ func (dao *TaskClassDAO) AddOrUpdateTaskClass(userID int, taskClass *model.TaskC
} }
return taskClass.ID, nil return taskClass.ID, nil
} }
// 更新:必须同时匹配 id + user_id否则不会更新任何行避免覆盖他人数据
tx := dao.db.Model(&model.TaskClass{}). // 1. 先显式校验任务类归属,避免“更新值与库内完全相同”时 RowsAffected=0 被误判成越权。
// 2. 这里只负责校验 id/user_id 是否匹配,不负责判断具体字段有没有变化。
// 3. 若确实不存在或不属于当前用户,统一返回 UserTaskClassForbidden。
if err := dao.ensureTaskClassOwned(userID, taskClass.ID); err != nil {
return 0, err
}
// 1. 更新语义是“前端提交什么,就以什么覆盖数据库当前值”。
// 2. 因此这里不能再直接用 struct Updates否则 nil/空切片 等零值字段会被 GORM 跳过,刷新后看起来像“没更新”。
// 3. 统一改成显式字段映射,保证可选字段清空、排除数组清空都能真正落库。
tx := dao.db.Model(&model.TaskClass{UserID: &userID}).
Where("id = ? AND user_id = ?", taskClass.ID, userID). Where("id = ? AND user_id = ?", taskClass.ID, userID).
Updates(taskClass) Updates(buildTaskClassUpdateMap(taskClass))
if tx.Error != nil { if tx.Error != nil {
return 0, tx.Error return 0, tx.Error
} }
if tx.RowsAffected == 0 {
// 未匹配到记录:要么不存在,要么不属于该用户
return 0, respond.UserTaskClassForbidden
}
return taskClass.ID, nil return taskClass.ID, nil
} }
@@ -82,7 +89,27 @@ func (dao *TaskClassDAO) AddOrUpdateTaskClassItems(userID int, items []model.Tas
return respond.UserTaskClassForbidden return respond.UserTaskClassForbidden
} }
// 2) 新增与更新分开处理:新增不受影响;更新时限定 category_id防越权 // 2. 收集本次要更新的已有 item先做一次归属校验。
// 2.1 这里单独校验是为了避免“只更新成原值”时 RowsAffected=0 被误判为越权。
// 2.2 校验通过后,后面的 UPDATE 只关心数据库错误,不再用 RowsAffected 判权限。
// 2.3 若请求里混入了不属于这些 task_class 的 item_id统一返回 UserTaskClassForbidden。
existingItemIDs := make([]int, 0, len(items))
existingItemIDSet := make(map[int]struct{}, len(items))
for _, it := range items {
if it.ID == 0 {
continue
}
if _, exists := existingItemIDSet[it.ID]; exists {
continue
}
existingItemIDSet[it.ID] = struct{}{}
existingItemIDs = append(existingItemIDs, it.ID)
}
if err := dao.ensureTaskClassItemsOwnedByCategories(existingItemIDs, categoryIDs); err != nil {
return err
}
// 3) 新增与更新分开处理:新增直接插入;已有 item 按现有契约更新可编辑字段。
var toCreate []model.TaskClassItem var toCreate []model.TaskClassItem
for _, it := range items { for _, it := range items {
if it.ID == 0 { if it.ID == 0 {
@@ -93,14 +120,14 @@ func (dao *TaskClassDAO) AddOrUpdateTaskClassItems(userID int, items []model.Tas
tx := dao.db.Model(&model.TaskClassItem{}). tx := dao.db.Model(&model.TaskClassItem{}).
Where("id = ? AND category_id IN ?", it.ID, categoryIDs). Where("id = ? AND category_id IN ?", it.ID, categoryIDs).
Updates(map[string]any{ Updates(map[string]any{
"category_id": it.CategoryID, "category_id": it.CategoryID,
"order": it.Order,
"content": it.Content,
"embedded_time": it.EmbeddedTime,
}) })
if tx.Error != nil { if tx.Error != nil {
return tx.Error return tx.Error
} }
if tx.RowsAffected == 0 {
return respond.UserTaskClassForbidden
}
} }
if len(toCreate) > 0 { if len(toCreate) > 0 {
@@ -111,6 +138,84 @@ func (dao *TaskClassDAO) AddOrUpdateTaskClassItems(userID int, items []model.Tas
return nil return nil
} }
// ensureTaskClassOwned 只负责校验 task_class 是否属于当前用户。
func (dao *TaskClassDAO) ensureTaskClassOwned(userID int, taskClassID int) error {
var count int64
if err := dao.db.Model(&model.TaskClass{}).
Where("id = ? AND user_id = ?", taskClassID, userID).
Count(&count).Error; err != nil {
return err
}
if count == 0 {
return respond.UserTaskClassForbidden
}
return nil
}
// ensureTaskClassItemsOwnedByCategories 只负责校验一批 item 是否都挂在允许的 task_class 下。
func (dao *TaskClassDAO) ensureTaskClassItemsOwnedByCategories(itemIDs []int, categoryIDs []int) error {
if len(itemIDs) == 0 {
return nil
}
var count int64
if err := dao.db.Model(&model.TaskClassItem{}).
Where("id IN ? AND category_id IN ?", itemIDs, categoryIDs).
Count(&count).Error; err != nil {
return err
}
if count != int64(len(itemIDs)) {
return respond.UserTaskClassForbidden
}
return nil
}
// buildTaskClassUpdateMap 负责把“全量更新”请求转换成显式列更新。
func buildTaskClassUpdateMap(taskClass *model.TaskClass) map[string]any {
return map[string]any{
"name": nullableStringValue(taskClass.Name),
"mode": nullableStringValue(taskClass.Mode),
"start_date": nullableTimeValue(taskClass.StartDate),
"end_date": nullableTimeValue(taskClass.EndDate),
"subject_type": nullableStringValue(taskClass.SubjectType),
"difficulty_level": nullableStringValue(taskClass.DifficultyLevel),
"cognitive_intensity": nullableStringValue(taskClass.CognitiveIntensity),
"total_slots": nullableIntValue(taskClass.TotalSlots),
"allow_filler_course": nullableBoolValue(taskClass.AllowFillerCourse),
"strategy": nullableStringValue(taskClass.Strategy),
"excluded_slots": taskClass.ExcludedSlots,
"excluded_days_of_week": taskClass.ExcludedDaysOfWeek,
}
}
func nullableStringValue(value *string) any {
if value == nil {
return nil
}
return *value
}
func nullableIntValue(value *int) any {
if value == nil {
return nil
}
return *value
}
func nullableBoolValue(value *bool) any {
if value == nil {
return nil
}
return *value
}
func nullableTimeValue(value *time.Time) any {
if value == nil {
return nil
}
return *value
}
// Transaction 在一个事务中执行传入的函数,供 service 层复用(自动提交/回滚) // Transaction 在一个事务中执行传入的函数,供 service 层复用(自动提交/回滚)
// 规则fn 返回 nil -> commitfn 返回 error 或 panic -> rollback // 规则fn 返回 nil -> commitfn 返回 error 或 panic -> rollback
func (dao *TaskClassDAO) Transaction(fn func(txDAO *TaskClassDAO) error) error { func (dao *TaskClassDAO) Transaction(fn func(txDAO *TaskClassDAO) error) error {

View File

@@ -264,6 +264,7 @@ func defaultCreditPriceRules() []storemodel.CreditPriceRule {
CachedPriceMicros: 800, CachedPriceMicros: 800,
ReasoningPriceMicros: 16000, ReasoningPriceMicros: 16000,
CreditPerYuan: 100, CreditPerYuan: 100,
ProfitRateBps: 0,
Status: storemodel.CreditPriceRuleStatusActive, Status: storemodel.CreditPriceRuleStatusActive,
Priority: 100, Priority: 100,
Description: "Default Ark rule, prices are expressed in micros CNY per 1K tokens.", Description: "Default Ark rule, prices are expressed in micros CNY per 1K tokens.",

View File

@@ -172,11 +172,12 @@ type CreditPriceRule struct {
Scene string `gorm:"column:scene;type:varchar(64);not null;index:idx_credit_price_rules_scene_status,priority:1;comment:计费场景"` Scene string `gorm:"column:scene;type:varchar(64);not null;index:idx_credit_price_rules_scene_status,priority:1;comment:计费场景"`
ProviderName string `gorm:"column:provider_name;type:varchar(64);not null;comment:模型提供方"` ProviderName string `gorm:"column:provider_name;type:varchar(64);not null;comment:模型提供方"`
ModelName string `gorm:"column:model_name;type:varchar(128);not null;comment:模型名称"` ModelName string `gorm:"column:model_name;type:varchar(128);not null;comment:模型名称"`
InputPriceMicros int64 `gorm:"column:input_price_micros;not null;default:0;comment:输入Token单价单位微人民币"` InputPriceMicros int64 `gorm:"column:input_price_micros;not null;default:0;comment:原始输入Token成本单价,单位微人民币"`
OutputPriceMicros int64 `gorm:"column:output_price_micros;not null;default:0;comment:输出Token单价单位微人民币"` OutputPriceMicros int64 `gorm:"column:output_price_micros;not null;default:0;comment:原始输出Token成本单价,单位微人民币"`
CachedPriceMicros int64 `gorm:"column:cached_price_micros;not null;default:0;comment:缓存Token单价单位微人民币"` CachedPriceMicros int64 `gorm:"column:cached_price_micros;not null;default:0;comment:原始缓存Token成本单价,单位微人民币"`
ReasoningPriceMicros int64 `gorm:"column:reasoning_price_micros;not null;default:0;comment:推理Token单价单位微人民币"` ReasoningPriceMicros int64 `gorm:"column:reasoning_price_micros;not null;default:0;comment:原始推理Token成本单价,单位微人民币"`
CreditPerYuan int64 `gorm:"column:credit_per_yuan;not null;default:0;comment:1元人民币换算多少Credit"` CreditPerYuan int64 `gorm:"column:credit_per_yuan;not null;default:0;comment:1元人民币换算多少Credit"`
ProfitRateBps int64 `gorm:"column:profit_rate_bps;not null;default:0;comment:在原始CNY成本基础上加价多少基点10000=100%"`
Status string `gorm:"column:status;type:varchar(32);not null;default:'inactive';index:idx_credit_price_rules_scene_status,priority:2;comment:active/inactive"` Status string `gorm:"column:status;type:varchar(32);not null;default:'inactive';index:idx_credit_price_rules_scene_status,priority:2;comment:active/inactive"`
Priority int `gorm:"column:priority;not null;default:0;comment:匹配优先级,越大越优先"` Priority int `gorm:"column:priority;not null;default:0;comment:匹配优先级,越大越优先"`
Description string `gorm:"column:description;type:varchar(255);comment:规则说明"` Description string `gorm:"column:description;type:varchar(255);comment:规则说明"`

View File

@@ -336,18 +336,23 @@ func creditTransactionsToPB(items []creditcontracts.CreditTransactionView) []*pb
func creditPriceRuleToPB(rule creditcontracts.CreditPriceRuleView) *pb.CreditPriceRuleView { func creditPriceRuleToPB(rule creditcontracts.CreditPriceRuleView) *pb.CreditPriceRuleView {
return &pb.CreditPriceRuleView{ return &pb.CreditPriceRuleView{
RuleId: rule.RuleID, RuleId: rule.RuleID,
Scene: rule.Scene, Scene: rule.Scene,
ProviderName: rule.ProviderName, ProviderName: rule.ProviderName,
ModelName: rule.ModelName, ModelName: rule.ModelName,
InputPriceMicros: rule.InputPriceMicros, InputPriceMicros: rule.InputPriceMicros,
OutputPriceMicros: rule.OutputPriceMicros, OutputPriceMicros: rule.OutputPriceMicros,
CachedPriceMicros: rule.CachedPriceMicros, CachedPriceMicros: rule.CachedPriceMicros,
ReasoningPriceMicros: rule.ReasoningPriceMicros, ReasoningPriceMicros: rule.ReasoningPriceMicros,
CreditPerYuan: rule.CreditPerYuan, CreditPerYuan: rule.CreditPerYuan,
Status: rule.Status, ProfitRateBps: rule.ProfitRateBps,
Priority: int32(rule.Priority), ChargeInputPriceMicros: rule.ChargeInputPriceMicros,
Description: rule.Description, ChargeOutputPriceMicros: rule.ChargeOutputPriceMicros,
ChargeCachedPriceMicros: rule.ChargeCachedPriceMicros,
ChargeReasoningPriceMicros: rule.ChargeReasoningPriceMicros,
Status: rule.Status,
Priority: int32(rule.Priority),
Description: rule.Description,
} }
} }

View File

@@ -331,18 +331,23 @@ func (m *CreditTransactionView) String() string { return proto.CompactTextString
func (*CreditTransactionView) ProtoMessage() {} func (*CreditTransactionView) ProtoMessage() {}
type CreditPriceRuleView struct { type CreditPriceRuleView struct {
RuleId uint64 `protobuf:"varint,1,opt,name=rule_id,json=ruleId,proto3" json:"rule_id,omitempty"` RuleId uint64 `protobuf:"varint,1,opt,name=rule_id,json=ruleId,proto3" json:"rule_id,omitempty"`
Scene string `protobuf:"bytes,2,opt,name=scene,proto3" json:"scene,omitempty"` Scene string `protobuf:"bytes,2,opt,name=scene,proto3" json:"scene,omitempty"`
ProviderName string `protobuf:"bytes,3,opt,name=provider_name,json=providerName,proto3" json:"provider_name,omitempty"` ProviderName string `protobuf:"bytes,3,opt,name=provider_name,json=providerName,proto3" json:"provider_name,omitempty"`
ModelName string `protobuf:"bytes,4,opt,name=model_name,json=modelName,proto3" json:"model_name,omitempty"` ModelName string `protobuf:"bytes,4,opt,name=model_name,json=modelName,proto3" json:"model_name,omitempty"`
InputPriceMicros int64 `protobuf:"varint,5,opt,name=input_price_micros,json=inputPriceMicros,proto3" json:"input_price_micros,omitempty"` InputPriceMicros int64 `protobuf:"varint,5,opt,name=input_price_micros,json=inputPriceMicros,proto3" json:"input_price_micros,omitempty"`
OutputPriceMicros int64 `protobuf:"varint,6,opt,name=output_price_micros,json=outputPriceMicros,proto3" json:"output_price_micros,omitempty"` OutputPriceMicros int64 `protobuf:"varint,6,opt,name=output_price_micros,json=outputPriceMicros,proto3" json:"output_price_micros,omitempty"`
CachedPriceMicros int64 `protobuf:"varint,7,opt,name=cached_price_micros,json=cachedPriceMicros,proto3" json:"cached_price_micros,omitempty"` CachedPriceMicros int64 `protobuf:"varint,7,opt,name=cached_price_micros,json=cachedPriceMicros,proto3" json:"cached_price_micros,omitempty"`
ReasoningPriceMicros int64 `protobuf:"varint,8,opt,name=reasoning_price_micros,json=reasoningPriceMicros,proto3" json:"reasoning_price_micros,omitempty"` ReasoningPriceMicros int64 `protobuf:"varint,8,opt,name=reasoning_price_micros,json=reasoningPriceMicros,proto3" json:"reasoning_price_micros,omitempty"`
CreditPerYuan int64 `protobuf:"varint,9,opt,name=credit_per_yuan,json=creditPerYuan,proto3" json:"credit_per_yuan,omitempty"` CreditPerYuan int64 `protobuf:"varint,9,opt,name=credit_per_yuan,json=creditPerYuan,proto3" json:"credit_per_yuan,omitempty"`
Status string `protobuf:"bytes,10,opt,name=status,proto3" json:"status,omitempty"` Status string `protobuf:"bytes,10,opt,name=status,proto3" json:"status,omitempty"`
Priority int32 `protobuf:"varint,11,opt,name=priority,proto3" json:"priority,omitempty"` Priority int32 `protobuf:"varint,11,opt,name=priority,proto3" json:"priority,omitempty"`
Description string `protobuf:"bytes,12,opt,name=description,proto3" json:"description,omitempty"` Description string `protobuf:"bytes,12,opt,name=description,proto3" json:"description,omitempty"`
ProfitRateBps int64 `protobuf:"varint,13,opt,name=profit_rate_bps,json=profitRateBps,proto3" json:"profit_rate_bps,omitempty"`
ChargeInputPriceMicros int64 `protobuf:"varint,14,opt,name=charge_input_price_micros,json=chargeInputPriceMicros,proto3" json:"charge_input_price_micros,omitempty"`
ChargeOutputPriceMicros int64 `protobuf:"varint,15,opt,name=charge_output_price_micros,json=chargeOutputPriceMicros,proto3" json:"charge_output_price_micros,omitempty"`
ChargeCachedPriceMicros int64 `protobuf:"varint,16,opt,name=charge_cached_price_micros,json=chargeCachedPriceMicros,proto3" json:"charge_cached_price_micros,omitempty"`
ChargeReasoningPriceMicros int64 `protobuf:"varint,17,opt,name=charge_reasoning_price_micros,json=chargeReasoningPriceMicros,proto3" json:"charge_reasoning_price_micros,omitempty"`
} }
func (m *CreditPriceRuleView) Reset() { *m = CreditPriceRuleView{} } func (m *CreditPriceRuleView) Reset() { *m = CreditPriceRuleView{} }

View File

@@ -235,6 +235,11 @@ message CreditPriceRuleView {
string status = 10; string status = 10;
int32 priority = 11; int32 priority = 11;
string description = 12; string description = 12;
int64 profit_rate_bps = 13;
int64 charge_input_price_micros = 14;
int64 charge_output_price_micros = 15;
int64 charge_cached_price_micros = 16;
int64 charge_reasoning_price_micros = 17;
} }
message CreditRewardRuleView { message CreditRewardRuleView {

View File

@@ -114,19 +114,31 @@ func creditTransactionViewFromModel(ledger storemodel.CreditLedger) creditcontra
} }
func creditPriceRuleViewFromModel(rule storemodel.CreditPriceRule) creditcontracts.CreditPriceRuleView { func creditPriceRuleViewFromModel(rule storemodel.CreditPriceRule) creditcontracts.CreditPriceRuleView {
chargePrices := creditcontracts.DeriveChargePriceMicrosSet(
rule.InputPriceMicros,
rule.OutputPriceMicros,
rule.CachedPriceMicros,
rule.ReasoningPriceMicros,
rule.ProfitRateBps,
)
return creditcontracts.CreditPriceRuleView{ return creditcontracts.CreditPriceRuleView{
RuleID: rule.ID, RuleID: rule.ID,
Scene: rule.Scene, Scene: rule.Scene,
ProviderName: rule.ProviderName, ProviderName: rule.ProviderName,
ModelName: rule.ModelName, ModelName: rule.ModelName,
InputPriceMicros: rule.InputPriceMicros, InputPriceMicros: rule.InputPriceMicros,
OutputPriceMicros: rule.OutputPriceMicros, OutputPriceMicros: rule.OutputPriceMicros,
CachedPriceMicros: rule.CachedPriceMicros, CachedPriceMicros: rule.CachedPriceMicros,
ReasoningPriceMicros: rule.ReasoningPriceMicros, ReasoningPriceMicros: rule.ReasoningPriceMicros,
CreditPerYuan: rule.CreditPerYuan, CreditPerYuan: rule.CreditPerYuan,
Status: rule.Status, ProfitRateBps: rule.ProfitRateBps,
Priority: rule.Priority, ChargeInputPriceMicros: chargePrices.InputChargePriceMicros,
Description: rule.Description, ChargeOutputPriceMicros: chargePrices.OutputChargePriceMicros,
ChargeCachedPriceMicros: chargePrices.CachedChargePriceMicros,
ChargeReasoningPriceMicros: chargePrices.ReasoningChargePriceMicros,
Status: rule.Status,
Priority: rule.Priority,
Description: rule.Description,
} }
} }

View File

@@ -0,0 +1,57 @@
package creditstore
const (
// ProfitRateScaleBPS 表示利润率的基点精度10000 = 100%。
ProfitRateScaleBPS = int64(10_000)
)
// ChargePriceMicrosSet 表示在“原始 CNY 成本 + 利润率”之后得到的实际计费单价。
type ChargePriceMicrosSet struct {
InputChargePriceMicros int64
OutputChargePriceMicros int64
CachedChargePriceMicros int64
ReasoningChargePriceMicros int64
}
// DeriveChargePriceMicrosSet 负责把一条价格规则里的原始 CNY 成本推导成实际计费用单价。
//
// 职责边界:
// 1. 这里只处理“原始成本 + 利润率”的价格推导,不负责 token 数量聚合与 credit 折算。
// 2. cached/reasoning 仍复用现有兜底语义:未配置时分别退回 input/output 单价。
// 3. 若利润率配置为负且绝对值过大导致结果 <= 0则统一按 0 处理,避免落出负价格。
func DeriveChargePriceMicrosSet(inputPriceMicros, outputPriceMicros, cachedPriceMicros, reasoningPriceMicros, profitRateBps int64) ChargePriceMicrosSet {
if cachedPriceMicros <= 0 {
cachedPriceMicros = inputPriceMicros
}
if reasoningPriceMicros <= 0 {
reasoningPriceMicros = outputPriceMicros
}
return ChargePriceMicrosSet{
InputChargePriceMicros: ApplyProfitRateToPriceMicros(inputPriceMicros, profitRateBps),
OutputChargePriceMicros: ApplyProfitRateToPriceMicros(outputPriceMicros, profitRateBps),
CachedChargePriceMicros: ApplyProfitRateToPriceMicros(cachedPriceMicros, profitRateBps),
ReasoningChargePriceMicros: ApplyProfitRateToPriceMicros(reasoningPriceMicros, profitRateBps),
}
}
// ApplyProfitRateToPriceMicros 负责把“成本单价”按利润率转换成“实际计费单价”。
func ApplyProfitRateToPriceMicros(priceMicros int64, profitRateBps int64) int64 {
if priceMicros <= 0 {
return 0
}
scaledRate := ProfitRateScaleBPS + profitRateBps
if scaledRate <= 0 {
return 0
}
return ceilDivInt64(priceMicros*scaledRate, ProfitRateScaleBPS)
}
func ceilDivInt64(numerator int64, denominator int64) int64 {
if numerator <= 0 || denominator <= 0 {
return 0
}
return (numerator + denominator - 1) / denominator
}

View File

@@ -93,19 +93,30 @@ type CreditConsumptionDashboardView struct {
} }
// CreditPriceRuleView 是 Credit 计价规则展示结构。 // CreditPriceRuleView 是 Credit 计价规则展示结构。
//
// 字段语义说明:
// 1. InputPriceMicros / OutputPriceMicros / CachedPriceMicros / ReasoningPriceMicros
// 表示原始 CNY 成本单价,方便管理端直接维护模型底价。
// 2. Charge*PriceMicros 表示后端按利润率自动推导出来的实际计费单价,
// LLM 扣费时会使用这一组价格继续换算 credit。
type CreditPriceRuleView struct { type CreditPriceRuleView struct {
RuleID uint64 `json:"rule_id"` RuleID uint64 `json:"rule_id"`
Scene string `json:"scene"` Scene string `json:"scene"`
ProviderName string `json:"provider_name"` ProviderName string `json:"provider_name"`
ModelName string `json:"model_name"` ModelName string `json:"model_name"`
InputPriceMicros int64 `json:"input_price_micros"` InputPriceMicros int64 `json:"input_price_micros"`
OutputPriceMicros int64 `json:"output_price_micros"` OutputPriceMicros int64 `json:"output_price_micros"`
CachedPriceMicros int64 `json:"cached_price_micros"` CachedPriceMicros int64 `json:"cached_price_micros"`
ReasoningPriceMicros int64 `json:"reasoning_price_micros"` ReasoningPriceMicros int64 `json:"reasoning_price_micros"`
CreditPerYuan int64 `json:"credit_per_yuan"` CreditPerYuan int64 `json:"credit_per_yuan"`
Status string `json:"status"` ProfitRateBps int64 `json:"profit_rate_bps"`
Priority int `json:"priority"` ChargeInputPriceMicros int64 `json:"charge_input_price_micros"`
Description string `json:"description"` ChargeOutputPriceMicros int64 `json:"charge_output_price_micros"`
ChargeCachedPriceMicros int64 `json:"charge_cached_price_micros"`
ChargeReasoningPriceMicros int64 `json:"charge_reasoning_price_micros"`
Status string `json:"status"`
Priority int `json:"priority"`
Description string `json:"description"`
} }
// CreditRewardRuleView 是 Credit 奖励规则展示结构。 // CreditRewardRuleView 是 Credit 奖励规则展示结构。

View File

@@ -69,6 +69,13 @@ func (p *GormCachePlugin) dispatchCacheLogic(modelObj interface{}) {
case model.Schedule: case model.Schedule:
p.invalidScheduleCache(m.UserID, m.Week) p.invalidScheduleCache(m.UserID, m.Week)
case model.TaskClass: case model.TaskClass:
// 1. update 场景若只用 Model(&model.TaskClass{}) 构造 SQL插件拿到的模型实例里 UserID 可能为空。
// 2. 这类情况下缓存插件不能影响主事务,更不能因为取缓存键时解引用空指针把服务打崩。
// 3. 若确实缺少 UserID则直接跳过本次失效由调用方补齐 Model 上下文或后续重读兜底。
if m.UserID == nil {
log.Printf("[GORM-Cache] Skip task class cache invalidation because UserID is nil")
return
}
p.invalidTaskClassCache(*m.UserID) p.invalidTaskClassCache(*m.UserID)
case model.Task: case model.Task:
p.invalidTaskCache(m.UserID) p.invalidTaskCache(m.UserID)

View File

@@ -3,6 +3,7 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="https://dl2.lecspace.com/SmartFlow-Agent/logo.png" />
<title>SmartMate</title> <title>SmartMate</title>
</head> </head>
<body> <body>

View File

@@ -181,3 +181,19 @@ export async function importCourses(payload: CourseImportPayload, idempotencyKey
throw new Error(extractErrorMessage(error, '\u8bfe\u7a0b\u5bfc\u5165\u5931\u8d25\uff0c\u8bf7\u7a0d\u540e\u91cd\u8bd5')) throw new Error(extractErrorMessage(error, '\u8bfe\u7a0b\u5bfc\u5165\u5931\u8d25\uff0c\u8bf7\u7a0d\u540e\u91cd\u8bd5'))
} }
} }
export async function updateTaskClass(taskClassId: number, payload: TaskClassCreatePayload, idempotencyKey = createIdempotencyKey('task-class-update')) {
try {
const response = await http.put<PlainResponse>('/task-class/update', payload, {
params: {
task_class_id: taskClassId,
},
headers: {
'X-Idempotency-Key': idempotencyKey,
},
})
return response.data
} catch (error) {
throw new Error(extractErrorMessage(error, '更新任务类失败,请稍后重试'))
}
}

View File

@@ -51,7 +51,9 @@ function handleSidebarNavigate(item: SidebarItem) {
<template> <template>
<aside class="dashboard-sidebar"> <aside class="dashboard-sidebar">
<div class="dashboard-sidebar__brand">S</div> <div class="dashboard-sidebar__brand">
<img src="https://dl2.lecspace.com/SmartFlow-Agent/logo.png" alt="SmartFlow" />
</div>
<nav class="dashboard-sidebar__nav"> <nav class="dashboard-sidebar__nav">
<div class="dashboard-sidebar__nav-indicator" :style="activeIndicatorStyle" /> <div class="dashboard-sidebar__nav-indicator" :style="activeIndicatorStyle" />
<button <button
@@ -89,13 +91,17 @@ function handleSidebarNavigate(item: SidebarItem) {
height: 48px; height: 48px;
border-radius: 14px; border-radius: 14px;
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%); background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
color: #fff;
font-size: 20px;
font-weight: 800;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3); box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
overflow: hidden;
}
.dashboard-sidebar__brand img {
width: 100%;
height: 100%;
object-fit: cover;
} }
.dashboard-sidebar__nav { position: relative; display: grid; gap: 12px; align-content: start; } .dashboard-sidebar__nav { position: relative; display: grid; gap: 12px; align-content: start; }

View File

@@ -1,12 +1,13 @@
<script setup lang="ts"> <script setup lang="ts">
import { reactive, watch } from 'vue' import { computed, reactive, watch } from 'vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { TaskClassCreatePayload, TaskClassCreateItemPayload } from '@/types/schedule' import type { TaskClassCreatePayload, TaskClassCreateItemPayload, TaskClassDetail } from '@/types/schedule'
const props = defineProps<{ const props = defineProps<{
modelValue: boolean modelValue: boolean
loading?: boolean loading?: boolean
initialData?: TaskClassDetail | null
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
@@ -36,21 +37,39 @@ watch(
return return
} }
form.name = '' if (props.initialData) {
form.start_date = '' form.name = props.initialData.name
form.end_date = '' form.start_date = props.initialData.start_date
form.total_slots = 8 form.end_date = props.initialData.end_date
form.allow_filler_course = true form.total_slots = props.initialData.config.total_slots
form.strategy = 'steady' form.allow_filler_course = props.initialData.config.allow_filler_course
form.excluded_slots = [] form.strategy = props.initialData.config.strategy
form.items = [ form.excluded_slots = props.initialData.config.excluded_slots || []
{ order: 1, content: '', embedded_time: null }, form.items = props.initialData.items.map(item => ({
{ order: 2, content: '', embedded_time: null }, id: item.id,
{ order: 3, content: '', embedded_time: null }, order: item.order,
] content: item.content,
embedded_time: item.embedded_time,
}))
} else {
form.name = ''
form.start_date = ''
form.end_date = ''
form.total_slots = 8
form.allow_filler_course = true
form.strategy = 'steady'
form.excluded_slots = []
form.items = [
{ order: 1, content: '', embedded_time: null },
{ order: 2, content: '', embedded_time: null },
{ order: 3, content: '', embedded_time: null },
]
}
}, },
) )
const isEdit = computed(() => !!props.initialData)
function addItem() { function addItem() {
form.items.push({ form.items.push({
order: form.items.length + 1, order: form.items.length + 1,
@@ -69,9 +88,10 @@ function removeItem(index: number) {
function handleSubmit() { function handleSubmit() {
const filteredItems = form.items const filteredItems = form.items
.map((item, index) => ({ .map((item, index) => ({
id: item.id,
order: index + 1, order: index + 1,
content: item.content.trim(), content: item.content.trim(),
embedded_time: null, embedded_time: item.embedded_time,
})) }))
.filter((item) => item.content) .filter((item) => item.content)
@@ -109,7 +129,7 @@ function handleSubmit() {
<template> <template>
<el-dialog <el-dialog
:model-value="modelValue" :model-value="modelValue"
title="创建任务类" :title="isEdit ? '编辑任务类' : '创建任务类'"
width="720px" width="720px"
align-center align-center
class="task-class-dialog" class="task-class-dialog"
@@ -187,7 +207,9 @@ function handleSubmit() {
<template #footer> <template #footer>
<div class="task-class-dialog__footer"> <div class="task-class-dialog__footer">
<el-button @click="emit('update:modelValue', false)">取消</el-button> <el-button @click="emit('update:modelValue', false)">取消</el-button>
<el-button type="primary" :loading="loading" @click="handleSubmit">创建任务类</el-button> <el-button type="primary" :loading="loading" @click="handleSubmit">
{{ isEdit ? '保存修改' : '确认创建' }}
</el-button>
</div> </div>
</template> </template>
</el-dialog> </el-dialog>

View File

@@ -82,10 +82,17 @@ export interface ForumPageEnvelope<T> {
has_more: boolean has_more: boolean
} }
export interface ForumRewardHint {
receiver: string
status: string
amount: number
}
export interface ForumInteractionResult { export interface ForumInteractionResult {
post_id: number post_id: number
liked: boolean liked: boolean
like_count: number like_count: number
reward_hint?: ForumRewardHint
} }
export interface ForumImportResult { export interface ForumImportResult {

View File

@@ -65,6 +65,7 @@ export interface TaskClassDetail {
} }
export interface TaskClassCreateItemPayload { export interface TaskClassCreateItemPayload {
id?: number
order: number order: number
content: string content: string
embedded_time: TaskClassEmbeddedTime | null embedded_time: TaskClassEmbeddedTime | null

View File

@@ -0,0 +1,16 @@
/**
* 获取头像 URL支持默认兜底
* @param url 原始头像 URL
* @param seed 兜底种(如用户 ID 或昵称),确保同一用户的默认头像一致
* @returns 最终可用的头像 URL
*/
export function getAvatarUrl(url?: string, seed?: string | number): string {
if (url && url.trim() && (url.startsWith('http') || url.startsWith('/') || url.startsWith('data:'))) {
return url
}
// 使用 DiceBear 提供的 avataaars 系列作为默认头像
// 如果没有提供 seed则生成一个随机字符串
const avatarSeed = seed !== undefined && seed !== null ? String(seed) : 'default'
return `https://api.dicebear.com/7.x/avataaars/svg?seed=${encodeURIComponent(avatarSeed)}`
}

View File

@@ -236,7 +236,7 @@ function syncDashboardMainScale() {
const naturalHeight = topbar.offsetHeight + content.scrollHeight + gridGap const naturalHeight = topbar.offsetHeight + content.scrollHeight + gridGap
if (!availableHeight || !naturalHeight) return if (!availableHeight || !naturalHeight) return
const nextScale = Number(Math.min(1, (availableHeight / naturalHeight) * 0.96).toFixed(4)) const nextScale = Number(Math.min(1.1, (availableHeight / naturalHeight) * 1.05).toFixed(4))
dashboardMainScale.value = nextScale dashboardMainScale.value = nextScale
} }
@@ -285,7 +285,7 @@ watch([() => tasks.value.length, () => todayEvents.value.length, taskLoading, sc
<header ref="dashboardTopbarRef" class="dashboard-topbar glass-panel dashboard-item-pop" :style="{ '--anim-delay': '0s' }"> <header ref="dashboardTopbarRef" class="dashboard-topbar glass-panel dashboard-item-pop" :style="{ '--anim-delay': '0s' }">
<div> <div>
<div class="dashboard-topbar__brandline"> <div class="dashboard-topbar__brandline">
<strong>AI 智慧日程系统</strong> <strong>SmartMate</strong>
<span>{{ pageTitleDate }}</span> <span>{{ pageTitleDate }}</span>
</div> </div>
</div> </div>

View File

@@ -15,6 +15,7 @@ import { getTaskClassList } from '@/api/scheduleCenter'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import type { ForumPostBrief } from '@/types/forum' import type { ForumPostBrief } from '@/types/forum'
import type { TaskClassListItem } from '@/types/schedule' import type { TaskClassListItem } from '@/types/schedule'
import { getAvatarUrl } from '@/utils/avatar'
const router = useRouter() const router = useRouter()
@@ -293,7 +294,7 @@ onBeforeUnmount(() => {
<div class="post-card__footer"> <div class="post-card__footer">
<div class="author-info"> <div class="author-info">
<img :src="post.author.avatar_url" class="author-avatar" /> <img :src="getAvatarUrl(post.author.avatar_url, post.author.user_id)" class="author-avatar" />
<span class="author-name">{{ post.author.nickname }}</span> <span class="author-name">{{ post.author.nickname }}</span>
</div> </div>

View File

@@ -2,16 +2,19 @@
import { computed, ref, watch } from 'vue' import { computed, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { ArrowLeft, ChatDotRound, Check, Connection, Filter } from '@element-plus/icons-vue' import { ArrowLeft, ChatDotRound, Check, Connection, Filter, Star, StarFilled } from '@element-plus/icons-vue'
import { import {
createForumComment, createForumComment,
deleteForumComment, deleteForumComment,
getForumPostDetail, getForumPostDetail,
importForumPost, importForumPost,
likeForumPost,
listForumComments, listForumComments,
unlikeForumPost,
} from '@/api/forum' } from '@/api/forum'
import type { ForumCommentNode, ForumPostBrief, ForumPostDetail, ForumTemplateDetail } from '@/types/forum' import type { ForumCommentNode, ForumPostBrief, ForumPostDetail, ForumTemplateDetail } from '@/types/forum'
import { getAvatarUrl } from '@/utils/avatar'
interface ForumPostDetailView extends ForumPostBrief { interface ForumPostDetailView extends ForumPostBrief {
template: ForumTemplateDetail template: ForumTemplateDetail
@@ -21,8 +24,9 @@ const route = useRoute()
const router = useRouter() const router = useRouter()
const isLoading = ref(true) const isLoading = ref(true)
const commentSubmitting = ref(false)
const selectedPost = ref<ForumPostDetailView | null>(null) const selectedPost = ref<ForumPostDetailView | null>(null)
const isLiking = ref(false)
const commentSubmitting = ref(false)
const comments = ref<ForumCommentNode[]>([]) const comments = ref<ForumCommentNode[]>([])
const newComment = ref('') const newComment = ref('')
const replyingToId = ref<number | null>(null) const replyingToId = ref<number | null>(null)
@@ -174,6 +178,41 @@ async function handleImport() {
} }
} }
async function handleLikeToggle() {
if (!selectedPost.value || isLiking.value) return
isLiking.value = true
const postId = selectedPost.value.post_id
const isLiked = selectedPost.value.viewer_state.liked
try {
const result = isLiked
? await unlikeForumPost(postId)
: await likeForumPost(postId)
// 以后端返回为准更新状态
if (selectedPost.value) {
selectedPost.value.viewer_state.liked = result.liked
selectedPost.value.counters.like_count = result.like_count
if (result.liked && result.reward_hint) {
ElMessage({
message: `点赞成功!已为您支持的作者贡献了 ${result.reward_hint.amount} 积分奖励`,
type: 'success',
duration: 4000,
showClose: true,
})
} else if (!isLiked) {
ElMessage.success('已点赞')
}
}
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '点赞操作失败')
} finally {
isLiking.value = false
}
}
async function submitComment() { async function submitComment() {
const content = newComment.value.trim() const content = newComment.value.trim()
if (!selectedPost.value || !content || commentSubmitting.value) { if (!selectedPost.value || !content || commentSubmitting.value) {
@@ -266,6 +305,16 @@ watch(
<el-button :icon="ArrowLeft" circle @click="goBack" /> <el-button :icon="ArrowLeft" circle @click="goBack" />
<span class="nav-title">计划详情</span> <span class="nav-title">计划详情</span>
<div class="nav-actions"> <div class="nav-actions">
<el-button
round
class="nav-like-btn"
:class="{ 'is-active': selectedPost.viewer_state.liked }"
:icon="selectedPost.viewer_state.liked ? StarFilled : Star"
:loading="isLiking"
@click="handleLikeToggle"
>
{{ selectedPost.counters.like_count }}
</el-button>
<el-button <el-button
type="primary" type="primary"
round round
@@ -280,7 +329,7 @@ watch(
<div class="detail-main-layout"> <div class="detail-main-layout">
<aside class="detail-sidebar"> <aside class="detail-sidebar">
<div class="author-card"> <div class="author-card">
<img :src="selectedPost.author.avatar_url" class="author-avatar" /> <img :src="getAvatarUrl(selectedPost.author.avatar_url, selectedPost.author.user_id)" class="author-avatar" />
<div class="author-name">{{ selectedPost.author.nickname }}</div> <div class="author-name">{{ selectedPost.author.nickname }}</div>
<div class="publish-time">发布于 {{ formatDate(selectedPost.created_at) }}</div> <div class="publish-time">发布于 {{ formatDate(selectedPost.created_at) }}</div>
<div class="author-stats"> <div class="author-stats">
@@ -336,6 +385,22 @@ watch(
<el-tag v-for="tag in selectedPost.tags" :key="tag" class="mx-1" effect="plain">{{ tag }}</el-tag> <el-tag v-for="tag in selectedPost.tags" :key="tag" class="mx-1" effect="plain">{{ tag }}</el-tag>
</div> </div>
<p class="plan-description">{{ selectedPost.summary }}</p> <p class="plan-description">{{ selectedPost.summary }}</p>
<div class="content-interaction">
<button
class="big-like-btn"
:class="{ 'is-liked': selectedPost.viewer_state.liked }"
:disabled="isLiking"
@click="handleLikeToggle"
>
<div class="like-icon-wrapper">
<el-icon v-if="isLiking" class="is-loading"><Connection /></el-icon>
<el-icon v-else><StarFilled v-if="selectedPost.viewer_state.liked" /><Star v-else /></el-icon>
</div>
<span class="like-label">{{ selectedPost.viewer_state.liked ? '取消点赞' : '点赞支持' }}</span>
<span class="like-count">{{ selectedPost.counters.like_count }}</span>
</button>
</div>
</section> </section>
<section class="comments-section"> <section class="comments-section">
@@ -362,7 +427,7 @@ watch(
<div class="comments-list"> <div class="comments-list">
<div v-for="comment in comments" :key="comment.comment_id" class="comment-item"> <div v-for="comment in comments" :key="comment.comment_id" class="comment-item">
<img :src="comment.author.avatar_url" class="c-avatar" /> <img :src="getAvatarUrl(comment.author.avatar_url, comment.author.user_id)" class="c-avatar" />
<div class="c-body"> <div class="c-body">
<div class="c-user"> <div class="c-user">
{{ comment.author.nickname }} {{ comment.author.nickname }}
@@ -398,7 +463,7 @@ watch(
<div v-if="comment.children.length > 0" class="comment-children"> <div v-if="comment.children.length > 0" class="comment-children">
<div v-for="child in comment.children" :key="child.comment_id" class="comment-item child"> <div v-for="child in comment.children" :key="child.comment_id" class="comment-item child">
<img :src="child.author.avatar_url" class="c-avatar small" /> <img :src="getAvatarUrl(child.author.avatar_url, child.author.user_id)" class="c-avatar small" />
<div class="c-body"> <div class="c-body">
<div class="c-user"> <div class="c-user">
{{ child.author.nickname }} {{ child.author.nickname }}
@@ -480,6 +545,29 @@ watch(
flex: 1; flex: 1;
} }
.nav-actions {
display: flex;
align-items: center;
gap: 12px;
}
.nav-like-btn {
background: #f8fafc;
border-color: #e2e8f0;
color: #64748b;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.nav-like-btn.is-active {
background: #fff1f2;
border-color: #fecdd3;
color: #e11d48;
}
.nav-like-btn:hover {
transform: translateY(-1px);
}
.detail-main-layout { .detail-main-layout {
display: grid; display: grid;
grid-template-columns: 320px 1fr; grid-template-columns: 320px 1fr;
@@ -678,6 +766,69 @@ watch(
line-height: 1.8; line-height: 1.8;
color: #475569; color: #475569;
white-space: pre-wrap; white-space: pre-wrap;
margin-bottom: 32px;
}
.content-interaction {
display: flex;
justify-content: center;
padding: 24px 0;
border-bottom: 1px solid #f1f5f9;
}
.big-like-btn {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 28px;
background: #ffffff;
border: 2px solid #f1f5f9;
border-radius: 100px;
cursor: pointer;
transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.02);
}
.big-like-btn:hover {
transform: scale(1.05);
border-color: #3b82f6;
background: #f0f7ff;
}
.big-like-btn.is-liked {
background: #fff1f2;
border-color: #fb7185;
color: #e11d48;
box-shadow: 0 8px 20px rgba(225, 29, 72, 0.12);
}
.big-like-btn.is-liked .like-icon-wrapper {
color: #e11d48;
transform: scale(1.2);
}
.like-icon-wrapper {
font-size: 24px;
display: flex;
transition: transform 0.3s ease;
}
.like-label {
font-weight: 700;
font-size: 15px;
}
.like-count {
font-family: 'JetBrains Mono', monospace;
font-weight: 800;
background: rgba(0, 0, 0, 0.05);
padding: 2px 8px;
border-radius: 6px;
font-size: 13px;
}
.big-like-btn.is-liked .like-count {
background: rgba(225, 29, 72, 0.1);
} }
.content-body h3, .comments-section h3 { .content-body h3, .comments-section h3 {

View File

@@ -13,6 +13,7 @@ import {
getWeekSchedule, getWeekSchedule,
smartPlanning, smartPlanning,
smartPlanningMulti, smartPlanningMulti,
updateTaskClass,
} from '@/api/scheduleCenter' } from '@/api/scheduleCenter'
import CreateTaskClassDialog from '@/components/schedule/CreateTaskClassDialog.vue' import CreateTaskClassDialog from '@/components/schedule/CreateTaskClassDialog.vue'
import TaskClassSidebar from '@/components/schedule/TaskClassSidebar.vue' import TaskClassSidebar from '@/components/schedule/TaskClassSidebar.vue'
@@ -131,6 +132,7 @@ const applyingLoading = ref(false)
const deletingLoading = ref(false) const deletingLoading = ref(false)
const createDialogVisible = ref(false) const createDialogVisible = ref(false)
const createDialogLoading = ref(false) const createDialogLoading = ref(false)
const editDialogInitialData = ref<TaskClassDetail | null>(null)
const courseImportDialogVisible = ref(false) const courseImportDialogVisible = ref(false)
const taskClasses = ref<TaskClassListItem[]>([]) const taskClasses = ref<TaskClassListItem[]>([])
@@ -1090,15 +1092,37 @@ function toggleManualEditMode() {
} }
} }
async function handleCreateTaskClass(payload: Parameters<typeof createTaskClass>[0]) { async function handleOpenEditDialog() {
if (expandedTaskClassId.value === null) return
taskClassDetailLoading.value = true
try {
const detail = await getTaskClassDetail(expandedTaskClassId.value)
editDialogInitialData.value = detail
createDialogVisible.value = true
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '获取详情失败')
} finally {
taskClassDetailLoading.value = false
}
}
async function handleTaskClassSubmit(payload: Parameters<typeof createTaskClass>[0]) {
createDialogLoading.value = true createDialogLoading.value = true
try { try {
await createTaskClass(payload) if (editDialogInitialData.value && expandedTaskClassId.value !== null) {
ElMessage.success('任务类已创建') await updateTaskClass(expandedTaskClassId.value, payload)
ElMessage.success('任务类已更新')
// 更新详情缓存
await loadTaskClassDetail(expandedTaskClassId.value)
} else {
await createTaskClass(payload)
ElMessage.success('任务类已创建')
}
createDialogVisible.value = false createDialogVisible.value = false
await loadTaskClasses() await loadTaskClasses()
} catch (error) { } catch (error) {
ElMessage.error(error instanceof Error ? error.message : '创建任务类失败') ElMessage.error(error instanceof Error ? error.message : '保存失败')
} finally { } finally {
createDialogLoading.value = false createDialogLoading.value = false
} }
@@ -1184,7 +1208,7 @@ onMounted(async () => {
:manual-edit-mode="manualEditMode" :manual-edit-mode="manualEditMode"
@activate="handleActivateTaskClass" @activate="handleActivateTaskClass"
@toggle-multi-mode="handleToggleTaskClassMultiMode" @toggle-multi-mode="handleToggleTaskClassMultiMode"
@create="createDialogVisible = true" @create="() => { editDialogInitialData = null; createDialogVisible = true }"
@delete-item="handleDeleteTaskItem" @delete-item="handleDeleteTaskItem"
/> />
@@ -1227,6 +1251,15 @@ onMounted(async () => {
导入课表 导入课表
</button> </button>
<button
v-if="expandedTaskClassId !== null && !taskClassMultiSelectMode && !manualEditMode && !scheduleSelectionMode"
type="button"
class="schedule-board__toolbar-button schedule-board__toolbar-button--ghost"
@click="handleOpenEditDialog"
>
编辑任务类
</button>
<button <button
v-if="showSmartPlanningButton" v-if="showSmartPlanningButton"
type="button" type="button"
@@ -1308,7 +1341,8 @@ onMounted(async () => {
<CreateTaskClassDialog <CreateTaskClassDialog
v-model="createDialogVisible" v-model="createDialogVisible"
:loading="createDialogLoading" :loading="createDialogLoading"
@submit="handleCreateTaskClass" :initial-data="editDialogInitialData"
@submit="handleTaskClassSubmit"
/> />
<CourseImageImportDialog <CourseImageImportDialog