From a4e53ef9b9cdb6a8fca2aa69c72a9a22793429cc Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Fri, 22 May 2020 18:31:41 +0800 Subject: [PATCH 1/3] download test --- src/api/db.js | 2 +- src/utils/downloader.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/db.js b/src/api/db.js index a579d6a..698e161 100644 --- a/src/api/db.js +++ b/src/api/db.js @@ -12,7 +12,7 @@ const _ = db.command export async function login() { await auth.signInAnonymously(); const loginState = await auth.getLoginState(); - isLogin = loginState + isLogin = loginState; } export function getDownloadCount(callback) { diff --git a/src/utils/downloader.js b/src/utils/downloader.js index 67a5fec..39d0fa8 100644 --- a/src/utils/downloader.js +++ b/src/utils/downloader.js @@ -10,7 +10,7 @@ export function saveSvg(value, content) { a.href = URL.createObjectURL(bl) a.download = filename a.hidden = true - a.click() + // a.click() } export function saveImg(value, content, width, height) { @@ -51,8 +51,8 @@ export function saveImg(value, content, width, height) { let data = canvas.toDataURL('image/jpeg', 0.8); a.setAttribute('href', data) a.setAttribute('target', 'download') - a.setAttribute('download', filename); - a.click(); + // a.setAttribute('download', filename); + // a.click(); resolve(data) }; From ec2090567bcb42e9efe6a66c25eb910c5c695712 Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Fri, 22 May 2020 19:20:05 +0800 Subject: [PATCH 2/3] download test --- src/utils/downloader.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/downloader.js b/src/utils/downloader.js index 39d0fa8..67a5fec 100644 --- a/src/utils/downloader.js +++ b/src/utils/downloader.js @@ -10,7 +10,7 @@ export function saveSvg(value, content) { a.href = URL.createObjectURL(bl) a.download = filename a.hidden = true - // a.click() + a.click() } export function saveImg(value, content, width, height) { @@ -51,8 +51,8 @@ export function saveImg(value, content, width, height) { let data = canvas.toDataURL('image/jpeg', 0.8); a.setAttribute('href', data) a.setAttribute('target', 'download') - // a.setAttribute('download', filename); - // a.click(); + a.setAttribute('download', filename); + a.click(); resolve(data) }; From e42d8945d05e7c230fce37d2b6a896381c9edba2 Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Fri, 22 May 2020 22:17:26 +0800 Subject: [PATCH 3/3] ios download --- src/api/db.js | 6 ++- src/containers/app/PartDownloadViewer.js | 59 ++++++++++++++---------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/api/db.js b/src/api/db.js index 698e161..0c914b1 100644 --- a/src/api/db.js +++ b/src/api/db.js @@ -49,7 +49,7 @@ export function increaseDownloadData(value, callback) { }) } -export function recordDownloadDetail({text, value, type, params, history}) { +export function recordDownloadDetail({text, value, type, params, history}, callback) { if (!isLogin) return; db.collection('QRDownloadData').add({ date: new Date().toString(), @@ -58,5 +58,7 @@ export function recordDownloadDetail({text, value, type, params, history}) { type: type, params: params, history: history - }).catch(console.error) + }).then(res => { + if (callback) callback(res); + }).catch(console.error); } diff --git a/src/containers/app/PartDownloadViewer.js b/src/containers/app/PartDownloadViewer.js index 135aeb3..d8a3d6f 100644 --- a/src/containers/app/PartDownloadViewer.js +++ b/src/containers/app/PartDownloadViewer.js @@ -5,42 +5,51 @@ import {getDownloadCount, increaseDownloadData, recordDownloadDetail} from "../. import {getParamDetailedValue, outerHtml} from "../../utils/util"; function saveDB(state, type, updateDownloadData) { - increaseDownloadData(state.value, () => { - getDownloadCount((res) => { - let downloadData = []; - res.data.forEach((item) => { - downloadData[item.value] = item.count; + return new Promise(resolve => { + increaseDownloadData(state.value, () => { + recordDownloadDetail({ + text: state.textUrl, + value: state.value, + type: type, + params: state.paramInfo[state.selectedIndex].map((item, index) => { + const value = getParamDetailedValue(item, state.paramValue[state.selectedIndex][index]) + if (typeof value != "string" || value.length <= 128) { + return { + key: item.key, + value: value + } + } + }), + history: state.history + }, () => { + getDownloadCount((res) => { + let downloadData = []; + res.data.forEach((item) => { + downloadData[item.value] = item.count; + }); + updateDownloadData(downloadData); + resolve() + }); }); - updateDownloadData(downloadData); }); }); - recordDownloadDetail({ - text: state.textUrl, - value: state.value, - type: type, - params: state.paramInfo[state.selectedIndex].map((item, index) => { - const value = getParamDetailedValue(item, state.paramValue[state.selectedIndex][index]) - if (typeof value != "string" || value.length <= 128) { - return { - key: item.key, - value: value - } - } - }), - history: state.history - }); } const mapStateToProps = (state, ownProps) => ({ value: state.value, downloadCount: state.downloadData[state.value], onSvgDownload: () => { - saveSvg(state.value, outerHtml(state.selectedIndex)) - saveDB(state, 'svg', ownProps.updateDownloadData) + saveSvg(state.value, outerHtml(state.selectedIndex)); + saveDB(state, 'svg', ownProps.updateDownloadData); }, onJpgDownload: () => { - saveDB(state, 'jpg', ownProps.updateDownloadData) - return saveImg(state.value, outerHtml(state.selectedIndex), 1500, 1500) + return new Promise(resolve => { + saveImg(state.value, outerHtml(state.selectedIndex), 1500, 1500).then((res) => { + saveDB(state, 'jpg', ownProps.updateDownloadData).then(() => { + resolve(res) + }); + }); + }); } })