完成导入账号功能

main
wuyize 2022-07-13 15:44:30 +08:00
parent 4f3d028beb
commit 26e43ae624
3 changed files with 38 additions and 15 deletions

11
package-lock.json generated
View File

@ -15,6 +15,7 @@
"echarts": "^5.3.3", "echarts": "^5.3.3",
"element-plus": "^2.2.6", "element-plus": "^2.2.6",
"moment": "^2.29.1", "moment": "^2.29.1",
"spark-md5": "^3.0.2",
"vue": "^3.0.0", "vue": "^3.0.0",
"vue-router": "^4.0.0-0", "vue-router": "^4.0.0-0",
"vuex": "^4.0.2", "vuex": "^4.0.2",
@ -12665,6 +12666,11 @@
"resolved": "https://registry.npmmirror.com/sourcemap-codec/download/sourcemap-codec-1.4.8.tgz", "resolved": "https://registry.npmmirror.com/sourcemap-codec/download/sourcemap-codec-1.4.8.tgz",
"integrity": "sha1-6oBL2UhXQC5pktBaOO8a41qatMQ=" "integrity": "sha1-6oBL2UhXQC5pktBaOO8a41qatMQ="
}, },
"node_modules/spark-md5": {
"version": "3.0.2",
"resolved": "https://registry.npmmirror.com/spark-md5/-/spark-md5-3.0.2.tgz",
"integrity": "sha512-wcFzz9cDfbuqe0FZzfi2or1sgyIrsDwmPwfZC4hiNidPdPINjeUwNfv5kldczoEAcjl9Y1L3SM7Uz2PUEQzxQw=="
},
"node_modules/spdx-correct": { "node_modules/spdx-correct": {
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmmirror.com/spdx-correct/download/spdx-correct-3.1.1.tgz", "resolved": "https://registry.npmmirror.com/spdx-correct/download/spdx-correct-3.1.1.tgz",
@ -25999,6 +26005,11 @@
"resolved": "https://registry.npmmirror.com/sourcemap-codec/download/sourcemap-codec-1.4.8.tgz", "resolved": "https://registry.npmmirror.com/sourcemap-codec/download/sourcemap-codec-1.4.8.tgz",
"integrity": "sha1-6oBL2UhXQC5pktBaOO8a41qatMQ=" "integrity": "sha1-6oBL2UhXQC5pktBaOO8a41qatMQ="
}, },
"spark-md5": {
"version": "3.0.2",
"resolved": "https://registry.npmmirror.com/spark-md5/-/spark-md5-3.0.2.tgz",
"integrity": "sha512-wcFzz9cDfbuqe0FZzfi2or1sgyIrsDwmPwfZC4hiNidPdPINjeUwNfv5kldczoEAcjl9Y1L3SM7Uz2PUEQzxQw=="
},
"spdx-correct": { "spdx-correct": {
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmmirror.com/spdx-correct/download/spdx-correct-3.1.1.tgz", "resolved": "https://registry.npmmirror.com/spdx-correct/download/spdx-correct-3.1.1.tgz",

View File

@ -14,6 +14,7 @@
"echarts": "^5.3.3", "echarts": "^5.3.3",
"element-plus": "^2.2.6", "element-plus": "^2.2.6",
"moment": "^2.29.1", "moment": "^2.29.1",
"spark-md5": "^3.0.2",
"vue": "^3.0.0", "vue": "^3.0.0",
"vue-router": "^4.0.0-0", "vue-router": "^4.0.0-0",
"vuex": "^4.0.2", "vuex": "^4.0.2",

View File

@ -78,7 +78,7 @@
</div> </div>
<template #tip> <template #tip>
<div class="el-upload__tip"> <div class="el-upload__tip">
<el-link href="https://element.eleme.io" type="primary">下载模板</el-link> <el-link href="https://www.hammer-hfut.tk/api/public/账户导入模板.xlsx" type="primary">下载模板</el-link>
</div> </div>
</template> </template>
</el-upload> </el-upload>
@ -95,7 +95,6 @@ import {UploadFilled} from '@element-plus/icons'
import request from "@/utils/request"; import request from "@/utils/request";
import router from "../router"; import router from "../router";
import {ElMessage} from "element-plus"; import {ElMessage} from "element-plus";
import md5 from 'blueimp-md5'
export default { export default {
name: 'Home', name: 'Home',
@ -126,20 +125,32 @@ export default {
}, },
methods: { methods: {
customUpload(options) { customUpload(options) {
const that = this
let param = new FormData() let param = new FormData()
param.append('fileDigest', md5(options.file)) const fileReader = new FileReader()
param.append('uploadFile', options.file) fileReader.readAsBinaryString(options.file);
request({ fileReader.onload = e => {
url: '/staff/import', console.log(e.target.result)
data: param, let SparkMD5 = require('spark-md5')
method: 'post', param.append('fileDigest', SparkMD5.hashBinary(e.target.result))
onUploadProgress: progressEvent => { param.append('uploadFile', options.file)
progressEvent.percent = progressEvent.loaded / progressEvent.total * 100 | 0 request({
options.onProgress(progressEvent) url: '/staff/import',
} data: param,
}).then((res) => { method: 'post',
console.log(res.data); onUploadProgress: progressEvent => {
}) progressEvent.percent = progressEvent.loaded / progressEvent.total * 100 | 0
options.onProgress(progressEvent)
}
}).then((res) => {
console.log(res.data);
ElMessage({
message: '导入成功',
type: 'success',
})
that.uploadDialogVisible = false
})
}
}, },
getStaffFullname() { getStaffFullname() {
if (this.$store && this.$store.state.staff) if (this.$store && this.$store.state.staff)