Skip to content

Commit

Permalink
fix: 第二批cr优化
Browse files Browse the repository at this point in the history
  • Loading branch information
skique committed Sep 19, 2024
1 parent 3e495e1 commit 55f5230
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 23 deletions.
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@nestjs/swagger": "^7.3.0",
"@nestjs/typeorm": "^10.0.1",
"ali-oss": "^6.20.0",
"cheerio": "^1.0.0-rc.12",
"cheerio": "1.0.0-rc.12",
"crypto-js": "^4.2.0",
"dotenv": "^16.3.2",
"fs-extra": "^11.2.0",
Expand Down
58 changes: 58 additions & 0 deletions web/src/common/localStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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 };
}

let serializedValue = JSON.stringify(item);

localStorage.setItem(key, serializedValue);
},

// 获取值
getItem<T>(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;
2 changes: 1 addition & 1 deletion web/src/common/xss.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const myxss = new xss.FilterXSS({
},
onIgnoreTag(tag, html) {
// <xxx>过滤为空,否则不过滤为空
var re1 = new RegExp('<.+?>', 'g')
let re1 = new RegExp('<.+?>', 'g')
if (re1.test(html)) {
return ''
} else {
Expand Down
4 changes: 1 addition & 3 deletions web/src/management/pages/analysis/pages/DataTablePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
<div class="data-table-page">
<template v-if="tableData.total">
<div class="menus">
<el-button type="primary" :loading="isDownloading" @click="onDownload"
>导出全部数据</el-button
>
<el-button type="primary" :loading="isDownloading" @click="onDownload">导出全部数据</el-button>
<el-switch
class="desensitive-switch"
:model-value="isShowOriginData"
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', 'limit_breakpointAnswer', 'limit_fillsubmitAnswer']
formList: ['limit_tLimit', 'limit_fillAnswer', 'limit_fillSubmitAnswer']
},
{
title: '作答限制',
Expand Down
8 changes: 4 additions & 4 deletions web/src/management/pages/edit/setterConfig/baseFormConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ export default {
type: 'QuestionTimeHour',
placement: 'top'
},
limit_breakpointAnswer: {
key: 'breakpointAnswer',
limit_fillAnswer: {
key: 'fillAnswer',
label: '允许断点续答',
tip: '回填前一次作答中的内容(注:更换设备/浏览器/清除缓存/更改内容重新发布则此功能失效)',
placement: 'top',
type: 'CustomedSwitch',
value: false
},
limit_fillsubmitAnswer: {
key: 'fillsubmitAnswer',
limit_fillSubmitAnswer: {
key: 'fillSubmitAnswer',
label: '自动填充上次提交内容',
tip: '回填前一次提交的内容(注:更换设备/浏览器/清除缓存/更改内容重新发布则此功能失效)',
placement: 'top',
Expand Down
2 changes: 1 addition & 1 deletion web/src/management/pages/login/LoginPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<el-form-item label="验证码" prop="captcha">
<div class="captcha-wrapper">
<el-input style="width: 280px" v-model="formData.captcha" size="large"></el-input>
<div class="captcha-img" click="refreshCaptcha" v-html="captchaImgData"></div>
<div class="captcha-img" @click="refreshCaptcha" v-html="captchaImgData"></div>
</div>
</el-form-item>

Expand Down
3 changes: 1 addition & 2 deletions web/src/management/stores/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,7 @@ export const useEditStore = defineStore('edit', () => {
async function init() {
const { metaData } = schema
if (!metaData || (metaData as any)?._id !== surveyId.value) {
await getSchemaFromRemote()
await initSessionId()
await Promise.all([getSchemaFromRemote(), initSessionId()])
}
currentEditOne.value = null
currentEditStatus.value = 'Success'
Expand Down
14 changes: 7 additions & 7 deletions web/src/render/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<script>
;(function () {
function resetRemUnit() {
var PC_W = 750
var docEl = window.document.documentElement
var width = docEl.getBoundingClientRect().width || 375
let PC_W = 750
let docEl = window.document.documentElement
let width = docEl.getBoundingClientRect().width || 375

if (!/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
width = width < PC_W ? width : PC_W
Expand All @@ -20,15 +20,15 @@
}
}

var f = Math.min(width / 7.5, 50)
let f = Math.min(width / 7.5, 50)
docEl.style.fontSize = f + 'px'

var d = window.document.createElement('div')
let d = window.document.createElement('div')
d.style.width = '1rem'
d.style.display = 'none'
var head = window.document.getElementsByTagName('head')[0]
let head = window.document.getElementsByTagName('head')[0]
head.appendChild(d)
var realf = parseFloat(window.getComputedStyle(d, null).getPropertyValue('width'))
let realf = parseFloat(window.getComputedStyle(d, null).getPropertyValue('width'))

if (f !== realf) {
docEl.style.fontSize = f * (f / realf) + 'px'
Expand Down
6 changes: 3 additions & 3 deletions web/src/render/stores/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ export const useSurveyStore = defineStore('survey', () => {
// 加载空白问卷
clearFormData(option)

const { breakpointAnswer, fillsubmitAnswer } = option.baseConf
const { fillAnswer, fillSubmitAnswer } = option.baseConf
const localData = parseJson(localStorage.getItem(surveyPath.value + FORMDATA_SUFFIX))

const isSubmit = parseJson(localStorage.getItem(SUBMIT_FLAG))
// 开启了断点续答 or 回填上一次提交内容
if ((breakpointAnswer || (fillsubmitAnswer && isSubmit)) && localData) {
const title = breakpointAnswer ? '是否继续上次填写的内容?' : '是否继续上次提交的内容?'
if ((fillAnswer || (fillSubmitAnswer && isSubmit)) && localData) {
const title = fillAnswer ? '是否继续上次填写的内容?' : '是否继续上次提交的内容?'
confirm({
title: title,
onConfirm: async () => {
Expand Down

0 comments on commit 55f5230

Please sign in to comment.