index.vue
4.85 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!--
* @Date: 2022-08-29 14:31:20
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-08-01 17:08:10
* @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" @blur="onBlur" :table_html="table_html" :readonly="item.component_props.readonly"></TEditor>
</div>
<!-- <div @click="getValue">获取内容</div>
<div @click="setValue">设置内容</div> -->
<!-- <div>
<div v-html="table_html" class="table-wrapper"></div>
<div @click="setHtml">设置内容</div>
</div> -->
<div
v-if="show_empty"
class="van-field__error-message"
style="padding: 1rem"
>
表格不能为空
</div>
</div>
</template>
<script setup>
import { useRoute } from "vue-router";
import { showSuccessToast, showFailToast, showToast } from 'vant';
// 初始化WX环境
import wx from 'weixin-js-sdk'
import $ from 'jquery'
import TEditor from "@/components/TEditor/index.vue";
const $route = useRoute();
const props = defineProps({
item: Object,
});
const emit = defineEmits(["active"]);
// 隐藏显示
const HideShow = computed(() => {
return !props.item.component_props.disabled
});
// 只读显示-流程模式
const ReadonlyShow = computed(() => {
return $route.query.page_type === 'flow' && !props.item.component_props.readonly;
});
onMounted(() => {
$('.tinymce-box').width($('.table-field-page').width() + 'px');
//
table_html.value = props.item.component_props.default;
//
props.item.value = {
key: "table_editor",
filed_name: props.item.key,
value: props.item.component_props.default,
};
emit("active", props.item.value);
// setTimeout(() => {
// }, 1000);
// nextTick(() => {
// if (refEdit.value) {
// refEdit.value.handleSetContent(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 onBlur = (html) => {
props.item.value = {
key: "table",
filed_name: props.item.key,
value: html,
};
emit("active", props.item.value);
table_html.value = html;
}
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>
`
const show_empty = ref(false);
// 校验模块
const validTableEditor = () => {
if (props.item.component_props.disabled) { // 通过规则隐藏的属性,不校验
show_empty.value = false;
} else {
// 必填项 未上传文件
if (props.item.component_props.required && !refEdit.value.handleGetContent()) {
show_empty.value = true;
showToast(props.item.component_props.label + "必填项未填写");
} else {
show_empty.value = false;
}
}
return !show_empty.value;
};
defineExpose({ validTableEditor });
</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%;
display: block;
margin-top: 1rem;
}
: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>