|
@@ -1,165 +1,203 @@
|
|
|
-// import { Component } from 'react'
|
|
|
-// import { View, Text } from '@tarojs/components'
|
|
|
-// import { observer, inject } from 'mobx-react'
|
|
|
-// import React from 'react'
|
|
|
-// import CustomNavbar from '../../components/customNavbar/index2'
|
|
|
-// import BookSearch from '../../components/puppetry/BookSearch'
|
|
|
-// import BookHead from '../../components/puppetry/BookHead'
|
|
|
-// import BookHotTabs from '../../components/puppetry/BookHotTabs'
|
|
|
-// import BookboxRowBig from '../../components/puppetry/BookBox/BookboxRowBig'
|
|
|
-// import Taro from '@tarojs/taro'
|
|
|
+import { Component } from 'react'
|
|
|
+import { View, Text } from '@tarojs/components'
|
|
|
+import { observer, inject } from 'mobx-react'
|
|
|
+import Taro from '@tarojs/taro'
|
|
|
|
|
|
-// import { getAllSearching, search } from '../../api/index'
|
|
|
+import './index.less'
|
|
|
+import CustomNavbar from '@src/components/TopNavBar'
|
|
|
+import ScrollViewHoc from '@src/components/ScrollView'
|
|
|
+import BookHead from '@src/components/PupPetry/BookHead'
|
|
|
+import BookboxRowBig from '@src/components/PupPetry/BookBox/BookboxRowBig'
|
|
|
+import BookSearch from '@src/components/PupPetry/BookSearch'
|
|
|
+import useApi from '@src/Hook/useApi'
|
|
|
+import { Store } from '@src/app'
|
|
|
|
|
|
-// import './index.less'
|
|
|
-// type PageStateProps = {
|
|
|
-// store: {
|
|
|
-// indexStore: {
|
|
|
-// navBarTop: number,
|
|
|
-// SET_NAVBARMARGINTOP: Function
|
|
|
-// },
|
|
|
-// bookStore: {
|
|
|
-// action: Function,
|
|
|
-// channel: 'f' | 'm',
|
|
|
-// setChannel: (str: 'f' | 'm') => void
|
|
|
-// },
|
|
|
-// }
|
|
|
-// }
|
|
|
-// interface Search {
|
|
|
-// props: PageStateProps;
|
|
|
-// }
|
|
|
|
|
|
+type PageStateProps = {
|
|
|
+ store: Store
|
|
|
+}
|
|
|
+interface Search {
|
|
|
+ props: PageStateProps;
|
|
|
+}
|
|
|
+interface ContentData {
|
|
|
+ current: number,
|
|
|
+ total: number,
|
|
|
+ size: number,
|
|
|
+ records: any[]
|
|
|
+}
|
|
|
+interface State {
|
|
|
+ searchData: ContentData;
|
|
|
+ searchVal: string,
|
|
|
+ hotVal: any[],
|
|
|
+ historyVal: any[],
|
|
|
+ api: {
|
|
|
+ getBookPageList: (data: any) => Promise<any>
|
|
|
+ } | null
|
|
|
+}
|
|
|
|
|
|
|
|
|
-// @inject('store')
|
|
|
-// @observer
|
|
|
-// class Search extends Component {
|
|
|
-// state = {
|
|
|
-// searchList: [], // 搜索结果
|
|
|
-// searchVal: "", // 搜索内容
|
|
|
-// hotVal: [], // 搜索页大家都在搜list
|
|
|
-// historyVal: [], // 搜索历史
|
|
|
-// }
|
|
|
-// onLoad() {
|
|
|
-// try{
|
|
|
-// let searchValue: any[] = Taro.getStorageSync('search-val')
|
|
|
-// if(searchValue) {
|
|
|
-// this.setState({
|
|
|
-// historyVal: searchValue
|
|
|
-// })
|
|
|
-// }
|
|
|
-// }catch(e) {}
|
|
|
-// this.getList()
|
|
|
-// }
|
|
|
+@inject('store')
|
|
|
+@observer
|
|
|
+class Search extends Component {
|
|
|
+ state: State = {
|
|
|
+ searchData: {
|
|
|
+ current: 0,
|
|
|
+ total: 0,
|
|
|
+ size: 0,
|
|
|
+ records: []
|
|
|
+ }, // 搜索结果
|
|
|
+ searchVal: "", // 搜索内容
|
|
|
+ hotVal: [], // 搜索页大家都在搜list
|
|
|
+ historyVal: [], // 搜索历史
|
|
|
+ api: null
|
|
|
+ }
|
|
|
+ onLoad() {
|
|
|
+ try {
|
|
|
+ let searchValue: any[] = Taro.getStorageSync('search-val')
|
|
|
+ if (searchValue) {
|
|
|
+ this.setState({
|
|
|
+ historyVal: searchValue,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (e) { }
|
|
|
+ }
|
|
|
+ componentDidMount(): void {
|
|
|
+ let api = useApi(this.props.store.appInfoStore)
|
|
|
+ this.setState({ api })
|
|
|
+ }
|
|
|
+ /** 点击搜索历史 */
|
|
|
+ historyHanlde = (text: string) => {
|
|
|
+ this.searchHandle(text)
|
|
|
+ }
|
|
|
|
|
|
-// getList = () => {
|
|
|
-// /** 搜索页大家都在搜 */
|
|
|
-// const { bookStore } = this.props.store
|
|
|
-// getAllSearching({channel: bookStore.channel}).then((res: any) => {
|
|
|
-// let body = res?.body?.map(item => {
|
|
|
-// let action = item?.action?.split('/')
|
|
|
-// return {
|
|
|
-// text: item?.character_title,
|
|
|
-// value: action[action.length - 1]
|
|
|
-// }
|
|
|
-// })
|
|
|
-// this.setState({
|
|
|
-// hotVal: body
|
|
|
-// })
|
|
|
-// })
|
|
|
-// }
|
|
|
+ /** 搜索 */
|
|
|
+ searchHandle = (value: string) => {
|
|
|
+ this.setState({
|
|
|
+ searchVal: value
|
|
|
+ })
|
|
|
+ this.getSearchData({ bookNameOrAuthorName: value, pageNum: 1, pageSize: 20 })
|
|
|
+ }
|
|
|
+ // 获取搜索结果
|
|
|
+ getSearchData = (params) => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let { bookNameOrAuthorName } = params
|
|
|
+ this.state.api?.getBookPageList(params).then((res: any) => {
|
|
|
+ console.log(res)
|
|
|
+ try {
|
|
|
+ // 保存搜索记录
|
|
|
+ let searchValue: any[] = this.state.historyVal
|
|
|
+ if (searchValue) {
|
|
|
+ let ind = searchValue.findIndex(item => item === bookNameOrAuthorName)
|
|
|
+ if (ind === -1) {
|
|
|
+ if (searchValue.length >= 10) {
|
|
|
+ searchValue = searchValue.splice(1)
|
|
|
+ searchValue.push(bookNameOrAuthorName)
|
|
|
+ } else {
|
|
|
+ searchValue.push(bookNameOrAuthorName)
|
|
|
+ }
|
|
|
+ Taro.setStorageSync('search-val', searchValue)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Taro.setStorageSync('search-val', [bookNameOrAuthorName])
|
|
|
+ }
|
|
|
+ this.setState({
|
|
|
+ historyVal: Taro.getStorageSync('search-val')
|
|
|
+ })
|
|
|
+ } catch (e) {
|
|
|
+ }
|
|
|
+ this.setState({
|
|
|
+ searchData: res?.data?.data
|
|
|
+ })
|
|
|
+ resolve(res)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ /** 清除搜索历史 */
|
|
|
+ removeHistory = () => {
|
|
|
+ try {
|
|
|
+ Taro.removeStorageSync('search-val')
|
|
|
+ this.setState({
|
|
|
+ historyVal: []
|
|
|
+ })
|
|
|
+ } catch (e) {
|
|
|
+ // Do something when catch error
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //下来加载
|
|
|
+ load = () => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let { size, total, records } = this.state.searchData
|
|
|
+ let pageSize = size + 20
|
|
|
+ if (records?.length >= total) {
|
|
|
+ Taro.showToast({
|
|
|
+ title: '没有更多了~~',
|
|
|
+ duration: 2000,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ reject()
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ this.getSearchData({ bookNameOrAuthorName: this.state.searchVal, pageNum: 1, pageSize }).then(res => {
|
|
|
+ console.log("Res", res)
|
|
|
+ resolve(true)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ render() {
|
|
|
+ return <View className='search'>
|
|
|
+ <View>
|
|
|
+ <BookSearch onBack={this.searchHandle} val={this.state.searchVal} onClear={() => {
|
|
|
+ this.setState({
|
|
|
+ searchVal: "",
|
|
|
+ searchData: {
|
|
|
+ current: 0,
|
|
|
+ total: 0,
|
|
|
+ size: 0,
|
|
|
+ records: []
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }} />
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ this.state.searchData?.records?.length === 0 ? <View>
|
|
|
+ {/* 推荐小说缺少接口 */}
|
|
|
+ {/* <BookHead title="大家都在搜" fontSize={32}></BookHead> */}
|
|
|
+ {/* <BookHotTabs hotValue={this.state.hotVal} onBack={(id) => { Taro.navigateTo({ url: `/pages/book/bookDetails/index?bookId=${id}` }) }} scroll={false}></BookHotTabs> */}
|
|
|
+ <View className="line"></View>
|
|
|
+ <BookHead title="搜索历史" fontSize={32} imgUrl={require('../../icon/delete.png')} fitOnBack={this.removeHistory} imgWidth={36}></BookHead>
|
|
|
+ {/* 历史记录 */}
|
|
|
+ <View className="history">
|
|
|
+ {
|
|
|
+ this.state.historyVal?.map(item => {
|
|
|
+ return <View className="histore_item" onClick={() => {
|
|
|
+ this.historyHanlde(item)
|
|
|
+ }}>
|
|
|
+ <Text>{item}</Text>
|
|
|
+ </View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ </View> :
|
|
|
|
|
|
-// /** 点击搜索历史 */
|
|
|
-// historyHanlde = (text: string) => {
|
|
|
-// this.searchHandle(text)
|
|
|
-// }
|
|
|
+ <View>
|
|
|
+ <View className="searchTs">
|
|
|
+ 搜索"<Text>{this.state.searchVal}</Text>"结果,共<Text>{this.state.searchData?.total}</Text>条
|
|
|
+ </View>
|
|
|
+ <ScrollViewHoc load={this.load} filterClassName='.searchTs' navHeight={this.props.store.indexStore.navHeight}>
|
|
|
+ <View className='w row for_top pd_btm'>
|
|
|
+ {
|
|
|
+ this.state.searchData?.records?.map((item) => {
|
|
|
+ return <View key={item.bookId}><BookboxRowBig {...item} /></View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ </ScrollViewHoc>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
|
|
|
-// /** 搜索 */
|
|
|
-// searchHandle = (value: string) => {
|
|
|
-// this.setState({
|
|
|
-// searchVal: value
|
|
|
-// })
|
|
|
-// search({keyword: value}).then((res: any) => {
|
|
|
-// try {
|
|
|
-// // 保存搜索记录
|
|
|
-// let searchValue: any[] = this.state.historyVal
|
|
|
-// if(searchValue){
|
|
|
-// let ind = searchValue.findIndex(item => item === value)
|
|
|
-// if(ind === -1){
|
|
|
-// if(searchValue.length >= 10) {
|
|
|
-// searchValue = searchValue.splice(1)
|
|
|
-// searchValue.push(value)
|
|
|
-// }else{
|
|
|
-// searchValue.push(value)
|
|
|
-// }
|
|
|
-// Taro.setStorageSync('search-val', searchValue)
|
|
|
-// }
|
|
|
-// }else{
|
|
|
-// Taro.setStorageSync('search-val', [value])
|
|
|
-// }
|
|
|
-// this.setState({
|
|
|
-// historyVal: Taro.getStorageSync('search-val')
|
|
|
-// })
|
|
|
-// } catch (e) { }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
-// this.setState({
|
|
|
-// searchList: res?.body?.list
|
|
|
-// })
|
|
|
-// })
|
|
|
-// }
|
|
|
-// /** 清除搜索历史 */
|
|
|
-// removeHistory = () => {
|
|
|
-// try {
|
|
|
-// Taro.removeStorageSync('search-val')
|
|
|
-// this.setState({
|
|
|
-// historyVal: []
|
|
|
-// })
|
|
|
-// } catch (e) {
|
|
|
-// // Do something when catch error
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// render() {
|
|
|
-// const { indexStore: { navBarTop } } = this.props.store
|
|
|
-// return (
|
|
|
-// <View className='search'>
|
|
|
-// <CustomNavbar navBarTop={navBarTop} title="搜索" isToBack fontSize={36}></CustomNavbar>
|
|
|
-// <BookSearch onBack={this.searchHandle} val={this.state.searchVal} onClear={()=>{this.setState({searchList: []})}}></BookSearch>
|
|
|
-// {
|
|
|
-// this.state.searchList.length === 0 ? <View>
|
|
|
-// <BookHead title="大家都在搜" fontSize={32}></BookHead>
|
|
|
-// <BookHotTabs hotValue={this.state.hotVal} onBack={(id)=>{Taro.navigateTo({url: `/pages/book/bookDetails/index?book_id=${id}`})}} scroll={false}></BookHotTabs>
|
|
|
-// <View className="line"></View>
|
|
|
-// <BookHead title="搜索历史" fontSize={32} imgUrl={require('../../icon/delete.png')} fitOnBack={this.removeHistory} imgWidth={36}></BookHead>
|
|
|
-// {/* 历史记录 */}
|
|
|
-// <View className="history">
|
|
|
-// {
|
|
|
-// this.state.historyVal?.map(item => {
|
|
|
-// return <View className="histore_item" onClick={()=>{
|
|
|
-// this.historyHanlde(item)
|
|
|
-// }}>
|
|
|
-// <Text>{item}</Text>
|
|
|
-// </View>
|
|
|
-// })
|
|
|
-// }
|
|
|
-// </View>
|
|
|
-// </View> :
|
|
|
-// <View>
|
|
|
-// <View className="searchTs">
|
|
|
-// 搜索"<Text>{this.state.searchVal}</Text>"结果,共<Text>{this.state.searchList?.length}</Text>条
|
|
|
-// </View>
|
|
|
-// <View className='w row for_top pd_btm'>
|
|
|
-// {
|
|
|
-// this.state.searchList?.map((item, index) => {
|
|
|
-// return <View onClick={() => { }} key={index}><BookboxRowBig {...item} /></View>
|
|
|
-// })
|
|
|
-// }
|
|
|
-// </View>
|
|
|
-// </View>
|
|
|
-// }
|
|
|
-// </View>
|
|
|
-// )
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// export default Search
|
|
|
+export default CustomNavbar(Search, { title: "搜索", isToBack: true })
|