Merge remote-tracking branch 'origin/master'

v2
king 1 year ago
commit 4605f01aeb
  1. 4
      src/api/search.ts
  2. 7
      src/components/loginView/index.module.scss
  3. 39
      src/components/loginView/index.tsx
  4. 2
      src/pages/business/userInfo/userInfo.tsx
  5. 3
      src/pages/my/my.module.scss
  6. 20
      src/pages/my/my.tsx
  7. 32
      src/pages/preview/search/search/components/list.module.scss
  8. 106
      src/pages/preview/search/search/components/list.tsx
  9. 22
      src/pages/preview/search/search/index.tsx
  10. 9
      src/store/profile.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")
},
}

@ -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;
}
}

@ -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> = (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> = (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 (
<View className={styles.content} style={sizeStyle}>
<Image src={NoLogin}></Image>
<View className={styles.title}></View>
<View className={styles.label}>{text}</View>
<View onClick={()=>{empty()}} className={styles.button}></View>
<View onClick={()=>{login()}} className={styles.button}></View>
<View className={styles.nextLabel}>使</View>
</View>
)
}

@ -45,7 +45,7 @@ const List = () => {
Taro.showModal({
title: '是否确定退出登录',
success({confirm}) {
confirm && empty()
confirm && empty(true,true)
}
})
}

@ -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;

@ -17,12 +17,15 @@ const My: FC = () => {
const [companyShow, setCompanyShow] = useState(false)
const [companyList, setCompanyList] = useState<Company[]>([])
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'}}></View>
{
companyList.length >= 1 &&
companyList.map(d =>
<View className={styles.box} onClick={async () => {
companyList.map((d,idx) =>
<View className={`${styles.box} ${companyList.length-1 === idx && styles.noBorder} ` } onClick={async () => {
if(company?.id === d.id){
return
}
Taro.showLoading({
title: '切换公司中',
mask: true,

@ -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;
}

@ -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<any[]>([])
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 (
<ScrollView
className='scrollview'
scrollY
scrollWithAnimation
style={{height:`${globalData.windowHeight-60}px`}}
onScrollToLower={onScrollToLower}
>
<Spinner enable={loading} overlay/>
{
brands.length ?
<>
{brands.map((d) => <View onClick={() => jumpInfo(d.data.id,d.data.table)} className={styles.box} key={d.data.id}>
<Img width={128} height={128} src={d.data['@data'].logo} mode='aspectFill' className={styles.image}/>
<View className={styles.rightBox}>
<View className='font-weight mb-2 font-28'>{d.data.title}</View>
<View className={styles.desc}>{d.graphic_introduction}</View>
</View>
</View>)
}
<View style={{width: '710rpx', textAlign: 'center', color: '#999'}} className="font-28 mt-3">{text}</View>
</> : <Empty name='空空如也'/>
}
</ScrollView>
)
}
export default SearchList

@ -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<string[]>([])
const [hotSearch,setHotSearch] = useState<any[]>([])
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 (
<View className="flex flex-column">
<View className={styles.searchBox}>
@ -53,7 +59,7 @@ const Search:FC = () => {
</View>
{
recentSearch.length >= 1 &&
recentSearch.length >= 1 && !show &&
<>
<View className={styles.titleBox} >
<Text className={styles.title}></Text>
@ -71,7 +77,7 @@ const Search:FC = () => {
</>
}
{
hotSearch.length >= 1 &&
hotSearch.length >= 1 && !show &&
<>
<View className={`flex justify-between ${styles.titleBox}`} >
@ -91,6 +97,10 @@ const Search:FC = () => {
</>
}
<PageContainer onClickOverlay={()=>{ setShow(false)}} show={show} round={true} overlay={true} overlayStyle={'background:rgba(0,0,0,0)'} >
<SearchList name={value}/>
</PageContainer>
</View>
)
}

@ -53,13 +53,18 @@ function useProfile() {
const [company, setCompany] = useState<Company | null>(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(() => {

Loading…
Cancel
Save