移除了 khhao 平台相关
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export type PlatformTab = 'agiso' | 'khhao' | 'ninetyone' | 'kuaishouEticket' | 'cloudtentacles'
|
||||
export type PlatformTab = 'agiso' | 'ninetyone' | 'kuaishouEticket' | 'cloudtentacles'
|
||||
|
||||
export type EditableDefaults = {
|
||||
messageTemplate: string
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import { showError, showSuccess } from '@/lib/feedback'
|
||||
import {
|
||||
queryAdminKhhaoOrders,
|
||||
saveAdminKhhaoSourceConfig,
|
||||
syncAdminKhhaoOrders,
|
||||
testAdminKhhaoLogin,
|
||||
} from '@/services/admin'
|
||||
import type {
|
||||
AdminKhhaoLoginTestResult,
|
||||
AdminKhhaoOrderQueryResult,
|
||||
AdminKhhaoOrderSyncResult,
|
||||
AdminKhhaoSyncState,
|
||||
} from '@/types/admin'
|
||||
|
||||
export function useAdminKhhaoPlatform() {
|
||||
const khhaoFilePath = ref('')
|
||||
const khhaoStateFilePath = ref('')
|
||||
const khhaoForm = ref({
|
||||
baseUrl: 'https://admin.khhao.com',
|
||||
username: '',
|
||||
password: '',
|
||||
page: 1,
|
||||
limit: 10,
|
||||
maxCaptchaAttempts: 3,
|
||||
autoSyncEnabled: false,
|
||||
autoSyncIntervalMinutes: 3,
|
||||
autoSyncPages: 2,
|
||||
autoSyncPageSize: 20,
|
||||
})
|
||||
const khhaoSaving = ref(false)
|
||||
const khhaoTesting = ref(false)
|
||||
const khhaoQuerying = ref(false)
|
||||
const khhaoSyncing = ref(false)
|
||||
const khhaoResultError = ref('')
|
||||
const khhaoLoginResult = ref<AdminKhhaoLoginTestResult | null>(null)
|
||||
const khhaoQueryResult = ref<AdminKhhaoOrderQueryResult | null>(null)
|
||||
const khhaoSyncResult = ref<AdminKhhaoOrderSyncResult | null>(null)
|
||||
const khhaoAutoSyncState = ref<AdminKhhaoSyncState | null>(null)
|
||||
|
||||
const khhaoStats = computed(() => ({
|
||||
hasCredential: Boolean(khhaoForm.value.username.trim() && khhaoForm.value.password.trim()),
|
||||
queryCount: khhaoQueryResult.value?.itemCount || 0,
|
||||
syncedCount: khhaoAutoSyncState.value?.syncedCount || khhaoSyncResult.value?.syncedCount || 0,
|
||||
ignoredCount: khhaoAutoSyncState.value?.ignoredCount || khhaoSyncResult.value?.ignoredCount || 0,
|
||||
}))
|
||||
|
||||
function hydrateKhhaoConfig(data: {
|
||||
filePath: string
|
||||
stateFilePath: string
|
||||
syncState: AdminKhhaoSyncState
|
||||
source: {
|
||||
baseUrl?: string
|
||||
username?: string
|
||||
password?: string
|
||||
maxCaptchaAttempts?: number
|
||||
autoSync?: {
|
||||
enabled?: boolean
|
||||
intervalMinutes?: number
|
||||
pages?: number
|
||||
pageSize?: number
|
||||
}
|
||||
}
|
||||
}) {
|
||||
khhaoFilePath.value = data.filePath
|
||||
khhaoStateFilePath.value = data.stateFilePath
|
||||
khhaoAutoSyncState.value = data.syncState
|
||||
khhaoForm.value = {
|
||||
baseUrl: data.source.baseUrl || 'https://admin.khhao.com',
|
||||
username: data.source.username || '',
|
||||
password: data.source.password || '',
|
||||
page: 1,
|
||||
limit: 10,
|
||||
maxCaptchaAttempts: data.source.maxCaptchaAttempts || 3,
|
||||
autoSyncEnabled: data.source.autoSync?.enabled === true,
|
||||
autoSyncIntervalMinutes: data.source.autoSync?.intervalMinutes || 3,
|
||||
autoSyncPages: data.source.autoSync?.pages || 2,
|
||||
autoSyncPageSize: data.source.autoSync?.pageSize || 20,
|
||||
}
|
||||
}
|
||||
|
||||
function buildKhhaoPayload() {
|
||||
return {
|
||||
baseUrl: khhaoForm.value.baseUrl.trim() || 'https://admin.khhao.com',
|
||||
username: khhaoForm.value.username.trim(),
|
||||
password: khhaoForm.value.password.trim(),
|
||||
page: Number(khhaoForm.value.page || 1),
|
||||
limit: Number(khhaoForm.value.limit || 10),
|
||||
maxCaptchaAttempts: Number(khhaoForm.value.maxCaptchaAttempts || 3),
|
||||
}
|
||||
}
|
||||
|
||||
function ensureKhhaoCredentials() {
|
||||
if (!khhaoForm.value.username.trim() || !khhaoForm.value.password.trim()) {
|
||||
khhaoResultError.value = '请先填写 khhao 账号和密码'
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async function handleKhhaoSaveSource() {
|
||||
khhaoSaving.value = true
|
||||
khhaoResultError.value = ''
|
||||
|
||||
try {
|
||||
const response = await saveAdminKhhaoSourceConfig({
|
||||
enabled: true,
|
||||
baseUrl: khhaoForm.value.baseUrl.trim() || 'https://admin.khhao.com',
|
||||
username: khhaoForm.value.username.trim(),
|
||||
password: khhaoForm.value.password.trim(),
|
||||
maxCaptchaAttempts: Number(khhaoForm.value.maxCaptchaAttempts || 3),
|
||||
autoSync: {
|
||||
enabled: Boolean(khhaoForm.value.autoSyncEnabled),
|
||||
intervalMinutes: Number(khhaoForm.value.autoSyncIntervalMinutes || 3),
|
||||
pages: Number(khhaoForm.value.autoSyncPages || 2),
|
||||
pageSize: Number(khhaoForm.value.autoSyncPageSize || 20),
|
||||
},
|
||||
})
|
||||
khhaoFilePath.value = response.data.filePath
|
||||
khhaoStateFilePath.value = response.data.stateFilePath
|
||||
khhaoAutoSyncState.value = response.data.syncState
|
||||
showSuccess('khhao 来源配置已保存')
|
||||
} catch (error) {
|
||||
khhaoResultError.value = error instanceof Error ? error.message : 'khhao 来源配置保存失败'
|
||||
showError(khhaoResultError.value)
|
||||
} finally {
|
||||
khhaoSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleKhhaoTestLogin() {
|
||||
if (!ensureKhhaoCredentials()) {
|
||||
return
|
||||
}
|
||||
|
||||
khhaoTesting.value = true
|
||||
khhaoResultError.value = ''
|
||||
|
||||
try {
|
||||
const response = await testAdminKhhaoLogin({
|
||||
...buildKhhaoPayload(),
|
||||
includeImageBase64: false,
|
||||
})
|
||||
khhaoLoginResult.value = response.data
|
||||
showSuccess('khhao 登录测试成功')
|
||||
} catch (error) {
|
||||
khhaoResultError.value = error instanceof Error ? error.message : 'khhao 登录测试失败'
|
||||
showError(khhaoResultError.value)
|
||||
} finally {
|
||||
khhaoTesting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleKhhaoQueryOrders() {
|
||||
if (!ensureKhhaoCredentials()) {
|
||||
return
|
||||
}
|
||||
|
||||
khhaoQuerying.value = true
|
||||
khhaoResultError.value = ''
|
||||
|
||||
try {
|
||||
const response = await queryAdminKhhaoOrders(buildKhhaoPayload())
|
||||
khhaoQueryResult.value = response.data
|
||||
showSuccess(`khhao 订单查询成功,共返回 ${response.data.itemCount} 条`)
|
||||
} catch (error) {
|
||||
khhaoResultError.value = error instanceof Error ? error.message : 'khhao 订单查询失败'
|
||||
showError(khhaoResultError.value)
|
||||
} finally {
|
||||
khhaoQuerying.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleKhhaoSyncOrders() {
|
||||
if (!ensureKhhaoCredentials()) {
|
||||
return
|
||||
}
|
||||
|
||||
khhaoSyncing.value = true
|
||||
khhaoResultError.value = ''
|
||||
|
||||
try {
|
||||
const response = await syncAdminKhhaoOrders(buildKhhaoPayload())
|
||||
khhaoSyncResult.value = response.data
|
||||
showSuccess(`khhao 同步完成:拉取 ${response.data.fetchedCount} 条,成功 ${response.data.syncedCount} 条`)
|
||||
} catch (error) {
|
||||
khhaoResultError.value = error instanceof Error ? error.message : 'khhao 订单同步失败'
|
||||
showError(khhaoResultError.value)
|
||||
} finally {
|
||||
khhaoSyncing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
khhaoFilePath,
|
||||
khhaoStateFilePath,
|
||||
khhaoForm,
|
||||
khhaoSaving,
|
||||
khhaoTesting,
|
||||
khhaoQuerying,
|
||||
khhaoSyncing,
|
||||
khhaoResultError,
|
||||
khhaoLoginResult,
|
||||
khhaoQueryResult,
|
||||
khhaoSyncResult,
|
||||
khhaoAutoSyncState,
|
||||
khhaoStats,
|
||||
hydrateKhhaoConfig,
|
||||
handleKhhaoSaveSource,
|
||||
handleKhhaoTestLogin,
|
||||
handleKhhaoQueryOrders,
|
||||
handleKhhaoSyncOrders,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user