forked from natuka/web.puabadge.com
修改:首页不用再默认请求url接口
This commit is contained in:
1 parent
73971e4a08
commit
e2afe86ea3
1 file changed
+26
-58
+26
-58
@@ -68,7 +68,7 @@
|
||||
<button
|
||||
class="btn-primary"
|
||||
type="button"
|
||||
:disabled="submitting || orderLocked || buttonDisabled"
|
||||
:disabled="submitting || orderLocked"
|
||||
@click="onSubmit"
|
||||
>
|
||||
{{
|
||||
@@ -86,11 +86,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { showToast } from 'vant'
|
||||
import * as badgeApi from '@/api/badge'
|
||||
import * as douyinApi from '@/api/douyin'
|
||||
import { douyinConfig as config } from '@/config/douyin'
|
||||
import { preloadLogoCloud } from './components/image-point-cloud/logo-cloud-cache'
|
||||
import DyNavBar from './components/DyNavBar.vue'
|
||||
@@ -108,13 +107,6 @@ const showEffect = ref(false)
|
||||
const orderStat = ref<any>({})
|
||||
const orderLocked = ref(false)
|
||||
const lockReason = ref('')
|
||||
const checkingLock = ref(false)
|
||||
|
||||
const buttonDisabled = computed(() => checkingLock.value)
|
||||
|
||||
function isSubmittedBizError(msg: string) {
|
||||
return /已提交制作|不能继续上传|不能继续生图/.test(String(msg || ''))
|
||||
}
|
||||
|
||||
function markOrderSubmitted(reason?: string) {
|
||||
orderLocked.value = true
|
||||
@@ -122,6 +114,19 @@ function markOrderSubmitted(reason?: string) {
|
||||
sessionStorage.setItem(SUBMITTED_KEY, '1')
|
||||
}
|
||||
|
||||
function applyOrderLock(res: any) {
|
||||
orderStat.value = res || {}
|
||||
// order_count > 0 表示已提交制作,锁定上传/生图
|
||||
if (res && Number(res.order_count) > 0) {
|
||||
markOrderSubmitted(config.messages.orderSubmitted || SUBMITTED_MSG)
|
||||
return
|
||||
}
|
||||
if (res && res.remain_count != null && Number(res.remain_count) <= 0) {
|
||||
orderLocked.value = true
|
||||
lockReason.value = config.messages.noRemain
|
||||
}
|
||||
}
|
||||
|
||||
function goRecords() {
|
||||
router.push(config.routes.records)
|
||||
}
|
||||
@@ -136,43 +141,12 @@ function triggerPick() {
|
||||
|
||||
function getOrderStat() {
|
||||
return badgeApi.getOrderStat({}).then((res: any) => {
|
||||
orderStat.value = res || {}
|
||||
// 剩余次数用尽时同样不可再上传生图
|
||||
if (res && res.remain_count != null && Number(res.remain_count) <= 0) {
|
||||
orderLocked.value = true
|
||||
lockReason.value = config.messages.noRemain
|
||||
}
|
||||
applyOrderLock(res)
|
||||
}).catch(() => {
|
||||
// 抖音链路可不依赖该接口,失败时不阻断上传
|
||||
})
|
||||
}
|
||||
|
||||
/** 轻量探测:已提交制作的订单签发上传地址会失败 */
|
||||
async function probeUploadAllowed() {
|
||||
if (sessionStorage.getItem(SUBMITTED_KEY) === '1') {
|
||||
markOrderSubmitted()
|
||||
return false
|
||||
}
|
||||
checkingLock.value = true
|
||||
try {
|
||||
await douyinApi.getUploadUrl({
|
||||
filename: '_probe.jpg',
|
||||
content_type: 'image/jpeg',
|
||||
})
|
||||
return true
|
||||
} catch (err: any) {
|
||||
const msg = err?.message || ''
|
||||
if (isSubmittedBizError(msg)) {
|
||||
markOrderSubmitted(msg)
|
||||
return false
|
||||
}
|
||||
// 其它错误不在首页拦截,交给后续流程
|
||||
return true
|
||||
} finally {
|
||||
checkingLock.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onFileChange(e: Event) {
|
||||
const input = e.target as HTMLInputElement
|
||||
const file = input.files?.[0]
|
||||
@@ -206,8 +180,8 @@ function onFileChange(e: Event) {
|
||||
}
|
||||
}
|
||||
|
||||
async function onSubmit() {
|
||||
if (submitting.value || checkingLock.value) return
|
||||
function onSubmit() {
|
||||
if (submitting.value) return
|
||||
if (orderLocked.value) {
|
||||
showToast(lockReason.value || SUBMITTED_MSG)
|
||||
return
|
||||
@@ -216,20 +190,18 @@ async function onSubmit() {
|
||||
showToast(config.messages.pleaseUpload)
|
||||
return
|
||||
}
|
||||
if (Number(orderStat.value.order_count) > 0) {
|
||||
markOrderSubmitted()
|
||||
showToast(lockReason.value || SUBMITTED_MSG)
|
||||
return
|
||||
}
|
||||
if (orderStat.value.remain_count != null && Number(orderStat.value.remain_count) <= 0) {
|
||||
showToast(config.messages.noRemain)
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
const allowed = await probeUploadAllowed()
|
||||
if (!allowed) {
|
||||
submitting.value = false
|
||||
showToast(lockReason.value || SUBMITTED_MSG)
|
||||
return
|
||||
}
|
||||
|
||||
// 先跳等待页,后台再上传/生图(不弹成功失败 toast)
|
||||
submitting.value = true
|
||||
setPendingUpload(photoFile.value, photoPreview.value)
|
||||
sessionStorage.setItem('douyin_source_preview', photoPreview.value)
|
||||
router.push({
|
||||
@@ -239,15 +211,11 @@ async function onSubmit() {
|
||||
submitting.value = false
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
onMounted(() => {
|
||||
if (sessionStorage.getItem(SUBMITTED_KEY) === '1') {
|
||||
markOrderSubmitted()
|
||||
}
|
||||
await getOrderStat()
|
||||
// 进首页即探测,已提交订单直接锁住按钮,避免再进等待页
|
||||
if (!orderLocked.value) {
|
||||
await probeUploadAllowed()
|
||||
}
|
||||
getOrderStat()
|
||||
// 预采样 Logo 点云,进入等待页可立刻上屏
|
||||
preloadLogoCloud().catch(() => {})
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user