diff --git a/web/env.d.ts b/web/env.d.ts index 9706856f..11f02fe2 100644 --- a/web/env.d.ts +++ b/web/env.d.ts @@ -1,8 +1 @@ /// -declare module "vuex" { - export * from "vuex/types/index.d.ts"; - export * from "vuex/types/helpers.d.ts"; - export * from "vuex/types/logger.d.ts"; - export * from "vuex/types/vue.d.ts"; - } - \ No newline at end of file diff --git a/web/package.json b/web/package.json index cc5d22b5..afc1e033 100644 --- a/web/package.json +++ b/web/package.json @@ -26,11 +26,11 @@ "moment": "^2.29.4", "nanoid": "^5.0.7", "node-forge": "^1.3.1", + "pinia": "^2.1.7", "qrcode": "^1.5.3", "vue": "^3.4.15", "vue-router": "^4.2.5", "vuedraggable": "^4.1.0", - "vuex": "^4.0.2", "xss": "^1.0.14", "yup": "^1.4.0" }, diff --git a/web/src/common/Editor/RichEditor.vue b/web/src/common/Editor/RichEditor.vue index 65b377bf..2696fa16 100644 --- a/web/src/common/Editor/RichEditor.vue +++ b/web/src/common/Editor/RichEditor.vue @@ -24,13 +24,13 @@ \ No newline at end of file diff --git a/web/src/render/App.vue b/web/src/render/App.vue index acafc152..28416b75 100644 --- a/web/src/render/App.vue +++ b/web/src/render/App.vue @@ -2,12 +2,12 @@ diff --git a/web/src/render/components/QuestionWrapper.vue b/web/src/render/components/QuestionWrapper.vue index ed2b8a23..d0f0f3d2 100644 --- a/web/src/render/components/QuestionWrapper.vue +++ b/web/src/render/components/QuestionWrapper.vue @@ -13,9 +13,10 @@ import QuestionRuleContainer from '../../materials/questions/QuestionRuleContain import { useVoteMap } from '@/render/hooks/useVoteMap' import { useShowOthers } from '@/render/hooks/useShowOthers' import { useShowInput } from '@/render/hooks/useShowInput' -import store from '@/render/store' import { cloneDeep } from 'lodash-es' import { ruleEngine } from '@/render/hooks/useRuleEngine.js' +import { useQuestionStore } from '../stores/question' +import { useSurveyStore } from '../stores/survey' import { NORMAL_CHOICES, RATES, QUESTION_TYPE } from '@/common/typeEnum.ts' @@ -32,9 +33,11 @@ const props = defineProps({ } }) const emit = defineEmits(['change']) +const questionStore = useQuestionStore() +const surveyStore = useSurveyStore() const formValues = computed(() => { - return store.state.formValues + return surveyStore.formValues }) const questionConfig = computed(() => { let moduleConfig = props.moduleConfig @@ -96,7 +99,7 @@ watch( key: field, value: value } - store.commit('changeFormData', data) + surveyStore.changeData(data) } } ) @@ -105,7 +108,7 @@ const handleChange = (data) => { emit('change', data) // 处理投票题 if (props.moduleConfig.type === QUESTION_TYPE.VOTE) { - store.dispatch('updateVoteData', data) + questionStore.updateVoteData(data) } } diff --git a/web/src/render/components/VerifyWhiteDialog.vue b/web/src/render/components/VerifyWhiteDialog.vue index 42770742..1d53d741 100644 --- a/web/src/render/components/VerifyWhiteDialog.vue +++ b/web/src/render/components/VerifyWhiteDialog.vue @@ -1,43 +1,52 @@ diff --git a/web/src/render/hooks/useProgress.js b/web/src/render/hooks/useProgress.js index 731b0a48..b76981cb 100644 --- a/web/src/render/hooks/useProgress.js +++ b/web/src/render/hooks/useProgress.js @@ -1,6 +1,7 @@ -import store from '../store/index' +import { useSurveyStore } from '../stores/survey' import { computed } from 'vue' export const useProgressBar = () => { + const surveyStore = useSurveyStore() const isVariableEmpty = (variable) => { if (variable === undefined || variable === null) { return true @@ -22,7 +23,7 @@ export const useProgressBar = () => { fillCount: 0, topicCount: 0 } - const formValues = store.state.formValues + const formValues = surveyStore.formValues for (let key in formValues) { if (key.split('_').length > 1) continue diff --git a/web/src/render/hooks/useShowInput.js b/web/src/render/hooks/useShowInput.js index 2bc446ee..b4982c4f 100644 --- a/web/src/render/hooks/useShowInput.js +++ b/web/src/render/hooks/useShowInput.js @@ -1,8 +1,12 @@ -import store from '../store/index' +import { useQuestionStore } from '../stores/question' +import { useSurveyStore } from '../stores/survey' + export const useShowInput = (questionKey) => { - const formValues = store.state.formValues + const questionStore = useQuestionStore() + const surveyStore = useSurveyStore() + const formValues = surveyStore.formValues const questionVal = formValues[questionKey] - let rangeConfig = store.state.questionData[questionKey].rangeConfig + let rangeConfig = questionStore.questionData[questionKey].rangeConfig let othersValue = {} if (rangeConfig && Object.keys(rangeConfig).length > 0) { for (let key in rangeConfig) { @@ -18,7 +22,8 @@ export const useShowInput = (questionKey) => { key: rangeKey, value: '' } - store.commit('changeFormData', data) + + surveyStore.changeData(data) } } } diff --git a/web/src/render/hooks/useShowOthers.js b/web/src/render/hooks/useShowOthers.js index 379c9874..df5a8b9e 100644 --- a/web/src/render/hooks/useShowOthers.js +++ b/web/src/render/hooks/useShowOthers.js @@ -1,9 +1,13 @@ -import store from '../store/index' +import { useQuestionStore } from '../stores/question' +import { useSurveyStore } from '../stores/survey' + export const useShowOthers = (questionKey) => { - const formValues = store.state.formValues + const questionStore = useQuestionStore() + const surveyStore = useSurveyStore() + const formValues = surveyStore.formValues const questionVal = formValues[questionKey] let othersValue = {} - let options = store.state.questionData[questionKey].options.map((optionItem) => { + let options = questionStore.questionData[questionKey].options.map((optionItem) => { if (optionItem.others) { const opKey = `${questionKey}_${optionItem.hash}` othersValue[opKey] = formValues[opKey] @@ -13,7 +17,7 @@ export const useShowOthers = (questionKey) => { key: opKey, value: '' } - store.commit('changeFormData', data) + surveyStore.changeData(data) } return { ...optionItem, diff --git a/web/src/render/hooks/useVoteMap.js b/web/src/render/hooks/useVoteMap.js index 70d7da95..31a1b397 100644 --- a/web/src/render/hooks/useVoteMap.js +++ b/web/src/render/hooks/useVoteMap.js @@ -1,10 +1,12 @@ -import store from '../store/index' -export const useVoteMap = (questionKey) => { - let voteTotal = store.state.voteMap?.[questionKey]?.total || 0 +import { useQuestionStore } from '../stores/question' - const options = store.state.questionData[questionKey].options.map((option) => { +export const useVoteMap = (questionKey) => { + const questionStore = useQuestionStore() + let voteTotal = questionStore.voteMap?.[questionKey]?.total || 0 + + const options = questionStore.questionData[questionKey].options.map((option) => { const optionHash = option.hash - const voteCount = store.state.voteMap?.[questionKey]?.[optionHash] || 0 + const voteCount = questionStore.voteMap?.[questionKey]?.[optionHash] || 0 return { ...option, diff --git a/web/src/render/main.js b/web/src/render/main.js index e8cc2762..ca68f229 100644 --- a/web/src/render/main.js +++ b/web/src/render/main.js @@ -2,15 +2,16 @@ import { createApp } from 'vue' import App from './App.vue' import EventBus from './utils/eventbus' import router from './router' -import store from './store' +import { createPinia } from 'pinia' const app = createApp(App) +const pinia = createPinia() const $bus = new EventBus() app.provide('$bus', $bus) // 挂载到this上 app.config.globalProperties.$bus = $bus +app.use(pinia) app.use(router) -app.use(store) app.mount('#app') diff --git a/web/src/render/pages/ErrorPage.vue b/web/src/render/pages/ErrorPage.vue index 88a209ce..38ac19cb 100755 --- a/web/src/render/pages/ErrorPage.vue +++ b/web/src/render/pages/ErrorPage.vue @@ -2,35 +2,41 @@
- +
-