更新
This commit is contained in:
@@ -30,5 +30,12 @@ export function edit(data) {
|
||||
data
|
||||
})
|
||||
}
|
||||
export function excelImport(data) {
|
||||
return request({
|
||||
url: 'api/dict/excelImport',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export default { add, edit, del }
|
||||
export default { add, edit, del, excelImport }
|
||||
|
||||
116
acs/nladmin-ui/src/views/system/dict/UploadDialog.vue
Normal file
116
acs/nladmin-ui/src/views/system/dict/UploadDialog.vue
Normal file
@@ -0,0 +1,116 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
title="导入Excel文件"
|
||||
append-to-body
|
||||
:visible.sync="dialogVisible"
|
||||
destroy-on-close
|
||||
width="400px"
|
||||
:show-close="true"
|
||||
@close="close"
|
||||
@open="open"
|
||||
>
|
||||
<el-upload
|
||||
ref="upload"
|
||||
class="upload-demo"
|
||||
action=""
|
||||
drag
|
||||
:on-exceed="is_one"
|
||||
:limit="1"
|
||||
:auto-upload="false"
|
||||
:multiple="false"
|
||||
:show-file-list="true"
|
||||
:on-change="uploadByJsqd"
|
||||
:file-list="fileList"
|
||||
accept=".xlsx,.xls"
|
||||
>
|
||||
<i class="el-icon-upload" />
|
||||
<div class="el-upload__text">
|
||||
将文件拖到此处,或
|
||||
<em>点击上传</em>
|
||||
</div>
|
||||
<div slot="tip" class="el-upload__tip">只能上传Excel文件,且不超过10MB</div>
|
||||
</el-upload>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
<el-button type="primary" @click="submit">确 定</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import crudDict from '@/api/system/dict'
|
||||
import CRUD, { crud } from '@crud/crud'
|
||||
|
||||
export default {
|
||||
name: 'UploadDialog',
|
||||
mixins: [crud()],
|
||||
components: {},
|
||||
props: {
|
||||
dialogShow: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
openParam: {
|
||||
type: String
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
dialogVisible: false,
|
||||
fileList: [],
|
||||
file1: ''
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
dialogShow: {
|
||||
handler(newValue, oldValue) {
|
||||
this.dialogVisible = newValue
|
||||
}
|
||||
},
|
||||
openParam: {
|
||||
handler(newValue, oldValue) {
|
||||
this.opendtlParam = newValue
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
open() {
|
||||
},
|
||||
close() {
|
||||
this.$emit('update:dialogShow', false)
|
||||
},
|
||||
is_one() {
|
||||
this.crud.notify('只能上传一个excel文件!', CRUD.NOTIFICATION_TYPE.WARNING)
|
||||
},
|
||||
// 文件校验方法
|
||||
beforeAvatarUpload(file) {
|
||||
// 不能导入大小超过2Mb的文件
|
||||
if (file.size > 10 * 1024 * 1024) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
// 文件发生改变就会触发的事件
|
||||
uploadByJsqd(file) {
|
||||
this.file1 = file
|
||||
},
|
||||
submit() {
|
||||
if (this.beforeAvatarUpload(this.file1)) {
|
||||
this.fileList.name = this.file1.name
|
||||
this.fileList.url = ''
|
||||
var formdata = new FormData()
|
||||
formdata.append('file', this.file1.raw)
|
||||
// excelImport:请求接口 formdata:传递参数
|
||||
crudDict.excelImport(formdata).then((res) => {
|
||||
this.crud.notify('导入成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
||||
this.$emit('tableChanged3', '')
|
||||
this.$emit('update:dialogShow', false)
|
||||
})
|
||||
} else {
|
||||
this.crud.notify('文件过大,请上传小于10MB的文件〜', CRUD.NOTIFICATION_TYPE.WARNING)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -60,11 +60,24 @@
|
||||
icon="el-icon-plus"
|
||||
@click="$refs.dictDetail && $refs.dictDetail.crud.toAdd()"
|
||||
>新增</el-button>
|
||||
<el-button
|
||||
v-if="dictNames === 'location_comparison'"
|
||||
slot="right"
|
||||
class="filter-item"
|
||||
style="float: right;padding: 4px 10px"
|
||||
type="warning"
|
||||
icon="el-icon-upload2"
|
||||
size="mini"
|
||||
@click="uploadShow = true"
|
||||
>
|
||||
导入
|
||||
</el-button>
|
||||
</div>
|
||||
<dictDetail ref="dictDetail" :permission="permission" />
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<UploadDialog :dialog-show.sync="uploadShow" @tableChanged3="tableChanged3" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -78,12 +91,12 @@ import crudOperation from '@crud/CRUD.operation'
|
||||
import pagination from '@crud/Pagination'
|
||||
import rrOperation from '@crud/RR.operation'
|
||||
import udOperation from '@crud/UD.operation'
|
||||
|
||||
import UploadDialog from '@/views/system/dict/UploadDialog'
|
||||
const defaultForm = { id: null, name: null, description: null, dictDetails: [] }
|
||||
|
||||
export default {
|
||||
name: 'Dict',
|
||||
components: { crudOperation, pagination, rrOperation, udOperation, dictDetail },
|
||||
components: { crudOperation, pagination, rrOperation, udOperation, dictDetail, UploadDialog },
|
||||
cruds() {
|
||||
return [
|
||||
CRUD({ title: '字典', url: 'api/dict', crudMethod: { ...crudDict }})
|
||||
@@ -105,7 +118,9 @@ export default {
|
||||
add: ['admin', 'dict:add'],
|
||||
edit: ['admin', 'dict:edit'],
|
||||
del: ['admin', 'dict:del']
|
||||
}
|
||||
},
|
||||
uploadShow: false,
|
||||
dictNames: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -117,9 +132,14 @@ export default {
|
||||
}
|
||||
return true
|
||||
},
|
||||
tableChanged3() {
|
||||
this.$refs.dictDetail.crud.toQuery()
|
||||
},
|
||||
// 选中字典后,设置字典详情数据
|
||||
handleCurrentChange(val) {
|
||||
if (val) {
|
||||
console.log(val)
|
||||
this.dictNames = val.name
|
||||
this.$refs.dictDetail.query.dictName = val.name
|
||||
this.$refs.dictDetail.dictId = val.id
|
||||
this.$refs.dictDetail.crud.toQuery()
|
||||
|
||||
Reference in New Issue
Block a user