From cdb8b6532a6ed0cc6e6e77f7291e44228f26fb85 Mon Sep 17 00:00:00 2001 From: sudoooooo Date: Sun, 22 Sep 2024 01:41:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=86=99=E6=B3=95?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=81C=E7=AB=AF=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../survey/controllers/survey.controller.ts | 11 - .../template/surveyTemplate/templateBase.json | 9 +- .../controllers/responseSchema.controller.ts | 9 +- .../services/surveyResponse.service.ts | 7 +- web/src/common/localstorage.ts | 58 -- web/src/management/App.vue | 8 +- web/src/management/api/base.js | 4 +- web/src/management/hooks/useResizeObserver.js | 4 +- .../pages/edit/components/QuestionWrapper.vue | 2 +- .../modules/contentModule/HistoryPanel.vue | 2 - .../components/TeamMemberList.vue | 2 +- .../edit/modules/skinModule/CatalogPanel.vue | 16 +- .../pages/edit/pages/skin/ContentPage.vue | 12 +- .../pages/edit/setterConfig/baseFormConfig.js | 10 +- .../pages/list/components/BaseList.vue | 6 - .../pages/list/components/SpaceList.vue | 14 +- web/src/management/pages/login/LoginPage.vue | 23 +- web/src/management/router/index.ts | 6 +- ...EditGlobalBaseConf.ts => useBaseConfig.ts} | 2 +- .../stores/composables/useCurrentEdit.ts | 100 +++ .../stores/composables/useInitializeSchema.ts | 146 ++++ .../stores/composables/useLogicEngine.ts | 20 + .../stores/composables/usePageEdit.ts | 156 ++++ .../stores/composables/useQuestionData.ts | 72 ++ web/src/management/stores/edit.ts | 708 +++--------------- web/src/management/stores/user.ts | 19 +- web/src/management/utils/storage.ts | 22 + .../questions/widgets/BaseInput/index.jsx | 2 +- web/src/render/components/AlertDialog.vue | 16 +- web/src/render/components/ConfirmDialog.vue | 101 ++- web/src/render/components/ProgressBar.vue | 1 - web/src/render/components/QuestionWrapper.vue | 133 ++-- .../VerifyDialog/FillDataDialog.vue | 23 + .../VerifyDialog/WhiteListDialog.vue | 80 ++ .../render/components/VerifyDialog/index.vue | 73 ++ .../render/components/VerifyWhiteDialog.vue | 147 ---- .../{useShowInput.js => useInputData.js} | 2 +- .../{useShowOthers.js => useOthersData.js} | 2 +- web/src/render/hooks/useProgress.js | 2 +- web/src/render/pages/EmptyPage.vue | 4 +- web/src/render/pages/IndexPage.vue | 68 +- web/src/render/pages/RenderPage.vue | 112 +-- web/src/render/pages/SuccessPage.vue | 4 +- web/src/render/plugins/dialog/index.js | 56 -- web/src/render/stores/question.js | 28 +- web/src/render/stores/survey.js | 48 +- web/src/render/styles/dialog.scss | 59 +- web/src/render/utils/constant.ts | 5 - web/src/render/utils/storage.ts | 44 ++ 49 files changed, 1259 insertions(+), 1199 deletions(-) delete mode 100644 web/src/common/localstorage.ts rename web/src/management/stores/composables/{useEditGlobalBaseConf.ts => useBaseConfig.ts} (98%) create mode 100644 web/src/management/stores/composables/useCurrentEdit.ts create mode 100644 web/src/management/stores/composables/useInitializeSchema.ts create mode 100644 web/src/management/stores/composables/useLogicEngine.ts create mode 100644 web/src/management/stores/composables/usePageEdit.ts create mode 100644 web/src/management/stores/composables/useQuestionData.ts create mode 100644 web/src/management/utils/storage.ts create mode 100644 web/src/render/components/VerifyDialog/FillDataDialog.vue create mode 100644 web/src/render/components/VerifyDialog/WhiteListDialog.vue create mode 100644 web/src/render/components/VerifyDialog/index.vue delete mode 100644 web/src/render/components/VerifyWhiteDialog.vue rename web/src/render/hooks/{useShowInput.js => useInputData.js} (95%) rename web/src/render/hooks/{useShowOthers.js => useOthersData.js} (95%) delete mode 100644 web/src/render/plugins/dialog/index.js delete mode 100644 web/src/render/utils/constant.ts create mode 100644 web/src/render/utils/storage.ts diff --git a/server/src/modules/survey/controllers/survey.controller.ts b/server/src/modules/survey/controllers/survey.controller.ts index f68cc456..19f80af8 100644 --- a/server/src/modules/survey/controllers/survey.controller.ts +++ b/server/src/modules/survey/controllers/survey.controller.ts @@ -33,7 +33,6 @@ import { SURVEY_PERMISSION } from 'src/enums/surveyPermission'; import { WorkspaceGuard } from 'src/guards/workspace.guard'; import { PERMISSION as WORKSPACE_PERMISSION } from 'src/enums/workspace'; import { SessionService } from '../services/session.service'; -import { MemberType, WhitelistType } from 'src/interfaces/survey'; import { UserService } from 'src/modules/auth/services/user.service'; @ApiTags('survey') @@ -247,16 +246,6 @@ export class SurveyController { surveyMeta.isCollaborated = false; } - // 白名单相关字段的默认值 - const baseConf = surveyConf.code?.baseConf; - if (baseConf) { - baseConf.passwordSwitch = baseConf.passwordSwitch ?? false; - baseConf.password = baseConf.password ?? ''; - baseConf.whitelistType = baseConf.whitelistType ?? WhitelistType.ALL; - baseConf.whitelist = baseConf.whitelist ?? []; - baseConf.memberType = baseConf.memberType ?? MemberType.MOBILE; - } - return { code: 200, data: { diff --git a/server/src/modules/survey/template/surveyTemplate/templateBase.json b/server/src/modules/survey/template/surveyTemplate/templateBase.json index 70726a46..2af433e7 100644 --- a/server/src/modules/survey/template/surveyTemplate/templateBase.json +++ b/server/src/modules/survey/template/surveyTemplate/templateBase.json @@ -34,7 +34,14 @@ "tLimit": 0, "language": "chinese", "answerBegTime": "00:00:00", - "answerEndTime": "23:59:59" + "answerEndTime": "23:59:59", + "passwordSwitch": false, + "password": "", + "whitelistType": "ALL", + "whitelist": [], + "memberType": "MOBILE", + "fillAnswer": false, + "fillSubmitAnswer": false }, "skinConf": { "skinColor": "#4a4c5b", diff --git a/server/src/modules/surveyResponse/controllers/responseSchema.controller.ts b/server/src/modules/surveyResponse/controllers/responseSchema.controller.ts index 2640eefd..5d8bd2e3 100644 --- a/server/src/modules/surveyResponse/controllers/responseSchema.controller.ts +++ b/server/src/modules/surveyResponse/controllers/responseSchema.controller.ts @@ -97,14 +97,17 @@ export class ResponseSchemaController { // 密码校验 if (passwordSwitch) { if (settingPassword !== password) { - throw new HttpException('验证失败', EXCEPTION_CODE.WHITELIST_ERROR); + throw new HttpException('密码验证失败', EXCEPTION_CODE.WHITELIST_ERROR); } } // 名单校验(手机号/邮箱) if (whitelistType === WhitelistType.CUSTOM) { if (!whitelist.includes(whitelistValue)) { - throw new HttpException('验证失败', EXCEPTION_CODE.WHITELIST_ERROR); + throw new HttpException( + '白名单验证失败', + EXCEPTION_CODE.WHITELIST_ERROR, + ); } } @@ -112,7 +115,7 @@ export class ResponseSchemaController { if (whitelistType === WhitelistType.MEMBER) { const user = await this.userService.getUserByUsername(whitelistValue); if (!user) { - throw new HttpException('验证失败', EXCEPTION_CODE.WHITELIST_ERROR); + throw new HttpException('名单验证失败', EXCEPTION_CODE.WHITELIST_ERROR); } const workspaceMember = await this.workspaceMemberService.findAllByUserId( diff --git a/server/src/modules/surveyResponse/services/surveyResponse.service.ts b/server/src/modules/surveyResponse/services/surveyResponse.service.ts index 59fa3543..78d79333 100644 --- a/server/src/modules/surveyResponse/services/surveyResponse.service.ts +++ b/server/src/modules/surveyResponse/services/surveyResponse.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { MongoRepository } from 'typeorm'; import { SurveyResponse } from 'src/models/surveyResponse.entity'; +import { RECORD_STATUS } from 'src/enums'; @Injectable() export class SurveyResponseService { constructor( @@ -35,14 +36,14 @@ export class SurveyResponseService { } async getSurveyResponseTotalByPath(surveyPath: string) { - const count = await this.surveyResponseRepository.count({ + const data = await this.surveyResponseRepository.find({ where: { surveyPath, 'curStatus.status': { - $ne: 'removed', + $ne: RECORD_STATUS.REMOVED, }, }, }); - return count; + return (data || []).length; } } diff --git a/web/src/common/localstorage.ts b/web/src/common/localstorage.ts deleted file mode 100644 index 0b5526c0..00000000 --- a/web/src/common/localstorage.ts +++ /dev/null @@ -1,58 +0,0 @@ -interface ExtendedItem { - value: any - expires?: number // 可选属性 -} - -const localstorage = { - // 检查是否支持localStorage - isSupported(): boolean { - return typeof window !== 'undefined' && 'localStorage' in window - }, - - // 设置值 - setItem(key: string, value: any, expires?: number): void { - if (!this.isSupported()) return - - let item: ExtendedItem = { value } - - if (expires !== undefined) { - item = { ...item, expires: Date.now() + expires * 1000 } - } - - const serializedValue = JSON.stringify(item) - - localStorage.setItem(key, serializedValue) - }, - - // 获取值 - getItem(key: string): T | null { - if (!this.isSupported()) return null - - const serializedValue = localStorage.getItem(key) as string - if (!serializedValue) return null - - let item: any - try { - item = JSON.parse(serializedValue) - } catch (e) { - console.error('Error parsing JSON from localStorage') - return null - } - - if (item.expires && item.expires < Date.now()) { - this.removeItem(key) - return null - } - - return item.value as T - }, - - // 移除值 - removeItem(key: string): void { - if (!this.isSupported()) return - - localStorage.removeItem(key) - } -} - -export default localstorage diff --git a/web/src/management/App.vue b/web/src/management/App.vue index 0041c563..c26a6762 100644 --- a/web/src/management/App.vue +++ b/web/src/management/App.vue @@ -18,7 +18,7 @@ const router = useRouter() let timer: any const showConfirmBox = () => { - ElMessageBox.alert('登录状态已失效,请重新登陆。', '提示', { + ElMessageBox.alert('登录状态已失效,请重新登录。', '提示', { confirmButtonText: '确认', showClose: false, callback: (action: Action) => { @@ -57,9 +57,9 @@ const checkAuth = async () => { } watch( - () => userStore.hasLogined, - (hasLogined) => { - if (hasLogined) { + () => userStore.hasLogin, + (hasLogin) => { + if (hasLogin) { timer = setTimeout( () => { checkAuth() diff --git a/web/src/management/api/base.js b/web/src/management/api/base.js index 1268f8bc..ab096cb8 100644 --- a/web/src/management/api/base.js +++ b/web/src/management/api/base.js @@ -37,9 +37,9 @@ instance.interceptors.response.use( instance.interceptors.request.use((config) => { const userStore = useUserStore() - const hasLogined = _get(userStore, 'hasLogined') + const hasLogin = _get(userStore, 'hasLogin') const token = _get(userStore, 'userInfo.token') - if (hasLogined && token) { + if (hasLogin && token) { if (!config.headers) { config.headers = {} } diff --git a/web/src/management/hooks/useResizeObserver.js b/web/src/management/hooks/useResizeObserver.js index cbf400ea..61e584a2 100644 --- a/web/src/management/hooks/useResizeObserver.js +++ b/web/src/management/hooks/useResizeObserver.js @@ -1,5 +1,5 @@ // 引入防抖函数 -import { debounce as _debounce } from 'lodash-es' +import { debounce } from 'lodash-es' /** * @description: 监听元素尺寸变化 * @param {*} el 元素dom @@ -8,7 +8,7 @@ import { debounce as _debounce } from 'lodash-es' * @return {*} */ export default (el, cb, wait = 200) => { - const resizeObserver = new ResizeObserver(_debounce(cb, wait)) + const resizeObserver = new ResizeObserver(debounce(cb, wait)) resizeObserver.observe(el) diff --git a/web/src/management/pages/edit/components/QuestionWrapper.vue b/web/src/management/pages/edit/components/QuestionWrapper.vue index 9d8b2cab..ca0afd06 100644 --- a/web/src/management/pages/edit/components/QuestionWrapper.vue +++ b/web/src/management/pages/edit/components/QuestionWrapper.vue @@ -7,7 +7,7 @@ >
-
+
{ id: v.ownerId, label: v.name, children: members?.map((v) => ({ - id: v.userId, + id: `${v.workspaceId}_${v.userId}`, label: v.username })) }) diff --git a/web/src/management/pages/edit/modules/skinModule/CatalogPanel.vue b/web/src/management/pages/edit/modules/skinModule/CatalogPanel.vue index 6d6c7275..077129dc 100644 --- a/web/src/management/pages/edit/modules/skinModule/CatalogPanel.vue +++ b/web/src/management/pages/edit/modules/skinModule/CatalogPanel.vue @@ -26,15 +26,21 @@
diff --git a/web/src/render/components/ConfirmDialog.vue b/web/src/render/components/ConfirmDialog.vue index 82c0e40c..cd7445e8 100644 --- a/web/src/render/components/ConfirmDialog.vue +++ b/web/src/render/components/ConfirmDialog.vue @@ -1,74 +1,115 @@ diff --git a/web/src/render/components/VerifyDialog/WhiteListDialog.vue b/web/src/render/components/VerifyDialog/WhiteListDialog.vue new file mode 100644 index 00000000..8aea4c15 --- /dev/null +++ b/web/src/render/components/VerifyDialog/WhiteListDialog.vue @@ -0,0 +1,80 @@ + + + diff --git a/web/src/render/components/VerifyDialog/index.vue b/web/src/render/components/VerifyDialog/index.vue new file mode 100644 index 00000000..e7b1a4c9 --- /dev/null +++ b/web/src/render/components/VerifyDialog/index.vue @@ -0,0 +1,73 @@ + + + diff --git a/web/src/render/components/VerifyWhiteDialog.vue b/web/src/render/components/VerifyWhiteDialog.vue deleted file mode 100644 index 4e61768f..00000000 --- a/web/src/render/components/VerifyWhiteDialog.vue +++ /dev/null @@ -1,147 +0,0 @@ - - - diff --git a/web/src/render/hooks/useShowInput.js b/web/src/render/hooks/useInputData.js similarity index 95% rename from web/src/render/hooks/useShowInput.js rename to web/src/render/hooks/useInputData.js index b4982c4f..8a1444f3 100644 --- a/web/src/render/hooks/useShowInput.js +++ b/web/src/render/hooks/useInputData.js @@ -1,7 +1,7 @@ import { useQuestionStore } from '../stores/question' import { useSurveyStore } from '../stores/survey' -export const useShowInput = (questionKey) => { +export const useInputData = (questionKey) => { const questionStore = useQuestionStore() const surveyStore = useSurveyStore() const formValues = surveyStore.formValues diff --git a/web/src/render/hooks/useShowOthers.js b/web/src/render/hooks/useOthersData.js similarity index 95% rename from web/src/render/hooks/useShowOthers.js rename to web/src/render/hooks/useOthersData.js index df5a8b9e..a60c2809 100644 --- a/web/src/render/hooks/useShowOthers.js +++ b/web/src/render/hooks/useOthersData.js @@ -1,7 +1,7 @@ import { useQuestionStore } from '../stores/question' import { useSurveyStore } from '../stores/survey' -export const useShowOthers = (questionKey) => { +export const useOthersData = (questionKey) => { const questionStore = useQuestionStore() const surveyStore = useSurveyStore() const formValues = surveyStore.formValues diff --git a/web/src/render/hooks/useProgress.js b/web/src/render/hooks/useProgress.js index b76981cb..7dd3e3f8 100644 --- a/web/src/render/hooks/useProgress.js +++ b/web/src/render/hooks/useProgress.js @@ -38,7 +38,7 @@ export const useProgressBar = () => { const percent = computed(() => { const { fillCount, topicCount } = surveySchedule.value - return Math.floor((100 / topicCount) * fillCount) + '%' + return Math.floor((100 / topicCount) * fillCount) || 0 + '%' }) return { surveySchedule, percent } diff --git a/web/src/render/pages/EmptyPage.vue b/web/src/render/pages/EmptyPage.vue index 2bb2f28d..1e8f1a0d 100644 --- a/web/src/render/pages/EmptyPage.vue +++ b/web/src/render/pages/EmptyPage.vue @@ -1,9 +1,7 @@ diff --git a/web/src/render/pages/IndexPage.vue b/web/src/render/pages/IndexPage.vue index 94161030..3b624ff5 100644 --- a/web/src/render/pages/IndexPage.vue +++ b/web/src/render/pages/IndexPage.vue @@ -2,10 +2,15 @@ diff --git a/web/src/render/pages/RenderPage.vue b/web/src/render/pages/RenderPage.vue index 5cf503fb..b70f8f9d 100644 --- a/web/src/render/pages/RenderPage.vue +++ b/web/src/render/pages/RenderPage.vue @@ -16,31 +16,36 @@ >
- +
diff --git a/web/src/render/pages/SuccessPage.vue b/web/src/render/pages/SuccessPage.vue index a6fc73b9..8ea66acd 100644 --- a/web/src/render/pages/SuccessPage.vue +++ b/web/src/render/pages/SuccessPage.vue @@ -30,7 +30,9 @@ import communalLoader from '@materials/communals/communalLoader.js' const LogoIcon = communalLoader.loadComponent('LogoIcon') const surveyStore = useSurveyStore() -const logoConf = computed(() => surveyStore?.bottomConf || {}) +const logoConf = computed(() => { + return surveyStore?.bottomConf || {} +}) const successMsg = computed(() => { const msgContent = (surveyStore?.submitConf as any)?.msgContent || {} return msgContent?.msg_200 || '提交成功' diff --git a/web/src/render/plugins/dialog/index.js b/web/src/render/plugins/dialog/index.js deleted file mode 100644 index 433c334d..00000000 --- a/web/src/render/plugins/dialog/index.js +++ /dev/null @@ -1,56 +0,0 @@ -import ConfirmDialog from '../../components/ConfirmDialog.vue' -import AlertDialog from '../../components/AlertDialog.vue' - -import { isFunction as _isFunction } from 'lodash-es' - -export default { - install(Vue) { - Vue.prototype.$dialog = { - confirm(options) { - const MyComponent = Vue.extend(ConfirmDialog) - const instance = new MyComponent({ - propsData: options - }) - const closeConfirm = () => { - if (instance && instance.$el) { - instance.$el.remove() - } - } - instance.$on('cancel', () => { - if (options?.onCancel && _isFunction(options.onCancel)) { - options.onCancel(closeConfirm) - } else { - closeConfirm() - } - }) - instance.$on('confirm', () => { - if (options?.onConfirm && _isFunction(options.onConfirm)) { - options.onConfirm(closeConfirm) - } - }) - instance.$mount() - document.body.append(instance.$el) - }, - alert(options) { - const MyComponent = Vue.extend(AlertDialog) - const instance = new MyComponent({ - propsData: options - }) - const closeConfirm = () => { - if (instance && instance.$el) { - instance.$el.remove() - } - } - instance.$on('confirm', () => { - if (options?.onConfirm && _isFunction(options.onConfirm)) { - options.onConfirm(closeConfirm) - } else { - closeConfirm() - } - }) - instance.$mount() - document.body.append(instance.$el) - } - } - } -} diff --git a/web/src/render/stores/question.js b/web/src/render/stores/question.js index 0182a822..c702d8ba 100644 --- a/web/src/render/stores/question.js +++ b/web/src/render/stores/question.js @@ -4,11 +4,11 @@ import { set } from 'lodash-es' import { useSurveyStore } from '@/render/stores/survey' import { queryVote } from '@/render/api/survey' import { QUESTION_TYPE } from '@/common/typeEnum' -import { VOTE_INFO_KEY } from '@/render/utils/constant' -import localstorage from '@/common/localstorage' + +import { getVoteData, setVoteData, clearVoteData } from '@/render/utils/storage' // 投票进度逻辑聚合 -const usevVoteMap = (questionData) => { +const useVoteMap = (questionData) => { const voteMap = ref({}) //初始化投票题的数据 const initVoteData = async () => { @@ -28,16 +28,14 @@ const usevVoteMap = (questionData) => { return } try { - localstorage.removeItem(VOTE_INFO_KEY) + clearVoteData() const voteRes = await queryVote({ surveyPath, fieldList: fieldList.join(',') }) if (voteRes.code === 200) { - localstorage.setItem(VOTE_INFO_KEY, { - ...voteRes.data - }) + setVoteData(voteRes.data) setVoteMap(voteRes.data) } } catch (error) { @@ -58,25 +56,25 @@ const usevVoteMap = (questionData) => { const updateVoteData = (data) => { const { key: questionKey, value: questionVal } = data // 更新前获取接口缓存在localstorage中的数据 - const voteinfo = localstorage.getItem(VOTE_INFO_KEY) + const voteInfo = getVoteData() const currentQuestion = questionData.value[questionKey] const options = currentQuestion.options - const voteTotal = voteinfo?.[questionKey]?.total || 0 + const voteTotal = voteInfo?.[questionKey]?.total || 0 let totalPayload = { questionKey, voteKey: 'total', voteValue: voteTotal } options.forEach((option) => { - const optionhash = option.hash - const voteCount = voteinfo?.[questionKey]?.[optionhash] || 0 + const optionHash = option.hash + const voteCount = voteInfo?.[questionKey]?.[optionHash] || 0 // 如果选中值包含该选项,对应voteCount 和 voteTotal + 1 if ( - Array.isArray(questionVal) ? questionVal.includes(optionhash) : questionVal === optionhash + Array.isArray(questionVal) ? questionVal.includes(optionHash) : questionVal === optionHash ) { const countPayload = { questionKey, - voteKey: optionhash, + voteKey: optionHash, voteValue: voteCount + 1 } totalPayload.voteValue += 1 @@ -84,7 +82,7 @@ const usevVoteMap = (questionData) => { } else { const countPayload = { questionKey, - voteKey: optionhash, + voteKey: optionHash, voteValue: voteCount } updateVoteMapByKey(countPayload) @@ -174,7 +172,7 @@ export const useQuestionStore = defineStore('question', () => { const setQuestionData = (data) => { questionData.value = data } - const { voteMap, setVoteMap, initVoteData, updateVoteData } = usevVoteMap(questionData) + const { voteMap, setVoteMap, initVoteData, updateVoteData } = useVoteMap(questionData) const changeSelectMoreData = (data) => { const { key, value, field } = data diff --git a/web/src/render/stores/survey.js b/web/src/render/stores/survey.js index 85182548..d699238d 100644 --- a/web/src/render/stores/survey.js +++ b/web/src/render/stores/survey.js @@ -1,25 +1,20 @@ import { ref } from 'vue' import { useRouter } from 'vue-router' import { defineStore } from 'pinia' -import { cloneDeep, pick } from 'lodash-es' +import { pick } from 'lodash-es' import moment from 'moment' // 引入中文 import 'moment/locale/zh-cn' // 设置中文 import { isMobile as isInMobile } from '@/render/utils/index' + import { getEncryptInfo as getEncryptInfoApi } from '@/render/api/survey' import { useQuestionStore } from '@/render/stores/question' import { useErrorInfo } from '@/render/stores/errorInfo' -import { FORMDATA_SUFFIX, SUBMIT_FLAG } from '@/render/utils/constant' import adapter from '../adapter' import { RuleMatch } from '@/common/logicEngine/RulesMatch' -import useCommandComponent from '../hooks/useCommandComponent' -import ConfirmDialog from '../components/ConfirmDialog.vue' -import localstorage from '@/common/localstorage' - -const confirm = useCommandComponent(ConfirmDialog) moment.locale('zh-cn') /** @@ -63,6 +58,10 @@ export const useSurveyStore = defineStore('survey', () => { enterTime.value = Date.now() } + const setFormValues = (data) => { + formValues.value = data + } + const getEncryptInfo = async () => { try { const res = await getEncryptInfoApi() @@ -154,13 +153,7 @@ export const useSurveyStore = defineStore('survey', () => { // 获取已投票数据 questionStore.initVoteData() } - function fillFormData(formData) { - const _formValues = cloneDeep(formValues.value) - for (const key in formData) { - _formValues[key] = formData[key] - } - formValues.value = _formValues - } + const initSurvey = (option) => { setEnterTime() if (!canFillQuestionnaire(option.baseConf, option.submitConf)) { @@ -168,31 +161,6 @@ export const useSurveyStore = defineStore('survey', () => { } // 加载空白问卷 clearFormData(option) - - const { fillAnswer, fillSubmitAnswer } = option.baseConf - const localData = localstorage.getItem(surveyPath.value + FORMDATA_SUFFIX) - - const isSubmit = localstorage.getItem(SUBMIT_FLAG) - // 开启了断点续答 or 回填上一次提交内容 - if ((fillAnswer || (fillSubmitAnswer && isSubmit)) && localData) { - const title = fillAnswer ? '是否继续上次填写的内容?' : '是否继续上次提交的内容?' - confirm({ - title: title, - onConfirm: async () => { - try { - // 回填答题内容 - fillFormData(localData) - } catch (error) { - console.error(error) - } finally { - confirm.close() - } - }, - onClose: async () => { - confirm.close() - } - }) - } } // 用户输入或者选择后,更新表单数据 @@ -204,6 +172,7 @@ export const useSurveyStore = defineStore('survey', () => { questionStore.setChangeField(key) } + // 初始化逻辑引擎 const showLogicEngine = ref() const initShowLogicEngine = (showLogicConf) => { showLogicEngine.value = new RuleMatch().fromJson(showLogicConf || []) @@ -231,6 +200,7 @@ export const useSurveyStore = defineStore('survey', () => { initSurvey, changeData, setWhiteData, + setFormValues, setSurveyPath, setEnterTime, getEncryptInfo, diff --git a/web/src/render/styles/dialog.scss b/web/src/render/styles/dialog.scss index 55845cc4..4def5a0c 100644 --- a/web/src/render/styles/dialog.scss +++ b/web/src/render/styles/dialog.scss @@ -8,19 +8,70 @@ flex-direction: column; align-items: center; justify-content: center; - background-color: rgba(0, 0, 0, 0.3); + background-color: #292a36f2; } .box { - width: 6rem; + width: 6.3rem; background: #fff; - padding: 0.56rem 0.44rem 0.32rem; + padding: 0.56rem 0.44rem 0.4rem; +} + +.head-wrapper { + margin-bottom: 0.5rem; } .title { - font-size: 0.3rem; + font-size: 0.33rem; color: #4a4c5b; letter-spacing: 0; text-align: center; font-weight: 600; } + +.form-item { + margin-top: 0.2rem; +} + +.input-wrapper { + padding: 1px 11px; + background-color: #fff; + border-radius: 0.1rem; + box-shadow: 0 0 0 1px #dcdfe6 inset; +} +.input-wrapper:hover { + box-shadow: 0 0 0 1px var(--primary-color) inset; +} + +.input-inner { + width: 100%; + color: #606266; + font-size: 0.27rem; + height: 0.6rem; + line-height: 0.6rem; + padding: 0; + outline: none; + border: none; + background: none; + box-sizing: border-box; +} + +.btn { + font-size: 0.26rem; + border-radius: 0.04rem; + text-align: center; + padding: 0.1rem 0; + line-height: 0.5rem; + cursor: pointer; + + &.btn-shallow { + background: #fff; + color: #92949d; + border: 1px solid #e3e4e8; + } + + &.btn-primary { + background-color: var(--primary-color); + color: #fff; + } +} diff --git a/web/src/render/utils/constant.ts b/web/src/render/utils/constant.ts deleted file mode 100644 index 41db3f26..00000000 --- a/web/src/render/utils/constant.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const VOTE_INFO_KEY = 'voteinfo' -export const QUOTA_INFO_KEY = 'limitinfo' - -export const SUBMIT_FLAG = 'isSubmit' -export const FORMDATA_SUFFIX = '_questionData' diff --git a/web/src/render/utils/storage.ts b/web/src/render/utils/storage.ts new file mode 100644 index 00000000..1d71fb62 --- /dev/null +++ b/web/src/render/utils/storage.ts @@ -0,0 +1,44 @@ +// 用于记录“问卷断点续答”的数据 +export const getSurveyData = (id: string): any => { + try { + return JSON.parse(localStorage.getItem(`${id}_questionData`) as string) || null + } catch (e) { + console.log(e) + } + + return null +} +export const setSurveyData = (id: string, formData: any = {}) => { + localStorage.setItem(`${id}_questionData`, JSON.stringify(formData)) +} +export const clearSurveyData = (id: string) => localStorage.removeItem(`${id}_questionData`) + +// 问卷是否提交过,用于“自动填充上次填写内容” +export const getSurveySubmit = (id: string): number => { + try { + return Number(JSON.parse(localStorage.getItem(`${id}_submit`) as string)) || 0 + } catch (e) { + console.log(e) + } + + return 0 +} +export const setSurveySubmit = (id: string, value: number) => { + localStorage.setItem(`${id}_submit`, JSON.stringify(value)) +} +export const clearSurveySubmit = (id: string) => localStorage.removeItem(`${id}_submit`) + +// 投票记录 +export const getVoteData = (): any => { + try { + return JSON.parse(localStorage.getItem('voteData') as string) || null + } catch (e) { + console.log(e) + } + + return null +} +export const setVoteData = (params: any) => { + localStorage.setItem('voteData', JSON.stringify(params)) +} +export const clearVoteData = () => localStorage.removeItem('voteData')