shot-manual.mjs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * 登录后按询价模块截图,供桌面用户手册使用。
  3. */
  4. import { chromium } from 'playwright-core'
  5. import { mkdirSync } from 'node:fs'
  6. import { join } from 'node:path'
  7. const base = process.env.DEMO_URL || 'http://localhost:5173'
  8. const dir = process.env.SHOT_DIR || 'C:\\Users\\Liumouren\\Desktop\\勤务系统2.0用户手册图'
  9. mkdirSync(dir, { recursive: true })
  10. const browser = await chromium.launch({
  11. executablePath: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
  12. headless: true,
  13. })
  14. const page = await browser.newPage({ viewport: { width: 1440, height: 900 } })
  15. async function shot(name, path, wait = 900) {
  16. await page.goto(base + path, { waitUntil: 'domcontentloaded', timeout: 60000 })
  17. await page.waitForTimeout(wait)
  18. await page.screenshot({ path: join(dir, `${name}.png`) })
  19. console.log('ok', name)
  20. }
  21. async function enter(account) {
  22. await page.goto(base + '/login', { waitUntil: 'domcontentloaded', timeout: 60000 })
  23. await page.waitForSelector(`[data-testid="login-${account}"]`, { timeout: 25000 })
  24. await page.waitForTimeout(1800)
  25. await page.click(`[data-testid="login-${account}"]`)
  26. await page.waitForTimeout(2200)
  27. }
  28. try {
  29. await shot('00-home', '/', 700)
  30. await enter('linqm')
  31. await shot('01-login-hq', '/login', 400)
  32. await shot('02-workbench', '/admin/workbench', 1400)
  33. await shot('03-people', '/admin/master?tab=people')
  34. await shot('04-sites', '/admin/master?tab=sites')
  35. await shot('05-contracts', '/admin/master?tab=contracts')
  36. await shot('06-train', '/admin/master?tab=train')
  37. await shot('07-schedule', '/admin/duty?tab=schedule')
  38. await shot('08-attend', '/admin/duty?tab=attend')
  39. await shot('09-ot', '/admin/duty?tab=ot')
  40. await shot('10-split', '/admin/duty?tab=split')
  41. await shot('11-ident', '/admin/duty?tab=ident')
  42. await shot('12-field', '/admin/field')
  43. await shot('13-notice', '/admin/collab?tab=notice')
  44. await shot('14-event', '/admin/collab?tab=event')
  45. await shot('15-alarm', '/admin/collab?tab=alarm')
  46. await shot('16-perform', '/admin/collab?tab=perform')
  47. await shot('17-alert', '/admin/collab?tab=alert')
  48. await shot('18-ledger', '/admin/finance?tab=ledger')
  49. await shot('19-board', '/admin/finance?tab=board')
  50. await shot('20-staffing', '/admin/finance?tab=staffing')
  51. await shot('21-supplier', '/admin/finance?tab=supplier')
  52. await shot('22-users', '/admin/users')
  53. await shot('23-perms', '/admin/perms', 1100)
  54. await shot('24-screen-duty', '/screen/duty', 2000)
  55. await shot('25-screen-prod', '/screen/productivity', 1800)
  56. await shot('26-screen-op', '/screen/operation', 1800)
  57. await shot('27-mp-hq', '/mp/punch', 1200)
  58. const out = page.locator('button.out')
  59. if (await out.count()) await out.click()
  60. await enter('zhoujh')
  61. await shot('28-branch-workbench', '/admin/workbench', 1400)
  62. if (await page.locator('button.out').count()) await page.locator('button.out').click()
  63. await enter('sunting')
  64. await shot('29-mp-punch', '/mp/punch', 1400)
  65. await shot('30-mp-shift', '/mp/shift', 900)
  66. await shot('31-mp-inbox', '/mp/inbox', 900)
  67. await shot('32-mp-mine', '/mp/mine', 900)
  68. } catch (err) {
  69. console.error(err)
  70. await page.screenshot({ path: join(dir, 'zz-error.png') }).catch(() => {})
  71. process.exitCode = 1
  72. } finally {
  73. await browser.close()
  74. }