Merge pull request #137 from leordsong/feature/douyin-productlink
如果抖音商品链接不可用,关掉弹窗
This commit is contained in:
@@ -529,9 +529,19 @@ const defaultTabInit = {
|
|||||||
publishStatus: null // 发布状态,包含message和type
|
publishStatus: null // 发布状态,包含message和type
|
||||||
}
|
}
|
||||||
|
|
||||||
// tab页数据 - 默认只有一个tab
|
// helper to create a fresh deep-copied tab from defaultTabInit
|
||||||
|
const makeNewTab = () => {
|
||||||
|
// prefer structuredClone when available (newer browsers/node), fallback to JSON
|
||||||
|
try {
|
||||||
|
return typeof structuredClone === 'function' ? structuredClone(defaultTabInit) : JSON.parse(JSON.stringify(defaultTabInit))
|
||||||
|
} catch (e) {
|
||||||
|
return JSON.parse(JSON.stringify(defaultTabInit))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// tab页数据 - 默认只有一个tab (use deep copy to avoid shared refs)
|
||||||
const tabs = reactive([
|
const tabs = reactive([
|
||||||
defaultTabInit
|
makeNewTab()
|
||||||
])
|
])
|
||||||
|
|
||||||
// 账号相关状态
|
// 账号相关状态
|
||||||
@@ -568,9 +578,9 @@ const recommendedTopics = [
|
|||||||
// 添加新tab
|
// 添加新tab
|
||||||
const addTab = () => {
|
const addTab = () => {
|
||||||
tabCounter++
|
tabCounter++
|
||||||
const newTab = defaultTabInit
|
const newTab = makeNewTab()
|
||||||
newTab['name'] = `tab${tabCounter}`
|
newTab.name = `tab${tabCounter}`
|
||||||
newTab['label'] = `发布${tabCounter}`
|
newTab.label = `发布${tabCounter}`
|
||||||
tabs.push(newTab)
|
tabs.push(newTab)
|
||||||
activeTab.value = newTab.name
|
activeTab.value = newTab.name
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ class DouYinVideo(object):
|
|||||||
"""处理商品编辑弹窗"""
|
"""处理商品编辑弹窗"""
|
||||||
|
|
||||||
await page.wait_for_timeout(2000)
|
await page.wait_for_timeout(2000)
|
||||||
|
await page.wait_for_selector('input[placeholder="请输入商品短标题"]', timeout=10000)
|
||||||
short_title_input = page.locator('input[placeholder="请输入商品短标题"]')
|
short_title_input = page.locator('input[placeholder="请输入商品短标题"]')
|
||||||
if not await short_title_input.count():
|
if not await short_title_input.count():
|
||||||
douyin_logger.error("[-] 未找到商品短标题输入框")
|
douyin_logger.error("[-] 未找到商品短标题输入框")
|
||||||
@@ -292,6 +293,7 @@ class DouYinVideo(object):
|
|||||||
"""设置商品链接功能"""
|
"""设置商品链接功能"""
|
||||||
try:
|
try:
|
||||||
# 定位"添加标签"文本,然后向上导航到容器,再找到下拉框
|
# 定位"添加标签"文本,然后向上导航到容器,再找到下拉框
|
||||||
|
await page.wait_for_selector('text=添加标签', timeout=10000)
|
||||||
dropdown = page.get_by_text('添加标签').locator("..").locator("..").locator("..").locator(".semi-select").first
|
dropdown = page.get_by_text('添加标签').locator("..").locator("..").locator("..").locator(".semi-select").first
|
||||||
if not await dropdown.count():
|
if not await dropdown.count():
|
||||||
douyin_logger.error("[-] 未找到标签下拉框")
|
douyin_logger.error("[-] 未找到标签下拉框")
|
||||||
@@ -321,6 +323,15 @@ class DouYinVideo(object):
|
|||||||
return False
|
return False
|
||||||
await add_button.click()
|
await add_button.click()
|
||||||
douyin_logger.debug("[+] 成功点击'添加链接'按钮")
|
douyin_logger.debug("[+] 成功点击'添加链接'按钮")
|
||||||
|
## 如果链接不可用
|
||||||
|
await page.wait_for_timeout(2000)
|
||||||
|
error_modal = page.locator('text=未搜索到对应商品')
|
||||||
|
if await error_modal.count():
|
||||||
|
confirm_button = page.locator('button:has-text("确定")')
|
||||||
|
await confirm_button.click()
|
||||||
|
# await page.wait_for_selector('.semi-modal-content', state='hidden', timeout=5000)
|
||||||
|
douyin_logger.error("[-] 商品链接无效")
|
||||||
|
return False
|
||||||
|
|
||||||
# 填写商品短标题
|
# 填写商品短标题
|
||||||
if not await self.handle_product_dialog(page, product_title):
|
if not await self.handle_product_dialog(page, product_title):
|
||||||
|
|||||||
Reference in New Issue
Block a user