download data record

This commit is contained in:
CPunisher 2020-05-08 00:45:24 +08:00
parent 616b1cd547
commit f9f5ceb28b
5 changed files with 174 additions and 5 deletions

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<file url="file://$PROJECT_DIR$" libraries="{qrbtf/node_modules}" />
<file url="PROJECT" libraries="{qrbtf/node_modules}" />
</component>
</project>

119
package-lock.json generated
View File

@ -1071,6 +1071,22 @@
"to-fast-properties": "^2.0.0"
}
},
"@cloudbase/adapter-interface": {
"version": "0.4.0",
"resolved": "https://registry.npm.taobao.org/@cloudbase/adapter-interface/download/@cloudbase/adapter-interface-0.4.0.tgz",
"integrity": "sha1-xXk1tQPnv6zksVHfY6h9xWSumQc="
},
"@cloudbase/database": {
"version": "0.9.11-rc.0",
"resolved": "https://registry.npm.taobao.org/@cloudbase/database/download/@cloudbase/database-0.9.11-rc.0.tgz",
"integrity": "sha1-ev1zOIzpzmct1bbZTm5XCNmRQ70=",
"requires": {
"bson": "^4.0.2",
"lodash.clonedeep": "4.5.0",
"lodash.set": "4.3.2",
"lodash.unset": "4.5.2"
}
},
"@cnakazawa/watch": {
"version": "1.0.4",
"resolved": "https://registry.npm.taobao.org/@cnakazawa/watch/download/@cnakazawa/watch-1.0.4.tgz",
@ -2384,6 +2400,37 @@
"resolved": "https://registry.npm.taobao.org/aws4/download/aws4-1.9.1.tgz?cache=0&sync_timestamp=1578959055063&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Faws4%2Fdownload%2Faws4-1.9.1.tgz",
"integrity": "sha1-fjPY99RJs/ZzzXLeuavcVS2+Uo4="
},
"axios": {
"version": "0.19.2",
"resolved": "https://registry.npm.taobao.org/axios/download/axios-0.19.2.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Faxios%2Fdownload%2Faxios-0.19.2.tgz",
"integrity": "sha1-PqNsXYgY0NX4qKl6bTa4bNwAyyc=",
"requires": {
"follow-redirects": "1.5.10"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npm.taobao.org/debug/download/debug-3.1.0.tgz",
"integrity": "sha1-W7WgZyYotkFJVmuhaBnmFRjGcmE=",
"requires": {
"ms": "2.0.0"
}
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npm.taobao.org/follow-redirects/download/follow-redirects-1.5.10.tgz?cache=0&sync_timestamp=1585479417937&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ffollow-redirects%2Fdownload%2Ffollow-redirects-1.5.10.tgz",
"integrity": "sha1-e3qfmuov3/NnhqlP9kPtB/T/Xio=",
"requires": {
"debug": "=3.1.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/ms/download/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
}
},
"axobject-query": {
"version": "2.1.2",
"resolved": "https://registry.npm.taobao.org/axobject-query/download/axobject-query-2.1.2.tgz",
@ -3099,6 +3146,26 @@
"node-int64": "^0.4.0"
}
},
"bson": {
"version": "4.0.4",
"resolved": "https://registry.npm.taobao.org/bson/download/bson-4.0.4.tgz",
"integrity": "sha1-S9os7fKuehjRXLJO4e3ox5f47s8=",
"requires": {
"buffer": "^5.1.0",
"long": "^4.0.0"
},
"dependencies": {
"buffer": {
"version": "5.6.0",
"resolved": "https://registry.npm.taobao.org/buffer/download/buffer-5.6.0.tgz?cache=0&sync_timestamp=1588706716358&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbuffer%2Fdownload%2Fbuffer-5.6.0.tgz",
"integrity": "sha1-oxdJ3H2B2E2wir+Te2uMQDP2J4Y=",
"requires": {
"base64-js": "^1.0.2",
"ieee754": "^1.1.4"
}
}
}
},
"buffer": {
"version": "4.9.2",
"resolved": "https://registry.npm.taobao.org/buffer/download/buffer-4.9.2.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbuffer%2Fdownload%2Fbuffer-4.9.2.tgz",
@ -3452,6 +3519,14 @@
"shallow-clone": "^0.1.2"
}
},
"cloudbase-adapter-wx_mp": {
"version": "0.1.1",
"resolved": "https://registry.npm.taobao.org/cloudbase-adapter-wx_mp/download/cloudbase-adapter-wx_mp-0.1.1.tgz",
"integrity": "sha1-J1DtgUX4IWhB0lu7XWubSiFLhDg=",
"requires": {
"@cloudbase/adapter-interface": "^0.4.0"
}
},
"co": {
"version": "4.6.0",
"resolved": "https://registry.npm.taobao.org/co/download/co-4.6.0.tgz",
@ -3812,6 +3887,11 @@
"randomfill": "^1.0.3"
}
},
"crypto-js": {
"version": "3.3.0",
"resolved": "https://registry.npm.taobao.org/crypto-js/download/crypto-js-3.3.0.tgz?cache=0&sync_timestamp=1581508591511&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcrypto-js%2Fdownload%2Fcrypto-js-3.3.0.tgz",
"integrity": "sha1-hG3RzOL2iqz6FWyFePkmpgm3l2s="
},
"css": {
"version": "2.2.4",
"resolved": "https://registry.npm.taobao.org/css/download/css-2.2.4.tgz",
@ -5565,6 +5645,11 @@
"locate-path": "^2.0.0"
}
},
"fingerprintjs2": {
"version": "2.1.0",
"resolved": "https://registry.npm.taobao.org/fingerprintjs2/download/fingerprintjs2-2.1.0.tgz",
"integrity": "sha1-Idw/7ifTsZkFbvjrhz3rzNjgYyM="
},
"flat-cache": {
"version": "2.0.1",
"resolved": "https://registry.npm.taobao.org/flat-cache/download/flat-cache-2.0.1.tgz",
@ -8164,11 +8249,21 @@
"resolved": "https://registry.npm.taobao.org/lodash._reinterpolate/download/lodash._reinterpolate-3.0.0.tgz",
"integrity": "sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0="
},
"lodash.clonedeep": {
"version": "4.5.0",
"resolved": "https://registry.npm.taobao.org/lodash.clonedeep/download/lodash.clonedeep-4.5.0.tgz",
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
},
"lodash.memoize": {
"version": "4.1.2",
"resolved": "https://registry.npm.taobao.org/lodash.memoize/download/lodash.memoize-4.1.2.tgz",
"integrity": "sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4="
},
"lodash.set": {
"version": "4.3.2",
"resolved": "https://registry.npm.taobao.org/lodash.set/download/lodash.set-4.3.2.tgz",
"integrity": "sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM="
},
"lodash.sortby": {
"version": "4.7.0",
"resolved": "https://registry.npm.taobao.org/lodash.sortby/download/lodash.sortby-4.7.0.tgz",
@ -8196,11 +8291,21 @@
"resolved": "https://registry.npm.taobao.org/lodash.uniq/download/lodash.uniq-4.5.0.tgz",
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M="
},
"lodash.unset": {
"version": "4.5.2",
"resolved": "https://registry.npm.taobao.org/lodash.unset/download/lodash.unset-4.5.2.tgz",
"integrity": "sha1-Nw0dPoW3Kn4bDN8tJyEhMG8j5O0="
},
"loglevel": {
"version": "1.6.8",
"resolved": "https://registry.npm.taobao.org/loglevel/download/loglevel-1.6.8.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Floglevel%2Fdownload%2Floglevel-1.6.8.tgz",
"integrity": "sha1-iiX7ddCSIw7NRFcnDYC1TigBEXE="
},
"long": {
"version": "4.0.0",
"resolved": "https://registry.npm.taobao.org/long/download/long-4.0.0.tgz",
"integrity": "sha1-mntxz7fTYaGU6lVSQckvdGjVvyg="
},
"loose-envify": {
"version": "1.4.0",
"resolved": "https://registry.npm.taobao.org/loose-envify/download/loose-envify-1.4.0.tgz",
@ -12569,6 +12674,20 @@
"resolved": "https://registry.npm.taobao.org/tapable/download/tapable-1.1.3.tgz",
"integrity": "sha1-ofzMBrWNth/XpF2i2kT186Pme6I="
},
"tcb-js-sdk": {
"version": "1.6.1",
"resolved": "https://registry.npm.taobao.org/tcb-js-sdk/download/tcb-js-sdk-1.6.1.tgz",
"integrity": "sha1-jaLnrtwR+iNYqtrr2YcSg4shFUM=",
"requires": {
"@cloudbase/adapter-interface": "^0.4.0",
"@cloudbase/database": "0.9.11-rc.0",
"axios": "^0.19.1",
"cloudbase-adapter-wx_mp": "^0.1.0",
"crypto-js": "^3.1.9-1",
"fingerprintjs2": "^2.1.0",
"url": "^0.11.0"
}
},
"terser": {
"version": "4.6.12",
"resolved": "https://registry.npm.taobao.org/terser/download/terser-4.6.12.tgz?cache=0&sync_timestamp=1587902079221&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fterser%2Fdownload%2Fterser-4.6.12.tgz",

View File

@ -8,7 +8,8 @@
"@testing-library/user-event": "^7.1.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
"react-scripts": "3.4.1",
"tcb-js-sdk": "^1.6.1"
},
"scripts": {
"start": "react-scripts start",

37
src/api/db.js Normal file
View File

@ -0,0 +1,37 @@
import * as tcb from 'tcb-js-sdk';
const app = tcb.init({
env: 'qrbtf-1d845d'
});
const auth = app.auth();
async function login() {
await auth.signInAnonymously();
const loginState = await auth.getLoginState()
console.log(loginState.isAnonymous);
}
login();
const db = app.database();
const _ = db.command
const counter = db.collection('QRCounter');
export function insert(value) {
counter.add({
value: value,
count: 1
}).then(res => {
console.log(res);
})
}
export function update(value) {
counter.where({
value: _.eq(value)
}).update({
count: _.inc(1)
}).then(res => {
console.log(res)
})
}

View File

@ -1,3 +1,5 @@
import {insert, update} from "../api/db";
const svgHead = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n " +
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
@ -5,21 +7,23 @@ export function isChrome() {
return navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
}
export function saveSvg(filename, content) {
export function saveSvg(value, content) {
let htmlContent = [svgHead + content]
let bl = new Blob(htmlContent, {type: "image/svg+xml"})
let a = document.createElement("a")
filename = "QRcode_" + filename + ".svg"
let filename = "QRcode_" + value + ".svg"
a.href = URL.createObjectURL(bl)
a.download = filename
a.hidden = true
a.click()
update(value)
}
export function saveImg(filename, content, width, height) {
export function saveImg(value, content, width, height) {
// Finish creating downloadable data
filename = "QRcode_" + filename + ".jpg";
let filename = "QRcode_" + value + ".jpg";
const wrap = document.createElement('div');
wrap.innerHTML = content;
@ -56,6 +60,7 @@ export function saveImg(filename, content, width, height) {
a.setAttribute('target', 'download')
a.setAttribute('download', filename);
a.click();
update(value)
};
img.setAttribute('src', 'data:image/svg+xml;base64,' + btoa(svgData));