Files
layui-admin/iframe/docs/docs.html

478 lines
22 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>layuiAdmin v2.x iframe 版 文档</title>
<meta name="description" content="">
<link href="//at.alicdn.com/t/font_24081_60slu02pimt.css" rel="stylesheet">
<link href="https://cdn.staticfile.org/layui/2.7.6/css/layui.css" rel="stylesheet">
<link href="static/dist/docs/2.7/css/global.css?t=118-1704302111161" rel="stylesheet">
<link href="static/dist/dev/css/index.css?t=118-1704302111161" rel="stylesheet">
<script>!function () {
if (self !== parent) try {
if (-1 !== parent.location.host.indexOf("layuion.com")) return
} catch (a) {
location.href = "about:blank"
}
}();</script>
<link rel="stylesheet" href="static/dist/dev/css/docs.css?t=118-1704302111161" charset="utf-8">
<style> .fly-footer {
border: none;
} </style>
</head>
<body class="fly-body-docs">
<div class="layui-header header header-docs">
<div class="layui-container">
<div class="ws-logo"><a href="/"> <img src="static/images/dev/logo.png" alt="layuion"> </a></div>
</div>
</div> <!-- Gird for ie 8/9 --> <!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script> <![endif]-->
<div class="layui-container">
<div class="fly-docs-container"><h1 class="fly-docs-title">layuiAdmin v2.x iframe 版 文档</h1>
<div class="layui-text fly-md-text" data-doc=&quot;0.000469605604273411&quot;>
<style>
body {
margin-top: 0;
padding-left: 220px;
}
.fly-body-docs .layui-container {
width: 100%
}
</style>
<blockquote>
<p>layuiAdmin iframe 版采用传统的 iframe
多页面开发模式,可更快速直接地开发网页管理系统模板,无需过多地学习成本,简单高效,更容易上手。</p>
</blockquote>
<div class="fly-md-dir">
<ul>
<li>
<p><a href="#quickstart">快速上手</a></p>
<ul>
<li><a href="#dir-desc">目录说明</a></li>
<li><a href="#deploy">部署到服务端</a></li>
<li><a href="#config">全局配置</a></li>
</ul>
</li>
<li>
<p><a href="#base-mehod">基础方法</a></p>
<ul>
<li><a href="#base-admin">admin 模块</a></li>
<li><a href="#base-view">view 模块</a></li>
</ul>
</li>
<li>
<p><a href="#openTabsPage">iframe 内部打开新标签</a></p>
</li>
<li>
<p><a href="#tabsTitle">自定义标签栏标题</a></p>
</li>
<li>
<p><a href="#util">实用组件</a></p>
</li>
<li>
<p><a href="#compatibility">兼容性</a></p>
</li>
<li>
<p><a href="#copyright">关于版权</a></p>
</li>
</ul>
</div>
<h2>前言</h2>
<ul>
<li>该文档适用于 <strong>layuiAdmin v2.x iframe 版的的最新版本</strong>,阅读之前请务必确认是否与你使用的版本对应。
</li>
<li>掌握 layuiAdmin 的前提是熟练掌握 layui因此除了本篇文档 <a href="https://layui.gitee.io/v2/docs/">layui
的文档</a> 也是必不可少的。
</li>
</ul>
<p><a name="quickstart"> </a></p>
<h2>快速上手</h2>
<p><a name="dir-desc"> </a></p>
<h3>目录说明</h3>
<p>解压文件后,你将看到以下目录:</p>
<pre>
<code>- res/ # 静态资源目录
- adminui/ # layuiAdmin 主题核心代码目录(重要:一般升级时主要替换此目录)
- dist/ # 主题核心代码构建后的目录(为主要引用)
- modules/ # 主题核心 JS 模块
- css/ # 主题核心 CSS 样式
- src/ # 主题核心源代码目录(不推荐引用,除非要改动核心代码),结构同 dist 目录
- json/ # 用于演示的模拟数据
- layui/ # layui 组件库(重要:若升级 layui 直接替换该目录即可)
- modules/ # 业务 JS 模块(可按照实际的业务需求进行修改)
- style/ # 业务 CSS 图片等资源目录
- views/ # 业务动态模板视图碎片目录
- config.js # 初始化配置文件
- index.js # 初始化主题入口模块
- views/ # 业务视图目录,可放置在项目任意目录(注意修改里面的 css、js 相关路径即可)
</code>
</pre>
<br>
<blockquote>
<p>注意:上述为当前 layuiAdmin v2.x iframe 最新版本的目录结构</p>
</blockquote>
<p><a name="deploy"> </a></p>
<h3>部署到服务端</h3>
<ol>
<li><em>views</em> 文件夹整个复制到你 <em>服务端工程</em> 的 view 层中,通过本地 web 服务器访问Tomcat
/ IIS / Apache / Nginx 等)
</li>
<li>确保可以访问后,修改好 HTML 文件中的 JS/CSS 路径,即可正常运行页面。</li>
</ol>
<blockquote>
<p><em>iframe 版</em> 相比于 <em>单页面版</em> ,无论是在目录结构还是开发模式上都要简单很多。因为单页版是接管了服务端
MVC 的视图层,而 iframe 版则将视图交给了服务端来控制和输出,可以避免鉴权的复杂程度,直接可衔接好新老项目(因为你们的大部分老项目都是采用
iframe 模式)。</p>
</blockquote>
<p><a name="config"> </a></p>
<h3>全局配置</h3>
<p>res 目录中的 <code>config.js</code>,里面存储着所有的默认配置项。你可以按照实际需求选择性修改:</p>
<pre><code class="language-js">layui.define(['all'], function(exports){
exports('setter', {
paths: { // v1.9.0 及以上版本的写法
core: layui.cache.base + 'adminui/dist/', // 核心库所在目录
views: layui.cache.base + 'views/', // 动态模板所在目录
modules: layui.cache.base + 'modules/', // 业务模块所在目录
base: layui.cache.base // 记录静态资源所在基础目录
},
/* v1.9.0 之前的写法
// views: layui.cache.base + 'views/', // 业务视图所在目录
// base: layui.cache.base, // 记录静态资源所在基础目录
*/
container: 'LAY_app', // 容器ID
entry: 'index', // 默认视图文件名
engine: '.html', // 视图文件后缀名
pageTabs: true, // 是否开启页面选项卡功能。iframe 版推荐开启
refreshCurrPage: true, // 当跳转页面 url 与当前页 url 相同时,是否自动执行刷新 --- 2.0+
name: 'layuiAdmin',
tableName: 'layuiAdmin', // 本地存储表名
MOD_NAME: 'admin', // 模块事件名
// 记忆
record: {
url: true // 是否开启 iframe 跳转时 url 记忆功能 --- 2.0+
},
debug: true, // 是否开启调试模式。如开启,接口异常时会抛出异常 URL 等信息
// 自定义请求字段
request: {
tokenName: false // 自动携带 token 的字段名access_token。可设置 false 不携带。
},
// 自定义响应字段
response: {
statusName: 'code', // 数据状态的字段名称
statusCode: {
ok: 0, // 数据状态一切正常的状态码
logout: 1001 // 登录状态失效的状态码
},
msgName: 'msg', // 状态信息的字段名称
dataName: 'data' // 数据详情的字段名称
},
// 配置业务模块目录中的特殊模块
extend: {
layim: 'layim/layim' // layim
},
// 主题配置
theme: {
// 配色方案,如果用户未设置主题,第一个将作为默认
color: [{
main: '#20222A', // 主题色
selected: '#009688', // 选中色
logo: '', // logo 区域背景色
header: '', // 头部区域背景色
alias: 'default' // 默认别名
}], // 为了减少篇幅,更多主题此处不做列举,可直接参考 config.js
// 初始的颜色索引,对应上面的配色方案数组索引
// 如果本地已经有主题色记录,则以本地记录为优先,除非清除 LocalStorage步骤F12呼出调试工具→Aplication→Local Storage→选中页面地址→layuiAdmin→再点上面的X
// 1.0 正式版开始新增
initColorIndex: 0
}
});
});
</code></pre>
<p><a name="base-mehod"> </a></p>
<h2>基础方法</h2>
<ul>
<li><strong>config 模块</strong></li>
</ul>
<blockquote>
<p>你可以在任何地方通过 <code>layui.setter</code> 得到 <em>config.js</em> 中的配置信息。如:<code>layui.setter.base</code>
</p>
</blockquote>
<p><a name="base-admin"> </a></p>
<ul>
<li><strong>admin 模块</strong></li>
</ul>
<blockquote>
<p>var admin = layui.admin;</p>
</blockquote>
<ul>
<li>
<p><strong>admin.req(options)</strong><br>
Ajax 请求,用法同 $.ajax(options),只是该方法会进行错误处理</p>
</li>
<li>
<p><strong>admin.screen()</strong><br>
获取屏幕类型,根据当前屏幕大小,返回 0 - 3 的值<br>
0: 低于768px的屏幕<br>
1768px到992px之间的屏幕<br>
2992px到1200px之间的屏幕<br>
3高于1200px的屏幕</p>
</li>
<li>
<p><strong>admin.sideFlexible(status)</strong><br>
侧边伸缩。status 为 null收缩status为 “spread”展开</p>
</li>
<li>
<p><strong>admin.on(eventName, callback)</strong></p>
</li>
</ul>
<table class="layui-table">
<thead>
<tr>
<th>eventName</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>tabsPage</td>
<td>标签页切换事件</td>
</tr>
<tr>
<td>side</td>
<td>侧边栏伸缩事件</td>
</tr>
</tbody>
</table>
<ul>
<li>
<p><strong>admin.popup(options)</strong><br>
弹出一个 layuiAdmin 主题风格的 layer 层,参数 options 跟 layer.open(options) 完全相同</p>
</li>
<li>
<p><strong>admin.popupRight(options)</strong><br>
在屏幕右侧呼出一个面板层。options 同上。</p>
</li>
</ul>
<pre><code>admin.popupRight({
id: 'LAY-popup-right-new1' //定义唯一ID防止重复弹出
,success: function(){
//将 views 目录下的某视图文件内容渲染给该面板
layui.view(this.id).render('视图文件所在路径');
}
});
</code></pre>
<ul>
<li>
<p><strong>admin.resize(callback)</strong><br>
窗口 resize 事件处理,我们推荐你使用该方法取代 jQuery 的 resize 事件,以避免多页面标签下可能存在的冲突。
</p>
</li>
<li>
<p><strong>admin.fullScreen()</strong><br>
全屏</p>
</li>
<li>
<p><strong>admin.exitScreen()</strong><br>
退出全屏</p>
</li>
<li>
<p><strong>admin.events</strong></p>
<ul>
<li>
<p>admin.events.refresh()<br>
刷新当前右侧区域</p>
</li>
<li>
<p>admin.events.closeThisTabs()<br>
关闭当前标签页</p>
<blockquote>
<p>注意:如果是在 iframe 页面中执行关闭,需要如下写法:</p>
<blockquote>
<p>parent.layui.admin.events.closeThisTabs();</p>
</blockquote>
</blockquote>
</li>
<li>
<p>admin.events.closeOtherTabs()<br>
关闭其它标签页</p>
</li>
<li>
<p>admin.events.closeAllTabs()<br>
关闭全部标签页</p>
</li>
</ul>
</li>
</ul>
<p><a name="base-view"> </a></p>
<ul>
<li><strong>view 模块</strong></li>
</ul>
<blockquote>
<p>var view = layui.view;</p>
</blockquote>
<ul>
<li><strong>view(id)</strong><br>
获取指定容器,并返回一些视图渲染的方法,如:</li>
</ul>
<pre><code>//渲染视图viewPath 即为视图路径
view('id').render(viewPath).then(function(){
//视图文件请求完毕,视图内容渲染前的回调
}).done(function(){
//视图文件请求完毕和内容渲染完毕的回调
});
</code></pre>
<p>也可以通过 <code>send</code> 方法直接向容器中插入模板:</p>
<pre><code>//tpl 为 模板字符data 是传入的数据。该方法会自动完成动态模板解析
view('id').send(tpl, data);
</code></pre>
<p>一般我们还是推荐 <code>render</code> 方法,因为它请求的是一个独立的模板碎片,可以保证代码的可维护性。该方法同样支持动态传参,并可在视图的动态模板中使用。如:</p>
<pre><code>admin.popup({
id: 'LAY-popup-test1'
,success: function(){
view(this.id).render('视图文件所在路径', {
id: 123 //这里的 id 值你可以在一些事件中动态获取(如 table 模块的编辑)
});
}
});
</code></pre>
<p>那么,在视图文件中,你可以在动态模板中通过 <code>{{ d.params.xxx }}</code> 得到传入的参数,如:</p>
<pre><code>&lt;script type=&quot;text/html&quot; template lay-url=&quot;http://api.com?id={{ d.params.id }}&quot;&gt;
配置了接口的动态模板,且接口动态获取了 render 传入的参数:{{ d.params.id }}
&lt;/script&gt;
&lt;script type=&quot;text/html&quot; template&gt;
也可以直接获取:&lt;input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;{{ d.params.id }}&quot;&gt;
&lt;/script&gt;
</code></pre>
<p><strong>而如果是在 JS 语句中去获取模板传递过来的变量,可以借助动态模板的 lay-done 属性去实现,如:</strong></p>
<pre><code>&lt;script type=&quot;text/html&quot; template lay-done=&quot;layui.data.sendParams(d.params)&quot;&gt;
&lt;/script&gt;
</code></pre>
<p>然后在 JS 语句中通过执行动态模板 lay-done 中对应的方法得到对应的参数值:</p>
<pre><code>&lt;script&gt;
//定义一个 lay-done 对应的全局方法,以供动态模板执行
layui.data.sendParams = function(params){
console.log(params.id) //得到传递过来的 id 参数(或其他参数)值
//通过得到的参数值,做一些你想做的事
//…
//若需用到 layui 组件layui.use 需写在该全局方法里面,如:
layui.use(['table'], function(){
var table = layui.table;
table.render({
elem: ''
,url: 'url?id='+ params.id
});
});
};
&lt;/script&gt;
</code></pre>
<p>总之,驾驭好 <code>view().render().done(callback)</code> 对您的项目开发至关重要。</p>
<p><a name="openTabsPage"> </a></p>
<h2>在 iframe 页面内部打开新标签</h2>
<blockquote>
<p>通常你会涉及一些在右侧 iframe 页面内部去打开一个新标签的需求,目前有以下方式可以实现</p>
</blockquote>
<h3>方法一:</h3>
<p>直接在 a 标签上加上相关属性</p>
<pre><code>&lt;a lay-href=&quot;url&quot;&gt;文本&lt;/a&gt;
</code></pre>
<h3>方法二:</h3>
<p>调用 index 模块的相关方法</p>
<pre><code>// 这里要注意的是 parent 的层级关系。
parent.layui.admin.openTabsPage({
url: '',
title: ''
});
// 注意v2.0.0 之前的版本写法为
// parent.layui.index.openTabsPage(url, title);
</code></pre>
<p><a name="tabsTitle"> </a></p>
<h2>自定义标签栏标题</h2>
<blockquote>
<p>每当你打开一个标签页,头部都会出现标题。它默认读取的是所点元素的文本,但是你也可以自定义标题。</p>
</blockquote>
<pre><code>&lt;a lay-href=&quot;url&quot; lay-title=&quot;自定义标题文本&quot;&gt;默认读取的文本&lt;/a&gt;
</code></pre>
<ul>
<li>值得说明的是,只要你配置了上述的 <code>lay-href</code> 属性,就会打开一个新的标签,如果要在当前标签跳转,直接配置
<code>href=&quot;&quot;</code> 属性即可。
</li>
</ul>
<p><a name="util"> </a></p>
<h2>实用组件</h2>
<h3>Hover 提示层</h3>
<p>通过对元素设置 <code>lay-tips=&quot;提示内容&quot;</code> 来开启一个 hover 提示,如:</p>
<pre><code>&lt;i class=&quot;layui-icon layui-icon-tips&quot; lay-tips=&quot;要支持的噢&quot; lay-offset=&quot;5&quot;&gt;&lt;/i&gt;
</code></pre>
<p>其中 <code>lay-offset</code> 用于定于水平偏移距离单位px以调整箭头让其对准元素</p>
<p><a name="compatibility"> </a></p>
<h2>兼容性</h2>
<p>layuiAdmin 使用到了 layui 的栅格系统而栅格则是基于浏览器的媒体查询。ie8、9不支持。<br>
所以要在 views 目录的 html 文件中加上下面这段代码保证兼容:</p>
<pre><code class="language-html">&lt;!-- 让IE8/9支持媒体查询从而兼容栅格 --&gt;
&lt;!--[if lt IE 9]&gt;
&lt;script src=&quot;https://cdn.staticfile.org/html5shiv/r29/html5.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js&quot;&gt;&lt;/script&gt;
&lt;![endif]--&gt;
</code></pre>
<p><a name="copyright"> </a></p>
<h2>关于版权</h2>
<blockquote>
<p>layuiAdmin
受国家计算机软件著作权保护,禁止公开及传播模板源文件、盗版及非法倒卖等,违者将自行承担相应的法律责任。</p>
</blockquote>
<p>© layuiAdmin</p>
<i icon="0.000058700699999266244"></i></div>
</div>
</div>
<div id="FLY-spread-dir" class="layui-hide"><i class="layui-icon layui-icon-spread-left"></i></div>
<div class="fly-footer"><p>Copyright &copy; 2024 <a href="/">Layuion</a></p>
<p><span> 感谢 <a href="https://www.upyun.com/?invite=SJ0wu6g2-" target="_blank" rel="nofollow" sponsor="upyun"
class="layui-font-blue"> <strong>又拍云</strong> </a> 提供云加速支持 </span></p></div>
<div class="dev-shade"></div>
<script src="https://cdn.staticfile.org/layui/2.7.6/layui.js"></script>
<script> layui.cache.page = 'docs';
layui.cache.user = {
username: 'Isve丨勿言',
uid: 9739968,
avatar: '//q.qlogo.cn/qqapp/101235792/7869FC3424ABACFF58566A04C8ED411D/100',
experience: 629,
sum: 829,
vip: 3,
sex: ''
};
layui.config({
version: "118-1704302111161",
reshost: './',
RESPATH: 'static/dist/dev/'
}).extend({'fly': 'static/dist/dev/modules/index'}).use('fly'); </script>
<script> var _hmt = _hmt || [];
(function () {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?697ca70ccd7673d85e991c9168d9cc09";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})(); </script>
<link href="https://cdn.staticfile.org/highlight.js/11.5.1/styles/base16/google-dark.min.css" rel="stylesheet">
<script src="https://cdn.staticfile.org/highlight.js/11.5.1/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</body>
</html>