hookehuyr

✨ feat(电子签名): 动态计算电子签名画板宽高

1 <!-- 1 <!--
2 * @Date: 2022-09-06 16:29:31 2 * @Date: 2022-09-06 16:29:31
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-09-07 16:50:16 4 + * @LastEditTime: 2023-02-09 13:01:54
5 * @FilePath: /data-table/src/components/SignField/index.vue 5 * @FilePath: /data-table/src/components/SignField/index.vue
6 * @Description: 电子签名控件 6 * @Description: 电子签名控件
7 --> 7 -->
8 <template> 8 <template>
9 <div v-if="HideShow" class="sign-page"> 9 <div v-if="HideShow" class="sign-page">
10 <div class="label"> 10 <div class="label">
11 - {{ item.component_props.label }}{{ valid 11 + {{ item.component_props.label }}{{
12 + valid
12 }}<span v-if="item.component_props.required">&nbsp;*</span> 13 }}<span v-if="item.component_props.required">&nbsp;*</span>
13 </div> 14 </div>
14 - <div style="padding: 1rem; position: relative"> 15 + <div ref="wrapperRef" class="esign-wrapper">
15 <!-- <div style="padding: 1rem; position: relative; height: 150px; background-color: #FCFCFC;border: 1px solid #EAEAEA; border-radius: 5px;"> --> 16 <!-- <div style="padding: 1rem; position: relative; height: 150px; background-color: #FCFCFC;border: 1px solid #EAEAEA; border-radius: 5px;"> -->
16 - <vue-esign 17 + <vue-esign v-if="esignWidth" ref="esign" class="sign-wrapper" :width="esignWidth" :height="esignHeight" :isCrop="isCrop"
17 - ref="esign" 18 + :lineWidth="lineWidth" :lineColor="lineColor" :bgColor.sync="bgColor" />
18 - class="sign-wrapper"
19 - style=""
20 - :isCrop="isCrop"
21 - :lineWidth="lineWidth"
22 - :lineColor="lineColor"
23 - :bgColor.sync="bgColor"
24 - />
25 <div v-if="show_sign" class="whiteboard"> 19 <div v-if="show_sign" class="whiteboard">
26 <div class="text" @click="startSign"> 20 <div class="text" @click="startSign">
27 <van-icon name="edit" />&nbsp;点击开始签署电子签名 21 <van-icon name="edit" />&nbsp;点击开始签署电子签名
...@@ -43,11 +37,7 @@ ...@@ -43,11 +37,7 @@
43 <van-button type="danger" block @click="handleReset">删除签名</van-button> 37 <van-button type="danger" block @click="handleReset">删除签名</van-button>
44 </div> 38 </div>
45 </div> 39 </div>
46 - <div 40 + <div v-if="show_empty" class="van-field__error-message" style="padding: 0 1rem 1rem 1rem">
47 - v-if="show_empty"
48 - class="van-field__error-message"
49 - style="padding: 0 1rem 1rem 1rem"
50 - >
51 电子签名不能为空 41 电子签名不能为空
52 </div> 42 </div>
53 <van-divider /> 43 <van-divider />
...@@ -80,6 +70,16 @@ const emit = defineEmits(["active"]); ...@@ -80,6 +70,16 @@ const emit = defineEmits(["active"]);
80 70
81 const esign = ref(null); 71 const esign = ref(null);
82 72
73 +let esignWidth = ref();
74 +let esignHeight = ref();
75 +const wrapperRef = ref(null)
76 +onMounted(() => {
77 + // 动态计算画板canvas宽度/高度
78 + setTimeout(() => {
79 + esignWidth.value = wrapperRef.value.offsetWidth - 32;
80 + esignHeight.value = (document.body.offsetHeight) / 5;
81 + }, 100);
82 +})
83 const lineWidth = ref(6); 83 const lineWidth = ref(6);
84 const lineColor = ref("#000000"); 84 const lineColor = ref("#000000");
85 const bgColor = ref("#FCFCFC"); 85 const bgColor = ref("#FCFCFC");
...@@ -240,6 +240,7 @@ export default { ...@@ -240,6 +240,7 @@ export default {
240 240
241 <style lang="less" scoped> 241 <style lang="less" scoped>
242 .sign-page { 242 .sign-page {
243 +
243 // padding-bottom: 1rem; 244 // padding-bottom: 1rem;
244 .label { 245 .label {
245 padding: 1rem 1rem 0 1rem; 246 padding: 1rem 1rem 0 1rem;
...@@ -250,25 +251,35 @@ export default { ...@@ -250,25 +251,35 @@ export default {
250 color: red; 251 color: red;
251 } 252 }
252 } 253 }
253 - .sign-wrapper { 254 +
254 - border: 1px solid #eaeaea; 255 + .esign-wrapper {
255 - border-radius: 5px; 256 + padding: 1rem;
256 - } 257 + position: relative;
257 - .whiteboard { 258 + box-sizing: border-box;
258 - position: absolute; 259 +
259 - height: 100%; 260 + .sign-wrapper {
260 - width: 100%; 261 + border: 1px solid #eaeaea;
261 - left: 50%; 262 + border-radius: 5px;
262 - top: 50%; 263 + }
263 - transform: translate(-50%, -50%); 264 +
264 - text-align: center; 265 + .whiteboard {
265 - .text {
266 position: absolute; 266 position: absolute;
267 + height: 100%;
267 width: 100%; 268 width: 100%;
268 - top: 50%;
269 left: 50%; 269 left: 50%;
270 + top: 50%;
270 transform: translate(-50%, -50%); 271 transform: translate(-50%, -50%);
272 + text-align: center;
273 +
274 + .text {
275 + position: absolute;
276 + width: 100%;
277 + top: 50%;
278 + left: 50%;
279 + transform: translate(-50%, -50%);
280 + }
271 } 281 }
282 +
272 } 283 }
273 284
274 .control-sign { 285 .control-sign {
......