Skip to content

Commit a114572

Browse files
committed
feat: support svg
1 parent f15db41 commit a114572

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

miniprogram/pages/repo/file.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// miniprogram/pages/repo/file.js
22
const REPO = require('../../api/repo.js')
33
const Base64 = require('../../utils/base64.js').Base64
4-
const img = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff', 'ico']
4+
const img = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'tiff', 'ico']
55
Page({
66

77
/**
@@ -61,6 +61,9 @@ Page({
6161
if (this.data.type === 'img') {
6262
content = 'data:image/png;base64,' + res.content
6363
}
64+
if (this.data.type === 'svg') {
65+
content = 'data:image/svg+xml;base64,' + res.content
66+
}
6467
this.setData({
6568
currThis: this,
6669
content: content,
@@ -75,11 +78,13 @@ Page({
7578
},
7679

7780
toPreview: function (e) {
78-
const img = e.currentTarget.dataset.img
79-
wx.previewImage({
80-
current: img,
81-
urls: [img]
82-
})
81+
if (this.data.type === 'img') {
82+
const img = e.currentTarget.dataset.img
83+
wx.previewImage({
84+
current: img,
85+
urls: [img]
86+
})
87+
}
8388
}
8489

8590
})

miniprogram/pages/repo/file.wxml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--miniprogram/pages/repo/file.wxml-->
2-
<view wx:if="{{ !loading }}" class="{{ type === 'md' ? 'wrap' : ''}} {{ type === 'img' ? 'imgwrap' : '' }}">
3-
<towxml wx:if="{{ type !== 'img' }}" loading="{{loading}}" curr-this="{{ currThis }}" md="{{ content || empty }}"></towxml>
2+
<view wx:if="{{ !loading }}" class="{{ type === 'md' ? 'wrap' : ''}} {{ type === 'img' || type === 'svg' ? 'imgwrap' : '' }}">
3+
<towxml wx:if="{{ type !== 'img' && type !== 'svg' }}" loading="{{loading}}" curr-this="{{ currThis }}" md="{{ content || empty }}"></towxml>
44
<image wx:else src="{{ content }}" class="img" mode="widthFix" bindtap="toPreview" data-img="{{ content }}"></image>
55
</view>
66
<image wx:else class="loading" src="../../assets/loading.gif"></image>

0 commit comments

Comments
 (0)