Skip to content

Commit 3817bf7

Browse files
committed
perf: 优化提交审核成功的节点优化
1 parent 8112609 commit 3817bf7

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

src/constants/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Viewport } from 'puppeteer'
2+
13
export const WEIXIN_URL = 'https://mp.weixin.qq.com/'
24

35
export enum PLATFORM {
@@ -9,3 +11,5 @@ export enum ACTION {
911
REVIEW,
1012
RELEASE,
1113
}
14+
15+
export const VIEWPORT: Viewport = { width: 1920, height: 1080, deviceScaleFactor: 1.5 }

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function main() {
3737
)
3838

3939
if (result.platform === PLATFORM.WEIXIN)
40-
await weixinRobot()
40+
await weixinRobot(result.action as ACTION)
4141
else
4242
console.log(bgGreen('正在开发中...'))
4343
}

src/weixin/index.ts

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { bgLightGreen, green } from 'kolorist'
22
import type { Browser, Page } from 'puppeteer'
33
import puppeteer from 'puppeteer'
4-
import { WEIXIN_URL } from '../constants'
4+
import { ACTION, VIEWPORT, WEIXIN_URL } from '../constants'
55
import { pathResolve, showQrCodeToTerminal, sleep } from '../utils'
66

77
let browser: Browser
@@ -14,7 +14,7 @@ export async function getLoginScanCode() {
1414
console.log(green('正在获取登录二维码...'))
1515
browser = await puppeteer.launch({ headless: false })
1616
page = await browser.newPage()
17-
await page.setViewport({ width: 1920, height: 1080, deviceScaleFactor: 1.5 })
17+
await page.setViewport(VIEWPORT)
1818
await page.goto(WEIXIN_URL)
1919
const imgSelector = '.login_frame.input_login'
2020
const loginCode = await page.waitForSelector(imgSelector)
@@ -92,6 +92,7 @@ export async function jumpToConfirmPage() {
9292
break
9393
}
9494
}
95+
void page.setViewport(VIEWPORT)
9596
if (!flag)
9697
throw new Error('获取提交审核页面失败')
9798
}
@@ -105,12 +106,31 @@ export async function toSubmitAudit() {
105106
if (!submitBtn)
106107
throw new Error('获取提交审核失败')
107108
await submitBtn.click()
108-
console.log(bgLightGreen('提交审核成功!'))
109+
await page.waitForSelector('.msg_icon_wrp .icon_msg.success')
110+
const msg = await page.evaluate(() => {
111+
return document.querySelector('.msg_content')?.innerHTML
112+
})
113+
if (msg?.includes('已提交审核'))
114+
console.log(bgLightGreen('提交审核成功!'))
115+
else
116+
throw new Error('提交审核失败')
109117
}
110118

111-
export default async function weixinRobot() {
119+
/**
120+
* 去发布
121+
*/
122+
export async function toRelease() {
123+
console.log('正在开发中...')
124+
}
125+
126+
export default async function weixinRobot(action: ACTION) {
112127
await getLoginScanCode()
113128
await jumpToVersions()
114-
await jumpToConfirmPage()
115-
await toSubmitAudit()
129+
if (action === ACTION.REVIEW) {
130+
await jumpToConfirmPage()
131+
await toSubmitAudit()
132+
}
133+
else {
134+
await toRelease()
135+
}
116136
}

0 commit comments

Comments
 (0)