暴露 LRU 开关
This commit is contained in:
parent
ddffc34276
commit
27cf1635f7
@ -34,7 +34,7 @@ export default class Dowloader {
|
||||
* 下载文件,会用 lru 方式来缓存文件到本地
|
||||
* @param {String} url 文件的 url
|
||||
*/
|
||||
download(url) {
|
||||
download(url, lru) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!(url && util.isValidUrl(url))) {
|
||||
resolve(url);
|
||||
@ -51,7 +51,7 @@ export default class Dowloader {
|
||||
},
|
||||
fail: (error) => {
|
||||
console.error(`the file is broken, redownload it, ${JSON.stringify(error)}`);
|
||||
downloadFile(url).then((path) => {
|
||||
downloadFile(url, lru).then((path) => {
|
||||
resolve(path);
|
||||
}, () => {
|
||||
reject();
|
||||
@ -59,7 +59,7 @@ export default class Dowloader {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
downloadFile(url).then((path) => {
|
||||
downloadFile(url, lru).then((path) => {
|
||||
resolve(path);
|
||||
}, () => {
|
||||
reject();
|
||||
@ -69,7 +69,7 @@ export default class Dowloader {
|
||||
}
|
||||
}
|
||||
|
||||
function downloadFile(url) {
|
||||
function downloadFile(url, lru) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.downloadFile({
|
||||
url: url,
|
||||
@ -84,13 +84,13 @@ function downloadFile(url) {
|
||||
filePath: tempFilePath,
|
||||
success: (tmpRes) => {
|
||||
const newFileSize = tmpRes.size;
|
||||
doLru(newFileSize).then(() => {
|
||||
lru ? doLru(newFileSize).then(() => {
|
||||
saveFile(url, newFileSize, tempFilePath).then((filePath) => {
|
||||
resolve(filePath);
|
||||
});
|
||||
}, () => {
|
||||
resolve(tempFilePath);
|
||||
});
|
||||
}) : resolve(tempFilePath);
|
||||
},
|
||||
fail: (error) => {
|
||||
// 文件大小信息获取失败,则此文件也不要进行存储
|
||||
|
||||
15
painter.js
15
painter.js
@ -52,6 +52,10 @@ Component({
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
LRU: {
|
||||
type: Boolean,
|
||||
value: true,
|
||||
},
|
||||
action: {
|
||||
type: Object,
|
||||
observer: function (newVal, oldVal) {
|
||||
@ -226,7 +230,12 @@ Component({
|
||||
doView.css = Object.assign({}, doView.css, newVal.css)
|
||||
}
|
||||
}
|
||||
(newVal && newVal.url && doView.url && newVal.url !== doView.url) && (doView.url = newVal.url);
|
||||
if (newVal && newVal.url && doView.url && newVal.url !== doView.url) {
|
||||
downloader.download(newVal.url, this.properties.LRU).then((path) => {
|
||||
doView.originUrl = doView.url
|
||||
doView.url = path
|
||||
})
|
||||
};
|
||||
(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);
|
||||
|
||||
@ -605,7 +614,7 @@ Component({
|
||||
const paletteCopy = JSON.parse(JSON.stringify(palette));
|
||||
if (paletteCopy.background) {
|
||||
preCount++;
|
||||
downloader.download(paletteCopy.background).then((path) => {
|
||||
downloader.download(paletteCopy.background, this.properties.LRU).then((path) => {
|
||||
paletteCopy.background = path;
|
||||
completeCount++;
|
||||
if (preCount === completeCount) {
|
||||
@ -623,7 +632,7 @@ Component({
|
||||
if (view && view.type === 'image' && view.url) {
|
||||
preCount++;
|
||||
/* eslint-disable no-loop-func */
|
||||
downloader.download(view.url).then((path) => {
|
||||
downloader.download(view.url, this.properties.LRU).then((path) => {
|
||||
view.originUrl = view.url;
|
||||
view.url = path;
|
||||
wx.getImageInfo({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user