This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0
wcui/src/layer/index.wc

829 lines
18 KiB
Plaintext
Raw Normal View History

2019-08-21 21:03:41 +08:00
<template>
<div class="layer">
<div class="layer__title noselect"></div>
<div class="layer__content"><slot></slot></div>
<div class="layer__ctrl noselect"></div>
</div>
</template>
2021-05-28 18:54:33 +08:00
2019-08-21 21:03:41 +08:00
<style lang="scss">
:host {
2019-09-04 18:12:41 +08:00
display: none;
2019-08-21 21:03:41 +08:00
justify-content: center;
align-items: center;
2019-09-04 20:56:15 +08:00
position: fixed;
z-index: 65534;
left: 0;
top: 0;
width: 100%;
2019-08-21 21:03:41 +08:00
}
2019-09-04 18:12:41 +08:00
:host([alert]),
:host([confirm]),
:host([prompt]),
:host([frame]),
:host([toast]),
:host([notify]),
:host([common]) {
display: flex;
}
2019-08-21 21:03:41 +08:00
.noselect {
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
img,
a {
-webkit-user-drag: none;
}
}
.layer {
overflow: hidden;
2019-08-21 21:03:41 +08:00
flex: 0 auto;
2020-07-24 13:55:12 +08:00
position: absolute;
2019-08-21 21:03:41 +08:00
z-index: 65535;
border-radius: 2px;
2019-08-21 21:03:41 +08:00
color: #666;
font-size: 14px;
2020-07-24 13:55:12 +08:00
background: rgba(255, 255, 255, 0.8);
2019-08-21 21:03:41 +08:00
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
2023-01-16 17:40:50 +08:00
transition: opacity 0.2s ease-in-out, left 0.2s ease-in-out,
right 0.2s ease-in-out, top 0.2s ease-in-out, bottom 0.2s ease-in-out;
2019-09-03 21:27:25 +08:00
opacity: 0;
2019-08-21 21:03:41 +08:00
2019-08-28 20:55:15 +08:00
&.scale {
transform: scale(1.01);
transition: transform 0.1s linear;
}
2019-08-26 19:23:04 +08:00
&.blur {
backdrop-filter: blur(5px);
}
2019-08-21 21:03:41 +08:00
&:active {
z-index: 65536;
}
/* 弹层样式 */
&__title {
display: none;
justify-content: space-between;
align-items: center;
2019-08-21 21:03:41 +08:00
width: 100%;
height: 60px;
padding: 15px;
2019-08-21 21:03:41 +08:00
font-size: 16px;
2020-12-14 14:44:05 +08:00
color: var(--color-dark-2);
wc-icon {
--size: 14px;
&:hover {
2020-12-14 14:44:05 +08:00
color: var(--color-red-1);
}
}
2019-08-21 21:03:41 +08:00
}
&__content {
2019-08-28 19:06:13 +08:00
display: flex;
2019-08-21 21:03:41 +08:00
position: relative;
width: 100%;
height: auto;
min-height: 50px;
word-break: break-all;
word-wrap: break-word;
2019-08-28 19:06:13 +08:00
::slotted(&__input) {
flex: 1;
2021-04-14 10:02:41 +08:00
height: 36px;
2019-08-28 19:06:13 +08:00
}
::slotted(&__frame) {
display: flex;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
border: 0;
resize: none;
2019-09-03 21:27:25 +08:00
background: #fff;
}
::slotted(&__toast) {
display: flex;
align-items: center;
width: 300px;
padding: 0 10px !important;
2021-05-28 18:54:33 +08:00
border-radius: 3px;
font-weight: normal;
2021-05-28 18:54:33 +08:00
text-indent: 8px;
--size: 16px;
2021-05-28 18:54:33 +08:00
color: var(--color-dark-1);
2019-09-03 21:27:25 +08:00
}
::slotted(&__toast.style-info) {
border: 1px solid #ebeef5;
background: #edf2fc;
color: var(--color-grey-3);
2019-09-03 21:27:25 +08:00
}
2019-12-20 17:45:36 +08:00
::slotted(&__toast.style-success) {
border: 1px solid #e1f3d8;
background: #f0f9eb;
color: var(--color-green-3);
2019-12-20 17:45:36 +08:00
}
::slotted(&__toast.style-warning) {
border: 1px solid #faebb4;
background: #faecd8;
color: var(--color-red-1);
2019-09-03 21:27:25 +08:00
}
::slotted(&__toast.style-error) {
border: 1px solid #f5c4c4;
background: #fde2e2;
color: var(--color-red-1);
2019-08-28 19:06:13 +08:00
}
2019-08-21 21:03:41 +08:00
}
&__ctrl {
display: none;
2019-08-28 19:06:13 +08:00
justify-content: flex-end;
2019-08-21 21:03:41 +08:00
width: 100%;
height: 60px;
padding: 15px;
2019-08-21 21:03:41 +08:00
line-height: 30px;
font-size: 14px;
color: #454545;
text-align: right;
2019-08-26 17:34:07 +08:00
button {
min-width: 64px;
height: 30px;
padding: 0 10px;
margin: 0 5px;
2020-12-14 14:44:05 +08:00
border: 1px solid var(--color-plain-3);
border-radius: 2px;
2019-08-26 17:34:07 +08:00
white-space: nowrap;
background: #fff;
font-size: inherit;
2019-09-05 11:26:14 +08:00
font-family: inherit;
2019-08-26 17:34:07 +08:00
outline: none;
color: inherit;
&:hover {
2020-12-14 14:44:05 +08:00
background: var(--color-plain-1);
2019-08-26 17:34:07 +08:00
}
&:active {
2020-12-14 14:44:05 +08:00
border-color: var(--color-grey-1);
2019-08-26 17:34:07 +08:00
}
&:focus {
box-shadow: 0 0 0 2px var(--color-plain-a);
}
2019-08-26 17:34:07 +08:00
&:last-child {
color: #fff;
2020-12-14 14:44:05 +08:00
background: var(--color-teal-2);
2019-08-26 17:34:07 +08:00
border-color: transparent;
&:hover {
2020-12-14 14:44:05 +08:00
background: var(--color-teal-1);
2019-08-26 17:34:07 +08:00
}
&:active {
2020-12-14 14:44:05 +08:00
background: var(--color-teal-3);
2019-08-26 17:34:07 +08:00
}
&:focus {
box-shadow: 0 0 0 2px var(--color-teal-a);
}
2019-08-26 17:34:07 +08:00
}
&::-moz-focus-inner {
border: none;
}
}
2019-08-21 21:03:41 +08:00
}
}
:host([mask]) {
height: 100%;
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(5px);
}
2019-09-04 18:12:41 +08:00
:host([alert]),
:host([confirm]),
:host([prompt]) {
2019-08-21 21:03:41 +08:00
.layer {
max-width: 600px;
min-width: 300px;
background: #fff;
&__content {
padding: 0 15px;
2019-08-21 21:03:41 +08:00
}
}
}
2019-09-04 18:12:41 +08:00
:host([notify]) {
.layer {
width: 300px;
height: 120px;
&__content {
padding: 0 15px;
}
}
}
2019-09-04 18:12:41 +08:00
:host([toast]) {
2019-09-03 21:27:25 +08:00
.layer {
box-shadow: none;
&__content {
min-height: 40px;
}
}
}
2019-08-21 21:03:41 +08:00
</style>
<script>
2019-08-28 19:06:13 +08:00
import '../form/input'
2019-08-22 18:36:22 +08:00
import Drag from '../drag/core'
2019-08-21 21:03:41 +08:00
2019-12-19 01:04:15 +08:00
import $ from '../utils'
2019-08-21 21:03:41 +08:00
const LANGUAGES = {
en: {
TITLE: 'Dialog',
2019-09-04 18:12:41 +08:00
BTNS: ['Cancel', 'OK']
2019-08-21 21:03:41 +08:00
},
2021-05-28 18:54:33 +08:00
cn: {
2019-08-21 21:03:41 +08:00
TITLE: '提示',
2019-09-04 18:12:41 +08:00
BTNS: ['取消', '确定']
2019-08-21 21:03:41 +08:00
}
}
2021-05-28 18:54:33 +08:00
LANGUAGES['zh-CN'] = LANGUAGES.cn
2023-01-16 17:40:50 +08:00
const lang =
LANGUAGES[window.__ENV_LANG__ || navigator.language] || LANGUAGES.cn
2019-08-26 19:23:04 +08:00
let uniqueInstance = null // 缓存当前打开的alert/confirm/prompt类型的弹窗
let toastInstance = null // 缓存toast的实例
2019-08-26 19:23:04 +08:00
// 要保证弹层唯一的类型
const UNIQUE_TYPES = ['alert', 'confirm', 'prompt']
2019-08-21 21:03:41 +08:00
function renderBtns(list) {
var html = ''
list.forEach((t, i) => {
html += `<button data-idx="${i}">${t || lang.BTNS[i]}</button>`
})
return html
}
2020-12-14 14:44:05 +08:00
export default class Layer {
props = {
2019-09-04 18:12:41 +08:00
left: 'auto',
right: 'auto',
top: 'auto',
bottom: 'auto',
from: Object.create(null),
to: Object.create(null),
btns: [],
type: '',
title: '',
2019-09-04 18:12:41 +08:00
blur: false,
background: null,
mask: false,
2019-12-23 23:51:51 +08:00
radius: null,
2019-09-04 18:12:41 +08:00
'mask-close': false,
'mask-color': null,
fixed: true //是否固定位置
}
__init__() {
/* render */
this.__TITLE__ = this.root.children[1].firstElementChild
this.__BODY__ = this.root.children[1].children[1]
this.__CTRL__ = this.root.children[1].lastElementChild
this.promise = new Promise((resolve, reject) => {
this.resolve = resolve
this.reject = reject
})
}
set title(val) {
this.props.title = val
if (val) {
2019-09-04 18:12:41 +08:00
if (this.__TITLE__.firstElementChild) {
2023-01-16 17:40:50 +08:00
this.__TITLE__.insertBefore(
document.createTextNode(val),
this.__TITLE__.firstElementChild
)
2019-09-04 18:12:41 +08:00
} else {
this.__TITLE__.textContent = val
}
this.__TITLE__.style.display = 'flex'
} else {
this.__TITLE__.style.display = ''
}
}
set type(val) {
var { btns } = this.props
2019-09-04 18:12:41 +08:00
if (!val || this._handleBtnClick) {
2019-09-03 21:27:25 +08:00
return
}
switch (val) {
case 'alert':
while (btns.length > 1) {
2021-06-10 23:35:03 +08:00
btns.shift()
}
break
case 'confirm':
case 'prompt':
while (btns.length > 2) {
2021-06-10 23:35:03 +08:00
btns.shift()
}
break
case 'toast':
case 'notify':
case 'frame':
if (val === 'notify') {
var _ico = document.createElement('wc-icon')
2019-09-04 18:58:48 +08:00
_ico.setAttribute('is', 'close')
this.__TITLE__.appendChild(_ico)
}
btns = []
break
default:
val = 'common'
break
}
this.props.type = val
if (btns.length) {
this.__CTRL__.innerHTML = renderBtns(btns)
this.__CTRL__.style.display = 'flex'
} else {
this.__CTRL__.style.display = ''
}
2019-09-04 18:12:41 +08:00
this.setAttribute(val, '')
}
set fixed(val) {
this.props.fixed = !!val
this._updateFixedStat()
}
_updateFixedStat() {
// 这3类弹层不允许拖拽
if (UNIQUE_TYPES.includes(this.props.type)) {
return
}
if (this.props.fixed) {
if (this._dragIns) {
this._dragIns.destroy()
this._dragIns = null
}
} else {
this._dragIns = new Drag(this.root.children[1]).by(this.__TITLE__, {
2023-01-16 17:40:50 +08:00
overflow: this.props.hasOwnProperty('overflow')
? this.props.overflow
: false
})
this.removeAttribute('fixed')
}
}
// 拦截 "确定"按钮的事件
_intercept(input) {
if (this.props.intercept) {
this.props.intercept(input, _ => {
delete this.props.intercept
this.resolve(input)
this.close()
})
} else {
this.resolve(input)
this.close()
}
}
close(force) {
2019-09-04 18:12:41 +08:00
if (this.wrapped === false) {
if (this._dragIns) {
this._dragIns.destroy()
2019-09-03 21:27:25 +08:00
}
2019-09-04 18:12:41 +08:00
if (UNIQUE_TYPES.includes(this.props.type)) {
uniqueInstance = null
}
delete this.promise
2019-12-20 17:52:58 +08:00
$.unbind(this.__CTRL__, 'click', this._handleBtnClick)
2019-09-04 18:12:41 +08:00
// 离场动画
if (this.props.from && !force) {
let _style = 'opacity:0;'
for (let k in this.props.from) {
_style += `${k}:${this.props.from[k]};`
}
this.root.children[1].style.cssText += _style
this.timer = setTimeout(() => {
this.parentNode.removeChild(this)
this.dispatchEvent(new CustomEvent('close'))
2019-09-04 18:12:41 +08:00
}, 200)
} else {
clearTimeout(this.timer)
2019-09-03 21:27:25 +08:00
this.parentNode.removeChild(this)
this.dispatchEvent(new CustomEvent('close'))
2019-09-04 18:12:41 +08:00
}
2019-09-03 21:27:25 +08:00
} else {
2019-09-04 18:12:41 +08:00
this.removeAttribute('common')
this.dispatchEvent(new CustomEvent('close'))
2019-09-04 18:12:41 +08:00
}
}
show() {
if (this.wrapped === false) {
return
2019-09-03 21:27:25 +08:00
}
2019-09-04 18:12:41 +08:00
this.setAttribute('common', '')
}
moveTo(obj = {}) {
var css = ''
for (var k in obj) {
css += `${k}:${obj[k]};`
}
this.root.children[1].style.cssText += css
}
mounted() {
2019-09-04 18:12:41 +08:00
this.type = this.props.type
this.title = this.props.title
2019-12-19 01:04:15 +08:00
this._handleBtnClick = $.bind(this.__CTRL__, 'click', ev => {
if (ev.target.tagName === 'BUTTON') {
var idx = +ev.target.dataset.idx
var { type } = this.props
switch (type) {
case 'alert':
this.resolve()
this.close()
break
case 'confirm':
case 'prompt':
if (idx === 0) {
this.reject()
this.close()
} else {
let inputValue = type === 'prompt' ? this.__INPUT__.value : null
this._intercept(inputValue)
}
break
default:
// 其他类型, 如有按钮, 直接交给拦截器处理
this._intercept(idx)
break
}
}
})
if (this.props.type === 'prompt') {
this.__INPUT__ = this.__BODY__.firstElementChild.assignedNodes().pop()
2019-12-19 01:04:15 +08:00
this._handleSubmit = $.bind(this.__INPUT__, 'submit', ev => {
this._intercept(ev.detail)
})
}
2019-09-04 18:12:41 +08:00
if (this.props.mask) {
this.setAttribute('mask', '')
}
this._updateFixedStat()
2019-09-03 21:27:25 +08:00
/* ------------------------ */
/* ---- 额外的样式 --- */
/* ------------------------ */
if (this.props.mask) {
2019-12-19 01:04:15 +08:00
this._handlMask = $.outside(this.root.children[1], ev => {
2019-11-05 21:15:51 +08:00
// 只作用于当前wc-layer
if (ev.target !== this) {
2019-10-30 11:21:43 +08:00
return
}
2019-09-04 18:12:41 +08:00
if (this.props['mask-close']) {
if (this.wrapped === false) {
this.reject(null)
}
this.close()
} else {
if (UNIQUE_TYPES.includes(this.props.type)) {
this.root.children[1].classList.toggle('scale', true)
setTimeout(_ => {
this.root.children[1].classList.remove('scale')
}, 100)
}
}
})
2019-09-04 18:12:41 +08:00
if (this.props['mask-color']) {
this.style.backgroundColor = this.props['mask-color']
}
}
if (this.props.blur) {
this.root.children[1].classList.toggle('blur', true)
}
let _style = this.props.from ? '' : 'opacity:1;'
if (this.props.background) {
_style += `background: ${this.props.background};`
2021-06-27 01:40:47 +08:00
if (this.props.background === 'transparent') {
_style += 'box-shadow:none;'
}
}
2019-09-03 21:27:25 +08:00
if (this.props.radius || this.props.radius === 0) {
_style += `border-radius: ${this.props.radius};`
}
2019-09-03 21:27:25 +08:00
if (this.props.size) {
for (let k in this.props.size) {
_style += `${k}:${this.props.size[k]};`
}
}
if (this.props.from) {
for (let k in this.props.from) {
_style += `${k}:${this.props.from[k]};`
}
// 进场动画
setTimeout(_ => {
let _nextStyle = 'opacity:1;'
for (let k in this.props.to) {
_nextStyle += `${k}:${this.props.to[k]};`
}
this.root.children[1].style.cssText += _nextStyle
}, 50)
}
if (_style) {
this.root.children[1].style.cssText += _style
}
2019-09-03 21:27:25 +08:00
2023-01-16 17:40:50 +08:00
// 不是prompt类型, 在有按钮时, 自动聚焦最后一个按钮
if (
this.props.type !== 'prompt' &&
this.props.btns.length &&
this.__CTRL__.lastElementChild
) {
// 部分浏览器需要执行一下 focus()才能聚焦成功
this.__CTRL__.lastElementChild.setAttribute('autofocus', '')
setTimeout(_ => this.__CTRL__.lastElementChild.focus(), 10)
}
2019-09-03 21:27:25 +08:00
if (this.props.type === 'toast') {
this.timer = setTimeout(() => {
2019-12-17 13:59:15 +08:00
toastInstance = null
this.close()
2021-06-01 23:21:25 +08:00
}, 3000)
}
if (this.props.type === 'notify') {
2019-12-19 01:04:15 +08:00
this._handleClose = $.bind(this.__TITLE__, 'click', ev => {
if (ev.target.tagName === 'WC-ICON') {
this.close()
}
})
2019-09-03 21:27:25 +08:00
}
}
2021-05-07 16:06:33 +08:00
unmounted() {
2019-12-19 01:04:15 +08:00
$.clearOutside(this._handlMask)
$.unbind(this.__TITLE__, 'click', this._handleClose)
2021-04-14 10:02:41 +08:00
$.unbind(this.__CTRL__, 'click', this._handleBtnClick)
this._handleSubmit && $.unbind(this.__INPUT__, 'submit', this._handleSubmit)
}
watch() {
switch (name) {
case 'title':
case 'type':
2019-09-04 18:12:41 +08:00
this[name] = val
break
case 'mask-color':
case 'background':
this.props[name] = val
break
case 'mask':
case 'mask-close':
case 'blur':
this.props[name] = true
break
2019-12-23 23:51:51 +08:00
case 'radius':
this.props.radius = val
break
2019-09-04 18:12:41 +08:00
case 'left':
case 'right':
case 'top':
case 'bottom':
2019-12-23 23:51:51 +08:00
this.props.from[name] = val
this.props.to = this.props.from
this.removeAttribute(name)
break
case 'fixed':
this.fixed = true
break
}
}
}
2019-09-04 18:12:41 +08:00
function _layer(opt) {
2019-08-26 19:23:04 +08:00
var layDom = document.createElement('wc-layer')
2019-08-21 21:03:41 +08:00
2019-09-23 18:04:47 +08:00
if (!opt.type) {
opt.type = 'common'
}
2019-09-03 21:27:25 +08:00
if (opt.type === 'toast') {
var { type, content } = opt
2019-09-03 21:27:25 +08:00
opt = {
type,
content,
from: { top: 0 },
to: { top: '30px' }
2019-09-03 21:27:25 +08:00
}
if (toastInstance) {
toastInstance.close(true)
}
toastInstance = layDom
2019-08-28 19:06:13 +08:00
} else {
2019-09-04 18:12:41 +08:00
layDom.props.mask = opt.mask
2019-09-03 21:27:25 +08:00
if (opt.btns === false) {
layDom.props.btns = []
} else if (opt.btns && opt.btns.length) {
layDom.props.btns = opt.btns
} else {
layDom.props.btns = lang.BTNS.concat()
}
if (opt.intercept && typeof opt.intercept === 'function') {
layDom.props.intercept = opt.intercept
}
layDom.props.mask = opt.mask
2019-09-04 18:12:41 +08:00
layDom.props['mask-close'] = opt['mask-close']
2019-08-21 21:03:41 +08:00
2019-09-03 21:27:25 +08:00
if (opt.hasOwnProperty('overflow')) {
layDom.props.overflow = opt.overflow
}
/* 额外样式 */
2019-09-04 18:12:41 +08:00
layDom.props['mask-color'] = opt['mask-color']
2019-09-03 21:27:25 +08:00
layDom.props.blur = opt.blur
layDom.props.radius = opt.radius
layDom.props.background = opt.background
if (opt.size && typeof opt.size === 'object') {
layDom.props.size = opt.size
}
2019-08-28 19:06:13 +08:00
// 这3种类型, 只允许同时存在1个, 如果之前有弹出则关闭
if (UNIQUE_TYPES.includes(opt.type)) {
if (uniqueInstance) {
uniqueInstance.close(true)
}
uniqueInstance = layDom
}
}
2019-09-03 21:27:25 +08:00
if (opt.to && typeof opt.to === 'object') {
layDom.props.to = opt.to
if (opt.from && typeof opt.from === 'object') {
layDom.props.from = opt.from
} else {
layDom.props.from = opt.to
}
}
2019-08-28 19:06:13 +08:00
2019-09-04 18:12:41 +08:00
layDom.props.type = opt.type
layDom.props.title = opt.title
2019-09-23 18:04:47 +08:00
if (opt.hasOwnProperty('fixed')) {
layDom.props.fixed = opt.fixed
}
2019-08-26 19:23:04 +08:00
layDom.innerHTML = opt.content
2019-09-04 18:12:41 +08:00
layDom.wrapped = false // 用于区分是API创建的还是包裹现有的节点
2019-08-26 19:23:04 +08:00
document.body.appendChild(layDom)
2019-08-21 21:03:41 +08:00
2019-08-28 19:06:13 +08:00
return layDom.promise
2019-08-21 21:03:41 +08:00
}
Object.assign(_layer, {
2021-06-10 23:38:03 +08:00
alert(content, title = lang.TITLE, btns) {
2021-06-10 23:35:03 +08:00
if (typeof title === 'object') {
btns = title
title = lang.TITLE
}
2019-09-04 18:12:41 +08:00
return this({
2019-08-26 19:23:04 +08:00
type: 'alert',
2019-08-28 19:06:13 +08:00
title,
content,
2021-06-10 23:35:03 +08:00
mask: true,
btns
2019-08-26 19:23:04 +08:00
})
2019-08-21 21:03:41 +08:00
},
2021-06-10 23:38:03 +08:00
confirm(content, title = lang.TITLE, btns) {
2021-06-10 23:35:03 +08:00
if (typeof title === 'object') {
btns = title
2019-08-28 19:06:13 +08:00
title = lang.TITLE
}
2019-09-04 18:12:41 +08:00
return this({
2019-08-26 19:23:04 +08:00
type: 'confirm',
2019-08-28 19:06:13 +08:00
title,
content,
mask: true,
2021-06-10 23:35:03 +08:00
btns
2019-08-28 19:06:13 +08:00
})
},
2021-04-14 10:02:41 +08:00
prompt(title = lang.TITLE, defaultValue = '', intercept) {
if (typeof defaultValue === 'function') {
intercept = defaultValue
defaultValue = ''
}
if (!intercept) {
2023-01-16 17:40:50 +08:00
intercept = function (val, done) {
2021-04-14 10:02:41 +08:00
if (val) {
done()
}
}
}
2019-09-04 18:12:41 +08:00
return this({
2019-08-28 19:06:13 +08:00
type: 'prompt',
title,
2021-04-14 10:02:41 +08:00
content: `<wc-input autofocus class="layer__content__input" value="${defaultValue}"></wc-input>`,
2019-08-28 19:06:13 +08:00
mask: true,
intercept
2019-08-26 19:23:04 +08:00
})
2019-08-21 21:03:41 +08:00
},
frame(url, extra = {}) {
2019-09-04 18:12:41 +08:00
return this({
2019-08-28 19:06:13 +08:00
...extra,
2019-08-26 19:23:04 +08:00
type: 'frame',
2019-08-28 19:06:13 +08:00
content: `<iframe class="layer__content__frame" src="${url}"></iframe>`,
2019-08-26 19:23:04 +08:00
mask: true,
2019-09-04 18:12:41 +08:00
'mask-close': true
2019-08-26 19:23:04 +08:00
})
2019-08-21 21:03:41 +08:00
},
notify(content) {
2019-09-04 18:12:41 +08:00
return this({
type: 'notify',
title: '通知',
content,
blur: true,
from: { right: '-300px', top: 0 },
to: { right: 0 }
})
},
toast(txt, type = 'info') {
var ico = type
2019-08-21 21:03:41 +08:00
switch (type) {
case 'info':
case 'warning':
break
2019-08-21 21:03:41 +08:00
case 'error':
ico = 'deny'
2019-08-21 21:03:41 +08:00
break
2019-12-20 17:45:36 +08:00
case 'success':
ico = 'get'
break
2019-08-21 21:03:41 +08:00
default:
ico = 'info'
2019-08-21 21:03:41 +08:00
}
2019-09-04 18:12:41 +08:00
return this({
2019-08-21 21:03:41 +08:00
content: `
2019-09-03 21:27:25 +08:00
<div class="layer__content__toast style-${type}">
<wc-icon is="${ico}"></wc-icon>
2021-05-28 18:54:33 +08:00
<span class="toast-txt">${txt}</span>
2019-09-03 21:27:25 +08:00
</div>`,
type: 'toast'
2019-09-03 21:27:25 +08:00
})
2019-08-28 19:06:13 +08:00
}
})
2019-08-21 21:03:41 +08:00
2019-08-28 19:06:13 +08:00
window.layer = _layer
2019-08-21 21:03:41 +08:00
</script>