1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import beautifier from "../utils/json-beautifier"
export default {
data() {
return {
historySteps: {
index: 0,
maxStep: 20,
steps: [],
storage: false,
},
}
},
watch: {
historySteps: {
handler(val) {
if (val.storage)
localStorage.setItem("avue-form-history", beautifier(val))
else localStorage.removeItem("avue-form-history")
},
deep: true,
},
},
methods: {
initHistory(data) {
if (data.storage) {
const history = localStorage.getItem("avue-form-history")
if (history) {
this.historySteps = eval("(" + history + ")")
const { index, steps } = this.historySteps
return this.deepClone(steps[index])
}
}
this.historySteps = {
...this.historySteps,
...data,
}
const { index, steps } = this.historySteps
return this.deepClone(steps[index])
},
handleHistoryChange(data) {
if (this.historySteps.index == this.historySteps.maxStep - 1)
this.historySteps.steps.shift()
else this.historySteps.index++
this.historySteps.steps[this.historySteps.index] = this.deepClone(data)
if (this.historySteps.index < this.historySteps.steps.length - 1) {
this.historySteps.steps = this.historySteps.steps.slice(
0,
this.historySteps.index + 1
)
}
this.$emit("filterField") //过滤字段
},
handleUndo() {
if (this.historySteps.index != 0) this.historySteps.index--
return this.deepClone(this.historySteps.steps[this.historySteps.index])
},
handleRedo() {
if (this.historySteps.index != this.historySteps.steps.length - 1)
this.historySteps.index++
return this.deepClone(this.historySteps.steps[this.historySteps.index])
},
},
}