Merge branch 'dev-redux' of https://github.com/ciaochaos/qrbtf into dev-redux
This commit is contained in:
commit
0fa1174a9f
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue