部门管理更多操作

main
king 1 year ago
parent 77dbdb87c1
commit 38dd48c99e
  1. 6
      src/api/manage.ts
  2. 4
      src/pages/index/index.tsx
  3. 103
      src/pages/manage/depAdmin/depAdmin.tsx
  4. 2
      src/static/css/module.scss

@ -94,10 +94,10 @@ export const ManageApi = {
addDep(data: AddDepProps) { addDep(data: AddDepProps) {
return request('/api/v1/department/save', "POST", data) return request('/api/v1/department/save', "POST", data)
}, },
putDep(data: AddDepProps) { putDep(id: string, name: string) {
return request(`/api/v1/department/${data.id}`, "PUT", data) return request(`/api/v1/department/${id}`, "PUT", {name})
}, },
delDep(id: number) { delDep(id: string) {
return request(`/api/v1/department/${id}`, "DELETE") return request(`/api/v1/department/${id}`, "DELETE")
}, },
/** 部门课程 */ /** 部门课程 */

@ -6,7 +6,7 @@ import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs";
import {CoursesKey} from "@/api/public"; import {CoursesKey} from "@/api/public";
import Taro from '@tarojs/taro' import Taro from '@tarojs/taro'
import {Profile} from '@/store' import {Profile} from '@/store'
import {Search} from "./components/search"; // import {Search} from "./components/search";
const Index: FC = () => { const Index: FC = () => {
@ -28,7 +28,7 @@ const Index: FC = () => {
<> <>
<View className={styles.content} style={`paddingTop:${globalData.statusBarHeight}px`}> <View className={styles.content} style={`paddingTop:${globalData.statusBarHeight}px`}>
{process.env.TARO_ENV !== "h5" && <View className='text-center font-weight font-34 mt-3'></View>} {process.env.TARO_ENV !== "h5" && <View className='text-center font-weight font-34 mt-3'></View>}
<Search/> {/*<Search/>*/}
<Tabs tabList={category} onChange={tabChange} current={categoryKey}/> <Tabs tabList={category} onChange={tabChange} current={categoryKey}/>
<VideoList categoryKey={categoryKey} ready={!!token}/> <VideoList categoryKey={categoryKey} ready={!!token}/>
</View> </View>

@ -1,48 +1,48 @@
import React, {FC, useEffect, useState} from "react"; import React, {FC, useCallback, useEffect, useState} from "react";
import {AddDepProps, ManageApi} from "@/api/manage"; import {ManageApi} from "@/api/manage";
import {View, Input} from "@tarojs/components"; import {View, Input} from "@tarojs/components";
import Taro from "@tarojs/taro"; import Taro, {useRouter} from "@tarojs/taro";
import {Profile} from '@/store'
import './depAdmin.scss' import './depAdmin.scss'
import PopPut from "@/components/popPut/popPut"; import PopPut from "@/components/popPut/popPut";
import folder from '@/static/img/folder.png' import folder from '@/static/img/folder.png'
import {getCurrentInstance} from "@tarojs/runtime";
import ShowModel from "@/components/showModel/showModel"; import ShowModel from "@/components/showModel/showModel";
import Empty from "@/components/empty/empty"; import Empty from "@/components/empty/empty";
import {Profile} from '@/store'
const DepAdmin: FC = () => { const DepAdmin: FC = () => {
const params = getCurrentInstance()?.router?.params as { dep_id: string, name: string, id: string } const router = useRouter()
// const params = getCurrentInstance()?.router?.params as { dep_id: string, name: string, id: string }
const [manages, setManages] = useState<Manage[]>([]) const [manages, setManages] = useState<Manage[]>([])
const [show, setShow] = useState(false) const [show, setShow] = useState(false)
const [users, setUsers] = useState<User[]>([]) const [users, setUsers] = useState<User[]>([])
const [putCompany, setPutCompany] = useState<Manage | null>(null) const [isPut, setIsPut] = useState(false)
const [depName, setDepName] = useState('') const [depName, setDepName] = useState('')
const {company} = Profile.useContainer() const {company} = Profile.useContainer()
async function getData() { async function getData() {
show && setShow(false) show && setShow(false)
const res = await ManageApi.depList(params.dep_id || 0) const res = await ManageApi.depList(router.params.dep_id || 0)
if (res) { if (res) {
setManages(res.department) setManages(res.department)
setUsers(res.data) setUsers(res.data)
} }
} }
function showPop(company: Manage | null) { function showPop(name: string | undefined) {
if (company) { if (name) {
setDepName(company.name) setDepName(name)
setIsPut(true)
} else { } else {
setIsPut(false)
setDepName('') setDepName('')
} }
setPutCompany(company)
setShow(true) setShow(true)
} }
function del(name: string, id: number) { function del(name: string, id: string) {
Taro.showModal({ Taro.showModal({
title: name + '删除后将不可恢复', title: name + ' 删除后将不可恢复',
async success({confirm}) { async success({confirm}) {
if (confirm) { if (confirm) {
try { try {
@ -50,6 +50,7 @@ const DepAdmin: FC = () => {
await ManageApi.delDep(id) await ManageApi.delDep(id)
Taro.hideLoading() Taro.hideLoading()
Taro.showToast({title: "删除成功"}) Taro.showToast({title: "删除成功"})
Taro.navigateBack()
await getData() await getData()
} catch (e) { } catch (e) {
} }
@ -58,27 +59,27 @@ const DepAdmin: FC = () => {
}) })
} }
function managesSheet(item: Manage) { function jumpDepAdmin(item: Manage) {
Taro.navigateTo({url: `/pages/manage/depAdmin/depAdmin?dep_id=${item.id}&name=${encodeURI(item.name)}&id=${item.id}`})
}
function managesSheet() {
Taro.showActionSheet({ Taro.showActionSheet({
itemList: [ itemList: [
'查看部门课程', '查看部门课程',
'查看子部门和学员', '修改当前部门名称',
'修改部门',
'删除部门' '删除部门'
], ],
success({tapIndex}) { success({tapIndex}) {
switch (tapIndex) { switch (tapIndex) {
case 0: case 0:
Taro.navigateTo({url: `/pages/manage/depCur/depCur?id=${item.id}`}) Taro.navigateTo({url: `/pages/manage/depCur/depCur?id=${router.params.id}`})
break break
case 1: case 1:
Taro.navigateTo({url: `/pages/manage/depAdmin/depAdmin?dep_id=${item.id}&name=${encodeURI(item.name)}&id=${item.id}`}) showPop(decodeURI(router.params.name!))
break break
case 2: case 2:
showPop(item) del(decodeURI(router.params.name!), router.params.id!)
break
case 3:
del(item.name, item.id)
break break
} }
}, },
@ -92,40 +93,41 @@ const DepAdmin: FC = () => {
Taro.navigateTo({url: '/pages/manage/addStudent/addStudent'}) Taro.navigateTo({url: '/pages/manage/addStudent/addStudent'})
} }
async function addDep() { const addDep = useCallback(async () => {
if (!depName) {
Taro.showToast({title: "请认真填写", icon: "error"})
return
}
try { try {
const company_id = putCompany?.company_id || company?.id || 0 if (isPut) {
const data: AddDepProps = { await ManageApi.putDep(router.params.id!, depName)
id: putCompany?.id || null, router.params.name = depName
name: depName, Taro.setNavigationBarTitle({
parent_id: putCompany ? putCompany?.parent_id : manages.length, title: depName
company_id: company_id, })
sort: putCompany?.sort || 0
}
if (putCompany) {
await ManageApi.putDep(data)
} else { } else {
await ManageApi.addDep(data) await ManageApi.addDep({
name: depName,
parent_id: Number(router.params.dep_id) || 0,
company_id: company?.id!,
sort: manages.length,
})
} }
setTimeout(() => Taro.showToast({title: '操作成功'})) setShow(false)
await getData()
} catch (e) { } catch (e) {
Taro.showToast({title: '操作失败', icon: 'error'})
} }
} }, [isPut, depName])
// Taro.useDidShow()
useEffect(() => { useEffect(() => {
getData() getData()
Taro.setNavigationBarTitle({ Taro.setNavigationBarTitle({
title: decodeURI(params.name) ?? '部门管理' title: decodeURI(router.params.name!) || '部门管理'
}) })
}, []) }, [])
Taro.useDidShow(() => {
if (manages.length) {
getData()
}
})
return ( return (
<> <>
<View> <View>
@ -133,7 +135,7 @@ const DepAdmin: FC = () => {
{manages.map(d => <PopPut {manages.map(d => <PopPut
key={d.id} key={d.id}
title={d.name} title={d.name}
onClick={() => managesSheet(d)} onClick={() => jumpDepAdmin(d)}
chevron chevron
leftImage={folder} leftImage={folder}
/>)} />)}
@ -151,14 +153,17 @@ const DepAdmin: FC = () => {
<View className='operation'> <View className='operation'>
<View className='safeAreaInsetBottom'> <View className='safeAreaInsetBottom'>
<View onClick={jumpAddStudent}></View> <View onClick={jumpAddStudent}></View>
<View onClick={() => showPop(null)}></View> <View onClick={() => showPop(undefined)}></View>
{
router.params.id && <View onClick={managesSheet}></View>
}
</View> </View>
</View> </View>
</View> </View>
<ShowModel <ShowModel
show={show} show={show}
title={putCompany?.name ? `修改${putCompany.name}` : '添加部门'} title={router.params.name ? `修改${decodeURI(router.params.name)}` : '添加部门'}
onClickOverlay={() => setShow(false)} onClickOverlay={() => setShow(false)}
onOk={addDep} onOk={addDep}
> >

@ -5,7 +5,7 @@ page,
-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling: touch;
box-sizing: border-box; box-sizing: border-box;
padding-bottom: env(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom);
min-height: 100vh; //min-height: 100vh;
} }
body { body {

Loading…
Cancel
Save