ff-dist/dist/common/main-DamvcBIJ.js
2024-07-12 10:30:05 +08:00

2246 lines
104 KiB
JavaScript

var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
var __publicField = (obj, key, value) => (__defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
}, __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
var __privateWrapper = (obj, member, setter, getter) => ({
set _(value) {
__privateSet(obj, member, value, setter);
},
get _() {
return __privateGet(obj, member, getter);
}
});
import _ from "lodash";
import axios from "axios";
import React, { useMemo, useEffect, useRef, useState, useCallback, useContext, useLayoutEffect, useId as useId$1 } from "react";
import Request from "ff-request";
import SparkMD5 from "https://assets.fsdpf.net/js/esm/spark-md5@3_0_2.min.js?url";
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
import { QuestionOutlined, LoadingOutlined, createFromIconfontCN } from "@ant-design/icons";
import cx from "classnames";
import { P as PropTypes, N as NProgress } from "./vender-CMS8SASe.js";
import Form, { Field, FieldContext } from "rc-field-form";
import { notification as notification$1, Drawer as Drawer$1, Modal as Modal$1, Form as Form$1, ConfigProvider, Input, Button as Button$1, Breadcrumb, Tree, Pagination, Table, Empty as Empty$1, Popconfirm, Tooltip, Popover as Popover$1 } from "antd";
import { flushSync } from "react-dom";
import update from "immutability-helper";
import { useParams, generatePath, Navigate, createBrowserRouter } from "react-router-dom";
const Iconfont = ({ type, className, ...props }) => {
if (!(type != null && type.startsWith("icon-")))
return /* @__PURE__ */ jsx(QuestionOutlined, {});
if (type === "icon-loading")
return /* @__PURE__ */ jsx(LoadingOutlined, { className, ...props });
const Icon = useMemo(() => createFromIconfontCN({ scriptUrl: configure.get("Common.ICONFONT", []) }), [configure.get("Common.ICONFONT")]);
return /* @__PURE__ */ jsx(Icon, { type, className: cx("iconfont", className), ...props });
}, Notification = ({ className, title, content, icon, $close, category, duration = 4.5 }) => {
const [api, contextHolder] = notification$1.useNotification();
return useEffect(() => {
api[category || "open"]({
className,
message: title,
description: content,
icon,
duration,
onClose: () => $close(!1)
});
}, [title, content, icon]), contextHolder;
}, Confirm = ({ className, title, content, okText, $close, duration = 5e3 }) => {
var _a;
const timeRef = useRef(), [time, setTime] = useState();
return useEffect(() => (time > 0 && (timeRef.current = setTimeout(() => {
time <= 1 ? $close() : setTime((time2) => time2 - 1);
}, 1e3)), () => clearTimeout(timeRef.current)), [time]), useEffect(() => {
setTime(Math.max(Math.ceil(duration / 1e3), 0));
}, [duration]), /* @__PURE__ */ jsx("div", { className: cx("ff-confirm", className), onClick: (e) => e.mpEvent.currentTarget.id === e.mpEvent.target.id && $close(), children: /* @__PURE__ */ jsxs("div", { className: "ff-confirm-container", children: [
/* @__PURE__ */ jsx("div", { className: "ff-confirm-title", children: title }),
/* @__PURE__ */ jsx("div", { className: "ff-confirm-content", children: content }),
/* @__PURE__ */ jsxs("div", { className: "ff-confirm-operations", children: [
/* @__PURE__ */ jsxs("div", { className: "ff-confirm-cancel", onClick: () => $close(!1), children: [
"取消 (",
time,
")"
] }),
React.isValidElement(okText) ? React.cloneElement(okText, {
onClick: () => $close(!0),
className: cx("ff-confirm-ok", (_a = okText.props) == null ? void 0 : _a.className)
}) : /* @__PURE__ */ jsx("div", { className: "ff-confirm-ok", onClick: () => $close(!0), children: okText || "确定" })
] })
] }) });
}, SlotContext = React.createContext({
ele: {},
mount: () => {
},
unmount: () => {
}
}), FFContainer = ({ className, children, actions, title, subTitle, extras, style }) => (actions && FFContainer.Action({ children: actions }), title && FFContainer.Title({ children: title }), subTitle && FFContainer.SubTitle({ children: subTitle }), extras && FFContainer.Extra({ children: extras }), /* @__PURE__ */ jsx("div", { className: cx("ff-container", className), style, children })), slot = (name) => ({ children, className }) => {
const { mount, unmount } = React.useContext(SlotContext);
return useEffect(() => (mount(name, React.createElement("div", {
key: `ff-${name}`,
className: cx(`ff-popup-${name}`, className)
}, children)), () => unmount(name)), [className, children]), null;
};
FFContainer.Action = slot("actions");
FFContainer.Title = slot("title");
FFContainer.SubTitle = slot("sub-title");
FFContainer.Extra = slot("extras");
const SlotRender = ({ name }) => {
const { ele } = React.useContext(SlotContext);
return ele == null ? void 0 : ele[name];
};
FFContainer.propTypes = {
// 容器 className
className: PropTypes.string,
// 容器样式
style: PropTypes.object,
// 标题占位符
title: PropTypes.any,
// 副标题占位符
subTitle: PropTypes.any,
// 操作按钮占位符
actions: PropTypes.any,
// 扩展安装占位符
extras: PropTypes.any
};
FFContainer.defaultProps = {
style: {}
};
const Drawer = React.forwardRef(({ $close, children, className, title, ...props }, ref) => {
const closeCarryRef = useRef(), [open, setOpen] = useState(!0), [ele, setEle] = useState({}), onMount = useCallback((solt, ele2) => setEle((state) => ({ ...state, [solt]: ele2 })), []), onUnmount = useCallback((solt) => setEle((state) => ({ ...state, [solt]: void 0 })), []);
return React.useImperativeHandle(ref, () => ({
handleClose: (result) => {
closeCarryRef.current = result, setOpen(!1);
}
})), /* @__PURE__ */ jsx(SlotContext.Provider, { value: { ele, mount: onMount, unmount: onUnmount }, children: /* @__PURE__ */ jsx(
Drawer$1,
{
...props,
title: title || (ele == null ? void 0 : ele.title),
open,
onClose: () => {
closeCarryRef.current = !1, setOpen(!1);
},
afterOpenChange: (open2) => !open2 && $close(closeCarryRef.current),
className: cx("ff-popup ff-drawer", className, ele == null ? void 0 : ele.className),
extra: ele == null ? void 0 : ele["sub-title"],
classNames: { header: "ff-popup-header", footer: "ff-popup-footer" },
footer: ele != null && ele.extras || ele != null && ele.actions ? /* @__PURE__ */ jsxs(React.Fragment, { children: [
(ele == null ? void 0 : ele.extras) || /* @__PURE__ */ jsx("div", { className: "ff-popup-extras" }),
(ele == null ? void 0 : ele.actions) || /* @__PURE__ */ jsx("div", { className: "ff-popup-actions" })
] }) : void 0,
children
}
) });
}), Modal = React.forwardRef(({ $close, children, className, title, ...props }, ref) => {
const closeCarryRef = useRef(), [open, setOpen] = useState(!0), [ele, setEle] = useState({}), onMount = useCallback((solt, ele2) => setEle((state) => ({ ...state, [solt]: ele2 })), []), onUnmount = useCallback((solt) => setEle((state) => ({ ...state, [solt]: void 0 })), []);
return React.useImperativeHandle(ref, () => ({
handleClose: (result) => {
closeCarryRef.current = result, setOpen(!1);
}
})), /* @__PURE__ */ jsx(SlotContext.Provider, { value: { ele, mount: onMount, unmount: onUnmount }, children: /* @__PURE__ */ jsx(
Modal$1,
{
...props,
title: /* @__PURE__ */ jsxs(Fragment, { children: [
title || (ele == null ? void 0 : ele.title),
ele == null ? void 0 : ele["sub-title"]
] }),
open,
onCancel: () => {
closeCarryRef.current = !1, setOpen(!1);
},
afterOpenChange: (open2) => !open2 && $close(closeCarryRef.current),
className: cx("ff-popup ff-modal", className, ele == null ? void 0 : ele.className),
keyboard: !0,
classNames: { header: "ff-popup-header", footer: "ff-popup-footer" },
footer: ele != null && ele.extras || ele != null && ele.actions ? /* @__PURE__ */ jsxs(React.Fragment, { children: [
(ele == null ? void 0 : ele.extras) || /* @__PURE__ */ jsx("div", { className: "ff-popup-extras" }),
(ele == null ? void 0 : ele.actions) || /* @__PURE__ */ jsx("div", { className: "ff-popup-actions" })
] }) : null,
children
}
) });
});
var _instance, _oWorker, _topic, _initWorker;
const _ResWs = class _ResWs {
constructor() {
__privateAdd(this, _oWorker, null);
__privateAdd(this, _topic, /* @__PURE__ */ new Map());
__privateAdd(this, _initWorker, () => {
if (__privateGet(this, _oWorker))
return __privateGet(this, _oWorker).port.postMessage({ command: "status", data: [] });
__privateSet(this, _oWorker, new SharedWorker(new URL("data:text/plain;base64,Y29uc3QgcG9ydHMgPSBbXQpsZXQgd3MgPSBudWxsCgpmdW5jdGlvbiBpbml0V3ModXJsKSB7CiAgd3MgPSBuZXcgV2ViU29ja2V0KHVybCkKICB3cy5vbmNsb3NlID0gKGUpID0+IGNvbnNvbGUubG9nKCd3cyBjbG9zZWQnLCBlKQogIHdzLm9uZXJyb3IgPSAoZSkgPT4gY29uc29sZS5sb2coJ3dzIGVycm9yJywgZSkKICB3cy5vbm1lc3NhZ2UgPSAoeyBkYXRhIH0pID0+IHsKICAgIGNvbnN0IHZhbHVlID0gSlNPTi5wYXJzZShkYXRhKQogICAgcG9ydHMuZm9yRWFjaChwb3J0ID0+IHBvcnQucG9zdE1lc3NhZ2UodmFsdWUpKQogIH0KfQoKZnVuY3Rpb24gY2xvc2VXcygpIHsKICBpZiAoIXdzIHx8IHdzLnJlYWR5U3RhdGUgPT0gV2ViU29ja2V0Lk9QRU4pIHsKICAgIHdzLmNsb3NlKCkKICB9Cn0KCmZ1bmN0aW9uIHN0YXR1cygpIHsKICB0aGlzLnBvc3RNZXNzYWdlKHsgcmVhZHlTdGF0ZTogd3MgPyB3cy5yZWFkeVN0YXRlIDogV2ViU29ja2V0LkNMT1NFRCB9KQp9CgpzZWxmLm9uY29ubmVjdCA9IChlKSA9PiB7CiAgY29uc3QgcG9ydCA9IGUucG9ydHNbMF07CgogIHBvcnQub25tZXNzYWdlID0gKHsgZGF0YTogeyBjb21tYW5kLCBkYXRhIH0gfSkgPT4gewogICAgaWYgKGNvbW1hbmQgJiYgWydpbml0V3MnLCAnY2xvc2VXcycsICdzdGF0dXMnXS5pbmNsdWRlcyhjb21tYW5kKSkgUmVmbGVjdC5hcHBseShzZWxmPy5bY29tbWFuZF0sIHBvcnQsIGRhdGEgfHwgW10pCiAgfQoKICBwb3J0cy5wdXNoKHBvcnQpCn0K", self.location))), __privateGet(this, _oWorker).port.onmessage = (e) => {
var _a, _b;
(_a = e.data) != null && _a.uuid ? __privateGet(this, _topic).forEach((flag, fn2) => {
var _a2;
(flag == "*" || (_a2 = flag == null ? void 0 : flag.includes) != null && _a2.call(flag, e.data.uuid)) && fn2(e.data);
}) : ((_b = e.data) == null ? void 0 : _b.readyState) == WebSocket.CLOSED && http.get("/api/user-api-token").then(({ token, expire_at }) => {
__privateGet(this, _oWorker).port.postMessage({ command: "initWs", data: [`ws${_.trimStart(AppUrl, "http")}api/user-resource-status-ws?token=${token}`] });
});
}, __privateGet(this, _oWorker).port.postMessage({ command: "status", data: [] });
});
__publicField(this, "subscribe", (cb, res = []) => (res ? Array.isArray(res) && res.length == 0 ? res = "*" : Array.isArray(res) || (res = [res].flat()) : res = "*", __privateGet(this, _topic).set(cb, res), __privateGet(this, _topic).size == 1 && __privateGet(this, _initWorker).call(this), () => this.unsubscribe(cb)));
__publicField(this, "unsubscribe", (cb) => __privateGet(this, _topic).delete(cb));
if (__privateGet(_ResWs, _instance))
return __privateGet(_ResWs, _instance);
}
};
_instance = new WeakMap(), _oWorker = new WeakMap(), _topic = new WeakMap(), _initWorker = new WeakMap(), __privateAdd(_ResWs, _instance, null), __publicField(_ResWs, "getInstance", () => (__privateGet(_ResWs, _instance) || __privateSet(_ResWs, _instance, new _ResWs()), __privateGet(_ResWs, _instance)));
let ResWs = _ResWs;
const ResWs$1 = ResWs.getInstance(), useUpdate = () => {
const isMouned = useRef(!0), [value, setValue] = useState(0);
return useEffect(() => () => isMouned.current = !1, []), () => isMouned.current && flushSync(() => {
setValue(value + 1);
});
}, usePropsValue = ({ value, defaultValue, onChange }) => {
const update2 = useUpdate(), stateRef = useRef(value !== void 0 ? value : defaultValue);
value !== void 0 && (stateRef.current = value);
const setState = useCallback(_.debounce((v) => {
value === void 0 && (stateRef.current = v, update2()), onChange && onChange(v);
}, 380, { leading: !0, trailing: !1 }), [value]);
return [stateRef.current, setState];
}, usePrevious = (state) => {
const ref = useRef();
return useEffect(() => {
ref.current = state;
}), ref.current;
}, useStateWithCallback = (init) => {
const cbRef = useRef(), [data2, setData] = useState(init);
return useEffect(() => {
_.isFunction(cbRef.current) && cbRef.current(data2);
}, [data2]), [data2, function(data3, callback) {
cbRef.current = callback, setData(data3);
}];
}, useDeepEqualEffect = (effect = React.EffectCallback, deps, compare = _.isEqual) => {
const oldDeps = React.useRef(deps);
(!oldDeps.current || !compare(deps, oldDeps.current)) && (oldDeps.current = deps), React.useEffect(effect, [oldDeps.current]);
}, transformOptions = (arr, type = "string") => {
var _a;
if (!Array.isArray(arr))
return arr;
for (let i = 0; i < arr.length; i++)
arr[i].value = _.toPrimitive((_a = arr[i]) == null ? void 0 : _a.value, type), arr[i] && Reflect.has(arr[i], "children") && (arr[i].children = transformOptions(arr[i].children, type));
return arr;
}, useOptions = (options, language = "json", type = "string", form, basicForm = null) => {
const [rcform] = Form.useForm(form), [data2, setData] = useState([{ label: "无", value: "", disabled: !0 }]), dependenciesFieldsRef = useRef([]), dependenciesValue = Form.useWatch((data3) => dependenciesFieldsRef.current.length === 0 ? null : _.pick(data3, dependenciesFieldsRef.current), rcform) || null;
return useEffect(() => {
Array.isArray(options) ? setData(options) : language === "javascript" && options ? fn.exec(options, {}, {
getFieldValue: (namePath) => (dependenciesFieldsRef.current.includes(namePath) || dependenciesFieldsRef.current.push(namePath), rcform.getFieldValue(namePath)),
getFieldValueForBasicForm: (namePath) => (dependenciesFieldsRef.current.includes(namePath) || dependenciesFieldsRef.current.push(namePath), basicForm ? basicForm.getFieldValue(namePath) : rcform.getFieldValue(namePath))
}).then((data3) => {
setData(_.toPrimitive(data3, "array"));
}) : options && setData(_.toPrimitive(options, "array"));
}, [options, language, dependenciesValue]), transformOptions(data2, type);
}, useSubscribeRequest = (param) => {
const [data2, setData] = useState(), opts = { type: "GET" };
if (typeof param == "string" ? opts.url = param : _.isPlainObject(param) && Object.assign(opts, param), !(opts != null && opts.url))
throw "url is required";
const initData = (e) => http.request(opts, !1).resp((resp) => (console.log("useSubscribeRequest", e), setData(resp), resp));
return useDeepEqualEffect(() => {
let unsubscribe = null;
return initData().then((resp) => {
unsubscribe = ResWs$1.subscribe(_.throttle(initData, 180, { leading: !1, trailing: !0 }), resp.res);
}), () => unsubscribe == null ? void 0 : unsubscribe();
}, opts), data2;
}, useConfigure = (code) => {
const [data2, setData] = React.useState({ gridItems: [], hideItems: [] });
return React.useEffect(() => {
code && http.get(`/api/_/${code}`).then(({
pk,
uuid,
code: code2,
resource,
align,
cols,
rowHeight,
marginX,
marginY,
listenChangeFields,
listenChangeFieldsFunc,
fields
}) => ({
pk,
uuid,
code: code2,
resource,
align,
cols,
rowHeight,
marginX,
marginY,
listenChangeFields,
listenChangeFieldsFunc,
...fields.reduce((carry, item) => {
var _a;
return (_a = item == null ? void 0 : item.field) != null && _a.hidden ? carry.hides.push(item == null ? void 0 : item.field) : carry.items.push(item), carry;
}, { items: [], hides: [] })
})).then(setData);
}, [code]), data2;
}, useRules = ({
max = 0,
min = 0,
type = "",
message,
pattern,
required = !1,
validator
} = {}, fieldName, fieldType) => {
const [rules, setRules] = useState([]);
return useEffect(() => {
const initRules = [];
if (required) {
let requiredFieldType = fieldType;
switch (fieldType) {
case "number":
case "string":
case "array":
break;
case "bool":
requiredFieldType = "boolean";
break;
case "json":
requiredFieldType = "object";
break;
}
initRules.push({ type: requiredFieldType, required: !0, whitespace: !0, message: "该项必填" });
}
switch (type) {
case "string":
initRules.push({
type,
max,
min,
message: message || (min && max ? `字符必须在 ${min} ~ ${max} 之间` : `${max ? "最多能有" : "最少要有"} ${min || max} 个字符`)
});
break;
case "pattern":
initRules.push({ type: "string", pattern, message });
break;
case "validator":
validator && initRules.push(({ getFieldValue }) => ({
validator: async (__, value) => {
const msg = await fn.exec(validator, { value, fieldName }, { getFieldValue });
return _.isString(msg) && msg ? Promise.reject(msg) : _.isBoolean(msg) && !msg ? Promise.reject(message) : Promise.resolve();
}
}));
break;
}
setRules(initRules);
}, [max, min, type, message, pattern, required, validator]), rules;
}, useFormData = (code, primaryKey, formSetting) => {
const [formData, setFormData] = useState(null);
return useEffect(() => {
const {
initDataUri = `/api/${code}`,
initDataMethod = "GET"
} = formSetting || {};
primaryKey && http.request({
method: initDataMethod,
url: _.trimEnd(`${initDataUri}/${primaryKey}`, "/")
}).then((data2) => {
setFormData(data2);
});
}, [code, primaryKey, formSetting]), formData;
}, useFnRun = (fn$1, form, initialValue, props = {}) => {
const forceUpdate = useUpdate(), isMountedRef = useRef(!0), dependenciesRef = useRef([]), [result, setResult] = useState(initialValue), flag = Form.useWatch((values) => JSON.stringify(_.pick(values, dependenciesRef.current)), form) || "{}";
return useEffect(() => {
fn$1 && fn.exec(fn$1, props, {
getFieldValue: _.wrap(form.getFieldValue, (cb, namePath) => (dependenciesRef.current.some((item) => _.isEqual(item, namePath)) || (dependenciesRef.current.push(namePath), forceUpdate()), cb(namePath))),
isFieldTouched: form.isFieldTouched,
isFieldsTouched: form.isFieldsTouched
}).then((v) => isMountedRef.current && setResult(v));
}, [fn$1, flag, form, props]), useEffect(() => () => isMountedRef.current = !1, []), result;
}, GridLayoutFormHoc = (WrapComponent) => ({
code,
layout,
name,
primaryKey = 0,
style = {},
formProps = {},
form: initForm,
isPreview = !1,
className,
onFinish,
onValuesChange = () => {
},
...props
}) => {
const {
align,
autoComplete,
resource,
items,
hides,
rowHeight,
marginX,
marginY,
cols,
listenChangeFields,
listenChangeFieldsFunc,
pk,
uuid
} = useConfigure(code), [form] = Form$1.useForm(initForm), onFormValuesChange = ({
changedValues,
allValues,
listenChangeFields: listenChangeFields2,
listenChangeFieldsFunc: listenChangeFieldsFunc2,
onValuesChange: onValuesChange2,
code: code2
}) => {
onValuesChange2(changedValues, allValues), listenChangeFieldsFunc2 && Array.isArray(listenChangeFields2) && fn.exec(
listenChangeFieldsFunc2,
{ changedValues, allValues },
{
getFieldValue: form.getFieldValue,
setFieldsValue: form.setFieldsValue,
isFieldTouched: form.isFieldTouched,
isFieldsTouched: form.isFieldsTouched
}
);
}, formPropsFields = useMemo(() => [
{ name: "__PK__", value: pk },
{ name: "__PROPS__", value: formProps },
{ name: "__RESOURCE__", value: resource },
{ name: "__LAYOUT_KEY__", value: code },
{ name: "__LAYOUT_UUID__", value: uuid },
{ name: "__PRIMARY_KEY__", value: primaryKey }
], [pk, code, uuid, resource, primaryKey, formProps]);
return /* @__PURE__ */ jsxs(
Form$1,
{
className,
requiredMark: !0,
name: name || code,
layout: layout || align,
fields: formPropsFields,
form,
autoComplete,
style: { ...style, position: "relative" },
onFinish,
onValuesChange: (changedValues, allValues) => onFormValuesChange(
{
changedValues,
allValues,
listenChangeFields,
listenChangeFieldsFunc,
onValuesChange,
code
}
),
children: [
/* @__PURE__ */ jsx(
WrapComponent,
{
...props,
form,
code,
fields: items,
cols,
rowHeight,
itemMargin: [marginX, marginY]
}
),
hides == null ? void 0 : hides.map((item) => {
var _a;
return /* @__PURE__ */ jsx(Field, { name: item.code, children: /* @__PURE__ */ jsx(
HideField,
{
form,
name: item.code,
type: item.type,
initialValue: item.initialValue,
initialValueLanguage: (_a = item.extras) == null ? void 0 : _a.initialValueLanguage
}
) }, JSON.stringify(item.code));
})
]
}
);
}, HideField = ({ type, initialValue, initialValueLanguage, onChange, form }) => {
const value = useFnRun(
initialValueLanguage == "javascript" && initialValue,
form,
initialValueLanguage == "javascript" ? void 0 : initialValue,
{}
);
return useEffect(() => {
initialValueLanguage == "javascript" ? onChange(_.toPrimitive(value, type)) : onChange(_.toPrimitive(initialValue, type));
}, [type, initialValue, value]), null;
}, GridLayoutHoc = (Component2) => function({ code, data: data2, ...props }) {
const [layout, setLayout] = useState({
resource: null,
cols: 12,
rowHeight: 21,
fields: []
});
return useEffect(() => {
code && http.get(`/api/_/${code}`).then((resp) => setLayout(_.pick(resp, ["resource", "cols", "rowHeight", "fields"])));
}, [code]), (layout == null ? void 0 : layout.resource) && /* @__PURE__ */ jsx(
Component2,
{
...props,
rowHeight: layout.rowHeight,
cols: layout.cols,
fields: layout.fields,
data: layout != null && layout.resource ? { [layout == null ? void 0 : layout.resource]: data2 } : {}
}
);
}, HOOK_MARK = "RC_FORM_INTERNAL_HOOKS", useField = (name, {
initialValue,
initialValueLanguage,
convertJs,
convertJsSetting,
type = "string"
}, pContext = null) => {
const isMountedRef = useRef(!1), form = useContext(FieldContext), [newValue, setNewValue] = useState(), [value, setValue] = useState(initialValueLanguage == "javascript" || !name ? void 0 : form.getFieldValue(name)), { registerWatch } = form.getInternalHooks(HOOK_MARK) || {};
return useEffect(() => registerWatch == null ? void 0 : registerWatch((_values, allValues, _namePath) => {
if (!isMountedRef.current)
return;
const watchValue = _.get(allValues, name);
_.isEqual(watchValue, value) || setValue(_.toPrimitive(watchValue, type));
}), [value]), useEffect(() => {
initialValueLanguage == "javascript" && initialValue ? fn.exec(initialValue, {}, {
getFieldValueForBasicForm: (name2) => pContext ? pContext.getFieldValue(name2) : form.getFieldValue(name2),
getFieldValue: (name2) => form.getFieldValue(name2)
}).then((data2) => setValue(_.toPrimitive(data2, type))).catch((e) => notification.error({ message: `布局数据错误: ${JSON.stringify(e)}` })).finally(() => isMountedRef.current = !0) : (initialValue && setValue(_.toPrimitive(initialValue ?? form.getFieldValue(name), type)), isMountedRef.current = !0);
}, [initialValue, initialValueLanguage]), useDeepEqualEffect(() => {
isMountedRef.current && convertJs && core.getWidgetComponent(convertJs).then(({ default: fn2 }) => fn2({ value, record: form.getFieldsValue(!0), $setting: convertJsSetting })).then(setNewValue).catch((e) => console.error("布局数据转换错误: ", e, convertJs));
}, [value, convertJs, convertJsSetting]), [newValue || value, value];
}, getBoxStyle = (x, y, w, h, boxStyle = {}, height = 0) => {
const style = {
"--grid-layout-h": `${h}`,
"--grid-layout-w": `${w}`,
"--grid-layout-x": `${x}`,
"--grid-layout-y": `${y}`,
"--grid-layout-row-height-offset": "0px"
};
return boxStyle != null && boxStyle.autoHeight ? style.height = "fit-content" : style["--grid-layout-row"] = `${h}`, style["--grid-layout-box-margin"] = getBoxMargin(boxStyle == null ? void 0 : boxStyle.marginTop, boxStyle == null ? void 0 : boxStyle.marginRight, boxStyle == null ? void 0 : boxStyle.marginBottom, boxStyle == null ? void 0 : boxStyle.marginLeft), style["--grid-layout-box-padding"] = getBoxMargin(boxStyle == null ? void 0 : boxStyle.paddingTop, boxStyle == null ? void 0 : boxStyle.paddingRight, boxStyle == null ? void 0 : boxStyle.paddingBottom, boxStyle == null ? void 0 : boxStyle.paddingLeft), height && (style.height = `${height}px`), style;
}, getBoxMargin = (top, right, bottom, left) => `${top || 0}px ${right || 0}px ${bottom || 0}px ${left || 0}px`, GridLayout = ({ cols, rowHeight, fields, data: data2, containerPadding = [0, 0], itemMargin = [4, 0], formProps = {}, className, ...props }) => {
const [form] = Form.useForm(), items = useGridLayoutFields(fields, itemWidgetRender$2, "@pkg/grid-layouts"), formPropsFields = useMemo(() => [
{ name: "__PROPS__", value: formProps }
], [formProps]);
return useDeepEqualEffect(() => {
form.setFieldsValue(data2);
}, [data2]), /* @__PURE__ */ jsx(Form, { fields: formPropsFields, form, component: !1, children: /* @__PURE__ */ jsx(
"div",
{
...props,
className: cx("ff-grid-layout", className),
style: {
"--grid-layout-item-margin-y": `${(itemMargin == null ? void 0 : itemMargin[0]) || 0}px`,
"--grid-layout-item-margin-x": `${(itemMargin == null ? void 0 : itemMargin[1]) || 0}px`,
"--grid-layout-container-padding-y": `${(containerPadding == null ? void 0 : containerPadding[0]) || 0}px`,
"--grid-layout-container-padding-x": `${(containerPadding == null ? void 0 : containerPadding[1]) || 0}px`,
"--grid-layout-cols": cols || 12,
"--grid-layout-row-height": `${rowHeight || 21}px`
},
children: items
}
) });
}, useGridLayoutFields = (fields, itemWidgetRender2, prefix = "@pkg/grid-layouts", basicForm = null) => useMemo(() => {
var _a;
return (_a = _.sortBy(fields, ["y", "x"])) == null ? void 0 : _a.map(
({ i, x, y, w, h, field: { boxStyle, widgetPrefix = prefix, widget, ...field } }, index2) => /* @__PURE__ */ jsx(
"div",
{
className: "grid-layout-item",
style: getBoxStyle(x, y, w, h, boxStyle, widget === "Height" && (field == null ? void 0 : field.initialValue)),
children: /* @__PURE__ */ jsx(
ItemWidget,
{
...field,
basicForm,
itemWidget: widget != null && widget.startsWith("@") ? widget : `${widgetPrefix}/${widget}`,
itemWidgetRender: itemWidgetRender2
}
)
},
i || index2
)
);
}, [fields]), ItemWidget = ({ itemWidget, itemWidgetRender: itemWidgetRender2, basicForm, ...props }) => {
const [children, setChildren] = useState();
return useEffect(() => {
core.getWidgetComponent(itemWidget).then(({ defaultProps, default: ItemWidget2 }) => {
setChildren(React.createElement(itemWidgetRender2(ItemWidget2, defaultProps, basicForm), props));
}).catch((e) => setChildren(itemWidget));
}, [itemWidget]), children;
}, itemWidgetRender$2 = (ItemWidget2, defaultProps, basicForm = null) => (props) => {
const {
code,
label,
extras,
isVirtual,
initialValue,
initialValueLanguage,
convertJs,
convertJsSetting,
...itemWidgetProps
} = _.merge({}, defaultProps, props), [value, rawValue] = useField(isVirtual ? null : code, {
initialValue,
initialValueLanguage,
convertJs,
convertJsSetting,
type: (itemWidgetProps == null ? void 0 : itemWidgetProps.type) || "string"
}, basicForm);
return /* @__PURE__ */ jsx(ItemWidget2, { ...itemWidgetProps, value, rawValue, $setting: extras || {} });
}, GridLayout$1 = GridLayoutHoc(GridLayout), GridLayoutFormWidget = ({ widget, widgetPrefix, widgetDecorator, subWidgets, basicForm, ...props }) => {
const itemWidget = widget != null && widget.startsWith("@") ? widget : `${widgetPrefix}/${widget}`, [ItemWidget2, setItemWidget] = useState();
return useEffect(() => {
itemWidget && core.getWidgetComponent(itemWidget).then(({ defaultProps, default: ItemWidget22 }) => ({
default: itemWidgetRender$1(ItemWidget22, defaultProps, basicForm)
})).catch((e) => ({ default: () => `${e}` })).then((res) => setItemWidget(React.createElement(res.default, props)));
}, [itemWidget]), ItemWidget2 && React.cloneElement(ItemWidget2, props);
};
GridLayoutFormWidget.defaultProps = {
widgetPrefix: "@pkg/grid-layout-forms",
widget: "Input"
};
const itemWidgetRender$1 = (ItemWidget2, defaultProps, basicForm = null) => (props) => {
const {
type,
code,
label,
noStyle,
placeholder,
extras,
validators,
help,
isVirtual,
$isReserved,
initialValue,
initialValueLanguage,
convertJs,
convertJsSetting,
widgetPerfix: _widgetPerfix,
boxStyle: _boxStyle,
widgetDecorator,
subWidgets,
...itemWidgetProps
} = { ...defaultProps, ...props }, rules = useRules(validators || {}, code, type), itemProps = {
label,
noStyle,
colon: !1
}, fieldProps = {
placeholder,
...itemWidgetProps
}, normalize = useCallback((value) => value == null ? void 0 : _.toPrimitive(value, type), [type]);
return /* @__PURE__ */ jsx(
Field,
{
name: code,
rules,
initialValue: normalize(initialValue),
normalize,
children: (control, meta, rcform) => {
var _a;
return /* @__PURE__ */ jsx(
ItemWidget2,
{
type,
rcform,
itemProps: {
validateStatus: meta.errors.length > 0 ? "error" : "success",
tooltip: help,
help: meta.errors.length > 0 ? meta.errors.join("、") : null,
required: ((_a = rules == null ? void 0 : rules[0]) == null ? void 0 : _a.required) || !1,
...itemProps
},
fieldProps: { ...fieldProps, ...control },
$setting: extras || {}
}
);
}
}
);
}, GridLayoutForm = ({ cols, rowHeight, itemMargin, containerPadding, fields, children }) => {
const items = useGridLayoutFields(fields, itemWidgetRender$1, "@pkg/grid-layout-forms");
return /* @__PURE__ */ jsx(ConfigProvider, { theme: { components: { Form: { itemMarginBottom: 0 } } }, children: /* @__PURE__ */ jsxs("div", { className: "ff-grid-layout-form", style: {
"--grid-layout-item-margin-x": `${(itemMargin == null ? void 0 : itemMargin[0]) ?? 8}px`,
"--grid-layout-item-margin-y": `${(itemMargin == null ? void 0 : itemMargin[1]) ?? 16}px`,
"--grid-layout-container-padding-y": `${(containerPadding == null ? void 0 : containerPadding[0]) || 0}px`,
"--grid-layout-container-padding-x": `${(containerPadding == null ? void 0 : containerPadding[1]) || 0}px`,
"--grid-layout-cols": cols || 24,
"--grid-layout-row-height": `${rowHeight || 16}px`
}, children: [
items,
children && React.cloneElement(children, { cols, rowHeight, itemMargin, containerPadding, fields })
] }) });
};
GridLayoutForm.propTypes = {
fields: PropTypes.array.isRequired
};
GridLayoutForm.defaultProps = {
fields: [],
itemMargin: [8, 16],
containerPadding: [0, 0]
};
const GridLayoutForm$1 = GridLayoutFormHoc(GridLayoutForm), FFPageRender = ({ children }) => {
const [ele, setEle] = useState({}), onMount = useCallback((solt, ele2) => setEle((state) => ({ ...state, [solt]: ele2 })), []), onUnmount = useCallback((solt) => setEle((state) => ({ ...state, [solt]: void 0 })), []);
return /* @__PURE__ */ jsx(SlotContext.Provider, { value: { ele, mount: onMount, unmount: onUnmount }, children });
};
FFPageRender.defaultProps = {
isDrawerRender: !1
};
FFPageRender.propTypes = {
isDrawerRender: PropTypes.bool
};
const getWidgetPropsData = (registerProps = {}, data2 = {}, fns2 = {}, defaultValue = "") => _.deepSome(registerProps, (value, key) => key === "type" && value === "code") ? getWidgetPropsDataAsync(registerProps, data2, fns2, defaultValue) : getWidgetPropsDataSync(registerProps, data2, defaultValue), getWidgetPropsDataAsync = async (registerProps = {}, data2 = {}, fns2 = {}, defaultValue = "") => {
let res = /* @__PURE__ */ Object.create(null);
for (let key in registerProps) {
let newValue;
if (Reflect.has(registerProps[key], "type") && ["code", "field", "router", "query", "string"].includes(registerProps[key].type)) {
const { type: fieldType, value: fieldData = "", default: fieldDefault = defaultValue } = registerProps[key];
switch (fieldType) {
case "code":
newValue = await fn.exec(fieldData, data2, fns2);
break;
case "field":
newValue = _.get(data2, fieldData) ?? _.get(data2, fieldData.substring(fieldData.indexOf(".") + 1));
break;
case "router":
case "query":
newValue = route.getPageParams(fieldData);
break;
case "string":
newValue = fieldData;
}
newValue ?? (newValue = fieldDefault);
} else
newValue = await getWidgetPropsDataAsync(registerProps[key], data2, fns2, defaultValue);
_.set(res, key, newValue);
}
return res;
}, getWidgetPropsDataSync = (registerProps = {}, data2 = {}, defaultValue = "") => Object.keys(registerProps || {}).reduce((res, key) => {
if (_.isPlainObject(registerProps[key])) {
let newValue;
if (Reflect.has(registerProps[key], "type") && ["field", "router", "query", "string"].includes(registerProps[key].type)) {
const { type: fieldType, value: fieldData = "", default: fieldDefault = defaultValue } = registerProps[key];
switch (fieldType) {
case "field":
newValue = _.get(data2, fieldData) ?? _.get(data2, fieldData.substring(fieldData.indexOf(".") + 1));
break;
case "router":
case "query":
newValue = route.getPageParams(fieldData);
break;
case "string":
newValue = fieldData;
break;
}
newValue ?? (newValue = fieldDefault);
} else
newValue = getWidgetPropsDataSync(registerProps[key], data2, defaultValue);
_.set(res, key, newValue);
}
return res;
}, {}), DataListFramework = ({
className,
itemClassName,
classNames,
dataSource,
isPaginate,
pageSize,
isItemOperations,
isBatchOperations,
batchOperations,
itemOperations,
itemOperationsAccess,
resource,
primaryKey,
title,
itemGridLayout,
$setting,
tabs,
isTreeSider,
treeSiderConfig
}) => {
const { getBase62params, onClickCallback, onTabChange } = useContext(DataListContext), { total, page, tab } = getBase62params() || {}, itemRender = useCallback((children, data2, index2) => /* @__PURE__ */ jsx(
ItemOperations,
{
className: cx("ff-data-list-framework-item", itemClassName),
operations: isItemOperations && data2 ? itemOperations == null ? void 0 : itemOperations.filter((oper) => !primaryKey || !oper.uuid || !itemOperationsAccess.has(oper.uuid) ? !0 : itemOperationsAccess.get(oper.uuid).includes(data2 == null ? void 0 : data2[primaryKey])) : [],
data: resource ? { [resource]: data2 } : data2,
children,
onClickCallback
}
), [resource, primaryKey, isItemOperations, onClickCallback, itemOperations, itemOperationsAccess]);
return /* @__PURE__ */ jsxs("div", { className: cx("ff-data-list-framework", className), children: [
/* @__PURE__ */ jsx(DataListSider, { className: classNames == null ? void 0 : classNames.sider, isTreeSider, ...treeSiderConfig }),
/* @__PURE__ */ jsxs("div", { className: cx("ff-data-list-container", classNames == null ? void 0 : classNames.container), children: [
/* @__PURE__ */ jsx(DataListFilter, { className: classNames == null ? void 0 : classNames.filter }),
/* @__PURE__ */ jsx(
DataListToolbar,
{
title,
className: classNames == null ? void 0 : classNames.toolbar,
tabs,
tab,
onTabChange
}
),
/* @__PURE__ */ jsx(
DataListContent,
{
...itemGridLayout,
className: classNames == null ? void 0 : classNames.content,
style: { "--col-num": ($setting == null ? void 0 : $setting.colNum) || 1 },
primaryKey,
itemRender,
dataSource
}
),
/* @__PURE__ */ jsx(
DataListFooter,
{
className: classNames == null ? void 0 : classNames.footer,
isPaginate,
isOperations: isBatchOperations,
operations: batchOperations,
total,
page,
pageSize
}
)
] })
] });
}, ItemOperations = ({ className, operations, children, data: data2, onClickCallback }) => /* @__PURE__ */ jsxs("div", { className: cx("data-list-grid-layout-item-container", className), children: [
children,
!!(operations != null && operations.length) && /* @__PURE__ */ jsx("div", { className: "data-list-grid-layout-item-actions", children: operations.map((item) => /* @__PURE__ */ jsx("span", { className: "data-list-grid-layout-item-action", children: /* @__PURE__ */ jsx(
Button.Link,
{
uuid: item.uuid,
type: item.type,
name: item.name,
widget: item.widget,
widgetType: item.widgetType,
widgetProps: item.widgetProps,
widgetSetting: item.widgetSetting,
widgetContainerProps: item.widgetContainerSetting,
data: data2,
onAfterClick: (e) => e !== !1 && (onClickCallback == null ? void 0 : onClickCallback(item.isRefresh, data2))
},
item.uuid || useId()
) }, (item == null ? void 0 : item.uuid) || useId())) })
] }), DataTableFramework = ({
listCode,
className,
itemClassName,
dataSource,
columns,
isItemOperations,
isBatchOperations,
batchOperations,
itemOperations,
itemOperationsAccess,
resource,
primaryKey,
title,
isPaginate,
pageSize,
isTreeSider,
treeSiderConfig,
...props
}) => {
const { getBase62params, onClickCallback } = useContext(DataListContext), { total, page } = getBase62params() || {};
return /* @__PURE__ */ jsxs("div", { className: cx("ff-data-table-framework", className), children: [
/* @__PURE__ */ jsx(DataListSider, { isTreeSider, ...treeSiderConfig }),
/* @__PURE__ */ jsxs("div", { className: "ff-data-table-container", children: [
/* @__PURE__ */ jsx(DataListFilter, { listCode }),
/* @__PURE__ */ jsx(DataListToolbar, { title }),
/* @__PURE__ */ jsx(
DataListTable,
{
...props,
className: "ff-data-table-content",
columns,
dataSource,
operationRender: (record) => /* @__PURE__ */ jsx("div", { className: "ff-data-table-actions", children: itemOperations == null ? void 0 : itemOperations.reduce((carry, item, i) => [
...carry,
/* @__PURE__ */ jsx(
Button.Link,
{
size: "small",
uuid: item.uuid,
type: item.type,
name: item.name,
widget: item.widget,
widgetType: item.widgetType,
widgetProps: item.widgetProps,
widgetSetting: item.widgetSetting,
widgetContainerProps: item.widgetContainerSetting,
data: record,
onAfterClick: (e) => e !== !1 && (onClickCallback == null ? void 0 : onClickCallback(item.isRefresh, data))
},
item.uuid || i
)
], []) })
}
),
/* @__PURE__ */ jsx(
DataListFooter,
{
isPaginate,
isOperations: isBatchOperations,
operations: batchOperations,
total,
page,
pageSize
}
)
] })
] });
}, DataListContext = React.createContext({
listCode: "",
getBase62params: (k, defaultValue) => {
},
onReload: () => {
},
onClickCallback: () => {
},
onConditonChange: () => {
},
onTabChange: () => {
},
onSiderChange: () => {
},
onKeywordChange: () => {
},
onPageChange: () => {
},
onPageSizeChange: () => {
}
}), DataList$1 = ({
isItemGridLayout,
theme,
themeProps,
onClickCallback,
onReload,
getBase62params,
listCode,
onPageChange,
onPageSizeChange,
onTabChange,
onSiderChange,
onKeywordChange,
onConditonChange,
...props
}) => {
const [framework, setFramework] = useState();
return useEffect(() => {
theme ? core.getWidgetComponent(theme).then((resp) => {
if (!resp)
throw `${theme} not found`;
return resp;
}).catch((e) => ({ default: () => `${e}` })).then((resp) => setFramework(React.createElement(resp.default, { ...props, $setting: themeProps }))) : framework || setFramework(null);
}, [theme, themeProps]), /* @__PURE__ */ jsx(DataListContext.Provider, { value: {
listCode,
onClickCallback,
onReload,
getBase62params,
onPageChange,
onPageSizeChange,
onTabChange,
onSiderChange,
onKeywordChange,
onConditonChange
}, children: framework ? React.cloneElement(framework, { ...props, $setting: themeProps }) : isItemGridLayout ? /* @__PURE__ */ jsx(DataListFramework, { ...props, $setting: themeProps }) : /* @__PURE__ */ jsx(DataTableFramework, { ...props, $setting: themeProps }) });
};
DataList$1.defaultProps = {
onReload: () => {
},
getBase62params: () => {
}
};
const loadDataListFieldWidget = (widget, value, record, widgetSetting, base62params) => {
const Widget = React.lazy(() => core.getWidgetComponent(widget).catch((e) => ({ default: () => `${e}` })));
return /* @__PURE__ */ jsx(React.Suspense, { children: /* @__PURE__ */ jsx(
Widget,
{
value,
record,
$setting: widgetSetting,
base62params
}
) }, widget);
}, useColumnsRender = (columns, base62params = {}) => (usePrevious(columns), usePrevious(base62params), useMemo(() => columns == null ? void 0 : columns.map(({ widgetByJs, widgetByJsSetting, ...item }, i) => widgetByJs && !widgetByJs.endsWith("/BasicShowFieldData") ? {
...item,
render: (value, record) => {
const widgetByJsRender = loadDataListFieldWidget(widgetByJs, value, record, widgetByJsSetting, base62params);
return _.isFunction(item == null ? void 0 : item.render) ? item.render(widgetByJsRender, value, record) : widgetByJsRender;
}
} : item), [columns, base62params])), useStructure = (listCode) => {
const [option, setOption] = useState({});
return useEffect(() => {
let flag = !1;
return listCode && http.get(`/api/_/${listCode}`).then((data2) => _.pick(data2, [
"uuid",
"name",
"code",
"resource",
"marginX",
"marginY",
"cols",
"rowHeight",
"primaryKey",
"columns",
"itemOperations",
"batchOperations",
"isConditionFormLayout",
"layout",
"tabs",
"pageSize",
"layoutConfig"
])).then((data2) => !flag && setOption(data2)), () => flag = !0;
}, [listCode]), option;
}, useDataSource = (listCode, base62params = {}) => {
const [option, setOption] = useState({ dataSource: [] });
return useDeepEqualEffect(() => {
let flag = !1;
return listCode && http.get(`/api/${listCode}/${http.encode({ page: 1, ...base62params })}`).then((data2) => !flag && setOption(data2)), () => flag = !0;
}, [listCode, base62params]), option;
}, useHasOperationColumn = (operations, dataSource = null, itemOperationsAccess = null, pk = "id") => useMemo(() => {
if (_.isEmpty(operations) || !operations.every(({ uuid }) => auth.check(uuid)))
return !1;
if (_.isEmpty(itemOperationsAccess) || _.isEmpty(dataSource))
return !0;
const ids = dataSource.map((item) => item == null ? void 0 : item[pk]);
return operations.some(({ uuid }) => !uuid || !itemOperationsAccess.has(uuid) ? !0 : itemOperationsAccess.get(uuid).some((oper) => ids.includes(oper)));
}, [operations, dataSource, itemOperationsAccess, pk]), DataListHelper = React.forwardRef(({ listCode, base62params, className, itemClassName, theme: _theme, themeProps, classNames }, ref) => {
const [{ tab, page, total, condition, sider, keyword, dataSource, itemOperationsAccess, pageSize }, setData] = useStateWithCallback(base62params), [{
resource,
primaryKey,
batchOperations = [],
itemOperations = [],
columns = [],
themeConfig,
theme,
isTreeSider,
treeSiderConfig,
isItemGridLayout,
itemGridLayout,
title,
isPaginate,
tabs
}, setStructure] = useState({ isItemGridLayout: !1, itemGridLayout: {} }), initData = (params) => http.list(listCode, { tab, page, total, condition, sider, keyword, ...params }).then(({
condition: condition2,
total: total2,
tab: tab2,
page: page2,
pageSize: pageSize2,
operationsAccess,
dataSource: dataSource2
}) => {
setData({
dataSource: dataSource2,
pageSize: pageSize2,
total: total2,
page: page2,
tab: tab2,
condition: condition2,
sider,
keyword,
itemOperationsAccess: new Map(operationsAccess)
});
}), isItemOperations = useHasOperationColumn(itemOperations, dataSource, itemOperationsAccess, primaryKey), isBatchOperations = useHasOperationColumn(batchOperations);
useEffect(() => {
let unsubscribe = null;
return listCode && http.get(`/api/_/${listCode}`).resp(({ data: data2, res }) => {
data2 != null && data2.isDynamicRefresh && (unsubscribe = ResWs$1.subscribe(() => initData(), res)), setStructure(data2);
}).catch(() => setStructure({})), setData((data2) => ({ ...data2, dataSource: [] })), () => unsubscribe == null ? void 0 : unsubscribe();
}, [listCode]), useEffect(() => {
listCode && initData(base62params);
}, [JSON.stringify(base62params)]);
const onConditonChange = (value, keyword2) => initData({ keyword: keyword2, condition: update(condition || {}, { $merge: value || {} }), page: 1 }), onTabChange = (tab2) => initData({ tab: tab2, page: 1 }), onSiderChange = (sider2) => initData({ sider: sider2, page: 1 }), onKeywordChange = (keyword2) => initData({ keyword: keyword2, page: 1 }), onPageChange = (page2, pageSize2) => initData({ page: page2, pageSize: pageSize2 }), onPageSizeChange = (pageSize2) => initData({ pageSize: pageSize2, page: 1 }), getBase62params = (k, defaultValue, isInit = !1) => {
if (k == "init")
return base62params;
const params = { tab, sider, keyword, page, pageSize, condition, total };
return k ? _.get(params, k, defaultValue) : params;
}, onReload = () => {
initData();
}, onClickCallback = (isRefresh = 0, item = null) => {
if (isRefresh === 2) {
const parentPk = _.get(item, "__PARENT_ID__", ""), pk = _.get(item, primaryKey, _.get(item, [resource, primaryKey], "")), pIndex = _.findIndex(dataSource, ["__PARENT_ID__", parentPk]), index2 = _.findIndex(pIndex > -1 ? _.get(dataSource, [pIndex, "children"]) : dataSource, [primaryKey, pk]);
index2 > -1 ? (http.get(`/api/${listCode}/detail/${pk}`).then((resp) => {
setData((data2) => {
const children = _.get(data2.dataSource, pIndex > -1 ? [pIndex, "children", index2, "children"] : [index2, "children"]);
return {
...data2,
dataSource: pIndex > -1 ? update(data2.dataSource, { [pIndex]: { children: { $splice: [[index2, 1, { ...resp, children }]] } } }) : update(data2.dataSource, { $splice: [[index2, 1, { ...resp, children }]] })
};
});
}), http.post(`/api/${listCode}/list-operations-access`, { ids: pk }).then((data2) => new Map(data2)).then((detailAccess) => {
setData((data2) => (data2.itemOperationsAccess.forEach((ids, uuid) => {
var _a;
(_a = detailAccess.get(uuid)) != null && _a.some((item2) => item2 == pk) || data2.itemOperationsAccess.set(uuid, ids.filter((id) => id !== pk));
}), detailAccess.forEach((ids, uuid) => {
data2.itemOperationsAccess.has(uuid) ? data2.itemOperationsAccess.set(uuid, _.uniq([...data2.itemOperationsAccess.get(uuid) || [], ...ids])) : data2.itemOperationsAccess.set(uuid, ids);
}), { ...data2 }));
})) : onReload();
} else
isRefresh === 1 && onReload();
};
return React.useImperativeHandle(ref, () => ({
onReload,
onClickCallback
})), /* @__PURE__ */ jsx(
DataList$1,
{
...{
listCode,
title,
itemClassName,
classNames,
resource,
primaryKey,
theme: _theme || theme,
themeProps: themeProps || themeConfig,
isPaginate,
pageSize,
page,
isTreeSider,
treeSiderConfig,
tabs,
isItemOperations,
isBatchOperations,
batchOperations,
itemOperations,
itemOperationsAccess,
dataSource,
isItemGridLayout,
columns,
itemGridLayout
},
className: cx("ff-data-list-helper", className),
getBase62params,
onReload,
onClickCallback,
onConditonChange,
onTabChange,
onSiderChange,
onKeywordChange,
onPageChange,
onPageSizeChange
}
);
}), DataListFilter = ({ className }) => {
var _a, _b;
const [structure, setStructure] = useState({}), { listCode, onKeywordChange, onConditonChange, getBase62params } = React.useContext(DataListContext), { keyword, condition } = getBase62params() || {}, [form] = Form$1.useForm();
useEffect(() => {
http.get(`/api/_/${listCode}/list-condition-form-layout`).then(({ resource, marginX, marginY, rowHeight, cols, fields }) => {
setStructure({ resource, itemMargin: [marginX, marginY], rowHeight, cols, fields });
}).catch(() => setStructure({}));
}, [listCode]), useEffect(() => {
form.setFieldsValue({ keyword, ...condition });
}, [JSON.stringify([keyword, condition])]);
const onReset = () => {
const { keyword: keyword2, condition: condition2 } = getBase62params("init") || {};
form.setFieldsValue({ keyword: keyword2, ...condition2 });
}, onSubmit = (value) => onConditonChange(value[structure == null ? void 0 : structure.resource], value.keyword), onKeywordSearch = (value) => onKeywordChange(value);
return /* @__PURE__ */ jsx("div", { className: cx("ff-data-list-filter", className), children: /* @__PURE__ */ jsx(
Form$1,
{
form,
layout: "vertical",
autoComplete: "off",
onFinish: ((_a = structure.fields) == null ? void 0 : _a.length) > 1 ? onSubmit : () => {
},
children: ((_b = structure.fields) == null ? void 0 : _b.length) > 1 ? /* @__PURE__ */ jsx(GridLayoutForm, { ...structure, children: /* @__PURE__ */ jsx(DataListFilterAction, { onReset }) }) : /* @__PURE__ */ jsx("div", { className: "ff-data-list-filter-default-form ff-grid-layout-form", children: /* @__PURE__ */ jsx("div", { className: "grid-layout-item", style: getBoxStyle(20, 0, 5, 2), children: /* @__PURE__ */ jsx(Form$1.Item, { name: ["keyword"], children: /* @__PURE__ */ jsx(Input.Search, { allowClear: !0, enterButton: "搜索", placeholder: "多关键字 | 分割", onSearch: onKeywordSearch }) }) }) })
}
) });
}, DataListFilterAction = ({ cols, fields, onReset }) => {
const [expanded, setExpanded] = useState(!1), isMore = useMemo(() => fields == null ? void 0 : fields.toReversed().some((item) => item.y > 1 || item.x + item.w >= cols - 5), [cols, fields]);
return /* @__PURE__ */ jsxs(Form$1.Item, { label: " ", style: { "--item-span": 5 }, className: cx("ff-data-list-filter-actions", { expanded }), children: [
/* @__PURE__ */ jsx(Button$1, { onClick: onReset, children: "重置" }),
/* @__PURE__ */ jsx(Button$1, { type: "primary", htmlType: "submit", children: "查询" }),
isMore && /* @__PURE__ */ jsx(
Button.Link,
{
className: "ff-data-list-filter-expanded-button",
widget: () => setExpanded((flag) => !flag),
type: "primary",
name: expanded ? "关闭" : "展开",
icon: expanded ? "icon-up" : "icon-down",
iconPosition: "end"
}
)
] });
};
DataListFilter.reservedFields = [
{
x: 0,
y: 0,
h: 3,
w: 5,
field: {
isVirtual: !0,
widgetPrefix: "@pkg/grid-layout-forms",
widget: "Input",
code: "keyword",
label: "关键字",
placeholder: "多关键字 | 分割",
extras: { prefix: "icon-search" }
}
}
];
const DataListToolbar = ({ className, title, tabs, tab, onTabChange }) => {
const [tabValue, setTabValue] = usePropsValue({ value: tab, defaultValue: tabs == null ? void 0 : tabs[0].value, onChange: onTabChange });
return /* @__PURE__ */ jsxs("div", { className: cx("ff-data-list-toolbar", className), children: [
/* @__PURE__ */ jsx("div", { className: "ff-data-list-title", children: title }),
/* @__PURE__ */ jsx(
Breadcrumb,
{
className: "ff-data-list-tabs",
itemRender: ({ label, code: value }) => /* @__PURE__ */ jsx("span", { onClick: () => setTabValue(value), className: cx("ff-data-list-tab", { active: value == tabValue }), children: label }),
items: tabs
}
),
/* @__PURE__ */ jsxs("div", { className: "ff-data-list-actions", children: [
/* @__PURE__ */ jsx(Button.Link, { icon: "icon-reload" }),
/* @__PURE__ */ jsx(Button.Link, { icon: "icon-setting" })
] })
] });
}, treeData = [
{
title: "parent 1",
key: "0-0",
children: [
{
title: "parent 1-0",
key: "0-0-0",
disabled: !0,
children: [
{
title: "leaf",
key: "0-0-0-0",
disableCheckbox: !0
},
{
title: "leaf",
key: "0-0-0-1"
}
]
},
{
title: "parent 1-1",
key: "0-0-1",
children: [
{
title: /* @__PURE__ */ jsx(
"span",
{
style: {
color: "#1677ff"
},
children: "sss"
}
),
key: "0-0-1-0"
}
]
}
]
}
], DataListSider = ({ className, width, isTreeSider }) => isTreeSider ? /* @__PURE__ */ jsx(
Tree.DirectoryTree,
{
className: cx("ff-data-list-sider", className),
style: { "--sider-width": width },
showLine: !0,
showIcon: !1,
treeData
}
) : null;
DataListSider.defaultProps = {
width: 280
};
const DataListFooter = ({ className, operations, isOperations, isPaginate, total, page, pageSize }) => {
const { onPageChange, onPageSizeChange, onClickCallback } = React.useContext(DataListContext);
return isOperations && !_.isEmpty(operations) || isPaginate ? /* @__PURE__ */ jsxs("div", { className: cx("ff-data-list-footer", className), children: [
/* @__PURE__ */ jsx("div", { className: "ff-data-list-actions", children: operations == null ? void 0 : operations.map((item, i) => /* @__PURE__ */ jsx(
Button,
{
uuid: item.uuid,
type: item.type,
name: item.name,
widget: item.widget,
widgetType: item.widgetType,
widgetProps: item.widgetProps,
widgetSetting: item.widgetSetting,
widgetContainerProps: item.widgetContainerSetting,
onAfterClick: (e) => e !== !1 && (onClickCallback == null ? void 0 : onClickCallback(item.isRefresh, null))
},
item.uuid || i
)) }),
isPaginate && /* @__PURE__ */ jsx(
Pagination,
{
size: "small",
total,
pageSize,
showSizeChanger: !1,
showTotal: (total2) => `${page} 页 / 总共 ${total2}`,
onChange: onPageChange,
onShowSizeChange: onPageSizeChange
}
)
] }) : null;
}, getDefaultExpandRowKeys = (data2, key, depth = !0) => depth !== !0 && depth-- <= 0 ? [] : _.isArray(data2) && !_.isEmpty(data2) ? data2.reduce((res, item) => (Reflect.has(item, key) && Reflect.has(item, "children") && res.push(item[key]), Reflect.has(item, "children") && !_.isEmpty(item.children) ? res.concat(getDefaultExpandRowKeys(item.children, key, depth)) : res), []) : [], DataListTable = ({
className,
primaryKey,
columns,
dataSource,
operationRender,
operationWidth,
...props
}) => {
const tableRef = useRef(null), divRef = useRef(null), [expandedRowKeys, setExpandedRowKeys] = useState([]), [divSize, setDivSize] = useState({ width: 0, height: 0 });
useEffect(() => {
setExpandedRowKeys(getDefaultExpandRowKeys(dataSource, primaryKey));
}, [dataSource, primaryKey]), useLayoutEffect(() => {
const resizeObserver = new ResizeObserver(() => {
var _a;
setDivSize({
width: ((_a = tableRef.current) == null ? void 0 : _a.nativeElement.querySelector(".ant-table-body").scrollWidth) || divRef.current.offsetWidth,
height: divRef.current.offsetHeight
});
});
return divRef.current && resizeObserver.observe(divRef.current), () => {
divRef.current && resizeObserver.unobserve(divRef.current);
};
}, []);
const newColumns = useColumnsRender(columns);
return /* @__PURE__ */ jsx("div", { ref: divRef, className: cx("ff-data-list-table", className), children: divSize.height ? /* @__PURE__ */ jsx(
Table,
{
...props,
ref: tableRef,
rowKey: (v, index2) => (v == null ? void 0 : v[primaryKey]) ?? index2,
columns: newColumns == null ? void 0 : newColumns.concat(operationRender ? [{
title: "操作",
align: "center",
fixed: "right",
width: `${Math.ceil(operationWidth / divSize.width * 100).toFixed(2)}%`,
render: (_text, record, index2) => operationRender(record, index2)
}] : []),
dataSource,
size: "middle",
scroll: { x: "max-content", y: divSize.height - 47 },
pagination: !1,
expandable: {
defaultExpandAllRows: !0,
expandRowByClick: !0,
onExpandedRowsChange: setExpandedRowKeys,
expandedRowKeys
}
}
) : null });
};
DataListTable.defaultProps = {
operationWidth: 180,
columns: [],
dataSource: []
};
const GridLayoutWidget = ({ widget, widgetPrefix, basicForm, ...props }) => {
const itemWidget = widget != null && widget.startsWith("@") ? widget : `${widgetPrefix}/${widget}`, [ItemWidget2, setItemWidget] = useState();
return useEffect(() => {
itemWidget && core.getWidgetComponent(itemWidget).then(({ defaultProps, default: ItemWidget22 }) => ({
default: itemWidgetRender(ItemWidget22, defaultProps, basicForm)
})).catch((e) => ({ default: () => `${e}` })).then((res) => setItemWidget(React.createElement(res.default, props)));
}, [itemWidget]), ItemWidget2;
}, itemWidgetRender = (ItemWidget2, defaultProps, basicForm = null) => (props) => {
const {
code,
label,
extras,
isVirtual,
initialValue,
initialValueLanguage,
convertJs,
convertJsSetting,
value: _value,
...itemWidgetProps
} = _.merge({}, defaultProps, props), [value, rawValue] = useField(isVirtual ? null : code, {
initialValue,
initialValueLanguage,
convertJs,
convertJsSetting,
type: (itemWidgetProps == null ? void 0 : itemWidgetProps.type) || "string"
}, basicForm);
return /* @__PURE__ */ jsx(ItemWidget2, { ...itemWidgetProps, value, rawValue, $setting: extras || {} });
};
GridLayoutWidget.defaultProps = {
widgetPrefix: "@pkg/grid-layouts"
};
const DataListContent = ({
cols,
rowHeight,
itemMargin,
fields,
primaryKey,
itemRender,
dataSource,
itemClassName,
empty,
className,
style
}) => {
const id = useId$1(), GridLayoutElement = useMemo(() => /* @__PURE__ */ jsx(
GridLayout,
{
cols,
rowHeight,
itemMargin,
fields,
className: itemClassName
}
), [fields, cols, rowHeight, itemMargin]);
return /* @__PURE__ */ jsx("div", { className: cx("ff-data-list-content", className), style, children: _.isEmpty(dataSource) ? empty : dataSource == null ? void 0 : dataSource.map((item, i) => /* @__PURE__ */ jsx(React.Fragment, { children: itemRender(React.cloneElement(GridLayoutElement, { data: item }), item, i) }, `${id}-${(item == null ? void 0 : item[primaryKey]) || i}`)) });
};
DataListContent.defaultProps = {
itemRender: (children, data2, index2) => children,
empty: /* @__PURE__ */ jsx(Empty$1, { description: null }),
style: {}
};
const redirect = (params, widget, { isReplaceRouteHistory = !1 } = {}) => route.redirect(widget, params, { replace: isReplaceRouteHistory }), func = (params, widget, { status: { loading, disabled }, setStatus }) => {
const extras = {
loading: (flag) => flag === void 0 ? loading : setStatus((data2) => ({ ...data2, loading: flag })),
disabled: (flag) => flag === void 0 ? disabled : setStatus((data2) => ({ ...data2, disabled: flag }))
};
return _.isFunction(widget) ? widget.call(null, { ...params, ...extras }) : _.isString(widget) && widget ? fn.exec(widget, params, extras) : null;
}, component = (data2, widget, widgetSetting, widgetContainerProps) => _.isString(widget) && widget ? core.getWidgetComponent(widget).then(({ default: WidgetComponent }) => FFPopupRender.modal(
WidgetComponent,
{ ...data2, $setting: widgetSetting },
widgetContainerProps
)).catch((e) => {
FFPopupRender.error(widget, { content: e.toString() });
}) : FFPopupRender.modal(
widget,
{ ...data2, $setting: widgetSetting },
widgetContainerProps
), gridLayoutForm = (data2, widget, widgetSetting, widgetContainerProps) => FFPopupRender.modal(
GridLayoutFormHelper,
{ ...data2, $setting: widgetSetting, code: widget },
widgetContainerProps
), list = (data2, widget, widgetSetting, widgetContainerProps) => FFPopupRender.modal(
DataListHelper,
{ base62params: data2, $setting: widgetSetting, listCode: widget },
widgetContainerProps
), useButton = ({
widget,
widgetType,
widgetData,
widgetProps,
widgetSetting,
widgetContainerProps
}, { onAfterClick, onBeforeClick }) => {
const listFn = useContext(DataListContext);
useContext(AppGlobalParamsContext);
const [status, setStatus] = useState({ leading: !0, trailing: !1 }), fn2 = useMemo(() => {
switch (widgetType) {
case "redirect":
return _.partialRight(redirect, widget, widgetSetting);
case "func":
return _.partialRight(func, (widgetSetting == null ? void 0 : widgetSetting.code) ?? widget, { status, setStatus });
case "fsdpf-component":
return _.partialRight(component, widget, widgetSetting, widgetContainerProps);
case "grid-layout-form":
return _.partialRight(gridLayoutForm, widget, widgetSetting, widgetContainerProps);
case "data-list":
return _.partialRight(list, widget, widgetSetting, widgetContainerProps);
default:
if (isReactComponent(widget) || React.isValidElement(widget))
return _.partialRight(component, widget, widgetSetting, widgetContainerProps);
if (_.isFunction(widget))
return _.partialRight(func, (widgetSetting == null ? void 0 : widgetSetting.code) || widget, { status, setStatus });
}
return (...args) => console.error("useButton unknown widgetType", widgetType, ...args);
}, [widget, widgetType]);
return [_.debounce((data2) => (onBeforeClick == null || onBeforeClick(data2), Promise.resolve(getWidgetPropsData(widgetProps, data2, { list: listFn })).then((data22) => fn2({ ...widgetData, ...data22 })).then((result) => onAfterClick == null ? void 0 : onAfterClick(result)).catch(console.error)), 300, { leading: !0, trailing: !1 }), status];
};
var _instance2, _data;
const _OperationAuth = class _OperationAuth {
constructor() {
__privateAdd(this, _data, null);
__publicField(this, "init", (data2) => __privateSet(this, _data, new Map(data2)));
__publicField(this, "check", (uuid) => !__privateGet(this, _data).has(uuid) || __privateGet(this, _data).get(uuid));
if (__privateGet(_OperationAuth, _instance2))
return __privateGet(_OperationAuth, _instance2);
}
};
_instance2 = new WeakMap(), _data = new WeakMap(), __privateAdd(_OperationAuth, _instance2, null), __publicField(_OperationAuth, "getInstance", () => (__privateGet(_OperationAuth, _instance2) || __privateSet(_OperationAuth, _instance2, new _OperationAuth()), __privateGet(_OperationAuth, _instance2)));
let OperationAuth = _OperationAuth;
const auth = OperationAuth.getInstance(), entry = (cate) => function({
className,
children,
name,
icon,
type,
data: data2,
noAuthType,
onAfterClick,
onBeforeClick,
loading: customLoading,
disabled: customDisabled,
tooltip,
popConfirm,
widget,
widgetType,
widgetData,
widgetProps,
widgetSetting,
widgetContainerProps,
...props
}) {
const btnProps = {
type: "primary",
className: cx("ff-button", className)
};
type === "danger" ? btnProps.danger = !0 : type === "default" && (btnProps.type = type), cate === "link" || cate === "dashed" ? (btnProps.type = cate, type === "default" && (btnProps.className = cx(btnProps.className, "ff-default"))) : (cate === "circle" || cate === "round") && (btnProps.shape = cate), icon && (btnProps.icon = /* @__PURE__ */ jsx(Iconfont, { type: icon }));
const [confirmOpen, setConfirmOpen] = useState(!1), [onClick, { disabled, loading }] = useButton({ widget, widgetType, widgetData, widgetProps, widgetSetting, widgetContainerProps }, { onAfterClick, onBeforeClick });
return /* @__PURE__ */ jsx(
Popconfirm,
{
okText: "确定",
cancelText: "取消",
...popConfirm || {},
disabled: disabled || customDisabled,
open: confirmOpen,
onOpenChange: (flag) => {
if (!flag)
return setConfirmOpen(flag);
popConfirm ? setConfirmOpen(flag) : onClick(data2);
},
onConfirm: () => {
onClick(data2);
},
onClick: (e) => {
e.stopPropagation();
},
children: /* @__PURE__ */ jsx(Tooltip, { ...tooltip, title: confirmOpen ? null : tooltip == null ? void 0 : tooltip.title, trigger: ["hover", "click"], children: /* @__PURE__ */ jsx(
Button$1,
{
loading: loading || customLoading,
disabled: disabled || customDisabled,
...btnProps,
...props,
children: children || name
}
) })
}
);
}, Button = entry("default"), Link = entry("link"), Circle = entry("circle"), Round = entry("round"), Dashed = entry("dashed"), Popover = ({ data: data2, widget, widgetType, children, widgetData, widgetProps, widgetSetting, widgetContainerProps }) => {
const listFn = useContext(DataListContext), [open, setOpen] = useState(!1), [trigger, setTrigger] = useState("hover"), [componentData, setComponentData] = useState({}), [component2, setComponent] = useState();
useEffect(() => {
widgetType == "grid-layout-form" ? setComponent(React.createElement(GridLayoutFormHelper, { ...widgetData, $setting: widgetSetting, code: widget })) : widgetType == "data-list" ? setComponent(React.createElement(DataListHelper, { base62params: data2, $setting: widgetSetting, listCode: widget })) : _.isString(widget) ? core.getWidgetComponent(widget).then(({ default: WidgetComponent }) => {
setComponent(React.createElement(WidgetComponent, { ...widgetData, $setting: widgetSetting }));
}).catch((e) => setComponent(e.toString())) : isReactComponent(widget) ? setComponent(React.createElement(widget, { ...widgetData, $setting: widgetSetting })) : React.isValidElement(widget) && setComponent(React.cloneElement(widget, { ...widgetData, $setting: widgetSetting }));
}, [widget, widgetType, widgetData]), useEffect(() => {
Promise.resolve(getWidgetPropsData(widgetProps, data2, { list: listFn })).then(setComponentData);
}, [widgetProps, data2]);
const onOpenChange = (flag) => {
setOpen(flag), !flag && setTrigger("hover");
}, onClick = () => {
setOpen(!0), setTrigger("click");
};
return /* @__PURE__ */ jsx(
Popover$1,
{
zIndex: 1e3,
...widgetContainerProps,
onPopupClick: onClick,
onClick,
open,
trigger,
content: /* @__PURE__ */ jsx(PopoverContent, { children: component2 && React.cloneElement(component2, { ...componentData, $close: () => onOpenChange(!1) }) }),
children,
onOpenChange,
overlayClassName: "ff-popup ff-popover"
}
);
}, PopoverContent = ({ children }) => {
const [ele, setEle] = useState({}), onMount = useCallback((solt, ele2) => setEle((state) => ({ ...state, [solt]: ele2 })), []), onUnmount = useCallback((solt) => setEle((state) => ({ ...state, [solt]: void 0 })), []);
return /* @__PURE__ */ jsxs(SlotContext.Provider, { value: { ele, mount: onMount, unmount: onUnmount }, children: [
ele != null && ele.title || ele != null && ele["sub-title"] ? /* @__PURE__ */ jsxs("div", { className: "ff-popup-header", children: [
(ele == null ? void 0 : ele.title) || /* @__PURE__ */ jsx("div", { className: "ff-popup-title" }),
(ele == null ? void 0 : ele["sub-title"]) || /* @__PURE__ */ jsx("div", { className: "ff-popup-sub-title" })
] }) : null,
children,
ele != null && ele.extras || ele != null && ele.actions ? /* @__PURE__ */ jsxs("div", { className: "ff-popup-footer", children: [
(ele == null ? void 0 : ele.extras) || /* @__PURE__ */ jsx("div", { className: "ff-popup-extras" }),
(ele == null ? void 0 : ele.actions) || /* @__PURE__ */ jsx("div", { className: "ff-popup-actions" })
] }) : null
] });
};
Popover.defaultProps = {
widgetType: "fsdpf-component"
};
Popover.propTypes = {
widgetType: PropTypes.oneOf(["fsdpf-component", "grid-layout-form", "data-list"])
};
Button.defaultProps = {
type: "default",
iconPosition: "start"
};
Button.propTypes = {
type: PropTypes.oneOf(["primary", "default", "danger", ""]),
name: PropTypes.string,
// 按钮名称
icon: PropTypes.string,
// 图标
iconPosition: PropTypes.oneOf(["start", "end"]),
// 图标位置
data: PropTypes.any,
// onClick 数据源, 会受到 widgetProps 数据结构影响
widget: PropTypes.any,
// 组件
widgetType: PropTypes.oneOf(["destroy", "redirect", "func", "fsdpf-component", "grid-layout-form", "grid-layout", "data-list"]),
// 组件类型
widgetData: PropTypes.object,
// onClick缺省数据
widgetProps: PropTypes.object,
// data 数据结构
widgetSetting: PropTypes.object,
// $setting
widgetContainerProps: PropTypes.object
// 容器配置
};
Button.Link = Link;
Button.Link.defaultProps = Button.defaultProps;
Button.Link.propTypes = Button.propTypes;
Button.Circle = Circle;
Button.Circle.defaultProps = Button.defaultProps;
Button.Circle.propTypes = Button.propTypes;
Button.Round = Round;
Button.Round.defaultProps = Button.defaultProps;
Button.Round.propTypes = Button.propTypes;
Button.Dashed = Dashed;
Button.Dashed.defaultProps = Button.defaultProps;
Button.Dashed.propTypes = Button.propTypes;
Button.Popover = Popover;
const GridLayoutFormHelper = ({ $setting, $close, extras, code, primaryKey, ...props }) => {
const [form] = Form$1.useForm(), data2 = useFormData(code, primaryKey, $setting);
useEffect(() => {
data2 && form.setFieldsValue(data2);
}, [data2]);
const onSubmit = () => {
const key = form.getFieldValue("__RESOURCE__"), {
initDataUri = `/api/${code}`
} = $setting || {};
form.validateFields(!0).then((data22) => key ? _.pick(data22, [key]) : data22).then((data22) => http.post(primaryKey ? `${initDataUri}/${primaryKey}` : `${initDataUri}`, data22).msg($close)).catch(() => FFPopupRender.error("请先完善表单信息", { duration: 2e3 }));
};
return /* @__PURE__ */ jsx(
FFContainer,
{
actions: /* @__PURE__ */ jsxs(React.Fragment, { children: [
/* @__PURE__ */ jsx(Button, { name: "保存", type: "primary", widget: onSubmit }),
/* @__PURE__ */ jsx(Button, { name: "取消", widget: () => $close(!1) })
] }),
extras,
children: /* @__PURE__ */ jsx(GridLayoutForm$1, { form, code, primaryKey, ...props })
}
);
}, getOptionItemByValue = (items, value, depthKey = "children") => {
if (_.isEmpty(items))
return {};
const item = _.find(items, ["value", value]);
if (!_.isEmpty(item))
return item;
const len = items.length;
for (let i = 0; i < len; i++) {
const { [depthKey]: children } = items[i], result = getOptionItemByValue(children, value, depthKey);
if (!_.isEmpty(result))
return result;
}
return {};
}, FormModalContainer = ({ fields, formProps, $close }) => {
const [form] = Form$1.useForm(), onSubmit = () => form.validateFields(!0).then($close), formPropsFields = useMemo(() => [
{ name: "__PROPS__", value: formProps }
], [formProps]);
return /* @__PURE__ */ jsx(FFContainer, { actions: /* @__PURE__ */ jsxs(React.Fragment, { children: [
/* @__PURE__ */ jsx(Button, { name: "取消", widget: () => $close(!1) }),
/* @__PURE__ */ jsx(Button, { name: "确定", type: "primary", widget: () => onSubmit() })
] }), children: /* @__PURE__ */ jsx(ConfigProvider, { theme: { components: { Form: { itemMarginBottom: 6 } } }, children: /* @__PURE__ */ jsx(Form$1, { fields: formPropsFields, layout: "vertical", form, children: fields == null ? void 0 : fields.map(({ code, ...props }) => /* @__PURE__ */ jsx(GridLayoutFormWidget, { code, ...props }, code)) }) }) });
};
var _pending, _index, _renders, _onNotificationClick, _onConfirmClick, _onModalClick, _onFormClick, _onModalClose;
const _FFPopupRender = class _FFPopupRender extends React.Component {
constructor(props) {
super(props);
__privateAdd(this, _pending, null);
__privateAdd(this, _index, 0);
__privateAdd(this, _renders, /* @__PURE__ */ new Map());
__privateAdd(this, _onNotificationClick, (opts) => new Promise((resolve) => {
const index2 = __privateWrapper(this, _index)._++;
__privateGet(this, _renders).set(index2, React.createElement(Notification, {
...opts,
key: index2,
$close: (flag) => __privateGet(this, _onModalClose).call(this, index2, () => resolve(flag))
})), this.forceUpdate();
}));
__privateAdd(this, _onConfirmClick, (content, opts) => new Promise((resolve) => {
const index2 = __privateWrapper(this, _index)._++;
__privateGet(this, _renders).set(index2, React.createElement(Confirm, {
...opts,
content,
key: index2,
$close: (flag) => __privateGet(this, _onModalClose).call(this, index2, () => resolve(flag))
})), this.forceUpdate();
}));
__privateAdd(this, _onModalClick, (widget, widgetProps, { mode, ...widgetContainerProps } = {}) => new Promise((resolve) => {
const index2 = __privateWrapper(this, _index)._++, ref = { current: null };
__privateGet(this, _renders).set(index2, React.createElement(
mode == "drawer" ? Drawer : Modal,
{
ref,
key: index2,
maskClosable: !1,
...widgetContainerProps,
$close: (flag) => __privateGet(this, _onModalClose).call(this, index2, () => resolve(flag))
},
React.createElement(widget, {
...widgetProps,
$close: (flag) => ref.current.handleClose(flag)
})
)), this.forceUpdate();
}));
__privateAdd(this, _onFormClick, (fields, widgetContainerProps = {}, formProps = {}) => __privateGet(this, _onModalClick).call(this, FormModalContainer, { formProps, fields }, widgetContainerProps).then((resp) => {
if (resp === !1)
throw !1;
return resp;
}));
__privateAdd(this, _onModalClose, (index2, cb) => {
__privateGet(this, _renders).delete(index2), this.forceUpdate(cb);
});
_FFPopupRender.modal = __privateGet(this, _onModalClick), _FFPopupRender.notification = __privateGet(this, _onNotificationClick), _FFPopupRender.confirm = __privateGet(this, _onConfirmClick), _FFPopupRender.form = __privateGet(this, _onFormClick);
}
componentWillUnmount() {
var _a, _b;
(_b = (_a = __privateGet(this, _pending)) == null ? void 0 : _a[1]) == null || _b.call(_a);
}
render() {
const renders = Array.from(__privateGet(this, _renders));
return /* @__PURE__ */ jsx(React.Fragment, { children: renders.map(([i, item]) => item) });
}
};
_pending = new WeakMap(), _index = new WeakMap(), _renders = new WeakMap(), _onNotificationClick = new WeakMap(), _onConfirmClick = new WeakMap(), _onModalClick = new WeakMap(), _onFormClick = new WeakMap(), _onModalClose = new WeakMap();
let FFPopupRender = _FFPopupRender;
FFPopupRender.notification = ({ title, content, icon, category, ...opts }) => Promise.resolve(notification$1[category || "open"]({
...opts,
icon: icon ? /* @__PURE__ */ jsx(Iconfont, { type: icon || "" }) : void 0,
message: title,
description: content
}));
FFPopupRender.success = (title, opts = {}) => FFPopupRender.notification({ title, category: "success", ...opts });
FFPopupRender.error = (title, opts = {}) => FFPopupRender.notification({ title, category: "error", ...opts });
FFPopupRender.confirm = (content, opts = {}) => FFPopupRender.notification({ content, ...opts });
FFPopupRender.form = (title, opts = {}) => FFPopupRender.notification({ title, ...opts });
FFPopupRender.modal = (opts = {}) => FFPopupRender.notification(opts);
const USER_MINE = "mine", USER_TOKEN = "token", USER_PLATFORM = "web", USER_TOKEN_EXPIRE = 60 * 60 * 24 * 30, getUserToken = () => {
const token = window.localStorage.getItem(USER_TOKEN);
if (!token)
return "";
const jwt = token.split(".");
if (!Array.isArray(jwt) || jwt.length !== 3)
throw "登录令牌无效!";
const { iat } = JSON.parse(window.atob(jwt[1]));
if (Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - iat > USER_TOKEN_EXPIRE)
throw "登录令牌已过期, 请重新登录!";
return token;
}, checkUserToken = () => {
try {
return !!getUserToken();
} catch {
return !1;
}
}, getUserInfo = (isAutoLogout = !0) => {
var _a;
try {
const token = getUserToken();
if (!token)
return Promise.resolve(null);
const { iat: t_iat } = JSON.parse(window.atob((_a = token == null ? void 0 : token.split(".")) == null ? void 0 : _a[1])), { iat: u_iat, ...User } = http.decode(window.localStorage.getItem(USER_MINE) || "", {});
return u_iat === t_iat ? Promise.resolve(User) : http.get("/api/mine-info").then(({ User: User2 = null }) => (window.localStorage.setItem(USER_MINE, http.encode({ ...User2, iat: t_iat })), User2));
} catch (e) {
console.error(e), isAutoLogout && FFPopupRender.error("请登录").then(logout);
}
return Promise.resolve(null);
}, login = (username, passwd, opts = {}) => http.post("/api/user-token", {
username,
passwd: SparkMD5.hash(passwd),
platform: USER_PLATFORM,
...opts
}).then(({ token }) => (window.localStorage.setItem(USER_TOKEN, token), token)), logout = () => {
window.localStorage.removeItem(USER_MINE), window.localStorage.removeItem(USER_TOKEN);
};
NProgress.configure({ showSpinner: !1 });
axios.interceptors.request.use((config) => {
config.headers.Platform = "web", config.headers.SaaS = window.localStorage.getItem("SaaS");
try {
const token = getUserToken();
config.headers.Authorization = token ? `Bearer ${token} ` : void 0;
} catch {
}
return NProgress.inc(), config;
}, (errMsg) => (NProgress.done(), Promise.reject({ code: -1, msg: errMsg })));
axios.interceptors.response.use(({ data: data2, headers }) => (NProgress.done(), { ...data2, res: headers == null ? void 0 : headers.res }), function(e) {
return NProgress.done(), Promise.reject(e.message);
});
window.addEventListener("unhandledrejection", Request.onUnhandledRejection);
Request.onMsg = (code, msg) => FFPopupRender[[0, 1].includes(code) ? "success" : "error"](msg).then(() => code === 20300 && route.redirect(configure.get("Common.WEBSITE_LOGIN_PAGE")));
const AppContext = React.createContext({
user: {},
initUser: () => {
},
initUserComplete: !1
}), AppGlobalParamsContext = React.createContext({
set: () => {
},
get: () => {
},
assign: () => {
},
currentRoute: () => {
}
});
var _cache, _loading, _pending2, _pResult, _target, _get;
class Cache {
constructor(target, fn2) {
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
__privateAdd(this, _loading, !0);
__privateAdd(this, _pending2, []);
__privateAdd(this, _pResult, void 0);
__privateAdd(this, _target, () => __privateGet(this, _pResult));
__privateAdd(this, _get, () => Promise.resolve());
__publicField(this, "get", (...args) => new Promise((resolve, reject) => {
const key = JSON.stringify(args);
if (__privateGet(this, _cache).has(key))
return resolve(__privateGet(this, _get).call(this, __privateGet(this, _pResult), ...args));
if (__privateGet(this, _pResult) === void 0)
__privateGet(this, _pending2).push([args, resolve, reject]), __privateGet(this, _loading) && (__privateSet(this, _loading, !1), Promise.resolve(typeof __privateGet(this, _target) == "function" ? __privateGet(this, _target).call(this) : __privateGet(this, _target)).then((data2) => __privateSet(this, _pResult, data2 || null)).finally(() => {
__privateGet(this, _pending2).forEach(([args2, resolve2, reject2]) => {
try {
const result = __privateGet(this, _get).call(this, __privateGet(this, _pResult), ...args2);
__privateGet(this, _cache).set(JSON.stringify(args2), result), resolve2(result);
} catch (e) {
reject2(e);
}
}), __privateGet(this, _pending2).length = 0;
}));
else {
const result = __privateGet(this, _get).call(this, __privateGet(this, _pResult), ...args);
__privateGet(this, _cache).set(key, result), resolve(result);
}
}));
__privateSet(this, _get, fn2), __privateSet(this, _target, target);
}
}
_cache = new WeakMap(), _loading = new WeakMap(), _pending2 = new WeakMap(), _pResult = new WeakMap(), _target = new WeakMap(), _get = new WeakMap();
var _instance3, _data2;
const _Configure = class _Configure {
constructor() {
__privateAdd(this, _data2, null);
__publicField(this, "init", (data2) => __privateSet(this, _data2, data2));
__publicField(this, "get", (key, _default) => _.get(__privateGet(this, _data2), key, _default));
if (__privateGet(_Configure, _instance3))
return __privateGet(_Configure, _instance3);
}
};
_instance3 = new WeakMap(), _data2 = new WeakMap(), __privateAdd(_Configure, _instance3, null), __publicField(_Configure, "getInstance", () => (__privateGet(_Configure, _instance3) || __privateSet(_Configure, _instance3, new _Configure()), __privateGet(_Configure, _instance3)));
let Configure = _Configure;
const configure = Configure.getInstance(), DataList = ({ component: component2 }) => {
const { base62params } = useParams();
return /* @__PURE__ */ jsx(FFContainer, { children: /* @__PURE__ */ jsx(
DataListHelper,
{
listCode: component2,
base62params: http.decode(base62params)
}
) });
}, Component = ({ component: component2, $setting }) => {
const [children, setChildren] = useState();
useEffect(() => {
if (!component2)
return setChildren(/* @__PURE__ */ jsx(Empty, { description: null }));
core.getWidgetComponent(component2).catch((e) => ({ default: () => `${e}` })).then((pkg) => React.createElement(pkg.default, { $setting })).then(setChildren);
}, [component2]);
const props = {};
return children ? React.cloneElement(children, props) : null;
};
var _instance4, _data3, _menus, _router, _findPathById, _getMenuItems;
const _Route = class _Route {
constructor() {
__privateAdd(this, _data3, /* @__PURE__ */ new Map());
__privateAdd(this, _menus, {});
__privateAdd(this, _router, null);
__publicField(this, "init", (data2, menus) => {
__privateSet(this, _data3, data2), __privateSet(this, _menus, menus);
});
__publicField(this, "get", (uuid) => (__privateGet(this, _data3).has(uuid) || (uuid = Array.from(__privateGet(this, _data3).keys()).find((k) => __privateGet(this, _data3).get(k).uri === uuid)), __privateGet(this, _data3).get(uuid) || {}));
__publicField(this, "redirect", (uuid, params, opt = {}) => {
const { uri, type, widgetProps } = this.get(uuid) || {};
let url = generatePath(uri || uuid, type != "list" ? params : _.mapValues(params, (item) => http.encode(item)));
const oUrlParam = new URLSearchParams();
for (const key in widgetProps || {})
(widgetProps == null ? void 0 : widgetProps.type) == "query" && oUrlParam.append(key, params[key]);
return oUrlParam.size > 0 && (url = `${url}?${oUrlParam.toString()}`), __privateGet(this, _router).navigate(url, opt);
});
/**
*
* @param {*} category // user, system, navigator
* @returns
*/
__publicField(this, "getMenus", (category) => {
var _a;
return ((_a = __privateGet(this, _menus)) == null ? void 0 : _a[category]) || [];
});
__publicField(this, "findMenuPathByUuid", (uuid) => {
let result = [];
for (const key in __privateGet(this, _menus))
if (result = __privateGet(this, _findPathById).call(this, __privateGet(this, _menus)[key], uuid, [key]), result.length > 1)
return result;
return result;
});
__publicField(this, "getMenusByRouteUuid", (key) => __privateGet(this, _getMenuItems).call(this, key, Object.values(__privateGet(this, _menus)).flat()));
__privateAdd(this, _findPathById, (items, target, path = []) => {
if (_.isEmpty(items))
return path;
for (const { uuid, children } of items) {
if (uuid == target)
return path.concat(uuid);
if (!_.isEmpty(children))
return path.concat(uuid, __privateGet(this, _findPathById).call(this, children, target));
}
return path;
});
__privateAdd(this, _getMenuItems, (key, items) => {
var _a;
let result = [];
for (const item of items)
item.widgetType == "redirect" && (item.uuid == key || item.widget == key ? result.push(item) : (_a = item.children) != null && _a.length && (result = result.concat(__privateGet(this, _getMenuItems).call(this, key, item.children))));
return result;
});
__publicField(this, "getCurrentMenu", () => {
const { uuid } = this.getCurrentRoute() || {};
if (!uuid)
return;
const items = this.getMenusByRouteUuid(uuid);
if (!_.isEmpty(items))
return items[0];
});
__publicField(this, "getCurrentRoute", (delta = 0) => {
var _a;
const route2 = (_a = __privateGet(this, _router).state.matches[__privateGet(this, _router).state.matches.length - 1 - delta]) == null ? void 0 : _a.route;
if (!route2)
return null;
for (let [_key, item] of __privateGet(this, _data3))
if (item.uri === route2.path)
return item;
return null;
});
__publicField(this, "getPageParams", (key) => {
var _a;
const { location, matches } = __privateGet(this, _router).state, params = ((_a = matches[matches.length - 1]) == null ? void 0 : _a.params) || {};
return location.search && new URLSearchParams(location.search).forEach((value, key2) => {
params[key2] = value;
}), key ? _.get(params, key) : params;
});
__publicField(this, "createBrowserRouter", (opt = {}) => {
if (__privateGet(this, _data3).size == 0)
return null;
const theme = configure.get("Common.WEBSITE_DEFAULT_THEME", "@pkg/frameworks/BasicLayout"), index2 = configure.get(checkUserToken() ? "Common.WEBSITE_LOGIN_REDIRECT" : "Common.WEBSITE_DEFAULT", "/index"), themeMap = { [theme]: 0 }, routes = Array.from(__privateGet(this, _data3).values()).reduce((carry, { uuid, uri, name, type, component: component2, widgetSetting, isLogin, isLayout, extra }) => {
let item = {}, themeIndex = 0;
switch (type) {
case "list":
item.element = React.createElement(DataList, { component: component2 });
break;
case "fsdpf-component":
item.element = React.createElement(Component, { key: component2, component: component2, $setting: widgetSetting });
break;
}
if (extra != null && extra.layout)
if (themeMap[extra == null ? void 0 : extra.layout])
themeIndex = themeMap[extra == null ? void 0 : extra.layout];
else
return themeMap[extra == null ? void 0 : extra.layout] = carry.length, [...carry, {
path: "/",
lazy: () => core.getWidgetComponent(extra == null ? void 0 : extra.layout).then((resp) => ({ Component: resp.default })),
children: [{ path: uri, ...item }]
}];
return isLayout && themeIndex > -1 ? (carry[themeIndex].children.push({ path: uri, ...item }), carry) : [...carry, { path: uri, ...item }];
}, [
{
path: "/",
lazy: () => core.getWidgetComponent(theme).then((resp) => ({ Component: resp.default })),
children: []
}
]);
return routes.push({ index: !0, element: React.createElement(Navigate, { to: index2, replace: !0 }) }), __privateSet(this, _router, createBrowserRouter(routes, opt));
});
if (__privateGet(_Route, _instance4))
return __privateGet(_Route, _instance4);
}
};
_instance4 = new WeakMap(), _data3 = new WeakMap(), _menus = new WeakMap(), _router = new WeakMap(), _findPathById = new WeakMap(), _getMenuItems = new WeakMap(), __privateAdd(_Route, _instance4, null), __publicField(_Route, "getInstance", () => (__privateGet(_Route, _instance4) || __privateSet(_Route, _instance4, new _Route()), __privateGet(_Route, _instance4)));
let Route = _Route;
const route = Route.getInstance(), oWorker = new Worker(new URL("data:text/plain;base64,KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2ltcG9ydFNjcmlwdHMoImh0dHBzOi8vYXNzZXRzLmZzZHBmLm5ldC9qcy91bWQvbG9kYXNoQDRfMTdfMjEubWluLmpzIiwiaHR0cHM6Ly9hc3NldHMuZnNkcGYubmV0L2pzL3VtZC9sb2Rhc2gubWl4aW4uanMiKSxpbXBvcnRTY3JpcHRzKCJodHRwczovL2Fzc2V0cy5mc2RwZi5uZXQvanMvdW1kL21vbWVudEAyXzI5XzQubWluLmpzIiwiaHR0cHM6Ly9hc3NldHMuZnNkcGYubmV0L2pzL3VtZC9tb21lbnQubG9jYWxlLnpoLWNuLmpzIiksbW9tZW50LmxvY2FsZSgiemgtY24iKTtjb25zdCBVdGlsPShlLHMpPT57Y29uc3QgdD1VdGlsLm1zZ19pZCsrO3JldHVybiBuZXcgUHJveHkoKCk9Pnt9LHtnZXQoe3Jvb3Q6YX0sbil7Y29uc3Qgbz1hP2Ake2F9LyR7bn1gOm47cmV0dXJuIGZ1bmN0aW9uKC4uLmkpe3JldHVybiBuZXcgUHJvbWlzZSgocixsKT0+e1V0aWwubVF1ZXVlLnNldCh0LFtyLGxdKSxzZWxmLnBvc3RNZXNzYWdlKHtpZDp0LHRhc2tfaWQ6ZSxzZXNzaW9uOnMsY2F0ZWdvcnk6InV0aWwiLG1ldGhvZDpvLGFyZ3M6aX0pfSl9fSxhcHBseShhLG4sbyl7cmV0dXJuIG5ldyBQcm94eShPYmplY3QuY3JlYXRlKHtyb290Om9bMF18fG51bGx9KSx7Z2V0OnRoaXMuZ2V0fSl9fSl9O1V0aWwubXNnX2lkPTAsVXRpbC5tUXVldWU9bmV3IE1hcCxVdGlsLm1NZXRob2RXb3Jrc3BhY2U9bmV3IE1hcCxzZWxmLmFkZEV2ZW50TGlzdGVuZXIoIm1lc3NhZ2UiLGZ1bmN0aW9uKHtkYXRhOntpZDplLGRhdGE6cyxlcnJvcjp0LGNhdGVnb3J5OmF9fSl7YT09PSJ1dGlsIiYmKHQhPT1udWxsP1V0aWwubVF1ZXVlLmdldChlKVsxXSh0KTpVdGlsLm1RdWV1ZS5nZXQoZSlbMF0ocyksVXRpbC5tUXVldWUuZ2V0KGUpLFV0aWwubVF1ZXVlLmRlbGV0ZShlKSl9LCExKSxzZWxmLmFkZEV2ZW50TGlzdGVuZXIoIm1lc3NhZ2UiLCh7ZGF0YTp7aWQsbWV0aG9kLGFyZ3MsY2F0ZWdvcnksc2Vzc2lvbixzb3VyY2VVUkx9fSk9PntpZihjYXRlZ29yeSE9PSJldmFsIilyZXR1cm47c2Vzc2lvbiYmIVV0aWwubU1ldGhvZFdvcmtzcGFjZS5oYXMoc2Vzc2lvbikmJlV0aWwubU1ldGhvZFdvcmtzcGFjZS5zZXQoc2Vzc2lvbix7fSk7Y29uc3QgZXZhbERhdGFTb3VyY2VVUkw9c291cmNlVVJMP2AKLy8jIHNvdXJjZVVSTD1mZjovLy8uLyR7c291cmNlVVJMfWA6IiIsZXZhbERhdGE9ZXZhbChgKGFzeW5jIGZ1bmN0aW9uKHske09iamVjdC5rZXlzKGFyZ3MpLmpvaW4oIiwgIil9fSwgVXRpbCl7JHttZXRob2R9Cn0pJHtldmFsRGF0YVNvdXJjZVVSTH1gKS5jYWxsKHNlc3Npb24/VXRpbC5tTWV0aG9kV29ya3NwYWNlLmdldChzZXNzaW9uKTp7fSxhcmdzLFV0aWwoaWQsc2Vzc2lvbikpO3JldHVybiBQcm9taXNlLnJlc29sdmUoZXZhbERhdGEpLnRoZW4oZT0+e3NlbGYucG9zdE1lc3NhZ2Uoe2lkLHNlc3Npb24sY2F0ZWdvcnksZGF0YTplLGVycm9yOm51bGx9KX0pLmNhdGNoKGU9PntzZWxmLnBvc3RNZXNzYWdlKHtpZCxzZXNzaW9uLGNhdGVnb3J5LGRhdGE6bnVsbCxlcnJvcjplIGluc3RhbmNlb2YgRE9NRXhjZXB0aW9uJiZlLm5hbWU9PT0iRGF0YUNsb25lRXJyb3IiPyJEYXRhQ2xvbmVFcnJvciDov5Tlm57nu5Pmnpzlj6rog73kuLrnroDljZXmlbDmja7moLzlvI8iOmV9KX0pfSksc2VsZi5hZGRFdmVudExpc3RlbmVyKCJtZXNzYWdlIiwoe2RhdGE6e2NhdGVnb3J5OmUsc2Vzc2lvbjpzfX0pPT57ZT09PSJjbGVhciImJlV0aWwubU1ldGhvZFdvcmtzcGFjZS5kZWxldGUocyl9LCExKX0pKCk7Cg==", self.location)), fns = {
getConfigure: (key) => configure.get(key),
route: {
redirect: (...args) => route.redirect(...args),
getPageParams: (...args) => route.getPageParams(...args),
getCurrentRoute: () => route.getCurrentRoute()
},
modal: {
notification: (...args) => FFPopupRender.notification(...args),
success: (...args) => FFPopupRender.success(...args),
error: (...args) => FFPopupRender.error(...args),
form: (...args) => FFPopupRender.form(...args)
},
popup: {
notification: (...args) => FFPopupRender.notification(...args),
success: (...args) => FFPopupRender.success(...args),
error: (...args) => FFPopupRender.error(...args),
form: (...args) => FFPopupRender.form(...args)
}
};
var _msg_id, _fns, _instance5;
const _Func = class _Func {
constructor() {
__publicField(this, "exec", (source, args = {}, fns2 = {}, session = "") => new Promise((resolve, reject) => {
const id = __privateWrapper(_Func, _msg_id)._++;
__privateGet(_Func, _fns).set(id, fns2), _Func.mQueue.set(id, [resolve, reject]), oWorker.postMessage({ id, session, category: "eval", method: source, args });
}));
__publicField(this, "clear", (session) => oWorker.postMessage({ session, category: "clear" }));
if (__privateGet(_Func, _instance5))
return __privateGet(_Func, _instance5);
Promise.resolve().then(() => index).then((m) => {
fns.http = m.http;
}), oWorker.addEventListener("message", ({ data: { id, task_id, method, args, category, data: data2, error, session } }) => {
if (category === "eval" && _Func.mQueue.has(id))
error !== null ? _Func.mQueue.get(id)[1](error) : _Func.mQueue.get(id)[0](data2), __privateGet(_Func, _fns).delete(id), _Func.mQueue.delete(id);
else if (category === "util")
try {
const func2 = _.get(fns, method.split("/")) || _.get(__privateGet(_Func, _fns).get(task_id), method.split("/"));
if (!_.isFunction(func2))
throw `${method} not found`;
Promise.resolve(Reflect.apply(func2, void 0, args)).then((data3) => {
oWorker.postMessage({ id, task_id, category, method, args, session, data: data3, error: null });
}).catch((e) => {
oWorker.postMessage({ id, task_id, category, method, args, session, data: null, error: e });
});
} catch (e) {
oWorker.postMessage({ id, task_id, category, method, args, session, data: null, error: e });
}
}, !1);
}
};
_msg_id = new WeakMap(), _fns = new WeakMap(), _instance5 = new WeakMap(), __publicField(_Func, "mQueue", /* @__PURE__ */ new Map()), __privateAdd(_Func, _msg_id, 0), __privateAdd(_Func, _fns, /* @__PURE__ */ new Map()), __privateAdd(_Func, _instance5, null), __publicField(_Func, "getInstance", () => (__privateGet(_Func, _instance5) || __privateSet(_Func, _instance5, new _Func()), __privateGet(_Func, _instance5)));
let Func = _Func;
const fn = Func.getInstance();
var _instance6, _cache2;
const _Core = class _Core {
constructor() {
__privateAdd(this, _cache2, /* @__PURE__ */ new Map());
__publicField(this, "setVendor", (key, vendor) => __privateGet(this, _cache2).set(key, new Cache(vendor, (self2, pkg) => self2.dynamicRequireFsdpfComponent(pkg))));
__publicField(this, "getWidgetComponent", async (w) => {
if (!w)
throw "getWidgetComponent widget is required";
const [, ff] = w == null ? void 0 : w.split("@ff/"), [, app] = w == null ? void 0 : w.split("@app/"), [, pkg] = w == null ? void 0 : w.split("@pkg/"), [, fsdpf] = w == null ? void 0 : w.split("@fsdpf/");
try {
switch (!0) {
case (!!ff && __privateGet(this, _cache2).has("pkg")):
return await __privateGet(this, _cache2).get("pkg").get(ff);
case (!!app && __privateGet(this, _cache2).has("pkg")):
return await __privateGet(this, _cache2).get("pkg").get(app);
case (!!pkg && __privateGet(this, _cache2).has("pkg")):
return await __privateGet(this, _cache2).get("pkg").get(pkg);
case (!!fsdpf && __privateGet(this, _cache2).has("pkg")):
return await __privateGet(this, _cache2).get("pkg").get(fsdpf);
}
} catch (e) {
throw e;
}
});
if (__privateGet(_Core, _instance6))
return __privateGet(_Core, _instance6);
}
};
_instance6 = new WeakMap(), _cache2 = new WeakMap(), __privateAdd(_Core, _instance6, null), __publicField(_Core, "getInstance", () => (__privateGet(_Core, _instance6) || __privateSet(_Core, _instance6, new _Core()), __privateGet(_Core, _instance6)));
let Core = _Core;
const core = Core.getInstance(), convertFns = {
null2json: (data2) => null,
null2array: (data2) => null,
null2number: (data2) => null,
null2bool: (data2) => null,
null2string: (data2) => null,
null2integer: (data2) => null,
null2float: (data2) => null,
// null2json: (data) => ({}),
// null2array: (data) => ([]),
// null2number: (data) => 0,
// null2bool: (data) => false,
// null2string: (data) => '',
string2json: (data2) => data2 ? JSON.parse(data2) : "{}",
string2array: (data2) => data2.substr(0, 1) === "[" && data2.substr(-1) === "]" ? JSON.parse(data2) : data2.split(","),
string2number: (data2) => data2 == "" ? null : +data2,
string2integer: (data2) => data2 == "" ? null : +data2,
string2float: (data2) => data2 == "" ? null : +data2,
string2bool: (data2) => {
switch (`${data2}`.toLowerCase()) {
case "0":
case "false":
case "[]":
case "{}":
return !1;
}
return !!data2;
},
string2string: (data2) => data2,
json2json: (data2) => data2,
json2array: (data2) => data2 ? Object.values(data2) : [],
json2number: (data2) => Object.keys(data2).length,
json2integer: (data2) => Object.keys(data2).length,
json2float: (data2) => Object.keys(data2).length,
json2bool: (data2) => Object.keys(data2).length > 0,
json2string: (data2) => data2 ? JSON.stringify(data2) : "",
array2json: (data2) => ({ ...data2 }),
array2array: (data2) => data2,
array2number: (data2) => data2.length,
array2integer: (data2) => data2.length,
array2float: (data2) => data2.length,
array2bool: (data2) => data2.length > 0,
array2string: (data2) => JSON.stringify(data2),
number2json: (data2) => ({}),
number2array: (data2) => [data2],
number2number: (data2) => data2,
number2integer: (data2) => data2,
number2float: (data2) => data2,
number2bool: (data2) => !!data2,
number2string: (data2) => data2.toString(),
boolean2json: (data2) => ({}),
boolean2array: (data2) => [],
boolean2number: (data2) => +data2,
boolean2integer: (data2) => +data2,
boolean2float: (data2) => +data2,
boolean2bool: (data2) => data2,
boolean2string: (data2) => data2 ? "true" : "false"
};
_.mixin({
toPairsDeep: (obj, i) => _.flatMap(
_.toPairs(obj),
([k, v]) => _.isObjectLike(v) ? _.toPairsDeep(v, k) : [[`${_.isUndefined(i) ? "" : i + "."}${k}`, v]]
),
deepSome: (items, func2 = () => !1) => _.some(items, (item) => {
if (_.some(item, func2))
return !0;
if (!_.isEmpty(item) && (_.isPlainObject(item) || _.isArray(item)))
return _.deepSome(item, func2);
}),
toPrimitive: (data2, type) => {
let sourceType = "string";
Array.isArray(data2) ? sourceType = "array" : sourceType = typeof data2, _.isObject(data2) && (sourceType = "json");
const fn2 = `${sourceType}2${type}`;
return Reflect.has(convertFns, fn2) ? convertFns[fn2](data2) : data2;
},
replaceKeys: (obj, keyMap) => !obj || typeof obj != "object" ? obj : Array.isArray(obj) ? obj.map((item) => _.replaceKeys(item, keyMap)) : Object.keys(obj).reduce((acc, key) => (keyMap[key] ? acc[keyMap[key]] = _.replaceKeys(obj[key], keyMap) : acc[key] = _.replaceKeys(obj[key], keyMap), acc), {})
});
let AppUrl = "";
const http = {
init: (appKey, appSecret, appUrl) => {
axios.defaults.baseURL = AppUrl = appUrl, axios.defaults.timeout = 15e3, Object.assign(http, new Request(appKey, appSecret, axios));
}
}, isReactComponent = (component2) => component2 != null && component2.name ? component2.prototype instanceof React.Component ? !0 : /^[A-Z]/.test(component2.name) : !1, index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
__proto__: null,
AppGlobalParamsContext,
get AppUrl() {
return AppUrl;
},
cache: Cache,
configure,
core,
default: AppContext,
func: fn,
http,
isReactComponent,
route
}, Symbol.toStringTag, { value: "Module" })), getRoutes = () => http.get("/api/my-router").then((resp) => [
...resp,
{ uuid: "data-list-setting", isLayout: !0, uri: "/data-list-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/components/ff-design/DataListSetting", extra: { layout: "@pkg/frameworks/DesignTheme" } },
{ uuid: "grid-layout-setting", isLayout: !0, uri: "/grid-layout-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/components/ff-design/GridLayoutSetting", extra: { layout: "@pkg/frameworks/DesignTheme" } },
{ uuid: "grid-layout-form-setting", isLayout: !0, uri: "/grid-layout-form-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/components/ff-design/GridLayoutFormSetting", extra: { layout: "@pkg/frameworks/DesignTheme" } },
{ uuid: "resource-api-setting", isLayout: !0, uri: "/resource-api-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/components/ff-design/ResourceApiSetting", extra: { layout: "@pkg/frameworks/DesignTheme" } },
{ uuid: "charts-setting", isLayout: !0, uri: "/resource-api-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/components/ff-design/ChartsSetting", extra: { layout: "@pkg/frameworks/DesignTheme" } },
{ uuid: "fsm-setting", isLayout: !0, uri: "/fsm-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/components/ff-design/FsmSetting", extra: { layout: "@pkg/frameworks/DesignTheme" } },
{ uuid: "component-setting", isLayout: !0, uri: "/component-setting/:category/:categoryUuid", type: "fsdpf-component", component: "@pkg/components/ff-design/ComponentSetting", extra: { layout: "@pkg/frameworks/DesignTheme" } },
{ uuid: "login", uri: "/login", name: "登录", type: "fsdpf-component", isLogin: !1, component: "@pkg/components/ff/Login" },
{ uuid: "not-found", uri: "*", name: "Not Found", type: "fsdpf-component", isLogin: !1, component: "@pkg/components/ff/NotFound" }
].map(({ uuid, ...item }) => [uuid, { uuid, ...item }])).then((data2) => new Map(data2)), getMenus = () => http.get("/api/my-menu"), getConfigure = () => http.get("api/init-configure"), getWidgetOperationAuth = () => http.get("/api/init-widget-operation-auth").then((resp) => resp.reduce((carry, { uuid, auth: auth2 }) => [...carry, [uuid, auth2]], [])), getPhoneNumber = (code) => http.get(`/api/user-wx-phone-number/${code}`);
export {
configure as $,
useHasOperationColumn as A,
Button as B,
useButton as C,
DataList$1 as D,
auth as E,
FFContainer as F,
GridLayout$1 as G,
GridLayoutForm$1 as H,
GridLayoutForm as I,
GridLayoutFormWidget as J,
GridLayoutFormHelper as K,
useFnRun as L,
getOptionItemByValue as M,
Iconfont as N,
getUserToken as O,
checkUserToken as P,
getUserInfo as Q,
ResWs$1 as R,
SlotContext as S,
login as T,
logout as U,
AppUrl as V,
http as W,
isReactComponent as X,
AppContext as Y,
AppGlobalParamsContext as Z,
Cache as _,
usePropsValue as a,
fn as a0,
core as a1,
route as a2,
getRoutes as a3,
getMenus as a4,
getConfigure as a5,
getWidgetOperationAuth as a6,
getPhoneNumber as a7,
usePrevious as b,
useStateWithCallback as c,
useDeepEqualEffect as d,
useOptions as e,
useSubscribeRequest as f,
SlotRender as g,
FFPageRender as h,
FFPopupRender as i,
getDefaultExpandRowKeys as j,
GridLayout as k,
GridLayoutWidget as l,
DataListFilter as m,
DataListToolbar as n,
DataListSider as o,
DataListFooter as p,
DataListHelper as q,
DataListContext as r,
DataListTable as s,
DataListContent as t,
useUpdate as u,
DataListFramework as v,
loadDataListFieldWidget as w,
useColumnsRender as x,
useStructure as y,
useDataSource as z
};