Skip to content

Commit

Permalink
fix: pinia改写
Browse files Browse the repository at this point in the history
  • Loading branch information
skique committed Aug 26, 2024
1 parent 20ef020 commit 2162f3c
Show file tree
Hide file tree
Showing 12 changed files with 383 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { SURVEY_PERMISSION } from 'src/enums/surveyPermission';
import { Logger } from 'src/logger';
import { HttpException } from 'src/exceptions/httpException';
import { EXCEPTION_CODE } from 'src/enums/exceptionCode';
import { val } from 'cheerio/lib/api/attributes';

@ApiTags('survey')
@Controller('/api/surveyHisotry')
export class SurveyHistoryController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class SurveyDownloadService implements OnModuleInit {
}
return {
...data,
difTime: (submitedData.difTime / 1000).toFixed(2),
diffTime: (submitedData.diffTime / 1000).toFixed(2),
createDate: moment(submitedData.createDate).format(
'YYYY-MM-DD HH:mm:ss',
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<script setup lang="ts">
import { ref, computed } from 'vue'
import { useEditStore } from '@/management/stores/edit'
import { useUserStore } from '@/management/stores/user'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox, type Action } from 'element-plus'
import 'element-plus/theme-chalk/src/message.scss'
Expand All @@ -24,9 +25,10 @@ const props = defineProps<Props>()
const isPublishing = ref<boolean>(false)
const editStore = useEditStore()
const { schema, getSchemaFromRemote } = editStore
const userStore = useUserStore()
const router = useRouter()
const saveData = computed(() => {
return buildData(store.state.edit.schema, sessionStorage.getItem('sessionUUID'))
return buildData(schema, sessionStorage.getItem('sessionUUID'))
})
const validate = () => {
Expand Down Expand Up @@ -74,12 +76,12 @@ const onSave = async () => {
// 增加冲突检测
const [isconflict, conflictName] = await checkConflict(saveData.value.surveyId)
if(isconflict) {
if (conflictName == store.state.user.userInfo.username) {
if (conflictName == userStore.userInfo.username) {
ElMessageBox.alert('当前问卷已在其它页面开启编辑,刷新以获取最新内容。', '提示', {
confirmButtonText: '确认',
callback: (action: Action) => {
if (action === 'confirm') {
store.dispatch('edit/getSchemaFromRemote')
getSchemaFromRemote()
}
}
});
Expand All @@ -88,58 +90,7 @@ const onSave = async () => {
confirmButtonText: '确认',
callback: (action: Action) => {
if (action === 'confirm') {
store.dispatch('edit/getSchemaFromRemote')
}
}
});
}
return null
} else {
// 保存数据
res = await saveSurvey(saveData.value)
}
return res
}
const checkConflict = async (surveyid:string) => {
try {
const dailyHis = await getConflictHistory({surveyId: surveyid, historyType: 'dailyHis', sessionId: sessionStorage.getItem('sessionUUID')})
if (dailyHis.data.length > 0) {
const lastHis = dailyHis.data.at(0)
if (Date.now() - lastHis.createDate > 2 * 60 * 1000) {
return [false, '']
}
return [true, lastHis.operator.username]
}
} catch (error) {
console.log(error)
}
return [false, '']
}
const onSave = async () => {
let res
if (!saveData.value.surveyId) {
ElMessage.error('未获取到问卷id')
return null
}
// 增加冲突检测
const [isconflict, conflictName] = await checkConflict(saveData.value.surveyId)
if(isconflict) {
if (conflictName == store.state.user.userInfo.username) {
ElMessageBox.alert('当前问卷已在其它页面开启编辑,刷新以获取最新内容。', '提示', {
confirmButtonText: '确认',
callback: (action: Action) => {
if (action === 'confirm') {
store.dispatch('edit/getSchemaFromRemote')
}
}
});
} else {
ElMessageBox.alert(`当前问卷2分钟内由${conflictName}编辑,刷新以获取最新内容。`, '提示', {
confirmButtonText: '确认',
callback: (action: Action) => {
if (action === 'confirm') {
store.dispatch('edit/getSchemaFromRemote')
getSchemaFromRemote()
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const handleSave = async () => {
isSaving.value = false
}
}
const schemaUpdateTime = computed(() => _get(store.state, 'edit.schemaUpdateTime'))
watch(schemaUpdateTime, () => {
triggerAutoSave()
})
Expand Down
2 changes: 1 addition & 1 deletion web/src/management/pages/edit/setterConfig/baseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default [
{
title: '提交限制',
key: 'limitConfig',
formList: ['limit_tLimit']
formList: ['limit_tLimit', 'limit_breakAnswer', 'limit_backAnswer']
},
{
title: '作答限制',
Expand Down
16 changes: 15 additions & 1 deletion web/src/management/pages/edit/setterConfig/baseFormConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ export default {
type: 'QuestionTimeHour',
placement: 'top'
},
limit_breakAnswer: {
key: 'baseConf.breakAnswer',
label: '允许断点续答',
tip: '回填前一次作答中的内容(注:更换设备/浏览器/清除缓存/更改内容重新发布则此功能失效)',
type: 'ELSwitch',
value: false
},
limit_backAnswer: {
key: 'baseConf.backAnswer',
label: '自动填充上次填写内容',
tip: '回填前一次提交的内容(注:更换设备/浏览器/清除缓存/更改内容重新发布则此功能失效)',
type: 'ELSwitch',
value: false
},
interview_pwd_switch: {
key: 'passwordSwitch',
label: '访问密码',
Expand Down Expand Up @@ -96,5 +110,5 @@ export default {
relyFunc: (data) => {
return data.whitelistType == 'MEMBER'
}
}
},
}
17 changes: 17 additions & 0 deletions web/src/render/components/QuestionWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ const handleChange = (data) => {
if (props.moduleConfig.type === QUESTION_TYPE.VOTE) {
questionStore.updateVoteData(data)
}
// 处理选项配额
if (props.moduleConfig.type === NORMAL_CHOICES) {
store.dispatch('changeQuota', data)
}
// 断点续答的的数据缓存
localStorageBack()
processJumpSkip()
}
Expand Down Expand Up @@ -180,4 +186,15 @@ const processJumpSkip = () => {
questionStore.addNeedHideFields(skipKey)
}
const localStorageBack = () => {
var formData = Object.assign({}, surveyStore.formValues);
for(const key in formData){
formData[key] = encodeURIComponent(formData[key])
}
//浏览器存储
localStorage.removeItem(surveyStore.surveyPath + "_questionData")
localStorage.setItem(surveyStore.surveyPath + "_questionData", JSON.stringify(formData))
localStorage.setItem('isSubmit', JSON.stringify(false))
}
</script>
7 changes: 4 additions & 3 deletions web/src/render/hooks/useOptionsQuota.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import store from '../store/index'
import { useQuestionStore } from '../stores/question'
export const useOptionsQuota = (questionKey) => {
const options = store.state.questionData[questionKey].options.map((option) => {
const questionStore = useQuestionStore()
const options = questionStore.questionData[questionKey].options.map((option) => {
if(option.quota){
const optionHash = option.hash
const selectCount = store.state.quotaMap?.[questionKey]?.[optionHash] || 0
const selectCount = questionStore.quotaMap?.[questionKey]?.[optionHash] || 0
const release = Number(option.quota) - Number(selectCount)
return {
...option,
Expand Down
2 changes: 1 addition & 1 deletion web/src/render/pages/RenderPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const normalizationRequestBody = () => {
localStorage.removeItem(surveyPath.value + "_questionData")
localStorage.removeItem("isSubmit")
//数据加密
var formData = Object.assign({}, store.state.formValues)
var formData = Object.assign({}, surveyStore.formValues)
for(const key in formData){
formData[key] = encodeURIComponent(formData[key])
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/render/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,5 +360,5 @@ export default {
})
// 获取已投票数据
dispatch('initVoteData')
dispatch('initQuotaMap')
// dispatch('initQuotaMap')
}
Loading

0 comments on commit 2162f3c

Please sign in to comment.