| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- function isObject(value) {
- return value !== null && typeof value === 'object'
- }
- function isFunction(value) {
- return typeof value === 'function'
- }
- function identifyType(value) {
- if (isFunction(value)) {
- return 'Function'
- } else if (isObject(value)) {
- return 'Object'
- } else {
- return 'Neither Object nor Function'
- }
- }
- export default {
- methods: {
- //导入按钮
- importButton(func, name = '导入', params, fun1, fun2) {
- return (
- <el-upload
- action={'_'}
- show-file-list={false}
- http-request={async data => {
- var formdata = new FormData()
- formdata.append('file', data.file)
- if (identifyType(params) == 'Object') {
- for (const key in params) {
- if (Object.hasOwnProperty.call(params, key)) {
- formdata.append(key, params[key])
- }
- }
- } else if (identifyType(params) == 'Function') {
- try {
- var chanshu = await params()
- for (const key in chanshu || {}) {
- if (Object.hasOwnProperty.call(chanshu, key)) {
- formdata.append(key, chanshu[key])
- }
- }
- } catch (error) {
- return
- }
- }
- const loading = this.$loading({
- lock: true,
- text: '正在导入',
- spinner: 'el-icon-loading',
- background: 'rgba(0, 0, 0, 0.7)'
- })
- fun1 && fun1()
- func({ formdata })
- .then(res => {
- fun2 && fun2(res)
- this.$refs.pageRef.refreshList()
- loading.close()
- this.$message({
- type: 'success',
- message: '导入成功!'
- })
- })
- .catch(err => {
- fun2 && fun2()
- loading.close()
- this.$message({
- type: 'error',
- message: err.message || '导入失败'
- })
- })
- }}
- >
- <span class="teshudeshangchuananniu">{name}</span>
- </el-upload>
- )
- }
- }
- }
|