storetext policies

This commit is contained in:
Jesse-Ma
2023-03-29 16:11:59 +08:00
parent b017e7bda1
commit 0de98e660b
4 changed files with 86 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
NODE_ENV = developement NODE_ENV = developement
VUE_APP_BASE_NAME = developement VUE_APP_BASE_NAME = developement
VUE_APP_BASE_URL = http://localhost:8080 VUE_APP_BASE_URL = http://localhost:8080
VUE_APP_NOTE_MAX_COUNT = 409600 VUE_APP_NOTE_MAX_COUNT = 131072
VUE_APP_NOTE_MAX_DESC = 400K VUE_APP_NOTE_MAX_DESC = 128K

View File

@@ -1,5 +1,5 @@
NODE_ENV = production NODE_ENV = production
VUE_APP_BASE_NAME = production VUE_APP_BASE_NAME = production
VUE_APP_BASE_URL = https://flagnote.com VUE_APP_BASE_URL = https://flagnote.com
VUE_APP_NOTE_MAX_COUNT = 409600 VUE_APP_NOTE_MAX_COUNT = 131072
VUE_APP_NOTE_MAX_DESC = 400K VUE_APP_NOTE_MAX_DESC = 128K

View File

@@ -115,8 +115,7 @@
@click="createNote(); switchMenu(); " icon="md-add"></Button> @click="createNote(); switchMenu(); " icon="md-add"></Button>
<Button aria-label="crop" v-show="model.showDownloadText" type="error" <Button aria-label="crop" v-show="model.showDownloadText" type="error"
style="border-radius: 0px;font-size: 24px;" @click="saveImage();switchMenu();" style="border-radius: 0px;font-size: 24px;" @click="saveImage(); switchMenu();" icon="md-crop"></Button>
icon="md-crop"></Button>
<Button aria-label="download text" v-show="model.showDownloadText" type="error" <Button aria-label="download text" v-show="model.showDownloadText" type="error"
style="border-radius: 0px;font-size: 24px;" @click="downLoadText(); switchMenu();" style="border-radius: 0px;font-size: 24px;" @click="downLoadText(); switchMenu();"
@@ -144,7 +143,7 @@
:lg="{ span: 18, offset: 3 }" :xl="{ span: 16, offset: 4 }" :xxl="{ span: 16, offset: 4 }"> :lg="{ span: 18, offset: 3 }" :xl="{ span: 16, offset: 4 }" :xxl="{ span: 16, offset: 4 }">
<Card :padding="0"> <Card :padding="0">
<Form :model="noteForm" :label-width="80"> <Form :model="noteForm" :label-width="80">
<div ref="html2canvas" id="wrapper" style="border-left: 2px solid #ed4014;"> <div ref="html2canvas" id="wrapper" style="border-left: 2px solid #ed4014;">
<Input element-id="noteText" type="textarea" :border="false" v-model="noteForm.text" autofocus <Input element-id="noteText" type="textarea" :border="false" v-model="noteForm.text" autofocus
:autosize="{ minRows: 30, maxRows: 409600 }" :placeholder="$t('content.noteTip')" @input="recordText" :autosize="{ minRows: 30, maxRows: 409600 }" :placeholder="$t('content.noteTip')" @input="recordText"
@on-keydown="recordEventKdown" /> @on-keydown="recordEventKdown" />
@@ -192,7 +191,7 @@ import { unwrap } from '../libs/secret'
import { saveNote } from "@/api/note"; import { saveNote } from "@/api/note";
import { getStoreKey } from "@/api/lock"; import { getStoreKey } from "@/api/lock";
import storage from "@/libs/storage"; import storage from "@/libs/storage";
import { setStoreText,setNewStoreText } from "@/libs/noteStorage"; import { setStoreText, setNewStoreText } from "@/libs/noteStorage";
import { saveAs } from 'file-saver'; import { saveAs } from 'file-saver';
import { isWeixin } from "@/libs/utils"; import { isWeixin } from "@/libs/utils";
import NoteConstant from "@/libs/constants"; import NoteConstant from "@/libs/constants";
@@ -231,12 +230,15 @@ export default {
toTopState: false, toTopState: false,
showMenuState: false, showMenuState: false,
showHeaderShade: false, showHeaderShade: false,
pageSession: '',
errorInfo: '', errorInfo: '',
lastEditTime: 0,
backStoreTextInterval: null,
lastStoreCount: 0,
lastStoreTime: 0,
} }
}, },
created() { created() {
this.pageSession = new Date().getTime(); this.editTime = new Date().getTime();
// read $route // read $route
this.noteForm.key = this.$route.params.name; this.noteForm.key = this.$route.params.name;
@@ -272,7 +274,7 @@ export default {
// } // }
storage.local.setText(storeKey, "0|" + this.secret.cipher + "|0|" + this.state.initTime + "|"); storage.local.setText(storeKey, "0|" + this.secret.cipher + "|0|" + this.state.initTime + "|");
storage.session.delete(keyMeta.key+".keyMeta"); storage.session.delete(keyMeta.key + ".keyMeta");
} else { } else {
// second edit // second edit
let noteMeta = this.$route.meta.noteMeta; let noteMeta = this.$route.meta.noteMeta;
@@ -290,6 +292,10 @@ export default {
} }
} }
this.lastStoreCount = this.noteForm.text.length;
this.lastEditTime = new Date().getTime();
this.lastStoreTime = this.lastEditTime;
this.bindCtrlAllEvent(); this.bindCtrlAllEvent();
this.bindToTopEvent(); this.bindToTopEvent();
@@ -310,12 +316,15 @@ export default {
const someOtherEl = document.querySelector('#wrapper'); const someOtherEl = document.querySelector('#wrapper');
myObserver.observe(someOtherEl); myObserver.observe(someOtherEl);
window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
}, },
updated() { updated() {
}, },
beforeDestroy() { beforeDestroy() {
}, },
destroyed() { destroyed() {
window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
}, },
computed: {}, computed: {},
watch: {}, watch: {},
@@ -352,7 +361,49 @@ export default {
return; return;
} }
setStoreText(this.noteForm, this.state, this.secret); let nowEditCount = this.noteForm.text.length;
let nowEditTime = new Date().getTime();
if (nowEditCount < 1024) {
setStoreText(this.noteForm, this.state, this.secret);
this.lastStoreTime = nowEditTime;
this.lastStoreCount = nowEditCount;
} else {
if (null == this.backStoreTextInterval) {
this.backStoreTextInterval = window.setInterval(this.backStoreFunction(), 500);
}
}
this.lastEditTime = nowEditTime;
},
backStoreFunction() {
let that = this;
return function () {
that.backStoreText(that);
}
},
backStoreText(that) {
let nowEditCount = that.noteForm.text.length;
let nowEditTime = new Date().getTime();
if (Math.abs(nowEditCount - that.lastStoreCount) > 10) {
setStoreText(that.noteForm, that.state, that.secret);
that.lastStoreTime = that.lastEditTime;
that.lastStoreCount = nowEditCount;
} else {
if (nowEditTime - that.lastEditTime >= 1000 && nowEditTime - that.lastEditTime < 20000) {
if (that.lastEditTime != that.lastStoreTime) {
setStoreText(that.noteForm, that.state, that.secret);
that.lastStoreTime = that.lastEditTime;
that.lastStoreCount = nowEditCount;
}
} else if (nowEditTime - that.lastEditTime >= 20000) {
if (that.backStoreTextInterval != null) {
let ivl = that.backStoreTextInterval;
that.backStoreTextInterval = null;
window.clearInterval(ivl);
}
}
}
}, },
// recordEventKup(event) { // recordEventKup(event) {
// let tn = event.currentTarget.value; // let tn = event.currentTarget.value;
@@ -392,7 +443,7 @@ export default {
} }
this.noteForm.text = event.currentTarget.value; this.noteForm.text = event.currentTarget.value;
setStoreText(this.noteForm, this.state, this.secret); this.recordText();
} else if (event.ctrlKey && (event.which == 13)) { } else if (event.ctrlKey && (event.which == 13)) {
//save //save
@@ -446,9 +497,9 @@ export default {
alert(res.data.code); alert(res.data.code);
this.model.submitting = false; this.model.submitting = false;
this.state.locking = 0; this.state.locking = 0;
if(res.data.code=="100013"||res.data.code=="800001"){ if (res.data.code == "100013" || res.data.code == "800001") {
let key = setNewStoreText(this.noteForm); let key = setNewStoreText(this.noteForm);
location.href="/"+key; location.href = "/" + key;
} }
} }
@@ -511,24 +562,24 @@ export default {
let that = this; let that = this;
let a = document.createElement('a'); let a = document.createElement('a');
html2canvas(canvasID,{ html2canvas(canvasID, {
scale: 1, scale: 1,
windowWidth: parseInt(document.getElementById("noteText").offsetWidth)+2, windowWidth: parseInt(document.getElementById("noteText").offsetWidth) + 2,
onclone: (clonedDocument) => { onclone: (clonedDocument) => {
let nt = clonedDocument.getElementById("noteText"); let nt = clonedDocument.getElementById("noteText");
const div = clonedDocument.createElement('div') const div = clonedDocument.createElement('div')
div.innerText = nt.value div.innerText = nt.value
div.style.color="black"; div.style.color = "black";
div.style.padding = "10px"; div.style.padding = "10px";
div.style.textAlign = "left"; div.style.textAlign = "left";
div.style.wordBreak = "break-word"; div.style.wordBreak = "break-word";
div.style.whiteSpace = "pre-wrap"; div.style.whiteSpace = "pre-wrap";
div.style.verticalAlign = "top"; div.style.verticalAlign = "top";
div.style.fontSize ="15px"; div.style.fontSize = "15px";
div.style.width= "100%"; div.style.width = "100%";
div.style.border="0px"; div.style.border = "0px";
div.style.fontFamily="'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif"; div.style.fontFamily = "'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif";
nt.style.display = 'none' nt.style.display = 'none'
@@ -550,6 +601,9 @@ export default {
document.body.removeChild(a); document.body.removeChild(a);
}); });
}, },
beforeunloadHandler() {
this.recordText();
},
} }
} }
</script> </script>

View File

@@ -8,7 +8,7 @@ module.exports = defineConfig({
productionSourceMap: false, productionSourceMap: false,
configureWebpack: (config) => { configureWebpack: (config) => {
config.experiments = { asyncWebAssembly: true,syncWebAssembly:true } config.experiments = { asyncWebAssembly: true, syncWebAssembly: true }
config.externals = { config.externals = {
@@ -24,8 +24,8 @@ module.exports = defineConfig({
"file-saver": 'saveAs', "file-saver": 'saveAs',
"clipboard": "ClipboardJS", "clipboard": "ClipboardJS",
"vue-i18n": "VueI18n", "vue-i18n": "VueI18n",
"html2canvas":"html2canvas", "html2canvas": "html2canvas",
"wasm_flate":"wasm_flate" "wasm_flate": "wasm_flate"
}; };
// 为生产环境修改配置 // 为生产环境修改配置
@@ -68,7 +68,7 @@ module.exports = defineConfig({
proxy: { proxy: {
"/note": { "/note": {
target: "https://flagnote.com/", // 后台接口域名 target: "https://flagnote.com/", // 后台接口域名
// target: "http://localhost:10000/", // 后台接口域名 // target: "http://localhost:10000/", // 后台接口域名
secure: false, // 如果是https接口需要配置这个参数 secure: false, // 如果是https接口需要配置这个参数
changeOrigin: true, //是否跨域 changeOrigin: true, //是否跨域
pathRewrite: { pathRewrite: {