venus-design 1.1.21 → 1.1.23

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.
Files changed (36) hide show
  1. package/dist/Config/api.d.ts +6 -0
  2. package/dist/Config/api.js +154 -118
  3. package/dist/DataView/dataVirtual/index.d.ts +32 -0
  4. package/dist/DataView/dataVirtual/index.js +1060 -0
  5. package/dist/DataView/dataVirtual/style.css +7 -0
  6. package/dist/DataView/index.js +7 -1
  7. package/dist/DataView/resizable/index.js +14 -5
  8. package/dist/Drawer/index.js +6 -3
  9. package/dist/ProForm/index.d.ts +14 -2
  10. package/dist/ProForm/index.js +122 -35
  11. package/dist/RadioAndInput/index.js +1 -0
  12. package/dist/SelectCompoments/SelectUserOrDeptBySeclevel/selectPanel/dept.js +4 -4
  13. package/dist/SelectCompoments/SelectUserOrDeptBySeclevel/selectPanel/user.js +19 -15
  14. package/dist/SelectCompoments/SelectUserOrDeptBySeclevel/styles.less +1 -0
  15. package/dist/VenusAdjust/index.js +8 -4
  16. package/dist/VenusAdjust/interface.d.ts +10 -9
  17. package/dist/VenusDesignCom/components/Form.js +1 -1
  18. package/dist/VenusDetail/handleVenusDetailFunctions.js +6 -4
  19. package/dist/VenusDetail/staticAttr.js +74 -26
  20. package/dist/VenusForm/VenusFormScriptEngine.d.ts +96 -0
  21. package/dist/VenusForm/VenusFormScriptEngine.js +207 -0
  22. package/dist/VenusForm/VenusFormScriptUtils.d.ts +7 -0
  23. package/dist/VenusForm/VenusFormScriptUtils.js +190 -0
  24. package/dist/VenusForm/index.js +226 -37
  25. package/dist/VenusForm/interface.d.ts +4 -2
  26. package/dist/VenusForm/staticAttr.d.ts +1 -0
  27. package/dist/VenusForm/staticAttr.js +90 -62
  28. package/dist/VenusTable/components/filterDrawer/index.js +6 -3
  29. package/dist/VenusTable/components/filterDrawer/staticAttr.js +5 -4
  30. package/dist/VenusTable/index.js +46 -39
  31. package/dist/VenusTable/staticAttr.js +16 -10
  32. package/dist/VenusTable/style.css +2 -6
  33. package/dist/VenusUploadSecLevel/index.js +1 -0
  34. package/dist/index.d.ts +2 -1
  35. package/dist/index.js +2 -1
  36. package/package.json +162 -161
@@ -0,0 +1,1060 @@
1
+ import "antd/es/button/style";
2
+ import _Button from "antd/es/button";
3
+ import "antd/es/tooltip/style";
4
+ import _Tooltip from "antd/es/tooltip";
5
+ import "antd/es/checkbox/style";
6
+ import _Checkbox from "antd/es/checkbox";
7
+ var _excluded = ["onResizeStart"],
8
+ _excluded2 = ["columns", "scroll", "virtual", "columnsState", "onSizeChange", "request", "exportHidden", "exportFileName", "permission", "permissionViewFn", "rowKey", "toolBarRender", "onColumnsStateChange", "columnsStateMap", "getExportData", "columnsFnExport", "exportButtonConfig", "rowSelection"];
9
+ 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); }
10
+ 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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
11
+ 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); } }
12
+ 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); }); }; }
13
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
14
+ 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."); }
15
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
16
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
18
+ 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."); }
19
+ 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); }
20
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
21
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
22
+ 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; }
23
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
24
+ 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; }
25
+ 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; }
26
+ 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; }
27
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
28
+ 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); }
29
+ 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; }
30
+ 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; }
31
+ import { ProTable } from '@ant-design/pro-components';
32
+ import classNames from 'classnames';
33
+ import ResizeObserver from 'rc-resize-observer';
34
+ import React, { useRef, useState, useCallback, useMemo, useEffect } from 'react';
35
+ import { PlusOutlined, MinusOutlined, SlidersOutlined } from '@ant-design/icons';
36
+ import { saveAs } from 'file-saver';
37
+ import * as ExcelJs from 'exceljs';
38
+ import { DrawerDataAuth, storage } from "../..";
39
+ import { StyleProvider, legacyLogicalPropertiesTransformer } from '@ant-design/cssinjs';
40
+ import "./style.css";
41
+ import dayjs from 'dayjs';
42
+ var DENSITY_CONFIG = {
43
+ small: {
44
+ rowHeight: 32,
45
+ padding: '4px 8px',
46
+ fontSize: 12
47
+ },
48
+ middle: {
49
+ rowHeight: 48,
50
+ padding: '8px 16px',
51
+ fontSize: 14
52
+ },
53
+ large: {
54
+ rowHeight: 64,
55
+ padding: '12px 24px',
56
+ fontSize: 14
57
+ }
58
+ };
59
+ var SCROLLBAR_WIDTH = 15;
60
+
61
+ // 拖拽辅助线
62
+ var ResizeGuideLine = function ResizeGuideLine(_ref) {
63
+ var visible = _ref.visible,
64
+ left = _ref.left,
65
+ topOffset = _ref.topOffset;
66
+ if (!visible) return null;
67
+ return /*#__PURE__*/React.createElement("div", {
68
+ style: {
69
+ position: 'absolute',
70
+ top: topOffset,
71
+ bottom: 0,
72
+ left: left + 'px',
73
+ width: 1,
74
+ background: '#cbc9c9',
75
+ zIndex: 999,
76
+ pointerEvents: 'none'
77
+ }
78
+ });
79
+ };
80
+
81
+ // 可拖拽表头
82
+ var ResizableTitle = function ResizableTitle(props) {
83
+ var onResizeStart = props.onResizeStart,
84
+ rest = _objectWithoutProperties(props, _excluded);
85
+ return /*#__PURE__*/React.createElement("th", _extends({}, rest, {
86
+ style: _objectSpread(_objectSpread({}, rest.style), {}, {
87
+ position: 'relative'
88
+ })
89
+ }), rest.children, !rest['data-is-checkbox'] && /*#__PURE__*/React.createElement("div", {
90
+ style: {
91
+ position: 'absolute',
92
+ right: -4,
93
+ top: 0,
94
+ height: '100%',
95
+ width: 10,
96
+ cursor: 'col-resize',
97
+ zIndex: 100
98
+ },
99
+ onMouseDown: function onMouseDown(e) {
100
+ return onResizeStart === null || onResizeStart === void 0 ? void 0 : onResizeStart(e);
101
+ }
102
+ }));
103
+ };
104
+
105
+ // 树形数据拍平工具函数
106
+ function flattenTreeData(data, expandedKeys) {
107
+ var parentKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
108
+ var level = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
109
+ var result = [];
110
+ if (!Array.isArray(data)) return result;
111
+ data.forEach(function (item) {
112
+ var key = item.key;
113
+ result.push(_objectSpread(_objectSpread({}, item), {}, {
114
+ _level: level,
115
+ _parentKey: parentKey
116
+ }));
117
+ if (item.children && item.children.length && expandedKeys.has(key)) {
118
+ result.push.apply(result, _toConsumableArray(flattenTreeData(item.children, expandedKeys, key, level + 1)));
119
+ }
120
+ });
121
+ return result;
122
+ }
123
+ // 虚拟表格组件 props
124
+ // 1. 继承 ProTableProps<any>,除 components 外的其他 props
125
+ // 2. dataSource 为 any[],用于虚拟表格数据
126
+ //@ts-ignore
127
+
128
+ /**
129
+ * 虚拟表格组件
130
+ * 1. 继承 ProTableProps<any>,除 components 外的其他 props
131
+ * 2. dataSource 为 any[],用于虚拟表格数据
132
+ // 虚拟表格组件
133
+ // 1. 继承 ProTable �<any>
134
+ // 2. 处理 virtual 为 true 时的特殊逻辑
135
+ // 3. 处理 dataSource 为 any[] 时的特殊逻辑
136
+ // 4. 处理 columnsState 为 Record<string, any> 时的特殊逻辑
137
+ // 5. 处理 columnsStateMap 为 Record<string, any> 时的特殊逻辑
138
+ // 6. 处理 columnsFnExport 为 (columns: any[]) => any[] 时的特殊逻辑
139
+ // 7. 处理 getExportData 为 (data: any[]) => any[] 时的特殊逻辑
140
+ // 8. 处理 exportButtonConfig 为 any[] 时的特殊逻辑
141
+ // 9. 处理 rowSelection 为 any 时的特殊逻辑
142
+ // 10. 处理 onColumnsStateChange 为 (columnsState: Record<string, any>) => void 时的特殊逻辑
143
+ // 11. 处理 columnsStateMap 为 Record<string, any> 时的特殊逻辑
144
+ // 12. 处理 getExportData 为 (data: any[]) => any[] 时的特殊逻辑
145
+ // 13. 处理 columnsFnExport 为 (columns: any[]) => any[] 时的特殊逻辑
146
+ // 14. 处理 exportButtonConfig 为 any[] 时的特殊逻辑
147
+ // 15. 处理 rowSelection 为 any 时的特殊逻辑
148
+ // 16. 处理 onColumnsStateChange 为 (columnsState: Record<string, any>) => void 时的特殊逻辑
149
+ // 17. 处理 columnsStateMap 为 Record<string, any> 时的特殊逻辑
150
+ // 18. 处理 getExportData 为 (data: any[]) => any[] 时的特殊逻辑
151
+ // 19. 处理 columnsFnExport 为 (columns: any[]) => any[] 时的特殊逻辑*/
152
+ var DataViewTable = function DataViewTable(props) {
153
+ var rawColumns = props.columns,
154
+ scroll = props.scroll,
155
+ _props$virtual = props.virtual,
156
+ virtual = _props$virtual === void 0 ? false : _props$virtual,
157
+ columnsState = props.columnsState,
158
+ onSizeChange = props.onSizeChange,
159
+ request = props.request,
160
+ exportHidden = props.exportHidden,
161
+ exportFileName = props.exportFileName,
162
+ permission = props.permission,
163
+ permissionViewFn = props.permissionViewFn,
164
+ rowKey = props.rowKey,
165
+ _toolBarRender = props.toolBarRender,
166
+ onColumnsStateChange = props.onColumnsStateChange,
167
+ columnsStateMap = props.columnsStateMap,
168
+ getExportData = props.getExportData,
169
+ columnsFnExport = props.columnsFnExport,
170
+ exportButtonConfig = props.exportButtonConfig,
171
+ rowSelection = props.rowSelection,
172
+ restProps = _objectWithoutProperties(props, _excluded2);
173
+
174
+ // 基础状态
175
+ var _useState = useState(0),
176
+ _useState2 = _slicedToArray(_useState, 2),
177
+ tableWidth = _useState2[0],
178
+ setTableWidth = _useState2[1];
179
+ var _useState3 = useState('middle'),
180
+ _useState4 = _slicedToArray(_useState3, 2),
181
+ density = _useState4[0],
182
+ setDensity = _useState4[1];
183
+ var _useState5 = useState(0),
184
+ _useState6 = _slicedToArray(_useState5, 2),
185
+ scrollTop = _useState6[0],
186
+ setScrollTop = _useState6[1];
187
+ var tableRef = useRef(null);
188
+ var scrollContainerRef = useRef(null);
189
+ var _DENSITY_CONFIG$densi = DENSITY_CONFIG[density],
190
+ rowHeight = _DENSITY_CONFIG$densi.rowHeight,
191
+ padding = _DENSITY_CONFIG$densi.padding,
192
+ fontSize = _DENSITY_CONFIG$densi.fontSize;
193
+
194
+ // 展开状态
195
+ var _useState7 = useState(new Set()),
196
+ _useState8 = _slicedToArray(_useState7, 2),
197
+ expandedKeys = _useState8[0],
198
+ setExpandedKeys = _useState8[1];
199
+
200
+ // 行选择配置
201
+ var _ref2 = rowSelection || {},
202
+ selType = _ref2.type,
203
+ _ref2$columnWidth = _ref2.columnWidth,
204
+ selWidth = _ref2$columnWidth === void 0 ? 48 : _ref2$columnWidth,
205
+ _ref2$selectedRowKeys = _ref2.selectedRowKeys,
206
+ selectedRowKeys = _ref2$selectedRowKeys === void 0 ? [] : _ref2$selectedRowKeys,
207
+ onSelChange = _ref2.onChange,
208
+ onSelect = _ref2.onSelect,
209
+ onSelectAll = _ref2.onSelectAll,
210
+ hideSelectAll = _ref2.hideSelectAll,
211
+ getCheckboxProps = _ref2.getCheckboxProps;
212
+ var showCheckbox = selType === 'checkbox';
213
+ var selectedSet = useMemo(function () {
214
+ return new Set(selectedRowKeys);
215
+ }, [selectedRowKeys]);
216
+ // 外部列状态是否启用
217
+ var useExternalColumnState = !!columnsStateMap && Object.keys(columnsStateMap).length > 0;
218
+
219
+ // 内部状态(兜底)
220
+ var _useState9 = useState(function () {
221
+ var map = {};
222
+ rawColumns.forEach(function (col, idx) {
223
+ var key = col.key || col.dataIndex || idx;
224
+ map[key] = {
225
+ show: true,
226
+ fixed: col.fixed,
227
+ order: idx
228
+ };
229
+ });
230
+ return map;
231
+ }),
232
+ _useState10 = _slicedToArray(_useState9, 2),
233
+ internalColumnsMap = _useState10[0],
234
+ setInternalColumnsMap = _useState10[1];
235
+
236
+ // 最终使用的 columnsMap(智能判断)
237
+ var columnsMap = useExternalColumnState ? columnsStateMap : internalColumnsMap;
238
+
239
+ // 列宽拖拽状态
240
+ var _useState11 = useState(function () {
241
+ return rawColumns.map(function (col) {
242
+ return _objectSpread(_objectSpread({}, col), {}, {
243
+ width: col.width || 120
244
+ });
245
+ });
246
+ }),
247
+ _useState12 = _slicedToArray(_useState11, 2),
248
+ rawColumnsWithWidth = _useState12[0],
249
+ setRawColumnsWithWidth = _useState12[1];
250
+ // 引导线状态
251
+ var _useState13 = useState(0),
252
+ _useState14 = _slicedToArray(_useState13, 2),
253
+ guideLineLeft = _useState14[0],
254
+ setGuideLineLeft = _useState14[1];
255
+ // 引导线是否可见
256
+ var _useState15 = useState(false),
257
+ _useState16 = _slicedToArray(_useState15, 2),
258
+ guideLineVisible = _useState16[0],
259
+ setGuideLineVisible = _useState16[1];
260
+ // 表头高度
261
+ var _useState17 = useState(0),
262
+ _useState18 = _slicedToArray(_useState17, 2),
263
+ headerHeight = _useState18[0],
264
+ setHeaderHeight = _useState18[1];
265
+ // 表格是否可见
266
+ var _useState19 = useState(false),
267
+ _useState20 = _slicedToArray(_useState19, 2),
268
+ qxVisible = _useState20[0],
269
+ setQxVisible = _useState20[1];
270
+ // 表格容器引用
271
+ var tableContainerRef = useRef(null);
272
+ // 重置数据引用
273
+ var resizeDataRef = useRef(null);
274
+
275
+ // 原始数据源
276
+ var _useState21 = useState([]),
277
+ _useState22 = _slicedToArray(_useState21, 2),
278
+ dataSource = _useState22[0],
279
+ setDataSource = _useState22[1];
280
+
281
+ // 拍平后的数据
282
+ var flatData = useMemo(function () {
283
+ return flattenTreeData(dataSource, expandedKeys);
284
+ }, [dataSource, expandedKeys]);
285
+
286
+ // 同步外部列状态(只有启用外部状态才同步)
287
+ useEffect(function () {
288
+ if (useExternalColumnState && columnsStateMap) {
289
+ // 不覆盖 internalMap
290
+ }
291
+ }, [columnsStateMap, useExternalColumnState]);
292
+
293
+ // 原始列变化时同步更新
294
+ useEffect(function () {
295
+ setRawColumnsWithWidth(rawColumns.map(function (col) {
296
+ return _objectSpread(_objectSpread({}, col), {}, {
297
+ width: col.width || 120
298
+ });
299
+ }));
300
+ }, [rawColumns]);
301
+
302
+ // 插入复选框列
303
+ var realColumns = useMemo(function () {
304
+ var cols = _toConsumableArray(rawColumnsWithWidth);
305
+ if (showCheckbox) {
306
+ cols.unshift({
307
+ key: '__SELECTION__',
308
+ // 复选框列 key
309
+ title: null,
310
+ // 复选框列标题
311
+ width: selWidth,
312
+ // 复选框列宽度
313
+ fixed: 'left',
314
+ // 复选框列固定位置
315
+ align: 'center',
316
+ // 复选框列对齐方式
317
+ isCheckbox: true,
318
+ // 是否为复选框列
319
+ hideInSetting: true // 是否隐藏在设置中
320
+ });
321
+ }
322
+ return cols;
323
+ }, [rawColumnsWithWidth, showCheckbox, selWidth]);
324
+
325
+ // 合并列、固定列、宽度计算
326
+ var _useMemo = useMemo(function () {
327
+ var list = realColumns.map(function (col, idx) {
328
+ var _state$order, _state$fixed;
329
+ if (col.isCheckbox) return _objectSpread(_objectSpread({}, col), {}, {
330
+ _show: true,
331
+ _key: col.key,
332
+ _fixed: 'left',
333
+ _order: -1,
334
+ _index: idx
335
+ });
336
+ var key = col.key || col.dataIndex || idx;
337
+ var state = columnsMap[key];
338
+ return _objectSpread(_objectSpread({}, col), {}, {
339
+ _key: key,
340
+ _show: (state === null || state === void 0 ? void 0 : state.show) !== false,
341
+ _order: (_state$order = state === null || state === void 0 ? void 0 : state.order) !== null && _state$order !== void 0 ? _state$order : idx,
342
+ _fixed: (_state$fixed = state === null || state === void 0 ? void 0 : state.fixed) !== null && _state$fixed !== void 0 ? _state$fixed : col.fixed,
343
+ _index: idx
344
+ });
345
+ }).sort(function (a, b) {
346
+ return a._order - b._order;
347
+ });
348
+ // 过滤可见列
349
+ var visibleCols = list.filter(function (col) {
350
+ return col._show;
351
+ });
352
+ // 过滤隐藏列
353
+ var hiddenCols = list.filter(function (col) {
354
+ return !col._show;
355
+ });
356
+ // 过滤左侧固定列
357
+ var leftCols = visibleCols.filter(function (c) {
358
+ return c._fixed === 'left';
359
+ });
360
+ // 过滤普通列
361
+ var normalCols = visibleCols.filter(function (c) {
362
+ return !c._fixed;
363
+ });
364
+ // 过滤右侧固定列
365
+ var rightCols = visibleCols.filter(function (c) {
366
+ return c._fixed === 'right';
367
+ });
368
+ var visibleOrdered = [].concat(_toConsumableArray(leftCols), _toConsumableArray(normalCols), _toConsumableArray(rightCols));
369
+ // 计算原始宽度
370
+ var sumOriginalW = visibleOrdered.reduce(function (s, c) {
371
+ return s + (c.width || 0);
372
+ }, 0);
373
+ // 计算剩余宽度
374
+ var remainingW = tableWidth - sumOriginalW;
375
+ // 计算总宽度
376
+ var sumW = sumOriginalW;
377
+ // 处理普通列宽度
378
+ if (remainingW > 0 && normalCols.length > 0) {
379
+ // 找到最后一个普通列索引
380
+ var lastNormalIdx = visibleOrdered.findIndex(function (c) {
381
+ return !c._fixed && c._show;
382
+ });
383
+ // 处理普通列宽度
384
+ if (lastNormalIdx !== -1) {
385
+ // 处理普通列宽度
386
+ visibleOrdered = _toConsumableArray(visibleOrdered);
387
+ // 处理普通列宽度
388
+ var targetCol = visibleOrdered[lastNormalIdx];
389
+ // 处理普通列宽度
390
+ visibleOrdered[lastNormalIdx] = _objectSpread(_objectSpread({}, targetCol), {}, {
391
+ width: targetCol.width + remainingW
392
+ });
393
+ sumW = tableWidth;
394
+ }
395
+ } else if (remainingW > 0) {
396
+ // 处理最后一个普通列宽度
397
+ var lastIdx = visibleOrdered.length - 1;
398
+ if (lastIdx >= 0) {
399
+ // 处理普通列宽度
400
+ visibleOrdered = _toConsumableArray(visibleOrdered);
401
+ // 处理普通列宽度
402
+ var _targetCol = visibleOrdered[lastIdx];
403
+ // 处理普通列宽度
404
+ visibleOrdered[lastIdx] = _objectSpread(_objectSpread({}, _targetCol), {}, {
405
+ width: _targetCol.width + remainingW
406
+ });
407
+ sumW = tableWidth;
408
+ }
409
+ }
410
+ // 合并可见列和隐藏列
411
+ list = [].concat(_toConsumableArray(visibleOrdered), _toConsumableArray(hiddenCols));
412
+ var hasHorizontalScroll = sumW > tableWidth;
413
+ var left = 0;
414
+ visibleOrdered.forEach(function (col) {
415
+ if (col._fixed === 'left') {
416
+ col.stickyLeft = left;
417
+ left += col.width;
418
+ }
419
+ });
420
+ // 处理右侧固定列宽度
421
+ var right = 0;
422
+ for (var i = visibleOrdered.length - 1; i >= 0; i--) {
423
+ var c = visibleOrdered[i];
424
+ if (c._fixed === 'right') {
425
+ c.stickyRight = right;
426
+ right += c.width;
427
+ }
428
+ }
429
+ // 表头样式
430
+ var processedColumns = list.map(function (col) {
431
+ return _objectSpread(_objectSpread({}, col), {}, {
432
+ // 表头样式
433
+ onHeaderCell: function onHeaderCell() {
434
+ return {
435
+ 'data-key': col._key,
436
+ 'data-is-checkbox': col.isCheckbox,
437
+ style: {
438
+ width: col.width,
439
+ minWidth: col.width,
440
+ maxWidth: col.width,
441
+ padding: col.isCheckbox ? '0' : padding,
442
+ fontSize: fontSize,
443
+ display: col._show ? undefined : 'none',
444
+ position: col._fixed ? 'sticky' : undefined,
445
+ left: col._fixed === 'left' ? col.stickyLeft : undefined,
446
+ right: col._fixed === 'right' ? "".concat(col.stickyRight + (hasHorizontalScroll ? SCROLLBAR_WIDTH : 0), "px") : undefined,
447
+ zIndex: col._fixed ? 100 : undefined,
448
+ background: '#fafafa',
449
+ textAlign: col.align || 'left'
450
+ },
451
+ onResizeStart: function onResizeStart(e) {
452
+ return !col.isCheckbox && handleResizeStart(e, col);
453
+ }
454
+ };
455
+ }
456
+ });
457
+ });
458
+ return {
459
+ mergedColumns: processedColumns,
460
+ sumW: sumW,
461
+ hasHorizontalScroll: hasHorizontalScroll
462
+ };
463
+ }, [realColumns, columnsMap, tableWidth, padding, fontSize]),
464
+ mergedColumns = _useMemo.mergedColumns,
465
+ sumW = _useMemo.sumW,
466
+ hasHorizontalScroll = _useMemo.hasHorizontalScroll;
467
+
468
+ // 表格总宽度
469
+ var totalWidth = useMemo(function () {
470
+ return sumW + (hasHorizontalScroll ? SCROLLBAR_WIDTH : 0);
471
+ }, [sumW, hasHorizontalScroll]);
472
+
473
+ // 虚拟滚动可视区域
474
+ var viewHeight = (scroll === null || scroll === void 0 ? void 0 : scroll.y) || 500;
475
+ var visibleStart = Math.max(0, Math.floor(scrollTop / rowHeight) - 1);
476
+ var visibleEnd = Math.min(flatData.length, visibleStart + Math.ceil(viewHeight / rowHeight) + 3);
477
+ var _useState23 = useState(false),
478
+ _useState24 = _slicedToArray(_useState23, 2),
479
+ flagAdd = _useState24[0],
480
+ setFlagAdd = _useState24[1];
481
+
482
+ // 展开/收起
483
+ var toggleExpand = useCallback(function (record) {
484
+ var key = record[rowKey || 'key'];
485
+ setExpandedKeys(function (prev) {
486
+ var newSet = new Set(prev);
487
+ newSet.has(key) ? newSet.delete(key) : newSet.add(key);
488
+ return newSet;
489
+ });
490
+ }, [rowKey]);
491
+
492
+ // 表头样式修复
493
+ useEffect(function () {
494
+ if (!tableRef.current) return;
495
+ var timer = setTimeout(function () {
496
+ try {
497
+ //获取表头的col元素
498
+ //@ts-ignore
499
+ var colgroup = tableRef.current.querySelector('.ant-table-header colgroup');
500
+ var cols = (colgroup === null || colgroup === void 0 ? void 0 : colgroup.querySelectorAll('col')) || [];
501
+ if (cols.length >= 2 && hasHorizontalScroll && !flagAdd) {
502
+ cols[cols.length - 2].style.width = "".concat(parseInt(cols[cols.length - 2].style.width || '0') + SCROLLBAR_WIDTH, "px");
503
+ cols[cols.length - 1].style.width = "".concat(SCROLLBAR_WIDTH, "px");
504
+ }
505
+ //获取表头的th元素
506
+ //@ts-ignore
507
+ var ths = tableRef.current.querySelectorAll('.ant-table-thead th') || [];
508
+ ths.forEach(function (th, i) {
509
+ var col = mergedColumns[i];
510
+ if (!col) return;
511
+ th.style.width = "".concat(col.width, "px");
512
+ th.style.minWidth = "".concat(col.width, "px");
513
+ th.style.maxWidth = "".concat(col.width, "px");
514
+ th.style.background = '#fafafa';
515
+ th.style.textAlign = col.align || 'left';
516
+ if (col._fixed === 'left') th.style.left = "".concat(col.stickyLeft, "px");
517
+ if (col._fixed === 'right') th.style.right = "".concat(col.stickyRight + (hasHorizontalScroll ? SCROLLBAR_WIDTH : 0), "px");
518
+ if (col.isCheckbox && !hideSelectAll) {
519
+ var allKeys = dataSource.map(function (item) {
520
+ return item[rowKey || 'key'];
521
+ });
522
+ var checked = allKeys.length > 0 && selectedRowKeys.length === allKeys.length;
523
+ var indeterminate = selectedRowKeys.length > 0 && !checked;
524
+ th.innerHTML = '';
525
+ var checkbox = document.createElement('input');
526
+ checkbox.type = 'checkbox';
527
+ checkbox.checked = checked;
528
+ checkbox.indeterminate = indeterminate;
529
+ checkbox.style.cursor = 'pointer';
530
+ checkbox.style.width = '16px';
531
+ checkbox.style.height = '16px';
532
+ checkbox.style.margin = '0 auto';
533
+ checkbox.style.opacity = checked ? '1' : '0.3';
534
+ checkbox.onchange = function (e) {
535
+ var target = e.target;
536
+ var newKeys = target.checked ? allKeys : [];
537
+ onSelChange === null || onSelChange === void 0 || onSelChange(newKeys, target.checked ? dataSource : []);
538
+ onSelectAll === null || onSelectAll === void 0 || onSelectAll(target.checked);
539
+ };
540
+ th.appendChild(checkbox);
541
+ }
542
+ });
543
+ setFlagAdd(true);
544
+ var lastTh = ths[ths.length - 1];
545
+ if (lastTh && hasHorizontalScroll) {
546
+ lastTh.style.position = 'sticky';
547
+ lastTh.style.right = '0';
548
+ lastTh.style.width = "".concat(SCROLLBAR_WIDTH, "px");
549
+ lastTh.style.minWidth = "".concat(SCROLLBAR_WIDTH, "px");
550
+ lastTh.style.maxWidth = "".concat(SCROLLBAR_WIDTH, "px");
551
+ lastTh.style.zIndex = 99;
552
+ lastTh.style.background = '#fafafa';
553
+ }
554
+ } catch (e) {}
555
+ }, 100);
556
+ return function () {
557
+ return clearTimeout(timer);
558
+ };
559
+ }, [mergedColumns, dataSource, selectedRowKeys, hideSelectAll, rowKey, onSelChange, onSelectAll, hasHorizontalScroll]);
560
+
561
+ // 滚动事件
562
+ var handleScroll = useCallback(function (e) {
563
+ var _tableRef$current;
564
+ setScrollTop(e.target.scrollTop);
565
+ var header = (_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : _tableRef$current.querySelector('.ant-table-header');
566
+ if (header) header.scrollLeft = e.target.scrollLeft;
567
+ }, []);
568
+
569
+ // 同步外部数据源
570
+ useEffect(function () {
571
+ if (props.dataSource) setDataSource(props.dataSource);
572
+ }, [props.dataSource]);
573
+
574
+ // 表格请求
575
+ var loadData = useCallback( /*#__PURE__*/function () {
576
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
577
+ var res, _res$data, list;
578
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
579
+ while (1) switch (_context.prev = _context.next) {
580
+ case 0:
581
+ _context.next = 2;
582
+ return request(_objectSpread(_objectSpread({}, params), {}, {
583
+ limit: 999999,
584
+ page: 1
585
+ }));
586
+ case 2:
587
+ res = _context.sent;
588
+ if (!res.success) {
589
+ _context.next = 7;
590
+ break;
591
+ }
592
+ list = ((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.records) || res.data || [];
593
+ setDataSource(list);
594
+ return _context.abrupt("return", _objectSpread(_objectSpread({}, res), {}, {
595
+ data: list,
596
+ success: true
597
+ }));
598
+ case 7:
599
+ return _context.abrupt("return", {
600
+ data: [],
601
+ total: 0,
602
+ success: false
603
+ });
604
+ case 8:
605
+ case "end":
606
+ return _context.stop();
607
+ }
608
+ }, _callee);
609
+ }));
610
+ return function (_x) {
611
+ return _ref3.apply(this, arguments);
612
+ };
613
+ }(), [request]);
614
+
615
+ // 获取滚动元素
616
+ var getScrollEl = function getScrollEl() {
617
+ var _tableContainerRef$cu;
618
+ return (_tableContainerRef$cu = tableContainerRef.current) === null || _tableContainerRef$cu === void 0 ? void 0 : _tableContainerRef$cu.querySelector('.ant-table-body');
619
+ };
620
+
621
+ // 更新表头高度
622
+ var updateHeaderHeight = useCallback(function () {
623
+ var _tableContainerRef$cu2;
624
+ var el = (_tableContainerRef$cu2 = tableContainerRef.current) === null || _tableContainerRef$cu2 === void 0 ? void 0 : _tableContainerRef$cu2.querySelector('.ant-table-thead');
625
+ if (el) setHeaderHeight(el.offsetHeight);
626
+ }, []);
627
+
628
+ // 列宽拖拽事件
629
+ useEffect(function () {
630
+ updateHeaderHeight();
631
+ setTimeout(updateHeaderHeight, 100);
632
+ }, [mergedColumns]);
633
+
634
+ // 列宽拖拽
635
+ var handleResizeStart = useCallback(function (e, column) {
636
+ var _tableContainerRef$cu3;
637
+ e.preventDefault();
638
+ e.stopPropagation();
639
+ var scrollEl = getScrollEl();
640
+ var rect = (_tableContainerRef$cu3 = tableContainerRef.current) === null || _tableContainerRef$cu3 === void 0 ? void 0 : _tableContainerRef$cu3.getBoundingClientRect();
641
+ var mouseX = e.clientX;
642
+ var currentScroll = (scrollEl === null || scrollEl === void 0 ? void 0 : scrollEl.scrollLeft) || 0;
643
+ //@ts-ignore
644
+ var originIndex = rawColumnsWithWidth.findIndex(function (c) {
645
+ return (c.key || c.dataIndex) === (column.key || column.dataIndex);
646
+ });
647
+ if (originIndex === -1) return;
648
+ resizeDataRef.current = {
649
+ originIndex: originIndex,
650
+ startX: mouseX,
651
+ startWidth: column.width,
652
+ containerLeft: rect.left,
653
+ scrollLeft: currentScroll
654
+ };
655
+ var realPos = mouseX - rect.left + currentScroll;
656
+ setGuideLineLeft(realPos);
657
+ setGuideLineVisible(true);
658
+ document.addEventListener('mousemove', handleMouseMove);
659
+ document.addEventListener('mouseup', handleResizeEnd);
660
+ }, [rawColumnsWithWidth]);
661
+
662
+ // 列宽拖拽中
663
+ var handleMouseMove = useCallback(function (e) {
664
+ var _getScrollEl;
665
+ if (!resizeDataRef.current) return;
666
+ var _resizeDataRef$curren = resizeDataRef.current,
667
+ containerLeft = _resizeDataRef$curren.containerLeft,
668
+ scrollLeft = _resizeDataRef$curren.scrollLeft;
669
+ var currentScroll = ((_getScrollEl = getScrollEl()) === null || _getScrollEl === void 0 ? void 0 : _getScrollEl.scrollLeft) || 0;
670
+ var mouseX = e.clientX;
671
+ var realPos = mouseX - containerLeft + (currentScroll - scrollLeft);
672
+ setGuideLineLeft(realPos);
673
+ }, []);
674
+
675
+ // 列宽拖拽结束
676
+ var handleResizeEnd = useCallback(function (e) {
677
+ if (!resizeDataRef.current) return;
678
+ var _resizeDataRef$curren2 = resizeDataRef.current,
679
+ originIndex = _resizeDataRef$curren2.originIndex,
680
+ startX = _resizeDataRef$curren2.startX,
681
+ startWidth = _resizeDataRef$curren2.startWidth;
682
+ var diff = e.clientX - startX;
683
+ var newWidth = Math.max(80, startWidth + diff);
684
+ // 更新列宽
685
+ //@ts-ignore
686
+ setRawColumnsWithWidth(function (prev) {
687
+ var next = _toConsumableArray(prev);
688
+ if (originIndex >= 0 && originIndex < next.length) {
689
+ next[originIndex] = _objectSpread(_objectSpread({}, next[originIndex]), {}, {
690
+ width: newWidth
691
+ });
692
+ }
693
+ return next;
694
+ });
695
+ setGuideLineVisible(false);
696
+ resizeDataRef.current = null;
697
+ document.removeEventListener('mousemove', handleMouseMove);
698
+ document.removeEventListener('mouseup', handleResizeEnd);
699
+ }, []);
700
+
701
+ // 虚拟滚动主体
702
+ var renderVirtualBody = useCallback(function () {
703
+ var firstDataColIndex = mergedColumns.findIndex(function (col) {
704
+ return !col.isCheckbox && col.key !== '__SELECTION__';
705
+ });
706
+ return /*#__PURE__*/React.createElement("div", {
707
+ ref: scrollContainerRef,
708
+ className: "virtual-body-scroll",
709
+ style: {
710
+ height: viewHeight,
711
+ overflow: 'auto'
712
+ },
713
+ onScroll: handleScroll
714
+ }, /*#__PURE__*/React.createElement("div", {
715
+ style: {
716
+ height: flatData.length * rowHeight,
717
+ width: totalWidth - (hasHorizontalScroll ? SCROLLBAR_WIDTH : 0),
718
+ position: 'relative'
719
+ }
720
+ }, /*#__PURE__*/React.createElement("div", {
721
+ style: {
722
+ position: 'absolute',
723
+ top: visibleStart * rowHeight
724
+ }
725
+ }, flatData.slice(visibleStart, visibleEnd).map(function (record, idx) {
726
+ var _record;
727
+ var rowIdx = visibleStart + idx;
728
+ var key = (_record = record[rowKey || 'key']) !== null && _record !== void 0 ? _record : rowIdx;
729
+ var checked = selectedSet.has(key);
730
+ var checkboxProps = (getCheckboxProps === null || getCheckboxProps === void 0 ? void 0 : getCheckboxProps(record)) || {};
731
+ var level = record._level || 0;
732
+ var isLeaf = !record.children || record.children.length === 0;
733
+ var expanded = expandedKeys.has(key);
734
+ return /*#__PURE__*/React.createElement("div", {
735
+ key: key,
736
+ className: classNames('virtual-row', {
737
+ odd: rowIdx % 2
738
+ }),
739
+ style: {
740
+ display: 'flex',
741
+ width: totalWidth - (hasHorizontalScroll ? SCROLLBAR_WIDTH : 0),
742
+ height: rowHeight,
743
+ alignItems: 'center'
744
+ }
745
+ }, mergedColumns.map(function (col, colIndex) {
746
+ if (!col._show || col.key === 'children') return null;
747
+ var sticky = col._fixed === 'left' ? {
748
+ position: 'sticky',
749
+ left: col.stickyLeft,
750
+ zIndex: 2
751
+ } : col._fixed === 'right' ? {
752
+ position: 'sticky',
753
+ right: col.stickyRight,
754
+ zIndex: 2
755
+ } : {};
756
+ var align = col.align || 'left';
757
+ var isFirstDataCol = colIndex === firstDataColIndex;
758
+ var content;
759
+ if (col.isCheckbox) {
760
+ content = /*#__PURE__*/React.createElement(_Checkbox, _extends({}, checkboxProps, {
761
+ checked: checked,
762
+ onChange: function onChange(e) {
763
+ var newSet = new Set(selectedRowKeys);
764
+ e.target.checked ? newSet.add(key) : newSet.delete(key);
765
+ var newKeys = Array.from(newSet);
766
+ onSelChange === null || onSelChange === void 0 || onSelChange(newKeys);
767
+ }
768
+ }));
769
+ } else {
770
+ var val = record[col.dataIndex];
771
+
772
+ // ---------- 1. 先处理 valueEnum ----------
773
+ var displayValue = val;
774
+ if (col.valueEnum && _typeof(col.valueEnum) === 'object') {
775
+ var enumItem = col.valueEnum[val];
776
+ if (enumItem && _typeof(enumItem) === 'object') {
777
+ var _enumItem$text;
778
+ displayValue = (_enumItem$text = enumItem.text) !== null && _enumItem$text !== void 0 ? _enumItem$text : val;
779
+ } else {
780
+ displayValue = enumItem !== null && enumItem !== void 0 ? enumItem : val;
781
+ }
782
+ }
783
+
784
+ // ---------- 2. 处理 valueType ----------
785
+ if (displayValue != null && displayValue !== '') {
786
+ if (col.valueType === 'date') {
787
+ displayValue = dayjs(displayValue).format('YYYY-MM-DD');
788
+ } else if (col.valueType === 'dateTime') {
789
+ displayValue = dayjs(displayValue).format('YYYY-MM-DD HH:mm:ss');
790
+ }
791
+ }
792
+
793
+ // ---------- 3. 空值兜底 ----------
794
+ if (displayValue == null || displayValue === '') {
795
+ displayValue = '-';
796
+ }
797
+
798
+ // ---------- 4. 传给 render(如果有) ----------
799
+ var finalContent = displayValue;
800
+ if (col.render) {
801
+ finalContent = col.render(displayValue, record, rowIdx);
802
+ }
803
+
804
+ // ---------- 5. 省略 + Tooltip ----------
805
+ content = /*#__PURE__*/React.createElement("div", {
806
+ style: {
807
+ display: 'flex',
808
+ alignItems: 'center',
809
+ width: '100%',
810
+ height: '100%',
811
+ justifyContent: 'flex-start'
812
+ }
813
+ }, isFirstDataCol && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
814
+ style: {
815
+ width: level * 12,
816
+ flexShrink: 0
817
+ }
818
+ }), !isLeaf ? /*#__PURE__*/React.createElement("div", {
819
+ onClick: function onClick() {
820
+ return toggleExpand(record);
821
+ },
822
+ style: {
823
+ width: 16,
824
+ height: 16,
825
+ display: 'flex',
826
+ alignItems: 'center',
827
+ justifyContent: 'center',
828
+ cursor: 'pointer',
829
+ marginRight: 6,
830
+ flexShrink: 0,
831
+ border: '1px solid #d9d9d9',
832
+ borderRadius: '6px',
833
+ background: '#fff',
834
+ fontSize: 10,
835
+ transition: 'transform 0.4s ease',
836
+ transform: expanded ? 'rotate(180deg)' : 'rotate(0deg)',
837
+ color: expanded ? '#1890ff' : '#555',
838
+ boxShadow: expanded ? '0 0 0 2px rgba(24,144,255,0.2)' : 'none'
839
+ }
840
+ }, expanded ? /*#__PURE__*/React.createElement(MinusOutlined, {
841
+ style: {
842
+ fontSize: 10
843
+ }
844
+ }) : /*#__PURE__*/React.createElement(PlusOutlined, {
845
+ style: {
846
+ fontSize: 10
847
+ }
848
+ })) : /*#__PURE__*/React.createElement("div", {
849
+ style: {
850
+ width: 16,
851
+ marginRight: 6,
852
+ flexShrink: 0
853
+ }
854
+ })), /*#__PURE__*/React.createElement("div", {
855
+ style: {
856
+ width: '100%',
857
+ textAlign: align
858
+ }
859
+ }, function () {
860
+ // 超出部分显示Tooltip
861
+ var Comp = function Comp() {
862
+ var ref = useRef(null);
863
+ var _useState25 = useState(false),
864
+ _useState26 = _slicedToArray(_useState25, 2),
865
+ showTip = _useState26[0],
866
+ setShowTip = _useState26[1];
867
+ useEffect(function () {
868
+ var el = ref.current;
869
+ if (!el) return;
870
+ var need = el.scrollWidth > el.clientWidth;
871
+ setShowTip(need);
872
+ }, [finalContent]);
873
+ var node = /*#__PURE__*/React.createElement("div", {
874
+ ref: ref,
875
+ style: {
876
+ width: '100%',
877
+ overflow: 'hidden',
878
+ textOverflow: 'ellipsis',
879
+ whiteSpace: 'nowrap',
880
+ textAlign: align
881
+ }
882
+ }, finalContent);
883
+ if (showTip) {
884
+ return /*#__PURE__*/React.createElement(_Tooltip, {
885
+ title: finalContent,
886
+ placement: "top",
887
+ mouseEnterDelay: 0.2,
888
+ overlayStyle: {
889
+ maxWidth: 500
890
+ }
891
+ }, node);
892
+ }
893
+ return node;
894
+ };
895
+ return /*#__PURE__*/React.createElement(Comp, null);
896
+ }()));
897
+ }
898
+ return /*#__PURE__*/React.createElement("div", {
899
+ key: col._key,
900
+ className: "virtual-cell"
901
+ //@ts-ignore
902
+ ,
903
+ style: _objectSpread(_objectSpread({
904
+ width: col.width,
905
+ minWidth: col.width,
906
+ maxWidth: col.width,
907
+ padding: padding,
908
+ fontSize: fontSize,
909
+ height: rowHeight,
910
+ display: 'flex',
911
+ alignItems: 'center',
912
+ borderRight: '1px solid #f0f0f0',
913
+ boxSizing: 'border-box'
914
+ }, sticky), {}, {
915
+ background: rowIdx % 2 ? '#fafafa' : '#fff',
916
+ overflow: 'hidden'
917
+ })
918
+ }, content);
919
+ }));
920
+ }))));
921
+ }, [flatData, rowHeight, viewHeight, totalWidth, visibleStart, visibleEnd, handleScroll, mergedColumns, selectedSet, selectedRowKeys, onSelChange, rowKey, toggleExpand, expandedKeys, padding, fontSize, hasHorizontalScroll]);
922
+ // 导出
923
+ var generateHeaders = function generateHeaders(columns) {
924
+ //@ts-ignore
925
+ return columns.filter(function (c) {
926
+ return !c.isCheckbox && c.title !== '操作';
927
+ }).map(function (c) {
928
+ return {
929
+ header: c.title,
930
+ key: c.dataIndex,
931
+ width: 20
932
+ };
933
+ });
934
+ };
935
+ //@ts-ignore
936
+ var saveWorkbook = function saveWorkbook(wb, name) {
937
+ return wb.xlsx.writeBuffer().then(function (b) {
938
+ return saveAs(new Blob([b]), name);
939
+ });
940
+ };
941
+ var tableExport = function tableExport(data, cols, name) {
942
+ var wb = new ExcelJs.Workbook();
943
+ var ws = wb.addWorksheet('sheet');
944
+ ws.columns = generateHeaders(cols);
945
+ ws.addRows(data);
946
+ saveWorkbook(wb, name + '.xlsx');
947
+ };
948
+ var getData = /*#__PURE__*/function () {
949
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
950
+ var _res$data2;
951
+ var res;
952
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
953
+ while (1) switch (_context2.prev = _context2.next) {
954
+ case 0:
955
+ _context2.next = 2;
956
+ return request({
957
+ current: 1,
958
+ pageSize: 99999
959
+ });
960
+ case 2:
961
+ res = _context2.sent;
962
+ if (res.success) tableExport(((_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : _res$data2.records) || res.data, columnsFnExport || rawColumns, exportFileName || '导出');
963
+ case 4:
964
+ case "end":
965
+ return _context2.stop();
966
+ }
967
+ }, _callee2);
968
+ }));
969
+ return function getData() {
970
+ return _ref4.apply(this, arguments);
971
+ };
972
+ }();
973
+
974
+ // ==============================================
975
+ // 列状态变更
976
+ // ==============================================
977
+ var handleColChange = useCallback(function (m) {
978
+ if (useExternalColumnState) {
979
+ // 父组件有传 → 调用父的方法
980
+ onColumnsStateChange === null || onColumnsStateChange === void 0 || onColumnsStateChange(m);
981
+ } else {
982
+ // 父组件没传 → 更新自己内部状态
983
+ setInternalColumnsMap(function (p) {
984
+ return _objectSpread(_objectSpread({}, p), m);
985
+ });
986
+ }
987
+ }, [onColumnsStateChange, useExternalColumnState]);
988
+ return /*#__PURE__*/React.createElement(StyleProvider, {
989
+ hashPriority: "high",
990
+ transformers: [legacyLogicalPropertiesTransformer]
991
+ }, /*#__PURE__*/React.createElement("div", {
992
+ ref: tableContainerRef,
993
+ style: {
994
+ width: '100%',
995
+ position: 'relative'
996
+ }
997
+ }, /*#__PURE__*/React.createElement(ResizeGuideLine, {
998
+ visible: guideLineVisible,
999
+ left: guideLineLeft,
1000
+ topOffset: headerHeight
1001
+ }), /*#__PURE__*/React.createElement("div", {
1002
+ ref: tableRef,
1003
+ style: {
1004
+ width: '100%'
1005
+ }
1006
+ }, /*#__PURE__*/React.createElement(ResizeObserver, {
1007
+ onResize: function onResize(_ref5) {
1008
+ var width = _ref5.width;
1009
+ return setTableWidth(width);
1010
+ }
1011
+ }, /*#__PURE__*/React.createElement(ProTable, _extends({}, restProps, {
1012
+ tableLayout: "fixed",
1013
+ size: density,
1014
+ rowKey: rowKey || 'id',
1015
+ columns: mergedColumns,
1016
+ rowClassName: function rowClassName() {
1017
+ return 'ant-table-row';
1018
+ },
1019
+ request: loadData,
1020
+ dataSource: [],
1021
+ scroll: _objectSpread(_objectSpread({}, scroll), {}, {
1022
+ x: totalWidth
1023
+ }),
1024
+ onSizeChange: setDensity,
1025
+ columnsState: {
1026
+ value: columnsMap,
1027
+ onChange: handleColChange
1028
+ },
1029
+ components: {
1030
+ header: {
1031
+ cell: ResizableTitle
1032
+ },
1033
+ body: virtual ? renderVirtualBody : undefined
1034
+ },
1035
+ rowSelection: undefined,
1036
+ toolBarRender: function toolBarRender() {
1037
+ var _storage$getSessionIt;
1038
+ return [/*#__PURE__*/React.createElement(_Button, {
1039
+ type: "primary",
1040
+ size: "small",
1041
+ hidden: exportHidden,
1042
+ onClick: getData
1043
+ }, "\u5BFC\u51FA")].concat(_toConsumableArray((_toolBarRender === null || _toolBarRender === void 0 ? void 0 : _toolBarRender()) || []), [((_storage$getSessionIt = storage.getSessionItem('user')) === null || _storage$getSessionIt === void 0 ? void 0 : _storage$getSessionIt.username) === 'venus' && /*#__PURE__*/React.createElement(SlidersOutlined, {
1044
+ style: {
1045
+ marginLeft: 8,
1046
+ cursor: 'pointer'
1047
+ },
1048
+ onClick: function onClick() {
1049
+ return setQxVisible(true);
1050
+ }
1051
+ })]);
1052
+ }
1053
+ })))), /*#__PURE__*/React.createElement(DrawerDataAuth, {
1054
+ open: qxVisible,
1055
+ onClose: function onClose() {
1056
+ return setQxVisible(false);
1057
+ }
1058
+ })));
1059
+ };
1060
+ export default DataViewTable;