优化
This commit is contained in:
@@ -82,6 +82,13 @@ export async function testLingxingConnection(skuCode: string) {
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
|
||||
export async function submitLingxingVerificationCode(code: string) {
|
||||
const response = await http.post<ApiEnvelope<string>, ApiEnvelope<string>>(
|
||||
`${basePath}/verification-code`, { code },
|
||||
)
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
|
||||
export async function updateMojiaSkuSync(id: string, data: {
|
||||
skuCode: string
|
||||
lengthCm: number
|
||||
|
||||
@@ -10,7 +10,7 @@ import AppDialog from '@/shared/components/AppDialog.vue'
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { getApiErrorMessage } from '@/shared/api/http'
|
||||
import {
|
||||
getMojiaSkuSyncConfig, listMojiaSkuSync, retryMojiaSkuSync, testLingxingConnection, updateMojiaSkuSync,
|
||||
getMojiaSkuSyncConfig, listMojiaSkuSync, retryMojiaSkuSync, submitLingxingVerificationCode, testLingxingConnection, updateMojiaSkuSync,
|
||||
type LingxingConnectionTestResult, type MojiaSkuSyncRecord, type MojiaSkuSyncStatus,
|
||||
} from '../api/mojiaSkuSync'
|
||||
|
||||
@@ -31,6 +31,10 @@ const actionId = ref('')
|
||||
const testingConnection = ref(false)
|
||||
const testOpen = ref(false)
|
||||
const testResult = ref<LingxingConnectionTestResult | null>(null)
|
||||
const verificationOpen = ref(false)
|
||||
const verificationCode = ref('')
|
||||
const submittingVerification = ref(false)
|
||||
const pendingVerificationAction = ref<{ type: 'test' } | { type: 'retry', id: string, revision: number } | null>(null)
|
||||
const page = ref(1)
|
||||
const size = ref(20)
|
||||
const form = reactive({ skuCode: '', syncStatus: '' as '' | MojiaSkuSyncStatus })
|
||||
@@ -91,10 +95,38 @@ async function testConnection() {
|
||||
try {
|
||||
testResult.value = await testLingxingConnection(skuCode)
|
||||
testOpen.value = true
|
||||
} catch (cause) { ElMessage.error(getApiErrorMessage(cause, '领星连接测试失败')) }
|
||||
} catch (cause) {
|
||||
const message = getApiErrorMessage(cause, '领星连接测试失败')
|
||||
if (/二次验证码|验证码|安全验证/.test(message)) {
|
||||
pendingVerificationAction.value = { type: 'test' }
|
||||
verificationOpen.value = true
|
||||
}
|
||||
ElMessage.error(message)
|
||||
}
|
||||
finally { testingConnection.value = false }
|
||||
}
|
||||
|
||||
async function submitVerification() {
|
||||
if (!verificationCode.value.trim()) { ElMessage.warning('请输入验证码'); return }
|
||||
submittingVerification.value = true
|
||||
try {
|
||||
await submitLingxingVerificationCode(verificationCode.value.trim())
|
||||
const pending = pendingVerificationAction.value
|
||||
verificationCode.value = ''
|
||||
verificationOpen.value = false
|
||||
pendingVerificationAction.value = null
|
||||
await load()
|
||||
ElMessage.success('验证码已提交,正在继续原操作')
|
||||
if (pending?.type === 'test') {
|
||||
await testConnection()
|
||||
} else if (pending?.type === 'retry') {
|
||||
const row = rows.value.find((item) => item.id === pending.id)
|
||||
if (row) await retry(row, false)
|
||||
}
|
||||
} catch (cause) { ElMessage.error(getApiErrorMessage(cause, '验证码提交失败')) }
|
||||
finally { submittingVerification.value = false }
|
||||
}
|
||||
|
||||
function openEdit(row: MojiaSkuSyncRecord) {
|
||||
editing.value = row
|
||||
Object.assign(editForm, { skuCode: row.skuCode, lengthCm: row.lengthCm, widthCm: row.widthCm, heightCm: row.heightCm, weightKg: row.weightKg, revision: row.revision })
|
||||
@@ -117,13 +149,26 @@ async function saveEdit() {
|
||||
finally { actionId.value = '' }
|
||||
}
|
||||
|
||||
async function retry(row: MojiaSkuSyncRecord) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认重新推送 SKU「${row.skuCode}」的最新测量值?`, '重新推送领星', { type: 'warning', confirmButtonText: '重新推送', cancelButtonText: '取消', customClass: 'admin-density-confirm' })
|
||||
} catch { return }
|
||||
async function retry(row: MojiaSkuSyncRecord, confirm = true) {
|
||||
if (confirm) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认重新推送 SKU「${row.skuCode}」的最新测量值?`, '重新推送领星', { type: 'warning', confirmButtonText: '重新推送', cancelButtonText: '取消', customClass: 'admin-density-confirm' })
|
||||
} catch { return }
|
||||
}
|
||||
actionId.value = row.id
|
||||
try { await retryMojiaSkuSync(row.id, row.revision); ElMessage.success('已进入待同步队列'); await load() }
|
||||
catch (cause) { ElMessage.error(getApiErrorMessage(cause, '重新推送失败')) }
|
||||
try {
|
||||
const result = await retryMojiaSkuSync(row.id, row.revision)
|
||||
ElMessage.success(result.syncStatus === 'SUCCESS' ? '已成功推送到领星' : '推送失败,详情已记录')
|
||||
await load()
|
||||
}
|
||||
catch (cause) {
|
||||
const message = getApiErrorMessage(cause, '重新推送失败')
|
||||
if (/二次验证码|验证码|安全验证/.test(message)) {
|
||||
pendingVerificationAction.value = { type: 'retry', id: row.id, revision: row.revision }
|
||||
verificationOpen.value = true
|
||||
}
|
||||
ElMessage.error(message)
|
||||
}
|
||||
finally { actionId.value = '' }
|
||||
}
|
||||
|
||||
@@ -194,6 +239,10 @@ onMounted(() => { void Promise.all([loadConfig(), load()]) })
|
||||
</el-table>
|
||||
</div>
|
||||
</AppDialog>
|
||||
<AppDialog v-model="verificationOpen" class="admin-density-dialog" title="领星二次验证" width="min(460px, calc(100vw - 28px))" confirm-text="提交验证码" :confirm-loading="submittingVerification" @confirm="submitVerification">
|
||||
<el-alert type="warning" :closable="false" title="领星要求二次验证,请在验证码发送到手机、邮箱或验证器后输入。" />
|
||||
<el-form label-position="top" class="verification-form"><el-form-item label="验证码"><el-input v-model.trim="verificationCode" maxlength="16" autocomplete="one-time-code" @keyup.enter="submitVerification" /></el-form-item></el-form>
|
||||
</AppDialog>
|
||||
</AdminPage>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user