优化tk版私信开启流程

This commit is contained in:
2026-04-24 14:04:38 +08:00
parent 0e79f6297b
commit fdc87fa88a

View File

@@ -13,8 +13,8 @@
class="flex items-center gap-2 rounded-lg bg-gradient-to-r from-emerald-500 to-teal-500 px-4 py-2 text-sm text-white shadow-sm transition-all hover:from-emerald-600 hover:to-teal-600 disabled:cursor-not-allowed disabled:opacity-60"> class="flex items-center gap-2 rounded-lg bg-gradient-to-r from-emerald-500 to-teal-500 px-4 py-2 text-sm text-white shadow-sm transition-all hover:from-emerald-600 hover:to-teal-600 disabled:cursor-not-allowed disabled:opacity-60">
<span>{{ isPreparing ? '预热中...' : '预热视图' }}</span> <span>{{ isPreparing ? '预热中...' : '预热视图' }}</span>
</button> </button>
<button @click="openBrowserView" <button @click="openBrowserView" :disabled="isPreparing || !isElectronEnv"
class="flex items-center gap-2 rounded-lg bg-gradient-to-r from-blue-500 to-cyan-500 px-4 py-2 text-sm text-white shadow-sm transition-all hover:from-blue-600 hover:to-cyan-600"> class="flex items-center gap-2 rounded-lg bg-gradient-to-r from-blue-500 to-cyan-500 px-4 py-2 text-sm text-white shadow-sm transition-all hover:from-blue-600 hover:to-cyan-600 disabled:cursor-not-allowed disabled:opacity-60">
<span>打开浏览器视图</span> <span>打开浏览器视图</span>
</button> </button>
</div> </div>
@@ -355,6 +355,12 @@ function buildStartPayload() {
} }
function ensureElectronCapability(methodName) { if (!isElectronEnv || !window.electronAPI?.[methodName]) { ElMessage.error('当前环境不支持该功能'); return false } return true } function ensureElectronCapability(methodName) { if (!isElectronEnv || !window.electronAPI?.[methodName]) { ElMessage.error('当前环境不支持该功能'); return false } return true }
function invalidatePreparedState(nextStatus = '配置已变更,请重新预热视图') { preparedConfigKey.value = ''; loginConfirmed.value = false; if (!statusText.value.includes('运行')) statusText.value = nextStatus } function invalidatePreparedState(nextStatus = '配置已变更,请重新预热视图') { preparedConfigKey.value = ''; loginConfirmed.value = false; if (!statusText.value.includes('运行')) statusText.value = nextStatus }
async function showBrowserWorkspace(viewId, fallbackStatusText) {
pageMode.value = 'browser'
await window.electronAPI.switchToView(viewId)
await window.electronAPI.showViews()
if (!statusText.value.includes('运行')) statusText.value = fallbackStatusText
}
function handleGreetingConfirm(data) { configForm.prologueList = { yolo: data.sentences || [], ...(data.translations || {}) }; configForm.needTranslate = Boolean(data.needTranslate); showGreetingDialog.value = false; invalidatePreparedState(); void saveSharedConfig() } function handleGreetingConfirm(data) { configForm.prologueList = { yolo: data.sentences || [], ...(data.translations || {}) }; configForm.needTranslate = Boolean(data.needTranslate); showGreetingDialog.value = false; invalidatePreparedState(); void saveSharedConfig() }
function handleSwitchMinutesBlur() { configForm.groupSwitchMinutes = clampMinutes(configForm.groupSwitchMinutes); invalidatePreparedState() } function handleSwitchMinutesBlur() { configForm.groupSwitchMinutes = clampMinutes(configForm.groupSwitchMinutes); invalidatePreparedState() }
function handlePostUserSleepBlur() { configForm.postUserSleepSeconds = clampPositiveSeconds(configForm.postUserSleepSeconds, 6); invalidatePreparedState() } function handlePostUserSleepBlur() { configForm.postUserSleepSeconds = clampPositiveSeconds(configForm.postUserSleepSeconds, 6); invalidatePreparedState() }
@@ -422,10 +428,11 @@ async function handlePrepareViews() {
if (result.currentViewId) activeViewId.value = result.currentViewId if (result.currentViewId) activeViewId.value = result.currentViewId
preparedConfigKey.value = currentPrepareKey.value preparedConfigKey.value = currentPrepareKey.value
await saveSharedConfig() await saveSharedConfig()
// pageMode.value = 'browser' if (pageMode.value === 'config') {
await window.electronAPI.showViews() await window.electronAPI.hideViews()
}
statusText.value = `视图已预热,请先在视图 ${activeViewId.value} 手动登录,再启动脚本` statusText.value = `视图已预热,请先在视图 ${activeViewId.value} 手动登录,再启动脚本`
ElMessage.success('视图预热完成,切换到浏览器视图') ElMessage.success('视图预热完成,切换到浏览器视图')
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : String(error) const message = error instanceof Error ? error.message : String(error)
ElMessage.error(`预热视图失败:${message}`) ElMessage.error(`预热视图失败:${message}`)
@@ -435,15 +442,20 @@ async function handlePrepareViews() {
} }
async function openBrowserView() { async function openBrowserView() {
if (!ensureElectronCapability('switchToView')) return if (!ensureElectronCapability('switchToView')) return
pageMode.value = 'browser' if (isPreparing.value) {
try { ElMessage.warning('视图预热中,请等待预热完成后再打开浏览器视图')
await window.electronAPI.switchToView(activeViewId.value) return
await window.electronAPI.showViews()
if (!statusText.value.includes('运行')) {
statusText.value = hasPreparedViews.value ? `已打开预热视图 ${activeViewId.value},请手动登录后启动脚本` : '当前配置尚未预热,请先返回工作台执行预热视图'
} }
try {
await showBrowserWorkspace(
activeViewId.value,
hasPreparedViews.value
? `已打开预热视图 ${activeViewId.value},请手动登录后启动脚本`
: '当前配置尚未预热,请先返回工作台执行预热视图'
)
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : String(error) const message = error instanceof Error ? error.message : String(error)
pageMode.value = 'config'
ElMessage.error(`打开浏览器视图失败:${message}`) ElMessage.error(`打开浏览器视图失败:${message}`)
} }
} }
@@ -490,8 +502,7 @@ async function handleStart() {
isStarting.value = true isStarting.value = true
try { try {
await saveSharedConfig() await saveSharedConfig()
await window.electronAPI.switchToView(activeViewId.value) await showBrowserWorkspace(activeViewId.value, `已打开预热视图 ${activeViewId.value},请手动登录后启动脚本`)
await window.electronAPI.showViews()
const result = await window.electronAPI.startStandaloneTikTokAutomationAll(buildStartPayload()) const result = await window.electronAPI.startStandaloneTikTokAutomationAll(buildStartPayload())
if (!result?.success) { if (!result?.success) {
statusText.value = '启动失败' statusText.value = '启动失败'