919f3698 by liangyifan

弹窗封装

1 parent 1e1a4498
1 import Vue from 'vue'
2 import Popup from './index.vue'
3
4 const PopupBox = Vue.extend(Popup)
5 Popup.install = function (data) {
6 console.log(data)
7 let instance = new PopupBox({
8 data
9 }).$mount()
10
11 document.body.appendChild(instance.$el)
12
13 Vue.nextTick(() => {
14 instance.isShow = true
15 })
16 }
17
18 export default Popup
...\ No newline at end of file ...\ No newline at end of file
1 <template>
2 <transition name="fade" mode="out-in" v-if="isShow">
3 <div class="ls-mask" v-loading="loading">
4 <div class="ls-mask-window" :style="{'width':width,'height':height}">
5 <div :style="{'text-align':titleStyle}"><b >{{title}}</b></div>
6 <i class="el-icon-close" @click="onCancel" ></i>
7 <div class="ls-mask-content">
8 <component :is="editItem" ref='childRef' @loading='loadingFn' />
9 </div>
10 <div class="ls-mask-footer">
11 <el-button type="primary" @click="onConfirm">{{confirmText}}</el-button>
12 <el-button @click="onCancel">{{cancelText}}</el-button>
13 </div>
14 </div>
15 </div>
16 </transition>
17 </template>
18 <script>
19 export default {
20 name: 'index',
21 data () {
22 return {
23 title: '提示',
24 cancelText: '取消',
25 confirmText: '确认',
26 isSync: false,
27 isShow: false,
28 editItem:"",
29 titleStyle:'',
30 width:"75%",
31 height:"500px",
32 }
33 },
34 props:{
35 loading: { type: Boolean, default: false },
36 },
37 watch:{
38 isShow(a,b){
39 this.editItem = this.loadViewFn(this.editItem)
40 },
41 },
42 methods: {
43 onCancel () {
44 this.isShow = false
45 },
46 onConfirm () {
47 this.loading = true
48 this.$refs.childRef.childFn()
49 },
50 loadingFn(e){ //加载状态
51 this.loading = e
52 },
53 loadViewFn (view) {
54 return (r) =>
55 require.ensure([], () =>
56 r(require(`@/views/${view}.vue`))
57 );
58 },
59 }
60 }
61 </script>
62 <style scoped>
63 #app{
64 overflow: hidden;
65 }
66 .ls-mask{
67 width: 100%;
68 height: 100%;
69 z-index: 2001;
70 position: fixed;
71 left: 0;
72 top: 0;
73 background: rgba(0,0,0,0.3);
74 }
75 .ls-mask-window{
76 padding-top: 20px;
77 background: white;
78 position: absolute;
79 left: 50%;
80 top: 50%;
81 transform: translate(-50%,-50%);
82 }
83 .ls-mask-window b{
84 padding-left: 12px;
85 }
86 .ls-mask-content{
87 padding: 20px;
88 text-align: center;
89 }
90 .ls-mask-footer{
91 height: 45px;
92 border-top: 1px solid #f0f0f0;
93 display: flex;
94 justify-content: end;
95 padding: 2px;
96 position: absolute;
97 width: 98%;
98 bottom: 10px;
99 right: 12px;
100 }
101 /deep/.el-icon-close{
102 position: absolute;
103 top: 20px;
104 right: 12px;
105 font-size: 20px;
106 cursor: pointer;
107 }
108 /deep/.el-loading-mask{
109 background: none;
110 }
111 </style>
112
...\ No newline at end of file ...\ No newline at end of file
...@@ -14,6 +14,8 @@ import rules from './utils/rule.js' ...@@ -14,6 +14,8 @@ import rules from './utils/rule.js'
14 // 全局方法挂载 14 // 全局方法挂载
15 Vue.prototype.$rules = rules 15 Vue.prototype.$rules = rules
16 16
17 import Popup from './components/tanchuang/index'
18 Vue.prototype.$popup = Popup.install
17 19
18 import { theme } from "@/directive/theme.js" 20 import { theme } from "@/directive/theme.js"
19 Vue.directive("theme", theme) 21 Vue.directive("theme", theme)
......