对接api
This commit is contained in:
parent
e7a130533d
commit
4c46c6e22d
12
src/api/banner.ts
Normal file
12
src/api/banner.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { useRequest } from "@/use/useHttp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取轮播图列表
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const GetBannerList = () => {
|
||||||
|
return useRequest({
|
||||||
|
url: `/v1/mall/carouselBanner/list`,
|
||||||
|
method: "get",
|
||||||
|
})
|
||||||
|
}
|
35
src/api/material.ts
Normal file
35
src/api/material.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { useRequest } from "@/use/useHttp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取面料分类列表
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const GetCategoryList = () => {
|
||||||
|
return useRequest({
|
||||||
|
url: `/v1/mall/category/list`,
|
||||||
|
method: "get",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取面料种类列表
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const GetProductKindListApi = () => {
|
||||||
|
return useRequest({
|
||||||
|
url: `/v1/mall/product/kind/list`,
|
||||||
|
method: "get",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取面料列表
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const GetProductListApi = () => {
|
||||||
|
return useRequest({
|
||||||
|
url: `/v1/mall/product/list`,
|
||||||
|
method: "get",
|
||||||
|
})
|
||||||
|
}
|
@ -1,4 +1,3 @@
|
|||||||
console.log('环境变量2',CURRENT_ENV);
|
|
||||||
// export const BASE_URL = CURRENT_ENV.includes('development') ? `https://test.zzfzyc.com/lymarket` : `https://www.zzfzyc.com/lymarket`
|
// export const BASE_URL = CURRENT_ENV.includes('development') ? `https://test.zzfzyc.com/lymarket` : `https://www.zzfzyc.com/lymarket`
|
||||||
// export const BASE_URL = `http://192.168.0.75:50001/lymarket`
|
// export const BASE_URL = `http://192.168.0.75:50001/lymarket`
|
||||||
// export const BASE_URL = `http://192.168.0.89:50001/lymarket`
|
// export const BASE_URL = `http://192.168.0.89:50001/lymarket`
|
||||||
@ -9,9 +8,6 @@ console.log('环境变量2',CURRENT_ENV);
|
|||||||
export const BASE_URL = `http://192.168.1.30:40001/lymarket` // 发
|
export const BASE_URL = `http://192.168.1.30:40001/lymarket` // 发
|
||||||
// export const BASE_URL = `https://dev.zzfzyc.com/lymarket` // 开发环境
|
// export const BASE_URL = `https://dev.zzfzyc.com/lymarket` // 开发环境
|
||||||
// export const BASE_URL = `https://www.zzfzyc.com/lymarket` // 正式环境
|
// export const BASE_URL = `https://www.zzfzyc.com/lymarket` // 正式环境
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// export const BASE_URL = `http://192.168.1.165:40001/lymarket` // 王霞
|
// export const BASE_URL = `http://192.168.1.165:40001/lymarket` // 王霞
|
||||||
|
|
||||||
// CDN
|
// CDN
|
||||||
@ -27,4 +23,4 @@ export const IMG_CND_Prefix = "http://test.cdn.zzfzyc.com/"
|
|||||||
export const CDN_UPLOAD_IMG = `${UPLOAD_CDN_URL || ''}`;
|
export const CDN_UPLOAD_IMG = `${UPLOAD_CDN_URL || ''}`;
|
||||||
|
|
||||||
//appid
|
//appid
|
||||||
export const WX_APPID = 'wx6c8b9156543480b0'
|
export const WX_APPID = 'wx68d92d7cbf0b6963'
|
51
src/components/banner/index.tsx
Normal file
51
src/components/banner/index.tsx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { Image, Swiper, SwiperItem, View } from "@tarojs/components"
|
||||||
|
import { goLink } from "@/common/common"
|
||||||
|
import {GetBannerList} from "@/api/banner"
|
||||||
|
import styles from './index.module.scss'
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
|
type item = {title:string, img:string, url:string, id:number}
|
||||||
|
|
||||||
|
type params = {
|
||||||
|
list?: item[]
|
||||||
|
swiperOnClick?: (val: item) => void,
|
||||||
|
style?: Object
|
||||||
|
}
|
||||||
|
export default (props:params) => {
|
||||||
|
let {swiperOnClick, style = {}} = props
|
||||||
|
|
||||||
|
const [list, setList] = useState<any[]>([])
|
||||||
|
const {fetchData, state} = GetBannerList()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getData()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const getData = async () => {
|
||||||
|
const res = await fetchData()
|
||||||
|
setList(res.data.list)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View className={styles.swiper_con} style={style}>
|
||||||
|
<Swiper
|
||||||
|
className={styles.xswiper}
|
||||||
|
indicatorColor='#ccc'
|
||||||
|
indicatorActiveColor='#fff'
|
||||||
|
circular
|
||||||
|
indicatorDots
|
||||||
|
autoplay>
|
||||||
|
{
|
||||||
|
list.map(item => {
|
||||||
|
return <SwiperItem key={item.id}>
|
||||||
|
<View className={styles.image_item} onClick={() => goLink(item.link)}>
|
||||||
|
<Image mode="aspectFill" src={item.prev_view_url}></Image>
|
||||||
|
</View>
|
||||||
|
</SwiperItem>
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</Swiper>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
@ -82,7 +82,7 @@ export default memo(({
|
|||||||
{moreStatus&&<View className={style.infinite_scroll}>
|
{moreStatus&&<View className={style.infinite_scroll}>
|
||||||
{
|
{
|
||||||
hasMore&&<View className={style.loading_more}>加载中<DotLoading/></View>||
|
hasMore&&<View className={style.loading_more}>加载中<DotLoading/></View>||
|
||||||
<View>没有更多了</View>
|
<View>没有更多数据了</View>
|
||||||
}
|
}
|
||||||
</View>}
|
</View>}
|
||||||
</View>
|
</View>
|
||||||
|
@ -3,27 +3,27 @@ import Taro from "@tarojs/taro"
|
|||||||
import { goLink } from "@/common/common"
|
import { goLink } from "@/common/common"
|
||||||
import styles from './index.module.scss'
|
import styles from './index.module.scss'
|
||||||
|
|
||||||
type params = {
|
type Params = {
|
||||||
desStatus?: true|false
|
desStatus?: true|false,
|
||||||
|
productList?: any[]
|
||||||
}
|
}
|
||||||
export default ({desStatus = true}: params) => {
|
export default ({desStatus = true, productList = []}:Params) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View className={styles.products_list}>
|
<View className={styles.products_list}>
|
||||||
{new Array(10).fill('').map(item => {
|
{productList.map(item => {
|
||||||
return <View className={styles.products_item} onClick={() => goLink('/pages/details/index?id=1')}>
|
return <View className={styles.products_item} onClick={() => goLink('/pages/details/index?id=1')}>
|
||||||
<View className={styles.item_img}>
|
<View className={styles.item_img}>
|
||||||
<Image src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp01%2F1ZZQ214233446-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651827249&t=b2fc2a3672dc8ced9e0f37ce7e2ff901"/>
|
<Image src={item.texture_url}/>
|
||||||
<View className={styles.num}>230色</View>
|
<View className={styles.num}>{item.product_color_count}色</View>
|
||||||
</View>
|
</View>
|
||||||
<View className={styles.item_con}>
|
<View className={styles.item_con}>
|
||||||
<View className={styles.title}><text>0770#</text>21S单面平纹(食毛)</View>
|
<View className={styles.title}><text>{item.code}#</text>{item.name}</View>
|
||||||
<View className={styles.tag_list}>
|
<View className={styles.tag_list}>
|
||||||
<View className={styles.tag}>160cm</View>
|
<View className={styles.tag}>{item.width}</View>
|
||||||
<View className={styles.tag}>110g</View>
|
<View className={styles.tag}>{item.weight_density}</View>
|
||||||
</View>
|
</View>
|
||||||
<View className={styles.introduce}>67.6%棉24%涤纶6.4%氨纶</View>
|
<View className={styles.introduce}>{item.component}</View>
|
||||||
{desStatus&&<View className={styles.des}>产品描述产品描述产品描述产品描述产品描述</View>}
|
{desStatus&&<View className={styles.des}>{item.describe}</View>}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
})}
|
})}
|
||||||
|
@ -1,24 +1,23 @@
|
|||||||
import { ScrollView, View } from "@tarojs/components"
|
import { ScrollView, View } from "@tarojs/components"
|
||||||
import { memo, ReactNode, useRef, useState } from "react"
|
import { memo, ReactNode, useEffect, useRef, useState } from "react"
|
||||||
import styles from "./index.module.scss"
|
import styles from "./index.module.scss"
|
||||||
import classnames from "classnames";
|
import classnames from "classnames";
|
||||||
import Taro, { useReady } from "@tarojs/taro";
|
import Taro, { useReady } from "@tarojs/taro";
|
||||||
import InfiniteScroll from "../infiniteScroll";
|
import InfiniteScroll from "../infiniteScroll";
|
||||||
|
|
||||||
type ListProps = {
|
|
||||||
title: string,
|
|
||||||
value: number
|
|
||||||
}
|
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
list?: ListProps[],
|
list?: any[],
|
||||||
defaultValue?: number|string,
|
defaultValue?: number|string,
|
||||||
children?: ReactNode,
|
children?: ReactNode,
|
||||||
height?: string,
|
height?: string,
|
||||||
heightItem?: number,
|
heightItem?: number,
|
||||||
sideBarOnClick?: (ListProps) => void,
|
sideBarOnClick?: (val:any) => void,
|
||||||
refresherTriggered?: true|false,
|
refresherTriggered?: true|false,
|
||||||
selfOnRefresherRefresh?: () => void
|
selfOnRefresherRefresh?: () => void
|
||||||
|
selfOnScrolltolower?: () => void,
|
||||||
|
hasMore?: true|false
|
||||||
}
|
}
|
||||||
|
|
||||||
export default memo(({list = [],
|
export default memo(({list = [],
|
||||||
@ -28,7 +27,9 @@ export default memo(({list = [],
|
|||||||
children,
|
children,
|
||||||
heightItem = 100,
|
heightItem = 100,
|
||||||
refresherTriggered = false,
|
refresherTriggered = false,
|
||||||
selfOnRefresherRefresh
|
selfOnRefresherRefresh,
|
||||||
|
selfOnScrolltolower,
|
||||||
|
hasMore = true
|
||||||
}: Params) => {
|
}: Params) => {
|
||||||
|
|
||||||
let num_half = useRef(0)
|
let num_half = useRef(0)
|
||||||
@ -36,17 +37,21 @@ export default memo(({list = [],
|
|||||||
const [selected, setSelected] = useState(defaultValue)
|
const [selected, setSelected] = useState(defaultValue)
|
||||||
const [tabId, setTabId] = useState('')
|
const [tabId, setTabId] = useState('')
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSelected(defaultValue)
|
||||||
|
}, [defaultValue])
|
||||||
|
|
||||||
const init = () => {
|
const init = () => {
|
||||||
const index = list?.findIndex(item => {
|
const index = list?.findIndex(item => {
|
||||||
return item.value == defaultValue
|
return item.id == defaultValue
|
||||||
})
|
})
|
||||||
if(index !== -1) {
|
if(index !== -1) {
|
||||||
computeSelectTab(index)
|
computeSelectTab(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const clickEvent = ({item, index}: {item:ListProps, index:number}) => {
|
const clickEvent = ({item, index}: {item, index:number}) => {
|
||||||
setSelected(item.value)
|
setSelected(item.id)
|
||||||
sideBarOnClick?.(item)
|
sideBarOnClick?.(item)
|
||||||
computeSelectTab(index)
|
computeSelectTab(index)
|
||||||
}
|
}
|
||||||
@ -54,9 +59,10 @@ export default memo(({list = [],
|
|||||||
const computeSelectTab = (index) => {
|
const computeSelectTab = (index) => {
|
||||||
if((index + 1) > num_half.current) {
|
if((index + 1) > num_half.current) {
|
||||||
let num = index + 1 - num_half.current
|
let num = index + 1 - num_half.current
|
||||||
setTabId(list[num].value.toString())
|
setTabId(list[num].id.toString())
|
||||||
} else {
|
} else {
|
||||||
setTabId(list[0].value.toString())
|
setTabId(list[0].id.toString())
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,10 +81,7 @@ export default memo(({list = [],
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
//触底事件
|
|
||||||
const onScrolltolower = () => {
|
|
||||||
console.log('触底了')
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -88,14 +91,14 @@ export default memo(({list = [],
|
|||||||
list?.map((item, index) => {
|
list?.map((item, index) => {
|
||||||
return(
|
return(
|
||||||
<View
|
<View
|
||||||
className={classnames(styles.sideBar_select_title, {[styles.sideBar_select_title_select]:(selected == item.value)})}
|
className={classnames(styles.sideBar_select_title, {[styles.sideBar_select_title_select]:(selected == item.id)})}
|
||||||
onClick={() => clickEvent({item, index})}
|
onClick={() => clickEvent({item, index})}
|
||||||
id={`tab_${item.value}`}
|
id={`tab_${item.id}`}
|
||||||
key={item.value}
|
key={item.id}
|
||||||
style={{height:heightItem+'rpx'}}
|
style={{height:heightItem+'rpx'}}
|
||||||
>
|
>
|
||||||
<View className={styles.title_con}>
|
<View className={styles.title_con}>
|
||||||
{item.title}
|
{item.name}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
@ -104,7 +107,7 @@ export default memo(({list = [],
|
|||||||
<View className="common_safe_area_y"></View>
|
<View className="common_safe_area_y"></View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<View className={styles.sideBar_con}>
|
<View className={styles.sideBar_con}>
|
||||||
<InfiniteScroll selfonScrollToLower={() => onScrolltolower()} refresherTriggered={refresherTriggered} refresherEnabled={true} selfOnRefresherRefresh={() => selfOnRefresherRefresh?.()}>
|
<InfiniteScroll hasMore={hasMore} selfonScrollToLower={() => selfOnScrolltolower?.()} refresherTriggered={refresherTriggered} refresherEnabled={true} selfOnRefresherRefresh={() => selfOnRefresherRefresh?.()}>
|
||||||
{children}
|
{children}
|
||||||
</InfiniteScroll>
|
</InfiniteScroll>
|
||||||
</View>
|
</View>
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
import { Image, Swiper, SwiperItem, View } from "@tarojs/components"
|
|
||||||
import { goLink } from "@/common/common"
|
|
||||||
import Taro from "@tarojs/taro"
|
|
||||||
import styles from './index.module.scss'
|
|
||||||
|
|
||||||
type item = {title:string, img:string, url:string, id:number}
|
|
||||||
|
|
||||||
type params = {
|
|
||||||
list?: item[]
|
|
||||||
swiperOnClick?: (val: item) => void,
|
|
||||||
style?: Object
|
|
||||||
}
|
|
||||||
export default (props:params) => {
|
|
||||||
let {list = [], swiperOnClick, style = {}} = props
|
|
||||||
list = [
|
|
||||||
{
|
|
||||||
title:'数据',
|
|
||||||
img:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F811%2F021315104H2%2F150213104H2-3-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817947&t=5467a207f845ddfc7737d55934e6b26d',
|
|
||||||
url:'',
|
|
||||||
id:1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title:'数据',
|
|
||||||
img:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F811%2F021315104H2%2F150213104H2-3-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817947&t=5467a207f845ddfc7737d55934e6b26d',
|
|
||||||
url:'',
|
|
||||||
id:2
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View className={styles.swiper_con} style={style}>
|
|
||||||
<Swiper
|
|
||||||
className={styles.xswiper}
|
|
||||||
indicatorColor='#ccc'
|
|
||||||
indicatorActiveColor='#fff'
|
|
||||||
circular
|
|
||||||
indicatorDots
|
|
||||||
autoplay>
|
|
||||||
{
|
|
||||||
list.map(item => {
|
|
||||||
return <SwiperItem key={item.id}>
|
|
||||||
<View className={styles.image_item} onClick={() => goLink(`/pages/classList/index?id=${item.id}`)}>
|
|
||||||
<Image mode="aspectFill" src={item.img}></Image>
|
|
||||||
</View>
|
|
||||||
</SwiperItem>
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</Swiper>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
@ -1,15 +1,16 @@
|
|||||||
import { Image, Swiper, SwiperItem, View } from "@tarojs/components"
|
import { Image, Swiper, SwiperItem, View } from "@tarojs/components"
|
||||||
import { useMemo, useState } from "react"
|
import { useMemo, useRef, useState } from "react"
|
||||||
import styles from './index.module.scss'
|
import styles from './index.module.scss'
|
||||||
|
|
||||||
type item = {title:string, img:string, url:string, id:number}
|
type item = {title:string, img:string, url:string, id:number}
|
||||||
|
|
||||||
type params = {
|
type params = {
|
||||||
list?: item[]
|
list?: item[]
|
||||||
}
|
}
|
||||||
export default ({list = []}: params) => {
|
export default ({list = []}: params) => {
|
||||||
|
|
||||||
const [pageIndex, setPageIndex] = useState(1)
|
const [pageIndex, setPageIndex] = useState(1)
|
||||||
|
const pageRef = useRef<any>(null)
|
||||||
|
|
||||||
const pageCount = useMemo(() => {
|
const pageCount = useMemo(() => {
|
||||||
return list.length
|
return list.length
|
||||||
@ -17,8 +18,10 @@ export default ({list = []}: params) => {
|
|||||||
|
|
||||||
const swiperChange = (e) => {
|
const swiperChange = (e) => {
|
||||||
setPageIndex(e.detail.current + 1)
|
setPageIndex(e.detail.current + 1)
|
||||||
|
pageRef.current.innerHTML = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View className={styles.swiper}>
|
<View className={styles.swiper}>
|
||||||
<Swiper className={styles.swiper_item} circular={true} onAnimationFinish={(e) => swiperChange(e)}>
|
<Swiper className={styles.swiper_item} circular={true} onAnimationFinish={(e) => swiperChange(e)}>
|
||||||
@ -30,7 +33,7 @@ export default ({list = []}: params) => {
|
|||||||
</SwiperItem>
|
</SwiperItem>
|
||||||
})}
|
})}
|
||||||
</Swiper>
|
</Swiper>
|
||||||
<View className={styles.page}>{pageIndex+'/'+pageCount}</View>
|
<View className={styles.page} ref={pageRef}>{pageIndex+'/'+pageCount}</View>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -11,6 +11,7 @@ import { useEffect, useMemo, useState } from 'react';
|
|||||||
import useManualPullDownRefresh from '@/use/useManualPullDownRefresh';
|
import useManualPullDownRefresh from '@/use/useManualPullDownRefresh';
|
||||||
import { goLink } from '@/common/common';
|
import { goLink } from '@/common/common';
|
||||||
import useUserInfo from '@/use/useUserInfo';
|
import useUserInfo from '@/use/useUserInfo';
|
||||||
|
|
||||||
type item = {title:string, img:string, url:string, id:number}
|
type item = {title:string, img:string, url:string, id:number}
|
||||||
|
|
||||||
type params = {
|
type params = {
|
||||||
@ -48,9 +49,6 @@ export default (props:params) => {
|
|||||||
|
|
||||||
|
|
||||||
const [showOrderCount, setShowOrderCount] = useState(false)
|
const [showOrderCount, setShowOrderCount] = useState(false)
|
||||||
// const showCartmemo = useMemo(() => {
|
|
||||||
// return showCart
|
|
||||||
// },[showCart])
|
|
||||||
|
|
||||||
const html = `<h1>这里是详情</h1>
|
const html = `<h1>这里是详情</h1>
|
||||||
<div style="font-size:13px">你好啊啊</div>
|
<div style="font-size:13px">你好啊啊</div>
|
||||||
@ -106,6 +104,7 @@ export default (props:params) => {
|
|||||||
|
|
||||||
const {user} = useUserInfo()
|
const {user} = useUserInfo()
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View className={styles.main}>
|
<View className={styles.main}>
|
||||||
<DesSwiper list={list}/>
|
<DesSwiper list={list}/>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {View} from '@tarojs/components'
|
import {View} from '@tarojs/components'
|
||||||
import Swiper from '@/components/swiper'
|
import Banner from '@/components/banner'
|
||||||
import Search from '@/components/search'
|
import Search from '@/components/search'
|
||||||
import SideBar from '@/components/sideBar'
|
import SideBar from '@/components/sideBar'
|
||||||
import Product from '@/components/product'
|
import Product from '@/components/product'
|
||||||
@ -7,50 +7,77 @@ import MoveBtn from '@/components/moveBtn'
|
|||||||
import ShopCart from '@/components/shopCart'
|
import ShopCart from '@/components/shopCart'
|
||||||
import styles from './index.module.scss'
|
import styles from './index.module.scss'
|
||||||
import { goLink } from '@/common/common'
|
import { goLink } from '@/common/common'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import Taro, { useDidShow, usePullDownRefresh, useRouter } from '@tarojs/taro'
|
import Taro, { useDidShow, usePullDownRefresh, useRouter } from '@tarojs/taro'
|
||||||
import useManualPullDownRefresh from '@/use/useManualPullDownRefresh'
|
import useManualPullDownRefresh from '@/use/useManualPullDownRefresh'
|
||||||
import useUserInfo from '@/use/useUserInfo'
|
import {GetProductKindListApi, GetProductListApi} from '@/api/material'
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const tabs_list = [
|
|
||||||
{title:'平纹系列', value: 1},
|
|
||||||
{title:'平纹系列', value: 2},
|
useEffect(() => {
|
||||||
{title:'平纹系列', value: 3},
|
categoryList()
|
||||||
{title:'平纹系列', value: 4},
|
}, [])
|
||||||
{title:'平纹系列', value: 5},
|
|
||||||
{title:'平纹系列', value: 6},
|
//获取面料种类
|
||||||
{title:'平纹系列', value: 7},
|
const [kindData, setKindData] = useState<any>({list:[], defaultId:0})
|
||||||
{title:'平纹系列', value: 8},
|
const {fetchData} = GetProductKindListApi()
|
||||||
{title:'平纹系列', value: 9},
|
const categoryList = async () => {
|
||||||
{title:'平纹系列', value: 10},
|
const res = await fetchData()
|
||||||
{title:'平纹系列', value: 11},
|
setKindData({...kindData, list:res.data.list, defaultId: res.data.list[0].id})
|
||||||
{title:'平纹系列', value: 12},
|
filtrate.current.product_kind_id = res.data.list[0].id
|
||||||
{title:'平纹系列', value: 13},
|
getProductList()
|
||||||
{title:'平纹系列', value: 14},
|
}
|
||||||
{title:'平纹系列', value: 15},
|
|
||||||
{title:'平纹系列', value: 16},
|
//获取面料列表
|
||||||
{title:'平纹系列', value: 17},
|
const [productData, setProductData] = useState({list:[], total:0, hasMore:true})
|
||||||
]
|
const filtrate = useRef({product_kind_id:0, size: 5,page: 1})
|
||||||
|
const pageNum = useRef(1)
|
||||||
|
const {fetchData: productFetchData, state: productState} = GetProductListApi()
|
||||||
|
const getProductKindId = async (e) => {
|
||||||
|
filtrate.current.size = 5
|
||||||
|
pageNum.current = 1
|
||||||
|
filtrate.current.product_kind_id = e.id
|
||||||
|
getProductList()
|
||||||
|
}
|
||||||
|
const getProductList = async () => {
|
||||||
|
filtrate.current.size = filtrate.current.size * pageNum.current
|
||||||
|
const {data,total} = await productFetchData(filtrate.current)
|
||||||
|
setProductData({...productData,list:data.list,total})
|
||||||
|
}
|
||||||
|
|
||||||
|
//上拉加载数据
|
||||||
|
const getScrolltolower = () => {
|
||||||
|
if(productData.list.length >= productData.total) {
|
||||||
|
setProductData({...productData, hasMore: false})
|
||||||
|
} else {
|
||||||
|
pageNum.current++
|
||||||
|
getProductList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const [showShopCart, setShowShopCart] = useState(false)
|
const [showShopCart, setShowShopCart] = useState(false)
|
||||||
|
|
||||||
|
//列表下拉刷新
|
||||||
|
const [refresherTriggeredStatus, setRefresherTriggeredStatus] = useState(false)
|
||||||
|
const getRefresherRefresh = async () => {
|
||||||
|
filtrate.current.size = 5
|
||||||
|
pageNum.current = 1
|
||||||
|
getProductList()
|
||||||
|
}
|
||||||
|
useEffect(() => {
|
||||||
|
setRefresherTriggeredStatus(productState.loading)
|
||||||
|
}, [productState.loading])
|
||||||
|
|
||||||
//页面下拉刷新
|
//页面下拉刷新
|
||||||
const res = useManualPullDownRefresh()
|
const res = useManualPullDownRefresh()
|
||||||
|
|
||||||
const [refresherTriggeredStatus, setRefresherTriggeredStatus] = useState(false)
|
|
||||||
const getData = () => {
|
|
||||||
setRefresherTriggeredStatus(true)
|
|
||||||
setTimeout(() => {
|
|
||||||
setRefresherTriggeredStatus(() => false)
|
|
||||||
console.log('12123')
|
|
||||||
}, 1000)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MoveBtn onClick={() => setShowShopCart(!showShopCart)}>
|
<MoveBtn onClick={() => setShowShopCart(!showShopCart)}>
|
||||||
<View className={styles.main}>
|
<View className={styles.main}>
|
||||||
<Swiper/>
|
<Banner/>
|
||||||
<View className={styles.search}>
|
<View className={styles.search}>
|
||||||
<View className={styles.search_collect}>我的收藏</View>
|
<View className={styles.search_collect}>我的收藏</View>
|
||||||
<View className={styles.search_input}>
|
<View className={styles.search_input}>
|
||||||
@ -58,8 +85,8 @@ export default () => {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View className={styles.products}>
|
<View className={styles.products}>
|
||||||
<SideBar list={tabs_list} height="100%" heightItem={150} refresherTriggered={refresherTriggeredStatus} selfOnRefresherRefresh={() => getData()}>
|
<SideBar list={kindData.list} height="100%" defaultValue={kindData.defaultId} hasMore={productData.hasMore} selfOnScrolltolower={() => getScrolltolower()} sideBarOnClick={(e) => getProductKindId(e)} heightItem={150} refresherTriggered={refresherTriggeredStatus} selfOnRefresherRefresh={() => getRefresherRefresh()}>
|
||||||
<Product/>
|
<Product productList={productData.list}/>
|
||||||
</SideBar>
|
</SideBar>
|
||||||
</View>
|
</View>
|
||||||
<View className='common_safe_area_y'></View>
|
<View className='common_safe_area_y'></View>
|
||||||
|
@ -11,11 +11,14 @@ export default ({onBlur, onSave}:Param) => {
|
|||||||
const [descData, setDescData] = useState({
|
const [descData, setDescData] = useState({
|
||||||
number: 0,
|
number: 0,
|
||||||
value: '',
|
value: '',
|
||||||
count: 10
|
count: 200
|
||||||
})
|
})
|
||||||
const getDesc = useCallback((e) => {
|
const getDesc = useCallback((e) => {
|
||||||
let value = e.detail.value
|
let value = e.detail.value
|
||||||
let res = value.slice(0, descData.count)
|
let res = value
|
||||||
|
if(value.length > descData.count) {
|
||||||
|
res = value.slice(0, descData.count)
|
||||||
|
}
|
||||||
setDescData({...descData, number:res.length, value: res})
|
setDescData({...descData, number:res.length, value: res})
|
||||||
},[])
|
},[])
|
||||||
|
|
||||||
@ -26,7 +29,7 @@ export default ({onBlur, onSave}:Param) => {
|
|||||||
<View className={styles.order_popup}>
|
<View className={styles.order_popup}>
|
||||||
<View className={styles.order_popup_title}>添加备注</View>
|
<View className={styles.order_popup_title}>添加备注</View>
|
||||||
<View className={styles.order_popup_input}>
|
<View className={styles.order_popup_input}>
|
||||||
<Textarea placeholder="请添加备注" maxlength={10} cursorSpacing={100} onInput={(e) => getDesc(e)} onBlur={(e) => onBlur?.(e)}></Textarea>
|
<Textarea placeholder="请添加备注" maxlength={descData.count} cursorSpacing={100} onInput={(e) => getDesc(e)} onBlur={(e) => onBlur?.(e)}></Textarea>
|
||||||
<View className={styles.descDataNum}>{descData.number}/{descData.count}</View>
|
<View className={styles.descDataNum}>{descData.number}/{descData.count}</View>
|
||||||
</View>
|
</View>
|
||||||
<View className={styles.order_save_address} onClick={() => setSave()}>保存</View>
|
<View className={styles.order_save_address} onClick={() => setSave()}>保存</View>
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
|
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
import { SET_USERINFO, SET_TOKEN, SET_SESSIONKEY, CLEAR_TOKEN, CLEAR_USERINFO, CLEAR_SESSIONKEY} from '../constants/userInfo'
|
import {
|
||||||
|
SET_USERINFO,
|
||||||
|
SET_TOKEN,
|
||||||
|
SET_SESSIONKEY,
|
||||||
|
CLEAR_TOKEN,
|
||||||
|
CLEAR_USERINFO,
|
||||||
|
CLEAR_SESSIONKEY
|
||||||
|
} from '../constants/userInfo'
|
||||||
|
|
||||||
export type UserParam = {
|
export type UserParam = {
|
||||||
name?:string,
|
name?:string,
|
||||||
@ -8,16 +15,18 @@ export type UserParam = {
|
|||||||
avatarUrl?:string,
|
avatarUrl?:string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DataParam = {
|
||||||
|
token?: string
|
||||||
|
sessionkey?: string,
|
||||||
|
userInfo: UserParam
|
||||||
|
}
|
||||||
|
|
||||||
type Action = {
|
type Action = {
|
||||||
type?: string,
|
type?: string,
|
||||||
data?: DataParam
|
data?: DataParam
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DataParam = {
|
|
||||||
token?: string
|
|
||||||
sessionkey?: string,
|
|
||||||
userInfo: UserParam
|
|
||||||
}
|
|
||||||
|
|
||||||
const INIT_USER = {
|
const INIT_USER = {
|
||||||
userInfo: Taro.getStorageSync('userInfo')?JSON.parse(Taro.getStorageSync('userInfo')):null,
|
userInfo: Taro.getStorageSync('userInfo')?JSON.parse(Taro.getStorageSync('userInfo')):null,
|
||||||
|
@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
import { useRef, useState } from 'react'
|
import { useRef, useState } from 'react'
|
||||||
|
import {BASE_URL} from '@/common/constant'
|
||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
code: string|null
|
code: string|null
|
||||||
success: true|false
|
success: true|false
|
||||||
@ -24,6 +23,16 @@ type Params = {
|
|||||||
pageSize?: number
|
pageSize?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type option = {
|
||||||
|
url?: string,
|
||||||
|
method?: 'get'|'post'|'put'|'delete',
|
||||||
|
type?: string,
|
||||||
|
data?: any,
|
||||||
|
page?: number,
|
||||||
|
pageSize?: number,
|
||||||
|
pagination?: true|false
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回状态信息,根据 http 状态错
|
* 返回状态信息,根据 http 状态错
|
||||||
* @param {Number} status
|
* @param {Number} status
|
||||||
@ -80,7 +89,7 @@ const showStatus = (status) => {
|
|||||||
* @param {Object} options.data 请求的参数
|
* @param {Object} options.data 请求的参数
|
||||||
* @returns {Object} 返回fetch(), loading, error, code, msg
|
* @returns {Object} 返回fetch(), loading, error, code, msg
|
||||||
*/
|
*/
|
||||||
export const useRequest = (options = {
|
export const useRequest = (options:option = {
|
||||||
url: '/',
|
url: '/',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
type: 'json',
|
type: 'json',
|
||||||
@ -90,7 +99,7 @@ export const useRequest = (options = {
|
|||||||
pagination: false, // 是否分页
|
pagination: false, // 是否分页
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
|
options.url = `${BASE_URL}${options.url}`
|
||||||
let params:Params = {
|
let params:Params = {
|
||||||
code: null, // 业务码
|
code: null, // 业务码
|
||||||
success: false, // 请求是否成功
|
success: false, // 请求是否成功
|
||||||
@ -110,43 +119,8 @@ export const useRequest = (options = {
|
|||||||
const stateRef = useRef({...params})
|
const stateRef = useRef({...params})
|
||||||
const [state, setState] = useState({...stateRef.current})
|
const [state, setState] = useState({...stateRef.current})
|
||||||
|
|
||||||
// // 每页多少条记录
|
|
||||||
// const handleSizeChange = (val) => {
|
|
||||||
// state.size = val
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // 当前
|
|
||||||
// const handleCurrentChange = (val) => {
|
|
||||||
// state.page = val
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 筛选搜索
|
|
||||||
// * @param {Object} val `{name:'ppx'}` name 为字段名,ppx 为字段内容
|
|
||||||
// */
|
|
||||||
// const handleFilterChange = (val) => {
|
|
||||||
// state.filter = val
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 排序
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 排序字段,排序方式
|
|
||||||
* @param {String} val 排序字段
|
|
||||||
* @param {String} sortOrder `desc` / `asc`
|
|
||||||
*/
|
|
||||||
// eslint-disable-next-line
|
|
||||||
const handleSort = (val, orderby = "desc") => {
|
|
||||||
if (val != null) {
|
|
||||||
stateRef.current.sort = orderby ? {
|
|
||||||
sort_key: `${orderby == 'desc' ? '-' + val : val}`
|
|
||||||
} : null
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 请求函数
|
// 请求函数
|
||||||
const fetchData = async (sub_options) => {
|
const fetchData = async (sub_options?:any) => {
|
||||||
stateRef.current.loading = true
|
stateRef.current.loading = true
|
||||||
setState((e) => ({...e, loading:true}))
|
setState((e) => ({...e, loading:true}))
|
||||||
stateRef.current.query = {
|
stateRef.current.query = {
|
||||||
@ -164,7 +138,7 @@ export const useRequest = (options = {
|
|||||||
...options,
|
...options,
|
||||||
...{
|
...{
|
||||||
header: {
|
header: {
|
||||||
"Platform": 3,
|
"Platform": 6,
|
||||||
"Authorization": token || stateRef.current.token,
|
"Authorization": token || stateRef.current.token,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -214,7 +188,6 @@ export const useRequest = (options = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
handleSort,
|
|
||||||
fetchData,
|
fetchData,
|
||||||
state,
|
state,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user