fastadmin 导入功能

1.框架自带的导入功能按钮,下面二选一即可

<button type="button" id="faupload-student" class="btn btn-info btn-import " data-input-id="c-local" data-mimetype="xls,xlsx"  data-preview-id="p-local" data-url="{:url('ajax/upload')}"><i class="fa fa-upload"></i> {:__("导入")}</button>
<a href="javascript:;" data-url="ajax/upload" class="btn btn-info btn-import{:$auth->check('student/import')?'':'hide'}" title="{:__('Import')}" ><i class="fa fa-upload"></i> {:__('导入')}</a>

2.自定义导入按钮

<button type="button" id="faupload-student" class="btn btn-info" data-input-id="c-student" data-mimetype="xls,xlsx" data-multiple="false" data-preview-id="p-student"><i class="fa fa-upload"></i> {:__('导入')}</button>
<input type="file" name="student" id="student" value="" style="display:none;"/>

然后对应的js文件里面需要添加

$('#faupload-student').on('click',function () {
                $('#student').click();
            });
            $('#student').on('change',function () {
                if(this.files.length <=0){
                    return false;
                }
                var length= this.files.length
                var files= this.files
                require(['upload'], function(Upload){
                    console.log(files)
                    for(var a=0;a<length;a++)
                    {
                        Upload.api.send(files[a], function(data, ret){

                            //
                            var formData = new FormData();
                            // 
                            formData.append('file',ret.data.url);
                            $.ajax({
                                url:'student/import',
                                type:'post',
                                data:formData,
                                cache: false, //上传文件不需要缓存
                                processData: false, // 告诉jQuery不要去处理发送的数据
                                contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                                success:function(data){
                                	console.log(data);
                                    // 
                                    // return data.msg;
                                    Toastr.success("成功");
                                    window.parent.location.reload();
                                    return false;
                                }
                            })

                        }, function(data, ret){
                            Toastr.success("失败");
                        });
                    }
                });
            });

由于时不时的会用到导入功能,这里也记录一下,下次有需要直接复制即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cq林志炫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值