diff --git a/lib/downloader.js b/lib/downloader.js index 679fbdb..3f94c98 100644 --- a/lib/downloader.js +++ b/lib/downloader.js @@ -40,6 +40,24 @@ export default class Dowloader { resolve(url); 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); if (file) { @@ -79,7 +97,9 @@ function downloadFile(url, lru) { reject(); return; } - const { tempFilePath } = res; + const { + tempFilePath + } = res; wx.getFileInfo({ filePath: tempFilePath, success: (tmpRes) => { @@ -93,7 +113,7 @@ function downloadFile(url, lru) { }) : resolve(tempFilePath); }, fail: (error) => { - // 文件大小信息获取失败,则此文件也不要进行存储 + // 文件大小信息获取失败,则此文件也不要进行存储 console.error(`getFileInfo ${res.tempFilePath} failed, ${JSON.stringify(error)}`); resolve(res.tempFilePath); }, @@ -186,7 +206,7 @@ function doLru(size) { key: SAVED_FILES_KEY, data: savedFiles, success: () => { - // 保证 storage 中不会存在不存在的文件数据 + // 保证 storage 中不会存在不存在的文件数据 if (pathsShouldDelete.length > 0) { removeFiles(pathsShouldDelete); } @@ -225,4 +245,4 @@ function getFile(key) { data: savedFiles, }); return savedFiles[key]; -} +} \ No newline at end of file diff --git a/painter.js b/painter.js index 33144f7..9bece41 100644 --- a/painter.js +++ b/painter.js @@ -234,11 +234,16 @@ Component({ downloader.download(newVal.url, this.properties.LRU).then((path) => { doView.originUrl = doView.url doView.url = path + this.reDraw(doView, callback, isMoving) }) - }; - (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); + } else { + (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); + this.reDraw(doView, callback, isMoving) + } + }, + reDraw(doView, callback, isMoving) { const draw = { width: this.currentPalette.width, height: this.currentPalette.height,