部门管理更多操作

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) {
return request('/api/v1/department/save', "POST", data)
},
putDep(data: AddDepProps) {
return request(`/api/v1/department/${data.id}`, "PUT", data)
putDep(id: string, name: string) {
return request(`/api/v1/department/${id}`, "PUT", {name})
},
delDep(id: number) {
delDep(id: string) {
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 Taro from '@tarojs/taro'
import {Profile} from '@/store'
import {Search} from "./components/search";
// import {Search} from "./components/search";
const Index: FC = () => {
@ -28,7 +28,7 @@ const Index: FC = () => {
<>
<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>}
<Search/>
{/*<Search/>*/}
<Tabs tabList={category} onChange={tabChange} current={categoryKey}/>
<VideoList categoryKey={categoryKey} ready={!!token}/>
</View>

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

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

Loading…
Cancel
Save