fix: 新增设备
This commit is contained in:
parent
7f321213a8
commit
c5bc7e7f6a
|
@ -26,7 +26,8 @@ const iconKeys = [
|
||||||
'ExportOutlined',
|
'ExportOutlined',
|
||||||
'SyncOutlined',
|
'SyncOutlined',
|
||||||
'ExclamationCircleOutlined',
|
'ExclamationCircleOutlined',
|
||||||
'UploadOutlined'
|
'UploadOutlined',
|
||||||
|
'LoadingOutlined'
|
||||||
]
|
]
|
||||||
|
|
||||||
const Icon = (props: {type: string}) => {
|
const Icon = (props: {type: string}) => {
|
||||||
|
|
|
@ -1,70 +1,213 @@
|
||||||
<template>
|
<template>
|
||||||
<a-upload
|
<div class="upload-image-warp">
|
||||||
v-model:file-list="fileList"
|
<div class="upload-image-border">
|
||||||
name="avatar"
|
<a-upload
|
||||||
list-type="picture-card"
|
name="file"
|
||||||
class="avatar-uploader"
|
list-type="picture-card"
|
||||||
:show-upload-list="false"
|
class="avatar-uploader"
|
||||||
action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
|
:show-upload-list="false"
|
||||||
:before-upload="beforeUpload"
|
:before-upload="beforeUpload"
|
||||||
@change="handleChange"
|
@change="handleChange"
|
||||||
>
|
:action="FILE_UPLOAD"
|
||||||
<img v-if="imageUrl" :src="imageUrl" alt="avatar" />
|
:headers="{
|
||||||
<div v-else>
|
'X-Access-Token': LocalStore.get(TOKEN_KEY)
|
||||||
<loading-outlined v-if="loading"></loading-outlined>
|
}"
|
||||||
<plus-outlined v-else></plus-outlined>
|
v-bind="props"
|
||||||
<div class="ant-upload-text">Upload</div>
|
>
|
||||||
|
<div class="upload-image-content" :style="props.style">
|
||||||
|
<template v-if="myValue">
|
||||||
|
<!-- <div class="upload-image"
|
||||||
|
:style="{
|
||||||
|
backgroundSize: props.backgroundSize,
|
||||||
|
backgroundImage: `url(${imageUrl})`
|
||||||
|
}"
|
||||||
|
></div> -->
|
||||||
|
<img :src="myValue" class="upload-image" />
|
||||||
|
<div class="upload-image-mask">点击修改</div>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<AIcon type="LoadingOutlined" v-if="loading" style="font-size: 20px" />
|
||||||
|
<AIcon v-else type="PlusOutlined" style="font-size: 20px" />
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</a-upload>
|
||||||
|
<div class="upload-loading-mask" v-if="props.disabled"></div>
|
||||||
|
<div class="upload-loading-mask" v-if="myValue && loading">
|
||||||
|
<AIcon type="LoadingOutlined" style="font-size: 20px" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a-upload>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { message, UploadChangeParam, UploadProps } from 'ant-design-vue';
|
import { message, UploadChangeParam, UploadProps } from 'ant-design-vue';
|
||||||
|
import { FILE_UPLOAD } from '@/api/comm'
|
||||||
|
import { TOKEN_KEY } from '@/utils/variable';
|
||||||
|
import { LocalStore } from '@/utils/comm';
|
||||||
|
import { CSSProperties } from 'vue';
|
||||||
|
|
||||||
|
type Emits = {
|
||||||
|
(e: 'update:modelValue', data: string): void;
|
||||||
|
};
|
||||||
|
interface JUploadProps extends UploadProps {
|
||||||
|
modelValue: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
types?: string[];
|
||||||
|
errorMessage?: string;
|
||||||
|
size?: number;
|
||||||
|
style?: CSSProperties;
|
||||||
|
backgroundSize?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const emit = defineEmits<Emits>();
|
||||||
|
|
||||||
|
const props: JUploadProps = defineProps({
|
||||||
|
modelValue: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const loading = ref<boolean>(false)
|
||||||
|
const imageUrl = ref<string>(props?.modelValue || '')
|
||||||
|
const imageTypes = props.types ? props.types : ['image/jpeg', 'image/png'];
|
||||||
|
|
||||||
|
const myValue = computed({
|
||||||
|
get: () => {
|
||||||
|
return props.modelValue;
|
||||||
|
},
|
||||||
|
set: (val: any) => {
|
||||||
|
imageUrl.value = val;
|
||||||
|
emit('update:modelValue', val);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const handleChange = (info: UploadChangeParam) => {
|
const handleChange = (info: UploadChangeParam) => {
|
||||||
// if (info.file.status === 'uploading') {
|
if (info.file.status === 'uploading') {
|
||||||
// loading.value = true;
|
loading.value = true;
|
||||||
// return;
|
}
|
||||||
// }
|
if (info.file.status === 'done') {
|
||||||
// if (info.file.status === 'done') {
|
myValue.value = info.file.response?.result
|
||||||
// // Get this url from response in real world.
|
loading.value = false;
|
||||||
// getBase64(info.file.originFileObj, (base64Url: string) => {
|
emit('update:modelValue', imageUrl.value)
|
||||||
// imageUrl.value = base64Url;
|
}
|
||||||
// loading.value = false;
|
if (info.file.status === 'error') {
|
||||||
// });
|
loading.value = false;
|
||||||
// }
|
message.error('上传失败');
|
||||||
// if (info.file.status === 'error') {
|
}
|
||||||
// loading.value = false;
|
|
||||||
// message.error('upload error');
|
|
||||||
// }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const beforeUpload = (file: UploadProps['fileList'][number]) => {
|
const beforeUpload = (file: UploadProps['fileList'][number]) => {
|
||||||
// const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
|
const isType = imageTypes.includes(file.type);
|
||||||
// if (!isJpgOrPng) {
|
if (!isType) {
|
||||||
// message.error('You can only upload JPG file!');
|
if (props.errorMessage) {
|
||||||
// }
|
message.error(props.errorMessage);
|
||||||
// const isLt2M = file.size / 1024 / 1024 < 2;
|
} else {
|
||||||
// if (!isLt2M) {
|
message.error(`请上传正确格式的图片`);
|
||||||
// message.error('Image must smaller than 2MB!');
|
}
|
||||||
// }
|
return false;
|
||||||
// return isJpgOrPng && isLt2M;
|
}
|
||||||
|
const isSize = file.size / 1024 / 1024 < (props.size || 4);
|
||||||
|
if (!isSize) {
|
||||||
|
message.error(`图片大小必须小于${props.size || 4}M`);
|
||||||
|
}
|
||||||
|
return isType && isSize;
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
.avatar-uploader {
|
@border: 1px dashed @border-color-base;
|
||||||
width: 160px;
|
@mask-color: rgba(#000, 0.35);
|
||||||
height: 160px;
|
@with: 150px;
|
||||||
padding: 8px;
|
@height: 150px;
|
||||||
background-color: rgba(0,0,0,.06);
|
|
||||||
cursor: pointer;
|
.flex-center() {
|
||||||
display: flex;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
}
|
||||||
:deep(.ant-upload.ant-upload-select-picture-card) {
|
|
||||||
|
.upload-image-warp {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
|
||||||
|
.upload-image-border {
|
||||||
|
position: relative;
|
||||||
|
width: @with;
|
||||||
|
height: @height;
|
||||||
|
overflow: hidden;
|
||||||
|
//border-radius: 50%;
|
||||||
|
// border: @border;
|
||||||
|
transition: all 0.3s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-color: @primary-color-hover;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-upload-picture-card-wrapper) {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
:deep(.ant-upload) {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-image-content {
|
||||||
|
.flex-center();
|
||||||
|
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgba(#000, 0.06);
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 8px;
|
||||||
|
|
||||||
|
.upload-image-mask {
|
||||||
|
.flex-center();
|
||||||
|
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
display: none;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 16px;
|
||||||
|
background-color: @mask-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
//border-radius: 50%;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
background-size: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover .upload-image-mask {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-loading-mask {
|
||||||
|
.flex-center();
|
||||||
|
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
color: #fff;
|
||||||
|
background-color: @mask-color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
|
@ -4,8 +4,8 @@
|
||||||
<a-form :layout="'vertical'">
|
<a-form :layout="'vertical'">
|
||||||
<a-row type="flex">
|
<a-row type="flex">
|
||||||
<a-col flex="180px">
|
<a-col flex="180px">
|
||||||
<a-form-item required>
|
<a-form-item required name="photoUrl">
|
||||||
<JUpload />
|
<JUpload v-model:value="modelRef.photoUrl" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-col>
|
</a-col>
|
||||||
<a-col flex="auto">
|
<a-col flex="auto">
|
||||||
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { queryNoPagingPost } from '@/api/device/product'
|
import { queryNoPagingPost } from '@/api/device/product'
|
||||||
|
import { getImage } from '@/utils/comm';
|
||||||
import { Form } from 'ant-design-vue';
|
import { Form } from 'ant-design-vue';
|
||||||
|
|
||||||
const emit = defineEmits(['close', 'save'])
|
const emit = defineEmits(['close', 'save'])
|
||||||
|
@ -49,7 +50,7 @@ const modelRef = reactive({
|
||||||
id: '',
|
id: '',
|
||||||
name: '',
|
name: '',
|
||||||
describe: '',
|
describe: '',
|
||||||
photoUrl: ''
|
photoUrl: getImage('/device/instance/device-card.png')
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
Loading…
Reference in New Issue