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
66
67
68
69
70
71
72
73
<template>
<c-rich-text-editor
v-model="value"
v-bind="$attrs"
@blur="blurEvent"
></c-rich-text-editor>
</template>
<script>
// 保函文本
export default {
name: "XmlFormatEditor",
props: ["model"],
data() {
return {
value: "",
isXml: false,
};
},
watch: {
model() {
let rows = this.model["rows"] || [];
this.value = this.show(rows);
},
},
methods: {
blurEvent(quill) {
if (this.model && this.model.rows) {
// const v = this.format(this.value);
const v = this.format(quill.getText());
this.model["rows"].length = 0;
this.model["rows"].unshift(v);
// this.$emit("change", v);
if (quill.isEnabled()) {
quill.disable();
this.$emit("blur", v, () => {
quill.blur();
setTimeout(() => {
quill.enable();
}, 0);
});
}
}
},
show: function (rows) {
let strs = rows.length > 0 ? rows[0] : "";
if (strs.startsWith("<?xml")) {
this.isXml = true;
var pattern = /<tdfmt\s[^>]*>([\s\S]*)<\/tdfmt>/;
var temp = pattern.exec(strs);
if (temp != null) {
strs = temp[1];
}
}
// return strs.replace(/<br\/>/g, "\n");
return strs;
},
format: function (value) {
if (this.isXml) {
var len = value.length;
value = value.replace(/\n/g, "<br/>");
var head = "<?xml version='1.0'?><tdfmt sel-start='" + len + "'>";
var tail = "</tdfmt>";
return head + value + tail;
}
return value;
},
},
};
</script>
<style>
</style>