@ccs-ui/rc-pro 1.1.9 → 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/ccs.d.ts CHANGED
@@ -197,11 +197,13 @@ type GlobalConfig = {
197
197
  /** 路由上下文 */
198
198
  Context: string;
199
199
  /** 图片上传地址 */
200
- UploadUrl: string;
200
+ UploadUrl?: string;
201
201
  /** 图片下载地址 */
202
- DownloadUrl: string;
202
+ DownloadUrl?: string;
203
203
  };
204
204
  type TableFormItems = TableFormItem[];
205
205
  type TableInstanceRef<T = any> = MutableRefObject<TableInstance<T> | undefined> | React.RefObject<TableInstance<T>>;
206
- type TableColumns<T = any> = ColumnsType<T>;
206
+ type TableColumns<T = any> = ColumnsType<T> & {
207
+ hidden?: boolean;
208
+ };
207
209
  export type { PageType, RecordType, MenuTreeNode, PageQuery, ListQuery, HttpResult, GlobalConfig, HttpListResult, HttpPageResult, AuthButtonItem, MenuTreeNodeData, UserDetail, RouteHistory, TableData, TableFormItems, TableColumns, TableInstance, TableInstanceRef, TriggerChildrenProps, };
@@ -7,7 +7,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
8
8
  import { Button, Tooltip } from 'antd';
9
9
  import { useState } from 'react';
10
- import { classPrefix } from "../pro-table";
10
+ import { classPrefix } from "../pro-table/table";
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
12
  export default (function (_ref) {
13
13
  var onFullScreen = _ref.onFullScreen;
@@ -1,83 +1,26 @@
1
- import { TableProps } from 'antd';
2
- import { CSSProperties, ReactElement, ReactNode } from 'react';
3
- import CCS from '..';
1
+ import { HttpPageResult, HttpResult } from '../ccs';
4
2
  import './index.less';
5
- type ParamType = Record<string, any>;
6
- export type ShowDependType = {
7
- name: string;
8
- value: any;
9
- };
10
- type SearchEventType = 'search' | 'reset' | 'reload' | 'changePage' | 'initSearch';
11
- type SearchBeforeType = ParamType & {
12
- query: ParamType;
13
- };
14
- export type CcsTableProps<T> = TableProps<T> & {
15
- data?: CCS.TableData<T>;
16
- /** request 方法 */
17
- request?: (params: any) => void;
18
- /** request 额外参数 */
19
- requestParam?: ParamType;
20
- /** 自定义渲染内容 */
21
- render?: (data: T[]) => ReactNode;
22
- /** 异步树、父级参数名称,参数值:默认取rowkey的值 */
23
- asyncTree?: {
24
- parentName: string;
25
- };
26
- /** class name */
27
- className?: string;
28
- /** useEventEmitter事件 */
29
- event$?: any;
30
- /** style */
31
- style?: CSSProperties;
3
+ import { CcsProTableProps, SearchEventType } from './table';
4
+ type TableProps<T> = Omit<CcsProTableProps<T>, 'onSearchAfter' | 'parentFieldName'> & {
5
+ /** 请求后格式化结果 */
6
+ onSearchAfter?: (data: HttpPageResult<T>, eventType?: SearchEventType) => any;
32
7
  };
33
- export type CcsProTableProps<T> = {
34
- /** api权限标识 */
35
- auth?: string | 'ignore';
36
- /** 是否初始查询,默认true */
37
- init?: boolean;
38
- /** 标题 */
39
- title?: string;
40
- /** 查询条件集合 */
41
- formItems?: CCS.TableFormItems;
42
- /** form item label 宽度 */
43
- formItemLabelWidth?: number | string;
44
- /** 查询form 初始值 */
45
- formInitValues?: ParamType;
46
- /** 按钮 操作部分 */
47
- toolbar?: ReactElement;
48
- /** 操作按钮扩展 */
49
- toolbarExtra?: ReactElement;
50
- /** 展开查询条件,默认false */
51
- expandForm?: boolean;
52
- /** 禁止收起条件,默认false */
53
- disableCollapseForm?: boolean;
54
- /** table 数据区域 */
55
- table?: CcsTableProps<T>;
56
- /** table style */
57
- tableStyle?: CSSProperties;
58
- /** 水印文字 */
59
- watermark?: string;
60
- /** ref 回调方法 */
61
- proRef?: CCS.TableInstanceRef<T>;
62
- /** class */
63
- className?: string;
64
- /** style */
65
- style?: CSSProperties;
66
- /** children */
67
- children?: ReactNode;
68
- /** 执行search 后回调函数 */
69
- searchEvent?: () => void;
70
- /** 请求前格式化参数 */
71
- onSearchBefore?: (params: SearchBeforeType, eventType?: SearchEventType) => SearchBeforeType;
8
+ type TableTreeProps<T> = Omit<CcsProTableProps<T>, 'onSearchAfter'> & {
9
+ /** 父级值字段 */
10
+ parentFieldName: string;
72
11
  /** 请求后格式化结果 */
73
- onSearchAfter?: (data: any, eventType?: SearchEventType) => any;
12
+ onSearchAfter?: (data: HttpResult<(T & {
13
+ children?: T[];
14
+ })[]>, eventType?: SearchEventType) => any;
74
15
  };
75
- export declare const classPrefix = "ccs-pl";
76
16
  /**
77
- * 布局组件 包括form、查询、toolbar、table 自动初始化数据
78
- * @param CcsProTableType
17
+ * 查询表格组件
18
+ * @param TableProps
79
19
  * @param ref
80
20
  * @returns
81
21
  */
82
- declare const ProTable: <T extends object = any>(props: CcsProTableProps<T>) => import("react/jsx-runtime").JSX.Element;
22
+ declare const ProTable: {
23
+ <T extends object = any>(props: TableProps<T>): import("react/jsx-runtime").JSX.Element;
24
+ tree: <T_1 extends object = any>(props: TableTreeProps<T_1>) => import("react/jsx-runtime").JSX.Element;
25
+ };
83
26
  export default ProTable;
@@ -1,492 +1,32 @@
1
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
2
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
4
  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; }
5
5
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
6
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
8
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
9
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
- 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); }
12
- 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; }
13
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
14
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
16
- import { useEventEmitter } from 'ahooks';
17
- import { Empty, Form, theme } from 'antd';
18
- import classNames from 'classnames';
19
- import _debounce from 'lodash/debounce';
20
- import _isArray from 'lodash/isArray';
21
- import React, { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
22
- import { CcsUtils, CcsWaterMark } from '..';
23
- import { useCcsPage } from "../";
24
- import useProGrid from "../pro-grid/useProGrid";
25
- import CcsTable from "../table";
26
7
  import "./index.less";
27
- import SearchComponent from "./search";
28
- import TableTree from "./tree";
8
+ import InternalProTable from "./table";
29
9
  import { jsx as _jsx } from "react/jsx-runtime";
30
- import { jsxs as _jsxs } from "react/jsx-runtime";
31
- // 判断组件所处dom
32
- var onIsInModalOrDrawer = function onIsInModalOrDrawer(node) {
33
- var _parent$classList, _parent$classList2, _parent$classList3, _parent$classList4;
34
- var parent = node.parentNode;
35
- if (!parent) return false;
36
- if (
37
- // 通过指定dom吸顶
38
- (_parent$classList = parent.classList) !== null && _parent$classList !== void 0 && _parent$classList.contains('ccs-trigger-container') || (_parent$classList2 = parent.classList) !== null && _parent$classList2 !== void 0 && _parent$classList2.contains('ccs-drawer-content')) {
39
- return {
40
- getContainer: function getContainer() {
41
- return parent;
42
- }
43
- };
44
- }
45
- // 在弹出框中吸顶top
46
- if ((_parent$classList3 = parent.classList) !== null && _parent$classList3 !== void 0 && _parent$classList3.contains('ant-modal') || (_parent$classList4 = parent.classList) !== null && _parent$classList4 !== void 0 && _parent$classList4.contains('ant-drawer')) {
47
- return {
48
- offsetHeader: 0
49
- };
50
- }
51
- return onIsInModalOrDrawer(parent);
52
- };
53
-
54
- // 根据ID查找树形节点
55
- var getDataById = function getDataById(data, rowKey, id) {
56
- if (!_isArray(data)) return;
57
- for (var i = 0; i < data.length; i += 1) {
58
- if (data[i][rowKey] === id) {
59
- return data[i];
60
- }
61
- if (data[i].children) {
62
- var v = getDataById(data[i].children, rowKey, id);
63
- if (v) return v;
64
- }
65
- }
66
- };
67
- var getAllChildrenId = function getAllChildrenId(data, rowKey) {
68
- return data.reduce(function (keys, item) {
69
- keys.push(item[rowKey]);
70
- if (item.children && _isArray(item.children)) {
71
- return keys.concat(getAllChildrenId(item.children, rowKey));
72
- }
73
- return keys;
74
- }, []);
75
- };
76
- export var classPrefix = 'ccs-pl';
77
-
78
10
  /**
79
- * 布局组件 包括form、查询、toolbar、table 自动初始化数据
80
- * @param CcsProTableType
11
+ * 查询表格组件
12
+ * @param TableProps
81
13
  * @param ref
82
14
  * @returns
83
15
  */
84
16
  var ProTable = function ProTable(props) {
85
- var init = props.init,
86
- auth = props.auth,
87
- table = props.table,
88
- title = props.title,
89
- style = props.style,
90
- proRef = props.proRef,
91
- toolbar = props.toolbar,
92
- children = props.children,
93
- watermark = props.watermark,
94
- className = props.className,
95
- expandForm = props.expandForm,
96
- tableStyle = props.tableStyle,
97
- searchEvent = props.searchEvent,
98
- toolbarExtra = props.toolbarExtra,
99
- _props$formItems = props.formItems,
100
- formItems = _props$formItems === void 0 ? [] : _props$formItems,
101
- _props$formInitValues = props.formInitValues,
102
- formInitValues = _props$formInitValues === void 0 ? {} : _props$formInitValues,
103
- onSearchBefore = props.onSearchBefore,
104
- onSearchAfter = props.onSearchAfter;
105
- var tableRef = useRef(null);
106
- var _useCcsPage = useCcsPage(),
107
- onAuth = _useCcsPage.onAuth;
108
- var _useProGrid = useProGrid(),
109
- inProGrid = _useProGrid.inProGrid;
110
- var _ref = table || {},
111
- pagination = _ref.pagination,
112
- request = _ref.request,
113
- _ref$requestParam = _ref.requestParam,
114
- requestParam = _ref$requestParam === void 0 ? {} : _ref$requestParam,
115
- columns = _ref.columns,
116
- asyncTree = _ref.asyncTree,
117
- rowKey = _ref.rowKey;
118
- var stickyRef = useRef(false);
119
- // 判断当前组件是否在弹出框中
120
- var isInModalOrDrawer = _typeof(stickyRef.current) === 'object';
121
- // column filter
122
- var filtersRef = useRef({});
123
- // 查询form
124
- var _Form$useForm = Form.useForm(),
125
- _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
126
- form = _Form$useForm2[0];
127
- // table data
128
- var _useState = useState({
129
- totalNum: 0,
130
- result: [],
131
- pageSize: 10,
132
- pageNo: 1
133
- }),
134
- _useState2 = _slicedToArray(_useState, 2),
135
- data = _useState2[0],
136
- setData = _useState2[1];
137
- var event$ = useEventEmitter();
138
- var treeRef = useRef(null);
139
- var _theme$useToken = theme.useToken(),
140
- token = _theme$useToken.token;
141
-
142
- // 权限判断
143
- var isAuth = useMemo(function () {
144
- if (auth) return onAuth && onAuth(auth);
145
- return true;
146
- }, []);
147
- var formatFormItems = useMemo(function () {
148
- return formItems.flat(Infinity).filter(function (f) {
149
- return f.onFormat;
150
- });
151
- }, []);
152
-
153
- // 获取数据
154
- var onRequest = /*#__PURE__*/function () {
155
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(eventType) {
156
- var pageNo,
157
- pageSize,
158
- record,
159
- _args2 = arguments;
160
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
161
- while (1) switch (_context2.prev = _context2.next) {
162
- case 0:
163
- pageNo = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : 1;
164
- pageSize = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : (pagination ? pagination.defaultPageSize : 10) || 10;
165
- record = _args2.length > 3 ? _args2[3] : undefined;
166
- if (!(!isAuth || !request)) {
167
- _context2.next = 5;
168
- break;
169
- }
170
- return _context2.abrupt("return");
171
- case 5:
172
- // 构建查询条件:表单数据、请求额外参数、分页参数、其他参数
173
- form.validateFields().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
174
- var formValues,
175
- pageValue,
176
- params,
177
- _treeRef$current,
178
- newParams,
179
- requestResult,
180
- newRequestResult,
181
- _newRequestResult$dat,
182
- totalNum,
183
- size,
184
- no,
185
- result,
186
- _args = arguments;
187
- return _regeneratorRuntime().wrap(function _callee$(_context) {
188
- while (1) switch (_context.prev = _context.next) {
189
- case 0:
190
- formValues = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
191
- // 格式化条件
192
- if (formatFormItems.length) {
193
- Object.keys(formValues).forEach(function (k) {
194
- if (formValues[k] !== undefined) {
195
- var s = formatFormItems.find(function (f) {
196
- return f.name === k;
197
- });
198
- if (s) formValues[k] = s.onFormat && s.onFormat(formValues[k]);
199
- }
200
- });
201
- }
202
- pageValue = pagination === false ? {} : {
203
- pageNo: pageNo,
204
- pageSize: pageSize
205
- };
206
- params = _objectSpread(_objectSpread({
207
- query: _objectSpread(_objectSpread({}, formValues), requestParam)
208
- }, pageValue), filtersRef.current); // 异步树
209
- if (!asyncTree) {
210
- _context.next = 7;
211
- break;
212
- }
213
- (_treeRef$current = treeRef.current) === null || _treeRef$current === void 0 ? void 0 : _treeRef$current.onRequestTree(params.query, record);
214
- return _context.abrupt("return");
215
- case 7:
216
- // onSearchBefore 请求前回传参数,可以在父组件进行修改
217
- newParams = onSearchBefore ? onSearchBefore(params, eventType) : params; // 发起请求
218
- setData(function (d) {
219
- return _objectSpread(_objectSpread({}, d), {}, {
220
- loading: true
221
- });
222
- });
223
- _context.next = 11;
224
- return request(_objectSpread({}, newParams));
225
- case 11:
226
- requestResult = _context.sent;
227
- if (!(requestResult && requestResult.success)) {
228
- _context.next = 22;
229
- break;
230
- }
231
- // onSearchAfter 处理请求结果
232
- newRequestResult = onSearchAfter ? onSearchAfter(requestResult, eventType) : requestResult;
233
- _newRequestResult$dat = newRequestResult.data, totalNum = _newRequestResult$dat.totalNum, size = _newRequestResult$dat.pageSize, no = _newRequestResult$dat.pageNo, result = _newRequestResult$dat.result;
234
- if (!(totalNum === undefined || pageSize === undefined || no === undefined || result === undefined)) {
235
- _context.next = 19;
236
- break;
237
- }
238
- CcsUtils.showLogWarning('分页返回对象,totalNum,pageSize,no,result不能为空');
239
- setData(_objectSpread(_objectSpread({}, data), {}, {
240
- loading: false
241
- }));
242
- return _context.abrupt("return");
243
- case 19:
244
- // 当前页无数据,返回上一页
245
- if (!result.length && no !== 1 && no !== undefined) {
246
- onRequest('reload', no - 1);
247
- } else {
248
- setData({
249
- pageNo: no,
250
- pageSize: size,
251
- loading: false,
252
- result: result,
253
- totalNum: totalNum || 0
254
- });
255
- }
256
- _context.next = 23;
257
- break;
258
- case 22:
259
- setData(function (d) {
260
- return _objectSpread(_objectSpread({}, d), {}, {
261
- loading: false
262
- });
263
- });
264
- case 23:
265
- case "end":
266
- return _context.stop();
267
- }
268
- }, _callee);
269
- }))).catch(function () {});
270
- case 6:
271
- case "end":
272
- return _context2.stop();
273
- }
274
- }, _callee2);
275
- }));
276
- return function onRequest(_x2) {
277
- return _ref2.apply(this, arguments);
278
- };
279
- }();
280
-
281
- // 异步树、局部刷新方法
282
- var _onPartialReload = function onPartialReload(id) {
283
- var _treeRef$current2, _treeRef$current3;
284
- // 查找需要刷新的节点
285
- var treeNode = getDataById(data.result || [], rowKey, id);
286
- // 没有查找到、全部刷新
287
- if (!treeNode) {
288
- onRequest('search');
289
- return;
290
- }
291
- // 获取所有下级ID
292
- var ids = getAllChildrenId(treeNode.children || [], rowKey);
293
- // 局部重载
294
- (_treeRef$current2 = treeRef.current) === null || _treeRef$current2 === void 0 ? void 0 : _treeRef$current2.onExpandKeys(ids);
295
- (_treeRef$current3 = treeRef.current) === null || _treeRef$current3 === void 0 ? void 0 : _treeRef$current3.onRequestTree({}, treeNode);
296
- };
297
-
298
- // 尺寸变化重设尺寸
299
- var resizeFn = _debounce(function () {
300
- // console.log('resizeFn...');
301
- }, 200);
302
- useEffect(function () {
303
- // 判断当前dom所处的滚动区域
304
- var inMd = onIsInModalOrDrawer(tableRef.current);
305
- if (inMd) stickyRef.current = inMd;
306
-
307
- // 监听resize
308
- window.addEventListener('resize', resizeFn);
309
- return function () {
310
- window.removeEventListener('resize', resizeFn);
311
- };
312
- }, []);
313
-
314
- // 初始查询
315
- useEffect(function () {
316
- if (init !== false && request) {
317
- onRequest('initSearch');
318
- }
319
- }, [Object.keys(requestParam || {}).toString(), Object.values(requestParam || {}).toString()]);
320
-
321
- // 查询按钮
322
- var _onSearch = function onSearch() {
323
- if (searchEvent) searchEvent();
324
- onRequest('search');
325
- };
326
-
327
- // 重置
328
- var _onReset = function onReset() {
329
- form === null || form === void 0 ? void 0 : form.resetFields();
330
- // 清空columns显示filter和sort值
331
- columns === null || columns === void 0 ? void 0 : columns.forEach(function (c) {
332
- if (c.filterDropdown || c.filters) {
333
- c.filteredValue = null;
334
- }
335
- if (c.sorter) {
336
- c.sortOrder = undefined;
337
- }
338
- });
339
- // 清空filter请求值
340
- filtersRef.current = {};
341
- onRequest('reset');
342
- };
343
-
344
- // 刷新
345
- var _onReload = function onReload() {
346
- onRequest('reload', data.pageNo, data.pageSize);
347
- };
348
-
349
- // form 数据 查询,重载,重置方法
350
- useImperativeHandle(proRef, function () {
351
- return {
352
- onSearch: function onSearch() {
353
- _onSearch();
354
- },
355
- onReload: function onReload() {
356
- _onReload();
357
- },
358
- onPartialReload: function onPartialReload(param) {
359
- _onPartialReload(param);
360
- },
361
- onReset: function onReset() {
362
- _onReset();
363
- },
364
- onChangeData: setData,
365
- formValues: form.getFieldsValue(),
366
- data: data
367
- };
368
- });
369
-
370
- // 分页查询
371
- var handlePageChange = function handlePageChange(paginationTable, filters, sorter) {
372
- // 记录filter,sorter,以便重置的时候可以清除数据
373
- if (filters) {
374
- columns === null || columns === void 0 ? void 0 : columns.forEach(function (c) {
375
- if (c.filterDropdown || c.filters) {
376
- // @ts-ignore
377
- c.filteredValue = filters[c.dataIndex];
378
- }
379
- });
380
- filtersRef.current = _objectSpread(_objectSpread({}, filtersRef.current), {}, {
381
- filters: filters
382
- });
383
- }
384
-
385
- // @ts-ignore
386
- if (sorter) {
387
- columns === null || columns === void 0 ? void 0 : columns.forEach(function (c) {
388
- if (c.sorter) {
389
- // @ts-ignore
390
- if (c.dataIndex !== sorter.field) {
391
- c.sortOrder = undefined;
392
- return;
393
- }
394
- // @ts-ignore
395
- c.sortOrder = sorter === null || sorter === void 0 ? void 0 : sorter.order;
396
- }
397
- });
398
- filtersRef.current = _objectSpread(_objectSpread({}, filtersRef.current), {}, {
399
- sorter: sorter
400
- });
401
- }
402
- onRequest('changePage', paginationTable.current || 0, paginationTable.pageSize || 10);
403
- };
404
- var renderTable = function renderTable() {
405
- if (!table) return null;
406
- if (!isAuth) {
407
- return /*#__PURE__*/_jsx(Empty, {
408
- style: {
409
- margin: 0,
410
- padding: '32px 0',
411
- color: 'red'
412
- },
413
- image: Empty.PRESENTED_IMAGE_DEFAULT,
414
- description: "\u6CA1\u6709\u6570\u636E\u8BF7\u6C42\u6743\u9650"
415
- });
416
- }
417
- if (_typeof(stickyRef.current) === 'object' && 'getContainer' in stickyRef.current) {
418
- // 判断吸顶dom是否有paddingTop,设置offsetHeader
419
- var dom = stickyRef.current.getContainer();
420
- var _window$getComputedSt = window.getComputedStyle(dom),
421
- paddingTop = _window$getComputedSt.paddingTop;
422
- if (paddingTop) {
423
- stickyRef.current = _objectSpread(_objectSpread({}, stickyRef.current), {}, {
424
- offsetHeader: -parseInt(paddingTop.replace('px', ''))
425
- });
426
- }
427
- }
17
+ return /*#__PURE__*/_jsx(InternalProTable, _objectSpread({}, props));
18
+ };
428
19
 
429
- // 异步树
430
- if (table !== null && table !== void 0 && table.asyncTree) {
431
- return /*#__PURE__*/_jsx(TableTree, {
432
- data: data,
433
- table: table,
434
- event$: event$,
435
- treeRef: treeRef,
436
- sticky: stickyRef.current || true,
437
- setData: setData,
438
- onSearchAfter: onSearchAfter,
439
- onSearchBefore: onSearchBefore,
440
- handlePageChange: handlePageChange,
441
- isInModalOrDrawer: isInModalOrDrawer
442
- });
443
- }
444
- return /*#__PURE__*/_jsx(CcsTable, _objectSpread(_objectSpread({
445
- onChange: handlePageChange,
446
- data: data,
447
- event$: event$,
448
- size: isInModalOrDrawer ? 'small' : 'middle',
449
- sticky: stickyRef.current || true
450
- }, table), {}, {
451
- columns: columns,
452
- showSorterTooltip: true,
453
- loading: table.loading || data.loading || false
454
- }));
455
- };
456
- var isDark = token._appTheme === 'dark';
457
- var render = /*#__PURE__*/_jsxs("div", {
458
- className: classNames(classPrefix, className, _defineProperty({}, 'dark-table', isDark)),
459
- style: style,
460
- children: [!(!formItems.length && !toolbar) && isAuth && /*#__PURE__*/_jsx(SearchComponent, {
461
- form: form,
462
- title: title,
463
- titleBordered: table === null || table === void 0 ? void 0 : table.bordered,
464
- toolbar: toolbar,
465
- columns: columns,
466
- formItems: formItems,
467
- expandForm: expandForm,
468
- formInitValues: formInitValues,
469
- isInModalOrDrawer: isInModalOrDrawer,
470
- formItemLabelWidth: props.formItemLabelWidth,
471
- disableCollapseForm: props.disableCollapseForm,
472
- event$: event$,
473
- onSearch: _onSearch,
474
- onReset: _onReset,
475
- children: toolbarExtra
476
- }), /*#__PURE__*/_jsxs("div", {
477
- className: "".concat(classPrefix, "-table-content"),
478
- style: _objectSpread({
479
- padding: isInModalOrDrawer || inProGrid ? '0 16px 16px 16px' : 16
480
- }, tableStyle),
481
- ref: tableRef,
482
- children: [renderTable(), children]
483
- })]
484
- });
485
- return watermark ? /*#__PURE__*/_jsx(CcsWaterMark, {
486
- content: watermark,
487
- fontColor: "rgba(0,0,0,.15)",
488
- zIndex: 105,
489
- children: render
490
- }) : render;
20
+ /**
21
+ * 查询表格树组件
22
+ * @param TableTreeProps
23
+ * @param ref
24
+ * @returns
25
+ */
26
+ var ProTableTree = function ProTableTree(props) {
27
+ return /*#__PURE__*/_jsx(InternalProTable, _objectSpread(_objectSpread({}, props), {}, {
28
+ onSearchAfter: props.onSearchAfter
29
+ }));
491
30
  };
31
+ ProTable.tree = ProTableTree;
492
32
  export default ProTable;
@@ -1,7 +1,7 @@
1
1
  import { EventEmitter } from 'ahooks/lib/useEventEmitter';
2
2
  import { FormInstance } from 'antd/lib/form';
3
3
  import { ReactElement } from 'react';
4
- import { CcsProTableProps } from './';
4
+ import { CcsProTableProps } from './table';
5
5
  type PropsType<T> = Pick<CcsProTableProps<T>, 'toolbar' | 'formItems' | 'formInitValues' | 'expandForm' | 'disableCollapseForm' | 'formItemLabelWidth' | 'title'> & {
6
6
  /** 显示列 */
7
7
  columns?: any;