forked from natuka/web.puabadge.com
修改:提交获取是否已提交订单
This commit is contained in:
1 parent
e2afe86ea3
commit
a76b181650
4 files changed
+27
-34
No files matched your search
@@ -87,6 +87,8 @@ export const douyinConfig = {
|
|||||||
selectQuantity: '请选择下单数量',
|
selectQuantity: '请选择下单数量',
|
||||||
orderSubmitted: '本订单号已提交制作,不能继续上传图片或生图',
|
orderSubmitted: '本订单号已提交制作,不能继续上传图片或生图',
|
||||||
orderSubmittedBtn: '订单已提交制作',
|
orderSubmittedBtn: '订单已提交制作',
|
||||||
|
orderStatFail: '订单信息获取失败,暂不可上传生图',
|
||||||
|
orderStatFailBtn: '暂不可上传生图',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,8 +132,6 @@ import ImagePointCloud from './components/ImagePointCloud.vue'
|
|||||||
import DyNavBar from './components/DyNavBar.vue'
|
import DyNavBar from './components/DyNavBar.vue'
|
||||||
import { takePendingUpload } from './pendingUpload'
|
import { takePendingUpload } from './pendingUpload'
|
||||||
|
|
||||||
const SUBMITTED_KEY = 'douyin_order_submitted'
|
|
||||||
|
|
||||||
function isSubmittedBizError(msg: string) {
|
function isSubmittedBizError(msg: string) {
|
||||||
return /已提交制作|不能继续上传|不能继续生图/.test(String(msg || ''))
|
return /已提交制作|不能继续上传|不能继续生图/.test(String(msg || ''))
|
||||||
}
|
}
|
||||||
@@ -404,7 +402,6 @@ async function beginPendingUpload() {
|
|||||||
errorTip.value = msg
|
errorTip.value = msg
|
||||||
// 已提交制作:不停留等待页,标记锁定并回首页
|
// 已提交制作:不停留等待页,标记锁定并回首页
|
||||||
if (isSubmittedBizError(msg)) {
|
if (isSubmittedBizError(msg)) {
|
||||||
sessionStorage.setItem(SUBMITTED_KEY, '1')
|
|
||||||
showToast(msg)
|
showToast(msg)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
router.replace(config.routes.home)
|
router.replace(config.routes.home)
|
||||||
@@ -442,7 +439,6 @@ async function confirmSubmit() {
|
|||||||
imageId.value = res.imageId
|
imageId.value = res.imageId
|
||||||
sessionStorage.setItem('douyin_image_id', res.imageId)
|
sessionStorage.setItem('douyin_image_id', res.imageId)
|
||||||
}
|
}
|
||||||
sessionStorage.setItem(SUBMITTED_KEY, '1')
|
|
||||||
showConfirmModal.value = false
|
showConfirmModal.value = false
|
||||||
router.replace(config.routes.success)
|
router.replace(config.routes.success)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
|||||||
+25
-29
@@ -73,7 +73,11 @@
|
|||||||
>
|
>
|
||||||
{{
|
{{
|
||||||
orderLocked
|
orderLocked
|
||||||
? (lockReason === config.messages.noRemain ? config.messages.noRemain : config.messages.orderSubmittedBtn)
|
? (Number(orderStat.order_count) > 0
|
||||||
|
? config.messages.orderSubmittedBtn
|
||||||
|
: (lockReason === config.messages.noRemain
|
||||||
|
? config.messages.noRemain
|
||||||
|
: config.messages.orderStatFailBtn))
|
||||||
: (photoPreview ? config.messages.startGenerate : config.messages.uploadBtn)
|
: (photoPreview ? config.messages.startGenerate : config.messages.uploadBtn)
|
||||||
}}
|
}}
|
||||||
</button>
|
</button>
|
||||||
@@ -95,7 +99,6 @@ import { preloadLogoCloud } from './components/image-point-cloud/logo-cloud-cach
|
|||||||
import DyNavBar from './components/DyNavBar.vue'
|
import DyNavBar from './components/DyNavBar.vue'
|
||||||
import { setPendingUpload } from './pendingUpload'
|
import { setPendingUpload } from './pendingUpload'
|
||||||
|
|
||||||
const SUBMITTED_KEY = 'douyin_order_submitted'
|
|
||||||
const SUBMITTED_MSG = '本订单号已提交制作,不能继续上传图片或生图'
|
const SUBMITTED_MSG = '本订单号已提交制作,不能继续上传图片或生图'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -108,20 +111,18 @@ const orderStat = ref<any>({})
|
|||||||
const orderLocked = ref(false)
|
const orderLocked = ref(false)
|
||||||
const lockReason = ref('')
|
const lockReason = ref('')
|
||||||
|
|
||||||
function markOrderSubmitted(reason?: string) {
|
/** 仅根据接口 orders/stat 判断,不用本地缓存 */
|
||||||
orderLocked.value = true
|
|
||||||
lockReason.value = reason || SUBMITTED_MSG
|
|
||||||
sessionStorage.setItem(SUBMITTED_KEY, '1')
|
|
||||||
}
|
|
||||||
|
|
||||||
function applyOrderLock(res: any) {
|
function applyOrderLock(res: any) {
|
||||||
orderStat.value = res || {}
|
orderStat.value = res || {}
|
||||||
// order_count > 0 表示已提交制作,锁定上传/生图
|
orderLocked.value = false
|
||||||
if (res && Number(res.order_count) > 0) {
|
lockReason.value = ''
|
||||||
markOrderSubmitted(config.messages.orderSubmitted || SUBMITTED_MSG)
|
// order_count > 0 表示已提交制作
|
||||||
|
if (Number(res?.order_count) > 0) {
|
||||||
|
orderLocked.value = true
|
||||||
|
lockReason.value = config.messages.orderSubmitted || SUBMITTED_MSG
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (res && res.remain_count != null && Number(res.remain_count) <= 0) {
|
if (res?.remain_count != null && Number(res.remain_count) <= 0) {
|
||||||
orderLocked.value = true
|
orderLocked.value = true
|
||||||
lockReason.value = config.messages.noRemain
|
lockReason.value = config.messages.noRemain
|
||||||
}
|
}
|
||||||
@@ -142,8 +143,11 @@ function triggerPick() {
|
|||||||
function getOrderStat() {
|
function getOrderStat() {
|
||||||
return badgeApi.getOrderStat({}).then((res: any) => {
|
return badgeApi.getOrderStat({}).then((res: any) => {
|
||||||
applyOrderLock(res)
|
applyOrderLock(res)
|
||||||
}).catch(() => {
|
}).catch((err: any) => {
|
||||||
// 抖音链路可不依赖该接口,失败时不阻断上传
|
// stat 失败(如 code:-1 没有卡券数据)禁止上传生图
|
||||||
|
orderStat.value = {}
|
||||||
|
orderLocked.value = true
|
||||||
|
lockReason.value = err?.message || config.messages.orderStatFail || '订单信息获取失败,暂不可上传生图'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,28 +184,23 @@ function onFileChange(e: Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSubmit() {
|
async function onSubmit() {
|
||||||
if (submitting.value) return
|
if (submitting.value) return
|
||||||
if (orderLocked.value) {
|
|
||||||
showToast(lockReason.value || SUBMITTED_MSG)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!photoFile.value || !photoPreview.value) {
|
if (!photoFile.value || !photoPreview.value) {
|
||||||
showToast(config.messages.pleaseUpload)
|
showToast(config.messages.pleaseUpload)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (Number(orderStat.value.order_count) > 0) {
|
|
||||||
markOrderSubmitted()
|
submitting.value = true
|
||||||
|
// 提交前重新拉 orders/stat,不依赖本地缓存 / 页面内存旧值
|
||||||
|
await getOrderStat()
|
||||||
|
if (orderLocked.value) {
|
||||||
|
submitting.value = false
|
||||||
showToast(lockReason.value || SUBMITTED_MSG)
|
showToast(lockReason.value || SUBMITTED_MSG)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (orderStat.value.remain_count != null && Number(orderStat.value.remain_count) <= 0) {
|
|
||||||
showToast(config.messages.noRemain)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 先跳等待页,后台再上传/生图(不弹成功失败 toast)
|
// 先跳等待页,后台再上传/生图(不弹成功失败 toast)
|
||||||
submitting.value = true
|
|
||||||
setPendingUpload(photoFile.value, photoPreview.value)
|
setPendingUpload(photoFile.value, photoPreview.value)
|
||||||
sessionStorage.setItem('douyin_source_preview', photoPreview.value)
|
sessionStorage.setItem('douyin_source_preview', photoPreview.value)
|
||||||
router.push({
|
router.push({
|
||||||
@@ -212,9 +211,6 @@ function onSubmit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (sessionStorage.getItem(SUBMITTED_KEY) === '1') {
|
|
||||||
markOrderSubmitted()
|
|
||||||
}
|
|
||||||
getOrderStat()
|
getOrderStat()
|
||||||
// 预采样 Logo 点云,进入等待页可立刻上屏
|
// 预采样 Logo 点云,进入等待页可立刻上屏
|
||||||
preloadLogoCloud().catch(() => {})
|
preloadLogoCloud().catch(() => {})
|
||||||
|
|||||||
@@ -164,7 +164,6 @@ function confirmOrder() {
|
|||||||
imageId.value = res.imageId
|
imageId.value = res.imageId
|
||||||
sessionStorage.setItem('douyin_image_id', res.imageId)
|
sessionStorage.setItem('douyin_image_id', res.imageId)
|
||||||
}
|
}
|
||||||
sessionStorage.setItem('douyin_order_submitted', '1')
|
|
||||||
showConfirmModal.value = false
|
showConfirmModal.value = false
|
||||||
showSuccessToast({
|
showSuccessToast({
|
||||||
message: config.messages.orderSuccess,
|
message: config.messages.orderSuccess,
|
||||||
|
|||||||
Reference in new issue
Block a user