图片更新需重新下载

This commit is contained in:
CPPAlien 2019-11-26 12:04:26 +08:00
parent 6dc9e69fa1
commit f7d4bcc5d9
2 changed files with 32 additions and 7 deletions

View File

@ -40,6 +40,24 @@ export default class Dowloader {
resolve(url); resolve(url);
return; return;
} }
if (!lru) {
// 无 lru 情况下直接判断 临时文件是否存在,不存在重新下载
wx.getFileInfo({
filePath: url,
success: () => {
resolve(url);
},
fail: () => {
downloadFile(url, lru).then((path) => {
resolve(path);
}, () => {
reject();
});
},
})
return
}
const file = getFile(url); const file = getFile(url);
if (file) { if (file) {
@ -79,7 +97,9 @@ function downloadFile(url, lru) {
reject(); reject();
return; return;
} }
const { tempFilePath } = res; const {
tempFilePath
} = res;
wx.getFileInfo({ wx.getFileInfo({
filePath: tempFilePath, filePath: tempFilePath,
success: (tmpRes) => { success: (tmpRes) => {
@ -93,7 +113,7 @@ function downloadFile(url, lru) {
}) : resolve(tempFilePath); }) : resolve(tempFilePath);
}, },
fail: (error) => { fail: (error) => {
// 文件大小信息获取失败,则此文件也不要进行存储 // 文件大小信息获取失败,则此文件也不要进行存储
console.error(`getFileInfo ${res.tempFilePath} failed, ${JSON.stringify(error)}`); console.error(`getFileInfo ${res.tempFilePath} failed, ${JSON.stringify(error)}`);
resolve(res.tempFilePath); resolve(res.tempFilePath);
}, },
@ -186,7 +206,7 @@ function doLru(size) {
key: SAVED_FILES_KEY, key: SAVED_FILES_KEY,
data: savedFiles, data: savedFiles,
success: () => { success: () => {
// 保证 storage 中不会存在不存在的文件数据 // 保证 storage 中不会存在不存在的文件数据
if (pathsShouldDelete.length > 0) { if (pathsShouldDelete.length > 0) {
removeFiles(pathsShouldDelete); removeFiles(pathsShouldDelete);
} }
@ -225,4 +245,4 @@ function getFile(key) {
data: savedFiles, data: savedFiles,
}); });
return savedFiles[key]; return savedFiles[key];
} }

View File

@ -234,11 +234,16 @@ Component({
downloader.download(newVal.url, this.properties.LRU).then((path) => { downloader.download(newVal.url, this.properties.LRU).then((path) => {
doView.originUrl = doView.url doView.originUrl = doView.url
doView.url = path doView.url = path
this.reDraw(doView, callback, isMoving)
}) })
}; } else {
(newVal && newVal.text && doView.text && newVal.text !== doView.text) && (doView.text = newVal.text); (newVal && newVal.text && doView.text && newVal.text !== doView.text) && (doView.text = newVal.text);
(newVal && newVal.content && doView.content && newVal.content !== doView.content) && (doView.content = newVal.content); (newVal && newVal.content && doView.content && newVal.content !== doView.content) && (doView.content = newVal.content);
this.reDraw(doView, callback, isMoving)
}
},
reDraw(doView, callback, isMoving) {
const draw = { const draw = {
width: this.currentPalette.width, width: this.currentPalette.width,
height: this.currentPalette.height, height: this.currentPalette.height,