1取消课程部门分配必修选修功能

2学习页面加载动画
v2
king 1 year ago
parent 3e4a30cf1f
commit 805b47435f
  1. 4
      .env
  2. 1
      src/api/manage.ts
  3. 25
      src/hooks/storageDep.ts
  4. 2
      src/pages/home/components/curRecommended.tsx
  5. 26
      src/pages/index/index.tsx
  6. 5
      src/pages/manage/courseAdmin/courseAdmin.tsx
  7. 52
      src/pages/manage/selectDep/selectDep.tsx

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

@ -46,7 +46,6 @@ export interface depCurProps {
interface AddCurProps {
course_id: number[]
dep_id: number[]
is_required: (1 | 0)[]
}

@ -1,14 +1,12 @@
import Taro from "@tarojs/taro";
const KET = 'SELECT_DEP'
const KET_REQUIRED = 'SELECT_REQUIRED'
/** 部门 */
function set(data: number[]) {
Taro.setStorageSync(KET, data)
}
function get(): number[] {
const deps = Taro.getStorageSync(KET)
if (deps && deps.length) {
@ -23,28 +21,7 @@ function removeDeps() {
Taro.removeStorageSync(KET)
}
/** 必修选修 */
function removeRequired() {
Taro.removeStorageSync(KET_REQUIRED)
}
function setRequired(data: number[]) {
Taro.setStorageSync(KET_REQUIRED, data)
}
/** getRequired 比 set后调用 */
function getRequired(): (0 | 1)[] {
const deps = Taro.getStorageSync(KET_REQUIRED)
if (deps && deps.length) {
removeRequired()
return deps
}
return []
}
function remove() {
removeRequired()
removeDeps()
}
@ -52,6 +29,4 @@ export default {
set,
get,
remove,
setRequired,
getRequired
}

@ -48,7 +48,7 @@ const CurRecommended: FC = () => {
{i > 0 && <View className='absolute top left right divided ml-3 mr-3' />}
<View className="font-34 bold 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>
<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">

@ -5,6 +5,9 @@ import {VideoList} from "@/pages/index/components/videoList";
import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs";
import {CoursesKey, publicApi} from "@/api/public";
import NavigationBar from "@/components/navigationBar/navigationBar";
import Spin from "@/components/spinner";
import Img from "@/components/image/image";
import {rfc33392time} from "@/utils/day";
// import Taro from "@tarojs/taro";
const category: TabList[] = [
@ -37,24 +40,35 @@ const Index: FC = () => {
const AuditMode: FC = () => {
const [auditMode, setAuditMode] = useState(false)
const [articles, setArticles] = useState<any[]>([])
const [enable, setEnable] = useState(true)
useEffect(() => {
publicApi.course({page: 1, pageSize: 10}).then(res => {
setAuditMode(res.audit_mode)
setArticles(res.articles)
// if(res.audit_mode){
// Taro.setTabBarItem({index: 1, text: '文章'})
// }
setEnable(false)
})
}, [])
return (
<>
<Spin enable={enable} overlay/>
{
auditMode ?
<>
<NavigationBar text='文章' cancelBack/>
<View className='p-2'>
<NavigationBar text='文章列表' cancelBack/>
<View className='bg-white rounded-20 clip'>
{
articles.map(d => <View className='mb-2 p-2 bg-white'>{d.title}</View>)
articles.map((d, i) => <View className='p-3 relative'>
{i > 0 && <View className='absolute top left right divided ml-3 mr-3'/>}
<View className="font-34 bold 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>{rfc33392time(d.created_at).split(' ')[0]}</View>
<View> {d.page_view || 0}</View>
</View>
</View>)
}
</View>
</>

@ -124,13 +124,12 @@ const CourseAdmin: FC = () => {
Taro.useDidShow(useCallback(async () => {
const dep_id = storageDep.get()
const is_required = storageDep.getRequired()
if (!dep_id.length || !is_required.length || !curs.length) return;
if (!dep_id.length || !curs.length) return;
try {
await ManageApi.addCur({course_id: curs, dep_id, is_required})
await ManageApi.addCur({course_id: curs, dep_id})
Taro.showToast({title: '修改成功'})
// deps 中没有 筛选条件中的depid 删除已选的课程
if (param.dep_id && dep_id.includes(param.dep_id)) {

@ -1,5 +1,5 @@
import React, {FC, useCallback, useEffect, useState} from "react";
import {Checkbox, Switch, View} from "@tarojs/components";
import {Checkbox, View} from "@tarojs/components";
import Taro from "@tarojs/taro";
import {curriculum} from "@/api";
import PopPut from "@/components/popPut/popPut";
@ -13,10 +13,9 @@ import Spin from "@/components/spinner";
* required
*/
const SelectDep: FC = () => {
const params = Taro.getCurrentInstance()?.router?.params as { depIds: string, required: string | undefined }
const params = Taro.getCurrentInstance()?.router?.params as { depIds: string}
const [ids, setIds] = useState<number[]>([])
const [deps, setDeps] = useState<Manage[]>([])
const [required, setRequired] = useState<number[]>([])
const [enable, setEnable] = useState(true)
useEffect(() => {
@ -25,7 +24,6 @@ const SelectDep: FC = () => {
})
setEnable(false)
setIds(JSON.parse(params.depIds))
setRequired(JSON.parse(params.required || "[]"))
}, [])
const onChange = useCallback((id: number) => {
@ -35,51 +33,19 @@ const SelectDep: FC = () => {
...ids,
id
])
if (params.required) {
setRequired([...required, 0])
}
} else {
const oldIds: number[] = JSON.parse(JSON.stringify(ids))
oldIds.splice(index, 1)
setIds(oldIds)
if (params.required) {
const oldRequired: number[] = JSON.parse(JSON.stringify(required))
oldRequired.splice(index, 1)
setRequired(oldRequired)
}
}
}, [ids])
function ok() {
storageDep.set(ids)
storageDep.setRequired(required)
Taro.navigateBack({delta: 1})
}
function isRequired(dep_id: number): boolean {
const index = ids.indexOf(dep_id)
if (index === -1) {
return false
} else {
return !!required?.[index]
}
}
function requiredChange(dep_id: number, value: boolean) {
const index = ids.indexOf(dep_id)
if (index === -1) {
setIds([...ids, dep_id])
setRequired([...required, value ? 1 : 0])
} else {
const oldRequired: number[] = JSON.parse(JSON.stringify(required))
oldRequired.splice(index, 1, value ? 1 : 0)
setRequired(oldRequired)
}
}
return (
<View className='px-2 bg-white'>
<Spin overlay enable={enable}/>
@ -90,19 +56,7 @@ const SelectDep: FC = () => {
key={d.id}
title={d.name}
chevron
leftImage={folder}
content={
params?.required ?
<View className='flex align-center'>
<Switch
color='#45d4a8'
onClick={() => event?.stopImmediatePropagation()}
checked={isRequired(d.id)}
onChange={(e) => requiredChange(d.id, e.detail.value)}/>
</View>
: null
}
/>
leftImage={folder}/>
</View>
</View>)}

Loading…
Cancel
Save