@infly/ui 1.0.27 → 1.0.29

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/index.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @infly/ui TypeScript 类型声明
3
+ *
4
+ * Vue 2 运营端组件库类型声明。
5
+ * 所有组件已全局注册,支持 Vue.use() 安装。
6
+ */
7
+
8
+ import Vue from "vue";
9
+
10
+ declare module "@infly/ui" {
11
+ interface InflyComponent {
12
+ name: string;
13
+ install(vue: typeof Vue): void;
14
+ }
15
+
16
+ /** 配置化列表页(表单 + 表格 + 分页一体) */
17
+ export const InflyList: InflyComponent;
18
+
19
+ /** 配置化表单(搜索栏 / 弹窗表单) */
20
+ export const InflyForm: InflyComponent;
21
+
22
+ /** 弹窗容器 */
23
+ export const InflyDialog: InflyComponent;
24
+
25
+ /** 输入框(支持 textarea / autocomplete) */
26
+ export const InflyInput: InflyComponent;
27
+
28
+ /** 复选框组件 */
29
+ export const InflyCheckBox: InflyComponent;
30
+
31
+ /** 业务开关组件 */
32
+ export const BusinessSwitch: InflyComponent;
33
+
34
+ /** 业务标签组件 */
35
+ export const BusinessTag: InflyComponent;
36
+
37
+ /** 机构选择器 */
38
+ export const InstitutionSelect: InflyComponent;
39
+
40
+ const _default: {
41
+ install(vue: typeof Vue): void;
42
+ InflyList: typeof InflyList;
43
+ InflyForm: typeof InflyForm;
44
+ InflyDialog: typeof InflyDialog;
45
+ InflyInput: typeof InflyInput;
46
+ InflyCheckBox: typeof InflyCheckBox;
47
+ BusinessSwitch: typeof BusinessSwitch;
48
+ BusinessTag: typeof BusinessTag;
49
+ InstitutionSelect: typeof InstitutionSelect;
50
+ };
51
+
52
+ export default _default;
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infly/ui",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "Infly 公共 UI 组件库(Vue 2)",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -12,13 +12,14 @@
12
12
  },
13
13
  "files": [
14
14
  "index.js",
15
+ "index.d.ts",
15
16
  "src/",
16
17
  "styles/",
17
18
  "scripts/install-comp.js",
18
19
  "README.md"
19
20
  ],
20
21
  "dependencies": {
21
- "@infly/ts-libs": "^1.0.0"
22
+ "@infly/ts-libs": "^1.0.1"
22
23
  },
23
24
  "peerDependencies": {
24
25
  "element-ui": "^2.15.0",
@@ -39,13 +40,15 @@
39
40
  "author": "Kahal",
40
41
  "license": "ISC",
41
42
  "devDependencies": {
43
+ "@vitejs/plugin-vue2": "2.3.4",
42
44
  "@vue/test-utils": "^1.3.6",
43
45
  "vite": "^7.3.6",
44
46
  "vitest": "^4.1.10",
45
47
  "vue-template-compiler": "2.7.16",
46
48
  "eslint": "^9.0.0",
47
49
  "@eslint/js": "^9.0.0",
48
- "globals": "^15.0.0"
50
+ "globals": "^15.0.0",
51
+ "@vitest/coverage-v8": "4.1.10"
49
52
  },
50
53
  "scripts": {
51
54
  "test": "vitest run",
@@ -1,105 +1,105 @@
1
- /**
2
- * InflyInput 组件测试
3
- *
4
- * 验证输入组件的 v-model、类型映射、前后置内容。
5
- */
6
- const { mount } = require("../../../test/helper");
7
- const InflyInput = require("./InflyInput.vue");
8
-
9
- describe("InflyInput", () => {
10
- describe("渲染", () => {
11
- it("默认渲染 el-input", () => {
12
- const wrapper = mount(InflyInput, {
13
- propsData: { value: "" },
14
- });
15
- assert.ok(wrapper.find(".el-input").exists());
16
- wrapper.destroy();
17
- });
18
-
19
- it("type=el-autocomplete 时渲染 el-autocomplete", () => {
20
- const wrapper = mount(InflyInput, {
21
- propsData: { value: "" },
22
- attrs: { type: "el-autocomplete" },
23
- });
24
- // el-autocomplete 有特定的 class
25
- assert.ok(wrapper.find(".el-autocomplete") || wrapper.exists());
26
- wrapper.destroy();
27
- });
28
-
29
- it("渲染容器 class", () => {
30
- const wrapper = mount(InflyInput, {
31
- propsData: {
32
- value: "",
33
- containerClass: "my-container",
34
- },
35
- });
36
- assert.ok(wrapper.find(".my-container").exists());
37
- wrapper.destroy();
38
- });
39
- });
40
-
41
- describe("v-model / 双向绑定", () => {
42
- it("接受初始 value", () => {
43
- const wrapper = mount(InflyInput, {
44
- propsData: { value: "初始值" },
45
- });
46
- assert.equal(wrapper.vm.$data.inputValue, "初始值");
47
- wrapper.destroy();
48
- });
49
-
50
- it("value 变化时同步内部状态", async () => {
51
- const wrapper = mount(InflyInput, {
52
- propsData: { value: "旧值" },
53
- });
54
- wrapper.setProps({ value: "新值" });
55
- await wrapper.vm.$nextTick();
56
- assert.equal(wrapper.vm.$data.inputValue, "新值");
57
- wrapper.destroy();
58
- });
59
-
60
- it("内部输入触发 input 事件(Vue 2 v-model)", () => {
61
- const wrapper = mount(InflyInput, {
62
- propsData: { value: "" },
63
- });
64
- wrapper.vm.$data.inputValue = "用户输入";
65
- wrapper.vm.$emit("input", "用户输入");
66
- assert.ok(wrapper.emitted().input);
67
- wrapper.destroy();
68
- });
69
- });
70
-
71
- describe("Props", () => {
72
- it("支持 prepend 前置内容", () => {
73
- const wrapper = mount(InflyInput, {
74
- propsData: {
75
- value: "",
76
- prepend: "https://",
77
- },
78
- });
79
- assert.ok(wrapper.exists());
80
- wrapper.destroy();
81
- });
82
-
83
- it("支持 append 后置内容", () => {
84
- const wrapper = mount(InflyInput, {
85
- propsData: {
86
- value: "",
87
- append: ".com",
88
- },
89
- });
90
- assert.ok(wrapper.exists());
91
- wrapper.destroy();
92
- });
93
-
94
- it("支持 wrapClass", () => {
95
- const wrapper = mount(InflyInput, {
96
- propsData: {
97
- value: "",
98
- wrapClass: "custom-wrap",
99
- },
100
- });
101
- assert.ok(wrapper.find(".custom-wrap").exists());
102
- wrapper.destroy();
103
- });
104
- });
105
- });
1
+ /**
2
+ * InflyInput 组件测试
3
+ *
4
+ * 验证输入组件的 v-model、类型映射、前后置内容。
5
+ */
6
+ const { mount } = require("../../../test/helper");
7
+ const InflyInput = require("./InflyInput.vue");
8
+
9
+ describe("InflyInput", () => {
10
+ describe("渲染", () => {
11
+ it("默认渲染 el-input", () => {
12
+ const wrapper = mount(InflyInput, {
13
+ propsData: { value: "" },
14
+ });
15
+ assert.ok(wrapper.find(".el-input").exists());
16
+ wrapper.destroy();
17
+ });
18
+
19
+ it("type=el-autocomplete 时渲染 el-autocomplete", () => {
20
+ const wrapper = mount(InflyInput, {
21
+ propsData: { value: "" },
22
+ attrs: { type: "el-autocomplete" },
23
+ });
24
+ // el-autocomplete 有特定的 class
25
+ assert.ok(wrapper.find(".el-autocomplete") || wrapper.exists());
26
+ wrapper.destroy();
27
+ });
28
+
29
+ it("渲染容器 class", () => {
30
+ const wrapper = mount(InflyInput, {
31
+ propsData: {
32
+ value: "",
33
+ containerClass: "my-container",
34
+ },
35
+ });
36
+ assert.ok(wrapper.find(".my-container").exists());
37
+ wrapper.destroy();
38
+ });
39
+ });
40
+
41
+ describe("v-model / 双向绑定", () => {
42
+ it("接受初始 value", () => {
43
+ const wrapper = mount(InflyInput, {
44
+ propsData: { value: "初始值" },
45
+ });
46
+ assert.equal(wrapper.vm.$data.inputValue, "初始值");
47
+ wrapper.destroy();
48
+ });
49
+
50
+ it("value 变化时同步内部状态", async () => {
51
+ const wrapper = mount(InflyInput, {
52
+ propsData: { value: "旧值" },
53
+ });
54
+ wrapper.setProps({ value: "新值" });
55
+ await wrapper.vm.$nextTick();
56
+ assert.equal(wrapper.vm.$data.inputValue, "新值");
57
+ wrapper.destroy();
58
+ });
59
+
60
+ it("内部输入触发 input 事件(Vue 2 v-model)", () => {
61
+ const wrapper = mount(InflyInput, {
62
+ propsData: { value: "" },
63
+ });
64
+ wrapper.vm.$data.inputValue = "用户输入";
65
+ wrapper.vm.$emit("input", "用户输入");
66
+ assert.ok(wrapper.emitted().input);
67
+ wrapper.destroy();
68
+ });
69
+ });
70
+
71
+ describe("Props", () => {
72
+ it("支持 prepend 前置内容", () => {
73
+ const wrapper = mount(InflyInput, {
74
+ propsData: {
75
+ value: "",
76
+ prepend: "https://",
77
+ },
78
+ });
79
+ assert.ok(wrapper.exists());
80
+ wrapper.destroy();
81
+ });
82
+
83
+ it("支持 append 后置内容", () => {
84
+ const wrapper = mount(InflyInput, {
85
+ propsData: {
86
+ value: "",
87
+ append: ".com",
88
+ },
89
+ });
90
+ assert.ok(wrapper.exists());
91
+ wrapper.destroy();
92
+ });
93
+
94
+ it("支持 wrapClass", () => {
95
+ const wrapper = mount(InflyInput, {
96
+ propsData: {
97
+ value: "",
98
+ wrapClass: "custom-wrap",
99
+ },
100
+ });
101
+ assert.ok(wrapper.find(".custom-wrap").exists());
102
+ wrapper.destroy();
103
+ });
104
+ });
105
+ });
@@ -1,167 +1,167 @@
1
- <template>
2
- <div class="comp-InflyInput" :class="containerClass">
3
- <component
4
- v-model="inputValue"
5
- :is="typeMap"
6
- :class="['infly-input__wrap', wrapClass]"
7
- :size="$attrs.size || 'mini'"
8
- :placeholder="$attrs.placeholder || `请输入${$attrs.label}`"
9
- v-bind="$attrs"
10
- @select="handleSelect"
11
- >
12
- <template v-if="prepend" slot="prepend">
13
- <el-select
14
- v-if="prepend.options"
15
- v-model="prependSelectValue"
16
- v-bind="prepend"
17
- @change="prepend.change || (() => {})"
18
- >
19
- <el-option
20
- v-for="option in prepend.options"
21
- :key="option.value"
22
- :label="option.label"
23
- :value="option.value"
24
- ></el-option>
25
- </el-select>
26
- <div v-else>{{ prepend }}</div>
27
- </template>
28
- <append-renderer v-if="append && append.inside" slot="append" :append="append" />
29
- </component>
30
- <append-renderer v-if="append && !append.inside" :append="append" />
31
- </div>
32
- </template>
33
-
34
- <script>
35
- import Uts from "../../utils/Uts.js";
36
-
37
- export default {
38
- name: "InflyInput",
39
- inheritAttrs: false,
40
- components: {
41
- RenderFunction: {
42
- functional: true,
43
- props: {
44
- renderFn: {
45
- type: Function,
46
- required: true
47
- }
48
- },
49
- render(h, ctx) {
50
- return ctx.props.renderFn();
51
- }
52
- },
53
- AppendRenderer: {
54
- functional: true,
55
- props: {
56
- append: {
57
- type: [String, Object, Function],
58
- required: true
59
- }
60
- },
61
- render(h, ctx) {
62
- const { append } = ctx.props;
63
-
64
- if (Uts.isFunction(append)) {
65
- return append();
66
- }
67
- if (Uts.isFunction(append?.render)) {
68
- return append.render();
69
- }
70
- return h('span', append);
71
- }
72
- }
73
- },
74
- props: {
75
- // 必需 Props
76
- value: {
77
- type: [String, Number],
78
- default: ""
79
- },
80
- // Vue3 默认 v-model -> modelValue
81
- modelValue: {
82
- type: [String, Number],
83
- default: ""
84
- },
85
- wrapClass: {
86
- type: String,
87
- default: ""
88
- },
89
- containerClass: {
90
- type: String,
91
- default: ""
92
- },
93
- prepend: {
94
- type: [String, Object],
95
- default: ""
96
- },
97
- append: {
98
- type: [String, Object, Function],
99
- default: ""
100
- }
101
- },
102
- computed: {
103
- typeMap() {
104
- let compType = "el-input";
105
- if (this.$attrs.type === "el-autocomplete") {
106
- compType = "el-autocomplete";
107
- }
108
- if (this.$attrs.type === "infly-input-number") {
109
- compType = "el-input-number";
110
- }
111
- return compType;
112
- }
113
- },
114
- watch: {
115
- // 外部 value 改变时,同步到内部 inputValue
116
- value(newVal) {
117
- this.inputValue = newVal || "";
118
- },
119
- modelValue(newVal) {
120
- this.inputValue = newVal || "";
121
- },
122
- // 内部输入改变时,往外 emit input 事件
123
- inputValue(newVal) {
124
- this.$emit("input", newVal); // Vue2 用法
125
- this.$emit("update:modelValue", newVal); // Vue3 用法
126
- }
127
- },
128
- data() {
129
- return {
130
- inputValue: this.value || this.modelValue || "",
131
- prependSelectValue: (this.prepend && this.prepend.defaultValue) || ""
132
- };
133
- },
134
- methods: {
135
- handleSelect(item) {
136
- const { value } = item || {};
137
- this.inputValue = value;
138
- },
139
- handleNativeInput(e) {
140
- // 如果配置了 numberOnly 属性,则限制只能输入数字和小数点
141
- if (this.$attrs.numberOnly !== undefined) {
142
- const input = e.target;
143
- const oldValue = input.value;
144
- // 只保留数字和小数点
145
- let newValue = oldValue.replace(/[^\d.]/g, '');
146
- // 确保只有一个小数点
147
- const parts = newValue.split('.');
148
- if (parts.length > 2) {
149
- newValue = parts[0] + '.' + parts.slice(1).join('');
150
- }
151
- // 如果值被修改了,更新输入框
152
- if (oldValue !== newValue) {
153
- input.value = newValue;
154
- this.inputValue = newValue;
155
- }
156
- }
157
- }
158
- }
159
- };
160
- </script>
161
-
162
- <style lang="scss" scoped>
163
- .comp-InflyInput {
164
- display: flex;
165
- align-items: center;
166
- }
167
- </style>
1
+ <template>
2
+ <div class="comp-InflyInput" :class="containerClass">
3
+ <component
4
+ v-model="inputValue"
5
+ :is="typeMap"
6
+ :class="['infly-input__wrap', wrapClass]"
7
+ :size="$attrs.size || 'mini'"
8
+ :placeholder="$attrs.placeholder || `请输入${$attrs.label}`"
9
+ v-bind="$attrs"
10
+ @select="handleSelect"
11
+ >
12
+ <template v-if="prepend" slot="prepend">
13
+ <el-select
14
+ v-if="prepend.options"
15
+ v-model="prependSelectValue"
16
+ v-bind="prepend"
17
+ @change="prepend.change || (() => {})"
18
+ >
19
+ <el-option
20
+ v-for="option in prepend.options"
21
+ :key="option.value"
22
+ :label="option.label"
23
+ :value="option.value"
24
+ ></el-option>
25
+ </el-select>
26
+ <div v-else>{{ prepend }}</div>
27
+ </template>
28
+ <append-renderer v-if="append && append.inside" slot="append" :append="append" />
29
+ </component>
30
+ <append-renderer v-if="append && !append.inside" :append="append" />
31
+ </div>
32
+ </template>
33
+
34
+ <script>
35
+ import Uts from "../../utils/Uts.js";
36
+
37
+ export default {
38
+ name: "InflyInput",
39
+ inheritAttrs: false,
40
+ components: {
41
+ RenderFunction: {
42
+ functional: true,
43
+ props: {
44
+ renderFn: {
45
+ type: Function,
46
+ required: true
47
+ }
48
+ },
49
+ render(h, ctx) {
50
+ return ctx.props.renderFn();
51
+ }
52
+ },
53
+ AppendRenderer: {
54
+ functional: true,
55
+ props: {
56
+ append: {
57
+ type: [String, Object, Function],
58
+ required: true
59
+ }
60
+ },
61
+ render(h, ctx) {
62
+ const { append } = ctx.props;
63
+
64
+ if (Uts.isFunction(append)) {
65
+ return append();
66
+ }
67
+ if (Uts.isFunction(append?.render)) {
68
+ return append.render();
69
+ }
70
+ return h('span', append);
71
+ }
72
+ }
73
+ },
74
+ props: {
75
+ // 必需 Props
76
+ value: {
77
+ type: [String, Number],
78
+ default: ""
79
+ },
80
+ // Vue3 默认 v-model -> modelValue
81
+ modelValue: {
82
+ type: [String, Number],
83
+ default: ""
84
+ },
85
+ wrapClass: {
86
+ type: String,
87
+ default: ""
88
+ },
89
+ containerClass: {
90
+ type: String,
91
+ default: ""
92
+ },
93
+ prepend: {
94
+ type: [String, Object],
95
+ default: ""
96
+ },
97
+ append: {
98
+ type: [String, Object, Function],
99
+ default: ""
100
+ }
101
+ },
102
+ computed: {
103
+ typeMap() {
104
+ let compType = "el-input";
105
+ if (this.$attrs.type === "el-autocomplete") {
106
+ compType = "el-autocomplete";
107
+ }
108
+ if (this.$attrs.type === "infly-input-number") {
109
+ compType = "el-input-number";
110
+ }
111
+ return compType;
112
+ }
113
+ },
114
+ watch: {
115
+ // 外部 value 改变时,同步到内部 inputValue
116
+ value(newVal) {
117
+ this.inputValue = newVal || "";
118
+ },
119
+ modelValue(newVal) {
120
+ this.inputValue = newVal || "";
121
+ },
122
+ // 内部输入改变时,往外 emit input 事件
123
+ inputValue(newVal) {
124
+ this.$emit("input", newVal); // Vue2 用法
125
+ this.$emit("update:modelValue", newVal); // Vue3 用法
126
+ }
127
+ },
128
+ data() {
129
+ return {
130
+ inputValue: this.value || this.modelValue || "",
131
+ prependSelectValue: (this.prepend && this.prepend.defaultValue) || ""
132
+ };
133
+ },
134
+ methods: {
135
+ handleSelect(item) {
136
+ const { value } = item || {};
137
+ this.inputValue = value;
138
+ },
139
+ handleNativeInput(e) {
140
+ // 如果配置了 numberOnly 属性,则限制只能输入数字和小数点
141
+ if (this.$attrs.numberOnly !== undefined) {
142
+ const input = e.target;
143
+ const oldValue = input.value;
144
+ // 只保留数字和小数点
145
+ let newValue = oldValue.replace(/[^\d.]/g, '');
146
+ // 确保只有一个小数点
147
+ const parts = newValue.split('.');
148
+ if (parts.length > 2) {
149
+ newValue = parts[0] + '.' + parts.slice(1).join('');
150
+ }
151
+ // 如果值被修改了,更新输入框
152
+ if (oldValue !== newValue) {
153
+ input.value = newValue;
154
+ this.inputValue = newValue;
155
+ }
156
+ }
157
+ }
158
+ }
159
+ };
160
+ </script>
161
+
162
+ <style lang="scss" scoped>
163
+ .comp-InflyInput {
164
+ display: flex;
165
+ align-items: center;
166
+ }
167
+ </style>