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