Showing
4 changed files
with
299 additions
and
281 deletions
| ... | @@ -19,7 +19,7 @@ declare module '@vue/runtime-core' { | ... | @@ -19,7 +19,7 @@ declare module '@vue/runtime-core' { |
| 19 | CalendarField: typeof import('./src/components/CalendarField/index.vue')['default'] | 19 | CalendarField: typeof import('./src/components/CalendarField/index.vue')['default'] |
| 20 | CheckboxField: typeof import('./src/components/CheckboxField/index.vue')['default'] | 20 | CheckboxField: typeof import('./src/components/CheckboxField/index.vue')['default'] |
| 21 | ContactField: typeof import('./src/components/ContactField/index.vue')['default'] | 21 | ContactField: typeof import('./src/components/ContactField/index.vue')['default'] |
| 22 | - copy: typeof import('./src/components/DesField copy/index.vue')['default'] | 22 | + copy: typeof import('./src/components/SignField copy/index.vue')['default'] |
| 23 | CustomField: typeof import('./src/components/CustomField/index.vue')['default'] | 23 | CustomField: typeof import('./src/components/CustomField/index.vue')['default'] |
| 24 | DatePickerField: typeof import('./src/components/DatePickerField/index.vue')['default'] | 24 | DatePickerField: typeof import('./src/components/DatePickerField/index.vue')['default'] |
| 25 | DateTimePickerField: typeof import('./src/components/DateTimePickerField/index.vue')['default'] | 25 | DateTimePickerField: typeof import('./src/components/DateTimePickerField/index.vue')['default'] |
| ... | @@ -32,7 +32,8 @@ declare module '@vue/runtime-core' { | ... | @@ -32,7 +32,8 @@ declare module '@vue/runtime-core' { |
| 32 | ImageUploaderField: typeof import('./src/components/ImageUploaderField/index.vue')['default'] | 32 | ImageUploaderField: typeof import('./src/components/ImageUploaderField/index.vue')['default'] |
| 33 | MarqueeField: typeof import('./src/components/MarqueeField/index.vue')['default'] | 33 | MarqueeField: typeof import('./src/components/MarqueeField/index.vue')['default'] |
| 34 | MultiRuleField: typeof import('./src/components/MultiRuleField/index.vue')['default'] | 34 | MultiRuleField: typeof import('./src/components/MultiRuleField/index.vue')['default'] |
| 35 | - MyComponent: typeof import('./src/components/CustomField/MyComponent.vue')['default'] | 35 | + MyComponent: typeof import('./src/components/AppointmentField/MyComponent.vue')['default'] |
| 36 | + MyComponet: typeof import('./src/components/SignField/MyComponet.vue')['default'] | ||
| 36 | NameField: typeof import('./src/components/NameField/index.vue')['default'] | 37 | NameField: typeof import('./src/components/NameField/index.vue')['default'] |
| 37 | NoteField: typeof import('./src/components/NoteField/index.vue')['default'] | 38 | NoteField: typeof import('./src/components/NoteField/index.vue')['default'] |
| 38 | NumberField: typeof import('./src/components/NumberField/index.vue')['default'] | 39 | NumberField: typeof import('./src/components/NumberField/index.vue')['default'] |
| ... | @@ -44,6 +45,7 @@ declare module '@vue/runtime-core' { | ... | @@ -44,6 +45,7 @@ declare module '@vue/runtime-core' { |
| 44 | RouterView: typeof import('vue-router')['RouterView'] | 45 | RouterView: typeof import('vue-router')['RouterView'] |
| 45 | RuleField: typeof import('./src/components/RuleField/index.vue')['default'] | 46 | RuleField: typeof import('./src/components/RuleField/index.vue')['default'] |
| 46 | SignField: typeof import('./src/components/SignField/index.vue')['default'] | 47 | SignField: typeof import('./src/components/SignField/index.vue')['default'] |
| 48 | + 'SignField copy': typeof import('./src/components/SignField copy/index.vue')['default'] | ||
| 47 | TableField: typeof import('./src/components/TableField/index.vue')['default'] | 49 | TableField: typeof import('./src/components/TableField/index.vue')['default'] |
| 48 | Test: typeof import('./src/components/VideoField/test.vue')['default'] | 50 | Test: typeof import('./src/components/VideoField/test.vue')['default'] |
| 49 | TextareaField: typeof import('./src/components/TextareaField/index.vue')['default'] | 51 | TextareaField: typeof import('./src/components/TextareaField/index.vue')['default'] | ... | ... |
src/components/SignField/MyComponent.vue
0 → 100644
| 1 | +<!-- | ||
| 2 | + * @Date: 2023-03-29 17:44:24 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2023-03-30 11:04:24 | ||
| 5 | + * @FilePath: /data-table/src/components/SignField/MyComponent.vue | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | +--> | ||
| 8 | +<template> | ||
| 9 | + <div style="width: 100%;"> | ||
| 10 | + <div ref="wrapperRef" class="esign-wrapper"> | ||
| 11 | + <vue-esign v-if="esignWidth" ref="esign" class="sign-wrapper" :width="esignWidth" :height="esignHeight" :isCrop="isCrop" | ||
| 12 | + :lineWidth="lineWidth" :lineColor="lineColor" :bgColor.sync="bgColor" /> | ||
| 13 | + <div v-if="show_sign" class="whiteboard"> | ||
| 14 | + <div class="text" @click="startSign"> | ||
| 15 | + <van-icon name="edit" /> 点击开始签署电子签名 | ||
| 16 | + </div> | ||
| 17 | + </div> | ||
| 18 | + </div> | ||
| 19 | + <div v-if="!show_sign"> | ||
| 20 | + <div v-if="show_control" class="control-sign"> | ||
| 21 | + <van-row gutter="20" style="padding: 0 1rem"> | ||
| 22 | + <van-col :span="12"> | ||
| 23 | + <van-button type="default" block @click="handleGenerate">确认签名</van-button> | ||
| 24 | + </van-col> | ||
| 25 | + <van-col :span="12"> | ||
| 26 | + <van-button type="default" block @click="cancelSign">取消签名</van-button> | ||
| 27 | + </van-col> | ||
| 28 | + </van-row> | ||
| 29 | + </div> | ||
| 30 | + <div v-else style="padding: 0 1rem"> | ||
| 31 | + <van-button type="danger" block @click="handleReset">删除签名</van-button> | ||
| 32 | + </div> | ||
| 33 | + </div> | ||
| 34 | + <van-divider /> | ||
| 35 | + </div> | ||
| 36 | + <van-overlay :show="loading"> | ||
| 37 | + <div class="wrapper" @click.stop> | ||
| 38 | + <van-loading vertical color="#FFFFFF">生成中...</van-loading> | ||
| 39 | + </div> | ||
| 40 | + </van-overlay> | ||
| 41 | +</template> | ||
| 42 | + | ||
| 43 | +<script setup> | ||
| 44 | +import { inject, ref } from 'vue' | ||
| 45 | +import { useCustomFieldValue } from '@vant/use'; | ||
| 46 | +import { v4 as uuidv4 } from "uuid"; | ||
| 47 | +import { qiniuTokenAPI, qiniuUploadAPI, saveFileAPI } from "@/api/common"; | ||
| 48 | +import { showSuccessToast, showFailToast } from "vant"; | ||
| 49 | +import { useRoute } from "vue-router"; | ||
| 50 | +import BMF from "browser-md5-file"; | ||
| 51 | +import { getEtag } from "@/utils/qetag.js"; // 生成hash值 | ||
| 52 | +import dayjs from "dayjs"; | ||
| 53 | + | ||
| 54 | +// 获取父组件传值 | ||
| 55 | +const props = inject('props'); | ||
| 56 | +const $route = useRoute(); | ||
| 57 | +const esign = ref(null); | ||
| 58 | + | ||
| 59 | +let esignWidth = ref(); | ||
| 60 | +let esignHeight = ref(); | ||
| 61 | +const wrapperRef = ref(null) | ||
| 62 | +onMounted(() => { | ||
| 63 | + // 动态计算画板canvas宽度/高度 | ||
| 64 | + setTimeout(() => { | ||
| 65 | + esignWidth.value = wrapperRef.value.offsetWidth - 32; | ||
| 66 | + esignHeight.value = (window.innerHeight) / 5; | ||
| 67 | + }, 100); | ||
| 68 | +}) | ||
| 69 | +const lineWidth = ref(6); | ||
| 70 | +const lineColor = ref("#000000"); | ||
| 71 | +const bgColor = ref("#FCFCFC"); | ||
| 72 | +const isCrop = ref(false); | ||
| 73 | +const show_control = ref(true); | ||
| 74 | +const image_url = ref(""); | ||
| 75 | +const show_empty = ref(false); | ||
| 76 | +const sign_value = computed(() => { | ||
| 77 | + return { name: `电子签名${dayjs().format('YYYYMMDDHHmmss')}.png`, url: image_url.value } | ||
| 78 | +}) | ||
| 79 | + | ||
| 80 | +const handleReset = () => { | ||
| 81 | + // 清空画板 | ||
| 82 | + esign.value.reset(); | ||
| 83 | + show_control.value = true; | ||
| 84 | + // 删除可能存在的签名 | ||
| 85 | + image_url.value = ""; | ||
| 86 | +}; | ||
| 87 | + | ||
| 88 | +/********** 上传七牛云获取图片地址 ***********/ | ||
| 89 | +const loading = ref(false); | ||
| 90 | +const formCode = $route.query.code; // 表单code | ||
| 91 | +const uuid = () => { | ||
| 92 | + let s = []; | ||
| 93 | + let hexDigits = "0123456789abcdef"; | ||
| 94 | + for (var i = 0; i < 36; i++) { | ||
| 95 | + s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); | ||
| 96 | + } | ||
| 97 | + s[14] = "4"; | ||
| 98 | + s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); | ||
| 99 | + s[8] = s[13] = s[18] = s[23] = "-"; | ||
| 100 | + | ||
| 101 | + var uuid = s.join(""); | ||
| 102 | + return uuid; | ||
| 103 | +}; | ||
| 104 | + | ||
| 105 | +const uploadQiniu = async (file, token, filename) => { | ||
| 106 | + let formData = new FormData(); | ||
| 107 | + formData.append("file", file); // 通过append向form对象添加数据 | ||
| 108 | + formData.append("token", token); | ||
| 109 | + formData.append("key", filename); | ||
| 110 | + let config = { | ||
| 111 | + headers: { "Content-Type": "multipart/form-data" }, | ||
| 112 | + }; | ||
| 113 | + // 自拍图片上传七牛服务器 | ||
| 114 | + let qiniuUploadUrl; | ||
| 115 | + if (window.location.protocol === 'https:') { | ||
| 116 | + qiniuUploadUrl = 'https://up.qbox.me'; | ||
| 117 | + } else { | ||
| 118 | + qiniuUploadUrl = 'http://upload.qiniu.com'; | ||
| 119 | + } | ||
| 120 | + const { filekey, hash, image_info } = await qiniuUploadAPI( | ||
| 121 | + qiniuUploadUrl, | ||
| 122 | + formData, | ||
| 123 | + config | ||
| 124 | + ); | ||
| 125 | + if (filekey) { | ||
| 126 | + // 保存图片 | ||
| 127 | + const { data } = await saveFileAPI({ | ||
| 128 | + filekey, | ||
| 129 | + hash, | ||
| 130 | + format: image_info.format, | ||
| 131 | + height: image_info.height, | ||
| 132 | + width: image_info.width, | ||
| 133 | + }); | ||
| 134 | + return data; | ||
| 135 | + } | ||
| 136 | +}; | ||
| 137 | +/****************** END *******************/ | ||
| 138 | + | ||
| 139 | +const handleUpload = async (files, filename) => { | ||
| 140 | + // 上传图片流程 | ||
| 141 | + loading.value = true; | ||
| 142 | + // 获取HASH值 | ||
| 143 | + const hash = getEtag(files); | ||
| 144 | + // 获取七牛token | ||
| 145 | + const { token, key, code } = await qiniuTokenAPI({ | ||
| 146 | + name: filename, | ||
| 147 | + hash, | ||
| 148 | + }); | ||
| 149 | + // 文件上传七牛云 | ||
| 150 | + const imgUrl = await uploadQiniu(files, token, filename); | ||
| 151 | + return imgUrl; | ||
| 152 | +}; | ||
| 153 | + | ||
| 154 | +const handleGenerate = () => { | ||
| 155 | + esign.value | ||
| 156 | + .generate() | ||
| 157 | + .then(async (res) => { | ||
| 158 | + let affix = uuidv4(); | ||
| 159 | + let fileName = `uploadForm/${formCode}/${affix}_sign.png`; | ||
| 160 | + let file = dataURLtoFile(res, fileName); // 生成文件 | ||
| 161 | + const imgUrl = await handleUpload(file, fileName); | ||
| 162 | + loading.value = false; | ||
| 163 | + image_url.value = imgUrl.src; | ||
| 164 | + show_control.value = false; | ||
| 165 | + show_empty.value = false; | ||
| 166 | + }) | ||
| 167 | + .catch((err) => { | ||
| 168 | + loading.value = false; | ||
| 169 | + // 签名生成失败 | ||
| 170 | + console.warn(err); | ||
| 171 | + if (err) { | ||
| 172 | + showFailToast("签名生成失败"); | ||
| 173 | + } | ||
| 174 | + }); | ||
| 175 | +}; | ||
| 176 | + | ||
| 177 | +//将图片base64转换为文件 | ||
| 178 | +const dataURLtoFile = (dataurl, filename) => { | ||
| 179 | + var arr = dataurl.split(","), | ||
| 180 | + mime = arr[0].match(/:(.*?);/)[1], | ||
| 181 | + bstr = atob(arr[1]), | ||
| 182 | + n = bstr.length, | ||
| 183 | + u8arr = new Uint8Array(n); | ||
| 184 | + while (n--) { | ||
| 185 | + u8arr[n] = bstr.charCodeAt(n); | ||
| 186 | + } | ||
| 187 | + return new File([u8arr], filename, { type: mime }); | ||
| 188 | +}; | ||
| 189 | + | ||
| 190 | +const show_sign = ref(true); | ||
| 191 | +const startSign = () => { | ||
| 192 | + show_sign.value = false; | ||
| 193 | + show_empty.value = false; | ||
| 194 | +}; | ||
| 195 | +const cancelSign = () => { | ||
| 196 | + show_sign.value = true; | ||
| 197 | + show_empty.value = false; | ||
| 198 | + handleReset(); | ||
| 199 | +}; | ||
| 200 | + | ||
| 201 | +// 此处传入的值会替代 Field 组件内部的 value | ||
| 202 | +useCustomFieldValue(() => sign_value.value); | ||
| 203 | +</script> | ||
| 204 | + | ||
| 205 | +<style lang="less" scoped> | ||
| 206 | + | ||
| 207 | +.esign-wrapper { | ||
| 208 | + padding: 1rem; | ||
| 209 | + position: relative; | ||
| 210 | + box-sizing: border-box; | ||
| 211 | + | ||
| 212 | + .sign-wrapper { | ||
| 213 | + border: 1px solid #eaeaea; | ||
| 214 | + border-radius: 5px; | ||
| 215 | + background: #fcfcfc !important; | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + .whiteboard { | ||
| 219 | + position: absolute; | ||
| 220 | + height: 100%; | ||
| 221 | + width: 100%; | ||
| 222 | + left: 50%; | ||
| 223 | + top: 50%; | ||
| 224 | + transform: translate(-50%, -50%); | ||
| 225 | + text-align: center; | ||
| 226 | + | ||
| 227 | + .text { | ||
| 228 | + position: absolute; | ||
| 229 | + width: 100%; | ||
| 230 | + top: 50%; | ||
| 231 | + left: 50%; | ||
| 232 | + transform: translate(-50%, -50%); | ||
| 233 | + } | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | +} | ||
| 237 | + | ||
| 238 | +.control-sign { | ||
| 239 | + padding-bottom: 1rem; | ||
| 240 | +} | ||
| 241 | + | ||
| 242 | +.wrapper { | ||
| 243 | + display: flex; | ||
| 244 | + align-items: center; | ||
| 245 | + justify-content: center; | ||
| 246 | + height: 100%; | ||
| 247 | +} | ||
| 248 | + | ||
| 249 | +.block { | ||
| 250 | + width: 120px; | ||
| 251 | + height: 120px; | ||
| 252 | + background-color: #fff; | ||
| 253 | +} | ||
| 254 | +</style> |
| 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: 2023-02-10 15:31:06 | 4 | + * @LastEditTime: 2023-03-29 17:58:28 |
| 5 | * @FilePath: /data-table/src/components/SignField/index.vue | 5 | * @FilePath: /data-table/src/components/SignField/index.vue |
| 6 | * @Description: 电子签名控件 | 6 | * @Description: 电子签名控件 |
| 7 | --> | 7 | --> |
| ... | @@ -10,241 +10,46 @@ | ... | @@ -10,241 +10,46 @@ |
| 10 | <div class="label"> | 10 | <div class="label"> |
| 11 | <span v-if="item.component_props.required"> *</span> | 11 | <span v-if="item.component_props.required"> *</span> |
| 12 | {{ item.component_props.label }} | 12 | {{ item.component_props.label }} |
| 13 | - {{ valid }} | ||
| 14 | </div> | 13 | </div> |
| 15 | - <div ref="wrapperRef" class="esign-wrapper"> | 14 | + <van-field :name="item.key" :rules="rules" style="padding: 0;"> |
| 16 | - <!-- <div style="padding: 1rem; position: relative; height: 150px; background-color: #FCFCFC;border: 1px solid #EAEAEA; border-radius: 5px;"> --> | 15 | + <template #input> |
| 17 | - <vue-esign v-if="esignWidth" ref="esign" class="sign-wrapper" :width="esignWidth" :height="esignHeight" :isCrop="isCrop" | 16 | + <my-component /> |
| 18 | - :lineWidth="lineWidth" :lineColor="lineColor" :bgColor.sync="bgColor" /> | 17 | + </template> |
| 19 | - <div v-if="show_sign" class="whiteboard"> | 18 | + </van-field> |
| 20 | - <div class="text" @click="startSign"> | ||
| 21 | - <van-icon name="edit" /> 点击开始签署电子签名 | ||
| 22 | </div> | 19 | </div> |
| 23 | - </div> | ||
| 24 | - </div> | ||
| 25 | - <div v-if="!show_sign"> | ||
| 26 | - <div v-if="show_control" class="control-sign"> | ||
| 27 | - <van-row gutter="20" style="padding: 0 1rem"> | ||
| 28 | - <van-col :span="12"> | ||
| 29 | - <van-button type="default" block @click="handleGenerate">确认签名</van-button> | ||
| 30 | - </van-col> | ||
| 31 | - <van-col :span="12"> | ||
| 32 | - <van-button type="default" block @click="cancelSign">取消签名</van-button> | ||
| 33 | - </van-col> | ||
| 34 | - </van-row> | ||
| 35 | - </div> | ||
| 36 | - <div v-else style="padding: 0 1rem"> | ||
| 37 | - <van-button type="danger" block @click="handleReset">删除签名</van-button> | ||
| 38 | - </div> | ||
| 39 | - </div> | ||
| 40 | - <div v-if="show_empty" class="van-field__error-message" style="padding: 0 1rem 1rem 1rem"> | ||
| 41 | - 电子签名不能为空 | ||
| 42 | - </div> | ||
| 43 | - <van-divider /> | ||
| 44 | - </div> | ||
| 45 | - | ||
| 46 | - <van-overlay :show="loading"> | ||
| 47 | - <div class="wrapper" @click.stop> | ||
| 48 | - <van-loading vertical color="#FFFFFF">生成中...</van-loading> | ||
| 49 | - </div> | ||
| 50 | - </van-overlay> | ||
| 51 | </template> | 20 | </template> |
| 52 | 21 | ||
| 53 | <script setup> | 22 | <script setup> |
| 54 | -import { v4 as uuidv4 } from "uuid"; | 23 | +import MyComponent from './MyComponent.vue'; |
| 55 | -import { qiniuTokenAPI, qiniuUploadAPI, saveFileAPI } from "@/api/common"; | ||
| 56 | -import { showSuccessToast, showFailToast } from "vant"; | ||
| 57 | -import { useRoute } from "vue-router"; | ||
| 58 | -import BMF from "browser-md5-file"; | ||
| 59 | -import { getEtag } from "@/utils/qetag.js"; // 生成hash值 | ||
| 60 | -import dayjs from "dayjs"; | ||
| 61 | 24 | ||
| 62 | const props = defineProps({ | 25 | const props = defineProps({ |
| 63 | item: Object, | 26 | item: Object, |
| 64 | }); | 27 | }); |
| 28 | +// 注入子组件属性 | ||
| 29 | +provide('props', props.item); | ||
| 65 | // 隐藏显示 | 30 | // 隐藏显示 |
| 66 | const HideShow = computed(() => { | 31 | const HideShow = computed(() => { |
| 67 | return !props.item.component_props.disabled | 32 | return !props.item.component_props.disabled |
| 68 | }) | 33 | }) |
| 69 | -const $route = useRoute(); | ||
| 70 | -const emit = defineEmits(["active"]); | ||
| 71 | - | ||
| 72 | -const esign = ref(null); | ||
| 73 | - | ||
| 74 | -let esignWidth = ref(); | ||
| 75 | -let esignHeight = ref(); | ||
| 76 | -const wrapperRef = ref(null) | ||
| 77 | -onMounted(() => { | ||
| 78 | - // 动态计算画板canvas宽度/高度 | ||
| 79 | - setTimeout(() => { | ||
| 80 | - esignWidth.value = wrapperRef.value.offsetWidth - 32; | ||
| 81 | - esignHeight.value = (window.innerHeight) / 5; | ||
| 82 | - }, 100); | ||
| 83 | -}) | ||
| 84 | -const lineWidth = ref(6); | ||
| 85 | -const lineColor = ref("#000000"); | ||
| 86 | -const bgColor = ref("#FCFCFC"); | ||
| 87 | -const isCrop = ref(false); | ||
| 88 | -const show_control = ref(true); | ||
| 89 | -const image_url = ref(""); | ||
| 90 | -const show_empty = ref(false); | ||
| 91 | 34 | ||
| 92 | -const handleReset = () => { | 35 | +// 规则校验 |
| 93 | - // 清空画板 | 36 | +const required = props.item.component_props.required; |
| 94 | - esign.value.reset(); | 37 | +const validator = (val) => { |
| 95 | - show_control.value = true; | 38 | + if (required && !val.url) { |
| 96 | - // 删除可能存在的签名 | 39 | + return false; |
| 97 | - image_url.value = ""; | ||
| 98 | - props.item.value = { | ||
| 99 | - key: "sign", | ||
| 100 | - filed_name: props.item.key, | ||
| 101 | - value: "", | ||
| 102 | - }; | ||
| 103 | - emit("active", props.item.value); | ||
| 104 | -}; | ||
| 105 | - | ||
| 106 | -/********** 上传七牛云获取图片地址 ***********/ | ||
| 107 | -const loading = ref(false); | ||
| 108 | -const formCode = $route.query.code; // 表单code | ||
| 109 | -const uuid = () => { | ||
| 110 | - let s = []; | ||
| 111 | - let hexDigits = "0123456789abcdef"; | ||
| 112 | - for (var i = 0; i < 36; i++) { | ||
| 113 | - s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); | ||
| 114 | - } | ||
| 115 | - s[14] = "4"; | ||
| 116 | - s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); | ||
| 117 | - s[8] = s[13] = s[18] = s[23] = "-"; | ||
| 118 | - | ||
| 119 | - var uuid = s.join(""); | ||
| 120 | - return uuid; | ||
| 121 | -}; | ||
| 122 | - | ||
| 123 | -const uploadQiniu = async (file, token, filename) => { | ||
| 124 | - let formData = new FormData(); | ||
| 125 | - formData.append("file", file); // 通过append向form对象添加数据 | ||
| 126 | - formData.append("token", token); | ||
| 127 | - formData.append("key", filename); | ||
| 128 | - let config = { | ||
| 129 | - headers: { "Content-Type": "multipart/form-data" }, | ||
| 130 | - }; | ||
| 131 | - // 自拍图片上传七牛服务器 | ||
| 132 | - let qiniuUploadUrl; | ||
| 133 | - if (window.location.protocol === 'https:') { | ||
| 134 | - qiniuUploadUrl = 'https://up.qbox.me'; | ||
| 135 | } else { | 40 | } else { |
| 136 | - qiniuUploadUrl = 'http://upload.qiniu.com'; | 41 | + return true; |
| 137 | - } | ||
| 138 | - const { filekey, hash, image_info } = await qiniuUploadAPI( | ||
| 139 | - qiniuUploadUrl, | ||
| 140 | - formData, | ||
| 141 | - config | ||
| 142 | - ); | ||
| 143 | - if (filekey) { | ||
| 144 | - // 保存图片 | ||
| 145 | - const { data } = await saveFileAPI({ | ||
| 146 | - filekey, | ||
| 147 | - hash, | ||
| 148 | - format: image_info.format, | ||
| 149 | - height: image_info.height, | ||
| 150 | - width: image_info.width, | ||
| 151 | - }); | ||
| 152 | - return data; | ||
| 153 | - } | ||
| 154 | -}; | ||
| 155 | -/****************** END *******************/ | ||
| 156 | - | ||
| 157 | -const handleUpload = async (files, filename) => { | ||
| 158 | - // 上传图片流程 | ||
| 159 | - loading.value = true; | ||
| 160 | - // 获取HASH值 | ||
| 161 | - const hash = getEtag(files); | ||
| 162 | - // 获取七牛token | ||
| 163 | - const { token, key, code } = await qiniuTokenAPI({ | ||
| 164 | - name: filename, | ||
| 165 | - hash, | ||
| 166 | - }); | ||
| 167 | - // 文件上传七牛云 | ||
| 168 | - const imgUrl = await uploadQiniu(files, token, filename); | ||
| 169 | - return imgUrl; | ||
| 170 | -}; | ||
| 171 | - | ||
| 172 | -const handleGenerate = () => { | ||
| 173 | - esign.value | ||
| 174 | - .generate() | ||
| 175 | - .then(async (res) => { | ||
| 176 | - let affix = uuidv4(); | ||
| 177 | - let fileName = `uploadForm/${formCode}/${affix}_sign.png`; | ||
| 178 | - let file = dataURLtoFile(res, fileName); // 生成文件 | ||
| 179 | - const imgUrl = await handleUpload(file, fileName); | ||
| 180 | - loading.value = false; | ||
| 181 | - props.item.value = { | ||
| 182 | - key: "sign", | ||
| 183 | - filed_name: props.item.key, | ||
| 184 | - value: { name: `电子签名${dayjs().format('YYYYMMDDHHmmss')}.png`, url: imgUrl.src}, | ||
| 185 | - }; | ||
| 186 | - image_url.value = imgUrl.src; | ||
| 187 | - show_control.value = false; | ||
| 188 | - show_empty.value = false; | ||
| 189 | - emit("active", props.item.value); | ||
| 190 | - }) | ||
| 191 | - .catch((err) => { | ||
| 192 | - loading.value = false; | ||
| 193 | - // 签名生成失败 | ||
| 194 | - console.warn(err); | ||
| 195 | - if (err) { | ||
| 196 | - showFailToast("签名生成失败"); | ||
| 197 | - } | ||
| 198 | - }); | ||
| 199 | -}; | ||
| 200 | - | ||
| 201 | -//将图片base64转换为文件 | ||
| 202 | -const dataURLtoFile = (dataurl, filename) => { | ||
| 203 | - var arr = dataurl.split(","), | ||
| 204 | - mime = arr[0].match(/:(.*?);/)[1], | ||
| 205 | - bstr = atob(arr[1]), | ||
| 206 | - n = bstr.length, | ||
| 207 | - u8arr = new Uint8Array(n); | ||
| 208 | - while (n--) { | ||
| 209 | - u8arr[n] = bstr.charCodeAt(n); | ||
| 210 | } | 42 | } |
| 211 | - return new File([u8arr], filename, { type: mime }); | ||
| 212 | -}; | ||
| 213 | - | ||
| 214 | -const show_sign = ref(true); | ||
| 215 | -const startSign = () => { | ||
| 216 | - show_sign.value = false; | ||
| 217 | - show_empty.value = false; | ||
| 218 | }; | 43 | }; |
| 219 | -const cancelSign = () => { | 44 | +// 错误提示文案 |
| 220 | - show_sign.value = true; | 45 | +const validatorMessage = (val, rule) => { |
| 221 | - show_empty.value = false; | 46 | + if (required && !val.url) { |
| 222 | - handleReset(); | 47 | + return "电子签名不能为空"; |
| 223 | -}; | ||
| 224 | - | ||
| 225 | -const validSign = () => { | ||
| 226 | - // 必填项 未生成签名 | ||
| 227 | - if (props.item.component_props.required && !image_url.value) { | ||
| 228 | - show_empty.value = true; | ||
| 229 | - } else { | ||
| 230 | - show_empty.value = false; | ||
| 231 | } | 48 | } |
| 232 | - return !show_empty.value; | ||
| 233 | }; | 49 | }; |
| 234 | - | 50 | +const rules = [{ validator, message: validatorMessage }]; |
| 235 | -defineExpose({ validSign }); | ||
| 236 | </script> | 51 | </script> |
| 237 | 52 | ||
| 238 | -<!-- <script> | ||
| 239 | -export default { | ||
| 240 | - methods: { | ||
| 241 | - validSign () { | ||
| 242 | - console.warn(0); | ||
| 243 | - } | ||
| 244 | - } | ||
| 245 | -} | ||
| 246 | -</script> --> | ||
| 247 | - | ||
| 248 | <style lang="less" scoped> | 53 | <style lang="less" scoped> |
| 249 | .sign-page { | 54 | .sign-page { |
| 250 | 55 | ||
| ... | @@ -258,52 +63,9 @@ export default { | ... | @@ -258,52 +63,9 @@ export default { |
| 258 | color: red; | 63 | color: red; |
| 259 | } | 64 | } |
| 260 | } | 65 | } |
| 261 | - | ||
| 262 | - .esign-wrapper { | ||
| 263 | - padding: 1rem; | ||
| 264 | - position: relative; | ||
| 265 | - box-sizing: border-box; | ||
| 266 | - | ||
| 267 | - .sign-wrapper { | ||
| 268 | - border: 1px solid #eaeaea; | ||
| 269 | - border-radius: 5px; | ||
| 270 | - } | ||
| 271 | - | ||
| 272 | - .whiteboard { | ||
| 273 | - position: absolute; | ||
| 274 | - height: 100%; | ||
| 275 | - width: 100%; | ||
| 276 | - left: 50%; | ||
| 277 | - top: 50%; | ||
| 278 | - transform: translate(-50%, -50%); | ||
| 279 | - text-align: center; | ||
| 280 | - | ||
| 281 | - .text { | ||
| 282 | - position: absolute; | ||
| 283 | - width: 100%; | ||
| 284 | - top: 50%; | ||
| 285 | - left: 50%; | ||
| 286 | - transform: translate(-50%, -50%); | ||
| 287 | - } | ||
| 288 | - } | ||
| 289 | - | ||
| 290 | - } | ||
| 291 | - | ||
| 292 | - .control-sign { | ||
| 293 | - padding-bottom: 1rem; | ||
| 294 | - } | ||
| 295 | -} | ||
| 296 | - | ||
| 297 | -.wrapper { | ||
| 298 | - display: flex; | ||
| 299 | - align-items: center; | ||
| 300 | - justify-content: center; | ||
| 301 | - height: 100%; | ||
| 302 | } | 66 | } |
| 303 | 67 | ||
| 304 | -.block { | 68 | +:deep(.van-field__error-message) { |
| 305 | - width: 120px; | 69 | + padding-left: 1rem; |
| 306 | - height: 120px; | ||
| 307 | - background-color: #fff; | ||
| 308 | } | 70 | } |
| 309 | </style> | 71 | </style> | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-07-18 10:22:22 | 2 | * @Date: 2022-07-18 10:22:22 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2023-03-29 16:24:48 | 4 | + * @LastEditTime: 2023-03-29 17:57:51 |
| 5 | * @FilePath: /data-table/src/views/index.vue | 5 | * @FilePath: /data-table/src/views/index.vue |
| 6 | * @Description: 首页 | 6 | * @Description: 首页 |
| 7 | --> | 7 | --> |
| ... | @@ -169,9 +169,9 @@ const setRefMap = (el, item) => { | ... | @@ -169,9 +169,9 @@ const setRefMap = (el, item) => { |
| 169 | if (item.component_props.tag === "file_uploader") { | 169 | if (item.component_props.tag === "file_uploader") { |
| 170 | file_uploader.value.push(el); | 170 | file_uploader.value.push(el); |
| 171 | } | 171 | } |
| 172 | - if (item.component_props.tag === "sign") { | 172 | + // if (item.component_props.tag === "sign") { |
| 173 | - sign.value.push(el); | 173 | + // sign.value.push(el); |
| 174 | - } | 174 | + // } |
| 175 | } | 175 | } |
| 176 | }; | 176 | }; |
| 177 | 177 | ||
| ... | @@ -428,9 +428,9 @@ const onActive = (item) => { | ... | @@ -428,9 +428,9 @@ const onActive = (item) => { |
| 428 | if (item.key === "file_uploader") { | 428 | if (item.key === "file_uploader") { |
| 429 | postData.value[item.filed_name] = item.value; | 429 | postData.value[item.filed_name] = item.value; |
| 430 | } | 430 | } |
| 431 | - if (item.key === "sign") { | 431 | + // if (item.key === "sign") { |
| 432 | - postData.value[item.filed_name] = item.value; | 432 | + // postData.value[item.filed_name] = item.value; |
| 433 | - } | 433 | + // } |
| 434 | if (item.type === "radio") { // 单选控件 | 434 | if (item.type === "radio") { // 单选控件 |
| 435 | postData.value = _.assign(postData.value, { [item.key]: item.affix ? item.affix : item.value }); | 435 | postData.value = _.assign(postData.value, { [item.key]: item.affix ? item.affix : item.value }); |
| 436 | } | 436 | } |
| ... | @@ -479,18 +479,18 @@ const validOther = () => { | ... | @@ -479,18 +479,18 @@ const validOther = () => { |
| 479 | } | 479 | } |
| 480 | }); | 480 | }); |
| 481 | } | 481 | } |
| 482 | - if (sign.value) { | 482 | + // if (sign.value) { |
| 483 | - // 电子签名 | 483 | + // // 电子签名 |
| 484 | - sign.value.forEach((item, index) => { | 484 | + // sign.value.forEach((item, index) => { |
| 485 | - if (!sign.value[index].validSign()) { | 485 | + // if (!sign.value[index].validSign()) { |
| 486 | - valid = { | 486 | + // valid = { |
| 487 | - status: sign.value[index].validSign(), | 487 | + // status: sign.value[index].validSign(), |
| 488 | - key: "sign", | 488 | + // key: "sign", |
| 489 | - }; | 489 | + // }; |
| 490 | - return false; | 490 | + // return false; |
| 491 | - } | 491 | + // } |
| 492 | - }); | 492 | + // }); |
| 493 | - } | 493 | + // } |
| 494 | return valid; | 494 | return valid; |
| 495 | }; | 495 | }; |
| 496 | 496 | ... | ... |
-
Please register or login to post a comment