From cdd26073afd1f34f8cdfcb2c54ecc27673ea4971 Mon Sep 17 00:00:00 2001 From: dayou <853094838@qq.com> Date: Fri, 28 Jun 2024 18:46:24 +0800 Subject: [PATCH 01/13] =?UTF-8?q?feat:=20user=E6=A8=A1=E5=9D=97=E7=9A=84pi?= =?UTF-8?q?nia=E8=BF=81=E7=A7=BB=20(#315)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/package.json | 1 + web/src/management/api/base.js | 7 +-- web/src/management/main.js | 3 ++ .../pages/list/components/MemberSelect.vue | 6 +-- web/src/management/pages/list/index.vue | 7 +-- web/src/management/pages/login/LoginPage.vue | 6 +-- web/src/management/router/index.ts | 11 ++-- web/src/management/store/index.js | 4 +- web/src/management/stores/user.js | 51 +++++++++++++++++++ web/src/render/main.js | 7 ++- web/src/render/pages/IndexPage.vue | 1 - web/src/render/pages/RenderPage.vue | 2 +- web/src/render/store/actions.js | 1 - 13 files changed, 85 insertions(+), 22 deletions(-) create mode 100644 web/src/management/stores/user.js diff --git a/web/package.json b/web/package.json index 114191e1..ad7c09f6 100644 --- a/web/package.json +++ b/web/package.json @@ -27,6 +27,7 @@ "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", diff --git a/web/src/management/api/base.js b/web/src/management/api/base.js index 45687330..1268f8bc 100644 --- a/web/src/management/api/base.js +++ b/web/src/management/api/base.js @@ -1,7 +1,7 @@ import axios from 'axios' -import store from '@/management/store/index' import router from '@/management/router/index' import { get as _get } from 'lodash-es' +import { useUserStore } from '../stores/user' export const CODE_MAP = { SUCCESS: 200, @@ -36,8 +36,9 @@ instance.interceptors.response.use( ) instance.interceptors.request.use((config) => { - const hasLogined = _get(store, 'state.user.hasLogined') - const token = _get(store, 'state.user.userInfo.token') + const userStore = useUserStore() + const hasLogined = _get(userStore, 'hasLogined') + const token = _get(userStore, 'userInfo.token') if (hasLogined && token) { if (!config.headers) { config.headers = {} diff --git a/web/src/management/main.js b/web/src/management/main.js index 56af3ac3..081784ef 100644 --- a/web/src/management/main.js +++ b/web/src/management/main.js @@ -1,14 +1,17 @@ import { createApp } from 'vue' import store from './store' +import { createPinia } from 'pinia' import plainText from './directive/plainText' import safeHtml from './directive/safeHtml' import App from './App.vue' import router from './router' +const pinia = createPinia() const app = createApp(App) app.use(store) +app.use(pinia) app.use(router) app.use(plainText) diff --git a/web/src/management/pages/list/components/MemberSelect.vue b/web/src/management/pages/list/components/MemberSelect.vue index e36437cd..9bb83ad2 100644 --- a/web/src/management/pages/list/components/MemberSelect.vue +++ b/web/src/management/pages/list/components/MemberSelect.vue @@ -23,7 +23,6 @@ diff --git a/web/src/management/pages/login/LoginPage.vue b/web/src/management/pages/login/LoginPage.vue index d502cf84..6564c9bf 100644 --- a/web/src/management/pages/login/LoginPage.vue +++ b/web/src/management/pages/login/LoginPage.vue @@ -57,7 +57,6 @@ diff --git a/web/src/management/pages/list/index.vue b/web/src/management/pages/list/index.vue index 4b2cc0ee..33b4a069 100644 --- a/web/src/management/pages/list/index.vue +++ b/web/src/management/pages/list/index.vue @@ -60,60 +60,52 @@ diff --git a/web/src/management/pages/list/index.vue b/web/src/management/pages/list/index.vue index 33b4a069..87c1d658 100644 --- a/web/src/management/pages/list/index.vue +++ b/web/src/management/pages/list/index.vue @@ -68,15 +68,15 @@ import SliderBar from './components/SliderBar.vue' import SpaceModify from './components/SpaceModify.vue' import { SpaceType } from '@/management/utils/types/workSpace' import { useUserStore } from '@/management/stores/user' -import { useTeamSpaceStore } from '@/management/stores/teamSpace' +import { useWorkSpaceStore } from '@/management/stores/workSpace' import { useSurveyListStore } from '@/management/stores/surveyList' const userStore = useUserStore() -const teamSpaceStore = useTeamSpaceStore() +const workSpaceStore = useWorkSpaceStore() const surveyListStore = useSurveyListStore() const { surveyList, surveyTotal } = storeToRefs(surveyListStore) -const { spaceMenus, workSpaceId, spaceType } = storeToRefs(teamSpaceStore) +const { spaceMenus, workSpaceId, spaceType } = storeToRefs(workSpaceStore) const router = useRouter() const userInfo = computed(() => { return userStore.userInfo @@ -87,25 +87,25 @@ const activeIndex = ref('1') const handleSpaceSelect = (id: any) => { if (id === SpaceType.Personal) { // 点击个人空间菜单 - if (teamSpaceStore.spaceType === SpaceType.Personal) { + if (workSpaceStore.spaceType === SpaceType.Personal) { return } - teamSpaceStore.changeSpaceType(SpaceType.Personal) - teamSpaceStore.changeWorkSpace('') + workSpaceStore.changeSpaceType(SpaceType.Personal) + workSpaceStore.changeWorkSpace('') } else if (id === SpaceType.Group) { // 点击团队空间组菜单 - if (teamSpaceStore.spaceType === SpaceType.Group) { + if (workSpaceStore.spaceType === SpaceType.Group) { return } - teamSpaceStore.changeSpaceType(SpaceType.Group) - teamSpaceStore.changeWorkSpace('') + workSpaceStore.changeSpaceType(SpaceType.Group) + workSpaceStore.changeWorkSpace('') } else if (!Object.values(SpaceType).includes(id)) { // 点击具体团队空间 - if (teamSpaceStore.workSpaceId === id) { + if (workSpaceStore.workSpaceId === id) { return } - teamSpaceStore.changeSpaceType(SpaceType.Teamwork) - teamSpaceStore.changeWorkSpace(id) + workSpaceStore.changeSpaceType(SpaceType.Teamwork) + workSpaceStore.changeWorkSpace(id) } fetchSurveyList() @@ -115,7 +115,7 @@ onMounted(() => { fetchSurveyList() }) const fetchSpaceList = () => { - teamSpaceStore.getSpaceList() + workSpaceStore.getSpaceList() } const fetchSurveyList = async (params?: any) => { if (!params) { diff --git a/web/src/management/store/list/index.js b/web/src/management/store/list/index.js index e347bebd..7561bcbe 100644 --- a/web/src/management/store/list/index.js +++ b/web/src/management/store/list/index.js @@ -37,7 +37,7 @@ export default { spaceType: SpaceType.Personal, workSpaceId: '', spaceDetail: null, - teamSpaceList: [], + workSpaceList: [], // 列表管理 surveyList: [], surveyTotal: 0, @@ -52,7 +52,7 @@ export default { } }, getters: { - listFliter(state) { + listFilter(state) { return [ { comparator: '', @@ -96,25 +96,25 @@ export default { } }, mutations: { - updateSpaceMenus(state, teamSpace) { + updateSpaceMenus(state, workSpace) { // 更新空间列表下的团队空间 - set(state, 'spaceMenus[1].children', teamSpace) + set(state, 'spaceMenus[1].children', workSpace) }, changeSpaceType(state, spaceType) { state.spaceType = spaceType }, changeWorkSpace(state, workSpaceId) { // 切换空间清除筛选条件 - this.commit('list/reserSelectValueMap') - this.commit('list/reserButtonValueMap') + this.commit('list/resetSelectValueMap') + this.commit('list/resetButtonValueMap') this.commit('list/setSearchVal', '') state.workSpaceId = workSpaceId }, setSpaceDetail(state, data) { state.spaceDetail = data }, - setTeamSpaceList(state, data) { - state.teamSpaceList = data + setWorkSpaceList(state, data) { + state.workSpaceList = data }, setSurveyList(state, list) { state.surveyList = list @@ -125,7 +125,7 @@ export default { setSearchVal(state, data) { state.searchVal = data }, - reserSelectValueMap(state) { + resetSelectValueMap(state) { state.selectValueMap = { surveyType: '', 'curStatus.status': '' @@ -134,7 +134,7 @@ export default { changeSelectValueMap(state, { key, value }) { state.selectValueMap[key] = value }, - reserButtonValueMap(state) { + resetButtonValueMap(state) { state.buttonValueMap = { 'curStatus.date': '', createDate: -1 @@ -151,14 +151,14 @@ export default { if (res.code === CODE_MAP.SUCCESS) { const { list } = res.data - const teamSpace = list.map((item) => { + const workSpace = list.map((item) => { return { id: item._id, name: item.name } }) - commit('setTeamSpaceList', list) - commit('updateSpaceMenus', teamSpace) + commit('setWorkSpaceList', list) + commit('updateSpaceMenus', workSpace) } else { ElMessage.error('getSpaceList' + res.errmsg) } @@ -221,7 +221,7 @@ export default { }, async getSurveyList({ state, getters, commit }, payload) { const filterString = JSON.stringify( - getters.listFliter.filter((item) => { + getters.listFilter.filter((item) => { return item.condition[0].value }) ) diff --git a/web/src/management/stores/surveyList.ts b/web/src/management/stores/surveyList.ts index 35d5d19e..017834b3 100644 --- a/web/src/management/stores/surveyList.ts +++ b/web/src/management/stores/surveyList.ts @@ -1,74 +1,13 @@ -import { CODE_MAP } from '@/management/api/base' import { ElMessage } from 'element-plus' import 'element-plus/theme-chalk/src/message.scss' -import { getSurveyList as getSurveyListReq } from '@/management/api/survey' import { defineStore } from 'pinia' -import { useTeamSpaceStore } from './teamSpace' + +import { CODE_MAP } from '@/management/api/base' +import { getSurveyList as getSurveyListReq } from '@/management/api/survey' + +import { useWorkSpaceStore } from './workSpace' import { ref, computed } from 'vue' -export const useSurveyListStore = defineStore('surveyList', () => { - const surveyList = ref([]) - const surveyTotal = ref(0) - - const { - searchVal, - selectValueMap, - buttonValueMap, - listFilter, - listOrder, - resetSearch, - resetSelectValueMap, - resetButtonValueMap, - changeSelectValueMap, - changeButtonValueMap - } = useSearchSurvey() - - const teamSpaceStore = useTeamSpaceStore() - async function getSurveyList(payload: { curPage?: number; pageSize?: number }) { - const filterString = JSON.stringify( - listFilter.value.filter((item) => { - return item.condition[0].value - }) - ) - const orderString = JSON.stringify(listOrder.value) - try { - const params = { - curPage: payload?.curPage || 1, - pageSize: payload?.pageSize || 10, // 默认一页10条 - filter: filterString, - order: orderString, - workspaceId: teamSpaceStore.workSpaceId - } - - const res: any = await getSurveyListReq(params) - if (res.code === CODE_MAP.SUCCESS) { - surveyList.value = res.data.data - surveyTotal.value = res.data.count - } else { - ElMessage.error(res.errmsg) - } - } catch (error) { - ElMessage.error('getSurveyList status' + error) - } - } - - return { - surveyList, - surveyTotal, - searchVal, - selectValueMap, - buttonValueMap, - listFliter: listFilter, - listOrder, - resetSearch, - getSurveyList, - resetSelectValueMap, - resetButtonValueMap, - changeSelectValueMap, - changeButtonValueMap - } -}) - function useSearchSurvey() { const searchVal = ref('') const selectValueMap = ref>({ @@ -117,7 +56,7 @@ function useSearchSurvey() { const listOrder = computed(() => { return Object.entries(buttonValueMap.value) .filter(([, effectValue]) => effectValue) - .reduce((prev: { field: string, value: string | number }[], item) => { + .reduce((prev: { field: string; value: string | number }[], item) => { const [effectKey, effectValue] = item prev.push({ field: effectKey, value: effectValue }) return prev @@ -165,3 +104,66 @@ function useSearchSurvey() { changeButtonValueMap } } + +export const useSurveyListStore = defineStore('surveyList', () => { + const surveyList = ref([]) + const surveyTotal = ref(0) + + const { + searchVal, + selectValueMap, + buttonValueMap, + listFilter, + listOrder, + resetSearch, + resetSelectValueMap, + resetButtonValueMap, + changeSelectValueMap, + changeButtonValueMap + } = useSearchSurvey() + + const workSpaceStore = useWorkSpaceStore() + async function getSurveyList(payload: { curPage?: number; pageSize?: number }) { + const filterString = JSON.stringify( + listFilter.value.filter((item) => { + return item.condition[0].value + }) + ) + const orderString = JSON.stringify(listOrder.value) + try { + const params = { + curPage: payload?.curPage || 1, + pageSize: payload?.pageSize || 10, // 默认一页10条 + filter: filterString, + order: orderString, + workspaceId: workSpaceStore.workSpaceId + } + + const res: any = await getSurveyListReq(params) + if (res.code === CODE_MAP.SUCCESS) { + surveyList.value = res.data.data + surveyTotal.value = res.data.count + } else { + ElMessage.error(res.errmsg) + } + } catch (error) { + ElMessage.error('getSurveyList status' + error) + } + } + + return { + surveyList, + surveyTotal, + searchVal, + selectValueMap, + buttonValueMap, + listFilter: listFilter, + listOrder, + resetSearch, + getSurveyList, + resetSelectValueMap, + resetButtonValueMap, + changeSelectValueMap, + changeButtonValueMap + } +}) diff --git a/web/src/management/stores/teamSpace.ts b/web/src/management/stores/workSpace.ts similarity index 88% rename from web/src/management/stores/teamSpace.ts rename to web/src/management/stores/workSpace.ts index d0902c7a..80e09a34 100644 --- a/web/src/management/stores/teamSpace.ts +++ b/web/src/management/stores/workSpace.ts @@ -1,3 +1,9 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' +import { ElMessage } from 'element-plus' +import 'element-plus/theme-chalk/src/message.scss' + +import { CODE_MAP } from '@/management/api/base' import { createSpace, updateSpace as updateSpaceReq, @@ -5,16 +11,16 @@ import { getSpaceList as getSpaceListReq, getSpaceDetail as getSpaceDetailReq } from '@/management/api/space' -import { CODE_MAP } from '@/management/api/base' import { SpaceType } from '@/management/utils/types/workSpace' -import { defineStore } from 'pinia' -import { ref } from 'vue' -import { ElMessage } from 'element-plus' +import { + type SpaceDetail, + type SpaceItem, + type IWorkspace +} from '@/management/utils/types/workSpace' + import { useSurveyListStore } from './surveyList' -import { type SpaceDetail, type SpaceItem, type IWorkspace } from '@/management/utils/types/workSpace' - -export const useTeamSpaceStore = defineStore('teamSpace', () => { +export const useWorkSpaceStore = defineStore('workSpace', () => { // list空间 const spaceMenus = ref([ { @@ -32,7 +38,7 @@ export const useTeamSpaceStore = defineStore('teamSpace', () => { const spaceType = ref(SpaceType.Personal) const workSpaceId = ref('') const spaceDetail = ref(null) - const teamSpaceList = ref([]) + const workSpaceList = ref([]) const surveyListStore = useSurveyListStore() @@ -42,14 +48,14 @@ export const useTeamSpaceStore = defineStore('teamSpace', () => { if (res.code === CODE_MAP.SUCCESS) { const { list } = res.data - const teamSpace = list.map((item: SpaceDetail) => { + const workSpace = list.map((item: SpaceDetail) => { return { id: item._id, name: item.name } }) - teamSpaceList.value = list - spaceMenus.value[1].children = teamSpace + workSpaceList.value = list + spaceMenus.value[1].children = workSpace } else { ElMessage.error('getSpaceList' + res.errmsg) } @@ -126,7 +132,7 @@ export const useTeamSpaceStore = defineStore('teamSpace', () => { spaceType, workSpaceId, spaceDetail, - teamSpaceList, + workSpaceList, getSpaceList, getSpaceDetail, changeSpaceType, From 1a15faad4289e832627fb41cfc2afb02c3f31a3d Mon Sep 17 00:00:00 2001 From: Jiangchunfu Date: Wed, 10 Jul 2024 14:05:41 +0800 Subject: [PATCH 05/13] =?UTF-8?q?feat:=20edit=20vuex=E8=BF=81=E7=A7=BBpini?= =?UTF-8?q?a=20(#325)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * build: dev reload optimized * feat: edit store change pinia * feat: store中状态修改增加方法 * feat: js改为ts --------- Co-authored-by: jiangchunfu --- web/src/management/hooks/useQuestionInfo.js | 12 +- web/src/management/hooks/useResizeObserver.js | 2 +- .../analysis/components/StatisticsItem.vue | 2 +- .../pages/edit/components/MaterialGroup.vue | 8 +- .../pages/edit/components/ModuleNavbar.vue | 7 +- web/src/management/pages/edit/index.vue | 11 +- .../modules/contentModule/HistoryPanel.vue | 15 +- .../modules/contentModule/PublishPanel.vue | 11 +- .../edit/modules/contentModule/SavePanel.vue | 13 +- .../modules/questionModule/PreviewPanel.vue | 38 +- .../modules/questionModule/SetterPanel.vue | 18 +- .../components/QuestionCatalog.vue | 24 +- .../questionModule/components/TypeList.vue | 20 +- .../modules/settingModule/SettingPanel.vue | 11 +- .../settingModule/result/CatalogPanel.vue | 12 +- .../settingModule/result/PreviewPanel.vue | 15 +- .../settingModule/result/SetterPanel.vue | 18 +- .../settingModule/skin/CatalogPanel.vue | 5 +- .../settingModule/skin/PreviewPanel.vue | 18 +- .../settingModule/skin/SetterPanel.vue | 10 +- .../pages/edit/pages/edit/LogicEditPage.vue | 10 +- .../management/pages/publish/PublishPage.vue | 15 +- web/src/management/stores/edit.ts | 343 ++++++++++++++++++ web/vite.config.ts | 8 +- 24 files changed, 494 insertions(+), 152 deletions(-) create mode 100644 web/src/management/stores/edit.ts diff --git a/web/src/management/hooks/useQuestionInfo.js b/web/src/management/hooks/useQuestionInfo.js index f8f66e3f..19049008 100644 --- a/web/src/management/hooks/useQuestionInfo.js +++ b/web/src/management/hooks/useQuestionInfo.js @@ -1,17 +1,19 @@ import { computed } from 'vue' -import store from '@/management/store' +import { storeToRefs } from 'pinia' +import { useEditStore } from '@/management/stores/edit' import { cleanRichText } from '@/common/xss' export const useQuestionInfo = (field) => { + const editStore = useEditStore() + const { questionDataList } = storeToRefs(editStore) + const getQuestionTitle = computed(() => { - const questionDataList = store.state.edit.schema.questionDataList return () => { - return questionDataList.find((item) => item.field === field)?.title + return questionDataList.value.find((item) => item.field === field)?.title } }) const getOptionTitle = computed(() => { - const questionDataList = store.state.edit.schema.questionDataList return (value) => { - const options = questionDataList.find((item) => item.field === field)?.options || [] + const options = questionDataList.value.find((item) => item.field === field)?.options || [] if (value instanceof Array) { return options .filter((item) => value.includes(item.hash)) diff --git a/web/src/management/hooks/useResizeObserver.js b/web/src/management/hooks/useResizeObserver.js index 486962f2..cbf400ea 100644 --- a/web/src/management/hooks/useResizeObserver.js +++ b/web/src/management/hooks/useResizeObserver.js @@ -1,5 +1,5 @@ // 引入防抖函数 -import _debounce from 'lodash/debounce' +import { debounce as _debounce } from 'lodash-es' /** * @description: 监听元素尺寸变化 * @param {*} el 元素dom diff --git a/web/src/management/pages/analysis/components/StatisticsItem.vue b/web/src/management/pages/analysis/components/StatisticsItem.vue index 7cd95b1e..9d43ce2d 100644 --- a/web/src/management/pages/analysis/components/StatisticsItem.vue +++ b/web/src/management/pages/analysis/components/StatisticsItem.vue @@ -34,7 +34,7 @@