This commit is contained in:
2022-11-29 15:38:04 +08:00
parent 0763920948
commit ca02e2998f
7 changed files with 223 additions and 4 deletions

View File

@@ -149,6 +149,14 @@ export function reload() {
})
}
export function excelImport(data) {
return request({
url: 'api/device/excelImport',
method: 'post',
data
})
}
export default { add, edit, del, selectDeviceList, selectDeviceListByRegion, callAgv, responseAgv, selectDeviceDevicerInfo, autoCreateTask,
changeDeviceStatus, cleanTask, queryStorageExtra, selectConDeviceList, saveBarcode, selectDeviceListOne, selectDeviceListTwo, selectDeviceListThree,
addMaterial, cleanMaterial, reload }
addMaterial, cleanMaterial, reload, excelImport }

View 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 crudDevice from '@/api/acs/device/device'
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传递参数
crudDevice.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>

View File

@@ -29,6 +29,16 @@
<rrOperation />
</div>
<crudOperation :permission="permission">
<el-button
slot="right"
class="filter-item"
type="warning"
icon="el-icon-upload2"
size="mini"
@click="uploadShow = true"
>
导入
</el-button>
<el-button
slot="right"
class="filter-item"
@@ -140,7 +150,7 @@
:data="scope.row"
:permission="permission"
/>
<el-button size="mini" style="margin-left: -1px;margin-right: 2px" type="text" slot="right">
<el-button slot="right" size="mini" style="margin-left: -1px;margin-right: 2px" type="text">
<router-link :to="'/devices/device/config/' + scope.row.device_code ">
驱动配置
</router-link>
@@ -151,6 +161,7 @@
<!--分页组件-->
<pagination />
</div>
<UploadDialog :dialog-show.sync="uploadShow" @tableChanged3="tableChanged3" />
</div>
</template>
@@ -162,6 +173,7 @@ import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import { get } from '@/api/system/dictDetail'
import UploadDialog from '@/views/acs/device/UploadDialog'
const defaultForm = {
manufacturer: null,
@@ -184,7 +196,7 @@ const defaultForm = {
}
export default {
name: 'Device',
components: { pagination, crudOperation, rrOperation, udOperation },
components: { pagination, crudOperation, rrOperation, udOperation, UploadDialog },
mixins: [presenter(), header(), form(defaultForm), crud()],
cruds() {
return CRUD({
@@ -203,6 +215,7 @@ export default {
del: ['admin', 'device:del']
},
device_types: [],
uploadShow: false,
regions: [],
rules: {
device_code: [
@@ -235,6 +248,9 @@ export default {
[CRUD.HOOK.beforeRefresh]() {
return true
},
tableChanged3() {
this.crud.toQuery()
},
reload() {
crudDevice.reload().then(res => {
this.crud.toQuery()