image-format.uvue 2.3 KB
Newer Older
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
1
<template>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
2
	<scroll-view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
3 4 5 6 7
		<page-head :title="title"></page-head>
		<view class="uni-padding-wrap uni-common-mt">
			<view class="uni-title">
				<text class="uni-title-text">支持的图片格式示例</text>
			</view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
8
			<view v-for="(item,index) in supportFormats" :key="index">
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
9 10 11 12 13
				<text class="uni-subtitle-text">{{item.format}}</text>
				<view class="uni-center" style="background:#FFFFFF;">
					<image class="image" mode="widthFix" :src="item.src"></image>
				</view>
			</view>
W
wanganxp 已提交
14 15 16
			<view class="uni-title">
				<text class="uni-title-text">暂不支持的格式</text>
			</view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
17 18
			<view v-for="(item,index) in notSupportFormats" :key="index">
				<text class="uni-subtitle-text">{{item.format}}</text>
W
wanganxp 已提交
19
				<view class="uni-center" style="background:#FFFFFF;">
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
20
					<image class="image" mode="widthFix" :src="item.src" @error="imageErrorEvent"></image>
W
wanganxp 已提交
21 22
				</view>
			</view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
23
		</view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
24
	</scroll-view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
25 26 27 28 29 30 31
</template>

<script>
	export default {
		data() {
			return {
				title: 'image-format',
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
32
				supportFormats: [
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
33
					{
W
wanganxp 已提交
34 35
						format: 'bmp',
						src: '/static/test-image/logo.bmp'
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
36 37
					},
					{
W
wanganxp 已提交
38 39
						format: 'gif',
						src: '/static/test-image/logo.gif'
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
40 41
					},
					{
W
wanganxp 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55
						format: 'ico',
						src: '/static/test-image/logo.ico'
					},
					{
						format: 'jpg',
						src: '/static/test-image/logo.jpg'
					},
					{
						format: 'png',
						src: '/static/test-image/logo.png'
					},
					{
						format: 'webp',
						src: '/static/test-image/logo.webp'
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69
					},
					{
						format: 'heic(Android10+支持)',
						src: '/static/test-image/logo.heic'
					}
				] as Array<ImageFormat>,
				notSupportFormats: [
					{
						format: 'avif',
						src: '/static/test-image/logo.avif'
					},
					{
						format: 'tif',
						src: '/static/test-image/logo.tif'
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
70
					}
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
71
				] as Array<ImageFormat>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
72
			}
W
wanganxp 已提交
73 74
		},
		methods: {
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
75 76 77 78
			imageErrorEvent(e : ImageErrorEvent) {
				console.log("图片加载错误", e.detail); //TODO tif打不出正确的错误日志
				// 图片加载失败,加载本地占位图
				e.target?.setAttribute('src', '/static/template/drop-card/dislike.png')
W
wanganxp 已提交
79 80
			}
		},
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
81 82 83
	}

	class ImageFormat {
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
84 85
		format : string;
		src : string;
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
86

DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
87
		constructor(format : string, src : string) {
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
88 89 90 91 92 93 94 95 96 97 98 99
			this.format = format;
			this.src = src;
		}
	}
</script>

<style>
	.image {
		margin: 40rpx auto;
		width: 200rpx;
	}
</style>