@infly/ui 1.0.18 → 1.0.20
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 +53 -43
- package/index.js +47 -33
- package/package.json +60 -29
- package/scripts/install-comp.js +13 -0
- package/src/Base/InflyCheckBox/InflyCheckBox.test.js +154 -0
- package/src/Base/InflyCheckBox/InflyCheckBox.vue +227 -0
- package/src/Base/InflyCheckBox/index.js +6 -0
- package/src/Base/InflyDialog/InflyDialog.test.js +122 -0
- package/src/Base/InflyDialog/InflyDialog.vue +111 -0
- package/src/Base/InflyDialog/index.js +6 -0
- package/src/Base/InflyForm/InflyForm.test.js +239 -0
- package/src/Base/InflyForm/InflyForm.vue +974 -0
- package/src/Base/InflyForm/index.js +6 -0
- package/src/Base/InflyInput/InflyInput.test.js +105 -0
- package/src/Base/InflyInput/InflyInput.vue +167 -0
- package/src/Base/InflyInput/index.js +6 -0
- package/src/Base/InflyList/InflyList.test.js +229 -0
- package/src/Base/InflyList/InflyList.vue +926 -0
- package/src/Base/InflyList/index.js +6 -0
- package/src/Business/BusinessSwitch/BusinessSwitch.test.js +250 -0
- package/src/Business/BusinessSwitch/BusinessSwitch.vue +115 -0
- package/src/Business/BusinessSwitch/index.js +6 -0
- package/src/Business/BusinessTag/BusinessTag.test.js +70 -0
- package/src/Business/BusinessTag/BusinessTag.vue +58 -0
- package/src/Business/BusinessTag/index.js +6 -0
- package/src/Business/InstitutionSelect/InstitutionSelect.test.js +281 -0
- package/src/Business/InstitutionSelect/InstitutionSelect.vue +768 -0
- package/src/Business/InstitutionSelect/index.js +6 -0
- package/src/utils/Uts.js +3 -0
- package/src/utils/ts-libs.test.js +31 -0
- package/styles/base.scss +755 -0
- package/styles/index.scss +202 -0
- package/styles/mixin.scss +19 -0
- package/styles/variables.scss +24 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- 统一多选框组件 - 整合了普通多选框和按钮样式多选框 -->
|
|
3
|
+
<div :class="['comp-InflyCheckbox infly-checkbox__wrap', wrapClass]">
|
|
4
|
+
<!-- 全选框 (仅在 checkbox 类型且 showSelectAll 为 true 时显示) -->
|
|
5
|
+
<el-checkbox
|
|
6
|
+
v-if="showSelectAllCheckbox"
|
|
7
|
+
class="infly-checkbox__select-all"
|
|
8
|
+
:indeterminate="isIndeterminate"
|
|
9
|
+
v-model="checkAll"
|
|
10
|
+
:border="border"
|
|
11
|
+
:size="size"
|
|
12
|
+
:disabled="disabled"
|
|
13
|
+
@change="selectChange"
|
|
14
|
+
>
|
|
15
|
+
{{ selectAllText }}
|
|
16
|
+
</el-checkbox>
|
|
17
|
+
|
|
18
|
+
<!-- 多选框组 -->
|
|
19
|
+
<el-checkbox-group
|
|
20
|
+
class="infly-checkbox__group"
|
|
21
|
+
v-model="selectedValue"
|
|
22
|
+
:size="size"
|
|
23
|
+
:disabled="disabled"
|
|
24
|
+
@change="itemChange"
|
|
25
|
+
>
|
|
26
|
+
<template v-if="!isButtonType">
|
|
27
|
+
<el-checkbox
|
|
28
|
+
v-for="(item, index) in computedOptions"
|
|
29
|
+
:key="`checkbox-${index}`"
|
|
30
|
+
:label="item[valueProp]"
|
|
31
|
+
:border="border"
|
|
32
|
+
:disabled="item.disabled || disabled"
|
|
33
|
+
>
|
|
34
|
+
{{ item.name || item.label }}
|
|
35
|
+
</el-checkbox>
|
|
36
|
+
</template>
|
|
37
|
+
<template v-else>
|
|
38
|
+
<el-checkbox-button
|
|
39
|
+
v-for="(item, index) in computedOptions"
|
|
40
|
+
:key="`button-${index}`"
|
|
41
|
+
:label="item[valueProp]"
|
|
42
|
+
:disabled="item.disabled || disabled"
|
|
43
|
+
>
|
|
44
|
+
{{ item.name || item.label }}
|
|
45
|
+
</el-checkbox-button>
|
|
46
|
+
</template>
|
|
47
|
+
</el-checkbox-group>
|
|
48
|
+
|
|
49
|
+
<!-- 自定义插槽 -->
|
|
50
|
+
<slot name="extra"></slot>
|
|
51
|
+
</div>
|
|
52
|
+
</template>
|
|
53
|
+
|
|
54
|
+
<script>
|
|
55
|
+
import Uts from "../../utils/Uts.js";
|
|
56
|
+
|
|
57
|
+
export default {
|
|
58
|
+
name: "InflyCheckbox",
|
|
59
|
+
inheritAttrs: false,
|
|
60
|
+
props: {
|
|
61
|
+
// 必需 Props
|
|
62
|
+
value: {
|
|
63
|
+
type: Array,
|
|
64
|
+
required: true,
|
|
65
|
+
default: () => []
|
|
66
|
+
},
|
|
67
|
+
wrapClass: {
|
|
68
|
+
type: String,
|
|
69
|
+
default: ""
|
|
70
|
+
},
|
|
71
|
+
// 数据字段
|
|
72
|
+
nameProp: {
|
|
73
|
+
type: String,
|
|
74
|
+
default: "name"
|
|
75
|
+
},
|
|
76
|
+
valueProp: {
|
|
77
|
+
type: String,
|
|
78
|
+
default: "value"
|
|
79
|
+
},
|
|
80
|
+
boxs: {
|
|
81
|
+
// 兼容旧参数
|
|
82
|
+
type: Array,
|
|
83
|
+
required: false,
|
|
84
|
+
default: () => []
|
|
85
|
+
},
|
|
86
|
+
options: {
|
|
87
|
+
type: Array,
|
|
88
|
+
required: false,
|
|
89
|
+
default: () => []
|
|
90
|
+
},
|
|
91
|
+
// 可选 Props
|
|
92
|
+
type: {
|
|
93
|
+
type: String,
|
|
94
|
+
default: "checkbox",
|
|
95
|
+
validator: type => ["checkbox", "button"].includes(type)
|
|
96
|
+
},
|
|
97
|
+
showSelectAll: {
|
|
98
|
+
type: Boolean,
|
|
99
|
+
default: true
|
|
100
|
+
},
|
|
101
|
+
border: {
|
|
102
|
+
type: Boolean,
|
|
103
|
+
default: false
|
|
104
|
+
},
|
|
105
|
+
size: {
|
|
106
|
+
type: String,
|
|
107
|
+
default: "default",
|
|
108
|
+
validator: type => ["large", "default", "small", "mini"].includes(type)
|
|
109
|
+
},
|
|
110
|
+
disabled: {
|
|
111
|
+
type: Boolean,
|
|
112
|
+
default: false
|
|
113
|
+
},
|
|
114
|
+
selectAllText: {
|
|
115
|
+
type: String,
|
|
116
|
+
default: "全选"
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
// 兼容旧组件的 Props
|
|
120
|
+
totalCheckbox: {
|
|
121
|
+
type: Boolean,
|
|
122
|
+
default: true
|
|
123
|
+
},
|
|
124
|
+
span: {
|
|
125
|
+
type: Number,
|
|
126
|
+
default: 21
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
data() {
|
|
131
|
+
return {
|
|
132
|
+
selectedValue: [...this.value],
|
|
133
|
+
checkAll: false,
|
|
134
|
+
isIndeterminate: false
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
computed: {
|
|
139
|
+
// 判断是否为按钮类型
|
|
140
|
+
isButtonType() {
|
|
141
|
+
return this.type === "button";
|
|
142
|
+
},
|
|
143
|
+
computedOptions() {
|
|
144
|
+
return Uts.notEmptyArray(this.options) ? this.options : this.boxs;
|
|
145
|
+
},
|
|
146
|
+
// 判断是否显示全选框
|
|
147
|
+
showSelectAllCheckbox() {
|
|
148
|
+
return this.showSelectAll && !this.isButtonType && this.totalCheckbox;
|
|
149
|
+
},
|
|
150
|
+
// 所有可选项的值数组
|
|
151
|
+
allValues() {
|
|
152
|
+
return this.computedOptions.filter(item => !item.disabled).map(item => item[this.valueProp]);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
watch: {
|
|
157
|
+
// 监听外部 value 变化
|
|
158
|
+
value: {
|
|
159
|
+
handler(newValue) {
|
|
160
|
+
if (JSON.stringify(newValue) !== JSON.stringify(this.selectedValue)) {
|
|
161
|
+
this.selectedValue = [...newValue];
|
|
162
|
+
this.updateSelectAllState();
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
deep: true,
|
|
166
|
+
immediate: true
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
// 监听内部 selectedValue 变化
|
|
170
|
+
selectedValue: {
|
|
171
|
+
handler(newValue) {
|
|
172
|
+
this.$emit("input", [...newValue]);
|
|
173
|
+
this.$emit("change", [...newValue]);
|
|
174
|
+
},
|
|
175
|
+
deep: true
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
// 监听 boxs 变化,重新计算状态
|
|
179
|
+
computedOptions: {
|
|
180
|
+
handler() {
|
|
181
|
+
this.updateSelectAllState();
|
|
182
|
+
},
|
|
183
|
+
deep: true
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
created() {
|
|
188
|
+
this.updateSelectAllState();
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
methods: {
|
|
192
|
+
// 全选/取消全选
|
|
193
|
+
selectChange(val) {
|
|
194
|
+
this.selectedValue = val ? [...this.allValues] : [];
|
|
195
|
+
this.isIndeterminate = false;
|
|
196
|
+
this.$emit("select-all", val);
|
|
197
|
+
},
|
|
198
|
+
|
|
199
|
+
// 单项选择变化
|
|
200
|
+
itemChange(val) {
|
|
201
|
+
this.updateSelectAllState();
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
// 更新全选和半选状态
|
|
205
|
+
updateSelectAllState() {
|
|
206
|
+
const checkedCount = this.selectedValue.length;
|
|
207
|
+
const totalCount = this.allValues.length;
|
|
208
|
+
|
|
209
|
+
this.checkAll = checkedCount === totalCount && totalCount > 0;
|
|
210
|
+
this.isIndeterminate = checkedCount > 0 && checkedCount < totalCount;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
</script>
|
|
215
|
+
|
|
216
|
+
<style lang="scss" scoped>
|
|
217
|
+
.infly-checkbox__wrap {
|
|
218
|
+
display: flex;
|
|
219
|
+
align-items: flex-start;
|
|
220
|
+
flex-wrap: wrap;
|
|
221
|
+
|
|
222
|
+
.infly-checkbox__select-all {
|
|
223
|
+
margin-right: 30px;
|
|
224
|
+
flex-shrink: 0;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
</style>
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InflyDialog 组件测试
|
|
3
|
+
*
|
|
4
|
+
* 验证弹窗的 v-model 双向绑定、事件、自定义文本和显示逻辑。
|
|
5
|
+
*/
|
|
6
|
+
const { mount, shallowMount } = require("../../../test/helper");
|
|
7
|
+
const InflyDialog = require("./InflyDialog.vue");
|
|
8
|
+
|
|
9
|
+
describe("InflyDialog", () => {
|
|
10
|
+
describe("渲染", () => {
|
|
11
|
+
it("visible=false 时 el-dialog 不显示", () => {
|
|
12
|
+
const wrapper = shallowMount(InflyDialog, {
|
|
13
|
+
propsData: { visible: false },
|
|
14
|
+
});
|
|
15
|
+
// shallowMount 会 stub el-dialog,通过检查 innerVisible 来判断
|
|
16
|
+
assert.equal(wrapper.vm.$data.innerVisible, false);
|
|
17
|
+
wrapper.destroy();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("visible=true 时显示弹窗", () => {
|
|
21
|
+
const wrapper = shallowMount(InflyDialog, {
|
|
22
|
+
propsData: { visible: true },
|
|
23
|
+
});
|
|
24
|
+
assert.equal(wrapper.vm.$data.innerVisible, true);
|
|
25
|
+
wrapper.destroy();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("默认显示 footer(确定/取消按钮)", () => {
|
|
29
|
+
const wrapper = mount(InflyDialog, {
|
|
30
|
+
propsData: { visible: true },
|
|
31
|
+
});
|
|
32
|
+
// footer slot 默认渲染确定和取消按钮
|
|
33
|
+
assert.ok(wrapper.text().includes("确定"));
|
|
34
|
+
assert.ok(wrapper.text().includes("取消"));
|
|
35
|
+
wrapper.destroy();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("showFooter=false 时隐藏 footer", () => {
|
|
39
|
+
const wrapper = shallowMount(InflyDialog, {
|
|
40
|
+
propsData: { visible: true, showFooter: false },
|
|
41
|
+
});
|
|
42
|
+
// showFooter=false 时 footer slot 不渲染
|
|
43
|
+
assert.equal(wrapper.props().showFooter, false);
|
|
44
|
+
wrapper.destroy();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("事件", () => {
|
|
49
|
+
it("点击确定触发 confirm 事件", () => {
|
|
50
|
+
const wrapper = mount(InflyDialog, {
|
|
51
|
+
propsData: { visible: true },
|
|
52
|
+
});
|
|
53
|
+
wrapper.vm.handleConfirm();
|
|
54
|
+
assert.equal(wrapper.emitted().confirm.length, 1);
|
|
55
|
+
wrapper.destroy();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("点击取消触发 cancel 事件并关闭弹窗", () => {
|
|
59
|
+
const wrapper = mount(InflyDialog, {
|
|
60
|
+
propsData: { visible: true },
|
|
61
|
+
});
|
|
62
|
+
wrapper.vm.handleCancel();
|
|
63
|
+
assert.equal(wrapper.emitted().cancel.length, 1);
|
|
64
|
+
assert.equal(wrapper.vm.$data.innerVisible, false);
|
|
65
|
+
wrapper.destroy();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("close 方法将 innerVisible 设为 false 并触发 input 事件", async () => {
|
|
69
|
+
const wrapper = shallowMount(InflyDialog, {
|
|
70
|
+
propsData: { visible: true },
|
|
71
|
+
});
|
|
72
|
+
// 初始值:created 中设置为 visible 的值
|
|
73
|
+
assert.equal(wrapper.vm.$data.innerVisible, true);
|
|
74
|
+
wrapper.vm.close();
|
|
75
|
+
// close() 将 innerVisible 设为 false,Vue 2 的 watch 同步触发 emit
|
|
76
|
+
assert.equal(wrapper.vm.$data.innerVisible, false);
|
|
77
|
+
// 事件由 watch innerVisible 触发
|
|
78
|
+
const emitted = wrapper.emitted();
|
|
79
|
+
if (emitted.input) {
|
|
80
|
+
assert.equal(emitted.input.slice(-1)[0][0], false);
|
|
81
|
+
}
|
|
82
|
+
wrapper.destroy();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("Props", () => {
|
|
87
|
+
it("支持自定义 confirmText 和 cancelText", () => {
|
|
88
|
+
const wrapper = mount(InflyDialog, {
|
|
89
|
+
propsData: {
|
|
90
|
+
visible: true,
|
|
91
|
+
confirmText: "提交",
|
|
92
|
+
cancelText: "返回",
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
assert.ok(wrapper.text().includes("提交"));
|
|
96
|
+
assert.ok(wrapper.text().includes("返回"));
|
|
97
|
+
wrapper.destroy();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("支持 confirmLoading 状态", () => {
|
|
101
|
+
const wrapper = mount(InflyDialog, {
|
|
102
|
+
propsData: {
|
|
103
|
+
visible: true,
|
|
104
|
+
confirmLoading: true,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
const confirmBtn = wrapper.findAll(".el-button").wrappers.find(
|
|
108
|
+
(btn) => btn.text() === "确定"
|
|
109
|
+
);
|
|
110
|
+
assert.ok(confirmBtn);
|
|
111
|
+
wrapper.destroy();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("支持 value prop(v-model 兼容)", () => {
|
|
115
|
+
const wrapper = shallowMount(InflyDialog, {
|
|
116
|
+
propsData: { value: true },
|
|
117
|
+
});
|
|
118
|
+
assert.equal(wrapper.vm.$data.innerVisible, true);
|
|
119
|
+
wrapper.destroy();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="comp-InflyDialog">
|
|
3
|
+
<el-dialog
|
|
4
|
+
:visible.sync="innerVisible"
|
|
5
|
+
:width="$attrs.width || '600px'"
|
|
6
|
+
v-bind="$attrs"
|
|
7
|
+
@open="handleOpen"
|
|
8
|
+
@opened="handleOpened"
|
|
9
|
+
@close="handleClose"
|
|
10
|
+
@closed="handleClosed"
|
|
11
|
+
>
|
|
12
|
+
<slot name="content"></slot>
|
|
13
|
+
<span slot="footer" v-if="showFooter">
|
|
14
|
+
<slot name="footer">
|
|
15
|
+
<el-button size="mini" @click="handleCancel">{{ cancelText }}</el-button>
|
|
16
|
+
<el-button
|
|
17
|
+
type="primary"
|
|
18
|
+
size="mini"
|
|
19
|
+
:loading="confirmLoading"
|
|
20
|
+
@click="handleConfirm"
|
|
21
|
+
>
|
|
22
|
+
{{ confirmText }}
|
|
23
|
+
</el-button>
|
|
24
|
+
</slot>
|
|
25
|
+
</span>
|
|
26
|
+
</el-dialog>
|
|
27
|
+
</div>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<script>
|
|
31
|
+
export default {
|
|
32
|
+
name: "InflyDialog",
|
|
33
|
+
inheritAttrs: false,
|
|
34
|
+
props: {
|
|
35
|
+
value: {
|
|
36
|
+
type: Boolean,
|
|
37
|
+
default: false
|
|
38
|
+
},
|
|
39
|
+
visible: {
|
|
40
|
+
type: Boolean,
|
|
41
|
+
default: false
|
|
42
|
+
},
|
|
43
|
+
showFooter: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
default: true
|
|
46
|
+
},
|
|
47
|
+
confirmText: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: "确定"
|
|
50
|
+
},
|
|
51
|
+
cancelText: {
|
|
52
|
+
type: String,
|
|
53
|
+
default: "取消"
|
|
54
|
+
},
|
|
55
|
+
confirmLoading: {
|
|
56
|
+
type: Boolean,
|
|
57
|
+
default: false
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
data() {
|
|
61
|
+
return {
|
|
62
|
+
innerVisible: false
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
watch: {
|
|
66
|
+
visible(val) {
|
|
67
|
+
this.innerVisible = val;
|
|
68
|
+
},
|
|
69
|
+
value(val) {
|
|
70
|
+
this.innerVisible = val;
|
|
71
|
+
},
|
|
72
|
+
innerVisible(val) {
|
|
73
|
+
if (!val) {
|
|
74
|
+
this.$emit("input", false);
|
|
75
|
+
this.$emit("update:visible", false);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
created() {
|
|
80
|
+
this.innerVisible = this.visible || this.value;
|
|
81
|
+
},
|
|
82
|
+
methods: {
|
|
83
|
+
open() {
|
|
84
|
+
this.innerVisible = true;
|
|
85
|
+
},
|
|
86
|
+
close() {
|
|
87
|
+
this.innerVisible = false;
|
|
88
|
+
},
|
|
89
|
+
handleOpen() {
|
|
90
|
+
this.$emit("open");
|
|
91
|
+
},
|
|
92
|
+
handleOpened() {
|
|
93
|
+
this.$emit("opened");
|
|
94
|
+
},
|
|
95
|
+
handleClose() {
|
|
96
|
+
this.innerVisible = false;
|
|
97
|
+
this.$emit("close");
|
|
98
|
+
},
|
|
99
|
+
handleClosed() {
|
|
100
|
+
this.$emit("closed");
|
|
101
|
+
},
|
|
102
|
+
handleConfirm() {
|
|
103
|
+
this.$emit("confirm");
|
|
104
|
+
},
|
|
105
|
+
handleCancel() {
|
|
106
|
+
this.innerVisible = false;
|
|
107
|
+
this.$emit("cancel");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
</script>
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InflyForm 组件测试
|
|
3
|
+
*
|
|
4
|
+
* 验证配置化表单的渲染、筛选列表、按钮组、编辑/展示模式等核心行为。
|
|
5
|
+
* 使用 shallowMount 隔离子组件依赖。
|
|
6
|
+
*/
|
|
7
|
+
const { shallowMount } = require("../../../test/helper");
|
|
8
|
+
const InflyForm = require("./InflyForm.vue");
|
|
9
|
+
|
|
10
|
+
describe("InflyForm", () => {
|
|
11
|
+
describe("渲染", () => {
|
|
12
|
+
it("渲染容器 div", () => {
|
|
13
|
+
const wrapper = shallowMount(InflyForm, {
|
|
14
|
+
propsData: { formData: {} },
|
|
15
|
+
});
|
|
16
|
+
assert.ok(wrapper.find(".comp-InflyForm").exists());
|
|
17
|
+
wrapper.destroy();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("注入表单 class", () => {
|
|
21
|
+
const wrapper = shallowMount(InflyForm, {
|
|
22
|
+
propsData: {
|
|
23
|
+
formData: {},
|
|
24
|
+
formClass: "my-form",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
assert.ok(wrapper.exists());
|
|
28
|
+
wrapper.destroy();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("layout 属性影响 class", () => {
|
|
32
|
+
const wrapper = shallowMount(InflyForm, {
|
|
33
|
+
propsData: {
|
|
34
|
+
formData: {},
|
|
35
|
+
layout: "inline",
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
assert.ok(wrapper.vm.layoutClass.includes("standard-form--inline"));
|
|
39
|
+
wrapper.destroy();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("多 layout 组合", () => {
|
|
43
|
+
const wrapper = shallowMount(InflyForm, {
|
|
44
|
+
propsData: {
|
|
45
|
+
formData: {},
|
|
46
|
+
layout: ["inline", "compact"],
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
const cls = wrapper.vm.layoutClass;
|
|
50
|
+
assert.ok(cls.includes("standard-form--inline"));
|
|
51
|
+
assert.ok(cls.includes("standard-form--compact"));
|
|
52
|
+
wrapper.destroy();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("按钮", () => {
|
|
57
|
+
it("默认显示查询按钮,隐藏重置按钮", () => {
|
|
58
|
+
const wrapper = shallowMount(InflyForm, {
|
|
59
|
+
propsData: { formData: {} },
|
|
60
|
+
});
|
|
61
|
+
const optList = wrapper.vm.formOptBtnList;
|
|
62
|
+
// 默认 hideSearchBtn=false(显示查询),hideResetBtn=true(隐藏重置)
|
|
63
|
+
const queryBtn = optList.find((b) => b.label === "查询");
|
|
64
|
+
const resetBtn = optList.find((b) => b.label === "重置");
|
|
65
|
+
assert.equal(queryBtn.isHide, false);
|
|
66
|
+
assert.equal(resetBtn.isHide, true);
|
|
67
|
+
wrapper.destroy();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("hideSearchBtn=true 时隐藏查询按钮", () => {
|
|
71
|
+
const wrapper = shallowMount(InflyForm, {
|
|
72
|
+
propsData: {
|
|
73
|
+
formData: {},
|
|
74
|
+
hideSearchBtn: true,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const queryBtn = wrapper.vm.formOptBtnList.find((b) => b.label === "查询");
|
|
78
|
+
assert.equal(queryBtn.isHide, true);
|
|
79
|
+
wrapper.destroy();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("hideResetBtn=false 时显示重置按钮", () => {
|
|
83
|
+
const wrapper = shallowMount(InflyForm, {
|
|
84
|
+
propsData: {
|
|
85
|
+
formData: {},
|
|
86
|
+
hideResetBtn: false,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
const resetBtn = wrapper.vm.formOptBtnList.find((b) => b.label === "重置");
|
|
90
|
+
assert.equal(resetBtn.isHide, false);
|
|
91
|
+
wrapper.destroy();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("btnList 渲染外部按钮", () => {
|
|
95
|
+
const btnList = [{ name: "导出", label: "导出" }];
|
|
96
|
+
const wrapper = shallowMount(InflyForm, {
|
|
97
|
+
propsData: {
|
|
98
|
+
formData: {},
|
|
99
|
+
btnList,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
assert.equal(wrapper.vm.visibleBtnList.length, 1);
|
|
103
|
+
assert.equal(wrapper.vm.visibleBtnList[0].name, "导出");
|
|
104
|
+
wrapper.destroy();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("optBtnList 追加操作按钮", () => {
|
|
108
|
+
const optBtnList = [{ name: "批量操作", label: "批量操作" }];
|
|
109
|
+
const wrapper = shallowMount(InflyForm, {
|
|
110
|
+
propsData: {
|
|
111
|
+
formData: {},
|
|
112
|
+
optBtnList,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
assert.ok(wrapper.vm.formOptBtnList.length >= 3); // 查询+重置+optBtnList
|
|
116
|
+
wrapper.destroy();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("筛选列表", () => {
|
|
121
|
+
it("filterList 过滤 isHide=true 项", () => {
|
|
122
|
+
const filterList = [
|
|
123
|
+
{ label: "姓名", name: "name", type: "text" },
|
|
124
|
+
{ label: "隐藏项", name: "secret", type: "text", isHide: true },
|
|
125
|
+
];
|
|
126
|
+
const wrapper = shallowMount(InflyForm, {
|
|
127
|
+
propsData: { formData: {}, filterList },
|
|
128
|
+
});
|
|
129
|
+
// visibleFilterList 不包含隐藏项
|
|
130
|
+
const names = wrapper.vm.visibleFilterList.map((f) => f.name);
|
|
131
|
+
assert.ok(names.includes("name"));
|
|
132
|
+
assert.ok(!names.includes("secret"));
|
|
133
|
+
wrapper.destroy();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("filterList isHide 支持函数", () => {
|
|
137
|
+
const filterList = [
|
|
138
|
+
{ label: "姓名", name: "name", type: "text" },
|
|
139
|
+
{
|
|
140
|
+
label: "条件项",
|
|
141
|
+
name: "conditional",
|
|
142
|
+
type: "text",
|
|
143
|
+
isHide: (formData) => formData.showSecret !== true,
|
|
144
|
+
},
|
|
145
|
+
];
|
|
146
|
+
const wrapper = shallowMount(InflyForm, {
|
|
147
|
+
propsData: {
|
|
148
|
+
formData: { showSecret: true },
|
|
149
|
+
filterList,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
// showSecret=true 时条件项不隐藏
|
|
153
|
+
const names = wrapper.vm.visibleFilterList.map((f) => f.name);
|
|
154
|
+
assert.ok(names.includes("conditional"));
|
|
155
|
+
wrapper.destroy();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("无 name 时使用 prop 作为回退", () => {
|
|
159
|
+
const filterList = [{ label: "姓名", prop: "name", type: "text" }];
|
|
160
|
+
const wrapper = shallowMount(InflyForm, {
|
|
161
|
+
propsData: { formData: {}, filterList },
|
|
162
|
+
});
|
|
163
|
+
assert.equal(wrapper.vm.visibleFilterList[0].name, "name");
|
|
164
|
+
wrapper.destroy();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("自定义空值显示 emptyStr", () => {
|
|
168
|
+
const wrapper = shallowMount(InflyForm, {
|
|
169
|
+
propsData: {
|
|
170
|
+
formData: { name: "" },
|
|
171
|
+
emptyStr: "暂无数据",
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
assert.equal(wrapper.props().emptyStr, "暂无数据");
|
|
175
|
+
wrapper.destroy();
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe("表单方法", () => {
|
|
180
|
+
it("validate 方法存在", () => {
|
|
181
|
+
const wrapper = shallowMount(InflyForm, {
|
|
182
|
+
propsData: { formData: {} },
|
|
183
|
+
});
|
|
184
|
+
assert.equal(typeof wrapper.vm.validate, "function");
|
|
185
|
+
wrapper.destroy();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("getFormInstance 方法存在", () => {
|
|
189
|
+
const wrapper = shallowMount(InflyForm, {
|
|
190
|
+
propsData: { formData: {}, formRef: "myForm" },
|
|
191
|
+
});
|
|
192
|
+
assert.equal(typeof wrapper.vm.getFormInstance, "function");
|
|
193
|
+
wrapper.destroy();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("clearValidate 方法存在", () => {
|
|
197
|
+
const wrapper = shallowMount(InflyForm, {
|
|
198
|
+
propsData: { formData: {} },
|
|
199
|
+
});
|
|
200
|
+
assert.equal(typeof wrapper.vm.clearValidate, "function");
|
|
201
|
+
wrapper.destroy();
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe("编辑模式", () => {
|
|
206
|
+
it("isEdit prop 控制编辑模式", () => {
|
|
207
|
+
const wrapper = shallowMount(InflyForm, {
|
|
208
|
+
propsData: {
|
|
209
|
+
formData: {},
|
|
210
|
+
isEdit: false,
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
assert.equal(wrapper.vm.computedEdit, false);
|
|
214
|
+
wrapper.destroy();
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("isEdit=true 时进入编辑模式", () => {
|
|
218
|
+
const wrapper = shallowMount(InflyForm, {
|
|
219
|
+
propsData: {
|
|
220
|
+
formData: {},
|
|
221
|
+
isEdit: true,
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
assert.equal(wrapper.vm.computedEdit, true);
|
|
225
|
+
wrapper.destroy();
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe("事件", () => {
|
|
230
|
+
it("resetFormData 触发 reset-form 事件", () => {
|
|
231
|
+
const wrapper = shallowMount(InflyForm, {
|
|
232
|
+
propsData: { formData: { name: "test" } },
|
|
233
|
+
});
|
|
234
|
+
wrapper.vm.resetFormData();
|
|
235
|
+
assert.ok(wrapper.emitted("reset-form"));
|
|
236
|
+
wrapper.destroy();
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
});
|