提交 ae48e33b 编写于 作者: B baiy 提交者: ninecents

base64支持对文件编码和解码 #59

上级 dba64a83
......@@ -2101,9 +2101,9 @@
"dev": true
},
"async-validator": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/async-validator/-/async-validator-3.5.1.tgz",
"integrity": "sha512-DDmKA7sdSAJtTVeNZHrnr2yojfFaoeW8MfQN8CeuXg8DDQHTqKk9Fdv38dSvnesHoO8MUwMI2HphOeSyIF+wmQ=="
"version": "3.5.2",
"resolved": "https://registry.npmjs.org/async-validator/-/async-validator-3.5.2.tgz",
"integrity": "sha512-8eLCg00W9pIRZSB781UUX/H6Oskmm8xloZfr09lz5bikRpBVDlJ3hRVuxxP1SxcwsEYfJ4IU8Q19Y8/893r3rQ=="
},
"asynckit": {
"version": "0.4.0",
......@@ -3669,9 +3669,9 @@
}
},
"cronstrue": {
"version": "1.112.0",
"resolved": "https://registry.npmjs.org/cronstrue/-/cronstrue-1.112.0.tgz",
"integrity": "sha512-sVw7RKaOm4l3DRGeOXpdxDKL5qcFrKy9diZHob/kie14OYuOV3uCxAthb56OOf/M2u+FCYPiBMYhZuFibuxwMQ=="
"version": "1.114.0",
"resolved": "https://registry.npmjs.org/cronstrue/-/cronstrue-1.114.0.tgz",
"integrity": "sha512-j1JuBHTJKKX41NUJVHmWn2ZYHnLipsIoq7bAZVeVzehA9+rmG6v9NgMiMa0KiiFzozihgt4yGNe5aMVc/IoYLg=="
},
"cross-spawn": {
"version": "6.0.5",
......@@ -4459,9 +4459,9 @@
"dev": true
},
"element-resize-detector": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/element-resize-detector/-/element-resize-detector-1.2.2.tgz",
"integrity": "sha512-+LOXRkCJc4I5WhEJxIDjhmE3raF8jtOMBDqSCgZTMz2TX3oXAX5pE2+MDeopJlGdXzP7KzPbBJaUGfNaP9HG4A==",
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/element-resize-detector/-/element-resize-detector-1.2.3.tgz",
"integrity": "sha512-+dhNzUgLpq9ol5tyhoG7YLoXL3ssjfFW+0gpszXPwRU6NjGr1fVHMEAF8fVzIiRJq57Nre0RFeIjJwI8Nh2NmQ==",
"requires": {
"batch-processor": "1.0.0"
}
......@@ -7455,12 +7455,18 @@
"dev": true
},
"mime-types": {
"version": "2.1.30",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.30.tgz",
"integrity": "sha512-crmjA4bLtR8m9qLpHvgxSChT+XoSlZi8J4n/aIdn3z92e/U47Z0V/yl+Wh9W046GgFVAmoNR/fmdbZYcSSIUeg==",
"dev": true,
"version": "2.1.32",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz",
"integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==",
"requires": {
"mime-db": "1.47.0"
"mime-db": "1.49.0"
},
"dependencies": {
"mime-db": {
"version": "1.49.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz",
"integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA=="
}
}
},
"mimic-fn": {
......@@ -8425,11 +8431,11 @@
"dev": true
},
"php-array-reader": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/php-array-reader/-/php-array-reader-1.2.0.tgz",
"integrity": "sha512-l8eo0tt3lrDwrIKCMtWQBKq83zrYK0Yb31NRv1MFhUPKRMvVQKww+Ga0rdiot2W5izc96EcZJhsv44il4WPs0Q==",
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/php-array-reader/-/php-array-reader-1.3.0.tgz",
"integrity": "sha512-mTWGcWL7U0R6AkR0OYTxJXkvVGDaoIQC0rTa5ljxWoL8bG4nlRXG0hqIsORKXFfTQDqC76ei7qw/sjwoZ/ACyg==",
"requires": {
"php-parser": "^3.0.0-prerelease.8"
"php-parser": "^3.0.3"
}
},
"php-parser": {
......@@ -11877,9 +11883,9 @@
}
},
"view-design": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/view-design/-/view-design-4.5.0.tgz",
"integrity": "sha512-0VL4YAlJ/IqEL6on0buUuTd9awjCqkqWrre3A42LXcrIn+fV69dYvQVyP/ukBOn9dOTfUMCgpiQnxBKFZQXVbQ==",
"version": "4.6.1",
"resolved": "https://registry.npmjs.org/view-design/-/view-design-4.6.1.tgz",
"integrity": "sha512-0pc9j8SEmmSWa/GGRM3H3T9WdEQ7IJHr2AMKJAIsW/1ft4glwhhuRN/lXDR11jHz/6g4nRZwzlneIbc0SpGFdQ==",
"requires": {
"async-validator": "^3.3.0",
"deepmerge": "^2.2.1",
......@@ -11898,9 +11904,9 @@
"dev": true
},
"vue": {
"version": "2.6.12",
"resolved": "https://registry.npmjs.org/vue/-/vue-2.6.12.tgz",
"integrity": "sha512-uhmLFETqPPNyuLLbsKz6ioJ4q7AZHzD8ZVFNATNyICSZouqP2Sz0rotWQC8UNBF6VGSCs5abnKJoStA6JbCbfg=="
"version": "2.6.14",
"resolved": "https://registry.npmjs.org/vue/-/vue-2.6.14.tgz",
"integrity": "sha512-x2284lgYvjOMj3Za7kqzRcUSxBboHqtgRE2zlos1qWaOye5yUmHn42LB1250NJBLRwEcdrB0JRwyPTEPhfQjiQ=="
},
"vue-cli-plugin-iview": {
"version": "1.0.6",
......@@ -11964,9 +11970,9 @@
}
},
"vue-router": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.5.1.tgz",
"integrity": "sha512-RRQNLT8Mzr8z7eL4p7BtKvRaTSGdCbTy2+Mm5HTJvLGYSSeG9gDzNasJPP/yOYKLy+/cLG/ftrqq5fvkFwBJEw=="
"version": "3.5.2",
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.5.2.tgz",
"integrity": "sha512-807gn82hTnjCYGrnF3eNmIw/dk7/GE4B5h69BlyCK9KHASwSloD1Sjcn06zg9fVG4fYH2DrsNBZkpLtb25WtaQ=="
},
"vue-style-loader": {
"version": "4.1.3",
......@@ -11979,9 +11985,9 @@
}
},
"vue-template-compiler": {
"version": "2.6.12",
"resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.6.12.tgz",
"integrity": "sha512-OzzZ52zS41YUbkCBfdXShQTe69j1gQDZ9HIX8miuC9C3rBCk9wIRjLiZZLrmX9V+Ftq/YEyv1JaVr5Y/hNtByg==",
"version": "2.6.14",
"resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.6.14.tgz",
"integrity": "sha512-ODQS1SyMbjKoO1JBJZojSw6FE4qnh9rIpUZn2EUT86FKizx9uH5z6uXiIrm4/Nb/gwxTi/o17ZDEGWAXHvtC7g==",
"dev": true,
"requires": {
"de-indent": "^1.0.2",
......@@ -12648,8 +12654,8 @@
}
},
"x2js": {
"version": "git+ssh://git@github.com/abdolence/x2js.git#185e410b3fa621070fea1f86a389b477afa216b9",
"from": "x2js@github:abdolence/x2js"
"version": "github:abdolence/x2js#185e410b3fa621070fea1f86a389b477afa216b9",
"from": "github:abdolence/x2js"
},
"xml-formatter": {
"version": "2.4.0",
......
{
"name": "c-tool",
"version": "1.6.2",
"version": "1.6.3",
"private": true,
"scripts": {
"serve": "vue-cli-service serve --port 8081",
......@@ -12,7 +12,7 @@
"babel-runtime": "^6.26.0",
"code-formatter": "0.0.1",
"cron-parser": "^2.16.3",
"cronstrue": "^1.100.0",
"cronstrue": "^1.114.0",
"crypto-js": "^3.3.0",
"diff": "^4.0.2",
"file": "^0.2.2",
......@@ -26,8 +26,9 @@
"jwt-decode": "^3.1.2",
"lodash": "^4.17.21",
"lscache": "^1.3.0",
"mime-types": "^2.1.32",
"moment": "^2.29.1",
"php-array-reader": "^1.2.0",
"php-array-reader": "^1.3.0",
"phparr": "^0.2.0",
"properties-to-json": "^0.1.7",
"qrcode": "^1.4.4",
......@@ -38,10 +39,10 @@
"sm-crypto": "^0.1.4",
"system": "^2.0.1",
"uuid": "^8.3.2",
"view-design": "^4.3.2",
"vue": "^2.6.12",
"view-design": "^4.6.1",
"vue": "^2.6.14",
"vue-codemirror": "^4.0.6",
"vue-router": "^3.4.3",
"vue-router": "^3.5.2",
"x2js": "github:abdolence/x2js",
"xml-formatter": "^2.4.0"
},
......@@ -55,7 +56,7 @@
"less": "^2.7.3",
"less-loader": "^5.0.0",
"vue-cli-plugin-iview": "^1.0.6",
"vue-template-compiler": "^2.6.12"
"vue-template-compiler": "^2.6.14"
},
"eslintConfig": {
"root": true,
......
......@@ -5,42 +5,74 @@
<FormItem>
<ButtonGroup>
<Button type="primary" @click="handle('encode')">编码</Button>
<Button type="primary" @click="handle('decode')"></Button>
<Button type="primary" @click="handle('decode')"></Button>
</ButtonGroup>
</FormItem>
<FormItem>
<Checkbox v-model="current.isUriSafe">Url Safe</Checkbox>
</FormItem>
<FormItem style="float: right;">
<Upload action="#" :before-upload="handleUpload">
<Button type="primary" icon="md-arrow-round-up">上传文件</Button>
</Upload>
</FormItem>
</option-block>
<Input v-model="current.output" :rows="7" type="textarea" placeholder="结果"></Input>
</div>
</template>
<script>
import { Base64 } from 'js-base64'
import {Base64} from 'js-base64'
import mimeType from 'mime-types'
import moment from "moment";
export default {
created () {
created() {
this.current = Object.assign(this.current, this.$getToolData('input'))
},
methods: {
handle (v) {
handle(v) {
if (this.current.input) {
if (v === "encode"){
this.current.output = Base64.encode(this.current.input,this.current.isUriSafe)
}
else{
this.current.output = Base64.decode(this.current.input)
if (v === "encode") {
this.current.output = Base64.encode(this.current.input, this.current.isUriSafe)
} else {
if (this.current.input.indexOf(',') !== -1) {
// 文件 base64 内容
this.exportFile();
}
else{
this.current.output = Base64.decode(this.current.input)
}
}
this.current.operation = v
this.$clipboardCopy(this.current.output)
this.$saveToolData(this.current)
console.log(this.current)
}
},
handleUpload(file) {
let r = new FileReader()
r.readAsDataURL(file)
r.onloadend = () => {
this.current.output = r.result
}
return false
},
exportFile() {
let arr = this.current.input.split(','), mime = arr[0].match(/:(.*?);/)[1];
let objectUrl = window.URL.createObjectURL(new Blob([new Blob([Base64.toUint8Array(arr[1])], {type: mime})], {type: mime}));
let aEle = document.createElement("a");
aEle.download = `ctools-base64-decode-${moment().unix()}` + (mimeType.extension(mime) ? `.${mimeType.extension(mime)}` : "");
aEle.href = objectUrl;
aEle.click();
aEle.remove();
window.URL.revokeObjectURL(objectUrl);
}
},
data () {
data() {
return {
current: {
input: '',
isFile: false,
output: '',
operation: '',
isUriSafe: false,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册