mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-07-20 04:02:31 +08:00
finish the filter logic of '公司行业'
This commit is contained in:
@@ -14,6 +14,7 @@ import { setDomainLocalStorage } from '@geekgeekrun/utils/puppeteer/local-storag
|
||||
import { readConfigFile, writeStorageFile, ensureConfigFileExist, readStorageFile, ensureStorageFileExist } from './runtime-file-utils.mjs'
|
||||
import { calculateTotalCombinations, combineFiltersWithConstraintsGenerator } from './combineCalculator.mjs'
|
||||
import { default as jobFilterConditions } from './internal-config/job-filter-conditions-20241002.json'
|
||||
import { default as rawIndustryFilterExemption } from './internal-config/job-filter-industry-filter-exemption-20241002.json'
|
||||
const jobFilterConditionsMapByCode = {}
|
||||
Object.values(jobFilterConditions).forEach(arr => {
|
||||
arr.forEach(option => {
|
||||
@@ -21,6 +22,23 @@ Object.values(jobFilterConditions).forEach(arr => {
|
||||
})
|
||||
})
|
||||
|
||||
let industryFilterCursorIndex = 0;
|
||||
const industryFilterExemption = JSON.parse(JSON.stringify(rawIndustryFilterExemption))
|
||||
const industryFilterConditionsMapByIndex = {}
|
||||
const industryFilterConditionsMapByCode = {}
|
||||
const industryFilterConditionCodeToIndexMap = {}
|
||||
industryFilterExemption.forEach(item => {
|
||||
if (!Array.isArray(item.subLevelModelList)) {
|
||||
return
|
||||
}
|
||||
item.subLevelModelList.forEach(option => {
|
||||
industryFilterConditionsMapByCode[option.code] = option
|
||||
industryFilterConditionsMapByIndex[industryFilterCursorIndex] = option
|
||||
industryFilterConditionCodeToIndexMap[option.code] = industryFilterCursorIndex
|
||||
industryFilterCursorIndex++
|
||||
})
|
||||
})
|
||||
|
||||
ensureConfigFileExist()
|
||||
ensureStorageFileExist()
|
||||
|
||||
@@ -158,15 +176,21 @@ async function setFilterCondition (selectedFilters) {
|
||||
industryList = []
|
||||
} = selectedFilters
|
||||
|
||||
const placeholderTexts = ['薪资待遇', '工作经验', '学历要求', '公司规模']
|
||||
const optionKaPrefixes = ['sel-job-rec-salary-', 'sel-job-rec-exp-', 'sel-job-rec-degree-', 'sel-job-rec-scale-']
|
||||
const conditionArr = [salaryList, experienceList, degreeList, scaleList]
|
||||
const placeholderTexts = ['薪资待遇', '工作经验', '学历要求', '公司行业', '公司规模']
|
||||
const optionKaPrefixes = ['sel-job-rec-salary-', 'sel-job-rec-exp-', 'sel-job-rec-degree-', 'sel-industry-', 'sel-job-rec-scale-']
|
||||
const conditionArr = [salaryList, experienceList, degreeList, industryList, scaleList]
|
||||
|
||||
console.log('current filter condition----')
|
||||
for (let i = 0; i < placeholderTexts.length; i++) {
|
||||
const text = placeholderTexts[i]
|
||||
const condition = conditionArr[i]
|
||||
console.log(`${text}:`, condition.length === 0 ? '不限' : condition.map(code => jobFilterConditionsMapByCode[code]?.name ?? code).join(',') )
|
||||
console.log(`${text}:`, condition.length === 0 ? '不限' : condition.map(code => {
|
||||
if (text === '公司行业') {
|
||||
return industryFilterConditionsMapByCode[code]?.name ?? code
|
||||
} else {
|
||||
return jobFilterConditionsMapByCode[code]?.name ?? code
|
||||
}
|
||||
}).join(','))
|
||||
}
|
||||
console.log('----------------------------')
|
||||
for(let i = 0; i < placeholderTexts.length; i++) {
|
||||
@@ -197,12 +221,19 @@ async function setFilterCondition (selectedFilters) {
|
||||
|
||||
const optionKaPrefix = optionKaPrefixes[i]
|
||||
if (!currentFilterConditions.length) {
|
||||
// select 不限 immediately
|
||||
const buxianOptionElProxy = await page.$(`.job-recommend-main .recommend-search-more .condition-filter-select .filter-select-dropdown li[ka="${optionKaPrefix}${0}"]`)
|
||||
await buxianOptionElProxy.click()
|
||||
if (placeholderText === '公司行业') {
|
||||
const activeOptionElAtCurrentFilterProxyList = await page.$$(`.job-recommend-main .recommend-search-more .active[ka^="${optionKaPrefix}"]`)
|
||||
for (const it of activeOptionElAtCurrentFilterProxyList) {
|
||||
await it.click()
|
||||
}
|
||||
} else {
|
||||
// select 不限 immediately
|
||||
const buxianOptionElProxy = await page.$(`.job-recommend-main .recommend-search-more [ka="${optionKaPrefix}${0}"]`)
|
||||
await buxianOptionElProxy.click()
|
||||
}
|
||||
} else {
|
||||
//#region uncheck options perviously checked but not existed in current filter.
|
||||
const activeOptionElAtCurrentFilterProxyList = await page.$$(`.job-recommend-main .recommend-search-more .condition-filter-select .filter-select-dropdown li.active[ka^="${optionKaPrefix}"]`)
|
||||
const activeOptionElAtCurrentFilterProxyList = await page.$$(`.job-recommend-main .recommend-search-more .active[ka^="${optionKaPrefix}"]`)
|
||||
const activeOptionValues = (await Promise.all(
|
||||
activeOptionElAtCurrentFilterProxyList.map(elProxy => {
|
||||
return elProxy.evaluate((el) => {
|
||||
@@ -212,7 +243,12 @@ async function setFilterCondition (selectedFilters) {
|
||||
)).map(it => it.replace(optionKaPrefix, '')).map(Number)
|
||||
if (placeholderText !== '薪资待遇') {
|
||||
for(let i = 0; i < activeOptionValues.length; i++) {
|
||||
const activeValue = activeOptionValues[i]
|
||||
let activeValue
|
||||
if (placeholderText === '公司行业') {
|
||||
activeValue = industryFilterConditionsMapByIndex[activeOptionValues[i]]?.code
|
||||
} else {
|
||||
activeValue = activeOptionValues[i]
|
||||
}
|
||||
const activeOptionElProxy = activeOptionElAtCurrentFilterProxyList[i]
|
||||
if (!currentFilterConditions.includes(activeValue)) {
|
||||
await activeOptionElProxy.click()
|
||||
@@ -222,12 +258,21 @@ async function setFilterCondition (selectedFilters) {
|
||||
//#endregion
|
||||
//#region only click the one which we need check, don't change already checked.
|
||||
const conditionToCheck = currentFilterConditions.filter(it => {
|
||||
return !activeOptionValues.includes(it)
|
||||
if (placeholderText === '公司行业') {
|
||||
return !activeOptionValues.map(value => industryFilterConditionsMapByIndex[value].code).includes(it);
|
||||
} else {
|
||||
return !activeOptionValues.includes(it)
|
||||
}
|
||||
})
|
||||
for(let j = 0; j < conditionToCheck.length; j++) {
|
||||
const optionValue = conditionToCheck[j]
|
||||
let optionValue
|
||||
if (placeholderText === '公司行业') {
|
||||
optionValue = industryFilterConditionCodeToIndexMap[conditionToCheck[j]]
|
||||
} else {
|
||||
optionValue = conditionToCheck[j]
|
||||
}
|
||||
await sleepWithRandomDelay(500)
|
||||
const optionElProxy = await page.$(`.job-recommend-main .recommend-search-more .condition-filter-select .filter-select-dropdown li[ka="${optionKaPrefix}${optionValue}"]`)
|
||||
const optionElProxy = await page.$(`.job-recommend-main .recommend-search-more [ka="${optionKaPrefix}${optionValue}"]`)
|
||||
if (!optionElProxy) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user