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}) }