index.vue
3.36 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!--
* @Date: 2022-08-29 14:31:20
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-08-01 13:17:05
* @FilePath: /data-table/src/components/TableField/index.vue
* @Description: 文件描述
-->
<template>
<div v-if="HideShow" class="table-field-page">
<div class="label">
<span v-if="item.component_props.required" style="color: red"> *</span>
<span :class="[ReadonlyShow ? 'readonly-show' : '']">{{ item.component_props.label }}</span>
</div>
<div class="tinymce-box">
<TEditor ref="refEdit" ></TEditor>
<div @click="getValue">获取内容</div>
<div @click="setValue">设置内容</div>
</div>
<div>
<div v-html="table_html" class="table-wrapper"></div>
<div @click="setHtml">设置内容</div>
</div>
</div>
</template>
<script setup>
import { useRoute } from "vue-router";
import { showSuccessToast, showFailToast } from 'vant';
// 初始化WX环境
import wx from 'weixin-js-sdk'
import TEditor from "@/components/TEditor/index.vue";
const $route = useRoute();
const props = defineProps({
item: Object,
});
// 隐藏显示
const HideShow = computed(() => {
return !props.item.component_props.disabled
});
// 只读显示-流程模式
const ReadonlyShow = computed(() => {
return $route.query.page_type === 'flow' && !props.item.component_props.readonly;
});
onMounted(() => {
props.item.value = props.item.component_props.default;
});
const refEdit = ref(null);
// refEdit.value.handleGetContent()
const getValue = () => {
console.warn(refEdit.value.handleGetContent());
}
const setValue = () => {
refEdit.value.handleSetContent(table)
}
const table_html = ref('');
const setHtml = () => {
table_html.value = table
}
const table = `
<table>
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
<th>城市</th>
<th>姓名</th>
<th>年龄</th>
<th>城市</th>
<th>姓名</th>
<th>年龄</th>
<th>城市</th>
<th>姓名</th>
<th>年龄</th>
<th>城市</th>
</tr>
</thead>
<tbody>
<tr>
<td>张三</td>
<td>28</td>
<td>北京</td>
<td>张三</td>
<td>28</td>
<td>北京</td>
<td>张三</td>
<td>28</td>
<td>北京</td>
<td>张三</td>
<td>28</td>
<td>北京</td>
</tr>
<tr>
<td>李四</td>
<td>34</td>
<td>上海</td>
<td>李四</td>
<td>34</td>
<td>上海</td>
<td>李四</td>
<td>34</td>
<td>上海</td>
<td>李四</td>
<td>34</td>
<td>上海</td>
</tr>
<tr>
<td>王五</td>
<td>22</td>
<td>广州</td>
<td>王五</td>
<td>22</td>
<td>广州</td>
<td>王五</td>
<td>22</td>
<td>广州</td>
<td>王五</td>
<td>22</td>
<td>广州</td>
</tr>
</tbody>
</table>
`
</script>
<style lang="less" scoped>
.table-field-page {
.label {
padding: 1rem 1rem 0 1rem;
font-size: 0.9rem;
font-weight: bold;
}
}
.tinymce-box {
// width: 100%;
}
:deep(.table-wrapper) {
overflow: auto;
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f4f4f4;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
tr:hover {
background-color: #f1f1f1;
}
}
</style>