1、大量页面调整
2、完善运力模块 3、完善规范、需求卡
This commit is contained in:
89
src/components/image-upload-field/main.vue
Normal file
89
src/components/image-upload-field/main.vue
Normal file
@@ -0,0 +1,89 @@
|
||||
<template>
|
||||
<el-form-item v-if="mode === 'form'" :label="label" :prop="prop">
|
||||
<el-upload
|
||||
:class="[`${classPrefix}-uploader`, { [`${classPrefix}-uploader--large`]: large }]"
|
||||
action="/api/blade-resource/oss/endpoint/put-file"
|
||||
name="file"
|
||||
:headers="headers"
|
||||
:show-file-list="false"
|
||||
:disabled="readonly"
|
||||
:before-upload="beforeUpload"
|
||||
:on-success="handleSuccess"
|
||||
>
|
||||
<img v-if="value" :src="value" :class="`${classPrefix}-uploader__image`" />
|
||||
<div v-else :class="`${classPrefix}-uploader__empty`">{{ emptyText }}</div>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
<el-form-item v-else :prop="prop" :class="`${classPrefix}-upload-item`">
|
||||
<div :class="[`${classPrefix}-upload-card`, { [`${classPrefix}-upload-card--large`]: large }]">
|
||||
<div v-if="label" :class="`${classPrefix}-upload-card__head`">
|
||||
<span :class="`${classPrefix}-upload-card__label`">{{ label }}</span>
|
||||
<span :class="`${classPrefix}-upload-card__action`">{{ actionText }}</span>
|
||||
</div>
|
||||
<el-upload
|
||||
:class="`${classPrefix}-upload-card__uploader`"
|
||||
action="/api/blade-resource/oss/endpoint/put-file"
|
||||
name="file"
|
||||
:headers="headers"
|
||||
:show-file-list="false"
|
||||
:disabled="readonly"
|
||||
:before-upload="beforeUpload"
|
||||
:on-success="handleSuccess"
|
||||
>
|
||||
<img v-if="value" :src="value" :class="`${classPrefix}-upload-card__image`" />
|
||||
<div v-else :class="`${classPrefix}-upload-card__empty`">{{ emptyText }}</div>
|
||||
</el-upload>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'ImageUploadField',
|
||||
props: {
|
||||
label: String,
|
||||
prop: String,
|
||||
value: String,
|
||||
readonly: Boolean,
|
||||
headers: Object,
|
||||
large: Boolean,
|
||||
mode: {
|
||||
type: String,
|
||||
default: 'form',
|
||||
},
|
||||
classPrefix: {
|
||||
type: String,
|
||||
default: 'driver',
|
||||
},
|
||||
emptyText: {
|
||||
type: String,
|
||||
default: '上传证件图片',
|
||||
},
|
||||
actionText: {
|
||||
type: String,
|
||||
default: '点击上传',
|
||||
},
|
||||
},
|
||||
emits: ['success'],
|
||||
methods: {
|
||||
handleSuccess(res) {
|
||||
if (res.code === 200 && res.data) {
|
||||
this.$emit('success', res.data.link || res.data.url || res.data.domain || '');
|
||||
} else {
|
||||
this.$message.error(res.msg || '上传失败');
|
||||
}
|
||||
},
|
||||
beforeUpload(file) {
|
||||
const validType = ['image/jpeg', 'image/png', 'image/jpg', 'image/bmp'].includes(file.type);
|
||||
const validSize = file.size / 1024 / 1024 < 5;
|
||||
if (!validType) {
|
||||
this.$message.error('仅支持 JPG、PNG、BMP 图片');
|
||||
}
|
||||
if (!validSize) {
|
||||
this.$message.error('图片大小不能超过 5MB');
|
||||
}
|
||||
return validType && validSize;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user