mirror of
https://github.com/layui/layui.git
synced 2026-02-09 10:19:20 +08:00
* style: 统一代码格式,修复ESLint错误 - 为所有模块添加尾随逗号 - 修复缺少分号的语句 - 统一对象字面量格式 - 添加ESLint配置文件和文档 - 更新package.json中的脚本和依赖项 * build: 添加 ESLint 配置文件以支持 IE9+ 兼容性 * refactor(upload): 使用已缓存的hint实例替换直接调用 优化代码性能,避免重复实例化hint对象,直接使用模块顶部已缓存的实例 * chore: 更新.gitignore文件以包含更多忽略规则 添加了更多常见的临时文件、编辑器文件、构建输出目录和运行时数据的忽略规则,使项目更加整洁并避免不必要的文件被提交到版本控制中 * fix(lay.js): 修复passive事件监听器选项的返回值 确保getter函数返回true以正确支持passive事件监听 * refactor(form): 移除表单模块中的冗余代码 删除表单模块中无实际作用的冗余代码行,这些代码只是将属性重新赋值为自身,没有实际功能意义 * fix(form): 修复复选框状态处理逻辑 确保复选框的 indeterminate 和 checked 状态被正确转换为布尔值,并优化事件调用时的空格格式 * feat(eslint): 完善 ESLint 配置并添加 VSCode 支持 添加 VSCode 配置文件以支持 ESLint 自动修复和格式化 更新 ESLint 配置,增强代码风格和兼容性规则 修复 package.json 中的脚本拼写错误并添加 format 脚本 调整 .gitignore 以允许特定 VSCode 配置文件 * style: 统一代码中的引号格式并修复缩进问题 统一将双引号改为单引号,修复部分代码缩进不一致的问题,提升代码风格一致性 * docs: 删除过时的ESLint配置文档文件 * build: 采用 prettier 作为代码格式化工具,剔除 ESLint 格式化部分 * chore: 剔除 .vscode/ 配置,保持编辑器中立 * build: 修改 ESLint 为「扁平化配置」方式,避免大量参数堆砌 * chore: 格式化代码 * ci: 添加 git hooks 和 CI 环节把关代码风格 * ci: update * ci: update * test: 测试 ci format * ci: 改用 husky 作为 git hooks,与 Layui 3 保持一致 经测试,simple-git-hooks 生成的 pre-commit 默认为 sh,在 Windows 不兼容(必须用 git bash 执行 commits) * build: 新增 CI 和生产环境跳过 husky 安装的判断 * build: 剔除重复配置 * build: 优化 eslint 配置 --------- Co-authored-by: 贤心 <3277200+sentsim@users.noreply.github.com>
380 lines
10 KiB
HTML
380 lines
10 KiB
HTML
<!doctype html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta
|
||
name="viewport"
|
||
content="width=device-width, initial-scale=1, maximum-scale=1"
|
||
/>
|
||
<title>下拉菜单 - layui</title>
|
||
|
||
<link rel="stylesheet" href="../src/css/layui.css" />
|
||
</head>
|
||
<body>
|
||
<div class="layui-container">
|
||
<div class="layui-btn-container" style="padding: 30px 0">
|
||
<button class="layui-btn" id="demo1">
|
||
按钮下拉
|
||
<i class="layui-icon layui-icon-down layui-font-12"></i>
|
||
</button>
|
||
<button class="layui-btn layui-btn-primary" id="demo2">
|
||
按钮下拉
|
||
<i class="layui-icon layui-icon-down layui-font-12"></i>
|
||
</button>
|
||
</div>
|
||
|
||
<div class="layui-text">
|
||
<a href="javascript:;" id="demo3"
|
||
>文字下拉 <i class="layui-icon layui-icon-down"></i
|
||
></a>
|
||
</div>
|
||
|
||
<div class="layui-btn-container">
|
||
<a href="javascript:;" id="testopen"
|
||
>testopen <i class="layui-icon layui-icon-down"></i
|
||
></a>
|
||
<button class="layui-btn" lay-on="open">open</button>
|
||
<button class="layui-btn" lay-on="close">close</button>
|
||
</div>
|
||
|
||
<div
|
||
class="layui-bg-gray"
|
||
style="margin-top: 30px; width: 100%; height: 300px; text-align: center"
|
||
id="ID-dropdown-demo-contextmenu"
|
||
>
|
||
<span class="layui-font-gray" style="position: relative; top: 50%"
|
||
>鼠标右键菜单</span
|
||
>
|
||
</div>
|
||
<button class="layui-btn" style="margin-top: 15px" lay-on="contextmenu">
|
||
开启全局右键菜单
|
||
</button>
|
||
</div>
|
||
|
||
<script src="../src/layui.js"></script>
|
||
<script>
|
||
layui.use('dropdown', function () {
|
||
var dropdown = layui.dropdown;
|
||
var util = layui.util;
|
||
|
||
dropdown.render({
|
||
elem: '#demo1',
|
||
shade: [0.1, '#ddd'],
|
||
//,align: 'right'
|
||
data: [
|
||
{
|
||
title: 'menu item 1',
|
||
templet:
|
||
'<i class="layui-icon layui-icon-light"></i> {{= d.title }} <span class="layui-badge-dot"></span>',
|
||
id: '',
|
||
href: '',
|
||
type: '' //菜单类型,支持:normal/group/parent
|
||
},
|
||
{
|
||
title: 'menu item <strong>2</strong>',
|
||
templet:
|
||
'<img src="https://unpkg.com/outeres@0.1.1/demo/avatar/0.png" style="width: 16px;"> {{- d.title }}',
|
||
id: '',
|
||
href: 'https://www.layui.com/',
|
||
target: '_blank'
|
||
},
|
||
{ type: '-' },
|
||
{},
|
||
{
|
||
title: 'menu item 3 <hello>',
|
||
id: '',
|
||
type: 'group',
|
||
child: [
|
||
{
|
||
title: 'menu item 3-1',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 3-2',
|
||
id: '',
|
||
child: [
|
||
{
|
||
title: 'menu item 3-2-1',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 3-2-2',
|
||
id: '',
|
||
type: 'group',
|
||
child: [
|
||
{
|
||
title: 'menu item 3-2-2-1',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 3-2-2-2',
|
||
id: ''
|
||
}
|
||
]
|
||
},
|
||
{
|
||
title: 'menu item 3-2-3',
|
||
id: ''
|
||
}
|
||
]
|
||
},
|
||
{
|
||
title: 'menu item 3-3',
|
||
id: '',
|
||
type: 'group',
|
||
child: [
|
||
{
|
||
title: 'menu item 3-3-1',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 3-3-2',
|
||
id: '',
|
||
child: [
|
||
{
|
||
title: 'menu item 3-3-2-1',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 3-3-2-2',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 3-3-2-3',
|
||
id: ''
|
||
}
|
||
]
|
||
},
|
||
{
|
||
title: 'menu item 3-3-3',
|
||
id: ''
|
||
}
|
||
]
|
||
}
|
||
]
|
||
},
|
||
{ type: '-' },
|
||
{
|
||
title: 'menu item 4',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 5',
|
||
id: '',
|
||
child: [
|
||
{
|
||
title: 'menu item 5-1',
|
||
id: '',
|
||
child: [
|
||
{
|
||
title: 'menu item 5-1-1',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 5-1-2',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 5-1-3',
|
||
id: ''
|
||
}
|
||
]
|
||
},
|
||
{
|
||
title: 'menu item 5-2',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 5-3',
|
||
id: ''
|
||
}
|
||
]
|
||
},
|
||
{ type: '-' },
|
||
{
|
||
title: 'menu item 6',
|
||
id: '',
|
||
type: 'group',
|
||
isSpreadItem: false,
|
||
child: [
|
||
{
|
||
title: 'menu item 6-1',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 6-2',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 6-3',
|
||
id: ''
|
||
}
|
||
]
|
||
}
|
||
],
|
||
|
||
id: 'demo1',
|
||
|
||
// 触发点击事件的元素范围 --- default: 仅子菜单触发点击事件(默认,可不填); all: 所有父子菜单均触发点击事件
|
||
clickScope: 'all',
|
||
|
||
// 菜单被点击的事件
|
||
click: function (obj) {
|
||
console.log(obj);
|
||
}
|
||
});
|
||
|
||
var inst = dropdown.render({
|
||
elem: '#demo2',
|
||
// ,show: true
|
||
data: [
|
||
{
|
||
title: 'menu item 1',
|
||
href: '#1',
|
||
disabled: true
|
||
},
|
||
{
|
||
title: 'menu item 2(点击不关闭)',
|
||
href: '#2',
|
||
id: 'bbb'
|
||
},
|
||
{
|
||
title: 'menu item 3',
|
||
href: '#3'
|
||
}
|
||
],
|
||
click: function (data, othis) {
|
||
console.log(data);
|
||
if (data.id === 'bbb') {
|
||
return false;
|
||
}
|
||
},
|
||
ready: function () {
|
||
console.log(arguments);
|
||
},
|
||
close: function () {
|
||
console.log('demo2', this.elem);
|
||
}
|
||
});
|
||
|
||
dropdown.render({
|
||
elem: '#demo3',
|
||
content: '自定义内容 123 ',
|
||
style: 'background:#666;color:#fff;padding:15px;',
|
||
align: 'center',
|
||
trigger: 'hover',
|
||
close: function () {
|
||
console.log('demo3', this.elem);
|
||
}
|
||
});
|
||
|
||
// 右键
|
||
dropdown.render({
|
||
elem: '#ID-dropdown-demo-contextmenu', // 也可绑定到 document,从而重置整个右键
|
||
trigger: 'contextmenu', //contextmenu
|
||
isAllowSpread: false,
|
||
//,style: 'width: 200px'
|
||
customName: {
|
||
children: 'children'
|
||
},
|
||
data: [
|
||
{
|
||
title: 'menu item 1',
|
||
id: '#1'
|
||
},
|
||
{
|
||
title: 'menu item 2',
|
||
id: 'reload'
|
||
},
|
||
{ type: '-' },
|
||
{
|
||
title: 'menu item 3',
|
||
id: '#3',
|
||
children: [
|
||
{
|
||
title: 'menu item 3-1',
|
||
id: '#1'
|
||
},
|
||
{
|
||
title: 'menu item 3-2',
|
||
id: '#2'
|
||
},
|
||
{
|
||
title: 'menu item 3-3',
|
||
id: '#3'
|
||
}
|
||
]
|
||
},
|
||
{ type: '-' },
|
||
{
|
||
title: 'menu item 4',
|
||
id: ''
|
||
},
|
||
{
|
||
title: 'menu item 5',
|
||
id: '#1'
|
||
},
|
||
{
|
||
title: 'menu item 6',
|
||
id: '#1'
|
||
}
|
||
],
|
||
click: function (obj, othis) {
|
||
if (obj.id === 'reload') {
|
||
location.reload();
|
||
}
|
||
}
|
||
});
|
||
|
||
util.on({
|
||
// 改变触发右键菜单的目标元素
|
||
contextmenu: function (othis) {
|
||
var ID = 'ID-dropdown-demo-contextmenu';
|
||
if (!othis.data('open')) {
|
||
dropdown.reload(ID, {
|
||
elem: document // 设置全局元素右键
|
||
});
|
||
|
||
othis.html('取消全局右键菜单');
|
||
othis.data('open', true);
|
||
} else {
|
||
dropdown.reload(ID, {
|
||
elem: '#' + ID // 设置局部元素右键
|
||
});
|
||
|
||
othis.html('开启全局右键菜单');
|
||
othis.data('open', false);
|
||
}
|
||
}
|
||
});
|
||
|
||
dropdown.render({
|
||
elem: '#testopen',
|
||
id: 'testopen',
|
||
trigger: 'manual',
|
||
data: [{ id: 'refresh', title: '刷新' }]
|
||
});
|
||
|
||
util.on(
|
||
{
|
||
open: function () {
|
||
dropdown.open('testopen');
|
||
},
|
||
close: function () {
|
||
dropdown.close('testopen');
|
||
}
|
||
},
|
||
{ trigger: 'mouseenter' }
|
||
);
|
||
|
||
return;
|
||
|
||
dropdown.render({
|
||
elem: document,
|
||
content: '123'
|
||
});
|
||
});
|
||
</script>
|
||
</body>
|
||
</html>
|