提交 e985e081 编写于 作者: B baiy 提交者: ninecents

保存历史数据防抖处理 防止历史记录爆炸

上级 a1cd854e
......@@ -3,6 +3,7 @@ import clipboard from './clipboard'
import setting from './setting'
import cache from './cache'
import history from './history.js'
import _ from "lodash";
let fixeInputData;
let toolCurrentFeature = "";
......@@ -44,6 +45,12 @@ const model = {
}
}
// 保存历史记录防抖
let debounceSaveToolData = {};
const debounceSaveToolDataMethod = _.debounce(function () {
return history(model.getCurrentTool()).push(debounceSaveToolData)
}, 3000)
export const plugin = {
install: function (Vue) {
Vue.prototype.$getToolData = function (clipboardField = '') {
......@@ -65,17 +72,18 @@ export const plugin = {
return data
}
Vue.prototype.$saveToolData = function (data) {
return history(model.getCurrentTool()).push(data)
debounceSaveToolData = _.cloneDeep(data)
debounceSaveToolDataMethod()
}
Vue.prototype.$clipboardCopy = function (data, force = false) {
if ((setting.autoSaveCopy() || force) && data){
if ((setting.autoSaveCopy() || force) && data) {
clipboard.copy(data, () => {
this.$Message.success('结果已复制 ^o^')
})
}
}
Vue.prototype.$clipboardCopyImages = function (data, force = false) {
if ((setting.autoSaveCopy() || force) && data){
if ((setting.autoSaveCopy() || force) && data) {
clipboard.copyImage(data, () => {
this.$Message.success('图片已复制 ^o^')
})
......
......@@ -143,7 +143,6 @@
* 不支持中文
*/
import JsBarcode from 'jsbarcode'
import _ from "lodash";
export default {
created() {
......@@ -193,7 +192,7 @@ export default {
valid: (valid) => {
this.validStr = !valid ? `"${barcodeContent}" 无效的条码内容` : "";
if (!this.validStr && this.current.text) {
this.saveToolData()
this.$saveToolData(this.current)
}
}
})
......@@ -202,10 +201,7 @@ export default {
if (!this.validStr && this.current.text) {
this.$clipboardCopyImages(this.$refs.barcode.toDataURL("image/png"), true)
}
},
saveToolData:_.debounce(function(){
this.$saveToolData(this.current)
}, 3000)
}
},
data() {
return {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册