选择部门返回本地(缓存)

main
king 1 year ago
parent 475570da04
commit e4465ebe7f
  1. 2
      src/app.tsx
  2. 26
      src/hooks/storageDep.ts
  3. 10
      src/pages/manage/addStudent/addStudent.tsx
  4. 3
      src/pages/manage/selectDep/selectDep.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()
})

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

@ -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 (

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

Loading…
Cancel
Save