forked from mengyxu/noob-components
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
681 B
32 lines
681 B
import { onMounted, toRef } from "vue"; |
|
import { useRoute } from "vue-router"; |
|
import { useStore } from "vuex"; |
|
|
|
export function useActionPers(parent?: string) { |
|
const store = useStore(); |
|
|
|
if (!parent) { |
|
const route = useRoute(); |
|
parent = route.path; |
|
} |
|
|
|
const update = async () => { |
|
await store.dispatch("updateActionPers", parent); |
|
}; |
|
|
|
const actionPers = toRef(() => { |
|
// @ts-ignore |
|
const pers = store.state.actionPers[parent] ?? []; |
|
return Object.fromEntries(pers.map((code) => [code, true])); |
|
}); |
|
|
|
onMounted(async () => { |
|
await update(); |
|
}); |
|
|
|
return { |
|
get: (per) => !!actionPers.value[per], |
|
update, |
|
actionPers, |
|
}; |
|
}
|
|
|