use-question-list.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { defineStore } from 'pinia';
  2. import { ref } from 'vue';
  3. const useQuestionListStore = defineStore('questionList', () => {
  4. const showQuestionList = ref(false);
  5. const ListType = ref<'all' | 'workshop' | 'camera'>('all');
  6. const workshopCodes = ref<string[]>([]);
  7. const cameraId = ref<number | null>();
  8. const openList = () => {
  9. if (showQuestionList.value === false) showQuestionList.value = true;
  10. };
  11. const closeList = () => {
  12. if (showQuestionList.value === true) showQuestionList.value = false;
  13. };
  14. const getState = () => ({ type: ListType.value, workshopCodes: workshopCodes.value, cameraId: cameraId.value });
  15. const setState = (data: { type: 'all' | 'workshop' | 'camera'; workshopCodes?: string[]; cameraId?: number }) => {
  16. ListType.value = data.type;
  17. console.log('setState', ListType.value);
  18. workshopCodes.value = data.workshopCodes || [];
  19. cameraId.value = data.cameraId || null;
  20. };
  21. const clearStore = () => {
  22. ListType.value = 'all';
  23. workshopCodes.value = [];
  24. cameraId.value = null;
  25. };
  26. return { showQuestionList, ListType, workshopCodes, cameraId, openList, closeList, getState, setState, clearStore };
  27. });
  28. export default useQuestionListStore;