@elementplus-kit/uikit 1.6.0 → 1.7.0
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/build.log +0 -0
- package/components/button/index.ts +4 -0
- package/components/button/src/constants.ts +50 -0
- package/components/button/src/index.ts +264 -0
- package/components/button/style/index.scss +3 -0
- package/components/config.ts +4 -0
- package/components/dialog/index.ts +6 -0
- package/components/dialog/src/constants.ts +3 -0
- package/components/dialog/src/index.ts +54 -0
- package/components/dialog/style/index.scss +18 -0
- package/components/dictLabel/index.ts +4 -0
- package/components/dictLabel/src/index.vue +21 -0
- package/components/drawer/index.ts +4 -0
- package/components/drawer/src/constants.ts +3 -0
- package/components/drawer/src/index.ts +53 -0
- package/components/drawer/style/index.scss +18 -0
- package/components/form/index.ts +4 -0
- package/components/form/src/FormItem.ts +398 -0
- package/components/form/src/constants.ts +161 -0
- package/components/form/src/index.ts +198 -0
- package/components/form/src/types.ts +39 -0
- package/components/form/src/utils.ts +4 -0
- package/components/form/style/index.scss +5 -0
- package/components/pagination/index.ts +4 -0
- package/components/pagination/src/constants.ts +5 -0
- package/components/pagination/src/index.ts +50 -0
- package/components/search/index.ts +4 -0
- package/components/search/src/index.tsx +294 -0
- package/components/search/style/index.scss +104 -0
- package/components/table/index.ts +4 -0
- package/components/table/src/TableColumn.ts +116 -0
- package/components/table/src/constants.ts +42 -0
- package/components/table/src/index.ts +250 -0
- package/components/table/src/index2.ts +219 -0
- package/components/table/src/index3.ts +233 -0
- package/components/table/src/tableDictLabel.vue +21 -0
- package/components/table/src/tableaa.ts +71 -0
- package/components/table/src/type.ts +0 -0
- package/components/table/type/index.scss +0 -0
- package/components/table2/index.ts +4 -0
- package/components/table2/src/config.ts +5 -0
- package/components/table2/src/index.ts +12 -0
- package/components/table2/src/render.ts +136 -0
- package/components/table2/src/types.ts +39 -0
- package/components/table2/style/index.scss +0 -0
- package/components//346/250/241/346/235/277/index.tsx +57 -0
- package/components//346/250/241/346/235/277/ttt.ts +66 -0
- package/components//346/250/241/346/235/277/ttt.vue +18 -0
- package/index.ts +2 -0
- package/package.json +1 -4
- package/vite.config.ts +30 -0
- package//345/205/266/344/273/226/core/dialog/elementPlus/dialogWarp.vue +151 -0
- package//345/205/266/344/273/226/core/dialog/index.ts +10 -0
- package//345/205/266/344/273/226/core/form/elementPlus/elementWarp.ts +15 -0
- package//345/205/266/344/273/226/core/form/elementPlus/elementWarp.vue +16 -0
- package//345/205/266/344/273/226/core/form/elementPlus/formRender.ts +55 -0
- package//345/205/266/344/273/226/core/form/index.ts +10 -0
- package//345/205/266/344/273/226/core/table/config.ts +5 -0
- package//345/205/266/344/273/226/core/table/render.ts +91 -0
- package//345/205/266/344/273/226/core/table/warp.ts +11 -0
- package//345/205/266/344/273/226/core/utils/fetch.ts +58 -0
- package//345/205/266/344/273/226/useMessage.ts +95 -0
- package/dist/index.css +0 -1
- package/dist/index.mjs +0 -1079
- package/dist/index.umd.js +0 -1
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
ref,
|
|
4
|
+
h,
|
|
5
|
+
computed,
|
|
6
|
+
toRefs,
|
|
7
|
+
getCurrentInstance,
|
|
8
|
+
provide,
|
|
9
|
+
type ExtractPropTypes,
|
|
10
|
+
type PropType,
|
|
11
|
+
} from "vue";
|
|
12
|
+
import { ElForm, ElRow, ElCol } from "element-plus";
|
|
13
|
+
// import zhCn from "element-plus/es/locale/lang/zh-cn";
|
|
14
|
+
import CFormItem from "./FormItem.ts";
|
|
15
|
+
import { has, isFunction } from "lodash-es";
|
|
16
|
+
import { getEmits } from "./constants"; // 获取所有的事件
|
|
17
|
+
import "../style/index.scss";
|
|
18
|
+
const propsAttrs = {
|
|
19
|
+
// 表单数据
|
|
20
|
+
model: { type: Object, default: () => ({}) },
|
|
21
|
+
// 表单项
|
|
22
|
+
formOptions: { type: Array, default: () => [] },
|
|
23
|
+
// 只读
|
|
24
|
+
readonly: { type: Boolean, default: false },
|
|
25
|
+
// row 间距
|
|
26
|
+
gutter: {
|
|
27
|
+
// tode 类型错误警告
|
|
28
|
+
type: (Number as PropType<number>) || (String as PropType<string>),
|
|
29
|
+
default: undefined,
|
|
30
|
+
},
|
|
31
|
+
// row 列数
|
|
32
|
+
col: { type: Number, default: undefined },
|
|
33
|
+
// 额外业务全局参数
|
|
34
|
+
params: { type: Object, default: () => ({}) },
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type PropsAttrs = ExtractPropTypes<typeof propsAttrs>;
|
|
38
|
+
|
|
39
|
+
export default defineComponent({
|
|
40
|
+
props: propsAttrs,
|
|
41
|
+
emits: [...getEmits()],
|
|
42
|
+
setup(props: PropsAttrs, { attrs: $attrs, emit, slots, expose }) {
|
|
43
|
+
provide("formContext", {
|
|
44
|
+
formSlots: slots,
|
|
45
|
+
events: (eProp, ...args: any) => {
|
|
46
|
+
// 按钮 reset 事件
|
|
47
|
+
// if (e == 'reset') {
|
|
48
|
+
// formRef.value?.resetFields()
|
|
49
|
+
// }
|
|
50
|
+
emit(eProp, ...args);
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// 各个表单组件的 ref
|
|
55
|
+
const optionsRef = ref<any>({});
|
|
56
|
+
|
|
57
|
+
// 暴露方法
|
|
58
|
+
expose({
|
|
59
|
+
optionsRef,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// 解构props
|
|
63
|
+
const { model, formOptions, readonly, gutter, col } = toRefs(props);
|
|
64
|
+
|
|
65
|
+
// 暴露elForm组件上的方法
|
|
66
|
+
const vm = getCurrentInstance(); // 获取虚拟DOM实例
|
|
67
|
+
const cFormFnRef = (el) => {
|
|
68
|
+
if (!el) return;
|
|
69
|
+
vm.exposed = el; // 设置暴露对象
|
|
70
|
+
vm.exposeProxy = el; // 设置代理暴露对象
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// 全部只读
|
|
74
|
+
const allReadonly = computed(() => readonly.value);
|
|
75
|
+
|
|
76
|
+
// 是否 row 布局 || ['', 0].includes(gutter.value)
|
|
77
|
+
const isLayout = computed(
|
|
78
|
+
() =>
|
|
79
|
+
["", 0].includes(gutter?.value) ||
|
|
80
|
+
col?.value ||
|
|
81
|
+
formOptions?.value.some((item) => has(item, "col"))
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// 渲染 row
|
|
85
|
+
const renderRow = () => {
|
|
86
|
+
const formItemVdom = renderFormItem();
|
|
87
|
+
if (isLayout.value) {
|
|
88
|
+
return h(
|
|
89
|
+
ElRow,
|
|
90
|
+
{
|
|
91
|
+
class: "c-row",
|
|
92
|
+
// gutter: gutter.value === 0 || gutter.value ? gutter.value : 10,
|
|
93
|
+
gutter: gutter.value || 20,
|
|
94
|
+
...$attrs,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
default: () => formItemVdom,
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
} else {
|
|
101
|
+
return formItemVdom;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
// 合并 formData 和 params
|
|
105
|
+
const mergeParams = computed(() => {
|
|
106
|
+
return { formData: model.value, params: props.params };
|
|
107
|
+
});
|
|
108
|
+
// 渲染表单项
|
|
109
|
+
const renderFormItem = () => {
|
|
110
|
+
// 过滤权限
|
|
111
|
+
const list = [];
|
|
112
|
+
|
|
113
|
+
formOptions.value.map((item) => {
|
|
114
|
+
// 处理 vIf true 显示 false 隐藏
|
|
115
|
+
if (
|
|
116
|
+
isFunction(item?.vIf) &&
|
|
117
|
+
item.vIf(mergeParams.value) !== undefined
|
|
118
|
+
) {
|
|
119
|
+
if (item.vIf(mergeParams.value)) {
|
|
120
|
+
list.push(item);
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
list.push(item);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return list.map((item) => {
|
|
127
|
+
// const { label, prop, type, required, col, formItem, attrs } = item
|
|
128
|
+
// const { label, prop, type, required, col, formItem, attrs, ...args } = item
|
|
129
|
+
const rFormItem = () => {
|
|
130
|
+
return h(CFormItem, {
|
|
131
|
+
class: "c-form-itme",
|
|
132
|
+
model: model.value,
|
|
133
|
+
allReadonly,
|
|
134
|
+
mergeParams: mergeParams.value,
|
|
135
|
+
...item,
|
|
136
|
+
optionsRef: optionsRef.value,
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
if (isLayout.value) {
|
|
140
|
+
// 是否有 col 插槽
|
|
141
|
+
let colSlot = undefined;
|
|
142
|
+
let colSlotName = `col.${item.prop}`;
|
|
143
|
+
// 手动开启 col 插槽
|
|
144
|
+
if (item?.colSlot) {
|
|
145
|
+
if (has(slots, colSlotName)) {
|
|
146
|
+
colSlot = slots[colSlotName];
|
|
147
|
+
} else {
|
|
148
|
+
colSlot = () => "col插槽模板未定义";
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
// 自动开启 col 插槽
|
|
152
|
+
if (has(slots, colSlotName)) {
|
|
153
|
+
colSlot = slots[colSlotName];
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return h(
|
|
158
|
+
ElCol,
|
|
159
|
+
{
|
|
160
|
+
class: "c-col",
|
|
161
|
+
span: has(item, "col")
|
|
162
|
+
? item.col
|
|
163
|
+
: col?.value
|
|
164
|
+
? col?.value
|
|
165
|
+
: isLayout.value
|
|
166
|
+
? 8
|
|
167
|
+
: undefined,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
default: () => (colSlot ? colSlot() : rFormItem()),
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
} else {
|
|
174
|
+
return rFormItem();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// 渲染表单
|
|
180
|
+
const renderForm = () => {
|
|
181
|
+
return h(
|
|
182
|
+
ElForm,
|
|
183
|
+
{
|
|
184
|
+
ref: cFormFnRef,
|
|
185
|
+
...$attrs,
|
|
186
|
+
model: model.value,
|
|
187
|
+
class: allReadonly.value ? "isReadonly c-form" : "c-form", // 放在 $attrs 后面可自动合并 放在 $attrs 前面会被 $attrs.class 覆盖, h函数渲染的是标签就会覆盖 是组件就会合并不用管顺序
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
default: () => renderRow(),
|
|
191
|
+
}
|
|
192
|
+
);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// 返回渲染函数
|
|
196
|
+
return () => renderForm();
|
|
197
|
+
},
|
|
198
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface FormItemListItem {
|
|
2
|
+
type: string
|
|
3
|
+
label?: string
|
|
4
|
+
prop: string
|
|
5
|
+
required?: Boolean
|
|
6
|
+
vIf?: boolean | ((item: FormItemListItem) => boolean)
|
|
7
|
+
dictType?: string
|
|
8
|
+
options?: Array<Object>
|
|
9
|
+
col?: Number
|
|
10
|
+
formItem?: Object
|
|
11
|
+
attrs?: Object
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FormItemList {
|
|
15
|
+
module: Object
|
|
16
|
+
formOpsions: FormItemListItem[]
|
|
17
|
+
readonly: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type formType =
|
|
21
|
+
| 'input'
|
|
22
|
+
| 'textarea'
|
|
23
|
+
| 'input-number'
|
|
24
|
+
| 'select'
|
|
25
|
+
| 'select-v2'
|
|
26
|
+
| 'cascader'
|
|
27
|
+
| 'tree-select'
|
|
28
|
+
| 'radio'
|
|
29
|
+
| 'checkbox'
|
|
30
|
+
| 'time-select'
|
|
31
|
+
| 'date-picker'
|
|
32
|
+
| 'time-picker'
|
|
33
|
+
| 'rate'
|
|
34
|
+
| 'color-picker'
|
|
35
|
+
| 'slider'
|
|
36
|
+
| 'switch'
|
|
37
|
+
| 'text'
|
|
38
|
+
| 'html'
|
|
39
|
+
| 'slot'
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
ref,
|
|
4
|
+
h,
|
|
5
|
+
computed,
|
|
6
|
+
toRefs,
|
|
7
|
+
type ExtractPropTypes,
|
|
8
|
+
} from "vue";
|
|
9
|
+
import { ElPagination } from "element-plus";
|
|
10
|
+
import { get, has, isArray, isBoolean, isFunction, isNumber } from "lodash-es";
|
|
11
|
+
import { defaultAttrs } from "./constants.ts";
|
|
12
|
+
|
|
13
|
+
const propsAttrs = {};
|
|
14
|
+
|
|
15
|
+
export type PropsAttrs = ExtractPropTypes<typeof propsAttrs>;
|
|
16
|
+
|
|
17
|
+
export default defineComponent({
|
|
18
|
+
// props: propsAttrs,
|
|
19
|
+
// emits: eventList,
|
|
20
|
+
|
|
21
|
+
// attrs, emit会继承, slots需要设置
|
|
22
|
+
setup(props: PropsAttrs, { attrs, emit, slots, expose }) {
|
|
23
|
+
// const pageRef = ref();
|
|
24
|
+
|
|
25
|
+
// 暴露方法
|
|
26
|
+
// expose({
|
|
27
|
+
// pageRef,
|
|
28
|
+
// });
|
|
29
|
+
|
|
30
|
+
// 属性处理
|
|
31
|
+
const getAttrs = () => {
|
|
32
|
+
const obj = {
|
|
33
|
+
...defaultAttrs, // 设置默认值
|
|
34
|
+
// ...attrs, // 当前传入覆盖默认值 第一层标签就是组件可以不用传入
|
|
35
|
+
};
|
|
36
|
+
return obj;
|
|
37
|
+
};
|
|
38
|
+
// 渲染表单
|
|
39
|
+
const render = () => {
|
|
40
|
+
return h(ElPagination, {
|
|
41
|
+
// ref: pageRef,
|
|
42
|
+
...getAttrs(),
|
|
43
|
+
class: "c-pagination",
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// 返回渲染函数
|
|
48
|
+
return () => render();
|
|
49
|
+
},
|
|
50
|
+
});
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { ref, defineComponent, onMounted, onUnmounted, nextTick, watch } from "vue";
|
|
2
|
+
|
|
3
|
+
import { CForm, CDrawer } from "@elementplus-kit/uikit";
|
|
4
|
+
import { ArrowUpBold } from "@element-plus/icons-vue";
|
|
5
|
+
import "../style/index.scss";
|
|
6
|
+
|
|
7
|
+
export default defineComponent({
|
|
8
|
+
props: {
|
|
9
|
+
modelValue: {
|
|
10
|
+
type: Object,
|
|
11
|
+
default: {},
|
|
12
|
+
},
|
|
13
|
+
formOptions: {
|
|
14
|
+
type: Array,
|
|
15
|
+
default: () => [],
|
|
16
|
+
},
|
|
17
|
+
isDrawer: {
|
|
18
|
+
type: Boolean,
|
|
19
|
+
default: false,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
emits: ["update:modelValue", "search", "reset", "close"],
|
|
23
|
+
|
|
24
|
+
setup(props, { emit, slots, attrs, expose }) {
|
|
25
|
+
// 自己的 slot
|
|
26
|
+
const slotsList = ["btn-left", "btn-right"];
|
|
27
|
+
// 解析 attrs 中的事件
|
|
28
|
+
const getEvent = () => {
|
|
29
|
+
let formObj: any = {};
|
|
30
|
+
Object.keys(attrs)?.forEach((name) => {
|
|
31
|
+
if (name.indexOf("on") === 0) {
|
|
32
|
+
formObj[name] = attrs[name];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return formObj;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// 解析插槽
|
|
39
|
+
const getSlot = () => {
|
|
40
|
+
let formObj = {};
|
|
41
|
+
Object.keys(slots).forEach((key) => {
|
|
42
|
+
if (!slotsList.includes(key)) {
|
|
43
|
+
formObj[key] = slots[key];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return formObj;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// 搜索
|
|
50
|
+
const handleSearch = () => {
|
|
51
|
+
emit("search");
|
|
52
|
+
showSearchForm.value = false;
|
|
53
|
+
document.removeEventListener("click", handleClickOutside); // 销毁点击事件
|
|
54
|
+
};
|
|
55
|
+
// 重置
|
|
56
|
+
const handleReset = () => {
|
|
57
|
+
emit("reset");
|
|
58
|
+
};
|
|
59
|
+
// 关闭
|
|
60
|
+
const handleClose = () => {
|
|
61
|
+
showSearchForm.value = false;
|
|
62
|
+
document.removeEventListener("click", handleClickOutside); // 销毁点击事件
|
|
63
|
+
emit("close");
|
|
64
|
+
};
|
|
65
|
+
// 点击元素外关闭
|
|
66
|
+
const dropdownRef = ref<HTMLElement | null>(null); // 下拉表单的 ref
|
|
67
|
+
|
|
68
|
+
// 点击外部关闭函数
|
|
69
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
70
|
+
// 如果下拉表单可见,且点击事件不在下拉表单内部
|
|
71
|
+
if (
|
|
72
|
+
showSearchForm.value &&
|
|
73
|
+
dropdownRef.value &&
|
|
74
|
+
!dropdownRef.value?.$el?.contains(event.target)
|
|
75
|
+
) {
|
|
76
|
+
showSearchForm.value = false; // 关闭下拉表单
|
|
77
|
+
document.removeEventListener("click", handleClickOutside); // 销毁点击事件
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
// 显示隐藏折叠搜索表单
|
|
81
|
+
const showSearchForm = ref(false);
|
|
82
|
+
const handleShow = () => {
|
|
83
|
+
if (showSearchForm.value) {
|
|
84
|
+
showSearchForm.value = false;
|
|
85
|
+
document.removeEventListener("click", handleClickOutside); // 销毁点击事件
|
|
86
|
+
} else {
|
|
87
|
+
showSearchForm.value = true;
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
document.addEventListener("click", handleClickOutside); // 注册点击事件
|
|
90
|
+
}, 0);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const showCount = ref(6); // 显示个数
|
|
95
|
+
const simpleRef = ref<HTMLDivElement>(null);
|
|
96
|
+
const simpleFormRef = ref<HTMLDivElement>(null);
|
|
97
|
+
const simpleFormContainerRef = ref<HTMLDivElement>(null);
|
|
98
|
+
const simpleBtnRef = ref<HTMLDivElement>(null);
|
|
99
|
+
const cFormRef = ref<HTMLDivElement>(null);
|
|
100
|
+
|
|
101
|
+
// 设置节流
|
|
102
|
+
let timer: any = null;
|
|
103
|
+
const searchResize = () => {
|
|
104
|
+
if (timer) {
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
}
|
|
107
|
+
timer = setTimeout(() => {
|
|
108
|
+
calcSunResize();
|
|
109
|
+
}, 200);
|
|
110
|
+
};
|
|
111
|
+
// 计算显示个数
|
|
112
|
+
const calcSunResize = () => {
|
|
113
|
+
if (simpleFormContainerRef.value) {
|
|
114
|
+
// 寻找cForm 先写死 后期做成动态寻找
|
|
115
|
+
const cFormDom = simpleFormContainerRef.value.children[0];
|
|
116
|
+
const cFormW = simpleFormRef.value.offsetWidth;
|
|
117
|
+
// 收集子元素宽度并保存到数组中
|
|
118
|
+
|
|
119
|
+
let maxW = 0;
|
|
120
|
+
showCount.value = cFormDom?.children?.length;
|
|
121
|
+
Array.from(cFormDom.children).map((child, index) => {
|
|
122
|
+
child.style.display = "inline-flex"; // 行内布局时的默认值 如果表单换了默认值要动态变化 暂时不考虑
|
|
123
|
+
if (maxW > cFormW) {
|
|
124
|
+
child.style.display = "none";
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const computedStyles = window.getComputedStyle(child); // 获取元素 css 样式
|
|
129
|
+
const mg = computedStyles.marginRight; // 获取元素 margin-right 样式值 有单位
|
|
130
|
+
const mgValue = parseFloat(mg); // 转换为数值
|
|
131
|
+
const w = child.offsetWidth + mgValue;
|
|
132
|
+
maxW = maxW + w;
|
|
133
|
+
if (maxW > cFormW) {
|
|
134
|
+
child.style.display = "none";
|
|
135
|
+
showCount.value = index;
|
|
136
|
+
maxW = 100000;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
// 监听表单宽度变化
|
|
142
|
+
const formWidth = ref(0);
|
|
143
|
+
const jt = () => {
|
|
144
|
+
// 获取需要监听的元素
|
|
145
|
+
const targetElement = simpleFormRef.value.children[0];
|
|
146
|
+
// 创建 ResizeObserver 实例
|
|
147
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
148
|
+
const clearW = 25; // input clear 按钮 22 按 25 算
|
|
149
|
+
for (const entry of entries) {
|
|
150
|
+
// 获取元素最新的宽度(contentBox 是内容区尺寸,也可改用 borderBox/devicePixelContentBox)
|
|
151
|
+
const newWidth = entry.contentRect.width;
|
|
152
|
+
// 变化了才执行
|
|
153
|
+
if (newWidth !== formWidth.value) {
|
|
154
|
+
if (formWidth.value === 0) {
|
|
155
|
+
// 初始化赋值
|
|
156
|
+
formWidth.value = newWidth;
|
|
157
|
+
searchResize();
|
|
158
|
+
} else if (newWidth < formWidth.value - clearW) {
|
|
159
|
+
// 过滤抖动
|
|
160
|
+
formWidth.value = newWidth;
|
|
161
|
+
searchResize();
|
|
162
|
+
} else if (newWidth > formWidth.value + clearW) {
|
|
163
|
+
// 过滤抖动
|
|
164
|
+
searchResize();
|
|
165
|
+
formWidth.value = newWidth;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// 开始监听目标元素
|
|
172
|
+
resizeObserver.observe(targetElement);
|
|
173
|
+
};
|
|
174
|
+
onMounted(() => {
|
|
175
|
+
// jt函数会触发一次初始化
|
|
176
|
+
jt();
|
|
177
|
+
// 注册页面大小函数
|
|
178
|
+
window.addEventListener("resize", searchResize);
|
|
179
|
+
});
|
|
180
|
+
// 销毁
|
|
181
|
+
onUnmounted(() => {
|
|
182
|
+
window.removeEventListener("resize", searchResize);
|
|
183
|
+
document.removeEventListener("click", handleClickOutside); // 销毁点击事件
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return () => {
|
|
187
|
+
return (
|
|
188
|
+
<div className="c-search">
|
|
189
|
+
<div className="c-search-simple" ref={simpleRef}>
|
|
190
|
+
<div className="c-search-simple-form" ref={simpleFormRef}>
|
|
191
|
+
<div
|
|
192
|
+
className="c-simple-form-container"
|
|
193
|
+
ref={simpleFormContainerRef}
|
|
194
|
+
>
|
|
195
|
+
<CForm
|
|
196
|
+
ref={(el) => (cFormRef.value = el)}
|
|
197
|
+
{...getEvent()}
|
|
198
|
+
inline
|
|
199
|
+
model={props.modelValue}
|
|
200
|
+
formOptions={props.formOptions}
|
|
201
|
+
>
|
|
202
|
+
{getSlot()}
|
|
203
|
+
</CForm>
|
|
204
|
+
</div>
|
|
205
|
+
</div>
|
|
206
|
+
<div className="c-search-simple-btn" ref={simpleBtnRef}>
|
|
207
|
+
{slots["arrow-left"]?.()}
|
|
208
|
+
{showCount.value < props.formOptions?.length && (
|
|
209
|
+
<div
|
|
210
|
+
className={`c-search-simple-icon ${showSearchForm.value ? "icon-rotate" : ""
|
|
211
|
+
}`}
|
|
212
|
+
onClick={handleShow}
|
|
213
|
+
>
|
|
214
|
+
<el-icon className="el-icon c-search-icon">
|
|
215
|
+
<ArrowUpBold />
|
|
216
|
+
</el-icon>
|
|
217
|
+
</div>
|
|
218
|
+
)}
|
|
219
|
+
{slots["search-btn"]
|
|
220
|
+
? slots["search-btn"]()
|
|
221
|
+
: (
|
|
222
|
+
<>
|
|
223
|
+
{slots["btn-left"]?.()}
|
|
224
|
+
<el-button type="primary" onClick={handleSearch}>
|
|
225
|
+
搜索
|
|
226
|
+
</el-button>
|
|
227
|
+
<el-button type="primary" onClick={handleReset}>
|
|
228
|
+
重置
|
|
229
|
+
</el-button>
|
|
230
|
+
{slots["btn-right"]?.()}
|
|
231
|
+
</>
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
|
|
237
|
+
{/* 下拉悬浮 */}
|
|
238
|
+
{!props.isDrawer && showSearchForm.value && (
|
|
239
|
+
<transition name="search-form-transition">
|
|
240
|
+
<el-card
|
|
241
|
+
ref={dropdownRef}
|
|
242
|
+
className="c-search-form el-card is-always-shadow"
|
|
243
|
+
>
|
|
244
|
+
<CForm
|
|
245
|
+
{...getEvent()}
|
|
246
|
+
inline
|
|
247
|
+
model={props.modelValue}
|
|
248
|
+
formOptions={props.formOptions.filter(
|
|
249
|
+
(item, index) => index >= showCount.value
|
|
250
|
+
)}
|
|
251
|
+
ref="formRef"
|
|
252
|
+
>
|
|
253
|
+
{getSlot()}
|
|
254
|
+
</CForm>
|
|
255
|
+
<div style="text-align: right;">
|
|
256
|
+
<el-button type="primary" onClick={handleSearch}>
|
|
257
|
+
搜索
|
|
258
|
+
</el-button>
|
|
259
|
+
<el-button type="primary" onClick={handleClose}>
|
|
260
|
+
关闭
|
|
261
|
+
</el-button>
|
|
262
|
+
</div>
|
|
263
|
+
</el-card>
|
|
264
|
+
</transition>
|
|
265
|
+
)}
|
|
266
|
+
|
|
267
|
+
{props.isDrawer && (
|
|
268
|
+
<CDrawer title="搜索" v-model={showSearchForm.value} size="660px">
|
|
269
|
+
<CForm
|
|
270
|
+
{...getEvent()}
|
|
271
|
+
col={12}
|
|
272
|
+
model={props.modelValue}
|
|
273
|
+
formOptions={props.formOptions.filter(
|
|
274
|
+
(item, index) => index >= showCount.value
|
|
275
|
+
)}
|
|
276
|
+
ref="formRef"
|
|
277
|
+
>
|
|
278
|
+
{getSlot()}
|
|
279
|
+
</CForm>
|
|
280
|
+
<div style="text-align: right;">
|
|
281
|
+
<el-button type="primary" onClick={handleSearch}>
|
|
282
|
+
搜索
|
|
283
|
+
</el-button>
|
|
284
|
+
<el-button type="primary" onClick={handleClose}>
|
|
285
|
+
关闭
|
|
286
|
+
</el-button>
|
|
287
|
+
</div>
|
|
288
|
+
</CDrawer>
|
|
289
|
+
)}
|
|
290
|
+
</div>
|
|
291
|
+
);
|
|
292
|
+
};
|
|
293
|
+
},
|
|
294
|
+
});
|