<bdo id='Fca5y'></bdo><ul id='Fca5y'></ul>

      <tfoot id='Fca5y'></tfoot>

      1. <i id='Fca5y'><tr id='Fca5y'><dt id='Fca5y'><q id='Fca5y'><span id='Fca5y'><b id='Fca5y'><form id='Fca5y'><ins id='Fca5y'></ins><ul id='Fca5y'></ul><sub id='Fca5y'></sub></form><legend id='Fca5y'></legend><bdo id='Fca5y'><pre id='Fca5y'><center id='Fca5y'></center></pre></bdo></b><th id='Fca5y'></th></span></q></dt></tr></i><div id='Fca5y'><tfoot id='Fca5y'></tfoot><dl id='Fca5y'><fieldset id='Fca5y'></fieldset></dl></div>

        <small id='Fca5y'></small><noframes id='Fca5y'>

        <legend id='Fca5y'><style id='Fca5y'><dir id='Fca5y'><q id='Fca5y'></q></dir></style></legend>

        layui table中的数据列中加入图片的上传和展示的例子

        时间:2024-06-17

              <bdo id='rAesW'></bdo><ul id='rAesW'></ul>

                <tbody id='rAesW'></tbody>
              <legend id='rAesW'><style id='rAesW'><dir id='rAesW'><q id='rAesW'></q></dir></style></legend>
                  <tfoot id='rAesW'></tfoot>
                • <i id='rAesW'><tr id='rAesW'><dt id='rAesW'><q id='rAesW'><span id='rAesW'><b id='rAesW'><form id='rAesW'><ins id='rAesW'></ins><ul id='rAesW'></ul><sub id='rAesW'></sub></form><legend id='rAesW'></legend><bdo id='rAesW'><pre id='rAesW'><center id='rAesW'></center></pre></bdo></b><th id='rAesW'></th></span></q></dt></tr></i><div id='rAesW'><tfoot id='rAesW'></tfoot><dl id='rAesW'><fieldset id='rAesW'></fieldset></dl></div>

                  <small id='rAesW'></small><noframes id='rAesW'>

                  layui table 中数据列中可点击按钮直接上传图片或者展示图片,实现功能如下:


                  这里直接展示代码(主要逻辑是要在table 加载时把upload 组件渲染在每一个格子)
                  //table 列中模板的代码
                  <script type="text/html" id="imgTpl2">
                  		#[[
                  		<a href="javascript:void(0);" onclick="imgOpen('{{d.ID}}')"  class="layui-table-link">查看</a>/
                  		<a href="javascript:void(0);" id="{{d.ID}}" class="layui-table-link upload_btn">更换</a>
                  		]]#
                  </script>
                  
                  //table 中渲染的代码
                  table.render({
                                  elem: '#searchPeople-manage'
                                  , url: url
                                  , toolbar: '#topBar' //开启头部工具栏,并为其绑定左侧模板
                                  , defaultToolbar: ['filter', 'exports']
                                  , title: '用户数据表'
                                  ,even:true //隔行变色
                                  , loading: true
                                  // 是否开启字段筛选的记忆功能,支持true/false/'local'/'session'/其他 开启的情况下默认是session,除非显式的指定为'local'
                                  , colFilterRecord: true
                                  // 是否开启智能reload的模式
                                  , smartReloadModel: true
                                  , cols: [[{type: "checkbox", fixed: "left"},
                                      {title: "序号",type:'numbers'},
                                      { templet: "#imgTpl2", title: '头像', align: 'center', width: '9%' },
                                      {field: "RYBM", title: "人员编码",minWidth:140,sort:true},
                                      {field: "XM", title: "姓名", minWidth:80,edit:"text",sort:true},
                                      {field: "RYZT", title: "人员状态",templet:"#RyStatus",sort:true},
                                      {title: "操作", minWidth: 130, align: "center",fixed:"right", toolbar: "#operation-toolbar"}]]
                                  ,request: {
                                      pageName: 'pageNum' //页码的参数名称,默认:page
                                      ,limitName: 'pageSize' //每页数据量的参数名,默认:limit
                                  }
                                  ,where:where
                                  , page: {
                                      limit: 20//默认加载20条
                                      , curr: 1
                                      , limits: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 500, 1000]
                                      , layout: ['count', 'prev', 'page', 'next', 'limit']
                                  }, done: function (res, curr, count) {
                                      //把当前分页条数存入cache,在export及重载时取出
                                      layui.laypage.pageNum = res.curr;
                                      layui.laypage.pageSize = res.limit;
                  
                                      var tableElem = this.elem;
                                      //table render出来实际显示的table组件
                                      var tableViewElem = tableElem.next();
                                      //渲染当前页面的所有upload组件
                                      upload.render({
                                          elem: tableViewElem.find('.upload_btn')
                                          ,url: '/admin/people/uploadPhoto'//这里是自己的上传的url
                                          ,accept: 'file'
                                          ,before: function(obj){ //obj包含信息,跟choose回调完全一致。在传值之前先获取id
                                              var tableElem = this.item;
                                              uploadParam = tableElem.attr('ID');
                                              layer.load(); //上传loading
                                          }
                                          ,data: {
                                              odd_number: function () {//data中写值的时候,要用动态获取的方式,即写个function的方式,不然直接写获取不到相应的值。
                                                  return uploadParam;
                                              }
                                          }
                                          ,done: function (res) {
                                              var tableElem = this.item;
                                              var id= tableElem.attr('ID');
                                              var imageUrl=res.imgUrl;
                                              //上传完成后 修改这条数据储存的图片url 
                                              //异步修改图片
                                              var data = {};
                                              data['model.ID']=id;
                                              data['model.ZP']=imageUrl;
                                              $.ajax({
                                                  url: '/admin/people/updateImg'
                                                  ,data:data
                                                  ,success:function (res) {
                                                      if (res.state=='ok'){
                                                          layer.closeAll('loading'); //关闭loading
                                                          layer.msg('上传成功');
                                                      }else{
                                                          layer.closeAll('loading'); //关闭loading
                                                          layer.msg('上传失败,请重试');
                                                      }
                                                  }
                                                  ,error:function (res) {
                                                      layer.closeAll('loading'); //关闭loading
                                                      layer.msg('上传失败,请重试');
                                                  }
                                              });
                  
                                          }
                                          ,error: function(index, upload){
                                              layer.closeAll('loading'); //关闭loading
                                              layer.msg('上传失败,请重试');
                                          }
                                      });
                  
                                  }
                                  , text: "对不起,加载出现异常!"
                              });
                  
                  
                  //展示图片的代码
                  
                  <script>
                  //异步请求url 展示
                   function imgOpen(id){
                          var imgUrl="";
                          var data = {};
                          data['model.ID']=id;
                          $.ajax({
                              url: '/admin/people/loadImg'
                              ,data:data
                              ,success:function (res) {
                                  layer.photos({
                                      photos: {title: "查看头像", data: [{src: res.ZP}]},
                                      shade: .01,
                                      closeBtn: 1,
                                      area: ["300px", "400px"]
                                  })
                              }
                              ,error:function (res) {
                                  layer.photos({
                                      photos: {title: "查看头像", data: [{src: res.ZP}]},
                                      shade: .01,
                                      closeBtn: 1,
                                      area: ["300px", "400px"]
                                  })
                              }
                          });
                  	}
                  </script>
                  
                  
                  
                   
                  上一篇:微信小程序获取某个元素的高度宽度的示例代码 下一篇:没有了

                  相关文章

                • <i id='riED9'><tr id='riED9'><dt id='riED9'><q id='riED9'><span id='riED9'><b id='riED9'><form id='riED9'><ins id='riED9'></ins><ul id='riED9'></ul><sub id='riED9'></sub></form><legend id='riED9'></legend><bdo id='riED9'><pre id='riED9'><center id='riED9'></center></pre></bdo></b><th id='riED9'></th></span></q></dt></tr></i><div id='riED9'><tfoot id='riED9'></tfoot><dl id='riED9'><fieldset id='riED9'></fieldset></dl></div>
                  • <bdo id='riED9'></bdo><ul id='riED9'></ul>

                    <tfoot id='riED9'></tfoot>

                    <small id='riED9'></small><noframes id='riED9'>

                    <legend id='riED9'><style id='riED9'><dir id='riED9'><q id='riED9'></q></dir></style></legend>