链接图片加载

This commit is contained in:
shenyanpei
2021-12-02 14:42:16 +08:00
parent c14d265793
commit 95f5eba025
2 changed files with 19 additions and 13 deletions
@@ -127,7 +127,6 @@
class="upload-demo" class="upload-demo"
:action="uploadUrl" :action="uploadUrl"
:show-file-list="false" :show-file-list="false"
:limit="1"
:on-success="handleAvatarSuccess" :on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload" :before-upload="beforeAvatarUpload"
> >
@@ -331,11 +330,11 @@ export default {
const index = file.name.lastIndexOf('.') const index = file.name.lastIndexOf('.')
const ext = file.name.substr(index + 1) const ext = file.name.substr(index + 1)
const isJPG = (file.type === 'image/jpeg' || file.type === 'image/png'); const isJPG = (file.type === 'image/jpeg' || file.type === 'image/png');
const isType = (ext === 'jpeg' || ext === 'jpg' || ext === 'png') const isType = (ext === 'jpg' || ext === 'png')
const isLt2M = file.size / 1024 / 1024 < 2; const isLt2M = file.size / 1024 / 1024 < 2;
if (!isJPG || !isType) { if (!isJPG || !isType) {
this.$message.error('上传头像图片只能是 .jpg、.jpeg、.png 格式!'); this.$message.error('上传头像图片只能是 .jpg、.png 格式!');
} }
if (!isLt2M) { if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 2MB!'); this.$message.error('上传头像图片大小不能超过 2MB!');
@@ -445,12 +444,16 @@ export default {
_this: this, _this: this,
loading: 'Loading' loading: 'Loading'
}, res => { }, res => {
this.Loading = true
this.linkList = res.data this.linkList = res.data
res.data.forEach(item => { res.data.forEach(item => {
if (item.type === 1) { if (item.type === 1) {
this.linkListFirst.push(item) this.linkListFirst.push(item)
} }
}) })
if (this.linkListFirst.length === 0) {
this.Loading = false
}
this.linkListFirst.forEach(item => { this.linkListFirst.forEach(item => {
if (item.icon !== '') { if (item.icon !== '') {
let imgId = { let imgId = {
@@ -466,6 +469,7 @@ export default {
) )
item.icon = src item.icon = src
}) })
this.Loading = false
} }
}) })
this.initSortable() this.initSortable()
@@ -127,7 +127,6 @@
class="avatar-uploader" class="avatar-uploader"
:action="uploadUrl" :action="uploadUrl"
:show-file-list="false" :show-file-list="false"
:limit="1"
:on-success="handleAvatarSuccess" :on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload"> :before-upload="beforeAvatarUpload">
<img v-if="imageUrl" :src="imageUrl" class="avatar"> <img v-if="imageUrl" :src="imageUrl" class="avatar">
@@ -443,12 +442,16 @@ export default {
_this: this, _this: this,
loading: 'Loading' loading: 'Loading'
}, res => { }, res => {
this.Loading = true
this.linkList = res.data this.linkList = res.data
res.data.forEach(item => { res.data.forEach(item => {
if (item.type === 2) { if (item.type === 2) {
this.linkListSecond.push(item) this.linkListSecond.push(item)
} }
}) })
if (this.linkListSecond.length === 0) {
this.Loading = false
}
this.linkListSecond.forEach(item => { this.linkListSecond.forEach(item => {
if (item.icon !== '') { if (item.icon !== '') {
let imgId = { let imgId = {
@@ -456,16 +459,15 @@ export default {
} }
// 图片转base64 // 图片转base64
getImg(imgId).then(res => { getImg(imgId).then(res => {
if (res.ok) { const src =
const src = "data:image/png;base64," +
"data:image/png;base64," + btoa(
btoa( new Uint8Array(res).reduce(
new Uint8Array(res).reduce( (data, byte) => data + String.fromCharCode(byte), "")
(data, byte) => data + String.fromCharCode(byte), "") )
) item.icon = src
item.icon = src
}
}) })
this.Loading = false
} }
}) })
this.initSortable() this.initSortable()