# TinyLayer **Repository Path**: se1per_php_code/tinylayer ## Basic Information - **Project Name**: TinyLayer - **Description**: 使用 Vue 开发的桌面端轻量级弹窗组件 - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: https://dreamer365.gitee.io/tinylayer/ - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 19 - **Created**: 2022-08-17 - **Last Updated**: 2022-08-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

TinyLayer

使用 Vue 开发的桌面端轻量级弹窗组件

在线示例


## 模式预览


## 组件特点 - 可同时兼容 vue2 和 vue3,无需为不同版本的 vue 安装不同的依赖包; - 提供了 5 种弹窗模式,包括:Alert、Confirm、Prompt、全屏 Loading、默认模式; - 丰富的配置功能,默认模式提供了多达 33 个可选配置项和 9 个可选事件,可满足各种开发需求。
## 安装引入 ```bash npm install tinylayer -S ``` **在 vue2 中引入** ```js // main.js 中引入并注册 import Vue from "vue"; import TinyLayer from "tinylayer"; Vue.use( TinyLayer ); ``` **在 vue3 中引入** ```js // main.js 中引入并注册 import { createApp } from "vue"; import App from "./App.vue"; const app = createApp( App ); import TinyLayer from "tinylayer"; app.use( TinyLayer ); ```
## Loading 模式 **vue2 中的用法** ```vue ``` **vue3 中的用法** ```vue ``` ## Loading 方法汇总 ```js // vue2 中的用法 this.$tinylayer.loading.open(); this.$tinylayer.loading.open( "Loading" ); this.$tinylayer.loading.open({ text: "Loading", background: "rgba(0, 0, 0, .9)", zIndex: 9999999 }); this.$tinylayer.loading.close(); // vue3 中的用法 import { getCurrentInstance } from "vue"; const { proxy } = getCurrentInstance(); proxy.$tinylayer.loading.open(); proxy.$tinylayer.loading.open( "Loading" ); proxy.$tinylayer.loading.open({ text: "Loading", background: "rgba(0, 0, 0, .9)", zIndex: 9999999 }); proxy.$tinylayer.loading.close(); ``` ## Loading 模式的配置属性(以对象形式传参)
属性 说明 类型 默认值
text 提示语 String -
background 背景色 String rgba(255, 255, 255, 0.95)
zIndex 层级 Number 2147483646


## Alert 模式 可用于替代浏览器自带的 `alert` 弹框 **vue2 中的用法** ```vue ``` **vue3 中的用法** ```vue ``` ## Alert 方法汇总 ```js // vue2.x 中的用法 this.$tinylayer.alert.info( "标题", "内容" ); this.$tinylayer.alert.success( "标题", "内容" ); this.$tinylayer.alert.warning( "标题", "内容" ); this.$tinylayer.alert.error( "标题", "内容" ); this.$tinylayer.alert.info({ title: "标题", content: "内容", zIndex: 999999, maskBackground: "rgba(255, 255, 255, .85)", ok: { text: "我知道了" } }); // vue3.x 中的用法 import { getCurrentInstance } from "vue"; const { proxy } = getCurrentInstance(); proxy.$tinylayer.alert.info( "标题", "内容" ); proxy.$tinylayer.alert.success( "标题", "内容" ); proxy.$tinylayer.alert.warning( "标题", "内容" ); proxy.$tinylayer.alert.error( "标题", "内容" ); proxy.$tinylayer.alert.info({ title: "标题", content: "内容", zIndex: 999999, maskBackground: "rgba(255, 255, 255, .85)", ok: { text: "我知道了" } }); ``` ## Alert 模式的配置属性(以对象形式传参)
属性 说明 类型 默认值
title 标题 String -
content 内容 String -
zIndex 层级 Number 20000
maskBackground 遮罩层背景色 String rgba(0, 0, 0, 0.7)
ok.text 确定按钮的文字 String 确定


## Confirm 模式 可用于替代浏览器自带的 `confirm` 弹框 **vue2 中的用法** ```vue ``` **vue3 中的用法** ```vue ``` ## Confirm 方法汇总 ```js // vue2.x 中的用法 this.$tinylayer.confirm.open({ title: "标题", content: "内容", zIndex: 999999, maskBackground: "rgba(255,255,255,.85)", ok: { text: "我知道了" } }); this.$tinylayer.confirm.close(); // vue3.x 中的用法 import { getCurrentInstance } from "vue"; const { proxy } = getCurrentInstance(); proxy.$tinylayer.confirm.open({ title: "标题", content: "内容", zIndex: 999999, maskBackground: "rgba(255,255,255,.85)", ok: { text: "我知道了" } }); proxy.$tinylayer.confirm.close(); ``` ## Confirm 模式的配置属性(以对象形式传参)
属性 说明 类型 默认值
title 标题 String -
content 内容 String -
zIndex 层级 Number 20000
maskBackground 遮罩层背景色 String rgba(0, 0, 0, 0.7)
ok.text 确定按钮的文字 String 确定
ok.callback 点击确定按钮执行的回调事件 Function 空函数
cancel.text 取消按钮的文字 String 取消
cancel.callback 点击取消按钮执行的回调事件 Function 空函数


## Prompt 模式 可用于替代浏览器自带的 `prompt` 弹框 **vue2 中的用法** ```vue ``` **vue3 中的用法** ```vue ``` ## Prompt 方法汇总 ```js // vue2.x 中的用法 this.$tinylayer.prompt.open({ title: "标题", content: "内容", ok: { text: "验证" } }); this.$tinylayer.prompt.close(); // vue3.x 中的用法 import { getCurrentInstance } from "vue"; const { proxy } = getCurrentInstance(); proxy.$tinylayer.prompt.open({ title: "标题", content: "内容", ok: { text: "验证" } }); proxy.$tinylayer.prompt.close(); ``` ## Prompt 模式的配置属性(以对象形式传参)
属性 说明 类型 默认值
title 标题 String -
zIndex 层级 Number 20000
maskBackground 遮罩层背景色 String rgba(0, 0, 0, 0.7)
defaultValue 输入框默认值 String -
placeholder 输入框提示语 String -
inputType 输入框类型,可选值:text, password String text
pattern 用于校验输入值的正则表达式 RegExp -
errorMsg 错误提示语 String ""
ok.text 确定按钮的文字 String 确定
ok.callback 点击确定按钮执行的回调事件,参数:
1. prompt 所有属性的集合
2. 输入框的值
3. 如果设置了 pattern 属性,则返回校验结果的布尔值
Function 空函数
ok.closable 点击确定按钮可关闭弹窗 Boolean true
cancel.text 取消按钮的文字 String 取消
cancel.callback 点击取消按钮执行的回调事件 Function 空函数


## 默认模式 **vue2 中的用法** ```vue ``` **vue3 中的用法** ```vue ```
## 默认模式的配置属性
属性 说明 类型 默认值
id 自定义的弹窗唯一 id 标识 String -
class-name 自定义的弹窗类名(多个类名之间用空格分隔) String -
z-index 弹窗的层级 Number 10000
mask-visible 显示遮罩层 Boolean true
mask-closable 点击遮罩层可以关闭弹窗 Boolean false
mask-background 遮罩层背景色 String rgba(0, 0, 0, 0.75)
fullscreen 默认全屏显示(并非浏览器按下 F11 的全屏模式,而是铺满网页可视区域) Boolean false
insert-iframe 内容区域嵌入 iframe 的地址(一旦嵌入 iframe,设置的其它内容将失效) String -
background 弹窗的背景色 String #fff
auto-close 自动关闭的倒计时时长,单位:ms(设置为 0 则不开启此功能) Number 0
auto-close-intercept 自动关闭功能的拦截器,到达自动关闭所设置的时长后将拦截关闭功能 Boolean false
destroy-after-close 关闭弹窗后销毁弹窗 Boolean true
esc-closable 按下 Esc 键可关闭弹窗 Boolean true
draggable 开启拖动功能(按住头部区域即可拖动) Boolean false
body-scrollable 打开弹窗后允许页面滚动 Boolean true
header-visible 显示头部 Boolean true
footer-visible 显示尾部 Boolean true
content-background 内容区域的背景色 String ""
content-loading 显示内容区域的 loading 层 Boolean false
content-loading-text 内容区域的 loading 层的提示信息 String -
content-loading-background 内容区域的 loading 层的背景色 String rgba(255, 255, 255, 0.95)
content-height 内容区域高度(可设置百分比或 px 单位) String auto
noline 去除头尾与内容区域的分割线 Boolean false
title 弹窗标题 String -
width 弹窗宽度(可设置百分比或 px 单位,最小有效值为 300px) String 450px
close-icon-visible 头部右侧显示关闭图标 Boolean true
fullscreen-icon-visible 头部右侧显示全屏切换图标 Boolean false
ok-text 确定按钮文本 String 确定
ok-visible 显示确定按钮 Boolean true
ok-disabled 禁用确定按钮 Boolean false
ok-closable 点击确定按钮可以关闭弹窗 Boolean true
ok-loading(v1.0.1 新增) 确定按钮加载中效果 Boolean false
cancel-text 取消按钮文本 String 取消
cancel-visible 显示取消按钮 Boolean true
## 默认模式的事件
事件名 说明 回调参数
fullscreen-change 全屏状态改变时的回调 代表全屏状态的布尔值
ok 点击确定按钮的回调 -
cancel 点击取消按钮的回调 -
after-open 弹窗打开动画结束后的回调 -
after-close 弹窗关闭动画结束后的回调 -
dragging 拖动弹窗时的回调 弹窗左上角的横纵坐标值
drag-end 弹窗拖动结束时的回调 弹窗左上角的横纵坐标值
auto-close-countdown 自动关闭的倒计时回调 倒计时的毫秒数和秒数
auto-close-intercept 到达自动关闭所设置的时长时的回调 -
## 默认模式的插槽
插槽名 说明
header 弹窗头部内容
footer 弹窗尾部内容

## 浏览器支持 | Chrome | Firefox | Opera | Edge | Safari | IE | | --- | --- | --- | --- | --- | --- | | last 2 versions | last 2 versions | last 2 versions | last 2 versions | last 2 versions | 不支持 |