@elementplus-kit/uikit 1.3.0 → 1.5.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.
|
@@ -50,7 +50,7 @@ const propsAttrs = {
|
|
|
50
50
|
options: { type: Array, default: () => [] },
|
|
51
51
|
// 字典选项
|
|
52
52
|
optionsRef: { type: Object, default: () => {} },
|
|
53
|
-
|
|
53
|
+
mergeParams: { type: Object, default: () => {} },
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
export default defineComponent({
|
|
@@ -108,7 +108,7 @@ export default defineComponent({
|
|
|
108
108
|
const getDisabled = () => {
|
|
109
109
|
let disabled = false;
|
|
110
110
|
if (isFunction(attrs.value?.disabled)) {
|
|
111
|
-
disabled = attrs.value.disabled(
|
|
111
|
+
disabled = attrs.value.disabled(props.mergeParams);
|
|
112
112
|
}
|
|
113
113
|
if (isBoolean(attrs.value?.disabled)) { // 在 attrs 后面结构, 也要处理直接赋值的情况,不然会覆盖
|
|
114
114
|
disabled = attrs.value.disabled;
|
|
@@ -101,15 +101,22 @@ export default defineComponent({
|
|
|
101
101
|
return formItemVdom;
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
|
-
|
|
104
|
+
// 合并 formData 和 params
|
|
105
|
+
const mergeParams = computed(() => {
|
|
106
|
+
return { formData: model.value, params: props.params };
|
|
107
|
+
});
|
|
105
108
|
// 渲染表单项
|
|
106
109
|
const renderFormItem = () => {
|
|
107
110
|
// 过滤权限
|
|
108
111
|
const list = [];
|
|
112
|
+
|
|
109
113
|
formOptions.value.map((item) => {
|
|
110
114
|
// 处理 vIf true 显示 false 隐藏
|
|
111
|
-
if (
|
|
112
|
-
|
|
115
|
+
if (
|
|
116
|
+
isFunction(item?.vIf) &&
|
|
117
|
+
item.vIf(mergeParams.value) !== undefined
|
|
118
|
+
) {
|
|
119
|
+
if (item.vIf(mergeParams.value)) {
|
|
113
120
|
list.push(item);
|
|
114
121
|
}
|
|
115
122
|
} else {
|
|
@@ -124,7 +131,7 @@ export default defineComponent({
|
|
|
124
131
|
class: "c-form-itme",
|
|
125
132
|
model: model.value,
|
|
126
133
|
allReadonly,
|
|
127
|
-
|
|
134
|
+
mergeParams: mergeParams.value,
|
|
128
135
|
...item,
|
|
129
136
|
optionsRef: optionsRef.value,
|
|
130
137
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, defineComponent, onMounted, onUnmounted, nextTick } from "vue";
|
|
1
|
+
import { ref, defineComponent, onMounted, onUnmounted, nextTick, watch } from "vue";
|
|
2
2
|
|
|
3
3
|
import { CForm, CDrawer } from "@elementplus-kit/uikit";
|
|
4
4
|
import { ArrowUpBold } from "@element-plus/icons-vue";
|
|
@@ -64,11 +64,7 @@ export default defineComponent({
|
|
|
64
64
|
};
|
|
65
65
|
// 点击元素外关闭
|
|
66
66
|
const dropdownRef = ref<HTMLElement | null>(null); // 下拉表单的 ref
|
|
67
|
-
|
|
68
|
-
const isClickOutside = (event, targetElement) => {
|
|
69
|
-
console.log("🚀 ~ isClickOutside ~ targetElement:", targetElement);
|
|
70
|
-
return !targetElement.contains(event.target);
|
|
71
|
-
};
|
|
67
|
+
|
|
72
68
|
// 点击外部关闭函数
|
|
73
69
|
const handleClickOutside = (event: MouseEvent) => {
|
|
74
70
|
// 如果下拉表单可见,且点击事件不在下拉表单内部
|
|
@@ -98,10 +94,9 @@ export default defineComponent({
|
|
|
98
94
|
const showCount = ref(6); // 显示个数
|
|
99
95
|
const simpleRef = ref<HTMLDivElement>(null);
|
|
100
96
|
const simpleFormRef = ref<HTMLDivElement>(null);
|
|
97
|
+
const simpleFormContainerRef = ref<HTMLDivElement>(null);
|
|
101
98
|
const simpleBtnRef = ref<HTMLDivElement>(null);
|
|
102
99
|
const cFormRef = ref<HTMLDivElement>(null);
|
|
103
|
-
const calcFlg = ref(false); // 计算宽度后再显示表单
|
|
104
|
-
const childW = ref([]);
|
|
105
100
|
|
|
106
101
|
// 设置节流
|
|
107
102
|
let timer: any = null;
|
|
@@ -113,58 +108,72 @@ export default defineComponent({
|
|
|
113
108
|
calcSunResize();
|
|
114
109
|
}, 200);
|
|
115
110
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (simpleFormRef.value) {
|
|
111
|
+
// 计算显示个数
|
|
112
|
+
const calcSunResize = () => {
|
|
113
|
+
if (simpleFormContainerRef.value) {
|
|
120
114
|
// 寻找cForm 先写死 后期做成动态寻找
|
|
121
|
-
const cFormDom =
|
|
122
|
-
const cFormW =
|
|
115
|
+
const cFormDom = simpleFormContainerRef.value.children[0];
|
|
116
|
+
const cFormW = simpleFormRef.value.offsetWidth;
|
|
123
117
|
// 收集子元素宽度并保存到数组中
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
+
|
|
127
128
|
const computedStyles = window.getComputedStyle(child); // 获取元素 css 样式
|
|
128
129
|
const mg = computedStyles.marginRight; // 获取元素 margin-right 样式值 有单位
|
|
129
130
|
const mgValue = parseFloat(mg); // 转换为数值
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
childW.value.reduce((pre, cur, index) => {
|
|
135
|
-
if (pre > cFormW) {
|
|
136
|
-
return 10000; // 终止累加
|
|
137
|
-
}
|
|
138
|
-
if (pre + cur > cFormW) {
|
|
131
|
+
const w = child.offsetWidth + mgValue;
|
|
132
|
+
maxW = maxW + w;
|
|
133
|
+
if (maxW > cFormW) {
|
|
134
|
+
child.style.display = "none";
|
|
139
135
|
showCount.value = index;
|
|
140
|
-
|
|
136
|
+
maxW = 100000;
|
|
141
137
|
}
|
|
142
|
-
|
|
143
|
-
}, 0);
|
|
138
|
+
});
|
|
144
139
|
}
|
|
145
140
|
};
|
|
146
|
-
//
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
+
}
|
|
155
167
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return pre + cur;
|
|
159
|
-
}
|
|
160
|
-
return pre + cur;
|
|
161
|
-
}, 0);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
168
|
+
}
|
|
169
|
+
});
|
|
164
170
|
|
|
171
|
+
// 开始监听目标元素
|
|
172
|
+
resizeObserver.observe(targetElement);
|
|
173
|
+
};
|
|
165
174
|
onMounted(() => {
|
|
166
|
-
//
|
|
167
|
-
|
|
175
|
+
// jt函数会触发一次初始化
|
|
176
|
+
jt();
|
|
168
177
|
// 注册页面大小函数
|
|
169
178
|
window.addEventListener("resize", searchResize);
|
|
170
179
|
});
|
|
@@ -173,25 +182,26 @@ export default defineComponent({
|
|
|
173
182
|
window.removeEventListener("resize", searchResize);
|
|
174
183
|
document.removeEventListener("click", handleClickOutside); // 销毁点击事件
|
|
175
184
|
});
|
|
185
|
+
|
|
176
186
|
return () => {
|
|
177
187
|
return (
|
|
178
188
|
<div className="c-search">
|
|
179
|
-
<div
|
|
180
|
-
className="c-search-simple"
|
|
181
|
-
ref={simpleRef}
|
|
182
|
-
>
|
|
189
|
+
<div className="c-search-simple" ref={simpleRef}>
|
|
183
190
|
<div className="c-search-simple-form" ref={simpleFormRef}>
|
|
184
|
-
<
|
|
185
|
-
|
|
186
|
-
{
|
|
187
|
-
inline
|
|
188
|
-
model={props.modelValue}
|
|
189
|
-
formOptions={props.formOptions?.filter(
|
|
190
|
-
(item, index) => index < showCount.value
|
|
191
|
-
)}
|
|
191
|
+
<div
|
|
192
|
+
className="c-simple-form-container"
|
|
193
|
+
ref={simpleFormContainerRef}
|
|
192
194
|
>
|
|
193
|
-
|
|
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>
|
|
195
205
|
</div>
|
|
196
206
|
<div className="c-search-simple-btn" ref={simpleBtnRef}>
|
|
197
207
|
{slots["btn-left"]?.()}
|