From e4465ebe7f56969b29bd459f8fae07d07131207d Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Wed, 2 Aug 2023 16:52:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=83=A8=E9=97=A8=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=9C=AC=E5=9C=B0(=E7=BC=93=E5=AD=98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.tsx | 2 ++ src/hooks/storageDep.ts | 26 ++++++++++++++++++++++ src/pages/manage/addStudent/addStudent.tsx | 10 ++++----- src/pages/manage/selectDep/selectDep.tsx | 3 ++- 4 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 src/hooks/storageDep.ts diff --git a/src/app.tsx b/src/app.tsx index ff9176d..778cdcf 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -3,6 +3,7 @@ import './app.scss' import {CustomWrapper} from "@tarojs/components"; import unique_ident from "@/hooks/unique_ident"; import {Profile} from '@/store' +import storageDep from "@/hooks/storageDep"; function updateApp() { @@ -36,6 +37,7 @@ function App(props) { Taro.useLaunch(() => { updateApp() + storageDep.remove() unique_ident.put() unique_ident.del() }) diff --git a/src/hooks/storageDep.ts b/src/hooks/storageDep.ts new file mode 100644 index 0000000..b70704a --- /dev/null +++ b/src/hooks/storageDep.ts @@ -0,0 +1,26 @@ +import Taro from "@tarojs/taro"; + +const KET = 'SELECTDEP' + +function set(data: number[]) { + Taro.setStorageSync(KET, data) +} + +function remove() { + Taro.removeStorageSync(KET) +} + +function get(): number[] { + const deps = Taro.getStorageSync(KET) + if (deps && deps.length) { + remove() + return deps + } + return [] +} + +export default { + set, + get, + remove +} diff --git a/src/pages/manage/addStudent/addStudent.tsx b/src/pages/manage/addStudent/addStudent.tsx index f10d161..6fae6aa 100644 --- a/src/pages/manage/addStudent/addStudent.tsx +++ b/src/pages/manage/addStudent/addStudent.tsx @@ -7,6 +7,7 @@ import {curriculum} from "@/api"; import './addStudent.scss' import {getCurrentInstance} from "@tarojs/runtime"; import {Profile} from '@/store' +import storageDep from "@/hooks/storageDep"; interface Department { id: number @@ -58,7 +59,7 @@ const AddStudent = () => { const formatDep = useCallback(() => { - console.log(depIds,12) + console.log(depIds, 12) const selected = department.filter(d => depIds.includes(d.id)).map(d => d.title) const top4 = selected.splice(0, 3).join('、') return top4 + (selected.length ? "+" + selected.length : '') @@ -82,11 +83,8 @@ const AddStudent = () => { }, []) Taro.useDidShow(() => { - const deps = Taro.getStorageSync('selectDep') - if (deps && deps.length) { - setDepIds(deps) - Taro.removeStorageSync('selectDep') - } + const newDepIds = storageDep.get() + setDepIds( newDepIds.length ?newDepIds: depIds) }) return ( diff --git a/src/pages/manage/selectDep/selectDep.tsx b/src/pages/manage/selectDep/selectDep.tsx index 3a6c125..0b0e997 100644 --- a/src/pages/manage/selectDep/selectDep.tsx +++ b/src/pages/manage/selectDep/selectDep.tsx @@ -5,6 +5,7 @@ import {curriculum} from "@/api"; import PopPut from "@/components/popPut/popPut"; import folder from "@/static/img/folder.png"; import MyButton from "@/components/button/MyButton"; +import storageDep from "@/hooks/storageDep"; const SelectDep: FC = () => { const {depIds} = Taro.getCurrentInstance()?.router?.params as { depIds: string } @@ -31,7 +32,7 @@ const SelectDep: FC = () => { Taro.showToast({title: '请选着部门', icon: "error"}) return } - Taro.setStorageSync('selectDep', ids) + storageDep.set(ids) Taro.navigateBack({delta: 1}) }