Compare commits

...

2 Commits

Author SHA1 Message Date
king 93064963a7 文章修改目录显示 1 year ago
king cecc425f17 我的学习记录 1 year ago
  1. 4
      .env
  2. 3
      src/components/collect/collect.tsx
  3. 7
      src/components/icon/index.tsx
  4. 4
      src/pages/home/components/curRecommended.tsx
  5. 2
      src/pages/home/home.tsx
  6. 3
      src/pages/index/index.tsx
  7. 15
      src/pages/my/components/header/time.tsx
  8. 6
      src/pages/my/my.tsx
  9. 2
      src/pages/preview/brand/article/article.module.scss
  10. 112
      src/pages/preview/brand/article/article.tsx
  11. 18
      src/pages/preview/illness/list/list.tsx
  12. BIN
      src/static/img/catalogue-inactive.png

@ -1,5 +1,5 @@
#TARO_APP_API=https://yjx.dev.yaojiankang.top #TARO_APP_API=https://yjx.dev.yaojiankang.top
#TARO_APP_API=https://mooc.yaojiankang.top TARO_APP_API=https://mooc.yaojiankang.top
TARO_APP_API=https://shopfix.yaojiankang.top #TARO_APP_API=https://shopfix.yaojiankang.top
#TARO_APP_API=https://playedu.yaojiankang.top #TARO_APP_API=https://playedu.yaojiankang.top
TARO_APP_LGOIN=true TARO_APP_LGOIN=true

@ -15,6 +15,7 @@ interface Props {
owner_id: number owner_id: number
owner_type: CreateOwnerType owner_type: CreateOwnerType
textHidden?: boolean textHidden?: boolean
onUpdate?: (v: boolean) => void
} }
/** 收藏 */ /** 收藏 */
@ -37,7 +38,9 @@ const Collect: FC<Props> = (props) => {
console.log(select) console.log(select)
setSelect(!select) setSelect(!select)
setLoading(true) setLoading(true)
// fixme: 动画逻辑不对,应该是先 loading, 然后只有操作成功之后才是 select 动画
await userApi.create({owner_id: props.owner_id, owner_type: props.owner_type}) await userApi.create({owner_id: props.owner_id, owner_type: props.owner_type})
props.onUpdate?.(!select)
setTimeout(() => { setTimeout(() => {
setLoading(false) setLoading(false)
}, 300) }, 300)

@ -213,12 +213,17 @@ export interface IconProps {
size?: string | number size?: string | number
color?: string color?: string
onClick?: (event: ITouchEvent) => void onClick?: (event: ITouchEvent) => void
bold?: boolean
} }
const Icon: FC<IconProps> = (props) => { const Icon: FC<IconProps> = (props) => {
const size = typeof props.size === 'string' ? props.size : `${props.size ?? 16}px` const size = typeof props.size === 'string' ? props.size : `${props.size ?? 16}px`
const color = props.color ?? 'currentColor' const color = props.color ?? 'currentColor'
const fontStyle: CSSProperties = {fontSize: size, color} const fontStyle: CSSProperties = {
fontSize: size,
color,
fontWeight: props.bold ? 'bold' : undefined,
}
return ( return (
<Text className={`icon icon-${props.name}`} style={fontStyle} onClick={props.onClick} /> <Text className={`icon icon-${props.name}`} style={fontStyle} onClick={props.onClick} />

@ -24,7 +24,7 @@ const CurRecommended: FC = () => {
const res = await HomeApi.course(page, 4) const res = await HomeApi.course(page, 4)
setArticles(res.articles) setArticles(res.articles)
setTotal(res.course.total) setTotal(res.course.total)
const newData = res.course.data.reduce((pre, cut) => { const newData = res.course.data?.reduce((pre, cut) => {
const index = pre.findIndex(d => d.id === cut.id) const index = pre.findIndex(d => d.id === cut.id)
if (index === -1) { if (index === -1) {
pre.push(cut) pre.push(cut)
@ -33,7 +33,7 @@ const CurRecommended: FC = () => {
} }
return pre return pre
}, JSON.parse(JSON.stringify(data)) as Curriculum[]) }, JSON.parse(JSON.stringify(data)) as Curriculum[])
setData(newData) setData(newData ?? [])
} }
useEffect(() => { useEffect(() => {

@ -52,7 +52,7 @@ const Home: FC = () => {
leftNode={ leftNode={
<> <>
<Image src={logo} style={{height: "110%"}} mode='heightFix'/> <Image src={logo} style={{height: "110%"}} mode='heightFix'/>
<Text className='font-36 font-weight'></Text> <Text className='font-36 font-weight'></Text>
</> </>
} }
> >

@ -9,6 +9,7 @@ import Spin from "@/components/spinner";
import Img from "@/components/image/image"; import Img from "@/components/image/image";
import {beforeTime} from "@/utils/time"; import {beforeTime} from "@/utils/time";
import {isBoolean} from "@tarojs/shared"; import {isBoolean} from "@tarojs/shared";
import Taro from "@tarojs/taro";
const category: TabList[] = [ const category: TabList[] = [
{title: "企选课程", value: 'is_required'}, {title: "企选课程", value: 'is_required'},
@ -57,7 +58,7 @@ const AuditMode: FC = () => {
<NavigationBar text='文章列表' cancelBack/> <NavigationBar text='文章列表' cancelBack/>
<View className='bg-white rounded-20 clip'> <View className='bg-white rounded-20 clip'>
{ {
articles.map((d, i) => <View className='p-3 relative'> articles.map((d, i) => <View className='p-3 relative' onClick={() => Taro.navigateTo({url: "/pages/preview/brand/article/article?id=" + d.id})}>
{i > 0 && <View className='absolute top left right divided ml-3 mr-3'/>} {i > 0 && <View className='absolute top left right divided ml-3 mr-3'/>}
<View className="font-34 text-black">{d.title}</View> <View className="font-34 text-black">{d.title}</View>
{(d.intro || '').length > 40 && (<View className='flex mt-1'> {(d.intro || '').length > 40 && (<View className='flex mt-1'>

@ -2,7 +2,7 @@ import {Image, View} from "@tarojs/components";
import styles from '../../my.module.scss' import styles from '../../my.module.scss'
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
import {curriculum} from "@/api"; import {curriculum} from "@/api";
import {FC, useState} from "react"; import {FC, useEffect, useState} from "react";
import {formatMinute} from "@/utils/time"; import {formatMinute} from "@/utils/time";
import time1 from "@/static/img/time1.png"; import time1 from "@/static/img/time1.png";
import time2 from "@/static/img/time2.png"; import time2 from "@/static/img/time2.png";
@ -28,20 +28,17 @@ const Time: FC = () => {
// {title: '未完成(必修)', time: '0', src: incomplete, type: 4}, // {title: '未完成(必修)', time: '0', src: incomplete, type: 4},
]) ])
useEffect(() => {
Taro.useDidShow(async () => { curriculum.course().then(res => {
try {
const res = await curriculum.course()
const oldList: List[] = JSON.parse(JSON.stringify(list)) const oldList: List[] = JSON.parse(JSON.stringify(list))
oldList[0].time = formatMinute(res.today_learn_time) oldList[0].time = formatMinute(res.today_learn_time)
oldList[1].time = formatMinute(res.total_learn_time) oldList[1].time = formatMinute(res.total_learn_time)
// oldList[2].time = res.required_count // oldList[2].time = res.required_count
// oldList[3].time = res.not_required_count // oldList[3].time = res.not_required_count
oldList[2].time = res.finished_count // oldList[2].time = res.finished_count
oldList[3].time = res.not_finished_count // oldList[3].time = res.not_finished_count
setList(oldList) setList(oldList)
} catch (e) { })
}
}) })
function jump(type?: number) { function jump(type?: number) {

@ -61,10 +61,10 @@ const My: FC = () => {
Taro.useDidShow(async () => { Taro.useDidShow(async () => {
try { try {
const res = await curriculum.course() const res = await curriculum.course()
setAuditMode(res.audit_mode) setAuditMode(!!res?.audit_mode)
const oldList: List[] = JSON.parse(JSON.stringify(list)) const oldList: List[] = JSON.parse(JSON.stringify(list))
oldList[1].time = res.finished_count || 0 oldList[0].time = res.finished_count || 0
oldList[2].time = res.not_finished_count || 0 oldList[1].time = res.not_finished_count || 0
setList(oldList) setList(oldList)
} catch (e) { } catch (e) {
} }

@ -65,7 +65,7 @@ page{
.article { .article {
font-size: 30rpx; font-size: 30rpx;
display: flex; display: flex;
margin-bottom: 40rpx; //margin-bottom: 40rpx;
} }
.articleImag { .articleImag {

@ -11,8 +11,8 @@ import Spin from "@/components/spinner";
import {beforeTime} from "@/utils/time"; import {beforeTime} from "@/utils/time";
import Img from "@/components/image/image"; import Img from "@/components/image/image";
import Collect from "@/components/collect/collect"; import Collect from "@/components/collect/collect";
import catalogue from "@/static/img/catalogue.png"; import catalogue from "@/static/img/catalogue-inactive.png";
import Icon from "@/components/icon";
const article: FC = () => { const article: FC = () => {
const {token} = Profile.useContainer() const {token} = Profile.useContainer()
@ -25,7 +25,7 @@ const article: FC = () => {
const pageHeight = globalData.windowHeight - globalData.textBarHeight - globalData.statusBarHeight const pageHeight = globalData.windowHeight - globalData.textBarHeight - globalData.statusBarHeight
const {children, headings} = useMemo(() => parse(articleInfo?.content || ''), [articleInfo]) const {children, headings} = useMemo(() => parse(articleInfo?.content || ''), [articleInfo])
const query = Taro.createSelectorQuery() const query = Taro.createSelectorQuery()
const [maoId, setMaoId] = useState('')
useEffect(() => { useEffect(() => {
setTimeout(() => { setTimeout(() => {
@ -39,11 +39,19 @@ const article: FC = () => {
}, 300) }, 300)
}, [children]) }, [children])
useEffect(() => {
if (!maoId && headings.length) {
setMaoId(headings[0].id)
}
}, [headings])
function mao(id: string) { function mao(id: string) {
setMaoId(id)
setShow(false) setShow(false)
Taro.nextTick(() => { Taro.nextTick(() => {
query.select(`#${id}`).boundingClientRect() query.select(`#${id}`).boundingClientRect()
query.exec((res) => { query.exec((res) => {
console.log({res})
if (res.length) { if (res.length) {
Taro.pageScrollTo({ Taro.pageScrollTo({
scrollTop: res[res.length - 1].top, scrollTop: res[res.length - 1].top,
@ -55,6 +63,10 @@ const article: FC = () => {
}) })
} }
const onCollect = (v: boolean | undefined) => {
setArticleInfo((s) => ({...s, collect: v} as ArticleRecord))
}
Taro.useReady(() => { Taro.useReady(() => {
getData().then() getData().then()
}) })
@ -82,13 +94,17 @@ const article: FC = () => {
styles={{flexDirection: 'column', justifyContent: 'center', padding: '20rpx'}} styles={{flexDirection: 'column', justifyContent: 'center', padding: '20rpx'}}
stylesImage={{margin: '0 0 8rpx 0'}} stylesImage={{margin: '0 0 8rpx 0'}}
owner_id={Number(id)} owner_id={Number(id)}
owner_type={1}/> owner_type={1}
onUpdate={onCollect}
/>
</View> </View>
{ {
headings.length > 0 && <View onClick={() => setShow(true)}> headings.length > 0 && (
<Image src={catalogue} mode='widthFix' style={{width: '40rpx', height: '40rpx'}}/> <View className='flex flex-column justify-center align-center' onClick={() => setShow(true)}>
<View></View> <Image src={catalogue} mode='widthFix' style={{width: '40rpx', height: '40rpx'}}/>
</View> <View></View>
</View>
)
} }
</View> </View>
@ -102,22 +118,35 @@ const article: FC = () => {
<View id="childrenNode"> <View id="childrenNode">
<View className={styles.articleTitle}>{articleInfo?.title}</View> <View className={styles.articleTitle}>{articleInfo?.title}</View>
{ {
children.length > 0 ? articleInfo?.brands.map(d => (
<View> <View className='flex align-center mb-4'>
{ <View className={`${styles.article} flex-1`}>
articleInfo?.brands.map(d => <View className={styles.article}> <Img src={d.logo} width={80} height={80} className={styles.articleImag} errorType='avatar'/>
<Img src={d.logo} width={80} height={80} className={styles.articleImag} errorType='avatar'/> <View className='ml-2'>
<View className='ml-2'> <View>{d?.name}</View>
<View>{d?.name}</View> <View className='flex mt-1 text-muted font-24'>
<View className='flex mt-1 text-muted font-24'> <View className='mr-2'>{beforeTime(articleInfo?.created_at)} . </View>
<View className='mr-2'>{beforeTime(articleInfo?.created_at)} . </View> <View> {articleInfo.page_view || 0}</View>
<View> {articleInfo.page_view || 1}</View>
</View>
</View> </View>
</View>) </View>
} </View>
{children} <View className='ml-2'>
<Collect
select={articleInfo?.collect}
styles={{flexDirection: 'column', justifyContent: 'center', padding: '20rpx'}}
stylesImage={{margin: '0 0 8rpx 0'}}
owner_id={Number(id)}
owner_type={1}
textHidden
onUpdate={onCollect}
/>
</View>
</View> </View>
))
}
{
children.length > 0
? <View>{children}</View>
: <Empty name='暂无数据'/> : <Empty name='暂无数据'/>
} }
</View> </View>
@ -138,20 +167,36 @@ const article: FC = () => {
} }
<PageContainer <PageContainer
onClickOverlay={() => setShow(false)} onClickOverlay={() => setShow(false)}
onAfterLeave={() => setShow(false)}
show={show} show={show}
round round
overlay overlay
overlayStyle={'background:rgba(0,0,0,0.3)'}> overlayStyle={'background:rgba(0,0,0,0.3)'}
<View className="px-3 py-5"> >
{ <View>
headings.length > 0 && headings.map((d) => <View <View className='text-center text-black relative clip'>
className="pb-3" <View className='absolute left top bottom flex flex-column justify-center align-center' style={{width: '58px'}} onClick={() => setShow(false)}>
style={{fontSize: '28rpx', fontWeight: '500', color: '#323635'}} <Icon name='close' color="#000" bold />
onClick={() => mao(d.id)}> </View>
{d.text} <View className='py-3 bold'></View>
</View> </View>
) <View className='hr-solid' />
} <View className="px-3 py-5">
{
headings.length > 0 && headings.map((d) => <View
className="pb-3"
style={{
fontSize: '28rpx',
fontWeight: '500',
color: maoId === d.id ? '#45D4A8' : '#323635',
marginLeft: 24*(d.level-1) + 'px',
}}
onClick={() => mao(d.id)}>
{d.text}
</View>
)
}
</View>
</View> </View>
</PageContainer> </PageContainer>
</> </>
@ -160,4 +205,5 @@ const article: FC = () => {
return helloWorld() return helloWorld()
} }
export default article export default article

@ -1,10 +1,11 @@
import {FC, useCallback, useEffect, useState} from "react"; import {FC, useCallback, useEffect, useState} from "react";
import {View} from "@tarojs/components"; import {View} from "@tarojs/components";
import styles from './list.module.scss'
import Taro, {useReachBottom, useRouter} from "@tarojs/taro"; import Taro, {useReachBottom, useRouter} from "@tarojs/taro";
import {illnessApi} from "@/api/illness"; import {illnessApi} from "@/api/illness";
import Empty from "@/components/empty/empty"; import Empty from "@/components/empty/empty";
import Spin from "@/components/spinner"; import Spin from "@/components/spinner";
import Img from "@/components/image/image";
import {beforeTime} from "@/utils/time";
const BrandList: FC = () => { const BrandList: FC = () => {
const params = useRouter().params as unknown as { id: number } const params = useRouter().params as unknown as { id: number }
@ -51,10 +52,19 @@ const BrandList: FC = () => {
{ {
articles.length > 0 ? articles.length > 0 ?
<> <>
<View className='bg-white'> <View className='bg-white rounded-20 clip'>
{ {
articles.map((d, index) => <View key={d.id} className={styles.articles} onClick={() => jump(d.id)}> articles.map((d, i) => <View className='p-3 relative' onClick={() => jump(d.id)}>
{index + 1} . {d.title} {i > 0 && <View className='absolute top left right divided ml-3 mr-3'/>}
<View className="font-34 text-black">{d.title}</View>
{(d.intro || '').length > 40 && (<View className='flex mt-1'>
<View className="flex-1 font-24 lh1_5">{d.intro}</View>
{d.cover && <Img className='ml-l' width={140} height={100} src={d.cover} errorType="acquiesce"/>}
</View>)}
<View className="flex mt-3 justify-between font-24 text-muted">
<View>{beforeTime(d.created_at)}</View>
<View> {d.page_view || 0}</View>
</View>
</View>) </View>)
} }
</View> </View>

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

Loading…
Cancel
Save