diff --git a/src/api/manage.ts b/src/api/manage.ts
index 5b3e189..712e3b3 100644
--- a/src/api/manage.ts
+++ b/src/api/manage.ts
@@ -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")
},
/** 部门课程 */
diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx
index e90f21a..0bb30bf 100644
--- a/src/pages/index/index.tsx
+++ b/src/pages/index/index.tsx
@@ -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 = () => {
<>
{process.env.TARO_ENV !== "h5" && 医学道}
-
+ {/**/}
diff --git a/src/pages/manage/depAdmin/depAdmin.tsx b/src/pages/manage/depAdmin/depAdmin.tsx
index a0e3bdf..ecb4849 100644
--- a/src/pages/manage/depAdmin/depAdmin.tsx
+++ b/src/pages/manage/depAdmin/depAdmin.tsx
@@ -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([])
const [show, setShow] = useState(false)
const [users, setUsers] = useState([])
- const [putCompany, setPutCompany] = useState(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 (
<>
@@ -133,7 +135,7 @@ const DepAdmin: FC = () => {
{manages.map(d => managesSheet(d)}
+ onClick={() => jumpDepAdmin(d)}
chevron
leftImage={folder}
/>)}
@@ -151,14 +153,17 @@ const DepAdmin: FC = () => {
添加学员
- showPop(null)}>添加部门
+ showPop(undefined)}>添加部门
+ {
+ router.params.id && 更多操作
+ }
setShow(false)}
onOk={addDep}
>
diff --git a/src/static/css/module.scss b/src/static/css/module.scss
index 32a7898..b46b410 100644
--- a/src/static/css/module.scss
+++ b/src/static/css/module.scss
@@ -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 {