0.1.0 • Published 3 years ago

vue-yy-window v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

安装:

npm i vue-yy-window

引入

import Vue from 'vue'
import YYWindow from 'vue-yy-window'

Vue.use(YYWindow, {
  // 务必传入store和router,否则对话框内组件用到时会报错,因为不共享同一个Vue实例
  store,
  router
})

使用示例:

this.$dialog(
  // 窗体标题
  'title',
  // 引入的组件模块、显示的内容
  import('components/dialog/testValidate'),
  // 窗体dialog的配置项
  {
    // minimizable为true时需要指定唯一id
    id: 'testValidate', 
    // 最小化时如果有设置id,不会执行then和beforeClose的方法,只会执行onMinimized()
    minimizable: true,
    maximizable: true,
    // 使用方法调用窗体时必须设置appendToBody为true,(默认为true),否则不会弹出
    appendToBody: true, 
    // 使用方法调用窗体时必须设置inline为false,(默认为false),否则不会弹出
    inline: false,
    // 是否显示默认取消按钮
    showCancelButton: false,
    // 默认取消按钮文字
    cancelButtonText: '取消',
    // 是否显示默认确认按钮
    showConfirmButton: false,
    // 默认确认按钮文字
    confirmButtonText: '确认',
    // 自定义窗体class
    customClass: 'custom',
    // 自定义按钮
    customButtons: [
      {
        text: '立即创建',
        type: 'primary',
        loading: false,
        click: (child, done, button) => {
          button.loading = true
          // 调用子组件的方法
          child.resetForm()
          button.loading = false
          button.text = '完成'
        }
      }, {
        text: '充值',
        click: (child, done, button ) => {
          // 传入父组件的参数
          child.resetForm(this.data1)
        }
      }
    ],
    // 窗体打开时的钩子
    onOpen: child => {
      child.search()
    },
    // 窗体关闭前的钩子,可以控制窗体是否要关闭
    onBeforeClose: (child, done, action) => {
      console.log(action)
      // 需要显示调用done()方法才会关闭窗体, 方法可以传入任意参数,会做为then的action
      done()
    }
  },
  // 传入子组件的props,用on+小驼峰命名来区分事件和props
  {
    type: 'edit',
    // 子组件$emit('onSearch')触发
    onSearch: (data) => {
      console.log(data)
    }
  }
).then(action => {
  // 窗体关闭后的钩子
  console.log(action)
})

Attributes

参数说明类型可选值默认值
id是否永久保存该窗体实例,若有id则保存,默认不保存,需要整个项目唯一idstring、number--
showCancelButton是否显示默认取消按钮boolean-true
cancelButtonText默认取消按钮文字string、number-'取消'
cancelButtonSize默认取消按钮大小stringmedium / small / mini'small'
showConfirmButton是否显示默认确认按钮boolean-true
confirmButtonText默认确认按钮文字string、number-'确认'
confirmButtonSize默认确认按钮大小stringmedium / small / mini'small'
customClass自定义窗体类名,样式可以直接写在style/index.scss里string--
customButtons自定义按钮,配置见使用示例Array--
title标题文字, 不传即不显示头部string-''
headerBackgroundheader背景, 可设置渐变string-'#e8f4ff'
footerBackgroundfooter背景, 可设置渐变string-'#fff'
icon标题旁边的图标样式名称stringelement-ui的图标-
width窗体宽度string-auto
height窗体高度string-auto
headerHeight头部高度string-'40px'
footerHeight底部高度string-'40px'
closable是否显示关闭按钮boolean-true
maximizable是否显示最小化按钮boolean-false
maximizable是否显示最大化按钮boolean-false
closeOnClickModal是否可以通过点击 modal 关闭窗体boolean-true
closeOnPressEscape是否可以通过按下 ESC 关闭窗体boolean-true
modal是否显示遮罩层,inline为true是无效boolean-true
draggable是否支持窗体拖拽boolean-true
resizable是否支持窗体改变尺寸boolean-true
zIndex窗体层级number-1000
shadow是否显示窗体阴影boolean-true
inline是否以内联方式显示boolean-false
left窗体左位置,inline为true时无效,left、top同时为null时,自动居中string-null
top窗体顶位置,inline为true时无效,left、top同时为null时,自动居中string-null

Hooks

钩子名称说明回调参数
onOpen窗体打开时的钩子子组件实例
onBeforeClose窗体关闭前的钩子,可以控制窗体是否要关闭(子组件实例,关闭窗体方法,关闭行为名称)
onStartDrag窗体开始拖拽时的钩子(子组件实例,关闭窗体方法,事件event)
onStopDrag窗体结束拖拽时的钩子(子组件实例,关闭窗体方法,事件event)
onDrag窗体正在拖拽时的钩子(子组件实例,关闭窗体方法,事件event)
onStartResize窗体开始改变尺寸时的钩子(子组件实例,关闭窗体方法,事件event)
onStopResize窗体结束改变尺寸时的钩子(子组件实例,关闭窗体方法,事件event)
onResize窗体正在改变尺寸时的钩子(子组件实例,关闭窗体方法,事件event)
onMinimized窗体切换最小化时的钩子(子组件实例,关闭窗体方法)
onMaximized窗体切换最大化时的钩子(子组件实例,关闭窗体方法,当前放大状态)
onClick窗体被点击时的钩子(子组件实例,关闭窗体方法,事件event)

Slots(模板语法)

name说明
title定义标题内容,设置了改插槽,参数title将无效
tools定义操作按钮
default窗体内容
footer定义底部内容
0.1.0

3 years ago