diff --git a/.env b/.env index 1eee7ad..064f56f 100644 --- a/.env +++ b/.env @@ -1,4 +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://playedu.yaojiankang.top TARO_APP_LGOIN=true diff --git a/src/api/home.ts b/src/api/home.ts new file mode 100644 index 0000000..7ce586d --- /dev/null +++ b/src/api/home.ts @@ -0,0 +1,37 @@ +import {request} from "@/api/request"; + +export interface AdwareParams { + key: string + value: string + + [key: string]: string +} + +export interface AdwareLinkType { + id: number + api_name: string + path: string + param: string +} + +export interface AdwareType { + advert_link: AdwareLinkType + scope_id: number | string + id: number + name: string + status: 0 | 1 // 禁用 + sort: number + image_url: string + image_link: string + start_time: number + end_time?: number +} + +export const HomeApi = { + advert(only_flag: string) { + return request("/home/v1/advert/unique?only_flag=" + only_flag, "GET") + }, + course(page: number, page_size: number) { + return request<{ data: Curriculum[], total: number }>('/home/v1/course/course', "GET", {page, page_size}) + } +} diff --git a/src/api/index.ts b/src/api/index.ts index bfc8739..341ea63 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -5,3 +5,4 @@ export * from './meeting' export * from './public' export * from './manage' export * from './course' +export * from './home' diff --git a/src/app.config.ts b/src/app.config.ts index 84acf9c..7ee6f9d 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -26,8 +26,8 @@ export default defineAppConfig({ { text: '学习', pagePath: 'pages/index/index', - iconPath: "static/tabs/home-unselect.png", - selectedIconPath: "static/tabs/home-selected.png", + iconPath: "static/tabs/study.png", + selectedIconPath: "static/tabs/study-selected.png", }, { text: "我的", diff --git a/src/components/popPut/popPut.tsx b/src/components/popPut/popPut.tsx index ea557ca..4184ffc 100644 --- a/src/components/popPut/popPut.tsx +++ b/src/components/popPut/popPut.tsx @@ -46,7 +46,7 @@ const PopPut: FC = ({title, chevron, content, image, isProp, children, sh <> - {opt.leftImage && } + {opt.leftImage != null && } {title} diff --git a/src/pages/home/components/adware.tsx b/src/pages/home/components/adware.tsx new file mode 100644 index 0000000..705563b --- /dev/null +++ b/src/pages/home/components/adware.tsx @@ -0,0 +1,51 @@ +import {Image, Swiper, SwiperItem, View} from "@tarojs/components"; +import {FC, useState} from "react"; +import {AdwareType, HomeApi} from "@/api"; +import Taro from "@tarojs/taro"; +import styles from '../home.module.scss' +import {jumpAdware} from "@/utils/pathFormt"; + +const Adware: FC = () => { + const [data, setData] = useState([]) + + async function getAdware() { + const res = await HomeApi.advert('home_swiper') + setData(res) + } + + Taro.useLoad(getAdware) + + return ( + + { + data.length === 1 && jumpAdware(data[0].advert_link)} + className={styles.adware}/> + } + { + data.length > 1 && + {data.map(d => + jumpAdware(d.advert_link)} + style={{width: "100%"}}/> + )} + + } + + ) +} + +export default Adware diff --git a/src/pages/home/components/curRecommended.tsx b/src/pages/home/components/curRecommended.tsx new file mode 100644 index 0000000..8862d61 --- /dev/null +++ b/src/pages/home/components/curRecommended.tsx @@ -0,0 +1,59 @@ +import {FC, useEffect, useState} from "react"; +import {Image, View} from "@tarojs/components"; +import {HomeApi} from "@/api"; +import {useReachBottom} from "@tarojs/taro"; +import styles from "../home.module.scss"; +import VideoCover from "@/components/videoCover/videoCover"; +import courseTag from '@/static/img/courseTag.png' + +const CurRecommended: FC = () => { + const [page, setPage] = useState(1) + const [data, setData] = useState([]) + const [total, setTotal] = useState(0) + + async function getData() { + const res = await HomeApi.course(page, 4) + setTotal(res.total) + const newData = res.data.reduce((pre, cut) => { + const index = pre.findIndex(d => d.id === cut.id) + if (index === 1) { + pre.push(cut) + } else { + pre.splice(index, 1, cut) + } + return pre + }, data) + setData(newData) + } + + useEffect(() => { + getData() + }, [page]) + + useReachBottom(() => { + data.length < total && setPage(page + 1) + }) + + return ( + <> + { + data.length > 0 && + + + { + data.map(c => ) + } + + + } + + ) +} + +export default CurRecommended diff --git a/src/pages/home/components/feature.tsx b/src/pages/home/components/feature.tsx new file mode 100644 index 0000000..8e98b25 --- /dev/null +++ b/src/pages/home/components/feature.tsx @@ -0,0 +1,33 @@ +import {FC} from "react"; +import {Image, View} from "@tarojs/components"; +import illness from '@/static/img/illness.png' +import profession from '@/static/img/profession.png' +import health from '@/static/img/health.png' +import article from '@/static/img/article.png' +import Taro from "@tarojs/taro"; + +const Feature: FC = () => { + const list = [ + {url: '', image: article, text: '品牌'}, + {url: '', image: health, text: '健康管理'}, + {url: '', image: profession, text: '专业技能'}, + {url: '', image: illness, text: '疾病知识'}, + ] + + function jump(url) { + Taro.navigateTo({url}) + } + + return ( + + { + list.map(d => jump(d.url)}> + + {d.text} + ) + } + + ) +} + +export default Feature diff --git a/src/pages/home/components/feature_recommended.tsx b/src/pages/home/components/feature_recommended.tsx new file mode 100644 index 0000000..507bc35 --- /dev/null +++ b/src/pages/home/components/feature_recommended.tsx @@ -0,0 +1,43 @@ +import {FC, useState} from "react"; +import {Swiper, SwiperItem, View} from "@tarojs/components"; +import styles from '../home.module.scss' +import Taro from "@tarojs/taro"; + +interface DataContent { + id: number, + title: string, + Description: string +} + +interface Data { + title: string, + url: string, + data: DataContent[] +} + +const FeatureRecommended: FC = () => { + const [data] = useState([ + {title: "品牌TOP3", url: '', data: []}, + {title: "健康", url: '', data: []}, + {title: "专业技能", url: '', data: []}, + {title: "疾病知识", url: '', data: []}, + ]) + + function jump(url: string) { + Taro.navigateTo({url}) + } + + + return ( + + + { + data.map(d => + jump(d.url)}>{d.title} + ) + } + + + ) +} +export default FeatureRecommended diff --git a/src/pages/home/components/search.tsx b/src/pages/home/components/search.tsx new file mode 100644 index 0000000..7910e33 --- /dev/null +++ b/src/pages/home/components/search.tsx @@ -0,0 +1,13 @@ +import {FC} from "react"; +import {Text, View} from "@tarojs/components"; +import styles from "../home.module.scss"; +import Icon from "@/components/icon"; + +export const Search: FC = () => { + return ( + + + 搜索课程 + + ) +} diff --git a/src/pages/home/home.config.ts b/src/pages/home/home.config.ts index d178761..3ad5d8a 100644 --- a/src/pages/home/home.config.ts +++ b/src/pages/home/home.config.ts @@ -1,4 +1,5 @@ export default definePageConfig({ navigationBarTitleText: '首页', navigationStyle: 'custom', + onReachBottomDistance: 30 }) diff --git a/src/pages/home/home.module.scss b/src/pages/home/home.module.scss new file mode 100644 index 0000000..0072faa --- /dev/null +++ b/src/pages/home/home.module.scss @@ -0,0 +1,62 @@ +.content { + position: relative; + padding: 0 20px; + min-height: 90vh; + box-sizing: border-box; + width: 750rpx; + overflow: hidden; + + &:after { + min-height: 100vh; + position: absolute; + top: 0; + left: -10%; + width: 120%; + content: ''; + display: block; + background: linear-gradient(40deg, #fff 50rpx, #caf0e2, #92ecc5) no-repeat; + min-height: 100vh; + background-size: 100% 600rpx; + filter: blur(50px); + z-index: -1; + } +} + +.search { + width: 710rpx; + margin: 34rpx 0 0; + background: #fff; + border-radius: 100px; + line-height: 68rpx; + color: #bbb; + font-size: 28rpx; + display: flex; + align-items: center; + justify-content: center; +} + +.adware { + margin-top: 40rpx; + width: 100%; + height: 260rpx; + border-radius: 16rpx; + overflow: hidden; +} + +.videoListBox { + border-radius: 20px; +} + +.courseTag { + width: 200px; + margin: auto; + display: block; +} + +.featureRecommended { + background: #fff; + padding: 30rpx; + margin-top: 20rpx; + border-radius: 16rpx; + box-shadow: inset -30px -30px 30px rgba(#fff, .9); +} diff --git a/src/pages/home/home.tsx b/src/pages/home/home.tsx index 39eb775..93d07f3 100644 --- a/src/pages/home/home.tsx +++ b/src/pages/home/home.tsx @@ -1,9 +1,34 @@ import {FC} from "react"; import {View} from "@tarojs/components"; +import styles from "@/pages/index/index.module.scss"; +import Taro from "@tarojs/taro"; +import {Search} from "@/pages/home/components/search"; +import Adware from "@/pages/home/components/adware"; +import Feature from "@/pages/home/components/feature"; +import FeatureRecommended from "@/pages/home/components/feature_recommended"; +import CurRecommended from "@/pages/home/components/curRecommended"; +import MyButton from "@/components/button/MyButton"; +import {Profile} from "@/store"; const Home: FC = () => { + const globalData = Taro.getApp().globalData + const {token, empty} = Profile.useContainer() + return ( - 2 + + 康一诺 + + + + + + { + !token && + 登录后享受更多学习服务~ + 立即登录 + + } + ) } diff --git a/src/pages/index/components/search.tsx b/src/pages/index/components/search.tsx deleted file mode 100644 index 1517300..0000000 --- a/src/pages/index/components/search.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import {FC} from "react"; -import {Text, View} from "@tarojs/components"; -import styles from "@/pages/index/index.module.scss"; -import Icon from "@/components/icon"; - -export const Search: FC = () => { - return ( - - - 搜索课程 - - ) -} diff --git a/src/pages/index/index.module.scss b/src/pages/index/index.module.scss index fe83aa1..b58360c 100644 --- a/src/pages/index/index.module.scss +++ b/src/pages/index/index.module.scss @@ -22,19 +22,21 @@ } } -.search { - width: 710rpx; - margin: 34rpx 0 0; - background: #fff; - border-radius: 100px; - line-height: 68rpx; - color: #bbb; - font-size: 28rpx; - display: flex; - align-items: center; - justify-content: center; -} .videoListBox { border-radius: 20px; } + +.tipsLogin { + padding: 24rpx; + color: #fff; + align-items: center; + position: fixed; + bottom: 0; + left: 0; + display: flex; + justify-content: space-between; + width: 100%; + box-sizing: border-box; + background: rgba(#000, .7); +} diff --git a/src/pages/manage/addStudent/addStudent.tsx b/src/pages/manage/addStudent/addStudent.tsx index 348f3de..44728ef 100644 --- a/src/pages/manage/addStudent/addStudent.tsx +++ b/src/pages/manage/addStudent/addStudent.tsx @@ -81,7 +81,7 @@ const AddStudent = () => { Taro.useDidShow(() => { const newDepIds = storageDep.get() - setDepIds(newDepIds.length ? newDepIds : depIds) + setDepIds(newDepIds) }) return ( @@ -104,9 +104,9 @@ const AddStudent = () => { - + 所属部门 - + {depIds.length ? formatDep() : '选择部门'} diff --git a/src/pages/manage/depAdmin/depAdmin.tsx b/src/pages/manage/depAdmin/depAdmin.tsx index 2956ae4..df6af00 100644 --- a/src/pages/manage/depAdmin/depAdmin.tsx +++ b/src/pages/manage/depAdmin/depAdmin.tsx @@ -159,7 +159,7 @@ const DepAdmin: FC = () => { 添加学员 - showPop(undefined)}>分配部门 + showPop(undefined)}>添加部门 { router.params.id && 更多操作 } diff --git a/src/static/img/article.png b/src/static/img/article.png new file mode 100644 index 0000000..2bdac55 Binary files /dev/null and b/src/static/img/article.png differ diff --git a/src/static/img/courseTag.png b/src/static/img/courseTag.png new file mode 100644 index 0000000..257f074 Binary files /dev/null and b/src/static/img/courseTag.png differ diff --git a/src/static/img/first.png b/src/static/img/first.png new file mode 100644 index 0000000..7aa1044 Binary files /dev/null and b/src/static/img/first.png differ diff --git a/src/static/img/health.png b/src/static/img/health.png new file mode 100644 index 0000000..049348e Binary files /dev/null and b/src/static/img/health.png differ diff --git a/src/static/img/illness.png b/src/static/img/illness.png new file mode 100644 index 0000000..d8faaab Binary files /dev/null and b/src/static/img/illness.png differ diff --git a/src/static/img/profession.png b/src/static/img/profession.png new file mode 100644 index 0000000..9be7421 Binary files /dev/null and b/src/static/img/profession.png differ diff --git a/src/static/img/second.png b/src/static/img/second.png new file mode 100644 index 0000000..a225843 Binary files /dev/null and b/src/static/img/second.png differ diff --git a/src/static/img/third.png b/src/static/img/third.png new file mode 100644 index 0000000..8226ada Binary files /dev/null and b/src/static/img/third.png differ diff --git a/src/static/tabs/study-selected.png b/src/static/tabs/study-selected.png new file mode 100644 index 0000000..f0b2de0 Binary files /dev/null and b/src/static/tabs/study-selected.png differ diff --git a/src/static/tabs/study.png b/src/static/tabs/study.png new file mode 100644 index 0000000..05cb70c Binary files /dev/null and b/src/static/tabs/study.png differ diff --git a/src/utils/pathFormt.ts b/src/utils/pathFormt.ts new file mode 100644 index 0000000..95fc525 --- /dev/null +++ b/src/utils/pathFormt.ts @@ -0,0 +1,17 @@ +import {AdwareLinkType, AdwareParams} from "@/api"; +import Taro from "@tarojs/taro"; + +/** 拼接完整路径 */ +export function jumpAdware(advert_link: AdwareLinkType) { + if (advert_link.path && advert_link.param) { + let url = advert_link.path + "?" + const params: AdwareParams[] = JSON.parse(advert_link.param) + params.forEach((d, index) => { + url += d.key + "=" + d.value + if (index !== params.length - 1) { + url += "&" + } + }) + Taro.navigateTo({url}) + } +}