!28 添加Avatar组件示例程序

Merge pull request !28 from Sagi/alpha
This commit is contained in:
Sagi 2022-09-30 15:17:53 +00:00 committed by Gitee
commit fc79738ccb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 210 additions and 202 deletions

View File

@ -2,65 +2,64 @@ import { defineComponent, computed, ref, SetupContext } from 'vue';
import { avatarProps, AvatarProps } from './avatar.props';
export default defineComponent({
name: 'Avatar',
props: avatarProps,
emits: ['change'],
setup(props: AvatarProps, context: SetupContext) {
const avatarClass = computed(() => ({
'f-avatar': true,
'f-avatar-readonly': props.readonly,
'f-avatar-circle': props.shape === 'circle',
'f-avatar-square': props.shape === 'square',
}));
name: 'Avatar',
props: avatarProps,
emits: ['change'],
setup(props: AvatarProps, context: SetupContext) {
const avatarClass = computed(() => ({
'f-avatar': true,
'f-avatar-readonly': props.readonly,
'f-avatar-circle': props.shape === 'circle',
'f-avatar-square': props.shape === 'square'
}));
const avatarStyle = computed(() => ({
width: props.avatarWidth + 'px',
height: props.avatarHeight + 'px',
}));
const avatarStyle = computed(() => ({
width: props.avatarWidth + 'px',
height: props.avatarHeight + 'px'
}));
let showLoading = false;
let imgSrc = '';
let showLoading = false;
let imgSrc = '';
const currentImgType = ['image/image', 'image/webp', 'image/png', 'image/svg', 'image/gif', 'image/jpg', 'image/jpeg', 'image/bmp'];
const currentImgType = ['image/image', 'image/webp', 'image/png', 'image/svg', 'image/gif', 'image/jpg', 'image/jpeg', 'image/bmp'];
function errorSrc() {
return '';
function errorSrc() {
return '';
}
function getfiledata() {}
const defaultImgSrc =
'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAZABkAAD/2wBDAAwICQoJBwwKCQoNDAwOER0TERAQESMZGxUdKiUsKyklKCguNEI4LjE/MigoOk46P0RHSktKLTdRV1FIVkJJSkf/2wBDAQwNDREPESITEyJHMCgwR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0f/wA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7t2T/vKh/mK0oviZ4mj++YpP8AeT/AigB//CdeNbP/AI+ucf8APSID+QFbvxUlcw6dG/3iHY/XC1Ri+KurL/r7aFv93cv8ya5XxT4om8T3EU0sQiESkAA569TnigDlqKKKACiiigD/1P7MKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/V/swooooAKKKKACiiigAooooAKKKKACiiigAooooA/9k=';
const imageType = computed(() => props.type.join());
return () => {
return (
<div class={avatarClass.value} style={avatarStyle.value}>
{showLoading && (
<div class="f-avatar-upload-loading">
<div class="loading-inner"></div>
</div>
)}
<img title={props.tile} class="f-avatar-image" src={imgSrc} onError={errorSrc()} />
{!props.readonly && (
<div class="f-avatar-icon">
<span class="f-icon f-icon-camera"></span>
</div>
)}
<input
name="file-input"
type="file"
class="f-avatar-upload"
accept={imageType.value}
onChange={getfiledata}
style="display: none;"
/>
</div>
);
};
}
function getfiledata() {}
const defaultImgSrc =
'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAZABkAAD/2wBDAAwICQoJBwwKCQoNDAwOER0TERAQESMZGxUdKiUsKyklKCguNEI4LjE/MigoOk46P0RHSktKLTdRV1FIVkJJSkf/2wBDAQwNDREPESITEyJHMCgwR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0f/wAARCAEsASwDASIAAhEBAxEB/8QAGgABAQEBAQEBAAAAAAAAAAAAAAECAwQFB//EADMQAQEAAQEECAQGAgMBAAAAAAABAhEDITFBBBRRUmFxgaESkcHwEyIysdHhM3IjQvE0/8QAFQEBAQAAAAAAAAAAAAAAAAAAAAH/xAAXEQEBAQEAAAAAAAAAAAAAAAAAEQEh/9oADAMBAAIRAxEAPwD9BBYqCiyAGhougIqyGgEhIui6AyuixdATQ0WQA0BdA4houhoCaGgugMrouhoCaJoum80BNDRdDQGTRbEBNCxdDQGTRUBE0asQGRTQGTT71WxNPP5AugqyACyAC6dpIsgGgshoBISKAiroQDQ0OSyAgoBoaAB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/B7H14oA9B8a+CLHQtPXUtNd9oYKyuQevQg4H5Vc0z/R/hddyf33P6sq1xOu+LNY8QxpDfsojQ5CoMDPqeTmu3m/cfCiNe8rf+1Sf5CgDyKiiigAooooA//9L+zCiiigDX8PyeVr1lJ6Tx/wDoQrrvifHs8SK39+FT+rD+lcHZSeVeRS/3XU/ka9r8d+FNX17U4bnTUVlWLYxZgMEMT9e9AHhgBJwOpr6Rv/DIv7XTdIuOLW0UNL2yUUKB+OTn2ryyLwZqWj6zp41XZ5c86r8pzyCDg9Otd5471y5aeLwpph2zXe0O54AVjgDPv39uKAOB8ceJxrN0NPsDiztzhcdGI43fQdB/9euCr0iX4XeIk5jkgf6MR/NazJfh94ri5FsHH+y6/wBSKAOKr1zxB/o/w20+L++yfqGauFl8JeJYfv2Up/3V3fyzXeeOka18I6TZSAqyhMg8EFY8HP50AeQ0UUUAFFFFAH//0/7MKKKKACvffG8viWSOyk8PGYiRWL+SD/skZI6dTXgVd3D8RfEkFsltG0eI1ChiuTgcc84oAoX+n+MYVXVdUS4IgIYPIS205GDyTjmvRfFehXfjCysdc0ZVMjR/MCQODyBk+hyK831Lxn4i1a1ayvJ8xP8AeVVUZx7gZrMste1rToxBY3UsaDooY7R+HSgDrP7A+Itj/qvtCgf3Jgf0DUv2/wCJNl1F1x3MZcfmQay4vHniyH7t2T/vKh/mK0oviZ4mj++YpP8AeT/AigB//CdeNbP/AI+ucf8APSID+QFbvxUlcw6dG/3iHY/XC1Ri+KurL/r7aFv93cv8ya5XxT4om8T3EU0sQiESkAA569TnigDlqKKKACiiigD/1P7MKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/V/swooooAKKKKACiiigAooooAKKKKACiiigAooooA/9k=';
const imageType = computed(() => props.type.join());
return () => {
return (
<div class={avatarClass.value} style={avatarStyle.value}>
{showLoading && (
<div class="f-avatar-upload-loading">
<div class="loading-inner"></div>
</div>
)}
<img title={props.tile} class="f-avatar-image" src={imgSrc} onError={errorSrc()} />
{!props.readonly && (
<div class="f-avatar-icon">
<span class="f-icon f-icon-camera"></span>
</div>
)}
<input
name="file-input"
type="file"
class="f-avatar-upload"
accept={imageType.value}
onChange={getfiledata}
style="display: none;"
/>
</div>
);
};
},
});

View File

@ -1,19 +1,19 @@
import { ComputedRef } from 'vue';
export interface UseImage {
acceptTypes: ComputedRef<string>;
acceptTypes: ComputedRef<string>;
imageSrc: ComputedRef<string>;
imageSrc: ComputedRef<string>;
imageTitle: ComputedRef<string>;
imageTitle: ComputedRef<string>;
}
export interface ImageFile {
size: number;
name: string;
type: string;
lastModified?: string;
lastModifiedDate?: Date;
state?: string;
base64?: string;
size: number;
name: string;
type: string;
lastModified?: string;
lastModifiedDate?: Date;
state?: string;
base64?: string;
}

View File

@ -5,88 +5,88 @@ import { AvatarProps } from '../avatar.props';
import { ImageFile } from './types';
export function useFile(props: AvatarProps, context: SetupContext, allowTypes: string[]) {
function getFileData($event: Event) {
if (props.readonly) {
return;
}
const fileInput = $event.target as HTMLInputElement;
const selectedFiles = fileInput.files;
if (!selectedFiles || !selectedFiles[0]) {
return;
}
const fileType = selectedFiles[0].type;
const isLtSize = selectedFiles[0].size / 1024 / 1024 < props.maxSize;
if (allowTypes.indexOf(fileType) < 0) {
const typeErrorMessage = this.localeService.getValue('avatar.typeError');
this.notifyService.error({
type: 'error',
title: '',
msg: typeErrorMessage,
});
fileInput.value = '';
return;
}
if (!isLtSize) {
const sizeErrorMessageTemplate = this.localeService.getValue('avatar.sizeError');
const sizeErrorMessage: string = sizeErrorMessageTemplate + props.maxSize + 'MB!';
this.notifyService.error({
type: 'error',
title: '',
msg: sizeErrorMessage,
});
fileInput.value = '';
return;
}
this.transformFile(selectedFiles[0]);
fileInput.value = '';
}
function readSourceFile(sourceFile: File): Promise<{ state: string; content: string | ArrayBuffer | null }> {
const result = new Promise<{ state: string; content: string | ArrayBuffer | null }>((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(sourceFile);
reader.onload = () => {
resolve({ state: 'done', content: reader.result });
};
reader.onerror = function () {
reject({ state: 'error', content: reader.result });
};
});
return result;
}
function updateImageSrc(imageSrc: string) {}
function removeBase64(imageSrc: string) {}
function transformFile(sourceFile: File) {
// const subject = new Subject();
const imageFile: ImageFile = {
size: sourceFile.size,
name: sourceFile.name,
type: sourceFile.type,
lastModified: String(sourceFile.lastModified),
};
readSourceFile(sourceFile)
.then((result) => {
if (result.state === 'done') {
updateImageSrc(result.content as string);
const imageFileContent = removeBase64(imageSrc);
context.emit('change', imageFileContent);
context.emit('touched');
imageFile.state = result.state;
imageFile.base64 = result.content as string;
context.emit('imageChange', imageFile);
function getFileData($event: Event) {
if (props.readonly) {
return;
}
})
.catch((reason) => {
const uploadErrorText = this.localeService.getValue('avatar.uploadError');
this.notifyService.error({
type: 'error',
title: '',
msg: uploadErrorText,
const fileInput = $event.target as HTMLInputElement;
const selectedFiles = fileInput.files;
if (!selectedFiles || !selectedFiles[0]) {
return;
}
const fileType = selectedFiles[0].type;
const isLtSize = selectedFiles[0].size / 1024 / 1024 < props.maxSize;
if (allowTypes.indexOf(fileType) < 0) {
const typeErrorMessage = this.localeService.getValue('avatar.typeError');
this.notifyService.error({
type: 'error',
title: '',
msg: typeErrorMessage
});
fileInput.value = '';
return;
}
if (!isLtSize) {
const sizeErrorMessageTemplate = this.localeService.getValue('avatar.sizeError');
const sizeErrorMessage: string = sizeErrorMessageTemplate + props.maxSize + 'MB!';
this.notifyService.error({
type: 'error',
title: '',
msg: sizeErrorMessage
});
fileInput.value = '';
return;
}
this.transformFile(selectedFiles[0]);
fileInput.value = '';
}
function readSourceFile(sourceFile: File): Promise<{ state: string; content: string | ArrayBuffer | null }> {
const result = new Promise<{ state: string; content: string | ArrayBuffer | null }>((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(sourceFile);
reader.onload = () => {
resolve({ state: 'done', content: reader.result });
};
reader.onerror = function () {
reject({ state: 'error', content: reader.result });
};
});
});
}
return result;
}
function updateImageSrc(imageSrc: string) {}
function removeBase64(imageSrc: string) {}
function transformFile(sourceFile: File) {
// const subject = new Subject();
const imageFile: ImageFile = {
size: sourceFile.size,
name: sourceFile.name,
type: sourceFile.type,
lastModified: String(sourceFile.lastModified)
};
readSourceFile(sourceFile)
.then((result) => {
if (result.state === 'done') {
updateImageSrc(result.content as string);
const imageFileContent = removeBase64(imageSrc);
context.emit('change', imageFileContent);
context.emit('touched');
imageFile.state = result.state;
imageFile.base64 = result.content as string;
context.emit('imageChange', imageFile);
}
})
.catch((reason) => {
const uploadErrorText = this.localeService.getValue('avatar.uploadError');
this.notifyService.error({
type: 'error',
title: '',
msg: uploadErrorText
});
});
}
}

View File

@ -3,69 +3,69 @@ import { AvatarProps } from '../avatar.props';
import { UseImage } from './types';
export function useImage(props: AvatarProps, context: SetupContext, fileInput: HTMLInputElement): UseImage {
const defaultImage = '';
const errorImage = '';
const defaultImage = '';
const errorImage = '';
// 判断是否是图片路径
function isUrl(url: string) {
return url.match(/\.(jpeg|jpg|gif|png|svg|bmp|webp)$/) != null;
}
// 判断是否是完成base64
function isBase64Image(url: string) {
return url.indexOf('data:image/') > -1;
}
function appendBase64ImageHeader(val) {
if (!val) {
return '';
// 判断是否是图片路径
function isUrl(url: string) {
return url.match(/\.(jpeg|jpg|gif|png|svg|bmp|webp)$/) != null;
}
return 'data:image/jpeg;base64,' + val;
}
const acceptTypes = computed(() => {
if (!props.type || !props.type.length) {
return '';
// 判断是否是完成base64
function isBase64Image(url: string) {
return url.indexOf('data:image/') > -1;
}
const imageTypesArray = props.type.map((fileType: string) => {
if (fileType === 'jpg') {
fileType = 'jpeg';
}
return `image/${fileType}`;
function appendBase64ImageHeader(val) {
if (!val) {
return '';
}
return 'data:image/jpeg;base64,' + val;
}
const acceptTypes = computed(() => {
if (!props.type || !props.type.length) {
return '';
}
const imageTypesArray = props.type.map((fileType: string) => {
if (fileType === 'jpg') {
fileType = 'jpeg';
}
return `image/${fileType}`;
});
if (!imageTypesArray || !imageTypesArray.length) {
return 'image/*';
}
return imageTypesArray.join(',');
});
if (!imageTypesArray || !imageTypesArray.length) {
return 'image/*';
}
return imageTypesArray.join(',');
});
const imageSrc = computed(() => {
if (!props.cover) {
return defaultImage;
}
if (isUrl(props.cover)) {
return props.cover;
}
if (isBase64Image(props.cover)) {
return props.cover;
}
return appendBase64ImageHeader(props.cover);
});
const imageSrc = computed(() => {
if (!props.cover) {
return defaultImage;
}
if (isUrl(props.cover)) {
return props.cover;
}
if (isBase64Image(props.cover)) {
return props.cover;
}
return appendBase64ImageHeader(props.cover);
});
const imageTitle = computed(() => {
return props.readonly ? '' : props.tile;
});
const imageTitle = computed(() => {
return props.readonly ? '' : props.tile;
});
function onClickImage() {
if (this.readonly) {
return;
function onClickImage() {
if (this.readonly) {
return;
}
fileInput.click();
}
fileInput.click();
}
function getImageFile() {
return this.imgFileObj;
}
function getImageFile() {
return this.imgFileObj;
}
return { acceptTypes, imageSrc, imageTitle };
return { acceptTypes, imageSrc, imageTitle };
}

View File

@ -4,6 +4,7 @@
import { ref } from "vue";
import HelloWorld from './components/hello-world.vue';
import ButtonEdit from "../components/button-edit/src/button-edit.component";
import Avatar from './components/avatar.vue';
const canEdit = ref(true);
const canAutoComplete = ref(false);
@ -25,6 +26,7 @@ const canAutoComplete = ref(false);
<label for="checkbox">auto complete:{{ canAutoComplete }}</label>
<HelloWorld msg="Vite + Vue" />
<ButtonEdit :editable="canEdit" :auto-complete="canAutoComplete" :enable-clear="true"></ButtonEdit>
<Avatar></Avatar>
</template>
<style scoped>

View File

@ -0,0 +1,7 @@
<script setup lang="ts">
import Avatar from '../../components/avatar/src/avatar.component';
</script>
<template>
<avatar></avatar>
</template>