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
|
<button
|
||||||
class="btn-primary"
|
class="btn-primary"
|
||||||
type="button"
|
type="button"
|
||||||
:disabled="submitting || orderLocked || buttonDisabled"
|
:disabled="submitting || orderLocked"
|
||||||
@click="onSubmit"
|
@click="onSubmit"
|
||||||
>
|
>
|
||||||
{{
|
{{
|
||||||
@@ -86,11 +86,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { showToast } from 'vant'
|
import { showToast } from 'vant'
|
||||||
import * as badgeApi from '@/api/badge'
|
import * as badgeApi from '@/api/badge'
|
||||||
import * as douyinApi from '@/api/douyin'
|
|
||||||
import { douyinConfig as config } from '@/config/douyin'
|
import { douyinConfig as config } from '@/config/douyin'
|
||||||
import { preloadLogoCloud } from './components/image-point-cloud/logo-cloud-cache'
|
import { preloadLogoCloud } from './components/image-point-cloud/logo-cloud-cache'
|
||||||
import DyNavBar from './components/DyNavBar.vue'
|
import DyNavBar from './components/DyNavBar.vue'
|
||||||
@@ -108,13 +107,6 @@ const showEffect = ref(false)
|
|||||||
const orderStat = ref<any>({})
|
const orderStat = ref<any>({})
|
||||||
const orderLocked = ref(false)
|
const orderLocked = ref(false)
|
||||||
const lockReason = ref('')
|
const lockReason = ref('')
|
||||||
const checkingLock = ref(false)
|
|
||||||
|
|
||||||
const buttonDisabled = computed(() => checkingLock.value)
|
|
||||||
|
|
||||||
function isSubmittedBizError(msg: string) {
|
|
||||||
return /已提交制作|不能继续上传|不能继续生图/.test(String(msg || ''))
|
|
||||||
}
|
|
||||||
|
|
||||||
function markOrderSubmitted(reason?: string) {
|
function markOrderSubmitted(reason?: string) {
|
||||||
orderLocked.value = true
|
orderLocked.value = true
|
||||||
@@ -122,6 +114,19 @@ function markOrderSubmitted(reason?: string) {
|
|||||||
sessionStorage.setItem(SUBMITTED_KEY, '1')
|
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() {
|
function goRecords() {
|
||||||
router.push(config.routes.records)
|
router.push(config.routes.records)
|
||||||
}
|
}
|
||||||
@@ -136,43 +141,12 @@ function triggerPick() {
|
|||||||
|
|
||||||
function getOrderStat() {
|
function getOrderStat() {
|
||||||
return badgeApi.getOrderStat({}).then((res: any) => {
|
return badgeApi.getOrderStat({}).then((res: any) => {
|
||||||
orderStat.value = res || {}
|
applyOrderLock(res)
|
||||||
// 剩余次数用尽时同样不可再上传生图
|
|
||||||
if (res && res.remain_count != null && Number(res.remain_count) <= 0) {
|
|
||||||
orderLocked.value = true
|
|
||||||
lockReason.value = config.messages.noRemain
|
|
||||||
}
|
|
||||||
}).catch(() => {
|
}).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) {
|
function onFileChange(e: Event) {
|
||||||
const input = e.target as HTMLInputElement
|
const input = e.target as HTMLInputElement
|
||||||
const file = input.files?.[0]
|
const file = input.files?.[0]
|
||||||
@@ -206,8 +180,8 @@ function onFileChange(e: Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onSubmit() {
|
function onSubmit() {
|
||||||
if (submitting.value || checkingLock.value) return
|
if (submitting.value) return
|
||||||
if (orderLocked.value) {
|
if (orderLocked.value) {
|
||||||
showToast(lockReason.value || SUBMITTED_MSG)
|
showToast(lockReason.value || SUBMITTED_MSG)
|
||||||
return
|
return
|
||||||
@@ -216,20 +190,18 @@ async function onSubmit() {
|
|||||||
showToast(config.messages.pleaseUpload)
|
showToast(config.messages.pleaseUpload)
|
||||||
return
|
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) {
|
if (orderStat.value.remain_count != null && Number(orderStat.value.remain_count) <= 0) {
|
||||||
showToast(config.messages.noRemain)
|
showToast(config.messages.noRemain)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
submitting.value = true
|
|
||||||
const allowed = await probeUploadAllowed()
|
|
||||||
if (!allowed) {
|
|
||||||
submitting.value = false
|
|
||||||
showToast(lockReason.value || SUBMITTED_MSG)
|
|
||||||
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({
|
||||||
@@ -239,15 +211,11 @@ async function onSubmit() {
|
|||||||
submitting.value = false
|
submitting.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(() => {
|
||||||
if (sessionStorage.getItem(SUBMITTED_KEY) === '1') {
|
if (sessionStorage.getItem(SUBMITTED_KEY) === '1') {
|
||||||
markOrderSubmitted()
|
markOrderSubmitted()
|
||||||
}
|
}
|
||||||
await getOrderStat()
|
getOrderStat()
|
||||||
// 进首页即探测,已提交订单直接锁住按钮,避免再进等待页
|
|
||||||
if (!orderLocked.value) {
|
|
||||||
await probeUploadAllowed()
|
|
||||||
}
|
|
||||||
// 预采样 Logo 点云,进入等待页可立刻上屏
|
// 预采样 Logo 点云,进入等待页可立刻上屏
|
||||||
preloadLogoCloud().catch(() => {})
|
preloadLogoCloud().catch(() => {})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user