| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- export const randomRange = (min: number, max: number) => {
- return Math.random() * (max - min) + min
- }
- export const scrollToElement = (selector: string) => {
- const el = document.querySelector(selector)
- if (el) {
- setTimeout(() => {
- el.scrollIntoView({
- behavior: 'smooth'
- })
- }, 17)
- }
- }
- export const findTopCatBySubCatId = (classes: any[], catId: string): any[] | null => {
- for (const topCat of classes) {
- const cats = topCat.categories
- const matchedCat = cats && cats.length && cats.find((cat) => cat.cat_id === catId)
- if (matchedCat) {
- return [topCat, matchedCat]
- }
- }
- return null
- }
- export const getTopCatSubCatIds = (topCat) => {
- return topCat && topCat.categories && topCat.categories.map((cat) => cat.cat_id) || []
- }
- export const parseCatIdAndServiceType = (input: {
- cat_id: string
- st: string
- classes: any[]
- serviceTypes: any[]
- }) => {
- const {
- cat_id,
- st,
- classes = [],
- serviceTypes = []
- } = input
- let topCatId = '_'
- let catId = '_'
- let serviceType = '_'
- let matchedCatIds: string[] = []
- let topCatName!: string
- let catName!: string
- if (cat_id) {
- let topCat
- let cat
- if (cat_id.length === 8) {
- topCat = classes.find((topCat) => topCat.hash_id === cat_id)
- matchedCatIds = getTopCatSubCatIds(topCat)
- } else {
- [topCat, cat] = findTopCatBySubCatId(classes, cat_id) || []
- if (cat) {
- catId = cat_id
- catName = cat.name
- matchedCatIds = [catId]
- }
- }
- if (topCat) {
- topCatId = topCat.hash_id
- topCatName = topCat.name
- }
- }
- if (st) {
- const matchedServiceType = serviceTypes.find((item) => item.hash_id === st)
- if (matchedServiceType) {
- serviceType = st
- }
- }
- return {
- topCatId,
- topCatName,
- catId,
- catName,
- serviceType,
- matchedCatIds
- }
- }
- export const genCatIdSearchSentence = (catIds: string[], serviceType: string) => {
- return [catIds.join('|'), serviceType].filter((val) => !!val && val != '_').join('&&')
- }
|