优化站内信图标和哈夫币发布校验

This commit is contained in:
yml2213
2026-06-27 09:38:08 +08:00
parent 378b7a0b79
commit 5ac12ae5c3
4 changed files with 55 additions and 4 deletions
@@ -2,6 +2,7 @@ package listing
import (
"hfb_sys/backend/pkg/response"
"strings"
"github.com/gin-gonic/gin"
)
@@ -14,7 +15,7 @@ func (h *Handler) Create(c *gin.Context) {
}
var req CreateRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "发布信息不完整")
response.BadRequest(c, listingBindErrorMessage(err))
return
}
item, err := h.service.Create(c.Request.Context(), ownerID, req)
@@ -37,7 +38,7 @@ func (h *Handler) Update(c *gin.Context) {
}
var req UpdateRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "发布信息不完整")
response.BadRequest(c, listingBindErrorMessage(err))
return
}
item, err := h.service.Update(c.Request.Context(), ownerID, id, req)
@@ -48,6 +49,17 @@ func (h *Handler) Update(c *gin.Context) {
response.OK(c, item)
}
func listingBindErrorMessage(err error) string {
if err == nil {
return "发布信息不完整"
}
message := strings.ToLower(err.Error())
if strings.Contains(message, "hafcoinamount") || strings.Contains(message, "haf_coin_amount") {
return "哈夫币数量格式不正确,请重新填写哈夫币/M后再提交"
}
return "发布信息不完整"
}
func (h *Handler) SubmitReview(c *gin.Context) {
ownerID, ok := currentUserID(c)
if !ok {
@@ -0,0 +1,33 @@
package listing
import (
"errors"
"testing"
)
func TestListingBindErrorMessage(t *testing.T) {
tests := []struct {
name string
err error
want string
}{
{
name: "哈夫币字段格式错误",
err: errors.New("json: cannot unmarshal number 197100000.1 into Go struct field CreateRequest.haf_coin_amount of type int64"),
want: "哈夫币数量格式不正确,请重新填写哈夫币/M后再提交",
},
{
name: "普通绑定错误",
err: errors.New("Key: 'CreateRequest.Title' Error:Field validation for 'Title' failed"),
want: "发布信息不完整",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := listingBindErrorMessage(tt.err); got != tt.want {
t.Fatalf("listingBindErrorMessage() = %q, want %q", got, tt.want)
}
})
}
}
@@ -378,7 +378,7 @@ function resolveAvatarURL(url: string | undefined | null) {
<div class="menu-card cell-card">
<van-cell-group :border="false">
<van-cell title="消息中心" icon="chat-o" is-link to="/m/messages" />
<van-cell title="站内信" icon="bell" is-link to="/m/notifications">
<van-cell title="站内信" icon="envelop-o" is-link to="/m/notifications">
<template #value>
<span v-if="notificationUnreadCount > 0" class="unread-cell-value">
{{ notificationUnreadLabel }} 未读
@@ -43,6 +43,7 @@ import {
const draftSaveDelay = 400
const multiScreenshotLimit = 3
const multiScreenshotKeys = new Set(['tencentSecurity', 'skin'])
const coinUnitPerM = 1000000
interface UsePublishFormOptions {
draftKey: string
@@ -684,7 +685,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
server_region: form.server_region,
login_platform: form.login_method,
rank_level: form.rank_level,
haf_coin_amount: pricing.coinMAmount.value * 1000000,
haf_coin_amount: toHafCoinAmount(pricing.coinMAmount.value),
asset_summary: buildAssetSummary(),
screenshot_urls: pricing.screenshotUrls.value,
price_cent: yuanToCent(pricing.calculatedFinalPrice.value),
@@ -728,6 +729,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
function validateForm() {
if (!form.server_region) return '请选择区服'
if (!Number.isFinite(pricing.coinMAmount.value)) return '哈夫币/M格式不正确'
if (pricing.coinMAmount.value <= 0) return '请填写哈夫币/M'
if (!form.rank_level) return '请选择段位'
if (!form.fire_level) return '请填写烽火等级'
@@ -899,6 +901,10 @@ export function usePublishForm(options: UsePublishFormOptions) {
return pricing.screenshotSlots.value.find(item => item.key === key)?.label || '该截图'
}
function toHafCoinAmount(coinM: number) {
return Math.round(coinM * coinUnitPerM)
}
function recordValue(value: unknown): Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value)
? (value as Record<string, unknown>)