联系官方销售客服
1835022288
028-61286886
在ftable里面加个图片上传的字段,可配置;
内容发布的时候,图片字段能够满足预览、上传、浏览、删除的需求
不影响cms升级!不影响cms升级!不影响cms升级!不影响cms升级!
放在dayrui/My/Field/Ftable.php
<?php namespace My\Field; class Ftable extends \Phpcmf\Field\Ftable { protected function _field_type_select($id, $type) { $arr = [ 0 => dr_lang('不使用'), 1 => dr_lang('文本框'), 2 => dr_lang('下拉选择框'), 3 => dr_lang('图片'), ]; $html = '<select class="form-control" name="data[setting][option][field]['.$id.'][type]">'; foreach ($arr as $i => $name) { $html.= '<option '.($i == $type ? 'selected' : '').' value="'.$i.'">'.$name.'</option>'; } $html.= '</select>'; return $html; } protected function _field_type_html($config, $cname, $value, $hang, $lie) { $html = ''; if ($config['type'] == 1) { $html.= '<label><input type="text" class="form-control" name="data['.$cname.']['.$hang.']['.$lie.']" value="'.$value[$hang][$lie].'"></label>'; } elseif ($config['type'] == 2) { $html = '<label><select class="form-control" name="data['.$cname.']['.$hang.']['.$lie.']">'; $arr = explode(',', $config['option']); foreach ($arr as $name) { $html.= '<option '.($value[$hang][$lie] == $name ? 'selected' : '').' value="'.$name.'">'.$name.'</option>'; } $html.= '</select></label>'; } elseif ($config['type'] == 3) { if ($value[$hang][$lie]) { $pp = dr_get_file($value[$hang][$lie]); } $html = '<label><input class="form-control2" type="hidden" name="data['.$cname.']['.$hang.']['.$lie.']" value="'.$value[$hang][$lie].'">'; $html.= '<input class="form-control3" type="hidden" value="'.($value[$hang][$lie] ? $pp : '').'">'; $html.= '<a href="javascript:;" onclick="myfileinput(this)" class="ftable-fileinput btn green btn-sm">上传</a>'; $html.= '<a href="javascript:;" onclick="myshow(this)" '.($value[$hang][$lie] ? '':'style="display:none"').' class="ftable-show btn blue btn-sm">预览</a> <a href="javascript:;" onclick="mydelete(this)" '.($value[$hang][$lie] ? '':'style="display:none"').' class="ftable-delete btn red btn-sm">删除</a> '; $html.= '</label>'; } return $html; } /** * 字段显示 * * @return string */ public function show($field, $value = null) { // 字段默认值 $value = dr_string2array($value); $str = '<div class="table-scrollable">'; $str.= dr_get_ftable($field['id'], $value); $str.= '</div>'; return $this->input_format($field['fieldname'], $field['name'], $str); } /** * 字段表单输入 */ public function input($field, $value = '') { // 字段禁止修改时就返回显示字符串 if ($this->_not_edit($field, $value)) { return $this->show($field, $value); } $html = parent::input($field, $value); $p = dr_authcode([ 'size' => 10, 'count' => 1, 'exts' => 'jpg,gif,png', 'attachment' => 0, 'image_reduce' => 0, ], 'ENCODE'); $url = '/index.php?s=api&c=file&m=input_file_list&token='.dr_get_csrf_token().'&siteid='.SITE_ID.'&p='.$p.'&ct=0&one=1'; $html.=" <script> function mydelete(e){ var ob = $(e); ob.parent().find('.form-control2').val('0'); ob.parent().find('.ftable-show').hide(); ob.parent().find('.ftable-delete').hide(); } function myshow(e){ var ob = $(e); var url = ob.parent().find('.form-control3').val(); dr_preview_image(url); } function myfileinput (e){ var ob = $(e); var c = 1; var url = '".$url."'; layer.open({ type: 2, title: '<i class=\"fa fa-folder-open\"></i>', fix:true, scrollbar: false, shadeClose: true, shade: 0, area: ['50%', '50%'], btn: [ lang['ok'] ], yes: function(index, layero){ var body = layer.getChildFrame('body', index); // 延迟加载 var loading = layer.load(2, { time: 10000000 }); $.ajax({type: \"POST\",dataType:\"json\", url: url, data: $(body).find('#myform').serialize(), success: function(json2) { layer.close(loading); if (json2.code == 1) { layer.close(index); var v = json2.data.result[0]; ob.parent().find('.form-control2').val(v.id); ob.parent().find('.form-control3').val(v.url); ob.parent().find('.ftable-show').show(); ob.parent().find('.ftable-delete').show(); dr_tips(1, json2.msg); } else { dr_tips(0, json2.msg); } return false; } }); return false; }, success: function(layero, index){ // 主要用于权限验证 var body = layer.getChildFrame('body', index); var json2 = $(body).html(); if (json2.indexOf('\"code\":0') > 0 && jso2n.length < 150){ var obj = JSON.parse(json2); layer.close(index); dr_tips(0, obj.msg); } if (json2.indexOf('\"code\":1') > 0 && json2.length < 150){ var obj = JSON.parse(json2); layer.close(index); dr_tips(1, obj.msg); } }, content: url+'&is_ajax=1' }); } </script> "; return $html; } }
很实用,学习一下!!!