Commit 0747fc0d by haojie

1

parent 57a7202c
......@@ -68,7 +68,11 @@
></LocalUpload>
</template>
<template v-else-if="it.component_type == 'upload'">
<CustomUpload v-model="it.value" :config="config"></CustomUpload>
<CustomUpload
v-model="it.value"
:config="config"
:rules="it.rules"
></CustomUpload>
</template>
<template v-else-if="it.component_type == 'label'">
<CustomAddTag
......
......@@ -17,6 +17,7 @@ export default defineComponent({
props: {
modelValue: String,
config: Object as any,
rules: Array,
},
emits: ['update:modelValue'],
setup(props, { emit }) {
......@@ -44,13 +45,50 @@ export default defineComponent({
percentage.value += 1;
}, 100);
};
const beforeUpload = (file: File) => {
// 获取文件尺寸
const getFileSize = async (file: any) => {
return new Promise((resolve, reject) => {
// 获取文件尺寸
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = async (e: any) => {
let data = e.target.result;
let image = new Image();
image.src = data;
image.onload = () => {
resolve(`${image.width},${image.height}`);
};
image.onerror = () => {
reject('');
};
};
});
};
const beforeUpload = async (file: any) => {
try {
const { config } = props;
const { config, rules } = props;
const config_len = Object.keys(config).length;
if (!config_len) {
show_message('无法上传,请尝试刷新页面');
return false;
} else if (rules && rules.length) {
// 判断是否存在 image_size 规则
const rule_data: any = rules.find(
(item: any) => item.type == 'image_size'
);
if (rule_data && rule_data !== -1) {
// 格式 1024,1024
const image_size = rule_data.value ?? '';
if (!image_size) {
show_message('缺少图片尺寸校验');
return false;
}
const size = await getFileSize(file.raw);
if (size !== image_size) {
show_message(rule_data.message);
return false;
}
}
}
return true;
} catch (e) {
......
......@@ -131,7 +131,6 @@ export const FormExample = [
],
},
{
// 继续聊天
type: 'gpt_continues_chat',
name: 'category_5',
label: '继续聊天',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment