1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| import { defineStore } from 'pinia' import { computed, ref, unref } from 'vue' import { useEventBus } from '@vueuse/core' import { get } from 'lodash-es'
export const pageBus = useEventBus('page-event')
enum TeamStateType { UNJOIN = '申请加入', UNCHECK = '待审核', JOINED = '我要退出', REJECT = '已拒绝', } enum MyProjectStateType { UNCHECK = '待录用', JOINED = '我要退出', DONE = '已结束', } enum ProjectStateType { CANJOIN = '报名参加', JOINDONE = '报名已结束,进行中', DONE = '活动已结束', }
const stateTypeCombine = { ...TeamStateType, ...MyProjectStateType, ...ProjectStateType, UNKNOW: 'unknow', } type stateType = keyof typeof stateTypeCombine
type pageEnum = 'PROJECT' | 'MYPROJECT' | 'TEAM' | 'UNKNOW' const stateMap = { TEAM: { UNCHECK: { text: TeamStateType.UNCHECK, style: 'btn-place__UNCHECK', }, UNJOIN: { text: TeamStateType.UNJOIN, style: 'btn-place__UNCHECK', }, JOINED: { text: TeamStateType.JOINED, style: 'btn-place__JOINED', }, REJECT: { text: TeamStateType.REJECT, style: 'btn-place__REJECT', }, }, MYPROJECT: { UNCHECK: { text: MyProjectStateType.UNCHECK, style: 'btn-my-project__UNCHECK', }, JOINED: { text: MyProjectStateType.JOINED, style: 'btn-my-project__JOINED', }, DONE: { text: MyProjectStateType.DONE, style: 'btn-my-project__DONE', }, }, PROJECT: { CANJOIN: { text: ProjectStateType.CANJOIN, style: 'btn-project__CANJOIN', }, JOINDONE: { text: ProjectStateType.JOINDONE, style: 'btn-project__JOINDONE', }, DONE: { text: ProjectStateType.DONE, style: 'btn-project__DONE', }, }, UNKNOW: { text: '未知', style: '', }, }
export const usePageStore = defineStore('pageStore', () => { const state = ref<stateType>('UNKNOW') const pageType = ref<pageEnum>('UNKNOW') function setState(type: pageEnum, newState: stateType, rest?: any) { pageType.value = type state.value = newState }
const nowState = computed(() => { return get(stateMap, [`${unref(pageType)}`, `${unref(state)}`], { text: stateMap.UNKNOW.text, style: stateMap.UNKNOW.style, }) })
const pageData = ref(null) const setPageData = (data) => { pageData.value = data }
const starStatus = computed(() => pageData.value?.user_collection > 0) return { state, setPageData, pageData, nowState, starStatus, pageType, setState, } })
|