前端框架 EasyUI (2)页面布局 Layout

  在 Web 程序中,页面布局对应用程序的用户体验至关重要。

  在一般的信息管理类的 Web 应用程序中,页面结构通常有一个主工作区,然后在工作区上下左右靠近边界的区域设置一些边栏,用于显示信息或放置一些功能选项的控件。比如下面这两个比较典型的例子:

   

  EasyUI 提供了一种非常简单方便的实现该效果的方法,可以让用户很方便的在页面上实现矩形区域划分的功能,这就是 EasyUI 的布局组件(Layout)。

EasyUI 布局组件Layout

  EasyUI 的布局组件允许用户在一个主工作区的四周各添加一个边栏,EasyUI 将自动为用户实现边界划分和边界位置控制功能。

  EasyUI 的布局组件需要基于一个布局容器,比如一个<div>,当然也可以使用整个<body>。将一个容器设置为 EasyUI 布局容器的方法很简单,只需要添加一个控件样式类 easyui-layout 就行了。

  然后,在布局容器中至少要添加一个主工作区 center。在主工作区四周,可以分别添加一个边栏,以上北、下南、左西、右东的规则,分别标记为nouth(上)、south(下)、west(左)、east(右)。工作区的名字标记为容器标签的 region 属性。

  例如,下面代码实现将一个300*300的<div>划分为5个区,左右侧区域宽度各100,其它自动:

复制代码
<div class="easyui-layout" style="width:300px; height:300px;">
    <div region="north">顶部</div>
    <div region="west" style="width:100px">左侧</div>
    <div region="center">主工作区</div>
    <div region="east" style="width:100px">右侧</div>
    <div region="south">底部</div>
</div>
复制代码

 

  显示效果如图:

  

(IE11)

  如果将页面中 <body> 标签定义为布局容器,那么 EasyUI 可以将整个浏览器的工作区划分为5个区域。

  需要注意的一点是,主工作区左侧和右侧的边栏必须要设置宽度,否则布局将不能正常显示。

Layout 常用属性

  Layout 可以为工作区设置标题;也可以将工作区边栏设置为可变大小,以便用户使用鼠标拖动改变工作区大小。这两个功能分别是 title 属性(string)和 split 属性(bool)。

  例如:下面代码将左侧边栏标题设置为“导航菜单”,并且大小可变:

复制代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="js/easyui-1.4.2/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="js/easyui-1.4.2/themes/icon.css" />
    <script type="text/javascript" src="js/easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="js/easyui-1.4.2/jquery.easyui.min.js" ></script>
</head>

<body class="easyui-layout">
    <div region="north">顶部</div>
    <div region="west" style="width:100px" title="导航菜单" split="true">左侧</div>
    <div region="center">主工作区</div>
    <div region="east" style="width:100px">右侧</div>
    <div region="south">底部</div>
</body>
</html>
复制代码

 

  在浏览器执行效果如图:

(IE11)

 

  当然,如果需要设置上侧或下侧边栏的大小,设置相应的<div>标签的高度即可。

 

  示例源码:http://files.cnblogs.com/files/zhhh/EasyUI-2.zip

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Sure! Here's an example of how you can upload an Excel file, store its data in a database, and display it on the front-end using the MVC pattern and the EasyUI framework: 1. Create the necessary database table to store the Excel data. Let's assume the table is named `excel_data` and has columns `id`, `name`, and `email`. 2. Create a file named `index.php` for the front-end view using EasyUI: ```html <!DOCTYPE html> <html> <head> <title>Excel Upload</title> <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/easyui@1.9.25/themes/default/easyui.css"> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/easyui@1.9.25/jquery.easyui.min.js"></script> </head> <body> <h2>Excel Upload</h2> <form id="excelForm" method="post" enctype="multipart/form-data"> <input id="excelFile" name="excelFile" type="file"> <button id="uploadBtn" class="easyui-linkbutton" type="submit">Upload</button> </form> <table id="datagrid"></table> <script type="text/javascript"> $(function(){ $('#excelForm').form({ url: 'upload.php', onSubmit: function(){ return $(this).form('validate'); }, success: function(result){ $('#datagrid').datagrid('reload'); $.messager.show({ title: 'Success', msg: result, timeout: 5000 }); } }); $('#datagrid').datagrid({ url: 'data.php', fitColumns: true, columns: [[ {field: 'id', title: 'ID', width: 50}, {field: 'name', title: 'Name', width: 100}, {field: 'email', title: 'Email', width: 150} ]] }); }); </script> </body> </html> ``` 3. Create a file named `upload.php` to handle the file upload and data insertion into the database: ```php <?php require_once 'PHPExcel/PHPExcel.php'; // Database connection details $host = 'localhost'; $username = 'your_username'; $password = 'your_password'; $database = 'your_database'; // File upload directory $targetDir = 'uploads/'; if (!is_dir($targetDir)) { mkdir($targetDir, 0777, true); } $targetFile = $targetDir . basename($_FILES["excelFile"]["name"]); move_uploaded_file($_FILES["excelFile"]["tmp_name"], $targetFile); $objPHPExcel = PHPExcel_IOFactory::load($targetFile); $worksheet = $objPHPExcel->getActiveSheet(); $conn = new mysqli($host, $username, $password, $database); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } foreach ($worksheet->getRowIterator() as $row) { $rowData = []; $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); foreach ($cellIterator as $cell) { $rowData[] = $cell->getValue(); } $sql = "INSERT INTO excel_data (name, email) VALUES (?, ?)"; $stmt = $conn->prepare($sql); $stmt->bind_param("ss", $rowData[0], $rowData[1]); $stmt->execute(); } $conn->close(); unlink($targetFile); echo "Upload successful!"; ?> ``` 4. Create a file named `data.php` to fetch the data from the database and return it as JSON for the front-end grid: ```php <?php // Database connection details $host = 'localhost'; $username = 'your_username'; $password = 'your_password'; $database = 'your_database'; $conn = new mysqli($host, $username, $password, $database); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM excel_data"; $result = $conn->query($sql); $data = array(); while ($row = $result->fetch_assoc()) { $data[] = $row; } $conn->close(); echo json_encode($data); ?> ``` Make sure to replace `'your_username'`, `'your_password'`, and `'your_database'` with your actual database credentials. This example follows the MVC pattern by separating the front-end view (`index.php`), the controller (`upload.php`), and the model (`data.php`). Remember to include the PHPExcel library in the appropriate locations and adjust the file paths accordingly. I hope this example helps you with uploading an Excel file, storing the data in a database, and displaying it on the front-end using the MVC pattern and EasyUI framework. Let me know if you have any further questions!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值