增加前端格式检查配置
This commit is contained in:
@@ -73,11 +73,11 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
selectedSkins,
|
||||
})
|
||||
const uploadedScreenshotCount = computed(
|
||||
() => pricing.screenshotSlots.value.filter((item) => getScreenshotCount(item.key) > 0).length,
|
||||
() => pricing.screenshotSlots.value.filter(item => getScreenshotCount(item.key) > 0).length
|
||||
)
|
||||
const requiredScreenshotCount = ref(0)
|
||||
const canPublishAfterAgreements = computed(
|
||||
() => virtualAssetSaleAgreementChecked.value && sellerAgreementChecked.value,
|
||||
() => virtualAssetSaleAgreementChecked.value && sellerAgreementChecked.value
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
@@ -98,7 +98,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
() => {
|
||||
saveDraft()
|
||||
},
|
||||
{ deep: true },
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
watch(
|
||||
@@ -106,7 +106,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
() => {
|
||||
syncRecommendedDeposit()
|
||||
},
|
||||
{ immediate: true },
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
watch(
|
||||
@@ -114,15 +114,17 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
() => {
|
||||
clearForbiddenQuantityItems()
|
||||
},
|
||||
{ deep: true },
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
watch(
|
||||
[pricing.screenshotSlots, () => form.ban_record],
|
||||
() => {
|
||||
requiredScreenshotCount.value = pricing.screenshotSlots.value.filter((item) => isScreenshotRequired(item)).length
|
||||
requiredScreenshotCount.value = pricing.screenshotSlots.value.filter(item =>
|
||||
isScreenshotRequired(item)
|
||||
).length
|
||||
},
|
||||
{ immediate: true, deep: true },
|
||||
{ immediate: true, deep: true }
|
||||
)
|
||||
|
||||
async function loadPublishOptions() {
|
||||
@@ -186,7 +188,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
quantityModes,
|
||||
screenshotFiles,
|
||||
selectedSkins: selectedSkins.value,
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -256,13 +258,13 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
|
||||
function toggleSkin(skin: string) {
|
||||
selectedSkins.value = selectedSkins.value.includes(skin)
|
||||
? selectedSkins.value.filter((item) => item !== skin)
|
||||
? selectedSkins.value.filter(item => item !== skin)
|
||||
: [...selectedSkins.value, skin]
|
||||
}
|
||||
|
||||
function toggleRegion(region: string) {
|
||||
form.common_regions = form.common_regions.includes(region)
|
||||
? form.common_regions.filter((item) => item !== region)
|
||||
? form.common_regions.filter(item => item !== region)
|
||||
: [...form.common_regions, region]
|
||||
}
|
||||
|
||||
@@ -288,7 +290,9 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
}
|
||||
const uploadFiles = files.slice(0, availableCount)
|
||||
if (files.length > availableCount) {
|
||||
options.notifyWarning(`${getScreenshotLabel(key)}最多上传${getScreenshotLimit(key)}张,本次仅上传${availableCount}张`)
|
||||
options.notifyWarning(
|
||||
`${getScreenshotLabel(key)}最多上传${getScreenshotLimit(key)}张,本次仅上传${availableCount}张`
|
||||
)
|
||||
}
|
||||
uploading.value = true
|
||||
try {
|
||||
@@ -302,7 +306,9 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
options.notifySuccess(uploadFiles.length > 1 ? `已上传${uploadFiles.length}张截图` : '截图已上传')
|
||||
options.notifySuccess(
|
||||
uploadFiles.length > 1 ? `已上传${uploadFiles.length}张截图` : '截图已上传'
|
||||
)
|
||||
} catch (error) {
|
||||
options.notifyError(readError(error, '截图上传失败'))
|
||||
} finally {
|
||||
@@ -353,7 +359,12 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
async function hydrateScreenshotPreviews() {
|
||||
for (const [key, fileURLs] of Object.entries(screenshotFiles)) {
|
||||
for (const [index, fileURL] of fileURLs.entries()) {
|
||||
if (!fileURL || screenshotPreviews[key]?.[index] || !fileURL.startsWith('/api/files/object')) continue
|
||||
if (
|
||||
!fileURL ||
|
||||
screenshotPreviews[key]?.[index] ||
|
||||
!fileURL.startsWith('/api/files/object')
|
||||
)
|
||||
continue
|
||||
try {
|
||||
const blob = await fetchFileBlobByURL(fileURL)
|
||||
setScreenshotPreview(key, index, URL.createObjectURL(blob))
|
||||
@@ -411,14 +422,18 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
}
|
||||
|
||||
function clampAcceleratedSaleRatioInput() {
|
||||
if (!pricing.hasAcceleratedSaleRatioInput() || pricing.calculatedDefaultSaleRatio.value <= 0) return
|
||||
if (!pricing.hasAcceleratedSaleRatioInput() || pricing.calculatedDefaultSaleRatio.value <= 0)
|
||||
return
|
||||
const ratio = Number(form.accelerated_sale_ratio)
|
||||
if (!Number.isFinite(ratio)) {
|
||||
form.accelerated_sale_ratio = ''
|
||||
return
|
||||
}
|
||||
form.accelerated_sale_ratio = roundRatio(
|
||||
Math.min(Math.max(ratio, pricing.calculatedDefaultSaleRatio.value), pricing.maxAcceleratedSaleRatio.value),
|
||||
Math.min(
|
||||
Math.max(ratio, pricing.calculatedDefaultSaleRatio.value),
|
||||
pricing.maxAcceleratedSaleRatio.value
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -460,7 +475,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
options.notifySuccess(
|
||||
listing.status === 'published' && listing.review_status === 'approved'
|
||||
? '发布成功,已上架'
|
||||
: '发布成功,等待后台审核',
|
||||
: '发布成功,等待后台审核'
|
||||
)
|
||||
await router.push(options.submitSuccessPath)
|
||||
} catch (error) {
|
||||
@@ -475,7 +490,8 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
if (pricing.coinMAmount.value <= 0) return '请填写哈夫币/M'
|
||||
if (!form.rank_level) return '请选择段位'
|
||||
if (!form.fire_level) return '请填写烽火等级'
|
||||
if (Number(form.fire_level) < pricing.fireLevelMin.value) return `烽火等级低于${pricing.fireLevelMin.value}级的号无法发布`
|
||||
if (Number(form.fire_level) < pricing.fireLevelMin.value)
|
||||
return `烽火等级低于${pricing.fireLevelMin.value}级的号无法发布`
|
||||
if (!form.season_insurance) return '请选择赛季保险'
|
||||
if (!form.stamina_level) return '请选择体力等级'
|
||||
if (!form.load_level) return '请选择负重等级'
|
||||
@@ -483,27 +499,41 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
if (pricing.hasAcceleratedSaleRatioInput()) {
|
||||
const ratio = Number(form.accelerated_sale_ratio)
|
||||
if (!Number.isFinite(ratio) || ratio <= 0) return '加速出售比例格式不正确'
|
||||
if (pricing.calculatedDefaultSaleRatio.value > 0 && ratio < pricing.calculatedDefaultSaleRatio.value) {
|
||||
if (
|
||||
pricing.calculatedDefaultSaleRatio.value > 0 &&
|
||||
ratio < pricing.calculatedDefaultSaleRatio.value
|
||||
) {
|
||||
return `加速出售比例不能低于默认比例 1:${formatNumber(pricing.calculatedDefaultSaleRatio.value)}`
|
||||
}
|
||||
if (pricing.maxAcceleratedSaleRatio.value > 0 && ratio > pricing.maxAcceleratedSaleRatio.value) {
|
||||
if (
|
||||
pricing.maxAcceleratedSaleRatio.value > 0 &&
|
||||
ratio > pricing.maxAcceleratedSaleRatio.value
|
||||
) {
|
||||
return `加速出售比例不能超过 1:${formatNumber(pricing.maxAcceleratedSaleRatio.value)}`
|
||||
}
|
||||
}
|
||||
if (pricing.banRecordOptions.value.length && !form.ban_record) return '请选择封禁记录'
|
||||
if (form.deposit_amount === '' || Number(form.deposit_amount) < 0) return '请填写押金'
|
||||
if (!Number.isFinite(Number(form.deposit_amount))) return '押金格式不正确'
|
||||
if (pricing.recommendedDepositAmount.value > 0 && Number(form.deposit_amount) < pricing.recommendedDepositAmount.value) {
|
||||
if (
|
||||
pricing.recommendedDepositAmount.value > 0 &&
|
||||
Number(form.deposit_amount) < pricing.recommendedDepositAmount.value
|
||||
) {
|
||||
return `押金不能低于智能推荐 ¥${pricing.recommendedDepositAmount.value}`
|
||||
}
|
||||
if (pricing.calculatedConsumablePrice.value > 0 && Number(form.deposit_amount) <= pricing.calculatedConsumablePrice.value) {
|
||||
if (
|
||||
pricing.calculatedConsumablePrice.value > 0 &&
|
||||
Number(form.deposit_amount) <= pricing.calculatedConsumablePrice.value
|
||||
) {
|
||||
return `押金必须大于额外消耗品总价值 ¥${pricing.calculatedConsumablePrice.value}`
|
||||
}
|
||||
if (!pricing.calculatedFinalPrice.value) return '请完善币数、保险、体力和负重后再发布'
|
||||
if (!Number.isFinite(pricing.calculatedFinalPrice.value)) return '发布价格计算异常,请检查填写内容'
|
||||
if (!Number.isFinite(pricing.calculatedFinalPrice.value))
|
||||
return '发布价格计算异常,请检查填写内容'
|
||||
if (!canPublishAfterAgreements.value) return '请先阅读并勾选两份发布协议'
|
||||
for (const item of pricing.screenshotSlots.value) {
|
||||
if (isScreenshotRequired(item) && getScreenshotCount(item.key) === 0) return `请上传${item.label}`
|
||||
if (isScreenshotRequired(item) && getScreenshotCount(item.key) === 0)
|
||||
return `请上传${item.label}`
|
||||
}
|
||||
for (const item of pricing.quantityItems.value) {
|
||||
if (!pricing.isQuantityItemDisabled(item)) {
|
||||
@@ -558,7 +588,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
season_insurance: form.season_insurance,
|
||||
stamina_level: form.stamina_level,
|
||||
load_level: form.load_level,
|
||||
resources: pricing.quantityItems.value.map((item) => ({
|
||||
resources: pricing.quantityItems.value.map(item => ({
|
||||
key: item.key,
|
||||
label: item.label,
|
||||
price: item.price,
|
||||
@@ -566,7 +596,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
mode: pricing.isQuantityItemDisabled(item) ? '赠送' : quantityModes[item.key] || '收费',
|
||||
})),
|
||||
skin_groups: pricing.skinGroups.value.reduce<Record<string, string[]>>((groups, group) => {
|
||||
groups[group.key] = group.options.filter((skin) => selectedSkins.value.includes(skin))
|
||||
groups[group.key] = group.options.filter(skin => selectedSkins.value.includes(skin))
|
||||
return groups
|
||||
}, {}),
|
||||
screenshot_groups: buildScreenshotGroups(),
|
||||
@@ -614,7 +644,7 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
}
|
||||
|
||||
function getScreenshotLabel(key: ScreenshotKey) {
|
||||
return pricing.screenshotSlots.value.find((item) => item.key === key)?.label || '该截图'
|
||||
return pricing.screenshotSlots.value.find(item => item.key === key)?.label || '该截图'
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user