点击自定义插槽上传文件并存入数据库,走的save方法
牛马
这个人很懒,什么都没有留下。
牛马
2022-10-11 09:40:49
744
{{single.collect_count}}
    /**
     * 保存新建的资源
     */
    public function save()
    {
        if ($this->request->isPost()) {
            $file = $this->request->file('file');

            $data = Excel::importExcel($file);
    
           //循环去除空值
        
            //去除空数组
        
            //获取主要信息
         
            //去除没用数组元素
        
            $info = [
                'robot_type'=>$robot_type['id'],
                'robot_detail'=>$robot_detail['id'],
                'product'=>$product,
                'module'=>$module,
                'create_time' =>date('Y-m-d H:i:s')
            ];

            TemplateLinkModel::create($info);
            return json(["status" => "success", "message" => "导入成功"]);
        }
    }

点击自定义插槽上传文件并存入数据库,走的save方法,成功后回调触发的是上传的回调,没有添加成功的提示,并且需要手动刷新

<div id="app" v-cloak>
	<el-curd ref="'curd"
		:field="field"
		:table-export="false"
		:table-page-size="20"
		:table-operation-width="250"
		:table-page-sizes="[20, 50, 100, 200, 500]"
		:search-keyword="false"
		:search-date="false">
		<template v-slot:button>
			<el-tooltip content="导入" placement="top">
				<el-upload
				class="el-upload"
				name="file"
				accept=".xls,.xlsx"
				:action="url(uploadUrl)"
				:before-upload="beforeUpload" 
				:on-progress="progressUpload" 
				:on-success="successUpload" 
				:on-error="errorUpload"
				
				:limit="1"
				:show-file-list="false">
				<el-button type="success" icon="el-icon-download">导入模板</el-button>
				</el-upload>

			 </el-tooltip>
		 </template>
	</el-curd>
</div>
<script>
	new Vue({
		el: "#app",
		props: {
			type: {
				type: String,
				default: '',
			},
		},
		data() {
			return {
				list:[],
				uploadUrl:'template/templateLink/save',
				search: {
					keyword: '',
					type: this.type,
					page: 1,
					prop: 'create_time',
					order: 'desc',
				},
				field: [
					……
				],
			}
		},
		methods:{
		/**
         * 上传文件开启
         */
		 beforeUpload(item) {
        },
		 /**
         * 上传文件中
         */
		 progressUpload(event, item) {
        },
        /**
         * 上传成功回调
         */
        successUpload(res, item) {
            let self = this;
            let index = common.arrayIndex(self.list, item['uid'], 'uid');
            if (res.status === 'success') {
				
				this.$notify({showClose: true, message: '导入成功', type: 'success'});

				location.href=location.href;
            } else {
                self.list.splice(index,1);
                self.$notify({showClose: true, message: res.message, type: 'error'});
            }
        },
        /**
         * 上传错误回调
         */
        errorUpload(res, item){
				let index = common.arrayIndex(this.list, item['uid'], 'uid');
				this.list.splice(index,1);
				this.$notify({showClose: true, message: '系统错误!', type: 'error'});
        	},
		}
		}
	})
</script>

 

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}