useCommonStore.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { defineStore } from 'pinia'
  2. import { ref } from 'vue'
  3. import { getSubjectList, getFormList, getContentList } from '@/api/common'
  4. export const useCommonStore = defineStore('useCommonStore', () => {
  5. const subjectList = ref([{ name: '全部', id: '', title: '培训科目' }])
  6. const formList = ref([{ name: '全部', id: '', title: '培训形式' }])
  7. const contentList = ref([])
  8. const _getSubjectList = async () => {
  9. if (subjectList.value.length === 1) {
  10. const { data } = await getSubjectList()
  11. subjectList.value.push(...data)
  12. }
  13. }
  14. const _getFormList = async () => {
  15. if (formList.value.length === 1) {
  16. const { data } = await getFormList()
  17. formList.value.push(...data)
  18. }
  19. }
  20. const _getContentList = async () => {
  21. const { data } = await getContentList()
  22. contentList.value.push(...data)
  23. }
  24. return {
  25. subjectList,
  26. formList,
  27. contentList,
  28. getSubjectList: _getSubjectList,
  29. getFormList: _getFormList,
  30. getContentList: _getContentList
  31. }
  32. })