提交 56b159de 编写于 作者: 雪洛's avatar 雪洛

fix: 修正不跨平台的用法

上级 192f66b9
......@@ -44,8 +44,8 @@
created() {
uni.loadFontFace({
global: false,
family: 'UniIconsFontFamily',
source: iconpath,
family: 'UniIconsFontFamily',
source: "url(" + iconpath + ")",
success() { },
fail(err) {
console.log(err);
......
......@@ -19,8 +19,8 @@ export default {
}
},
onLoad(options: OnLoadOptions) {
if (options.has('data')) {
this.data = options.get('data')!
if (options['data'] != null) {
this.data = options['data']
}
},
methods: {
......
......@@ -36,7 +36,7 @@ export default {
onShow(){
uni.loadFontFace({
family: 'UniFontFamily',
source: 'static/font/uni.ttf'
source: 'url(static/font/uni.ttf)'
})
},
methods: {
......
......@@ -31,7 +31,7 @@
type="text"
placeholder="请输入value"
name="data"
:value="data"
:value="typeof data === 'string' ? data : JSON.stringify(data)"
@input="dataChange"
/>
</view>
......
......@@ -11,10 +11,10 @@
<view class="title">性别</view>
<radio-group name="gender" class="flex-row">
<view class="group-item">
<radio :value="0" :checked="gender=='0'" /><text>男</text>
<radio :value="'0'" :checked="gender=='0'" /><text>男</text>
</view>
<view class="group-item">
<radio :value="1" :checked="gender=='1'" /><text>女</text>
<radio :value="'1'" :checked="gender=='1'" /><text>女</text>
</view>
</radio-group>
</view>
......@@ -31,7 +31,7 @@
</view>
<view class="uni-form-item">
<view class="title">年龄</view>
<slider name="age" :value="age" :show-value="true"></slider>
<slider name="age" :value="age + ''" :show-value="true"></slider>
</view>
<view class="uni-form-item">
<view class="title">保留选项</view>
......
<template>
<scroll-view>
<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>
<view v-for="(item,index) in supportFormats" :key="index">
<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>
<view class="uni-title">
<text class="uni-title-text">暂不支持的格式</text>
</view>
<view v-for="(item,index) in notSupportFormats" :key="index">
<text class="uni-subtitle-text">{{item.format}}</text>
<view class="uni-center" style="background:#FFFFFF;">
<image class="image" mode="widthFix" :src="item.src" @error="imageErrorEvent"></image>
</view>
</view>
</view>
</scroll-view>
<scroll-view>
<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>
<view v-for="(item,index) in supportFormats" :key="index">
<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>
<view class="uni-title">
<text class="uni-title-text">暂不支持的格式</text>
</view>
<view v-for="(item,index) in notSupportFormats" :key="index">
<text class="uni-subtitle-text">{{item.format}}</text>
<view class="uni-center" style="background:#FFFFFF;">
<image class="image" mode="widthFix" :src="item.errorImage == null ? item.src : item.errorImage"
@error="imageErrorEvent(index, $event as ImageErrorEvent)"></image>
</view>
</view>
</view>
</scroll-view>
</template>
<script>
export default {
data() {
return {
title: 'image-format',
supportFormats: [
{
format: 'bmp',
src: '/static/test-image/logo.bmp'
},
{
format: 'gif',
src: '/static/test-image/logo.gif'
},
{
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'
},
{
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'
}
] as Array<ImageFormat>
}
},
methods: {
imageErrorEvent(e : ImageErrorEvent) {
console.log("图片加载错误", e.detail); //TODO tif打不出正确的错误日志
// 图片加载失败,加载本地占位图
e.target?.setAttribute('src', '/static/template/drop-card/dislike.png')
}
},
}
type ImageFormat = {
format : string
src : string
}
export default {
data() {
return {
title: 'image-format',
supportFormats: [
{
format: 'bmp',
src: '/static/test-image/logo.bmp'
},
{
format: 'gif',
src: '/static/test-image/logo.gif'
},
{
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'
},
{
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'
}
] as Array<ImageFormat>
}
},
methods: {
imageErrorEvent(index: number, e: ImageErrorEvent) {
console.log("图片加载错误", e.detail); //TODO tif打不出正确的错误日志
// 图片加载失败,加载本地占位图
this.notSupportFormats[index].errorImage = '/static/template/drop-card/dislike.png'
}
},
}
type ImageFormat = {
format : string
src : string
errorImage ?: string | null
}
</script>
<style>
.image {
margin: 40rpx auto;
width: 200rpx;
}
</style>
\ No newline at end of file
.image {
margin: 40rpx auto;
width: 200rpx;
}
</style>
......@@ -8,13 +8,13 @@
<view v-for="(item,index) in data" :key="index">
<text class="uni-subtitle-text">{{item.description}}</text>
<view class="uni-center" style="background:#FFFFFF;">
<image class="image" mode="widthFix" :src="item.src" @error="imageErrorEvent"></image>
<image class="image" mode="widthFix" :src="item.errorImage == null ? item.src : item.errorImage" @error="imageErrorEvent(index, $event as ImageErrorEvent)"></image>
</view>
</view>
<view>
<text class="uni-subtitle-text">非static目录的src静态路径:./logo.png</text>
<view class="uni-center" style="background:#FFFFFF;">
<image class="image" mode="widthFix" src="./logo.png" @error="imageErrorEvent"></image>
<image class="image" mode="widthFix" :src="outsideStaticErrorPath == null ? outsideStaticPath : outsideStaticErrorPath" @error="imageOutsideStaticErrorEvent"></image>
</view>
</view>
</view>
......@@ -27,6 +27,8 @@
data() {
return {
title: 'image-path',
outsideStaticPath: './logo.png',
outsideStaticErrorPath: null as string | null,
data: [
{
src: '/static/test-image/logo.png',
......@@ -91,16 +93,21 @@
}
},
methods: {
imageErrorEvent(e : ImageErrorEvent) {
imageErrorEvent(index: number, e : ImageErrorEvent) {
console.log("图片加载错误", e.detail);
// 图片加载失败,加载本地占位图
e.target?.setAttribute('src', '/static/template/drop-card/dislike.png')
this.data[index].errorImage = '/static/template/drop-card/dislike.png'
},
imageOutsideStaticErrorEvent(e: ImageErrorEvent) {
console.log("图片加载错误", e.detail);
this.outsideStaticErrorPath = '/static/template/drop-card/dislike.png'
}
},
}
type ImagePath = {
src : string
errorImage ?: string | null
description : string
}
</script>
......
......@@ -8,7 +8,7 @@
<view v-for="(item,index) in supportFormats" :key="index">
<text class="uni-subtitle-text">{{item.format}}</text>
<video :id="'video-' + item.format" class="video" :src="item.src" :controls="true" :direction="-90"
@error="onError"></video>
@error="onError(item.format, $event as VideoErrorEvent)"></video>
</view>
<view class="uni-title">
<text class="uni-title-text">暂不支持的格式</text>
......@@ -78,10 +78,9 @@
}
},
methods: {
onError: function (e : VideoErrorEvent) {
const id = e.target?.getAttribute("id");
console.log(id + ":" + e.detail);
if (id != "video-错误路径") {
onError: function (format: string, e : VideoErrorEvent) {
console.log(format + ":" + e.detail);
if (format != "video-错误路径") {
this.isError = true;
}
}
......
// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('template-list-news', () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) {
it('dummyTest', async () => {
expect(1).toBe(1)
})
return
}
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/template/list-news/list-news');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册