vue2-components-plus 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ComponentDemo/DialogDemo.vue +273 -0
- package/dist/ComponentDemo/DirectivesDemo.vue +452 -0
- package/dist/ComponentDemo/FormDemo.vue +851 -0
- package/dist/ComponentDemo/NsTableDemo/index.vue +539 -0
- package/dist/ComponentDemo/NsTableDemo/mockData.js +117 -0
- package/dist/vue2-components-plus.js +2895 -0
- package/dist/vue2-components-plus.umd.cjs +1 -1
- package/package.json +13 -6
- package/dist/vue2-components-plus.es.js +0 -2181
- /package/dist/{style.css → vue2-components-plus.css} +0 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="dialog-demo">
|
|
3
|
+
<el-card shadow="never" class="dialog-demo__card">
|
|
4
|
+
<div slot="header" class="dialog-demo__header">
|
|
5
|
+
<div>
|
|
6
|
+
<div class="dialog-demo__title">NsDialog 预览</div>
|
|
7
|
+
<div class="dialog-demo__desc">演示多开、更新配置、调用内部组件方法、关闭单个与全部弹窗。</div>
|
|
8
|
+
</div>
|
|
9
|
+
<el-tag size="small" type="success">当前 {{ dialogInstances.length }} 个实例</el-tag>
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
<div class="dialog-demo__actions">
|
|
13
|
+
<el-button type="primary" @click="openDialog()">打开弹窗</el-button>
|
|
14
|
+
<el-button @click="openReadonlyDialog()">打开只读弹窗</el-button>
|
|
15
|
+
<el-button @click="updateDialogOption">更新最后一个弹窗</el-button>
|
|
16
|
+
<el-button @click="callDialogMethod">调用最后一个弹窗内容方法</el-button>
|
|
17
|
+
<el-button type="danger" plain :disabled="!dialogInstances.length" @click="closeAllDialogs">关闭全部</el-button>
|
|
18
|
+
</div>
|
|
19
|
+
</el-card>
|
|
20
|
+
|
|
21
|
+
<el-row :gutter="20">
|
|
22
|
+
<el-col :span="10">
|
|
23
|
+
<el-card shadow="never" class="dialog-demo__card dialog-demo__instance-card">
|
|
24
|
+
<div slot="header">弹窗实例列表</div>
|
|
25
|
+
<div v-if="dialogInstances.length" class="instance-list">
|
|
26
|
+
<div v-for="(instance, index) in dialogInstances" :key="instance.id" class="instance-item">
|
|
27
|
+
<div>
|
|
28
|
+
<div class="instance-item__title">实例 {{ index + 1 }}</div>
|
|
29
|
+
<div class="instance-item__meta">{{ instance.id }}</div>
|
|
30
|
+
</div>
|
|
31
|
+
<div class="instance-item__actions">
|
|
32
|
+
<el-button size="mini" @click="closeDialog(instance)">关闭</el-button>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
<el-empty v-else description="暂无已打开弹窗" :image-size="88" />
|
|
37
|
+
</el-card>
|
|
38
|
+
</el-col>
|
|
39
|
+
|
|
40
|
+
<el-col :span="14">
|
|
41
|
+
<el-card shadow="never" class="dialog-demo__card">
|
|
42
|
+
<div slot="header">能力说明</div>
|
|
43
|
+
<el-steps direction="vertical" :active="4" finish-status="success">
|
|
44
|
+
<el-step title="打开弹窗" description="每次打开会创建独立实例,并做错位展示。" />
|
|
45
|
+
<el-step title="更新配置" description="可更新标题、宽高、位置以及传入内容组件的 props。" />
|
|
46
|
+
<el-step title="调用方法" description="通过实例调用弹窗内部组件的公开方法,例如获取表单数据。" />
|
|
47
|
+
<el-step title="关闭管理" description="支持关闭指定实例与一键关闭全部实例。" />
|
|
48
|
+
</el-steps>
|
|
49
|
+
</el-card>
|
|
50
|
+
</el-col>
|
|
51
|
+
</el-row>
|
|
52
|
+
</div>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<script>
|
|
56
|
+
import FormDemo from '@/views/FormDemo.vue'
|
|
57
|
+
|
|
58
|
+
export default {
|
|
59
|
+
name: 'DialogDemo',
|
|
60
|
+
data() {
|
|
61
|
+
return {
|
|
62
|
+
dialogInstances: [],
|
|
63
|
+
openIndex: 0,
|
|
64
|
+
lastReadOnly: false,
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
mounted() {
|
|
68
|
+
this.refreshInstances()
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
this.openDialog({ silent: true })
|
|
71
|
+
}, 300)
|
|
72
|
+
},
|
|
73
|
+
beforeDestroy() {
|
|
74
|
+
this.closeAllDialogs()
|
|
75
|
+
},
|
|
76
|
+
methods: {
|
|
77
|
+
getDialogApi() {
|
|
78
|
+
return this.$NsDialog || window.NsDialog
|
|
79
|
+
},
|
|
80
|
+
refreshInstances() {
|
|
81
|
+
setTimeout(() => {
|
|
82
|
+
this.dialogInstances = Array.isArray(window.__dialogInstances)
|
|
83
|
+
? window.__dialogInstances.slice()
|
|
84
|
+
: []
|
|
85
|
+
}, 0)
|
|
86
|
+
},
|
|
87
|
+
openDialog(options) {
|
|
88
|
+
const api = this.getDialogApi()
|
|
89
|
+
if (!api) {
|
|
90
|
+
this.$message.error('NsDialog 尚未挂载到全局')
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
const config = options || {}
|
|
94
|
+
const offset = this.openIndex * 24
|
|
95
|
+
const readOnly = !!config.readOnly
|
|
96
|
+
api(
|
|
97
|
+
{
|
|
98
|
+
title: config.title || 'NsDialog 示例',
|
|
99
|
+
class: 'dialog-demo-instance',
|
|
100
|
+
dom: FormDemo,
|
|
101
|
+
option: {
|
|
102
|
+
readOnly,
|
|
103
|
+
insideDialog: true,
|
|
104
|
+
hintText: readOnly ? '当前是只读弹窗内容。' : '可以在弹窗中直接编辑表单并触发事件。',
|
|
105
|
+
},
|
|
106
|
+
events: {
|
|
107
|
+
btnClick: this.handleInnerButtonClick,
|
|
108
|
+
},
|
|
109
|
+
width: config.width || '960px',
|
|
110
|
+
height: config.height || '620px',
|
|
111
|
+
dialogPadding: [0, 0],
|
|
112
|
+
modal: config.modal !== undefined ? config.modal : false,
|
|
113
|
+
draggable: true,
|
|
114
|
+
x: 120 + offset,
|
|
115
|
+
y: 80 + offset,
|
|
116
|
+
domCompleted: (domRef) => {
|
|
117
|
+
if (!config.silent && domRef && typeof domRef.showToast === 'function') {
|
|
118
|
+
domRef.showToast('弹窗内容已加载完成')
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
confirm: (closeFn, componentRef) => {
|
|
122
|
+
if (componentRef && typeof componentRef.showToast === 'function') {
|
|
123
|
+
componentRef.showToast('点击了弹窗底部确认按钮')
|
|
124
|
+
}
|
|
125
|
+
setTimeout(() => {
|
|
126
|
+
if (typeof closeFn === 'function') {
|
|
127
|
+
closeFn()
|
|
128
|
+
}
|
|
129
|
+
}, 300)
|
|
130
|
+
},
|
|
131
|
+
close: this.refreshInstances,
|
|
132
|
+
closed: this.refreshInstances,
|
|
133
|
+
},
|
|
134
|
+
true,
|
|
135
|
+
'#app',
|
|
136
|
+
)
|
|
137
|
+
this.openIndex += 1
|
|
138
|
+
this.lastReadOnly = readOnly
|
|
139
|
+
this.refreshInstances()
|
|
140
|
+
},
|
|
141
|
+
openReadonlyDialog() {
|
|
142
|
+
this.openDialog({
|
|
143
|
+
readOnly: true,
|
|
144
|
+
title: '只读预览弹窗',
|
|
145
|
+
})
|
|
146
|
+
},
|
|
147
|
+
updateDialogOption() {
|
|
148
|
+
if (!this.dialogInstances.length) {
|
|
149
|
+
this.$message.warning('请先打开一个弹窗')
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
const lastInstance = this.dialogInstances[this.dialogInstances.length - 1]
|
|
153
|
+
this.lastReadOnly = !this.lastReadOnly
|
|
154
|
+
lastInstance.updateOption({
|
|
155
|
+
title: this.lastReadOnly ? '更新后的只读弹窗' : '更新后的编辑弹窗',
|
|
156
|
+
readOnly: this.lastReadOnly,
|
|
157
|
+
hintText: this.lastReadOnly ? '已通过 updateOption 切换为只读。' : '已通过 updateOption 切换为编辑。',
|
|
158
|
+
width: this.lastReadOnly ? '880px' : '960px',
|
|
159
|
+
})
|
|
160
|
+
this.$message.success('已更新最后一个弹窗配置')
|
|
161
|
+
},
|
|
162
|
+
async callDialogMethod() {
|
|
163
|
+
if (!this.dialogInstances.length) {
|
|
164
|
+
this.$message.warning('请先打开一个弹窗')
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
const lastInstance = this.dialogInstances[this.dialogInstances.length - 1]
|
|
168
|
+
const result = await lastInstance.callMethod('getFormData')
|
|
169
|
+
if (result === false) {
|
|
170
|
+
this.$message.warning('弹窗内表单还未通过校验')
|
|
171
|
+
return
|
|
172
|
+
}
|
|
173
|
+
this.$message.success('已调用内部组件方法并获取结果')
|
|
174
|
+
},
|
|
175
|
+
closeDialog(instance) {
|
|
176
|
+
if (!instance || typeof instance.close !== 'function') {
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
instance.close()
|
|
180
|
+
this.refreshInstances()
|
|
181
|
+
},
|
|
182
|
+
closeAllDialogs() {
|
|
183
|
+
if (typeof this.$closeAllNsDialog === 'function') {
|
|
184
|
+
this.$closeAllNsDialog()
|
|
185
|
+
} else if (typeof window.closeAllNsDialog === 'function') {
|
|
186
|
+
window.closeAllNsDialog()
|
|
187
|
+
} else if (Array.isArray(window.__dialogInstances)) {
|
|
188
|
+
window.__dialogInstances.slice().forEach((instance) => {
|
|
189
|
+
instance && typeof instance.close === 'function' && instance.close()
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
this.openIndex = 0
|
|
193
|
+
this.refreshInstances()
|
|
194
|
+
},
|
|
195
|
+
handleInnerButtonClick(payload) {
|
|
196
|
+
const keys = payload ? Object.keys(payload) : []
|
|
197
|
+
this.$message.info(`收到弹窗内容事件,共 ${keys.length} 个字段`)
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
</script>
|
|
202
|
+
|
|
203
|
+
<style scoped>
|
|
204
|
+
.dialog-demo {
|
|
205
|
+
display: flex;
|
|
206
|
+
flex-direction: column;
|
|
207
|
+
gap: 20px;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.dialog-demo__card {
|
|
211
|
+
border-radius: 12px;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.dialog-demo__header {
|
|
215
|
+
display: flex;
|
|
216
|
+
align-items: center;
|
|
217
|
+
justify-content: space-between;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.dialog-demo__title {
|
|
221
|
+
font-size: 18px;
|
|
222
|
+
font-weight: 700;
|
|
223
|
+
color: #303133;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
.dialog-demo__desc {
|
|
227
|
+
margin-top: 6px;
|
|
228
|
+
font-size: 13px;
|
|
229
|
+
color: #909399;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.dialog-demo__actions {
|
|
233
|
+
display: flex;
|
|
234
|
+
flex-wrap: wrap;
|
|
235
|
+
gap: 12px;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.instance-list {
|
|
239
|
+
display: flex;
|
|
240
|
+
flex-direction: column;
|
|
241
|
+
gap: 12px;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.instance-item {
|
|
245
|
+
display: flex;
|
|
246
|
+
align-items: center;
|
|
247
|
+
justify-content: space-between;
|
|
248
|
+
padding: 14px 16px;
|
|
249
|
+
border: 1px solid #ebeef5;
|
|
250
|
+
border-radius: 10px;
|
|
251
|
+
background: #fafafa;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.instance-item__title {
|
|
255
|
+
font-size: 14px;
|
|
256
|
+
font-weight: 600;
|
|
257
|
+
color: #303133;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.instance-item__meta {
|
|
261
|
+
margin-top: 4px;
|
|
262
|
+
font-size: 12px;
|
|
263
|
+
color: #909399;
|
|
264
|
+
word-break: break-all;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
@media (max-width: 960px) {
|
|
268
|
+
.dialog-demo__actions {
|
|
269
|
+
flex-direction: column;
|
|
270
|
+
align-items: stretch;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
</style>
|