pit-docs-mcp 1.0.2
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/README.md +180 -0
- package/dist/codegen.d.ts +5 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +112 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +10 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +115 -0
- package/dist/resources.d.ts +3 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +80 -0
- package/dist/tools.d.ts +3 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +258 -0
- package/dist/utils.d.ts +26 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +198 -0
- package/docs/codegen/pit-simplify-web.md +686 -0
- package/docs/pitBusinessUi/README.md +102 -0
- package/docs/pitBusinessUi/add-date-picker.md +57 -0
- package/docs/pitBusinessUi/add-operation.md +64 -0
- package/docs/pitBusinessUi/batch-download.md +44 -0
- package/docs/pitBusinessUi/bill-tree-dialog.md +82 -0
- package/docs/pitBusinessUi/collapse.md +88 -0
- package/docs/pitBusinessUi/date-time-picker.md +74 -0
- package/docs/pitBusinessUi/design-report-explain.md +47 -0
- package/docs/pitBusinessUi/dialog.md +89 -0
- package/docs/pitBusinessUi/dic-radio.md +67 -0
- package/docs/pitBusinessUi/dic.md +78 -0
- package/docs/pitBusinessUi/document-preview.md +54 -0
- package/docs/pitBusinessUi/drawer.md +67 -0
- package/docs/pitBusinessUi/editor.md +63 -0
- package/docs/pitBusinessUi/expand-search-form.md +65 -0
- package/docs/pitBusinessUi/file-preview.md +56 -0
- package/docs/pitBusinessUi/flow-table-status.md +47 -0
- package/docs/pitBusinessUi/icon-box.md +74 -0
- package/docs/pitBusinessUi/image-preview.md +55 -0
- package/docs/pitBusinessUi/image.md +53 -0
- package/docs/pitBusinessUi/input-formatter.md +100 -0
- package/docs/pitBusinessUi/input-number.md +47 -0
- package/docs/pitBusinessUi/input-select.md +68 -0
- package/docs/pitBusinessUi/input.md +56 -0
- package/docs/pitBusinessUi/jm-preview.md +47 -0
- package/docs/pitBusinessUi/json-editor.md +71 -0
- package/docs/pitBusinessUi/loading-btn.md +64 -0
- package/docs/pitBusinessUi/monaco.md +82 -0
- package/docs/pitBusinessUi/money-input.md +59 -0
- package/docs/pitBusinessUi/pagination.md +70 -0
- package/docs/pitBusinessUi/password-strength.md +59 -0
- package/docs/pitBusinessUi/positive-number.md +63 -0
- package/docs/pitBusinessUi/preview-image.md +62 -0
- package/docs/pitBusinessUi/preview-office.md +50 -0
- package/docs/pitBusinessUi/preview.md +57 -0
- package/docs/pitBusinessUi/quill.md +52 -0
- package/docs/pitBusinessUi/runflow-btn.md +52 -0
- package/docs/pitBusinessUi/search-date-picker.md +60 -0
- package/docs/pitBusinessUi/select-bid-list.md +66 -0
- package/docs/pitBusinessUi/select-color.md +38 -0
- package/docs/pitBusinessUi/select-contract-tree.md +41 -0
- package/docs/pitBusinessUi/select-dept.md +38 -0
- package/docs/pitBusinessUi/select-project-unit.md +48 -0
- package/docs/pitBusinessUi/select-section-tree.md +45 -0
- package/docs/pitBusinessUi/select-section.md +66 -0
- package/docs/pitBusinessUi/select-string.md +60 -0
- package/docs/pitBusinessUi/select-system-unit.md +41 -0
- package/docs/pitBusinessUi/select-user-by-role.md +51 -0
- package/docs/pitBusinessUi/switch.md +43 -0
- package/docs/pitBusinessUi/table-contract.md +66 -0
- package/docs/pitBusinessUi/table-operation.md +81 -0
- package/docs/pitBusinessUi/table.md +75 -0
- package/docs/pitBusinessUi/tag.md +86 -0
- package/docs/pitBusinessUi/textarea.md +65 -0
- package/docs/pitBusinessUi/transfer-direct.md +57 -0
- package/docs/pitBusinessUi/transfer-user-project.md +78 -0
- package/docs/pitBusinessUi/transfer.md +68 -0
- package/docs/pitBusinessUi/tree-lazy.md +72 -0
- package/docs/pitBusinessUi/tree-select-name.md +59 -0
- package/docs/pitBusinessUi/tree-select-plus.md +106 -0
- package/docs/pitBusinessUi/tree-select.md +86 -0
- package/docs/pitBusinessUi/upload-avatar.md +60 -0
- package/docs/pitBusinessUi/upload-file-dialog.md +86 -0
- package/docs/pitBusinessUi/upload-file.md +77 -0
- package/docs/pitBusinessUi/upload-list-card.md +62 -0
- package/docs/pitBusinessUi/upload-table.md +77 -0
- package/docs/pitBusinessUi/user-transform.md +72 -0
- package/docs/pitBusinessUi/utils.md +272 -0
- package/docs/pitBusinessUtils/README.md +144 -0
- package/docs/pitBusinessUtils/auth.md +170 -0
- package/docs/pitBusinessUtils/clipboard.md +72 -0
- package/docs/pitBusinessUtils/filePreview.md +60 -0
- package/docs/pitBusinessUtils/formValidate.md +75 -0
- package/docs/pitBusinessUtils/generateTitle.md +49 -0
- package/docs/pitBusinessUtils/get-page-title.md +65 -0
- package/docs/pitBusinessUtils/i18n.md +130 -0
- package/docs/pitBusinessUtils/jwks.md +82 -0
- package/docs/pitBusinessUtils/oss.md +391 -0
- package/docs/pitBusinessUtils/passwordValidate.md +120 -0
- package/docs/pitBusinessUtils/pit.md +496 -0
- package/docs/pitBusinessUtils/print.md +126 -0
- package/docs/pitBusinessUtils/request.md +137 -0
- package/docs/pitBusinessUtils/scroll-to.md +68 -0
- package/docs/pitBusinessUtils/utils.md +762 -0
- package/docs/pitBusinessUtils/validate.md +224 -0
- package/docs/pitElementUi/alert.md +238 -0
- package/docs/pitElementUi/avatar.md +147 -0
- package/docs/pitElementUi/backtop.md +60 -0
- package/docs/pitElementUi/badge.md +120 -0
- package/docs/pitElementUi/base-tabs.md +73 -0
- package/docs/pitElementUi/border.md +135 -0
- package/docs/pitElementUi/breadcrumb.md +44 -0
- package/docs/pitElementUi/button.md +301 -0
- package/docs/pitElementUi/calendar.md +66 -0
- package/docs/pitElementUi/card.md +170 -0
- package/docs/pitElementUi/carousel.md +212 -0
- package/docs/pitElementUi/cascader.md +1966 -0
- package/docs/pitElementUi/checkbox.md +283 -0
- package/docs/pitElementUi/collapse.md +131 -0
- package/docs/pitElementUi/color-picker.md +123 -0
- package/docs/pitElementUi/color.md +244 -0
- package/docs/pitElementUi/container.md +240 -0
- package/docs/pitElementUi/custom-theme.md +131 -0
- package/docs/pitElementUi/date-picker.md +448 -0
- package/docs/pitElementUi/datetime-picker.md +254 -0
- package/docs/pitElementUi/descriptions.md +191 -0
- package/docs/pitElementUi/dialog-header.md +53 -0
- package/docs/pitElementUi/dialog.md +239 -0
- package/docs/pitElementUi/divider.md +61 -0
- package/docs/pitElementUi/drawer.md +307 -0
- package/docs/pitElementUi/dropdown.md +308 -0
- package/docs/pitElementUi/empty.md +61 -0
- package/docs/pitElementUi/font-family.md +90 -0
- package/docs/pitElementUi/form-base.md +1239 -0
- package/docs/pitElementUi/form-item-checkbox-group.md +48 -0
- package/docs/pitElementUi/form-item-date.md +60 -0
- package/docs/pitElementUi/form-item-dic.md +18 -0
- package/docs/pitElementUi/form-item-editor.md +16 -0
- package/docs/pitElementUi/form-item-input-money.md +19 -0
- package/docs/pitElementUi/form-item-input-number.md +20 -0
- package/docs/pitElementUi/form-item-input.md +18 -0
- package/docs/pitElementUi/form-item-radio-group.md +21 -0
- package/docs/pitElementUi/form-item-select.md +21 -0
- package/docs/pitElementUi/form-item-switch.md +15 -0
- package/docs/pitElementUi/form-item-textarea.md +20 -0
- package/docs/pitElementUi/form-item-tree-select.md +27 -0
- package/docs/pitElementUi/form-item-upload-card.md +18 -0
- package/docs/pitElementUi/form-item-upload.md +1 -0
- package/docs/pitElementUi/form-two.md +102 -0
- package/docs/pitElementUi/form.md +952 -0
- package/docs/pitElementUi/i18n.md +228 -0
- package/docs/pitElementUi/icon-custom.md +99 -0
- package/docs/pitElementUi/icon-line-custom.md +12 -0
- package/docs/pitElementUi/icon.md +28 -0
- package/docs/pitElementUi/image.md +178 -0
- package/docs/pitElementUi/infiniteScroll.md +87 -0
- package/docs/pitElementUi/input-number.md +197 -0
- package/docs/pitElementUi/input-select.md +1 -0
- package/docs/pitElementUi/input.md +800 -0
- package/docs/pitElementUi/installation.md +9 -0
- package/docs/pitElementUi/layout-column.md +376 -0
- package/docs/pitElementUi/layout-tree.md +715 -0
- package/docs/pitElementUi/layout.md +354 -0
- package/docs/pitElementUi/link.md +66 -0
- package/docs/pitElementUi/loading.md +208 -0
- package/docs/pitElementUi/menu.md +403 -0
- package/docs/pitElementUi/message-box.md +326 -0
- package/docs/pitElementUi/message.md +219 -0
- package/docs/pitElementUi/notification.md +311 -0
- package/docs/pitElementUi/page-header.md +40 -0
- package/docs/pitElementUi/pagination.md +200 -0
- package/docs/pitElementUi/popconfirm.md +60 -0
- package/docs/pitElementUi/popover.md +167 -0
- package/docs/pitElementUi/progress.md +178 -0
- package/docs/pitElementUi/quickstart.md +290 -0
- package/docs/pitElementUi/radio.md +211 -0
- package/docs/pitElementUi/rate.md +135 -0
- package/docs/pitElementUi/result.md +76 -0
- package/docs/pitElementUi/select-tree.md +661 -0
- package/docs/pitElementUi/select.md +586 -0
- package/docs/pitElementUi/skeleton.md +316 -0
- package/docs/pitElementUi/slider.md +237 -0
- package/docs/pitElementUi/steps.md +154 -0
- package/docs/pitElementUi/switch.md +142 -0
- package/docs/pitElementUi/table.md +4023 -0
- package/docs/pitElementUi/tabs.md +303 -0
- package/docs/pitElementUi/tag.md +203 -0
- package/docs/pitElementUi/time-picker.md +199 -0
- package/docs/pitElementUi/timeline.md +154 -0
- package/docs/pitElementUi/tooltip.md +177 -0
- package/docs/pitElementUi/transfer.md +249 -0
- package/docs/pitElementUi/transition.md +155 -0
- package/docs/pitElementUi/tree.md +1157 -0
- package/docs/pitElementUi/typography.md +151 -0
- package/docs/pitElementUi/upload-table.md +39 -0
- package/docs/pitElementUi/upload.md +392 -0
- package/docs/pitElementUi/virtual-list.md +154 -0
- package/docs/pitElementUi/virtual-select-tree.md +243 -0
- package/docs/pitElementUi/virtual-select.md +451 -0
- package/docs/pitElementUi/virtual-table-column.md +1 -0
- package/docs/pitElementUi/virtual-table.md +490 -0
- package/docs/pitElementUi/virtual-tree.md +119 -0
- package/package.json +33 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
## MessageBox 弹框
|
|
2
|
+
模拟系统的消息提示框而实现的一套模态对话框组件,用于消息提示、确认消息和提交内容。
|
|
3
|
+
|
|
4
|
+
:::tip
|
|
5
|
+
从场景上说,MessageBox 的作用是美化系统自带的 `alert`、`confirm` 和 `prompt`,因此适合展示较为简单的内容。如果需要弹出较为复杂的内容,请使用 Dialog。
|
|
6
|
+
:::
|
|
7
|
+
|
|
8
|
+
### 消息提示
|
|
9
|
+
|
|
10
|
+
当用户进行操作时会被触发,该对话框中断用户操作,直到用户确认知晓后才可关闭。
|
|
11
|
+
|
|
12
|
+
:::demo 调用`$alert`方法即可打开消息提示,它模拟了系统的 `alert`,无法通过按下 ESC 或点击框外关闭。此例中接收了两个参数,`message`和`title`。值得一提的是,窗口被关闭后,它默认会返回一个`Promise`对象便于进行后续操作的处理。若不确定浏览器是否支持`Promise`,可自行引入第三方 polyfill 或像本例一样使用回调进行后续处理。
|
|
13
|
+
```html
|
|
14
|
+
<template>
|
|
15
|
+
<el-button type="text" @click="open">点击打开 Message Box</el-button>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script>
|
|
19
|
+
export default {
|
|
20
|
+
methods: {
|
|
21
|
+
open() {
|
|
22
|
+
this.$alert('这是一段内容', '标题名称', {
|
|
23
|
+
confirmButtonText: '确定',
|
|
24
|
+
callback: action => {
|
|
25
|
+
this.$message({
|
|
26
|
+
type: 'info',
|
|
27
|
+
message: `action: ${ action }`
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
</script>
|
|
35
|
+
```
|
|
36
|
+
:::
|
|
37
|
+
|
|
38
|
+
### 确认消息
|
|
39
|
+
|
|
40
|
+
提示用户确认其已经触发的动作,并询问是否进行此操作时会用到此对话框。
|
|
41
|
+
|
|
42
|
+
:::demo 调用`$confirm`方法即可打开消息提示,它模拟了系统的 `confirm`。Message Box 组件也拥有极高的定制性,我们可以传入`options`作为第三个参数,它是一个字面量对象。`type`字段表明消息类型,可以为`success`,`error`,`info`和`warning`,无效的设置将会被忽略。注意,第二个参数`title`必须定义为`String`类型,如果是`Object`,会被理解为`options`。在这里我们用了 Promise 来处理后续响应。
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<template>
|
|
46
|
+
<el-button type="text" @click="open">点击打开 Message Box</el-button>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
export default {
|
|
51
|
+
methods: {
|
|
52
|
+
open() {
|
|
53
|
+
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
|
|
54
|
+
confirmButtonText: '确定',
|
|
55
|
+
cancelButtonText: '取消',
|
|
56
|
+
type: 'warning'
|
|
57
|
+
}).then(() => {
|
|
58
|
+
this.$message({
|
|
59
|
+
type: 'success',
|
|
60
|
+
message: '删除成功!'
|
|
61
|
+
});
|
|
62
|
+
}).catch(() => {
|
|
63
|
+
this.$message({
|
|
64
|
+
type: 'info',
|
|
65
|
+
message: '已取消删除'
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
</script>
|
|
72
|
+
```
|
|
73
|
+
:::
|
|
74
|
+
|
|
75
|
+
### 提交内容
|
|
76
|
+
|
|
77
|
+
当用户进行操作时会被触发,中断用户操作,提示用户进行输入的对话框。
|
|
78
|
+
|
|
79
|
+
:::demo 调用`$prompt`方法即可打开消息提示,它模拟了系统的 `prompt`。可以用`inputPattern`字段自己规定匹配模式,或者用`inputValidator`规定校验函数,可以返回`Boolean`或`String`,返回`false`或字符串时均表示校验未通过,同时返回的字符串相当于定义了`inputErrorMessage`字段。此外,可以用`inputPlaceholder`字段来定义输入框的占位符。
|
|
80
|
+
|
|
81
|
+
```html
|
|
82
|
+
<template>
|
|
83
|
+
<el-button type="text" @click="open">点击打开 Message Box</el-button>
|
|
84
|
+
</template>
|
|
85
|
+
|
|
86
|
+
<script>
|
|
87
|
+
export default {
|
|
88
|
+
methods: {
|
|
89
|
+
open() {
|
|
90
|
+
this.$prompt('请输入邮箱', '提示', {
|
|
91
|
+
confirmButtonText: '确定',
|
|
92
|
+
cancelButtonText: '取消',
|
|
93
|
+
inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
|
|
94
|
+
inputErrorMessage: '邮箱格式不正确'
|
|
95
|
+
}).then(({ value }) => {
|
|
96
|
+
this.$message({
|
|
97
|
+
type: 'success',
|
|
98
|
+
message: '你的邮箱是: ' + value
|
|
99
|
+
});
|
|
100
|
+
}).catch(() => {
|
|
101
|
+
this.$message({
|
|
102
|
+
type: 'info',
|
|
103
|
+
message: '取消输入'
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
</script>
|
|
110
|
+
```
|
|
111
|
+
:::
|
|
112
|
+
|
|
113
|
+
### 自定义
|
|
114
|
+
|
|
115
|
+
可自定义配置不同内容。
|
|
116
|
+
|
|
117
|
+
:::demo 以上三个方法都是对`$msgbox`方法的再包装。本例直接调用`$msgbox`方法,使用了`showCancelButton`字段,用于显示取消按钮。另外可使用`cancelButtonClass`为其添加自定义样式,使用`cancelButtonText`来自定义按钮文本(Confirm 按钮也具有相同的字段,在文末的字段说明中有完整的字段列表)。此例还使用了`beforeClose`属性,它的值是一个方法,会在 MessageBox 的实例关闭前被调用,同时暂停实例的关闭。它有三个参数:`action`、实例本身和`done`方法。使用它能够在关闭前对实例进行一些操作,比如为确定按钮添加`loading`状态等;此时若需要关闭实例,可以调用`done`方法(若在`beforeClose`中没有调用`done`,则实例不会关闭)。
|
|
118
|
+
|
|
119
|
+
```html
|
|
120
|
+
<template>
|
|
121
|
+
<el-button type="text" @click="open">点击打开 Message Box</el-button>
|
|
122
|
+
</template>
|
|
123
|
+
|
|
124
|
+
<script>
|
|
125
|
+
export default {
|
|
126
|
+
methods: {
|
|
127
|
+
open() {
|
|
128
|
+
const h = this.$createElement;
|
|
129
|
+
this.$msgbox({
|
|
130
|
+
title: '消息',
|
|
131
|
+
message: h('p', null, [
|
|
132
|
+
h('span', null, '内容可以是 '),
|
|
133
|
+
h('i', { style: 'color: teal' }, 'VNode')
|
|
134
|
+
]),
|
|
135
|
+
showCancelButton: true,
|
|
136
|
+
confirmButtonText: '确定',
|
|
137
|
+
cancelButtonText: '取消',
|
|
138
|
+
beforeClose: (action, instance, done) => {
|
|
139
|
+
if (action === 'confirm') {
|
|
140
|
+
instance.confirmButtonLoading = true;
|
|
141
|
+
instance.confirmButtonText = '执行中...';
|
|
142
|
+
setTimeout(() => {
|
|
143
|
+
done();
|
|
144
|
+
setTimeout(() => {
|
|
145
|
+
instance.confirmButtonLoading = false;
|
|
146
|
+
}, 300);
|
|
147
|
+
}, 3000);
|
|
148
|
+
} else {
|
|
149
|
+
done();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}).then(action => {
|
|
153
|
+
this.$message({
|
|
154
|
+
type: 'info',
|
|
155
|
+
message: 'action: ' + action
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
</script>
|
|
162
|
+
```
|
|
163
|
+
:::
|
|
164
|
+
|
|
165
|
+
:::tip
|
|
166
|
+
弹出层的内容可以是 `VNode`,所以我们能把一些自定义组件传入其中。每次弹出层打开后,Vue 会对新老 `VNode` 节点进行比对,然后将根据比较结果进行最小单位地修改视图。这也许会造成弹出层内容区域的组件没有重新渲染,例如 [#8931](https://github.com/ElemeFE/element/issues/8931)。当这类问题出现时,解决方案是给 `VNode` 加上一个不相同的 key,参考[这里](https://jsfiddle.net/zhiyang/ezmhq2ef/)。
|
|
167
|
+
:::
|
|
168
|
+
|
|
169
|
+
### 使用 HTML 片段
|
|
170
|
+
|
|
171
|
+
`message` 属性支持传入 HTML 片段。
|
|
172
|
+
|
|
173
|
+
:::demo 将`dangerouslyUseHTMLString`属性设置为 true,`message` 就会被当作 HTML 片段处理。
|
|
174
|
+
|
|
175
|
+
```html
|
|
176
|
+
<template>
|
|
177
|
+
<el-button type="text" @click="open">点击打开 Message Box</el-button>
|
|
178
|
+
</template>
|
|
179
|
+
|
|
180
|
+
<script>
|
|
181
|
+
export default {
|
|
182
|
+
methods: {
|
|
183
|
+
open() {
|
|
184
|
+
this.$alert('<strong>这是 <i>HTML</i> 片段</strong>', 'HTML 片段', {
|
|
185
|
+
dangerouslyUseHTMLString: true
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
</script>
|
|
191
|
+
```
|
|
192
|
+
:::
|
|
193
|
+
|
|
194
|
+
:::warning
|
|
195
|
+
`message` 属性虽然支持传入 HTML 片段,但是在网站上动态渲染任意 HTML 是非常危险的,因为容易导致 [XSS 攻击](https://en.wikipedia.org/wiki/Cross-site_scripting)。因此在 `dangerouslyUseHTMLString` 打开的情况下,请确保 `message` 的内容是可信的,**永远不要**将用户提交的内容赋值给 `message` 属性。
|
|
196
|
+
:::
|
|
197
|
+
|
|
198
|
+
### 区分取消与关闭
|
|
199
|
+
|
|
200
|
+
有些场景下,点击取消按钮与点击关闭按钮有着不同的含义。
|
|
201
|
+
|
|
202
|
+
:::demo 默认情况下,当用户触发取消(点击取消按钮)和触发关闭(点击关闭按钮或遮罩层、按下 ESC 键)时,Promise 的 reject 回调和`callback`回调的参数均为 'cancel'。如果将`distinguishCancelAndClose`属性设置为 true,则上述两种行为的参数分别为 'cancel' 和 'close'。
|
|
203
|
+
|
|
204
|
+
```html
|
|
205
|
+
<template>
|
|
206
|
+
<el-button type="text" @click="open">点击打开 Message Box</el-button>
|
|
207
|
+
</template>
|
|
208
|
+
|
|
209
|
+
<script>
|
|
210
|
+
export default {
|
|
211
|
+
methods: {
|
|
212
|
+
open() {
|
|
213
|
+
this.$confirm('检测到未保存的内容,是否在离开页面前保存修改?', '确认信息', {
|
|
214
|
+
distinguishCancelAndClose: true,
|
|
215
|
+
confirmButtonText: '保存',
|
|
216
|
+
cancelButtonText: '放弃修改'
|
|
217
|
+
})
|
|
218
|
+
.then(() => {
|
|
219
|
+
this.$message({
|
|
220
|
+
type: 'info',
|
|
221
|
+
message: '保存修改'
|
|
222
|
+
});
|
|
223
|
+
})
|
|
224
|
+
.catch(action => {
|
|
225
|
+
this.$message({
|
|
226
|
+
type: 'info',
|
|
227
|
+
message: action === 'cancel'
|
|
228
|
+
? '放弃保存并离开页面'
|
|
229
|
+
: '停留在当前页面'
|
|
230
|
+
})
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
</script>
|
|
236
|
+
```
|
|
237
|
+
:::
|
|
238
|
+
|
|
239
|
+
### 居中布局
|
|
240
|
+
内容支持居中布局
|
|
241
|
+
|
|
242
|
+
:::demo 将 `center` 设置为 `true` 即可开启居中布局
|
|
243
|
+
|
|
244
|
+
```html
|
|
245
|
+
<template>
|
|
246
|
+
<el-button type="text" @click="open">点击打开 Message Box</el-button>
|
|
247
|
+
</template>
|
|
248
|
+
|
|
249
|
+
<script>
|
|
250
|
+
export default {
|
|
251
|
+
methods: {
|
|
252
|
+
open() {
|
|
253
|
+
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
|
|
254
|
+
confirmButtonText: '确定',
|
|
255
|
+
cancelButtonText: '取消',
|
|
256
|
+
type: 'warning',
|
|
257
|
+
center: true
|
|
258
|
+
}).then(() => {
|
|
259
|
+
this.$message({
|
|
260
|
+
type: 'success',
|
|
261
|
+
message: '删除成功!'
|
|
262
|
+
});
|
|
263
|
+
}).catch(() => {
|
|
264
|
+
this.$message({
|
|
265
|
+
type: 'info',
|
|
266
|
+
message: '已取消删除'
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
</script>
|
|
273
|
+
```
|
|
274
|
+
:::
|
|
275
|
+
|
|
276
|
+
### 全局方法
|
|
277
|
+
|
|
278
|
+
如果你完整引入了 Element,它会为 Vue.prototype 添加如下全局方法:$msgbox, $alert, $confirm 和 $prompt。因此在 Vue instance 中可以采用本页面中的方式调用 `MessageBox`。调用参数为:
|
|
279
|
+
- `$msgbox(options)`
|
|
280
|
+
- `$alert(message, title, options)` 或 `$alert(message, options)`
|
|
281
|
+
- `$confirm(message, title, options)` 或 `$confirm(message, options)`
|
|
282
|
+
- `$prompt(message, title, options)` 或 `$prompt(message, options)`
|
|
283
|
+
|
|
284
|
+
### 单独引用
|
|
285
|
+
|
|
286
|
+
如果单独引入 `MessageBox`:
|
|
287
|
+
|
|
288
|
+
```javascript
|
|
289
|
+
import { MessageBox } from 'element-ui';
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
那么对应于上述四个全局方法的调用方法依次为:MessageBox, MessageBox.alert, MessageBox.confirm 和 MessageBox.prompt,调用参数与全局方法相同。
|
|
293
|
+
|
|
294
|
+
### Options
|
|
295
|
+
|
|
296
|
+
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
297
|
+
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
|
298
|
+
| title | MessageBox 标题 | string | — | — |
|
|
299
|
+
| message | MessageBox 消息正文内容 | string / VNode | — | — |
|
|
300
|
+
| dangerouslyUseHTMLString | 是否将 message 属性作为 HTML 片段处理 | boolean | — | false |
|
|
301
|
+
| type | 消息类型,用于显示图标 | string | success / info / warning / error | — |
|
|
302
|
+
| iconClass | 自定义图标的类名,会覆盖 `type` | string | — | — |
|
|
303
|
+
| customClass | MessageBox 的自定义类名 | string | — | — |
|
|
304
|
+
| callback | 若不使用 Promise,可以使用此参数指定 MessageBox 关闭后的回调 | function(action, instance),action 的值为'confirm', 'cancel'或'close', instance 为 MessageBox 实例,可以通过它访问实例上的属性和方法 | — | — |
|
|
305
|
+
| showClose | MessageBox 是否显示右上角关闭按钮 | boolean | — | true |
|
|
306
|
+
| beforeClose | MessageBox 关闭前的回调,会暂停实例的关闭 | function(action, instance, done),action 的值为'confirm', 'cancel'或'close';instance 为 MessageBox 实例,可以通过它访问实例上的属性和方法;done 用于关闭 MessageBox 实例 | — | — |
|
|
307
|
+
| distinguishCancelAndClose | 是否将取消(点击取消按钮)与关闭(点击关闭按钮或遮罩层、按下 ESC 键)进行区分 | boolean | — | false |
|
|
308
|
+
| lockScroll | 是否在 MessageBox 出现时将 body 滚动锁定 | boolean | — | true |
|
|
309
|
+
| showCancelButton | 是否显示取消按钮 | boolean | — | false(以 confirm 和 prompt 方式调用时为 true) |
|
|
310
|
+
| showConfirmButton | 是否显示确定按钮 | boolean | — | true |
|
|
311
|
+
| cancelButtonText | 取消按钮的文本内容 | string | — | 取消 |
|
|
312
|
+
| confirmButtonText | 确定按钮的文本内容 | string | — | 确定 |
|
|
313
|
+
| cancelButtonClass | 取消按钮的自定义类名 | string | — | — |
|
|
314
|
+
| confirmButtonClass | 确定按钮的自定义类名 | string | — | — |
|
|
315
|
+
| closeOnClickModal | 是否可通过点击遮罩关闭 MessageBox | boolean | — | true(以 alert 方式调用时为 false) |
|
|
316
|
+
| closeOnPressEscape | 是否可通过按下 ESC 键关闭 MessageBox | boolean | — | true(以 alert 方式调用时为 false) |
|
|
317
|
+
| closeOnHashChange | 是否在 hashchange 时关闭 MessageBox | boolean | — | true |
|
|
318
|
+
| showInput | 是否显示输入框 | boolean | — | false(以 prompt 方式调用时为 true)|
|
|
319
|
+
| inputPlaceholder | 输入框的占位符 | string | — | — |
|
|
320
|
+
| inputType | 输入框的类型 | string | — | text |
|
|
321
|
+
| inputValue | 输入框的初始文本 | string | — | — |
|
|
322
|
+
| inputPattern | 输入框的校验表达式 | regexp | — | — |
|
|
323
|
+
| inputValidator | 输入框的校验函数。可以返回布尔值或字符串,若返回一个字符串, 则返回结果会被赋值给 inputErrorMessage | function | — | — |
|
|
324
|
+
| inputErrorMessage | 校验未通过时的提示文本 | string | — | 输入的数据不合法! |
|
|
325
|
+
| center | 是否居中布局 | boolean | — | false |
|
|
326
|
+
| roundButton | 是否使用圆角按钮 | boolean | — | false |
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
## Message 消息提示
|
|
2
|
+
|
|
3
|
+
常用于主动操作后的反馈提示。与 Notification 的区别是后者更多用于系统级通知的被动提醒。
|
|
4
|
+
|
|
5
|
+
### 基础用法
|
|
6
|
+
|
|
7
|
+
从顶部出现,3 秒后自动消失。
|
|
8
|
+
|
|
9
|
+
:::demo Message 在配置上与 Notification 非常类似,所以部分 options 在此不做详尽解释,文末有 options 列表,可以结合 Notification 的文档理解它们。Element 注册了一个`$message`方法用于调用,Message 可以接收一个字符串或一个 VNode 作为参数,它会被显示为正文内容。
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<template>
|
|
13
|
+
<el-button :plain="true" @click="open">打开消息提示</el-button>
|
|
14
|
+
<el-button :plain="true" @click="openVn">VNode</el-button>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script>
|
|
18
|
+
export default {
|
|
19
|
+
methods: {
|
|
20
|
+
open() {
|
|
21
|
+
this.$message('这是一条消息提示');
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
openVn() {
|
|
25
|
+
const h = this.$createElement;
|
|
26
|
+
this.$message({
|
|
27
|
+
message: h('p', null, [
|
|
28
|
+
h('span', null, '内容可以是 '),
|
|
29
|
+
h('i', { style: 'color: teal' }, 'VNode')
|
|
30
|
+
])
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
</script>
|
|
36
|
+
```
|
|
37
|
+
:::
|
|
38
|
+
|
|
39
|
+
### 不同状态
|
|
40
|
+
|
|
41
|
+
用来显示「成功、警告、消息、错误」类的操作反馈。
|
|
42
|
+
|
|
43
|
+
:::demo 当需要自定义更多属性时,Message 也可以接收一个对象为参数。比如,设置`type`字段可以定义不同的状态,默认为`info`。此时正文内容以`message`的值传入。同时,我们也为 Message 的各种 type 注册了方法,可以在不传入`type`字段的情况下像`open4`那样直接调用。
|
|
44
|
+
```html
|
|
45
|
+
<template>
|
|
46
|
+
<el-button :plain="true" @click="open2">成功</el-button>
|
|
47
|
+
<el-button :plain="true" @click="open3">警告</el-button>
|
|
48
|
+
<el-button :plain="true" @click="open1">消息</el-button>
|
|
49
|
+
<el-button :plain="true" @click="open4">错误</el-button>
|
|
50
|
+
</template>
|
|
51
|
+
|
|
52
|
+
<script>
|
|
53
|
+
export default {
|
|
54
|
+
methods: {
|
|
55
|
+
open1() {
|
|
56
|
+
this.$message('这是一条消息提示');
|
|
57
|
+
},
|
|
58
|
+
open2() {
|
|
59
|
+
this.$message({
|
|
60
|
+
message: '恭喜你,这是一条成功消息',
|
|
61
|
+
type: 'success'
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
open3() {
|
|
66
|
+
this.$message({
|
|
67
|
+
message: '警告哦,这是一条警告消息',
|
|
68
|
+
type: 'warning'
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
open4() {
|
|
73
|
+
this.$message.error('错了哦,这是一条错误消息');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
78
|
+
```
|
|
79
|
+
:::
|
|
80
|
+
|
|
81
|
+
### 可关闭
|
|
82
|
+
|
|
83
|
+
可以添加关闭按钮。
|
|
84
|
+
|
|
85
|
+
:::demo 默认的 Message 是不可以被人工关闭的,如果需要可手动关闭的 Message,可以使用`showClose`字段。此外,和 Notification 一样,Message 拥有可控的`duration`,设置`0`为不会被自动关闭,默认为 3000 毫秒。
|
|
86
|
+
```html
|
|
87
|
+
<template>
|
|
88
|
+
<el-button :plain="true" @click="open1">消息</el-button>
|
|
89
|
+
<el-button :plain="true" @click="open2">成功</el-button>
|
|
90
|
+
<el-button :plain="true" @click="open3">警告</el-button>
|
|
91
|
+
<el-button :plain="true" @click="open4">错误</el-button>
|
|
92
|
+
</template>
|
|
93
|
+
|
|
94
|
+
<script>
|
|
95
|
+
export default {
|
|
96
|
+
methods: {
|
|
97
|
+
open1() {
|
|
98
|
+
this.$message({
|
|
99
|
+
showClose: true,
|
|
100
|
+
message: '这是一条消息提示'
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
open2() {
|
|
105
|
+
this.$message({
|
|
106
|
+
showClose: true,
|
|
107
|
+
message: '恭喜你,这是一条成功消息',
|
|
108
|
+
type: 'success'
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
open3() {
|
|
113
|
+
this.$message({
|
|
114
|
+
showClose: true,
|
|
115
|
+
message: '警告哦,这是一条警告消息',
|
|
116
|
+
type: 'warning'
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
open4() {
|
|
121
|
+
this.$message({
|
|
122
|
+
showClose: true,
|
|
123
|
+
message: '错了哦,这是一条错误消息',
|
|
124
|
+
type: 'error'
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
</script>
|
|
130
|
+
```
|
|
131
|
+
:::
|
|
132
|
+
|
|
133
|
+
### 文字居中
|
|
134
|
+
使用 `center` 属性让文字水平居中。
|
|
135
|
+
|
|
136
|
+
:::demo
|
|
137
|
+
|
|
138
|
+
```html
|
|
139
|
+
<template>
|
|
140
|
+
<el-button :plain="true" @click="openCenter">文字居中</el-button>
|
|
141
|
+
</template>
|
|
142
|
+
|
|
143
|
+
<script>
|
|
144
|
+
export default {
|
|
145
|
+
methods: {
|
|
146
|
+
openCenter() {
|
|
147
|
+
this.$message({
|
|
148
|
+
message: '居中的文字',
|
|
149
|
+
center: true
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
</script>
|
|
155
|
+
```
|
|
156
|
+
:::
|
|
157
|
+
|
|
158
|
+
### 使用 HTML 片段
|
|
159
|
+
`message` 属性支持传入 HTML 片段
|
|
160
|
+
|
|
161
|
+
:::demo 将`dangerouslyUseHTMLString`属性设置为 true,`message` 就会被当作 HTML 片段处理。
|
|
162
|
+
|
|
163
|
+
```html
|
|
164
|
+
<template>
|
|
165
|
+
<el-button :plain="true" @click="openHTML">使用 HTML 片段</el-button>
|
|
166
|
+
</template>
|
|
167
|
+
|
|
168
|
+
<script>
|
|
169
|
+
export default {
|
|
170
|
+
methods: {
|
|
171
|
+
openHTML() {
|
|
172
|
+
this.$message({
|
|
173
|
+
dangerouslyUseHTMLString: true,
|
|
174
|
+
message: '<strong>这是 <i>HTML</i> 片段</strong>'
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
</script>
|
|
180
|
+
```
|
|
181
|
+
:::
|
|
182
|
+
|
|
183
|
+
:::warning
|
|
184
|
+
`message` 属性虽然支持传入 HTML 片段,但是在网站上动态渲染任意 HTML 是非常危险的,因为容易导致 [XSS 攻击](https://en.wikipedia.org/wiki/Cross-site_scripting)。因此在 `dangerouslyUseHTMLString` 打开的情况下,请确保 `message` 的内容是可信的,**永远不要**将用户提交的内容赋值给 `message` 属性。
|
|
185
|
+
:::
|
|
186
|
+
|
|
187
|
+
### 全局方法
|
|
188
|
+
|
|
189
|
+
Element 为 Vue.prototype 添加了全局方法 $message。因此在 vue instance 中可以采用本页面中的方式调用 `Message`。
|
|
190
|
+
|
|
191
|
+
### 单独引用
|
|
192
|
+
|
|
193
|
+
单独引入 `Message`:
|
|
194
|
+
|
|
195
|
+
```javascript
|
|
196
|
+
import { Message } from 'element-ui';
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
此时调用方法为 `Message(options)`。我们也为每个 type 定义了各自的方法,如 `Message.success(options)`。并且可以调用 `Message.closeAll()` 手动关闭所有实例。
|
|
200
|
+
|
|
201
|
+
### Options
|
|
202
|
+
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
203
|
+
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
|
204
|
+
| message | 消息文字 | string / VNode | — | — |
|
|
205
|
+
| type | 主题 | string | success/warning/info/error | info |
|
|
206
|
+
| iconClass | 自定义图标的类名,会覆盖 `type` | string | — | — |
|
|
207
|
+
| dangerouslyUseHTMLString | 是否将 message 属性作为 HTML 片段处理 | boolean | — | false |
|
|
208
|
+
| customClass | 自定义类名 | string | — | — |
|
|
209
|
+
| duration | 显示时间, 毫秒。设为 0 则不会自动关闭 | number | — | 3000 |
|
|
210
|
+
| showClose | 是否显示关闭按钮 | boolean | — | false |
|
|
211
|
+
| center | 文字是否居中 | boolean | — | false |
|
|
212
|
+
| onClose | 关闭时的回调函数, 参数为被关闭的 message 实例 | function | — | — |
|
|
213
|
+
| offset | Message 距离窗口顶部的偏移量 | number | — | 20 |
|
|
214
|
+
|
|
215
|
+
### 方法
|
|
216
|
+
调用 `Message` 或 `this.$message` 会返回当前 Message 的实例。如果需要手动关闭实例,可以调用它的 `close` 方法。
|
|
217
|
+
| 方法名 | 说明 |
|
|
218
|
+
| ---- | ---- |
|
|
219
|
+
| close | 关闭当前的 Message |
|