@infly/ui 1.0.17 → 1.0.19

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.
Files changed (33) hide show
  1. package/README.md +43 -43
  2. package/package.json +53 -29
  3. package/scripts/install-comp.js +13 -0
  4. package/src/Base/InflyCheckBox/InflyCheckBox.test.js +154 -0
  5. package/src/Base/InflyCheckBox/InflyCheckBox.vue +227 -0
  6. package/src/Base/InflyCheckBox/index.js +6 -0
  7. package/src/Base/InflyDialog/InflyDialog.test.js +122 -0
  8. package/src/Base/InflyDialog/InflyDialog.vue +111 -0
  9. package/src/Base/InflyDialog/index.js +6 -0
  10. package/src/Base/InflyForm/InflyForm.test.js +239 -0
  11. package/src/Base/InflyForm/InflyForm.vue +974 -0
  12. package/src/Base/InflyForm/index.js +6 -0
  13. package/src/Base/InflyInput/InflyInput.test.js +105 -0
  14. package/src/Base/InflyInput/InflyInput.vue +167 -0
  15. package/src/Base/InflyInput/index.js +6 -0
  16. package/src/Base/InflyList/InflyList.test.js +229 -0
  17. package/src/Base/InflyList/InflyList.vue +925 -0
  18. package/src/Base/InflyList/index.js +6 -0
  19. package/src/Base/InflySelect/InflySelect.js +0 -0
  20. package/src/Business/BusinessSwitch/BusinessSwitch.test.js +96 -0
  21. package/src/Business/BusinessSwitch/BusinessSwitch.vue +115 -0
  22. package/src/Business/BusinessSwitch/index.js +6 -0
  23. package/src/Business/BusinessTag/BusinessTag.test.js +83 -0
  24. package/src/Business/BusinessTag/BusinessTag.vue +58 -0
  25. package/src/Business/BusinessTag/index.js +6 -0
  26. package/src/Business/InstitutionSelect/InstitutionSelect.test.js +158 -0
  27. package/src/Business/InstitutionSelect/InstitutionSelect.vue +770 -0
  28. package/src/Business/InstitutionSelect/index.js +6 -0
  29. package/src/index.js +30 -0
  30. package/styles/base.scss +755 -0
  31. package/styles/index.scss +202 -0
  32. package/styles/mixin.scss +19 -0
  33. package/styles/variables.scss +24 -0
@@ -0,0 +1,122 @@
1
+ /**
2
+ * InflyDialog 组件测试
3
+ *
4
+ * 验证弹窗的 v-model 双向绑定、事件、自定义文本和显示逻辑。
5
+ */
6
+ const { describe, it, assert, 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,6 @@
1
+ import InflyDialog from "./InflyDialog.vue";
2
+ import { withInstall } from "../../../scripts/install-comp";
3
+
4
+ export { InflyDialog };
5
+
6
+ export default withInstall(InflyDialog);
@@ -0,0 +1,239 @@
1
+ /**
2
+ * InflyForm 组件测试
3
+ *
4
+ * 验证配置化表单的渲染、筛选列表、按钮组、编辑/展示模式等核心行为。
5
+ * 使用 shallowMount 隔离子组件依赖。
6
+ */
7
+ const { describe, it, assert, 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
+ });