Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dagouzhi committed Jun 15, 2024
1 parent b2507fc commit 229f5fe
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 143 deletions.
Binary file modified dgz/build/outputs/dist.dgz
Binary file not shown.
24 changes: 2 additions & 22 deletions src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import URLParse from 'url-parse';
import lodash from 'lodash';
import Item from '@/component/Item';
import jssdk from '@htyf-mp/js-sdk';
import { getHome } from '@/server/api';

console.log(jsCrawler);

Expand All @@ -38,28 +39,7 @@ function Index() {
content: '加载数据中...',
});
setLoading(true);
let data = await jssdk?.puppeteer({
url: `${host}`,
jscode: `${jsCrawler}`,
debug: isDebug,
wait: 2000,
timeout: 1000 * 30,
callback: () => {},
});
if (!data) {
ui.showToast({
content: '请先进行验证真人操作...',
});
data = await jssdk?.puppeteer({
url: `${host}`,
jscode: `${jsCrawler}`,
debug: true,
wait: 2000,
timeout: 1000 * 60 * 10,
callback: () => {},
});
}
resolve(data);
const data = getHome();
if (data?.items?.length) {
dispatch(
setHomeData({
Expand Down
36 changes: 3 additions & 33 deletions src/pages/index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,22 @@ import {
import jsCrawler, { host } from '@/utils/js-crawler';
import jssdk from '@htyf-mp/js-sdk';
import routes from '@/routes';
import { auth, getSearch } from '@/server/api';

function Index() {
const ui = useUI();
const apps = useAppSelector(i => i.apps);
const isDebug = apps?.__ENV__ === 'DEV';
const dispatch = useDispatch();
const [msg, setMsg] = useState('验证资源...');
const getData = useCallback(async () => {
return new Promise(async resolve => {
if (jssdk) {
const url = `${host}daoyongjiekoshibushiyoubing?q=我&f=_all&p=1`;
ui.showToast({
content: '加载数据中...',
});
let data = await jssdk?.puppeteer({
url: url,
jscode: `${jsCrawler}`,
debug: isDebug,
wait: 2000,
timeout: 1000 * 30,
callback: () => {},
});
if (!data) {
setMsg('请先进行验证真人操作...');
data = await jssdk?.puppeteer({
url: `${url}`,
jscode: `${jsCrawler}`,
debug: true,
wait: 2000,
timeout: 1000 * 60 * 10,
callback: () => {},
});
}
setMsg('正在验证真人操作...');
let data = await auth();
resolve(data);
navigate.relaunch({
url: routes.pages.home,
});
if (data?.items?.length) {
dispatch(
setHomeData({
...data,
items: data?.items?.map(i => i.url),
}),
);
dispatch(setDBData(data?.items));
}
}
});
}, [isDebug]);
Expand Down
180 changes: 92 additions & 88 deletions src/pages/search/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { View, Text, Image, ScrollView, Button, Input } from '@tarojs/components'
import Taro, { useDidShow, useLoad, useRouter } from '@tarojs/taro'
import './index.scss'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { BookItem, UIProvider, navigate, setDBData, setHomeData, useAppSelector, useDispatch, useUI } from '@/_UIHOOKS_';
import { Header } from '@/_UIHOOKS_/components';
import { View, Text, Image, ScrollView, Button, Input } from '@tarojs/components';
import Taro, { useDidShow, useLoad, useRouter } from '@tarojs/taro';
import './index.scss';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import {
BookItem,
UIProvider,
navigate,
setDBData,
setHomeData,
useAppSelector,
useDispatch,
useUI,
} from '@/_UIHOOKS_';
import { Header } from '@/_UIHOOKS_/components';
import lodash from 'lodash';
import { useImmer } from 'use-immer';
import jsCrawler, {host} from '@/utils/js-crawler';
import jsCrawler, { host } from '@/utils/js-crawler';
import Item from '@/component/Item';
import jssdk from '@htyf-mp/js-sdk'
import jssdk from '@htyf-mp/js-sdk';
import { getSearch } from '@/server/api';

function Index() {
const ui = useUI();
Expand All @@ -17,117 +27,111 @@ function Index() {
const dispatch = useDispatch();
const apps = useAppSelector(i => i.apps);
const isDebug = apps?.__ENV__ === 'DEV';
const [dataObj, setDataObj] = useImmer<{[key: string]: any[]}>({});
const [searchword, setSearchword] = useState('梦')
const [loading, setLoading] = useState(false)
const getData = useCallback(async (searchword: string = '梦', page: number = 1) => {
return new Promise(async (resolve) => {
if (jssdk) {
const url = `${host}daoyongjiekoshibushiyoubing?q=${searchword}&f=_all&p=${page}`
setLoading(true)
ui.showToast({
content: '加载数据中...'
})
const data = await jssdk?.puppeteer({
url: url,
jscode: `${jsCrawler}`,
debug: isDebug,
wait: 2000,
timeout: 1000 * 30,
callback: () => {}
})
console.error(data)
resolve(data)
if (data?.items?.length) {
dispatch(setDBData(data?.items))
setDataObj((_dataObj) => {
if (page === 1) {
return {
1: data
};
}
_dataObj[page] = data;
return _dataObj;
})
const [dataObj, setDataObj] = useImmer<{ [key: string]: any[] }>({});
const [searchword, setSearchword] = useState('梦');
const [loading, setLoading] = useState(false);
const getData = useCallback(
async (searchword: string = '梦', page: number = 1) => {
return new Promise(async resolve => {
if (jssdk) {
const url = `${host}daoyongjiekoshibushiyoubing?q=${searchword}&f=_all&p=${page}`;
setLoading(true);
ui.showToast({
content: '加载数据中...',
});
const data = await getSearch({
name: searchword,
page: page,
});
console.error(data);
resolve(data);
if (data?.items?.length) {
dispatch(setDBData(data?.items));
setDataObj(_dataObj => {
if (page === 1) {
return {
1: data,
};
}
_dataObj[page] = data;
return _dataObj;
});
}
ui.hideToast();
setLoading(false);
}
ui.hideToast()
setLoading(false)
}
})
}, [params, isDebug])
});
},
[params, isDebug],
);

useEffect(() => {
getData();
}, [])
}, []);

const list = useMemo(() => {
const _list: Array<BookItem> = []
const _list: Array<BookItem> = [];
for (const key in dataObj) {
const items: any = lodash.get(dataObj, `[${key}]['items']`, []);
_list.push(...items)
_list.push(...items);
}
return _list
}, [dataObj])
return _list;
}, [dataObj]);

return (
<View className='pages-search-wrap'>
<Header title='搜索' />
<View
className='pages-search-search-wrap'
>
<View className='pages-search-ipt-wrap'>
<Input
autoCapitalize="none"
className='pages-search-ipt'
<View className="pages-search-wrap">
<Header title="搜索" />
<View className="pages-search-search-wrap">
<View className="pages-search-ipt-wrap">
<Input
className="pages-search-ipt"
type="text"
onInput={(e) => {
setSearchword(e.detail.value)
onInput={e => {
setSearchword(e.detail.value);
}}
onConfirm={(e) => {
setSearchword(e.detail.value)
onConfirm={e => {
setSearchword(e.detail.value);
getData(searchword, 1);
}}
/>
</View>
<View
className='pages-search-ipt-btn'
className="pages-search-ipt-btn"
onClick={() => {
getData(searchword, 1);
}}
>
<Text className='pages-search-ipt-btn-text'>搜索</Text>
}}>
<Text className="pages-search-ipt-btn-text">搜索</Text>
</View>
</View>
{
loading ? <View>
{loading ? (
<View>
<Text>loading...</Text>
</View> : undefined
}
<View className='pages-search-body-wrap'>
</View>
) : undefined}
<View className="pages-search-body-wrap">
<ScrollView
className='pages-search-scroll-view'
className="pages-search-scroll-view"
scrollY
onScrollToLower={() => {
const nextPage = (Object.keys(dataObj || {})?.length || 1) + 1;
console.error('nextPage: ', nextPage)
getData(searchword, nextPage)
}}
>
<View
className='pages-search-scroll-body'
>
<View className='pages-search-items-wrap'>
{
list?.map((item: any) => {
return <Item key={item.url} item={item} />
})
}
console.error('nextPage: ', nextPage);
getData(searchword, nextPage);
}}>
<View className="pages-search-scroll-body">
<View className="pages-search-items-wrap">
{list?.map((item: any) => {
return <Item key={item.url} item={item} />;
})}
</View>
</View>
</ScrollView>
</View>
</View>
)
);
}

export default () => <UIProvider><Index/></UIProvider>
export default () => (
<UIProvider>
<Index />
</UIProvider>
);
42 changes: 42 additions & 0 deletions src/server/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import jsCrawler, { host } from '@/utils/js-crawler';
import jssdk, { RequestOptions } from '@htyf-mp/js-sdk';

export async function auth() {
const query = { name: '我', page: 1 };
let data = await getSearch(query);
if (!data) {
data = await getSearch(query, {
timeout: 1000 * 60 * 3,
});
}
return !!data;
}

export async function getSearch(
query: { name: string; page: number },
opt?: Partial<RequestOptions>,
) {
const url = `${host}daoyongjiekoshibushiyoubing?q=${query?.name}&f=_all&p=${query.page || 1}`;
const data = await jssdk?.puppeteer({
url: url,
jscode: `${jsCrawler}`,
debug: opt?.debug,
wait: 2000,
timeout: 1000 * 10,
callback: () => {},
...opt,
});
return data;
}

export async function getHome(query?: undefined, opt?: Partial<RequestOptions>) {
const data = await jssdk?.puppeteer({
url: `${host}`,
jscode: `${jsCrawler}`,
debug: opt?.debug,
wait: 2000,
timeout: 1000 * 10,
callback: () => {},
});
return data;
}

0 comments on commit 229f5fe

Please sign in to comment.