@cocoy/kit-components
Version:
一些前端组件
137 lines • 8.72 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _excluded = ["title", "dataIndex", "align", "width", "ellipsis", "copyable", "fixed", "render", "valueType", "valueEnum"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import { Space, Button, Typography } from 'antd';
import { matchLabel, parseDate, getLabel } from '@cocoy/kit-utils';
import { isFunction, isArray, isString } from 'lodash-es';
import Status from "./components/Status";
import { jsx as _jsx } from "react/jsx-runtime";
var renderText = function renderText(text, ellipsis, copyable, valueType, valueEnum, queryFormOptionData) {
var wrapperText = function wrapperText(_text) {
if (!ellipsis && !copyable) {
return _text;
} else {
return /*#__PURE__*/_jsx(Typography.Text, {
copyable: copyable,
ellipsis: ellipsis ? {
tooltip: _text
} : false,
children: _text
});
}
};
var valueEnumData = [];
if (isFunction(valueEnum)) {
valueEnumData = valueEnum(queryFormOptionData);
} else if (isArray(valueEnum)) {
valueEnumData = valueEnum;
} else if (isString(valueEnum)) {
var _queryFormOptionData$;
valueEnumData = (_queryFormOptionData$ = queryFormOptionData === null || queryFormOptionData === void 0 ? void 0 : queryFormOptionData[valueEnum]) !== null && _queryFormOptionData$ !== void 0 ? _queryFormOptionData$ : [];
} else {
valueEnumData = [];
}
switch (valueType) {
case 'status':
return wrapperText( /*#__PURE__*/_jsx(Status, {
map: valueEnumData,
value: text
}));
case 'map':
return wrapperText(getLabel(text, valueEnumData));
case 'date':
return wrapperText(parseDate(text, 'YYYY-MM-DD'));
case 'dateTime':
return wrapperText(parseDate(text));
default:
return wrapperText(text);
}
};
var renderOperationGroup = function renderOperationGroup(record, columnActions, navigate) {
var _columnActions2, _columnActions3;
var _ref = columnActions !== null && columnActions !== void 0 ? columnActions : {},
_ref$list = _ref.list,
list = _ref$list === void 0 ? [] : _ref$list,
_ref$showAliasConfig = _ref.showAliasConfig,
showAliasConfig = _ref$showAliasConfig === void 0 ? false : _ref$showAliasConfig;
var _columnActions = [];
if (showAliasConfig) {
var _key = showAliasConfig.key,
map = showAliasConfig.map;
_columnActions = list === null || list === void 0 ? void 0 : list.filter(function (it) {
return !(it !== null && it !== void 0 && it.show) ? true : matchLabel(record[_key], map, it === null || it === void 0 ? void 0 : it.show);
});
} else {
_columnActions = list === null || list === void 0 ? void 0 : list.filter(function (it) {
return !(it !== null && it !== void 0 && it.show) ? true : it.show(record);
});
}
return (_columnActions2 = _columnActions) !== null && _columnActions2 !== void 0 && _columnActions2.length ? /*#__PURE__*/_jsx(Space, {
className: "mango-pro-table-table-column-actions",
size: "large",
children: (_columnActions3 = _columnActions) === null || _columnActions3 === void 0 ? void 0 : _columnActions3.map(function (i) {
return /*#__PURE__*/_jsx(Button, {
size: "middle",
type: "link",
onClick: function onClick() {
return i.action(record, navigate);
},
children: i.title
}, i.title);
})
}) : null;
};
export var renderTableColumns = function renderTableColumns(columns, columnActions, queryFormOptionData, navigate) {
var _columns$map;
return [].concat(_toConsumableArray((_columns$map = columns === null || columns === void 0 ? void 0 : columns.map(function (_ref2) {
var title = _ref2.title,
dataIndex = _ref2.dataIndex,
_ref2$align = _ref2.align,
align = _ref2$align === void 0 ? 'left' : _ref2$align,
width = _ref2.width,
_ref2$ellipsis = _ref2.ellipsis,
ellipsis = _ref2$ellipsis === void 0 ? false : _ref2$ellipsis,
_ref2$copyable = _ref2.copyable,
copyable = _ref2$copyable === void 0 ? false : _ref2$copyable,
fixed = _ref2.fixed,
render = _ref2.render,
_ref2$valueType = _ref2.valueType,
valueType = _ref2$valueType === void 0 ? 'text' : _ref2$valueType,
_ref2$valueEnum = _ref2.valueEnum,
valueEnum = _ref2$valueEnum === void 0 ? [] : _ref2$valueEnum,
rest = _objectWithoutProperties(_ref2, _excluded);
return _objectSpread({
key: dataIndex,
title: title,
dataIndex: dataIndex,
align: align,
width: width,
ellipsis: ellipsis,
fixed: fixed,
render: render ? render : function (text) {
return renderText(text, ellipsis, copyable, valueType, valueEnum, queryFormOptionData);
}
}, rest);
})) !== null && _columns$map !== void 0 ? _columns$map : []), [columnActions ? {
title: '操作',
key: 'operation',
width: columnActions.width,
fixed: 'right',
align: 'left',
render: function render(text, record) {
return renderOperationGroup(record, columnActions, navigate);
}
} : undefined]).filter(Boolean);
};