diff --git a/application/admin/controller/Common.php b/application/admin/controller/Common.php index e836476d4..aaa00046e 100755 --- a/application/admin/controller/Common.php +++ b/application/admin/controller/Common.php @@ -33,6 +33,24 @@ class Common extends Controller // 左边权限菜单 protected $left_menu; + // 当前操作名称 + protected $module_name; + protected $controller_name; + protected $action_name; + + // 输入参数 post + protected $data_post; + + // 输入参数 get + protected $data_get; + + // 输入参数 request + protected $data_request; + + // 分页信息 + protected $page; + protected $page_size; + /** * 构造方法 * @author Devil @@ -48,6 +66,11 @@ class Common extends Controller // 系统初始化 $this->SystemInit(); + // 输入参数 + $this->data_post = input('post.'); + $this->data_get = input('get.'); + $this->data_request = input(); + // 管理员信息 $this->admin = session('admin'); @@ -92,6 +115,23 @@ class Common extends Controller // 公共底部钩子 $this->assign('plugins_admin_view_common_bottom_data', Hook::listen('plugins_admin_view_common_bottom', ['hook_name'=>'plugins_admin_view_common_bottom', 'is_backend'=>true, 'admin'=>$this->admin])); + + // 公共钩子名称动态处理 + $current = 'plugins_view_admin_'.$this->controller_name; + // 内容外部顶部 + $this->assign('hook_name_content_top', $current.'_content_top'); + // 内容外部底部 + $this->assign('hook_name_content_bottom', $current.'_content_bottom'); + // 内容内部顶部 + $this->assign('hook_name_content_inside_top', $current.'_content_inside_top'); + // 内容内部底部 + $this->assign('hook_name_content_inside_bottom', $current.'_content_inside_bottom'); + // 表格列表顶部操作 + $this->assign('hook_name_form_top_operate', $current.'_top_operate'); + // 表格列表底部操作 + $this->assign('hook_name_form_bottom_operate', $current.'_bottom_operate'); + // 表格列表后面操作栏 + $this->assign('hook_name_form_list_operate', $current.'_list_operate'); } /** @@ -145,25 +185,31 @@ class Common extends Controller $this->assign('default_theme', $default_theme); // 当前操作名称 - $module_name = strtolower(request()->module()); - $controller_name = strtolower(request()->controller()); - $action_name = strtolower(request()->action()); + $this->module_name = strtolower(request()->module()); + $this->controller_name = strtolower(request()->controller()); + $this->action_name = strtolower(request()->action()); // 当前操作名称 - $this->assign('module_name', $module_name); - $this->assign('controller_name', $controller_name); - $this->assign('action_name', $action_name); + $this->assign('module_name', $this->module_name); + $this->assign('controller_name', $this->controller_name); + $this->assign('action_name', $this->action_name); + + // 分页信息 + $this->page = max(1, isset($this->data_request['page']) ? intval($this->data_request['page']) : 1); + $this->page_size = MyC('admin_page_number', 10, true); + $this->assign('page', $this->page); + $this->assign('page_size', $this->page_size); // 价格符号 $this->assign('price_symbol', config('shopxo.price_symbol')); // 控制器静态文件状态css,js - $module_css = $module_name.DS.$default_theme.DS.'css'.DS.$controller_name; - $module_css .= file_exists(ROOT_PATH.'static'.DS.$module_css.'.'.$action_name.'.css') ? '.'.$action_name.'.css' : '.css'; + $module_css = $this->module_name.DS.$default_theme.DS.'css'.DS.$this->controller_name; + $module_css .= file_exists(ROOT_PATH.'static'.DS.$module_css.'.'.$this->action_name.'.css') ? '.'.$this->action_name.'.css' : '.css'; $this->assign('module_css', file_exists(ROOT_PATH.'static'.DS.$module_css) ? $module_css : ''); - $module_js = $module_name.DS.$default_theme.DS.'js'.DS.$controller_name; - $module_js .= file_exists(ROOT_PATH.'static'.DS.$module_js.'.'.$action_name.'.js') ? '.'.$action_name.'.js' : '.js'; + $module_js = $this->module_name.DS.$default_theme.DS.'js'.DS.$this->controller_name; + $module_js .= file_exists(ROOT_PATH.'static'.DS.$module_js.'.'.$this->action_name.'.js') ? '.'.$this->action_name.'.js' : '.js'; $this->assign('module_js', file_exists(ROOT_PATH.'static'.DS.$module_js) ? $module_js : ''); // 权限菜单 @@ -180,6 +226,12 @@ class Common extends Controller // 默认不加载百度地图api $this->assign('is_load_baidu_map_api', 0); + + // 动态表格处理 + $obj = new \app\form\GoodsForm(); + $table = $obj->Table(); + $this->assign('form_table', $table); + //print_r($table); } /** diff --git a/application/admin/controller/Goods.php b/application/admin/controller/Goods.php index 6b9ac43a3..2d0a00ca1 100755 --- a/application/admin/controller/Goods.php +++ b/application/admin/controller/Goods.php @@ -54,7 +54,7 @@ class Goods extends Common public function Index() { // 参数 - $params = input(); + $params = $this->data_request; // 条件 $where = GoodsService::GetAdminIndexWhere($params); @@ -63,12 +63,11 @@ class Goods extends Common $total = GoodsService::GoodsTotal($where); // 分页 - $number = MyC('admin_page_number', 10, true); $page_params = array( - 'number' => $number, + 'number' => $this->page_size, 'total' => $total, 'where' => $params, - 'page' => isset($params['page']) ? intval($params['page']) : 1, + 'page' => $this->page, 'url' => MyUrl('admin/goods/index'), ); $page = new \base\Page($page_params); @@ -77,7 +76,7 @@ class Goods extends Common $data_params = [ 'where' => $where, 'm' => $page->GetPageStarNumber(), - 'n' => $number, + 'n' => $this->page_size, 'is_category' => 1, ]; $ret = GoodsService::GoodsList($data_params); diff --git a/application/admin/controller/Myinc.php b/application/admin/controller/Myinc.php new file mode 100644 index 000000000..d8144b9a8 --- /dev/null +++ b/application/admin/controller/Myinc.php @@ -0,0 +1,50 @@ +IsLogin(); + + // 权限校验 + $this->IsPower(); + } + + public function view($template) + { + //return $template; + return $this->fetch($template); + } + +} \ No newline at end of file diff --git a/application/admin/view/default/goods/index.html b/application/admin/view/default/goods/index.html index 7e7ec1123..561fdaf40 100755 --- a/application/admin/view/default/goods/index.html +++ b/application/admin/view/default/goods/index.html @@ -1,267 +1,113 @@ -{{include file="public/header" /}} + +{{extend name="public/form" /}} - -
-
- -
- - - -{{include file="public/footer" /}} - \ No newline at end of file + +{{block name="form_operate_top"}} + 新增 + + {__block__} +{{/block}} \ No newline at end of file diff --git a/application/admin/view/default/goods/module/info.html b/application/admin/view/default/goods/module/info.html new file mode 100644 index 000000000..700555acf --- /dev/null +++ b/application/admin/view/default/goods/module/info.html @@ -0,0 +1,12 @@ + +{{if !empty($module_data)}} +
+ + + + {{$module_data.title}} + {{if !empty($module_data['simple_desc'])}} +

{{$module_data.simple_desc}}

+ {{/if}} +
+{{/if}} \ No newline at end of file diff --git a/application/admin/view/default/goods/module/operate.html b/application/admin/view/default/goods/module/operate.html new file mode 100644 index 000000000..59fdadf98 --- /dev/null +++ b/application/admin/view/default/goods/module/operate.html @@ -0,0 +1,13 @@ + + + + + 编辑 + + \ No newline at end of file diff --git a/application/admin/view/default/public/form.html b/application/admin/view/default/public/form.html new file mode 100644 index 000000000..54f4e8938 --- /dev/null +++ b/application/admin/view/default/public/form.html @@ -0,0 +1,281 @@ +{{include file="public/header" /}} + + +{{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}} +
+ {{$hook_name_content_top}} +
+{{/if}} +{{php}} + $hook_data = Hook::listen($hook_name_content_top, ['hook_name'=>$hook_name_content_top, 'is_backend'=>true]); + if(!empty($hook_data) && is_array($hook_data)) + { + foreach($hook_data as $hook) + { + if(is_string($hook) || is_int($hook)) + { + echo htmlspecialchars_decode($hook); + } + } + } +{{/php}} + + +
+
+ + {{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}} +
+ {{$hook_name_content_inside_top}} +
+ {{/if}} + {{php}} + $hook_data = Hook::listen($hook_name_content_inside_top, ['hook_name'=>$hook_name_content_inside_top, 'is_backend'=>true]); + if(!empty($hook_data) && is_array($hook_data)) + { + foreach($hook_data as $hook) + { + if(is_string($hook) || is_int($hook)) + { + echo htmlspecialchars_decode($hook); + } + } + } + {{/php}} + + + {{block name="search_form"}}{{/block}} + + + +
+ {{block name="form_operate_top"}} + {{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}} +
+ plugins_view_admin_goods_top_operate +
+ {{/if}} + {{php}} + $hook_name = 'plugins_view_admin_goods_top_operate'; + $hook_data = Hook::listen($hook_name, ['hook_name'=>$hook_name, 'is_backend'=>true]); + if(!empty($hook_data) && is_array($hook_data)) + { + foreach($hook_data as $hook) + { + if(is_string($hook) || is_int($hook)) + { + echo htmlspecialchars_decode($hook); + } + } + } + {{/php}} + {{/block}} +
+ + + +
+ + + + {{if !empty($form_table['form'])}} + {{foreach $form_table['form'] as $t}} + + + + + + {{/foreach}} + {{/if}} + + + + {{if !empty($data_list) and !empty($form_table['form']) and !empty($form_table['base']) and !empty($form_table['base']['key_field'])}} + + {{for start="0" end="(count($data_list) < $page_size ? count($data_list) : $page_size)"}} + + + + {{foreach $form_table['form'] as $t}} + + + + + + + {{/foreach}} + + {{/for}} + {{/if}} + +
{{if isset($t['label'])}}{{$t.label}}{{/if}}
+ {{if isset($data_list[$i]) and !empty($t['view_type']) and !empty($t['view_key'])}} + + {{switch $t.view_type}} + {{case field}} + + {{if is_array($t['view_key'])}} + {{foreach $t['view_key'] as $fk=>$fv}} + {{if isset($data_list[$i][$fv])}} + {{$data_list[$i][$fv]}} + + {{if isset($t['view_key_join']) and $fk lt count($t['view_key'])-1}} + {{$t.view_key_join|raw}} + {{/if}} + {{/if}} + {{/foreach}} + {{else /}} + + {{if isset($data_list[$i][$t['view_key']])}} + {{$data_list[$i][$t['view_key']]|raw}} + {{/if}} + {{/if}} + {{/case}} + {{case module}} + + {{:ModuleInclude($t['view_key'], $data_list[$i])}} + {{/case}} + {{case status}} + + {{if !empty($t['key_field']) and !empty($t['post_url'])}} + + {{/if}} + {{/case}} + {{case operate}} + + + {{:ModuleInclude($t['view_key'], $data_list[$i])}} + + + {{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}} +
+ {{$hook_name_form_list_operate}} +
+ {{/if}} + {{php}} + $hook_data = Hook::listen($hook_name_form_list_operate, [ + 'hook_name' => $hook_name_form_list_operate, + 'is_backend' => true, + 'id' => isset($data_list[$i][$form_table['base']['key_field']]) ? $data_list[$i][$form_table['base']['key_field']] : 0, + 'data' => $data_list[$i], + ]); + if(!empty($hook_data) && is_array($hook_data)) + { + foreach($hook_data as $hook) + { + if(is_string($hook) || is_int($hook)) + { + echo htmlspecialchars_decode($hook); + } + } + } + {{/php}} + {{/case}} + {{/switch}} + {{/if}} +
+ {{if empty($data_list)}} +
没有相关数据
+ {{/if}} +
+ + + +
+ {{block name="form_operate_bottom"}} + {{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}} +
+ {{$hook_name_form_bottom_operate}} +
+ {{/if}} + {{php}} + $hook_data = Hook::listen($hook_name_form_bottom_operate, ['hook_name'=>$hook_name_form_bottom_operate, 'is_backend'=>true]); + if(!empty($hook_data) && is_array($hook_data)) + { + foreach($hook_data as $hook) + { + if(is_string($hook) || is_int($hook)) + { + echo htmlspecialchars_decode($hook); + } + } + } + {{/php}} + {{/block}} +
+ + + + {{block name="form_page"}} + {{if !empty($data_list)}} + {{$page_html|raw}} + {{/if}} + {{/block}} + + + + {{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}} +
+ {{$hook_name_content_inside_bottom}} +
+ {{/if}} + {{php}} + $hook_data = Hook::listen($hook_name_content_inside_bottom, ['hook_name'=>$hook_name_content_inside_bottom, 'is_backend'=>true]); + if(!empty($hook_data) && is_array($hook_data)) + { + foreach($hook_data as $hook) + { + if(is_string($hook) || is_int($hook)) + { + echo htmlspecialchars_decode($hook); + } + } + } + {{/php}} +
+
+ + + +{{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}} +
+ {{$hook_name_content_bottom}} +
+{{/if}} +{{php}} + $hook_data = Hook::listen($hook_name_content_bottom, ['hook_name'=>$hook_name_content_bottom, 'is_backend'=>true]); + if(!empty($hook_data) && is_array($hook_data)) + { + foreach($hook_data as $hook) + { + if(is_string($hook) || is_int($hook)) + { + echo htmlspecialchars_decode($hook); + } + } + } +{{/php}} + + +{{include file="public/footer" /}} + \ No newline at end of file diff --git a/application/common.php b/application/common.php index d7a4252d3..2ba438980 100755 --- a/application/common.php +++ b/application/common.php @@ -11,6 +11,36 @@ // 应用公共文件 +/** + * 模块视图动态加载方法 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-05-25 + * @desc description + * @param [string] $template [视图路径] + * @param [mixed] $params [参数数据] + */ +function ModuleInclude($template, $params = []) +{ + // 应用控制器 + $module = '\app\module\ViewInclude'; + if(!class_exists($module)) + { + return '模块视图控制器未定义['.$module.']'; + } + + // 调用方法 + $action = 'Run'; + $obj = new $module(); + if(!method_exists($obj, $action)) + { + return '模块视图方法未定义['.$module.'->'.$action.'()]'; + } + + return $obj->Run($template, $params); +} + /** * 钩子返回数据处理,是否存在错误 * @author Devil diff --git a/application/form/GoodsForm.php b/application/form/GoodsForm.php index 142daca47..409bd2cde 100644 --- a/application/form/GoodsForm.php +++ b/application/form/GoodsForm.php @@ -8,7 +8,7 @@ // +---------------------------------------------------------------------- // | Author: Devil // +---------------------------------------------------------------------- -namespace app\service; +namespace app\form; use think\Db; @@ -33,18 +33,75 @@ class GoodsForm */ public function Table($params = []) { - $data = [ - [ - // 标题名称 - 'label' => '商品信息', - // 展示数据类型(field 字段取值, file 文件引入内容, status 状态操作, ) - 'view_type' => 'field', - // 展示数据的 key名称 - 'view_key' => 'title', - // 内容位置(left 居左, center 居中, right 居右)默认 left - 'align' => 'left', - // 格子大小(lg 350px, sm 200px, xs 150px)默认空(100px) - 'grid_size' => 'lg', + return [ + // 基础配置 + 'base' => [ + 'key_field' => 'id', + 'status_field' => 'is_shelves', + ], + // 表单配置 + 'form' => [ + [ + 'label' => '商品ID', + 'view_type' => 'field', + 'view_key' => 'id', + ], + [ + 'label' => '商品信息', + 'view_type' => 'module', + 'view_key' => 'goods/module/info', + 'grid_size' => 'lg', + ], + [ + 'label' => '销售价格(元)', + 'view_type' => 'field', + 'view_key' => 'price', + ], + [ + 'label' => '原价(元)', + 'view_type' => 'field', + 'view_key' => 'original_price', + ], + [ + 'label' => '库存数量', + 'view_type' => 'field', + 'view_key' => ['inventory', 'inventory_unit'], + 'view_key_join' => ' ', + ], + [ + 'label' => '上下架', + 'view_type' => 'status', + 'view_key' => 'is_shelves', + 'key_field' => 'id', + 'post_url' => MyUrl('admin/goods/statusshelves'), + 'is_form_su' => 1, + 'align' => 'center', + ], + [ + 'label' => '首页推荐', + 'view_type' => 'status', + 'view_key' => 'is_home_recommended', + 'key_field' => 'id', + 'post_url' => MyUrl('admin/goods/statushomerecommended'), + 'align' => 'center', + ], + [ + 'label' => '商品型号', + 'view_type' => 'field', + 'view_key' => 'model', + ], + [ + 'label' => '品牌', + 'view_type' => 'field', + 'view_key' => 'brand_name', + ], + [ + 'label' => '操作', + 'view_type' => 'operate', + 'view_key' => 'goods/module/operate', + 'align' => 'center', + 'fixed' => 'right', + ], ], ]; } diff --git a/application/index/view/default/index/index.html b/application/index/view/default/index/index.html index e019a9824..5bd0b4f88 100755 --- a/application/index/view/default/index/index.html +++ b/application/index/view/default/index/index.html @@ -230,7 +230,7 @@ {{if !empty($floor['goods'])}} {{foreach $floor.goods as $goods_key=>$goods}}
- + {{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}}
diff --git a/application/module/ViewInclude.php b/application/module/ViewInclude.php new file mode 100644 index 000000000..edd8b4792 --- /dev/null +++ b/application/module/ViewInclude.php @@ -0,0 +1,56 @@ +assign('module_data', $params); + return $this->fetch($template); + } +} +?> \ No newline at end of file diff --git a/application/service/GoodsService.php b/application/service/GoodsService.php index 95820ebcf..8ec5653a4 100755 --- a/application/service/GoodsService.php +++ b/application/service/GoodsService.php @@ -176,6 +176,9 @@ class GoodsService */ public static function HomeFloorList($params = []) { + // 商品数量 + $goods_count = 8; + // 缓存 $key = config('shopxo.cache_goods_floor_list_key'); $data = cache($key); @@ -198,7 +201,7 @@ class GoodsService 'g.is_home_recommended' => 1, 'g.is_shelves' => 1, ]; - $v['goods_ids'] = Db::name('Goods')->alias('g')->join(['__GOODS_CATEGORY_JOIN__'=>'gci'], 'g.id=gci.goods_id')->where($where)->group('g.id')->order('g.id desc')->limit(8)->column('g.id'); + $v['goods_ids'] = Db::name('Goods')->alias('g')->join(['__GOODS_CATEGORY_JOIN__'=>'gci'], 'g.id=gci.goods_id')->where($where)->group('g.id')->order('g.id desc')->limit($goods_count)->column('g.id'); $v['goods'] = []; } } @@ -215,7 +218,7 @@ class GoodsService { if(!empty($v['goods_ids']) && is_array($v['goods_ids'])) { - $res = self::GoodsList(['where'=>['id'=>$v['goods_ids'], 'is_home_recommended'=>1, 'is_shelves'=>1], 'm'=>0, 'n'=>8, 'field'=>'*']); + $res = self::GoodsList(['where'=>['id'=>$v['goods_ids'], 'is_home_recommended'=>1, 'is_shelves'=>1], 'm'=>0, 'n'=>$goods_count, 'field'=>'*']); $v['goods'] = $res['data']; } } diff --git a/public/static/common/css/common.css b/public/static/common/css/common.css index 9b2d396d7..b834436a0 100755 --- a/public/static/common/css/common.css +++ b/public/static/common/css/common.css @@ -430,6 +430,7 @@ button.colorpicker-submit img { */ .am-table-scrollable-horizontal { border: 1px solid #ddd; + position: relative; } .am-table-scrollable-horizontal .am-table { border-collapse: collapse; @@ -456,50 +457,48 @@ button.colorpicker-submit img { background: #e8e6e6; min-width: 100px; } -.am-table-scrollable-horizontal .am-table tr th.am-grid-lg { +.am-table-scrollable-horizontal .am-table tr .am-grid-lg { min-width: 350px; } -.am-table-scrollable-horizontal .am-table tr th.am-grid-sm { +.am-table-scrollable-horizontal .am-table tr .am-grid-sm { min-width: 200px; } -.am-table-scrollable-horizontal .am-table tr th.am-grid-xs { +.am-table-scrollable-horizontal .am-table tr .am-grid-xs { min-width: 150px; } .am-table-scrollable-horizontal .am-table tr .am-operate-grid { width: 100px; - padding: 0; } -.am-table-scrollable-horizontal .am-table tr .am-operate-grid .am-scrollable-vertical { - height: 45px; - padding: 10px 15px; - resize: none; - overflow-x: hidden; -} -.am-table-scrollable-horizontal .am-table-td-fixed-first th:first-child, -.am-table-scrollable-horizontal .am-table-td-fixed-first td:first-child, -.am-table-scrollable-horizontal .am-table-td-fixed-last th:last-child, -.am-table-scrollable-horizontal .am-table-td-fixed-last td:last-child { - position: absolute; - width: 100px; +.am-table-scrollable-horizontal .am-table tr .am-grid-fixed-left, +.am-table-scrollable-horizontal .am-table tr .am-grid-fixed-right { height: auto; - text-align: center; z-index: 2; + position: sticky; } -.am-table-scrollable-horizontal .am-table-td-fixed-first td:first-child, -.am-table-scrollable-horizontal .am-table-td-fixed-last td:last-child { +.am-table-scrollable-horizontal .am-table tr td.am-grid-fixed-left, +.am-table-scrollable-horizontal .am-table tr td.am-grid-fixed-right { + height: auto; + z-index: 2; + position: sticky; background: #fff; } -.am-table-scrollable-horizontal .am-table-td-fixed-first th:first-child, -.am-table-scrollable-horizontal .am-table-td-fixed-first td:first-child { +.am-table-scrollable-horizontal .am-table tr .am-grid-fixed-left { + -webkit-box-shadow: 1px 0px 1px #ddd; + -moz-box-shadow: 1px 0px 1px #ddd; + box-shadow: 1px 0px 1px #ddd; +} +.am-table-scrollable-horizontal .am-table tr .am-grid-fixed-right { + -webkit-box-shadow: 0px 0px 1px #ddd; + -moz-box-shadow: 0px 0px 1px #ddd; + box-shadow: 0px 0px 1px #ddd; +} +.am-table-scrollable-horizontal .am-table tr .am-grid-fixed-left-shadow { -webkit-box-shadow: 5px 0px 10px rgba(136, 136, 136, 0.3); -moz-box-shadow: 5px 0px 10px rgba(136, 136, 136, 0.3); box-shadow: 5px 0px 10px rgba(136, 136, 136, 0.3); - left: 0; } -.am-table-scrollable-horizontal .am-table-td-fixed-last th:last-child, -.am-table-scrollable-horizontal .am-table-td-fixed-last td:last-child { +.am-table-scrollable-horizontal .am-table tr .am-grid-fixed-right-shadow { -webkit-box-shadow: -5px 0px 10px rgba(136, 136, 136, 0.3); -moz-box-shadow: -5px 0px 10px rgba(136, 136, 136, 0.3); box-shadow: -5px 0px 10px rgba(136, 136, 136, 0.3); - right: 0; -} +} \ No newline at end of file diff --git a/public/static/common/js/common.js b/public/static/common/js/common.js index bdfceb53f..24ad30fe8 100755 --- a/public/static/common/js/common.js +++ b/public/static/common/js/common.js @@ -1559,134 +1559,52 @@ function TableContainerInit() { if($('.am-table-scrollable-horizontal').length > 0) { - // th - $('.am-table-scrollable-horizontal > table > thead > tr').each(function(k, v) - { - // 第一列 - if($(this).parents('.am-table').hasClass('am-table-td-fixed-first')) - { - $(this).find('>th:first').css('left', $(this).parents('.am-table').offset().left); + // 表格容器距离计算 + var $obj = $('.am-table-scrollable-horizontal'); + var document_width = $(window).width(); + var parent_left = $obj.offset().left; + var parent_width = $obj[0].scrollWidth; + var parent_right = document_width-parent_width-parent_left-2; - // 第一列自定义宽度->默认宽度,设置第二列 padding-left - var first_width = $(this).find('>th').first().data('width') || $(this).find('>th').first().innerWidth(); - if(first_width > 0) - { - $(this).find('>th').eq(1).css('min-width', (($(this).find('>th').eq(1).data('width') || 0)+first_width)+'px'); - $(this).find('>th').eq(1).css('padding-left', (first_width+10)+'px'); - } - } + // 左固定 + $('.am-table-scrollable-horizontal > table .am-grid-fixed-left').each(function(k, v) + { + var width = parseInt($(this).attr('data-width') || $(this).innerWidth()); + var left = parseInt($(this).attr('data-left') || $(this).position().left); + $(this).attr('data-width', width); + $(this).attr('data-left', left); + $(this).css({"width":width+"px", "left":left+"px"}); + }); - // 最后一列 - if($(this).parents('.am-table').hasClass('am-table-td-fixed-last')) - { - var $obj = $(this).parents('.am-table-scrollable-horizontal'); - var width = $(document.body).width(); - var left = $obj.offset().left; - var right = width-$obj.width()-left-1; - $(this).find('>th:last').css('right', right); + // 右固定 + $('.am-table-scrollable-horizontal > table .am-grid-fixed-right').each(function(k, v) + { + var width = parseInt($(this).attr('data-width') || $(this).innerWidth()); + var right = $(this).attr('data-right') || undefined; + if(right == undefined) + { + var left = $(this).offset().left; + var width = $(this).width(); + var right = parent_width-left-width-parent_left-4; + if(right < 0) + { + right = 0; + } + } else { + right = parseInt(right); + } + $(this).attr('data-width', width); + $(this).attr('data-right', right); + $(this).css({"width":width+"px", "right":right+"px"}); + }); - // 最后一列自定义宽度->默认宽度,设置倒数第二列 padding-right - var last_width = parseInt($(this).find('>th').last().attr('data-width') || $(this).find('>th').last().innerWidth()); - if(last_width > 0) - { - // 倒数第二个元素的宽度、默认读取属性宽度 - var last_width2 = parseInt($(this).find('>th').eq(-2).attr('data-width') || $(this).find('>th').eq(-2).innerWidth()); - // 设置宽度、倒数第二个元素的宽度+最后一个元素的宽度 - $(this).find('>th').eq(-2).css('min-width', last_width2+last_width+'px'); - // 设置宽度、最后一个元素的宽度+10 - $(this).find('>th').eq(-2).css('padding-right', (last_width+10)+'px'); - // 设置属性数据 - $(this).find('>th').eq(-2).attr('data-width', last_width2); - $(this).find('>th').last().attr('data-width', last_width); - } - } - - // 是否自定义宽高 - $(this).find('>th').each(function(ks, vs) - { - var width = $(this).data('width') || 0; - if(width > 0) - { - $(this).css('width', width+'px'); - } - var height = $(this).data('height') || 0; - if(height > 0) - { - $(this).css('height', height+'px'); - } - }); - }); - - // td - $('.am-table-scrollable-horizontal > table > tbody > tr').each(function(k, v) - { - // 容器 - var height = $(this).height() || 0; - - // 自定义高度,仅大于默认高度的时候有效 - var z_height = $(this).data('height') || 0; - if(z_height > height) - { - height = z_height; - } - if(height > 0) - { - $(this).find('>td').css('height', height+'px'); - - // 第一列 - if($(this).parents('.am-table').hasClass('am-table-td-fixed-first')) - { - $(this).find('>td:first').css('left', $(this).parents('.am-table').offset().left); - - // 第一列自定义宽度->默认宽度,设置第二列 padding-left - var first_width = $(this).find('>td').first().data('width') || $(this).find('>td').first().innerWidth(); - if(first_width > 0) - { - $(this).find('>td').eq(1).css('padding-left', (first_width+10)+'px'); - } - } - - // 最后一列 - if($(this).parents('.am-table').hasClass('am-table-td-fixed-last')) - { - var $obj = $(this).parents('.am-table-scrollable-horizontal'); - var width = $(document.body).width(); - var left = $obj.offset().left; - var right = width-$obj.width()-left-1; - $(this).find('>td:last').css('right', right); - - // 最后一列自定义宽度->默认宽度,设置倒数第二列 padding-right - var last_width = parseInt($(this).find('>td').last().attr('data-width') || $(this).find('>td').last().innerWidth()); - if(last_width > 0) - { - // 设置宽度、最后一个元素的宽度+10 - $(this).find('>td').eq(-2).css('padding-right', (last_width+10)+'px'); - } - } - - // 操作栏下容器高度 - if($(this).find('>td.am-operate-grid .am-scrollable-vertical').length > 0) - { - $(this).find('>td.am-operate-grid .am-scrollable-vertical').css('height', (height-1)+'px'); - } - - // 是否自定义宽高 - $(this).find('>td').each(function(ks, vs) - { - var width = $(this).data('width') || 0; - if(width > 0) - { - $(this).css('width', width+'px'); - } - var height = $(this).data('height') || 0; - if(height > 0) - { - $(this).css('height', height+'px'); - } - }); - } - }); - } + // 左边最后一列、右边第一列设置阴影样式 + $('.am-table-scrollable-horizontal > table tr').each(function(k, v) + { + $(this).find('.am-grid-fixed-left').last().addClass('am-grid-fixed-left-shadow'); + $(this).find('.am-grid-fixed-right').first().addClass('am-grid-fixed-right-shadow'); + }); + } }