mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-06 16:07:17 +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 { readConfigFile, writeStorageFile, ensureConfigFileExist, readStorageFile, ensureStorageFileExist } from './runtime-file-utils.mjs'
|
||||||
import { calculateTotalCombinations, combineFiltersWithConstraintsGenerator } from './combineCalculator.mjs'
|
import { calculateTotalCombinations, combineFiltersWithConstraintsGenerator } from './combineCalculator.mjs'
|
||||||
import { default as jobFilterConditions } from './internal-config/job-filter-conditions-20241002.json'
|
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 = {}
|
const jobFilterConditionsMapByCode = {}
|
||||||
Object.values(jobFilterConditions).forEach(arr => {
|
Object.values(jobFilterConditions).forEach(arr => {
|
||||||
arr.forEach(option => {
|
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()
|
ensureConfigFileExist()
|
||||||
ensureStorageFileExist()
|
ensureStorageFileExist()
|
||||||
|
|
||||||
@@ -158,15 +176,21 @@ async function setFilterCondition (selectedFilters) {
|
|||||||
industryList = []
|
industryList = []
|
||||||
} = selectedFilters
|
} = selectedFilters
|
||||||
|
|
||||||
const placeholderTexts = ['薪资待遇', '工作经验', '学历要求', '公司规模']
|
const placeholderTexts = ['薪资待遇', '工作经验', '学历要求', '公司行业', '公司规模']
|
||||||
const optionKaPrefixes = ['sel-job-rec-salary-', 'sel-job-rec-exp-', 'sel-job-rec-degree-', 'sel-job-rec-scale-']
|
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, scaleList]
|
const conditionArr = [salaryList, experienceList, degreeList, industryList, scaleList]
|
||||||
|
|
||||||
console.log('current filter condition----')
|
console.log('current filter condition----')
|
||||||
for (let i = 0; i < placeholderTexts.length; i++) {
|
for (let i = 0; i < placeholderTexts.length; i++) {
|
||||||
const text = placeholderTexts[i]
|
const text = placeholderTexts[i]
|
||||||
const condition = conditionArr[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('----------------------------')
|
console.log('----------------------------')
|
||||||
for(let i = 0; i < placeholderTexts.length; i++) {
|
for(let i = 0; i < placeholderTexts.length; i++) {
|
||||||
@@ -197,12 +221,19 @@ async function setFilterCondition (selectedFilters) {
|
|||||||
|
|
||||||
const optionKaPrefix = optionKaPrefixes[i]
|
const optionKaPrefix = optionKaPrefixes[i]
|
||||||
if (!currentFilterConditions.length) {
|
if (!currentFilterConditions.length) {
|
||||||
// select 不限 immediately
|
if (placeholderText === '公司行业') {
|
||||||
const buxianOptionElProxy = await page.$(`.job-recommend-main .recommend-search-more .condition-filter-select .filter-select-dropdown li[ka="${optionKaPrefix}${0}"]`)
|
const activeOptionElAtCurrentFilterProxyList = await page.$$(`.job-recommend-main .recommend-search-more .active[ka^="${optionKaPrefix}"]`)
|
||||||
await buxianOptionElProxy.click()
|
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 {
|
} else {
|
||||||
//#region uncheck options perviously checked but not existed in current filter.
|
//#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(
|
const activeOptionValues = (await Promise.all(
|
||||||
activeOptionElAtCurrentFilterProxyList.map(elProxy => {
|
activeOptionElAtCurrentFilterProxyList.map(elProxy => {
|
||||||
return elProxy.evaluate((el) => {
|
return elProxy.evaluate((el) => {
|
||||||
@@ -212,7 +243,12 @@ async function setFilterCondition (selectedFilters) {
|
|||||||
)).map(it => it.replace(optionKaPrefix, '')).map(Number)
|
)).map(it => it.replace(optionKaPrefix, '')).map(Number)
|
||||||
if (placeholderText !== '薪资待遇') {
|
if (placeholderText !== '薪资待遇') {
|
||||||
for(let i = 0; i < activeOptionValues.length; i++) {
|
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]
|
const activeOptionElProxy = activeOptionElAtCurrentFilterProxyList[i]
|
||||||
if (!currentFilterConditions.includes(activeValue)) {
|
if (!currentFilterConditions.includes(activeValue)) {
|
||||||
await activeOptionElProxy.click()
|
await activeOptionElProxy.click()
|
||||||
@@ -222,12 +258,21 @@ async function setFilterCondition (selectedFilters) {
|
|||||||
//#endregion
|
//#endregion
|
||||||
//#region only click the one which we need check, don't change already checked.
|
//#region only click the one which we need check, don't change already checked.
|
||||||
const conditionToCheck = currentFilterConditions.filter(it => {
|
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++) {
|
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)
|
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) {
|
if (!optionElProxy) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user