zmdms-webui 2.7.4 → 2.7.6
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.
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { useState, useCallback } from 'react';
|
|
2
2
|
import { getSetDynamicKey } from './useDynamic.js';
|
|
3
|
+
import '../config/ZtxkContext.js';
|
|
4
|
+
import useBaseContext from '../config/useBaseContext.js';
|
|
5
|
+
import '../config/MyStorage.js';
|
|
3
6
|
|
|
4
7
|
function useDrawer(currentDynamicList, setCurrentDynamicList, dynamicKey, parentDynamicKey, setTempDynamicList, list, onCurrentListChange) {
|
|
5
8
|
// 控制抽屉显示隐藏
|
|
6
9
|
var _a = useState(false), visible = _a[0], setVisible = _a[1];
|
|
10
|
+
var customConfigFetch = useBaseContext().customConfigFetch;
|
|
7
11
|
// 设置缓存数据的方法
|
|
8
12
|
var setDynamicKey = useCallback(function () {
|
|
9
|
-
return getSetDynamicKey(parentDynamicKey, "".concat(parentDynamicKey, "_lru_key"));
|
|
10
|
-
}, [parentDynamicKey]);
|
|
13
|
+
return getSetDynamicKey(parentDynamicKey, "".concat(parentDynamicKey, "_lru_key"), customConfigFetch);
|
|
14
|
+
}, [parentDynamicKey, customConfigFetch]);
|
|
11
15
|
// 关闭
|
|
12
16
|
var onClose = useCallback(function () {
|
|
13
17
|
setVisible(false);
|
|
@@ -143,7 +143,7 @@ function getCurrentDynamicItems(dynamicKey, parentDynamicKey, list) {
|
|
|
143
143
|
* @param dynamicStorageKey 保留的key值
|
|
144
144
|
* @param value 值
|
|
145
145
|
*/
|
|
146
|
-
function getSetDynamicKey(LOCALSTORAGE_KEY, LOCALSTORAGE_LRU_KEY) {
|
|
146
|
+
function getSetDynamicKey(LOCALSTORAGE_KEY, LOCALSTORAGE_LRU_KEY, customConfigFetch) {
|
|
147
147
|
return function (dynamicStorageKey, value) {
|
|
148
148
|
var obj = {};
|
|
149
149
|
var lruKeys = [];
|
|
@@ -184,8 +184,26 @@ function getSetDynamicKey(LOCALSTORAGE_KEY, LOCALSTORAGE_LRU_KEY) {
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
obj[dynamicStorageKey] = value;
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
var data = JSON.stringify(obj);
|
|
188
|
+
var lruData = JSON.stringify(lruKeys);
|
|
189
|
+
localStorage.setItem(LOCALSTORAGE_KEY, data);
|
|
190
|
+
localStorage.setItem(LOCALSTORAGE_LRU_KEY, lruData);
|
|
191
|
+
// 持久化存储
|
|
192
|
+
try {
|
|
193
|
+
customConfigFetch === null || customConfigFetch === void 0 ? void 0 : customConfigFetch({
|
|
194
|
+
customKey: LOCALSTORAGE_KEY,
|
|
195
|
+
customValue: data,
|
|
196
|
+
mark: "表单动态列配置缓存数据-新版组件库",
|
|
197
|
+
});
|
|
198
|
+
customConfigFetch === null || customConfigFetch === void 0 ? void 0 : customConfigFetch({
|
|
199
|
+
customKey: LOCALSTORAGE_LRU_KEY,
|
|
200
|
+
customValue: lruData,
|
|
201
|
+
mark: "表单动态列配置缓存LRUKey数据-新版组件库",
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
console.error("\u8BBE\u7F6E\u52A8\u6001\u5217\u7F13\u5B58\u6570\u636E\u5931\u8D25!", err);
|
|
206
|
+
}
|
|
189
207
|
};
|
|
190
208
|
}
|
|
191
209
|
/**
|
package/dist/es/form/form.js
CHANGED
|
@@ -27,26 +27,32 @@ var FormContext = createContext({});
|
|
|
27
27
|
// 用户配置优先,先从远端获取到 表单配置信息。
|
|
28
28
|
// 给子元素设置好了表单配置信息后 接下来的内容 交给动态列配置接管
|
|
29
29
|
var Form = function (props, ref) {
|
|
30
|
-
var form = props.form, bottomBorder = props.bottomBorder, _a = props.isFlex, isFlex = _a === void 0 ? true : _a, wrapClassName = props.wrapClassName, leftClassName = props.leftClassName; props.itemClassName; var rightWrapVisible = props.rightWrapVisible, rightClassName = props.rightClassName, children = props.children, dynamicKey = props.dynamicKey, dynamicVersion = props.dynamicVersion, formPreferences = props.formPreferences, items = props.items, outsideState = props.outsideState, onValuesChange = props.onValuesChange, isResetAndClear = props.isResetAndClear, onResetHandle = props.onResetHandle, onSearchHandle = props.onSearchHandle, type = props.type, directionColumn = props.directionColumn, isToggle = props.isToggle, toggleNum = props.toggleNum, defaultToggle = props.defaultToggle,
|
|
30
|
+
var form = props.form, bottomBorder = props.bottomBorder, _a = props.isFlex, isFlex = _a === void 0 ? true : _a, wrapClassName = props.wrapClassName, leftClassName = props.leftClassName; props.itemClassName; var rightWrapVisible = props.rightWrapVisible, rightClassName = props.rightClassName, children = props.children, dynamicKey = props.dynamicKey, dynamicVersion = props.dynamicVersion, formPreferences = props.formPreferences, items = props.items, outsideState = props.outsideState, onValuesChange = props.onValuesChange, isResetAndClear = props.isResetAndClear, onResetHandle = props.onResetHandle, onSearchHandle = props.onSearchHandle, type = props.type, directionColumn = props.directionColumn, isToggle = props.isToggle, toggleNum = props.toggleNum, defaultToggle = props.defaultToggle, isCommonSearch = props.isCommonSearch, restProps = __rest(props, ["form", "bottomBorder", "isFlex", "wrapClassName", "leftClassName", "itemClassName", "rightWrapVisible", "rightClassName", "children", "dynamicKey", "dynamicVersion", "formPreferences", "items", "outsideState", "onValuesChange", "isResetAndClear", "onResetHandle", "onSearchHandle", "type", "directionColumn", "isToggle", "toggleNum", "defaultToggle", "isCommonSearch"]);
|
|
31
31
|
var enableCommonSearch = useBaseContext().enableCommonSearch;
|
|
32
|
+
// 是否开启常用搜索
|
|
33
|
+
// 如果全局开启了默认添加,那么只要没有单独配置关闭,都认为需要打开
|
|
34
|
+
var isCommonSearchEnabled = rightWrapVisible &&
|
|
35
|
+
(enableCommonSearch ? isCommonSearch !== false : !!isCommonSearch);
|
|
32
36
|
// 常用搜索hooks
|
|
33
|
-
var
|
|
37
|
+
var _b = useCommonSearch({
|
|
34
38
|
commonSearchKey: dynamicKey || window.location.pathname,
|
|
35
|
-
|
|
39
|
+
isCommonSearchEnabled: isCommonSearchEnabled,
|
|
40
|
+
}), commonSearchList = _b.commonSearchList, setCommonSearchList = _b.setCommonSearchList, currentCommonSearchKey = _b.currentCommonSearchKey, setCurrentCommonSearchKey = _b.setCurrentCommonSearchKey, setData = _b.setData, deleteData = _b.deleteData, setReplaceData = _b.setReplaceData, reTransformData = _b.reTransformData, updateServerData = _b.updateServerData;
|
|
36
41
|
var onCommonSearchHandle = useCommonSearchModal({
|
|
37
42
|
commonSearchList: commonSearchList,
|
|
38
43
|
currentCommonSearchKey: currentCommonSearchKey,
|
|
39
44
|
form: form,
|
|
40
45
|
setData: setData,
|
|
46
|
+
isCommonSearchEnabled: isCommonSearchEnabled,
|
|
41
47
|
}).onCommonSearchHandle;
|
|
42
48
|
// 获取新的items 如果传入了配置项的话,配置项优先
|
|
43
49
|
var configInfoItems = useFormPreferencesCreateNewItems(formPreferences, items).configInfoItems;
|
|
44
50
|
// 根据items 和 dynamicKey 获取到动态列配置信息
|
|
45
|
-
var
|
|
51
|
+
var _c = useDynamicListByItems(configInfoItems, {
|
|
46
52
|
dynamicKey: dynamicKey,
|
|
47
53
|
formPreferences: formPreferences,
|
|
48
54
|
dynamicVersion: dynamicVersion,
|
|
49
|
-
}), dynamicList =
|
|
55
|
+
}), dynamicList = _c.dynamicList, onCurrentListChange = _c.onCurrentListChange, newItems = _c.newItems, dynamicSettingRef = _c.dynamicSettingRef;
|
|
50
56
|
// 主容器类名
|
|
51
57
|
var wrapClasses = classNames("ztxk-form", wrapClassName, {
|
|
52
58
|
"ztxk-form--bottom-border": bottomBorder,
|
|
@@ -118,22 +124,22 @@ var Form = function (props, ref) {
|
|
|
118
124
|
}
|
|
119
125
|
onValuesChange && onValuesChange(changedValues, allValues);
|
|
120
126
|
}, [onValuesChange, itemsShouldUpdate, form]);
|
|
121
|
-
var
|
|
127
|
+
var _d = useBtnHandle(form, {
|
|
122
128
|
onSearchHandle: onSearchHandle,
|
|
123
129
|
onResetHandle: onResetHandle,
|
|
124
|
-
}), onSearchHandleInner =
|
|
130
|
+
}), onSearchHandleInner = _d.onSearchHandleInner, onResetHandleInner = _d.onResetHandleInner, onDropdownResetHandleInner = _d.onDropdownResetHandleInner;
|
|
125
131
|
var leftWrapRef = useRef(null);
|
|
126
|
-
var
|
|
132
|
+
var _e = useToggle(leftWrapRef, {
|
|
127
133
|
isToggle: isToggle,
|
|
128
134
|
toggleNum: toggleNum,
|
|
129
135
|
defaultToggle: defaultToggle,
|
|
130
|
-
}), toggle =
|
|
136
|
+
}), toggle = _e.toggle, onToggleChange = _e.onToggleChange, setToggleHandle = _e.setToggleHandle;
|
|
131
137
|
useImperativeHandle(ref, function () {
|
|
132
138
|
return {
|
|
133
139
|
setToggleHandle: setToggleHandle,
|
|
134
140
|
};
|
|
135
141
|
});
|
|
136
|
-
return (jsxs(FormContext.Provider, __assign({ value: { onSearch: onSearchHandleInner } }, { children: [jsxs(Form$1, __assign({ form: form, onValuesChange: onValuesChangeHandle }, restProps, { className: wrapClasses }, { children: [jsx("div", __assign({ className: leftClasses, ref: leftWrapRef }, { children: items ? (jsx(FormItems, { items: dynamicKey ? newItems : configInfoItems, outsideState: outsideState })) : (children) })), jsxs("div", __assign({ className: "ztxk-form--operation" }, { children: [dynamicKey ? (jsx(DynamicSetting, { dynamicKey: dynamicKey, parentDynamicKey: FORM_DYNAMIC_KEY, defaultList: dynamicList, onCurrentListChange: onCurrentListChange, ref: dynamicSettingRef })) : null, isToggle ? (jsx(Toggle, { toggle: toggle, onClick: onToggleChange })) : null] })), rightWrapVisible ? (jsxs("div", __assign({ className: rightClasses }, { children: [jsxs("div", __assign({ className: "ztxk-form__right--common-left" }, { children: [isResetAndClear ? (jsx(ResetButton, { onClick: onDropdownResetHandleInner })) : (jsx(ButtonCom, __assign({ type: "default", onClick: onResetHandleInner }, { children: "\u91CD\u7F6E" }))), jsx(ButtonCom, __assign({ type: "primary", onClick: onSearchHandleInner }, { children: "\u67E5\u8BE2" }))] })),
|
|
142
|
+
return (jsxs(FormContext.Provider, __assign({ value: { onSearch: onSearchHandleInner } }, { children: [jsxs(Form$1, __assign({ form: form, onValuesChange: onValuesChangeHandle }, restProps, { className: wrapClasses }, { children: [jsx("div", __assign({ className: leftClasses, ref: leftWrapRef }, { children: items ? (jsx(FormItems, { items: dynamicKey ? newItems : configInfoItems, outsideState: outsideState })) : (children) })), jsxs("div", __assign({ className: "ztxk-form--operation" }, { children: [dynamicKey ? (jsx(DynamicSetting, { dynamicKey: dynamicKey, parentDynamicKey: FORM_DYNAMIC_KEY, defaultList: dynamicList, onCurrentListChange: onCurrentListChange, ref: dynamicSettingRef })) : null, isToggle ? (jsx(Toggle, { toggle: toggle, onClick: onToggleChange })) : null] })), rightWrapVisible ? (jsxs("div", __assign({ className: rightClasses }, { children: [jsxs("div", __assign({ className: "ztxk-form__right--common-left" }, { children: [isResetAndClear ? (jsx(ResetButton, { onClick: onDropdownResetHandleInner })) : (jsx(ButtonCom, __assign({ type: "default", onClick: onResetHandleInner }, { children: "\u91CD\u7F6E" }))), jsx(ButtonCom, __assign({ type: "primary", onClick: onSearchHandleInner }, { children: "\u67E5\u8BE2" }))] })), isCommonSearchEnabled ? (jsx("div", __assign({ className: "ztxk-form__right--common-right" }, { children: jsx(ButtonCom, __assign({ style: { width: "100%" }, onClick: onCommonSearchHandle }, { children: currentCommonSearchKey ? "更新常用搜索" : "保存为常用搜索" })) }))) : null] }))) : null] })), isCommonSearchEnabled ? (jsx(CommonSearchList, { commonSearchList: commonSearchList, setCommonSearchList: setCommonSearchList, currentCommonSearchKey: currentCommonSearchKey, setCurrentCommonSearchKey: setCurrentCommonSearchKey, form: form, reTransformData: reTransformData, deleteData: deleteData, setReplaceData: setReplaceData, updateServerData: updateServerData, onSearchHandle: onSearchHandleInner })) : null] })));
|
|
137
143
|
};
|
|
138
144
|
var MemoForm = memo(forwardRef(Form));
|
|
139
145
|
MemoForm.displayName = "ZTXK_WEBUI_Form";
|
|
@@ -14,17 +14,19 @@ var COMMON_SEARCH_KEY = "__zmdms-ui--common-search-key__";
|
|
|
14
14
|
// 常用搜索hooks
|
|
15
15
|
function useCommonSearch(options) {
|
|
16
16
|
var _this = this;
|
|
17
|
-
var commonSearchKey = options.commonSearchKey;
|
|
17
|
+
var commonSearchKey = options.commonSearchKey, isCommonSearchEnabled = options.isCommonSearchEnabled;
|
|
18
18
|
var customConfigFetch = useBaseContext().customConfigFetch;
|
|
19
19
|
// 常用搜索列表存储实例
|
|
20
|
-
var storageRef = useRef(
|
|
20
|
+
var storageRef = useRef(isCommonSearchEnabled
|
|
21
|
+
? new MyStorage({ tableKey: COMMON_SEARCH_KEY })
|
|
22
|
+
: null);
|
|
21
23
|
// 常用搜索列表
|
|
22
24
|
var _a = useState([]), commonSearchList = _a[0], setCommonSearchList = _a[1];
|
|
23
25
|
// 当前选中的常用搜索key值
|
|
24
26
|
var _b = useState(""), currentCommonSearchKey = _b[0], setCurrentCommonSearchKey = _b[1];
|
|
25
27
|
// 初始化常用搜索列表
|
|
26
28
|
useMount(function () {
|
|
27
|
-
if (commonSearchKey) {
|
|
29
|
+
if (commonSearchKey && storageRef.current) {
|
|
28
30
|
storageRef.current
|
|
29
31
|
.getItem(commonSearchKey)
|
|
30
32
|
.then(function (res) { return setCommonSearchList(res || []); });
|
|
@@ -179,23 +181,20 @@ function useCommonSearch(options) {
|
|
|
179
181
|
return __generator(this, function (_a) {
|
|
180
182
|
switch (_a.label) {
|
|
181
183
|
case 0:
|
|
182
|
-
|
|
183
|
-
_a.label = 1;
|
|
184
|
-
case 1:
|
|
185
|
-
_a.trys.push([1, 3, , 4]);
|
|
184
|
+
_a.trys.push([0, 2, , 3]);
|
|
186
185
|
return [4 /*yield*/, (customConfigFetch === null || customConfigFetch === void 0 ? void 0 : customConfigFetch({
|
|
187
186
|
customKey: COMMON_SEARCH_KEY,
|
|
188
187
|
customValue: JSON.stringify(res),
|
|
189
188
|
mark: "常用搜索用户配置",
|
|
190
189
|
}))];
|
|
191
|
-
case
|
|
190
|
+
case 1:
|
|
192
191
|
_a.sent();
|
|
193
|
-
return [3 /*break*/,
|
|
194
|
-
case
|
|
192
|
+
return [3 /*break*/, 3];
|
|
193
|
+
case 2:
|
|
195
194
|
error_1 = _a.sent();
|
|
196
195
|
console.error("更新服务器数据失败!", error_1);
|
|
197
|
-
return [3 /*break*/,
|
|
198
|
-
case
|
|
196
|
+
return [3 /*break*/, 3];
|
|
197
|
+
case 3: return [2 /*return*/];
|
|
199
198
|
}
|
|
200
199
|
});
|
|
201
200
|
}); })];
|
|
@@ -214,10 +213,13 @@ function useCommonSearch(options) {
|
|
|
214
213
|
};
|
|
215
214
|
}
|
|
216
215
|
function useCommonSearchModal(options) {
|
|
217
|
-
var commonSearchList = options.commonSearchList, currentCommonSearchKey = options.currentCommonSearchKey, form = options.form, setData = options.setData;
|
|
216
|
+
var commonSearchList = options.commonSearchList, currentCommonSearchKey = options.currentCommonSearchKey, form = options.form, setData = options.setData, isCommonSearchEnabled = options.isCommonSearchEnabled;
|
|
218
217
|
var iptRef = useRef(null);
|
|
219
218
|
useEffect(function () {
|
|
220
219
|
var _a;
|
|
220
|
+
if (!isCommonSearchEnabled) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
221
223
|
if (!(commonSearchList === null || commonSearchList === void 0 ? void 0 : commonSearchList.length)) {
|
|
222
224
|
return;
|
|
223
225
|
}
|
|
@@ -225,7 +227,7 @@ function useCommonSearchModal(options) {
|
|
|
225
227
|
if (currentCommon) {
|
|
226
228
|
(_a = iptRef.current) === null || _a === void 0 ? void 0 : _a.setValue(currentCommon.title);
|
|
227
229
|
}
|
|
228
|
-
}, [currentCommonSearchKey, commonSearchList]);
|
|
230
|
+
}, [currentCommonSearchKey, commonSearchList, isCommonSearchEnabled]);
|
|
229
231
|
/**
|
|
230
232
|
* 保存为常用搜索事件
|
|
231
233
|
*/
|