feat: add task management and progress reporting
- Implemented task and subtask structures with progress tracking. - Added reporting functionality to log progress at various stages in hotel room status management scripts. - Created a task store to manage tasks and their states, including persistence to local storage. - Updated UI components to display task lists and handle task actions (retry, remove). - Removed deprecated TaskCard and TaskList components, replacing them with a new structure for better maintainability. - Enhanced script execution service to emit progress events for UI updates.
This commit is contained in:
@@ -4,6 +4,10 @@ import tabsPkg from './common/tabs.js';
|
||||
|
||||
const { preparePage, safeDisconnectBrowser } = tabsPkg;
|
||||
|
||||
function reportProgress(step, percent) {
|
||||
console.log('__ZN_PROGRESS__' + JSON.stringify({ step, percent }));
|
||||
}
|
||||
|
||||
const parseDateInput = (dateStr) => {
|
||||
if (!dateStr) return null;
|
||||
if (typeof dateStr === 'number' && Number.isFinite(dateStr)) return new Date(dateStr);
|
||||
@@ -158,6 +162,7 @@ const navigateToRoomStatusManagement = async (page) => {
|
||||
let browser;
|
||||
|
||||
try {
|
||||
reportProgress('连接本地浏览器', 10);
|
||||
const groupId = '1816249020842116';
|
||||
const homeUrl = `https://life.douyin.com/p/home?groupid=${groupId}`;
|
||||
const priceAmountStateUrl = `https://life.douyin.com/p/travel-ari/hotel/price_amount_state?groupid=${groupId}`;
|
||||
@@ -175,6 +180,7 @@ const navigateToRoomStatusManagement = async (page) => {
|
||||
} catch (e2) {}
|
||||
}
|
||||
|
||||
reportProgress('定位目标页面', 30);
|
||||
// Navigation logic (User provided)
|
||||
try {
|
||||
// Try to click the store/login button if visible
|
||||
@@ -199,12 +205,14 @@ const navigateToRoomStatusManagement = async (page) => {
|
||||
|
||||
if (!roomType || !startDate) {
|
||||
log.info('ROOM_TYPE/START_DATE not provided, skip room toggle.');
|
||||
reportProgress('执行完成', 100);
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait for table rows to appear
|
||||
await page.locator('.lifep-table-row').first().waitFor({ state: 'visible', timeout: 15000 });
|
||||
|
||||
reportProgress('操作房态数据', 60);
|
||||
const dateList = buildDateList(startDate, endDate);
|
||||
for (const dateStr of dateList) {
|
||||
try {
|
||||
@@ -215,11 +223,13 @@ const navigateToRoomStatusManagement = async (page) => {
|
||||
await page.waitForTimeout(500 + Math.random() * 500);
|
||||
}
|
||||
|
||||
reportProgress('保存并校验', 90);
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
process.exitCode = 1;
|
||||
} finally {
|
||||
await safeDisconnectBrowser(browser);
|
||||
reportProgress('执行完成', 100);
|
||||
process.exit(process.exitCode || 0);
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user