diff --git a/src/api/search.ts b/src/api/search.ts index 1c6e93b..88ad654 100644 --- a/src/api/search.ts +++ b/src/api/search.ts @@ -2,10 +2,10 @@ import {request} from "@/api/request"; export const SearchApi = { /** 品牌列表 */ - list(page: number , page_size: number, search_content: string) { + list(page: number , page_size: number, name: string) { return request<{ data: any[], total: number - }>(`/home/v1/search/home?page=${page}&page_size=${page_size}&keywords=${search_content}&sort_type=1&sort=0` , "GET") + }>(`/home/v1/search/home?page=${page}&page_size=${page_size}&keywords=${name}&sort_type=1&sort=0` , "GET") }, } diff --git a/src/components/loginView/index.module.scss b/src/components/loginView/index.module.scss index 90a023d..53d8e13 100644 --- a/src/components/loginView/index.module.scss +++ b/src/components/loginView/index.module.scss @@ -33,4 +33,11 @@ font-size: 32rpx; font-weight: 500; } + .nextLabel{ + font-size: 24rpx; + font-weight: 500; + color: #909795; + line-height: 24rpx; + margin-top: 15rpx; + } } diff --git a/src/components/loginView/index.tsx b/src/components/loginView/index.tsx index b6bfb64..ca1994e 100644 --- a/src/components/loginView/index.tsx +++ b/src/components/loginView/index.tsx @@ -1,8 +1,10 @@ -import {CSSProperties,FC} from "react"; +import {CSSProperties, FC, useState} from "react"; import {View,Image} from "@tarojs/components"; import styles from './index.module.scss' import NoLogin from '@/static/img/noLogin.png' import {Profile} from "@/store"; +import Taro from "@tarojs/taro"; +import {userApi} from "@/api"; interface Props { tips?: string @@ -10,7 +12,8 @@ interface Props { } const LoginView: FC = (props) => { - const {empty} = Profile.useContainer() + const [isLoading, setLoading] = useState(false) + const {setUser,setToken,setCompany} = Profile.useContainer() const text = props.tips ?? '登录后可查看更多内容' const size: string = props.height? `${props.height}px`:'0rpx' const sizeStyle: CSSProperties = { @@ -18,13 +21,43 @@ const LoginView: FC = (props) => { paddingTop:size, } + function login() { + if (isLoading) return; + Taro.showLoading({title:'微信授权中...'}) + setLoading(true) + Taro.login({ + success: async (res) => { + try { + const {catch_key, user, token, company} = await userApi.login(res.code) + Taro.hideLoading() + if (token) { + Taro.showToast({title:'授权成功',duration:1500,icon:'success',mask:true}) + setTimeout(()=>{ + setUser(user) + setToken(token) + setCompany(company) + setLoading(false) + Taro.switchTab({url: '/pages/home/home'}) + },1500) + } else { + Taro.setStorageSync('openid', catch_key) + Taro.reLaunch({url: '/pages/check/check'}) + } + } catch (e) { + Taro.hideLoading() + } + setLoading(false) + } + }) + } return ( 暂未登录 {text} - {empty()}} className={styles.button}>立即登录 + {login()}} className={styles.button}>立即登录 + 点击立即登录完成微信授权以继续使用 ) } diff --git a/src/pages/business/userInfo/userInfo.tsx b/src/pages/business/userInfo/userInfo.tsx index 2bf8f9b..e517b85 100644 --- a/src/pages/business/userInfo/userInfo.tsx +++ b/src/pages/business/userInfo/userInfo.tsx @@ -45,7 +45,7 @@ const List = () => { Taro.showModal({ title: '是否确定退出登录', success({confirm}) { - confirm && empty() + confirm && empty(true,true) } }) } diff --git a/src/pages/my/my.module.scss b/src/pages/my/my.module.scss index 3c52ea1..d190f39 100644 --- a/src/pages/my/my.module.scss +++ b/src/pages/my/my.module.scss @@ -97,6 +97,9 @@ page { padding: 16rpx 0; box-sizing: border-box; border-bottom: 2rpx solid #F5F8F7; + &.noBorder{ + border:none; + } .image{ width: 68rpx; height:68rpx; diff --git a/src/pages/my/my.tsx b/src/pages/my/my.tsx index e5408b3..54bdf8d 100644 --- a/src/pages/my/my.tsx +++ b/src/pages/my/my.tsx @@ -17,12 +17,15 @@ const My: FC = () => { const [companyShow, setCompanyShow] = useState(false) const [companyList, setCompanyList] = useState([]) Taro.useDidShow(() => { - try { - userApi.companyList().then(res => { - setCompanyList(res as Company[]) - }) - } catch (e) { + if(token){ + try { + userApi.companyList().then(res => { + setCompanyList(res as Company[]) + }) + } catch (e) { + } } + }) return ( @@ -45,8 +48,11 @@ const My: FC = () => { style={{display: 'flex', justifyContent: 'center', borderBottom: '2rpx solid #f5f8f7'}}>选择公司 { companyList.length >= 1 && - companyList.map(d => - { + companyList.map((d,idx) => + { + if(company?.id === d.id){ + return + } Taro.showLoading({ title: '切换公司中', mask: true, diff --git a/src/pages/preview/search/search/components/list.module.scss b/src/pages/preview/search/search/components/list.module.scss new file mode 100644 index 0000000..f2d21e8 --- /dev/null +++ b/src/pages/preview/search/search/components/list.module.scss @@ -0,0 +1,32 @@ +.box { + display: flex; + margin-bottom: 20rpx; + background-color: #fff; + border-radius: 16rpx; + padding: 24rpx; + box-sizing: border-box; +} +.image{ + width: 128rpx; + height:128rpx; + background-color: #ededed; + border-radius: 8rpx; +} +.rightBox{ + padding-left: 24rpx; + box-sizing: border-box; + flex: 1; +} +.desc{ + font-size: 24rpx; + font-weight: 500; + color: #909795; + line-height: 34rpx; + display: -webkit-box; + word-break: break-all; + text-overflow: ellipsis; + overflow: hidden; + -webkit-box-orient:vertical; + -webkit-line-clamp:2; +} + diff --git a/src/pages/preview/search/search/components/list.tsx b/src/pages/preview/search/search/components/list.tsx new file mode 100644 index 0000000..184097b --- /dev/null +++ b/src/pages/preview/search/search/components/list.tsx @@ -0,0 +1,106 @@ +import {FC, useCallback, useEffect, useRef, useState} from "react"; +import {ScrollView, View} from "@tarojs/components"; +import styles from './list.module.scss' +import Taro from "@tarojs/taro"; +import Empty from "@/components/empty/empty"; +import Spinner from "@/components/spinner"; +import Img from "@/components/image/image"; +import { SearchApi } from "@/api/search"; + +type Props = { + name:string +} +const SearchList: FC<{name:string}> = ({name}:Props) => { + const globalData = Taro.getApp().globalData + const [page, setPage] = useState(1) + const [brands, setBrands] = useState([]) + const [total, setTotal] = useState(0) + const [text, setText] = useState('') + const [loading, setLoading] = useState(true) + + useEffect(() => { + getData() + }, [page,name]) + + const getData = useCallback(async () => { + try { + console.log(name) + const data = await SearchApi.list(page, 10,name) + if (page === 1) { + if (data.data.length < 10) { + setText('没有更多了~') + } else { + setText('上拉加载更多~') + } + } + setTotal(data.total) + setBrands([ + ...brands, + ...data.data + ]) + } catch (e) { + } + setLoading(false) + }, [page,name]) + + + function jumpInfo(id: number,type:string) { + console.log(type,'type') + let url = '' + switch (type){ + case 'brand': + url = '/pages/preview/brand/info/info'; + break; + case 'illness': + url = '/pages/preview/illness/list/list'; + break; + case 'article': + url = '/pages/preview/illness/article/article' + break + case 'video_record': + url = '/pages/preview/videoFull/videoFull' + break + } + Taro.navigateTo({url: `${url}?id=${id}`}) + + } + + function onScrollToLower(){ + useCallback(() => { + if (brands?.length < total) { + setPage(page + 1) + } else { + setText('没有更多了~') + } + }, [total, brands]) + } + + return ( + + + { + brands.length ? + <> + {brands.map((d) => jumpInfo(d.data.id,d.data.table)} className={styles.box} key={d.data.id}> + + + {d.data.title} + {d.graphic_introduction} + + ) + } + {text} + : + } + + ) +} + +export default SearchList + diff --git a/src/pages/preview/search/search/index.tsx b/src/pages/preview/search/search/index.tsx index b5acc05..75f21da 100644 --- a/src/pages/preview/search/search/index.tsx +++ b/src/pages/preview/search/search/index.tsx @@ -1,15 +1,17 @@ -import {Input, View, Text} from "@tarojs/components"; +import {Input, View, Text, PageContainer} from "@tarojs/components"; import {FC, useState} from "react"; import { AtIcon } from 'taro-ui' import styles from './index.module.scss' import Taro from "@tarojs/taro"; import { useReady, useDidShow } from '@tarojs/taro' +import SearchList from './components/list' const Search:FC = () => { const [value, setValue] = useState('') const [recentSearch, setRecentSearch] = useState([]) const [hotSearch,setHotSearch] = useState([]) + const [show, setShow] = useState(false) useReady(()=>{ console.log('onReady') @@ -31,9 +33,11 @@ const Search:FC = () => { setRecentSearch(Taro.getStorageSync('recentSearch')) } function getSearchItem(value) { - Taro.navigateTo({ - url:`/pages/preview/search/list/index?name=${value}` - }) + setValue(value) + // Taro.navigateTo({ + // url:`/pages/preview/search/list/index?name=${value}` + // }) + setShow(true) } function searchInput(){ @@ -45,6 +49,8 @@ const Search:FC = () => { Taro.setStorageSync('recentSearch', [...new Set(recentSearch)]) } + + return ( @@ -53,7 +59,7 @@ const Search:FC = () => { { - recentSearch.length >= 1 && + recentSearch.length >= 1 && !show && <> 最近搜索 @@ -71,7 +77,7 @@ const Search:FC = () => { } { - hotSearch.length >= 1 && + hotSearch.length >= 1 && !show && <> @@ -91,6 +97,10 @@ const Search:FC = () => { } + { setShow(false)}} show={show} round={true} overlay={true} overlayStyle={'background:rgba(0,0,0,0)'} > + + + ) } diff --git a/src/store/profile.ts b/src/store/profile.ts index abd2846..2d5c293 100644 --- a/src/store/profile.ts +++ b/src/store/profile.ts @@ -53,13 +53,18 @@ function useProfile() { const [company, setCompany] = useState(data?.company || null) - function empty(jump = true) { + function empty(jump = true,relaunch=false) { setUser(null) setUser(null) setToken(null) Taro.removeStorageSync('profile') Taro.clearStorage() - jump && Taro.navigateTo({url: '/pages/login/login'}) + if(relaunch){ + jump && Taro.reLaunch({url: '/pages/my/my'}) + }else{ + jump && Taro.navigateTo({url: '/pages/login/login'}) + + } } useEffect(() => {