Commit b940553e authored by puyongsong's avatar puyongsong

导入数据界面

parent dd7d6fa8
...@@ -14,18 +14,18 @@ function deepClone(source) { ...@@ -14,18 +14,18 @@ function deepClone(source) {
}) })
return targetObj return targetObj
} }
// 加密 // aes加密
function encrypt(word, keyStr) { function encrypt(word, keyStr) {
keyStr = keyStr || 'abcdefgabcdefg12' keyStr = keyStr || 'abcdefgabcdefg12'
var key = CryptoJS.enc.Utf8.parse(keyStr) // Latin1 w8m31+Yy/Nw6thPsMpO5fg== var key = CryptoJS.enc.Utf8.parse(keyStr)
var srcs = CryptoJS.enc.Utf8.parse(word) var srcs = CryptoJS.enc.Utf8.parse(word)
var encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }) var encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
return encrypted.toString() return encrypted.toString()
} }
// 解密 // aes解密
function decrypt(word, keyStr) { function decrypt(word, keyStr) {
keyStr = keyStr || 'abcdefgabcdefg12' keyStr = keyStr || 'abcdefgabcdefg12'
var key = CryptoJS.enc.Utf8.parse(keyStr) // Latin1 w8m31+Yy/Nw6thPsMpO5fg== var key = CryptoJS.enc.Utf8.parse(keyStr)
var decrypt = CryptoJS.AES.decrypt(word, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }) var decrypt = CryptoJS.AES.decrypt(word, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
return CryptoJS.enc.Utf8.stringify(decrypt).toString() return CryptoJS.enc.Utf8.stringify(decrypt).toString()
} }
......
<template> <template>
<div> <div>
<div class="drawer_body_box"> <div class="drawer_body_box">
<el-form ref="importForm" :rules="rules" label-position="left" label-width="90px"> <el-form
ref="importForm"
:rules="rules"
:model="temp"
label-position="left"
label-width="90px"
>
<el-form-item label="文件模板" prop="name"> <el-form-item label="文件模板" prop="name">
<el-button size="small" @click="downloadTemplate">下载模板</el-button> <el-button size="small" @click="downloadTemplate">下载模板</el-button>
<span>请按照模板格式填写数据</span> <span>请按照模板格式填写数据</span>
</el-form-item> </el-form-item>
<el-form-item label="导入文件" prop="name"> <el-form-item label="导入文件" prop="files">
<!-- “文件大小不可超过8MB”、“请上传格式为以.xlsx或.xls结尾的excel文件” --> <!-- “文件大小不可超过8MB”、“请上传格式为以.xlsx或.xls结尾的excel文件” -->
<el-upload <el-upload
action="#" action="#"
class="upload-demo" class="upload-demo"
ref="upload" ref="upload"
:limit="1"
:on-exceed="handleExceed"
:on-preview="handlePreview" :on-preview="handlePreview"
:on-change="handleChange" :on-change="handleChange"
:on-remove="handleRemove" :on-remove="handleRemove"
...@@ -75,6 +79,7 @@ export default { ...@@ -75,6 +79,7 @@ export default {
num_s: 10, num_s: 10,
num_f: 11, num_f: 11,
dialogResultVisible: false, dialogResultVisible: false,
temp: {},
fileList: [], fileList: [],
dialogFormVisible: false, dialogFormVisible: false,
rules: {} rules: {}
...@@ -82,6 +87,19 @@ export default { ...@@ -82,6 +87,19 @@ export default {
}, },
created() {}, created() {},
methods: { methods: {
validateFiles() {
let nv =
this.fileList.length &&
Object.prototype.toString.call(this.fileList[0]) === '[object Object]'
? this.fileList[0].raw
: { size: 0 }
if (Number(nv.size / 1024 / 1024) > 8) {
this.$message.warning('文件大小不可超过8MB')
return false
} else {
return true
}
},
downloadFail() { downloadFail() {
console.log(this) console.log(this)
}, },
...@@ -90,18 +108,19 @@ export default { ...@@ -90,18 +108,19 @@ export default {
}, },
downloadTemplate() {}, downloadTemplate() {},
addCallback(status) {}, addCallback(status) {},
handleRemove(file, fileList) {
console.log(file, fileList)
},
handlePreview(file) {
console.log(file)
},
handleChange(file, fileList) { handleChange(file, fileList) {
// 替换为最新的
console.log(arguments) console.log(arguments)
this.fileList = fileList this.fileList = [file]
}, this.validateFiles()
handleExceed(files, fileList) {
this.$message.warning(`当前限制选择 1 个文件`)
}, },
submitUpload() { submitUpload() {
if (!this.fileList.length) {
this.$message.warning('请先选择上文件')
return
}
var form = new FormData() var form = new FormData()
form.append('photo', this.fileList[0].raw) form.append('photo', this.fileList[0].raw)
const loading = this.$loading({ const loading = this.$loading({
...@@ -116,39 +135,25 @@ export default { ...@@ -116,39 +135,25 @@ export default {
console.log(res) console.log(res)
loading.close() loading.close()
this.$emit('save', 1) this.$emit('save', 1)
this.$message({ this.dialogResultVisible = true
message: res.status || 'Successfully',
type: 'success'
})
}) })
.catch(err => { .catch(err => {
loading.close() loading.close()
this.$message.warning(err.status) this.$message.warning(err.status)
}) })
}, },
handleRemove(file, fileList) {
console.log(file, fileList)
},
handlePreview(file) {
console.log(file)
},
handleDownload() {}, handleDownload() {},
saveData(status) { saveData(status) {
console.log(this.fileList) // console.log(this.fileList)
this.dialogResultVisible = true
// 0 cancel/close 1 save dialogStatus/create/update // 0 cancel/close 1 save dialogStatus/create/update
if (status) { if (status) {
this.$refs['importForm'].validate(valid => { this.$refs['importForm'].validate(valid => {
if (valid) { if (!this.fileList.length) {
// if (!this.fileList.length) { this.$message.warning('请先导入文件')
// this.$message({ return
// message: '请导入文件', }
// type: 'warning' if (valid && this.validateFiles()) {
// }) this.submitUpload()
// return false
// }
// this.submitUpload()
} }
}) })
} else { } else {
......
...@@ -142,8 +142,12 @@ export default { ...@@ -142,8 +142,12 @@ export default {
mounted() { mounted() {
if (localStorage.getItem('aicremenberpwd') === 'yes') { if (localStorage.getItem('aicremenberpwd') === 'yes') {
this.loginForm.remenber = true this.loginForm.remenber = true
this.loginForm.email = localStorage.getItem('aicusername') this.loginForm.email = this.$publicTools.decrypt(
this.loginForm.password = localStorage.getItem('aicuserpwd') localStorage.getItem('aicusername')
)
this.loginForm.password = this.$publicTools.decrypt(
localStorage.getItem('aicuserpwd')
)
} }
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
particlesJS('particlesId', { particlesJS('particlesId', {
...@@ -298,8 +302,14 @@ export default { ...@@ -298,8 +302,14 @@ export default {
} }
if (this.loginForm.remenber) { if (this.loginForm.remenber) {
localStorage.setItem('aicremenberpwd', 'yes') localStorage.setItem('aicremenberpwd', 'yes')
localStorage.setItem('aicusername', this.loginForm.email) localStorage.setItem(
localStorage.setItem('aicuserpwd', this.loginForm.password) 'aicusername',
this.$publicTools.encrypt(this.loginForm.email)
)
localStorage.setItem(
'aicuserpwd',
this.$publicTools.encrypt(this.loginForm.password)
)
} else { } else {
localStorage.removeItem('aicremenberpwd') localStorage.removeItem('aicremenberpwd')
localStorage.removeItem('aicusername') localStorage.removeItem('aicusername')
...@@ -309,6 +319,7 @@ export default { ...@@ -309,6 +319,7 @@ export default {
let { email, password } = this.loginForm let { email, password } = this.loginForm
// console.log(this.$publicTools.encrypt('欢迎登陆')) // 加密 // console.log(this.$publicTools.encrypt('欢迎登陆')) // 加密
// console.log(this.$publicTools.decrypt('BSC3Xq5Kxw0ICjur0TDQTQ==')) // 解密 // console.log(this.$publicTools.decrypt('BSC3Xq5Kxw0ICjur0TDQTQ==')) // 解密
// 本地存储用了aes加解密 登陆暂未用
this.$store this.$store
.dispatch('user/login', { email, password }) .dispatch('user/login', { email, password })
.then(() => { .then(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment