feat(admin): 客服手动录单支持平台与操作人,并可后台配置可选项
- 录单列表新增「平台」「操作人」两列,录单表单与编辑弹窗新增同名字段下拉 - 新增 cs_manual_entry_options 表与 4 个接口(读取/新增/重命名/删除),页面右上角弹窗维护平台与操作人 - 迁移 000087:cs_manual_entries 增加 platform/operator 列与索引,注册 cs_manual_entry:option_manage 权限并授予 ops/super_admin - 记录保存名称快照,删除选项不影响历史记录;同类型重名返回 409,跨类型同名允许 - 顶部关键词查询支持命中平台/操作人 - 新增单测:选项 CRUD 边界与录单平台/操作人读写
This commit is contained in:
@@ -4,10 +4,13 @@ import "time"
|
|||||||
|
|
||||||
// CSManualEntry 客服手动录单记录。
|
// CSManualEntry 客服手动录单记录。
|
||||||
// 客服在后台手动登记一个编号(如 202610120013),该编号与其登录账号绑定,
|
// 客服在后台手动登记一个编号(如 202610120013),该编号与其登录账号绑定,
|
||||||
// 记录登记时间等,供后续查询与按客服统计今日录单量。
|
// 记录平台、操作人、登记时间等,供后续查询与按客服统计今日录单量。
|
||||||
|
// platform / operator 存名称快照:后台删掉选项也不影响历史记录展示。
|
||||||
type CSManualEntry struct {
|
type CSManualEntry struct {
|
||||||
ID uint64 `gorm:"primaryKey" json:"id"`
|
ID uint64 `gorm:"primaryKey" json:"id"`
|
||||||
EntryNo string `gorm:"size:64;not null;uniqueIndex" json:"entry_no"`
|
EntryNo string `gorm:"size:64;not null;uniqueIndex" json:"entry_no"`
|
||||||
|
Platform string `gorm:"size:64;not null;default:'';index" json:"platform"`
|
||||||
|
Operator string `gorm:"size:64;not null;default:'';index" json:"operator"`
|
||||||
AdminID uint64 `gorm:"not null;index" json:"admin_id"`
|
AdminID uint64 `gorm:"not null;index" json:"admin_id"`
|
||||||
AdminName string `gorm:"size:64;not null;default:''" json:"admin_name"`
|
AdminName string `gorm:"size:64;not null;default:''" json:"admin_name"`
|
||||||
AdminUsername string `gorm:"size:64;not null;default:''" json:"admin_username"`
|
AdminUsername string `gorm:"size:64;not null;default:''" json:"admin_username"`
|
||||||
@@ -19,3 +22,18 @@ type CSManualEntry struct {
|
|||||||
func (CSManualEntry) TableName() string {
|
func (CSManualEntry) TableName() string {
|
||||||
return "cs_manual_entries"
|
return "cs_manual_entries"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CSManualEntryOption 客服手动录单的可选项配置(平台 / 操作人)。
|
||||||
|
// 仅作为录单表单的下拉数据源,记录里保存的是名称快照。
|
||||||
|
type CSManualEntryOption struct {
|
||||||
|
ID uint64 `gorm:"primaryKey" json:"id"`
|
||||||
|
Type string `gorm:"size:16;not null;uniqueIndex:uk_cs_manual_entry_options_type_name,priority:1" json:"type"`
|
||||||
|
Name string `gorm:"size:64;not null;uniqueIndex:uk_cs_manual_entry_options_type_name,priority:2" json:"name"`
|
||||||
|
SortOrder int `gorm:"not null;default:0" json:"sort_order"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (CSManualEntryOption) TableName() string {
|
||||||
|
return "cs_manual_entry_options"
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,22 +2,34 @@ package csmanualentry
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
// 录单选项类型。
|
||||||
|
const (
|
||||||
|
OptionTypePlatform = "platform" // 平台
|
||||||
|
OptionTypeOperator = "operator" // 操作人
|
||||||
|
)
|
||||||
|
|
||||||
// CreateRequest 客服手动录单请求。
|
// CreateRequest 客服手动录单请求。
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
EntryNo string `json:"entry_no" binding:"required"`
|
EntryNo string `json:"entry_no" binding:"required"`
|
||||||
Remark string `json:"remark"`
|
Platform string `json:"platform"`
|
||||||
|
Operator string `json:"operator"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateRequest 管理员修正录单请求。
|
// UpdateRequest 管理员修正录单请求。
|
||||||
type UpdateRequest struct {
|
type UpdateRequest struct {
|
||||||
EntryNo string `json:"entry_no" binding:"required"`
|
EntryNo string `json:"entry_no" binding:"required"`
|
||||||
Remark string `json:"remark"`
|
Platform string `json:"platform"`
|
||||||
|
Operator string `json:"operator"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EntryDTO 录单记录。
|
// EntryDTO 录单记录。
|
||||||
type EntryDTO struct {
|
type EntryDTO struct {
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
EntryNo string `json:"entry_no"`
|
EntryNo string `json:"entry_no"`
|
||||||
|
Platform string `json:"platform"`
|
||||||
|
Operator string `json:"operator"`
|
||||||
AdminID uint64 `json:"admin_id"`
|
AdminID uint64 `json:"admin_id"`
|
||||||
AdminName string `json:"admin_name"`
|
AdminName string `json:"admin_name"`
|
||||||
AdminUsername string `json:"admin_username"`
|
AdminUsername string `json:"admin_username"`
|
||||||
@@ -56,3 +68,29 @@ type AgentDayStatsDTO struct {
|
|||||||
type CreateResult struct {
|
type CreateResult struct {
|
||||||
Entry EntryDTO `json:"entry"`
|
Entry EntryDTO `json:"entry"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OptionDTO 录单可选项(平台 / 操作人)。
|
||||||
|
type OptionDTO struct {
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
SortOrder int `json:"sort_order"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// OptionListDTO 平台与操作人选项集合,供录单表单下拉直接使用。
|
||||||
|
type OptionListDTO struct {
|
||||||
|
Platforms []OptionDTO `json:"platforms"`
|
||||||
|
Operators []OptionDTO `json:"operators"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateOptionRequest 新增平台 / 操作人选项。
|
||||||
|
type CreateOptionRequest struct {
|
||||||
|
Type string `json:"type" binding:"required"`
|
||||||
|
Name string `json:"name" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOptionRequest 重命名平台 / 操作人选项。
|
||||||
|
type UpdateOptionRequest struct {
|
||||||
|
Name string `json:"name" binding:"required"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,4 +8,8 @@ var (
|
|||||||
ErrEntryNoInvalid = errors.New("entry number is invalid")
|
ErrEntryNoInvalid = errors.New("entry number is invalid")
|
||||||
ErrEntryNotFound = errors.New("manual entry not found")
|
ErrEntryNotFound = errors.New("manual entry not found")
|
||||||
ErrAdminNotFound = errors.New("admin not found")
|
ErrAdminNotFound = errors.New("admin not found")
|
||||||
|
ErrOptionTypeInvalid = errors.New("manual entry option type is invalid")
|
||||||
|
ErrOptionNameInvalid = errors.New("manual entry option name is invalid")
|
||||||
|
ErrOptionExists = errors.New("manual entry option already exists")
|
||||||
|
ErrOptionNotFound = errors.New("manual entry option not found")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -122,6 +122,81 @@ func (h *Handler) Delete(c *gin.Context) {
|
|||||||
response.OK(c, gin.H{"deleted": true})
|
response.OK(c, gin.H{"deleted": true})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListOptions 返回平台与操作人选项,供录单表单下拉使用。
|
||||||
|
func (h *Handler) ListOptions(c *gin.Context) {
|
||||||
|
if _, ok := currentAdminID(c); !ok {
|
||||||
|
response.Unauthorized(c, "缺少管理员上下文")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result, err := h.service.ListOptions(c.Request.Context())
|
||||||
|
if err != nil {
|
||||||
|
writeManualEntryError(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.OK(c, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateOption 新增平台 / 操作人选项。
|
||||||
|
func (h *Handler) CreateOption(c *gin.Context) {
|
||||||
|
if _, ok := currentAdminID(c); !ok {
|
||||||
|
response.Unauthorized(c, "缺少管理员上下文")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var req CreateOptionRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
response.BadRequest(c, "选项参数不正确")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
option, err := h.service.CreateOption(c.Request.Context(), req)
|
||||||
|
if err != nil {
|
||||||
|
writeManualEntryError(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Created(c, option)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOption 重命名平台 / 操作人选项。
|
||||||
|
func (h *Handler) UpdateOption(c *gin.Context) {
|
||||||
|
if _, ok := currentAdminID(c); !ok {
|
||||||
|
response.Unauthorized(c, "缺少管理员上下文")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||||
|
if err != nil || id == 0 {
|
||||||
|
response.BadRequest(c, "ID 不正确")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var req UpdateOptionRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
response.BadRequest(c, "选项参数不正确")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
option, err := h.service.UpdateOption(c.Request.Context(), id, req)
|
||||||
|
if err != nil {
|
||||||
|
writeManualEntryError(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.OK(c, option)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOption 删除平台 / 操作人选项。
|
||||||
|
func (h *Handler) DeleteOption(c *gin.Context) {
|
||||||
|
if _, ok := currentAdminID(c); !ok {
|
||||||
|
response.Unauthorized(c, "缺少管理员上下文")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||||
|
if err != nil || id == 0 {
|
||||||
|
response.BadRequest(c, "ID 不正确")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := h.service.DeleteOption(c.Request.Context(), id); err != nil {
|
||||||
|
writeManualEntryError(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.OK(c, gin.H{"deleted": true})
|
||||||
|
}
|
||||||
|
|
||||||
func currentAdminID(c *gin.Context) (uint64, bool) {
|
func currentAdminID(c *gin.Context) (uint64, bool) {
|
||||||
value, ok := c.Get(middleware.ContextAdminID)
|
value, ok := c.Get(middleware.ContextAdminID)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -159,6 +234,14 @@ func writeManualEntryError(c *gin.Context, err error) {
|
|||||||
response.NotFound(c, "录单记录不存在")
|
response.NotFound(c, "录单记录不存在")
|
||||||
case errors.Is(err, ErrEntryNoExists):
|
case errors.Is(err, ErrEntryNoExists):
|
||||||
response.Error(c, http.StatusConflict, "entry_no_exists", "该编号已被登记")
|
response.Error(c, http.StatusConflict, "entry_no_exists", "该编号已被登记")
|
||||||
|
case errors.Is(err, ErrOptionTypeInvalid):
|
||||||
|
response.BadRequest(c, "选项类型不正确")
|
||||||
|
case errors.Is(err, ErrOptionNameInvalid):
|
||||||
|
response.BadRequest(c, "选项名称不正确")
|
||||||
|
case errors.Is(err, ErrOptionNotFound):
|
||||||
|
response.NotFound(c, "选项不存在")
|
||||||
|
case errors.Is(err, ErrOptionExists):
|
||||||
|
response.Error(c, http.StatusConflict, "option_exists", "该选项已存在")
|
||||||
default:
|
default:
|
||||||
response.Error(c, http.StatusInternalServerError, "internal_error", "录单服务暂时不可用")
|
response.Error(c, http.StatusInternalServerError, "internal_error", "录单服务暂时不可用")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,9 +34,11 @@ func (r *Repository) FindAdminSnapshot(ctx context.Context, adminID uint64) (nam
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create 写入一条录单记录。
|
// Create 写入一条录单记录。
|
||||||
func (r *Repository) Create(ctx context.Context, adminID uint64, adminName, adminUsername, entryNo, remark string) (*EntryDTO, error) {
|
func (r *Repository) Create(ctx context.Context, adminID uint64, adminName, adminUsername, entryNo, platform, operator, remark string) (*EntryDTO, error) {
|
||||||
row := model.CSManualEntry{
|
row := model.CSManualEntry{
|
||||||
EntryNo: entryNo,
|
EntryNo: entryNo,
|
||||||
|
Platform: platform,
|
||||||
|
Operator: operator,
|
||||||
AdminID: adminID,
|
AdminID: adminID,
|
||||||
AdminName: adminName,
|
AdminName: adminName,
|
||||||
AdminUsername: adminUsername,
|
AdminUsername: adminUsername,
|
||||||
@@ -65,12 +67,14 @@ func (r *Repository) FindByID(ctx context.Context, id uint64) (*EntryDTO, error)
|
|||||||
return &dto, nil
|
return &dto, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update 修正录单的编号与备注。编号唯一冲突返回 ErrEntryNoExists。
|
// Update 修正录单的编号、平台、操作人与备注。编号唯一冲突返回 ErrEntryNoExists。
|
||||||
func (r *Repository) Update(ctx context.Context, id uint64, entryNo, remark string) (*EntryDTO, error) {
|
func (r *Repository) Update(ctx context.Context, id uint64, entryNo, platform, operator, remark string) (*EntryDTO, error) {
|
||||||
result := r.db.WithContext(ctx).Model(&model.CSManualEntry{}).
|
result := r.db.WithContext(ctx).Model(&model.CSManualEntry{}).
|
||||||
Where("id = ?", id).
|
Where("id = ?", id).
|
||||||
Updates(map[string]any{
|
Updates(map[string]any{
|
||||||
"entry_no": entryNo,
|
"entry_no": entryNo,
|
||||||
|
"platform": platform,
|
||||||
|
"operator": operator,
|
||||||
"remark": remark,
|
"remark": remark,
|
||||||
})
|
})
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
@@ -118,7 +122,10 @@ func (r *Repository) List(ctx context.Context, query ListQuery) (*PaginatedResul
|
|||||||
}
|
}
|
||||||
if kw := strings.TrimSpace(query.Keyword); kw != "" {
|
if kw := strings.TrimSpace(query.Keyword); kw != "" {
|
||||||
like := "%" + kw + "%"
|
like := "%" + kw + "%"
|
||||||
cond := r.db.Where("entry_no LIKE ? OR admin_name LIKE ? OR admin_username LIKE ?", like, like, like)
|
cond := r.db.Where(
|
||||||
|
"entry_no LIKE ? OR admin_name LIKE ? OR admin_username LIKE ? OR platform LIKE ? OR operator LIKE ?",
|
||||||
|
like, like, like, like, like,
|
||||||
|
)
|
||||||
db = db.Where(cond)
|
db = db.Where(cond)
|
||||||
countDB = countDB.Where(cond)
|
countDB = countDB.Where(cond)
|
||||||
}
|
}
|
||||||
@@ -192,11 +199,99 @@ func (r *Repository) TodayAgentStats(ctx context.Context, day time.Time) ([]Agen
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListOptions 返回某类型(平台 / 操作人)的全部可选项。
|
||||||
|
func (r *Repository) ListOptions(ctx context.Context, optionType string) ([]OptionDTO, error) {
|
||||||
|
if !IsValidOptionType(optionType) {
|
||||||
|
return nil, ErrOptionTypeInvalid
|
||||||
|
}
|
||||||
|
rows := make([]model.CSManualEntryOption, 0)
|
||||||
|
if err := r.db.WithContext(ctx).
|
||||||
|
Where("type = ?", optionType).
|
||||||
|
Order("sort_order ASC, id ASC").
|
||||||
|
Find(&rows).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items := make([]OptionDTO, 0, len(rows))
|
||||||
|
for _, row := range rows {
|
||||||
|
items = append(items, toOptionDTO(row))
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListAllOptions 返回平台与操作人两组可选项,供录单表单直接使用。
|
||||||
|
func (r *Repository) ListAllOptions(ctx context.Context) (*OptionListDTO, error) {
|
||||||
|
platforms, err := r.ListOptions(ctx, OptionTypePlatform)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
operators, err := r.ListOptions(ctx, OptionTypeOperator)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &OptionListDTO{Platforms: platforms, Operators: operators}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateOption 新增一个平台 / 操作人选项,重名返回 ErrOptionExists。
|
||||||
|
func (r *Repository) CreateOption(ctx context.Context, optionType, name string) (*OptionDTO, error) {
|
||||||
|
if !IsValidOptionType(optionType) {
|
||||||
|
return nil, ErrOptionTypeInvalid
|
||||||
|
}
|
||||||
|
row := model.CSManualEntryOption{Type: optionType, Name: name}
|
||||||
|
if err := r.db.WithContext(ctx).Create(&row).Error; err != nil {
|
||||||
|
if isDuplicateEntry(err) {
|
||||||
|
return nil, ErrOptionExists
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dto := toOptionDTO(row)
|
||||||
|
return &dto, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOption 重命名一个选项,重名返回 ErrOptionExists。
|
||||||
|
func (r *Repository) UpdateOption(ctx context.Context, id uint64, name string) (*OptionDTO, error) {
|
||||||
|
var row model.CSManualEntryOption
|
||||||
|
if err := r.db.WithContext(ctx).First(&row, id).Error; err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return nil, ErrOptionNotFound
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := r.db.WithContext(ctx).Model(&model.CSManualEntryOption{}).
|
||||||
|
Where("id = ?", id).
|
||||||
|
Update("name", name)
|
||||||
|
if result.Error != nil {
|
||||||
|
if isDuplicateEntry(result.Error) {
|
||||||
|
return nil, ErrOptionExists
|
||||||
|
}
|
||||||
|
return nil, result.Error
|
||||||
|
}
|
||||||
|
row.Name = name
|
||||||
|
dto := toOptionDTO(row)
|
||||||
|
return &dto, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOption 删除一个选项(历史录单里的名称快照不受影响)。
|
||||||
|
func (r *Repository) DeleteOption(ctx context.Context, id uint64) error {
|
||||||
|
result := r.db.WithContext(ctx).Delete(&model.CSManualEntryOption{}, id)
|
||||||
|
if result.Error != nil {
|
||||||
|
return result.Error
|
||||||
|
}
|
||||||
|
if result.RowsAffected == 0 {
|
||||||
|
return ErrOptionNotFound
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValidOptionType 判断选项类型是否合法。
|
||||||
|
func IsValidOptionType(optionType string) bool {
|
||||||
|
return optionType == OptionTypePlatform || optionType == OptionTypeOperator
|
||||||
|
}
|
||||||
|
|
||||||
func parseDay(value string, loc *time.Location) (time.Time, error) {
|
func parseDay(value string, loc *time.Location) (time.Time, error) {
|
||||||
return time.ParseInLocation("2006-01-02", value, loc)
|
return time.ParseInLocation("2006-01-02", value, loc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// isDuplicateEntry 判断错误是否为 entry_no 唯一键冲突。
|
// isDuplicateEntry 判断错误是否为唯一键冲突。
|
||||||
func isDuplicateEntry(err error) bool {
|
func isDuplicateEntry(err error) bool {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return false
|
return false
|
||||||
@@ -211,6 +306,8 @@ func toDTO(row model.CSManualEntry) EntryDTO {
|
|||||||
return EntryDTO{
|
return EntryDTO{
|
||||||
ID: row.ID,
|
ID: row.ID,
|
||||||
EntryNo: row.EntryNo,
|
EntryNo: row.EntryNo,
|
||||||
|
Platform: row.Platform,
|
||||||
|
Operator: row.Operator,
|
||||||
AdminID: row.AdminID,
|
AdminID: row.AdminID,
|
||||||
AdminName: row.AdminName,
|
AdminName: row.AdminName,
|
||||||
AdminUsername: row.AdminUsername,
|
AdminUsername: row.AdminUsername,
|
||||||
@@ -218,3 +315,13 @@ func toDTO(row model.CSManualEntry) EntryDTO {
|
|||||||
CreatedAt: row.CreatedAt,
|
CreatedAt: row.CreatedAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toOptionDTO(row model.CSManualEntryOption) OptionDTO {
|
||||||
|
return OptionDTO{
|
||||||
|
ID: row.ID,
|
||||||
|
Type: row.Type,
|
||||||
|
Name: row.Name,
|
||||||
|
SortOrder: row.SortOrder,
|
||||||
|
CreatedAt: row.CreatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
package csmanualentry
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"hfb_sys/backend/internal/database"
|
||||||
|
"hfb_sys/backend/internal/model"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newManualEntryTestRepo(t *testing.T) (*Repository, *gorm.DB) {
|
||||||
|
t.Helper()
|
||||||
|
db := database.NewTestDB()
|
||||||
|
if err := database.AutoMigrateIfMissing(db,
|
||||||
|
&model.AdminUser{},
|
||||||
|
&model.CSManualEntry{},
|
||||||
|
&model.CSManualEntryOption{},
|
||||||
|
); err != nil {
|
||||||
|
t.Fatalf("迁移测试表失败: %v", err)
|
||||||
|
}
|
||||||
|
return NewRepository(db), db
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNormalizeOptionName(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
input string
|
||||||
|
want string
|
||||||
|
wantErr error
|
||||||
|
}{
|
||||||
|
{name: "trim", input: " 网易大神 ", want: "网易大神"},
|
||||||
|
{name: "empty allowed", input: " ", want: ""},
|
||||||
|
{name: "inner space kept", input: "网易 大神", want: "网易 大神"},
|
||||||
|
{name: "64 runes", input: strings.Repeat("游", 64), want: strings.Repeat("游", 64)},
|
||||||
|
{name: "65 runes", input: strings.Repeat("游", 65), wantErr: ErrOptionNameInvalid},
|
||||||
|
{name: "newline", input: "网易\n大神", wantErr: ErrOptionNameInvalid},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, err := normalizeOptionName(tt.input)
|
||||||
|
if !errors.Is(err, tt.wantErr) {
|
||||||
|
t.Fatalf("normalizeOptionName(%q) error = %v, want %v", tt.input, err, tt.wantErr)
|
||||||
|
}
|
||||||
|
if tt.wantErr == nil && got != tt.want {
|
||||||
|
t.Fatalf("normalizeOptionName(%q) = %q, want %q", tt.input, got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRepositoryOptionCRUDAndEntryPlatformOperator(t *testing.T) {
|
||||||
|
repo, db := newManualEntryTestRepo(t)
|
||||||
|
ctx := t.Context()
|
||||||
|
|
||||||
|
admin := model.AdminUser{Username: "cs001", Nickname: "客服小张", PasswordHash: "x"}
|
||||||
|
if err := db.Create(&admin).Error; err != nil {
|
||||||
|
t.Fatalf("创建管理员失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. 选项 CRUD
|
||||||
|
platform, err := repo.CreateOption(ctx, OptionTypePlatform, "网易大神")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("创建平台选项失败: %v", err)
|
||||||
|
}
|
||||||
|
// 同类型第二个平台,用于验证重命名撞名(唯一键是 type+name,跨类型不算冲突)
|
||||||
|
if _, err := repo.CreateOption(ctx, OptionTypePlatform, "交易猫"); err != nil {
|
||||||
|
t.Fatalf("创建第二个平台选项失败: %v", err)
|
||||||
|
}
|
||||||
|
operator, err := repo.CreateOption(ctx, OptionTypeOperator, "技术测试")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("创建操作人选项失败: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := repo.CreateOption(ctx, OptionTypePlatform, "网易大神"); !errors.Is(err, ErrOptionExists) {
|
||||||
|
t.Fatalf("重复平台应返回 ErrOptionExists, got %v", err)
|
||||||
|
}
|
||||||
|
if _, err := repo.CreateOption(ctx, "unknown", "x"); !errors.Is(err, ErrOptionTypeInvalid) {
|
||||||
|
t.Fatalf("非法类型应返回 ErrOptionTypeInvalid, got %v", err)
|
||||||
|
}
|
||||||
|
// 与平台同名的操作人是允许的(不同 type)
|
||||||
|
if _, err := repo.CreateOption(ctx, OptionTypeOperator, "网易大神"); err != nil {
|
||||||
|
t.Fatalf("跨类型同名应允许: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := repo.UpdateOption(ctx, platform.ID, "网易"); err != nil {
|
||||||
|
t.Fatalf("重命名选项失败: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := repo.UpdateOption(ctx, platform.ID, "交易猫"); !errors.Is(err, ErrOptionExists) {
|
||||||
|
t.Fatalf("重命名撞同类型已有名应返回 ErrOptionExists, got %v", err)
|
||||||
|
}
|
||||||
|
if _, err := repo.UpdateOption(ctx, 999999, "任何"); !errors.Is(err, ErrOptionNotFound) {
|
||||||
|
t.Fatalf("重命名不存在选项应返回 ErrOptionNotFound, got %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
options, err := repo.ListAllOptions(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("读取选项列表失败: %v", err)
|
||||||
|
}
|
||||||
|
if len(options.Platforms) != 2 || options.Platforms[0].Name != "网易" {
|
||||||
|
t.Fatalf("平台选项 = %+v, want 2 条且首条为网易", options.Platforms)
|
||||||
|
}
|
||||||
|
if len(options.Operators) != 2 {
|
||||||
|
t.Fatalf("操作人选项 = %+v, want 2 条", options.Operators)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 录单写入平台 / 操作人
|
||||||
|
entry, err := repo.Create(ctx, admin.ID, "客服小张", "cs001", "202610130001", "网易", "技术测试", "备注1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("录单失败: %v", err)
|
||||||
|
}
|
||||||
|
if entry.Platform != "网易" || entry.Operator != "技术测试" {
|
||||||
|
t.Fatalf("录单平台/操作人 = %q/%q", entry.Platform, entry.Operator)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修正录单的平台与操作人
|
||||||
|
updated, err := repo.Update(ctx, entry.ID, "202610130001", "网易", "客服小李", "备注2")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("修正录单失败: %v", err)
|
||||||
|
}
|
||||||
|
if updated.Operator != "客服小李" || updated.Remark != "备注2" {
|
||||||
|
t.Fatalf("修正后 = %+v", updated)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 关键字命中平台 / 操作人
|
||||||
|
list, err := repo.List(ctx, ListQuery{Keyword: "客服小李", Page: 1, PageSize: 20})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("按操作人查询失败: %v", err)
|
||||||
|
}
|
||||||
|
if list.Total != 1 {
|
||||||
|
t.Fatalf("按操作人查询命中 %d 条, want 1", list.Total)
|
||||||
|
}
|
||||||
|
list, err = repo.List(ctx, ListQuery{Keyword: "网易", Page: 1, PageSize: 20})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("按平台查询失败: %v", err)
|
||||||
|
}
|
||||||
|
if list.Total != 1 {
|
||||||
|
t.Fatalf("按平台查询命中 %d 条, want 1", list.Total)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 删除选项不影响历史录单(记录里是名称快照)
|
||||||
|
if err := repo.DeleteOption(ctx, operator.ID); err != nil {
|
||||||
|
t.Fatalf("删除操作人选项失败: %v", err)
|
||||||
|
}
|
||||||
|
if err := repo.DeleteOption(ctx, operator.ID); !errors.Is(err, ErrOptionNotFound) {
|
||||||
|
t.Fatalf("重复删除应返回 ErrOptionNotFound, got %v", err)
|
||||||
|
}
|
||||||
|
after, err := repo.FindByID(ctx, entry.ID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("删除选项后读取录单失败: %v", err)
|
||||||
|
}
|
||||||
|
if after.Operator != "客服小李" {
|
||||||
|
t.Fatalf("删除选项后历史录单操作人 = %q, want 客服小李", after.Operator)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,15 @@ package csmanualentry
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"hfb_sys/backend/internal/timeutil"
|
"hfb_sys/backend/internal/timeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxEntryNoLength = 64
|
const (
|
||||||
|
maxEntryNoLength = 64
|
||||||
|
maxOptionNameLength = 64
|
||||||
|
)
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
repo *Repository
|
repo *Repository
|
||||||
@@ -26,6 +30,14 @@ func (s *Service) Create(ctx context.Context, adminID uint64, req CreateRequest)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
platform, err := normalizeOptionName(req.Platform)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
operator, err := normalizeOptionName(req.Operator)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
adminName, adminUsername, err := s.repo.FindAdminSnapshot(ctx, adminID)
|
adminName, adminUsername, err := s.repo.FindAdminSnapshot(ctx, adminID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -33,7 +45,7 @@ func (s *Service) Create(ctx context.Context, adminID uint64, req CreateRequest)
|
|||||||
if adminName == "" {
|
if adminName == "" {
|
||||||
adminName = adminUsername
|
adminName = adminUsername
|
||||||
}
|
}
|
||||||
entry, err := s.repo.Create(ctx, adminID, adminName, adminUsername, entryNo, strings.TrimSpace(req.Remark))
|
entry, err := s.repo.Create(ctx, adminID, adminName, adminUsername, entryNo, platform, operator, strings.TrimSpace(req.Remark))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -49,7 +61,15 @@ func (s *Service) Update(ctx context.Context, id uint64, req UpdateRequest) (*En
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return s.repo.Update(ctx, id, entryNo, strings.TrimSpace(req.Remark))
|
platform, err := normalizeOptionName(req.Platform)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
operator, err := normalizeOptionName(req.Operator)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return s.repo.Update(ctx, id, entryNo, platform, operator, strings.TrimSpace(req.Remark))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete 管理员删除录单记录。
|
// Delete 管理员删除录单记录。
|
||||||
@@ -76,6 +96,56 @@ func (s *Service) TodayAgentStats(ctx context.Context) ([]AgentDayStatsDTO, erro
|
|||||||
return s.repo.TodayAgentStats(ctx, timeutil.ShanghaiNow())
|
return s.repo.TodayAgentStats(ctx, timeutil.ShanghaiNow())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListOptions 返回平台与操作人两组可选项。
|
||||||
|
func (s *Service) ListOptions(ctx context.Context) (*OptionListDTO, error) {
|
||||||
|
if s.repo == nil {
|
||||||
|
return nil, ErrDependencyUnavailable
|
||||||
|
}
|
||||||
|
return s.repo.ListAllOptions(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateOption 新增平台 / 操作人选项。
|
||||||
|
func (s *Service) CreateOption(ctx context.Context, req CreateOptionRequest) (*OptionDTO, error) {
|
||||||
|
if s.repo == nil {
|
||||||
|
return nil, ErrDependencyUnavailable
|
||||||
|
}
|
||||||
|
optionType := strings.TrimSpace(req.Type)
|
||||||
|
if !IsValidOptionType(optionType) {
|
||||||
|
return nil, ErrOptionTypeInvalid
|
||||||
|
}
|
||||||
|
name, err := normalizeOptionName(req.Name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if name == "" {
|
||||||
|
return nil, ErrOptionNameInvalid
|
||||||
|
}
|
||||||
|
return s.repo.CreateOption(ctx, optionType, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOption 重命名平台 / 操作人选项。
|
||||||
|
func (s *Service) UpdateOption(ctx context.Context, id uint64, req UpdateOptionRequest) (*OptionDTO, error) {
|
||||||
|
if s.repo == nil {
|
||||||
|
return nil, ErrDependencyUnavailable
|
||||||
|
}
|
||||||
|
name, err := normalizeOptionName(req.Name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if name == "" {
|
||||||
|
return nil, ErrOptionNameInvalid
|
||||||
|
}
|
||||||
|
return s.repo.UpdateOption(ctx, id, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOption 删除平台 / 操作人选项。
|
||||||
|
func (s *Service) DeleteOption(ctx context.Context, id uint64) error {
|
||||||
|
if s.repo == nil {
|
||||||
|
return ErrDependencyUnavailable
|
||||||
|
}
|
||||||
|
return s.repo.DeleteOption(ctx, id)
|
||||||
|
}
|
||||||
|
|
||||||
// normalizeEntryNo 去除首尾空白并做基础校验。
|
// normalizeEntryNo 去除首尾空白并做基础校验。
|
||||||
func normalizeEntryNo(raw string) (string, error) {
|
func normalizeEntryNo(raw string) (string, error) {
|
||||||
value := strings.TrimSpace(raw)
|
value := strings.TrimSpace(raw)
|
||||||
@@ -90,3 +160,16 @@ func normalizeEntryNo(raw string) (string, error) {
|
|||||||
}
|
}
|
||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// normalizeOptionName 规整平台 / 操作人名称:去首尾空白、按字符数限长。
|
||||||
|
// 允许为空(录单时平台与操作人选填),但内部不允许换行等控制字符。
|
||||||
|
func normalizeOptionName(raw string) (string, error) {
|
||||||
|
value := strings.TrimSpace(raw)
|
||||||
|
if utf8.RuneCountInString(value) > maxOptionNameLength {
|
||||||
|
return "", ErrOptionNameInvalid
|
||||||
|
}
|
||||||
|
if strings.ContainsAny(value, "\t\r\n") {
|
||||||
|
return "", ErrOptionNameInvalid
|
||||||
|
}
|
||||||
|
return value, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -721,6 +721,10 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
|
|||||||
adminRoutes.POST("/files/upload", fileHandler.Upload)
|
adminRoutes.POST("/files/upload", fileHandler.Upload)
|
||||||
adminRoutes.GET("/dashboard", requirePerm("dashboard:view"), adminDashboardHandler.Summary)
|
adminRoutes.GET("/dashboard", requirePerm("dashboard:view"), adminDashboardHandler.Summary)
|
||||||
adminRoutes.GET("/manual-entries/today-stats", requirePerm("cs_manual_entry:view"), manualEntryHandler.TodayAgentStats)
|
adminRoutes.GET("/manual-entries/today-stats", requirePerm("cs_manual_entry:view"), manualEntryHandler.TodayAgentStats)
|
||||||
|
adminRoutes.GET("/manual-entries/options", requirePerm("cs_manual_entry:view"), manualEntryHandler.ListOptions)
|
||||||
|
adminRoutes.POST("/manual-entries/options", requirePerm("cs_manual_entry:option_manage"), manualEntryHandler.CreateOption)
|
||||||
|
adminRoutes.PUT("/manual-entries/options/:id", requirePerm("cs_manual_entry:option_manage"), manualEntryHandler.UpdateOption)
|
||||||
|
adminRoutes.DELETE("/manual-entries/options/:id", requirePerm("cs_manual_entry:option_manage"), manualEntryHandler.DeleteOption)
|
||||||
adminRoutes.GET("/manual-entries", requirePerm("cs_manual_entry:view"), manualEntryHandler.List)
|
adminRoutes.GET("/manual-entries", requirePerm("cs_manual_entry:view"), manualEntryHandler.List)
|
||||||
adminRoutes.POST("/manual-entries", requirePerm("cs_manual_entry:create"), manualEntryHandler.Create)
|
adminRoutes.POST("/manual-entries", requirePerm("cs_manual_entry:create"), manualEntryHandler.Create)
|
||||||
adminRoutes.PUT("/manual-entries/:id", requirePerm("cs_manual_entry:update"), manualEntryHandler.Update)
|
adminRoutes.PUT("/manual-entries/:id", requirePerm("cs_manual_entry:update"), manualEntryHandler.Update)
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
-- +goose Up
|
||||||
|
|
||||||
|
-- 客服手动录单:新增「平台」与「操作人」两列,并支持后台维护可选项。
|
||||||
|
-- platform/operator 存名称快照(与 admin_name 同样的快照思路),
|
||||||
|
-- 选项只作为下拉数据源,删除选项不影响历史记录。
|
||||||
|
ALTER TABLE cs_manual_entries
|
||||||
|
ADD COLUMN platform VARCHAR(64) NOT NULL DEFAULT '' COMMENT '平台名称快照' AFTER entry_no,
|
||||||
|
ADD COLUMN operator VARCHAR(64) NOT NULL DEFAULT '' COMMENT '操作人名称快照' AFTER platform,
|
||||||
|
ADD KEY idx_cs_manual_entries_platform (platform),
|
||||||
|
ADD KEY idx_cs_manual_entries_operator (operator);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS cs_manual_entry_options (
|
||||||
|
id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
type VARCHAR(16) NOT NULL COMMENT '选项类型: platform=平台, operator=操作人',
|
||||||
|
name VARCHAR(64) NOT NULL COMMENT '选项名称',
|
||||||
|
sort_order INT NOT NULL DEFAULT 0 COMMENT '排序值,越小越靠前',
|
||||||
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
UNIQUE KEY uk_cs_manual_entry_options_type_name (type, name),
|
||||||
|
KEY idx_cs_manual_entry_options_type_sort (type, sort_order, id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='客服手动录单平台/操作人选项配置表';
|
||||||
|
|
||||||
|
INSERT INTO permissions (code, name, resource, action) VALUES
|
||||||
|
('cs_manual_entry:option_manage', '配置客服手动录单平台与操作人', 'cs_manual_entry', 'option_manage')
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
name = VALUES(name),
|
||||||
|
resource = VALUES(resource),
|
||||||
|
action = VALUES(action);
|
||||||
|
|
||||||
|
-- 运营/超管:可维护平台与操作人选项
|
||||||
|
INSERT IGNORE INTO role_permissions (role_id, permission_id)
|
||||||
|
SELECT r.id, p.id
|
||||||
|
FROM roles r
|
||||||
|
JOIN permissions p ON p.code = 'cs_manual_entry:option_manage'
|
||||||
|
WHERE r.code IN ('ops', 'super_admin');
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
|
||||||
|
DELETE rp
|
||||||
|
FROM role_permissions rp
|
||||||
|
JOIN permissions p ON p.id = rp.permission_id
|
||||||
|
WHERE p.code = 'cs_manual_entry:option_manage';
|
||||||
|
|
||||||
|
DELETE FROM permissions WHERE code = 'cs_manual_entry:option_manage';
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS cs_manual_entry_options;
|
||||||
|
|
||||||
|
ALTER TABLE cs_manual_entries
|
||||||
|
DROP KEY idx_cs_manual_entries_platform,
|
||||||
|
DROP KEY idx_cs_manual_entries_operator,
|
||||||
|
DROP COLUMN platform,
|
||||||
|
DROP COLUMN operator;
|
||||||
@@ -2,9 +2,14 @@ import { apiClient } from '@/shared/api/client'
|
|||||||
|
|
||||||
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
||||||
|
|
||||||
|
/** 录单可选项类型:平台 / 操作人 */
|
||||||
|
export type ManualEntryOptionType = 'platform' | 'operator'
|
||||||
|
|
||||||
export interface ManualEntryItem {
|
export interface ManualEntryItem {
|
||||||
id: number
|
id: number
|
||||||
entry_no: string
|
entry_no: string
|
||||||
|
platform: string
|
||||||
|
operator: string
|
||||||
admin_id: number
|
admin_id: number
|
||||||
admin_name: string
|
admin_name: string
|
||||||
admin_username: string
|
admin_username: string
|
||||||
@@ -12,6 +17,19 @@ export interface ManualEntryItem {
|
|||||||
created_at: string
|
created_at: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ManualEntryOption {
|
||||||
|
id: number
|
||||||
|
type: ManualEntryOptionType
|
||||||
|
name: string
|
||||||
|
sort_order: number
|
||||||
|
created_at: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ManualEntryOptions {
|
||||||
|
platforms: ManualEntryOption[]
|
||||||
|
operators: ManualEntryOption[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface ManualEntryAgentStats {
|
export interface ManualEntryAgentStats {
|
||||||
admin_id: number
|
admin_id: number
|
||||||
admin_name: string
|
admin_name: string
|
||||||
@@ -20,11 +38,15 @@ export interface ManualEntryAgentStats {
|
|||||||
|
|
||||||
export interface CreateManualEntryRequest {
|
export interface CreateManualEntryRequest {
|
||||||
entry_no: string
|
entry_no: string
|
||||||
|
platform?: string
|
||||||
|
operator?: string
|
||||||
remark?: string
|
remark?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateManualEntryRequest {
|
export interface UpdateManualEntryRequest {
|
||||||
entry_no: string
|
entry_no: string
|
||||||
|
platform?: string
|
||||||
|
operator?: string
|
||||||
remark?: string
|
remark?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,3 +101,37 @@ export async function fetchManualEntryTodayStats() {
|
|||||||
)
|
)
|
||||||
return data.data
|
return data.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 获取平台 / 操作人可选项(录单下拉数据源) */
|
||||||
|
export async function fetchManualEntryOptions() {
|
||||||
|
const { data } = await apiClient.get<ApiResponse<ManualEntryOptions>>(
|
||||||
|
'/admin/manual-entries/options'
|
||||||
|
)
|
||||||
|
return data.data
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createManualEntryOption(payload: {
|
||||||
|
type: ManualEntryOptionType
|
||||||
|
name: string
|
||||||
|
}) {
|
||||||
|
const { data } = await apiClient.post<ApiResponse<ManualEntryOption>>(
|
||||||
|
'/admin/manual-entries/options',
|
||||||
|
payload
|
||||||
|
)
|
||||||
|
return data.data
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateManualEntryOption(id: number, name: string) {
|
||||||
|
const { data } = await apiClient.put<ApiResponse<ManualEntryOption>>(
|
||||||
|
`/admin/manual-entries/options/${id}`,
|
||||||
|
{ name }
|
||||||
|
)
|
||||||
|
return data.data
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteManualEntryOption(id: number) {
|
||||||
|
const { data } = await apiClient.delete<ApiResponse<{ deleted: boolean }>>(
|
||||||
|
`/admin/manual-entries/options/${id}`
|
||||||
|
)
|
||||||
|
return data.data
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,12 @@
|
|||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.page-header-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.manual-entry-form-head {
|
.manual-entry-form-head {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
@@ -34,19 +40,22 @@
|
|||||||
|
|
||||||
.manual-entry-form-grid {
|
.manual-entry-form-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
gap: 16px;
|
gap: 16px;
|
||||||
align-items: end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.manual-entry-form-grid :deep(.el-form-item) {
|
.manual-entry-form-grid :deep(.el-form-item) {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.manual-entry-submit {
|
.full-control {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.manual-entry-submit-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
justify-content: flex-end;
|
||||||
height: 32px;
|
margin-top: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.manual-entry-filter-row {
|
.manual-entry-filter-row {
|
||||||
@@ -62,7 +71,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.filter-keyword {
|
.filter-keyword {
|
||||||
width: 260px;
|
width: 320px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.filter-date {
|
.filter-date {
|
||||||
@@ -76,8 +85,87 @@
|
|||||||
color: #1e3a8a;
|
color: #1e3a8a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 平台 / 操作人配置弹窗 */
|
||||||
|
.option-config-tip {
|
||||||
|
margin: 0 0 16px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #94a3b8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-config-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-config-panel {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 16px;
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: #f8fafc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-config-title {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #1e293b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-config-add {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-config-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
max-height: 320px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-config-list li {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #ffffff;
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-config-name {
|
||||||
|
font-size: 13px;
|
||||||
|
color: #0f172a;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-config-actions {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-config-actions :deep(.el-button) {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-config-empty {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #94a3b8;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 1100px) {
|
@media (max-width: 1100px) {
|
||||||
.manual-entry-form-grid {
|
.manual-entry-form-grid,
|
||||||
|
.option-config-grid {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, reactive, ref } from 'vue'
|
import { computed, onMounted, reactive, ref } from 'vue'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createManualEntry,
|
createManualEntry,
|
||||||
|
createManualEntryOption,
|
||||||
deleteManualEntry,
|
deleteManualEntry,
|
||||||
|
deleteManualEntryOption,
|
||||||
fetchManualEntries,
|
fetchManualEntries,
|
||||||
|
fetchManualEntryOptions,
|
||||||
updateManualEntry,
|
updateManualEntry,
|
||||||
|
updateManualEntryOption,
|
||||||
type ManualEntryItem,
|
type ManualEntryItem,
|
||||||
|
type ManualEntryOption,
|
||||||
|
type ManualEntryOptionType,
|
||||||
|
type ManualEntryOptions,
|
||||||
} from '@/features/admin/api/adminManualEntry'
|
} from '@/features/admin/api/adminManualEntry'
|
||||||
import { useAdminPaginatedTable } from '@/features/admin/composables/useAdminPaginatedTable'
|
import { useAdminPaginatedTable } from '@/features/admin/composables/useAdminPaginatedTable'
|
||||||
import { useAdminSessionStore } from '@/stores/adminSession'
|
import { useAdminSessionStore } from '@/stores/adminSession'
|
||||||
@@ -21,6 +28,7 @@ const currentAdminName = computed(() => adminSession.nickname || adminSession.us
|
|||||||
const canCreate = computed(() => adminSession.hasPermission('cs_manual_entry:create'))
|
const canCreate = computed(() => adminSession.hasPermission('cs_manual_entry:create'))
|
||||||
const canUpdate = computed(() => adminSession.hasPermission('cs_manual_entry:update'))
|
const canUpdate = computed(() => adminSession.hasPermission('cs_manual_entry:update'))
|
||||||
const canDelete = computed(() => adminSession.hasPermission('cs_manual_entry:delete'))
|
const canDelete = computed(() => adminSession.hasPermission('cs_manual_entry:delete'))
|
||||||
|
const canManageOptions = computed(() => adminSession.hasPermission('cs_manual_entry:option_manage'))
|
||||||
|
|
||||||
const filters = reactive({
|
const filters = reactive({
|
||||||
keyword: '',
|
keyword: '',
|
||||||
@@ -28,8 +36,13 @@ const filters = reactive({
|
|||||||
dateRange: null as string[] | null,
|
dateRange: null as string[] | null,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const options = ref<ManualEntryOptions>({ platforms: [], operators: [] })
|
||||||
|
const optionsLoading = ref(false)
|
||||||
|
|
||||||
const entryForm = reactive({
|
const entryForm = reactive({
|
||||||
entry_no: '',
|
entry_no: '',
|
||||||
|
platform: '',
|
||||||
|
operator: '',
|
||||||
remark: '',
|
remark: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -54,6 +67,21 @@ const {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
void loadOptions()
|
||||||
|
})
|
||||||
|
|
||||||
|
async function loadOptions() {
|
||||||
|
optionsLoading.value = true
|
||||||
|
try {
|
||||||
|
options.value = await fetchManualEntryOptions()
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(readError(error, '获取平台与操作人选项失败'))
|
||||||
|
} finally {
|
||||||
|
optionsLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function resetFilters() {
|
function resetFilters() {
|
||||||
filters.keyword = ''
|
filters.keyword = ''
|
||||||
filters.entry_no = ''
|
filters.entry_no = ''
|
||||||
@@ -86,10 +114,14 @@ async function handleCreate() {
|
|||||||
try {
|
try {
|
||||||
const result = await createManualEntry({
|
const result = await createManualEntry({
|
||||||
entry_no: entryNo,
|
entry_no: entryNo,
|
||||||
|
platform: entryForm.platform,
|
||||||
|
operator: entryForm.operator,
|
||||||
remark: entryForm.remark,
|
remark: entryForm.remark,
|
||||||
})
|
})
|
||||||
ElMessage.success(`编号 ${result.entry.entry_no} 已登记到【${result.entry.admin_name}】`)
|
ElMessage.success(`编号 ${result.entry.entry_no} 已登记到【${result.entry.admin_name}】`)
|
||||||
entryForm.entry_no = ''
|
entryForm.entry_no = ''
|
||||||
|
entryForm.platform = ''
|
||||||
|
entryForm.operator = ''
|
||||||
entryForm.remark = ''
|
entryForm.remark = ''
|
||||||
currentPage.value = 1
|
currentPage.value = 1
|
||||||
await loadEntries()
|
await loadEntries()
|
||||||
@@ -104,11 +136,35 @@ async function handleCreate() {
|
|||||||
const editVisible = ref(false)
|
const editVisible = ref(false)
|
||||||
const editSubmitting = ref(false)
|
const editSubmitting = ref(false)
|
||||||
const editingEntry = ref<ManualEntryItem | null>(null)
|
const editingEntry = ref<ManualEntryItem | null>(null)
|
||||||
const editForm = reactive({ entry_no: '', remark: '' })
|
const editForm = reactive({ entry_no: '', platform: '', operator: '', remark: '' })
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 历史记录里的平台/操作人可能已被后台删除选项,
|
||||||
|
* 这里把当前值补进下拉,保证编辑时能正常显示与保留。
|
||||||
|
*/
|
||||||
|
function withCurrentValue(list: ManualEntryOption[], current: string) {
|
||||||
|
const items: { id: number | string; name: string }[] = list.map(item => ({
|
||||||
|
id: item.id,
|
||||||
|
name: item.name,
|
||||||
|
}))
|
||||||
|
if (current && !items.some(item => item.name === current)) {
|
||||||
|
items.unshift({ id: `current-${current}`, name: current })
|
||||||
|
}
|
||||||
|
return items
|
||||||
|
}
|
||||||
|
|
||||||
|
const editPlatformOptions = computed(() =>
|
||||||
|
withCurrentValue(options.value.platforms, editForm.platform)
|
||||||
|
)
|
||||||
|
const editOperatorOptions = computed(() =>
|
||||||
|
withCurrentValue(options.value.operators, editForm.operator)
|
||||||
|
)
|
||||||
|
|
||||||
function openEdit(row: ManualEntryItem) {
|
function openEdit(row: ManualEntryItem) {
|
||||||
editingEntry.value = row
|
editingEntry.value = row
|
||||||
editForm.entry_no = row.entry_no
|
editForm.entry_no = row.entry_no
|
||||||
|
editForm.platform = row.platform || ''
|
||||||
|
editForm.operator = row.operator || ''
|
||||||
editForm.remark = row.remark
|
editForm.remark = row.remark
|
||||||
editVisible.value = true
|
editVisible.value = true
|
||||||
}
|
}
|
||||||
@@ -124,6 +180,8 @@ async function handleUpdate() {
|
|||||||
try {
|
try {
|
||||||
await updateManualEntry(editingEntry.value.id, {
|
await updateManualEntry(editingEntry.value.id, {
|
||||||
entry_no: entryNo,
|
entry_no: entryNo,
|
||||||
|
platform: editForm.platform,
|
||||||
|
operator: editForm.operator,
|
||||||
remark: editForm.remark,
|
remark: editForm.remark,
|
||||||
})
|
})
|
||||||
ElMessage.success('录单已更新')
|
ElMessage.success('录单已更新')
|
||||||
@@ -154,6 +212,86 @@ async function handleDelete(row: ManualEntryItem) {
|
|||||||
ElMessage.error(readError(error, '删除失败'))
|
ElMessage.error(readError(error, '删除失败'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- 平台 / 操作人配置 ----------
|
||||||
|
const configVisible = ref(false)
|
||||||
|
const optionSubmitting = ref(false)
|
||||||
|
const newPlatformName = ref('')
|
||||||
|
const newOperatorName = ref('')
|
||||||
|
|
||||||
|
function openConfig() {
|
||||||
|
configVisible.value = true
|
||||||
|
if (!options.value.platforms.length && !options.value.operators.length) {
|
||||||
|
void loadOptions()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleAddOption(type: ManualEntryOptionType) {
|
||||||
|
const name = (type === 'platform' ? newPlatformName.value : newOperatorName.value).trim()
|
||||||
|
if (!name) {
|
||||||
|
ElMessage.warning('请输入名称')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
optionSubmitting.value = true
|
||||||
|
try {
|
||||||
|
await createManualEntryOption({ type, name })
|
||||||
|
if (type === 'platform') newPlatformName.value = ''
|
||||||
|
else newOperatorName.value = ''
|
||||||
|
ElMessage.success('已添加')
|
||||||
|
await loadOptions()
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(readError(error, '添加失败'))
|
||||||
|
} finally {
|
||||||
|
optionSubmitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleRenameOption(item: ManualEntryOption) {
|
||||||
|
let input: string
|
||||||
|
try {
|
||||||
|
const result = await ElMessageBox.prompt('请输入新的名称', '重命名', {
|
||||||
|
inputValue: item.name,
|
||||||
|
inputPattern: /\S/,
|
||||||
|
inputErrorMessage: '名称不能为空',
|
||||||
|
confirmButtonText: '保存',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
})
|
||||||
|
input = result.value
|
||||||
|
} catch {
|
||||||
|
return // 用户取消
|
||||||
|
}
|
||||||
|
const name = input.trim()
|
||||||
|
if (!name || name === item.name) return
|
||||||
|
optionSubmitting.value = true
|
||||||
|
try {
|
||||||
|
await updateManualEntryOption(item.id, name)
|
||||||
|
ElMessage.success('已重命名')
|
||||||
|
await loadOptions()
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(readError(error, '重命名失败'))
|
||||||
|
} finally {
|
||||||
|
optionSubmitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleRemoveOption(item: ManualEntryOption) {
|
||||||
|
try {
|
||||||
|
await ElMessageBox.confirm(
|
||||||
|
`确定删除${item.type === 'platform' ? '平台' : '操作人'}【${item.name}】吗?历史录单记录不受影响。`,
|
||||||
|
'删除确认',
|
||||||
|
{ confirmButtonText: '确认删除', cancelButtonText: '取消', type: 'warning' }
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
return // 用户取消
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await deleteManualEntryOption(item.id)
|
||||||
|
ElMessage.success('已删除')
|
||||||
|
await loadOptions()
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(readError(error, '删除失败'))
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -165,9 +303,14 @@ async function handleDelete(row: ManualEntryItem) {
|
|||||||
<p>
|
<p>
|
||||||
当前登录客服:
|
当前登录客服:
|
||||||
<strong>{{ currentAdminName }}</strong>
|
<strong>{{ currentAdminName }}</strong>
|
||||||
· 输入编号登记到本人名下,记录登记时间,支持查询与修正。
|
· 输入编号登记到本人名下,可选平台与操作人,支持查询与修正。
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="page-header-actions">
|
||||||
|
<el-button v-if="canManageOptions" :loading="optionsLoading" @click="openConfig">
|
||||||
|
配置平台/操作人
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 录单表单 -->
|
<!-- 录单表单 -->
|
||||||
@@ -186,6 +329,40 @@ async function handleDelete(row: ManualEntryItem) {
|
|||||||
@keyup.enter="handleCreate"
|
@keyup.enter="handleCreate"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="平台(可选)">
|
||||||
|
<el-select
|
||||||
|
v-model="entryForm.platform"
|
||||||
|
placeholder="请选择平台"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
class="full-control"
|
||||||
|
:loading="optionsLoading"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in options.platforms"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.name"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="操作人(可选)">
|
||||||
|
<el-select
|
||||||
|
v-model="entryForm.operator"
|
||||||
|
placeholder="请选择操作人"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
class="full-control"
|
||||||
|
:loading="optionsLoading"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in options.operators"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.name"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="备注(可选)">
|
<el-form-item label="备注(可选)">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="entryForm.remark"
|
v-model="entryForm.remark"
|
||||||
@@ -195,11 +372,9 @@ async function handleDelete(row: ManualEntryItem) {
|
|||||||
@keyup.enter="handleCreate"
|
@keyup.enter="handleCreate"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<div class="manual-entry-submit">
|
</div>
|
||||||
<el-button type="primary" :loading="submitting" @click="handleCreate">
|
<div class="manual-entry-submit-row">
|
||||||
提交登记
|
<el-button type="primary" :loading="submitting" @click="handleCreate"> 提交登记 </el-button>
|
||||||
</el-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -215,7 +390,7 @@ async function handleDelete(row: ManualEntryItem) {
|
|||||||
/>
|
/>
|
||||||
<el-input
|
<el-input
|
||||||
v-model="filters.keyword"
|
v-model="filters.keyword"
|
||||||
placeholder="按编号 / 客服名 / 登录名模糊查询"
|
placeholder="按编号 / 客服名 / 登录名 / 平台 / 操作人模糊查询"
|
||||||
clearable
|
clearable
|
||||||
class="filter-keyword"
|
class="filter-keyword"
|
||||||
@keyup.enter="applySearch"
|
@keyup.enter="applySearch"
|
||||||
@@ -235,11 +410,17 @@ async function handleDelete(row: ManualEntryItem) {
|
|||||||
|
|
||||||
<el-table v-loading="loading" class="table-panel" :data="entries">
|
<el-table v-loading="loading" class="table-panel" :data="entries">
|
||||||
<el-table-column prop="id" label="ID" width="80" />
|
<el-table-column prop="id" label="ID" width="80" />
|
||||||
<el-table-column prop="entry_no" label="编号" min-width="160">
|
<el-table-column prop="entry_no" label="编号" width="160">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<span class="mono-entry-no">{{ row.entry_no }}</span>
|
<span class="mono-entry-no">{{ row.entry_no }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column prop="platform" label="平台" min-width="120">
|
||||||
|
<template #default="{ row }">{{ row.platform || '-' }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column prop="operator" label="操作人" min-width="120">
|
||||||
|
<template #default="{ row }">{{ row.operator || '-' }}</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column prop="admin_name" label="客服" min-width="120">
|
<el-table-column prop="admin_name" label="客服" min-width="120">
|
||||||
<template #default="{ row }">{{ row.admin_name || row.admin_username || '-' }}</template>
|
<template #default="{ row }">{{ row.admin_name || row.admin_username || '-' }}</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
@@ -285,6 +466,38 @@ async function handleDelete(row: ManualEntryItem) {
|
|||||||
clearable
|
clearable
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="平台">
|
||||||
|
<el-select
|
||||||
|
v-model="editForm.platform"
|
||||||
|
placeholder="请选择平台"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
class="full-control"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in editPlatformOptions"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.name"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="操作人">
|
||||||
|
<el-select
|
||||||
|
v-model="editForm.operator"
|
||||||
|
placeholder="请选择操作人"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
class="full-control"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in editOperatorOptions"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.name"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="备注">
|
<el-form-item label="备注">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="editForm.remark"
|
v-model="editForm.remark"
|
||||||
@@ -299,6 +512,91 @@ async function handleDelete(row: ManualEntryItem) {
|
|||||||
<el-button type="primary" :loading="editSubmitting" @click="handleUpdate">保存</el-button>
|
<el-button type="primary" :loading="editSubmitting" @click="handleUpdate">保存</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
|
<!-- 平台 / 操作人配置弹窗 -->
|
||||||
|
<el-dialog
|
||||||
|
v-model="configVisible"
|
||||||
|
title="配置平台与操作人"
|
||||||
|
width="720px"
|
||||||
|
destroy-on-close
|
||||||
|
class="manual-entry-config-dialog"
|
||||||
|
>
|
||||||
|
<p class="option-config-tip">
|
||||||
|
这里维护的可选项会出现在录单表单的下拉中;删除选项不会影响已登记的历史记录。
|
||||||
|
</p>
|
||||||
|
<div class="option-config-grid">
|
||||||
|
<section class="option-config-panel">
|
||||||
|
<header class="option-config-title">平台</header>
|
||||||
|
<div class="option-config-add">
|
||||||
|
<el-input
|
||||||
|
v-model="newPlatformName"
|
||||||
|
placeholder="新增平台名称"
|
||||||
|
maxlength="64"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleAddOption('platform')"
|
||||||
|
/>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
:loading="optionSubmitting"
|
||||||
|
@click="handleAddOption('platform')"
|
||||||
|
>
|
||||||
|
添加
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
<ul class="option-config-list">
|
||||||
|
<li v-for="item in options.platforms" :key="item.id">
|
||||||
|
<span class="option-config-name">{{ item.name }}</span>
|
||||||
|
<span class="option-config-actions">
|
||||||
|
<el-button link type="primary" size="small" @click="handleRenameOption(item)">
|
||||||
|
重命名
|
||||||
|
</el-button>
|
||||||
|
<el-button link type="danger" size="small" @click="handleRemoveOption(item)">
|
||||||
|
删除
|
||||||
|
</el-button>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<p v-if="!options.platforms.length" class="option-config-empty">暂无平台,请先添加</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="option-config-panel">
|
||||||
|
<header class="option-config-title">操作人</header>
|
||||||
|
<div class="option-config-add">
|
||||||
|
<el-input
|
||||||
|
v-model="newOperatorName"
|
||||||
|
placeholder="新增操作人名称"
|
||||||
|
maxlength="64"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleAddOption('operator')"
|
||||||
|
/>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
:loading="optionSubmitting"
|
||||||
|
@click="handleAddOption('operator')"
|
||||||
|
>
|
||||||
|
添加
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
<ul class="option-config-list">
|
||||||
|
<li v-for="item in options.operators" :key="item.id">
|
||||||
|
<span class="option-config-name">{{ item.name }}</span>
|
||||||
|
<span class="option-config-actions">
|
||||||
|
<el-button link type="primary" size="small" @click="handleRenameOption(item)">
|
||||||
|
重命名
|
||||||
|
</el-button>
|
||||||
|
<el-button link type="danger" size="small" @click="handleRemoveOption(item)">
|
||||||
|
删除
|
||||||
|
</el-button>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<p v-if="!options.operators.length" class="option-config-empty">暂无操作人,请先添加</p>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
<template #footer>
|
||||||
|
<el-button type="primary" @click="configVisible = false">关闭</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user