@bos-model-alpha/data
Version:
数据管理
270 lines (269 loc) • 17.8 kB
JavaScript
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState, useRef, useEffect } from 'react';
import { Input, Menu, Dropdown, Button, Switch, Modal } from 'antd';
import * as api from '@bos-alpha/common/lib/services';
import { Icon, AdvancedSearch } from '@bos-alpha/common/lib/components';
import styled from '@emotion/styled';
import { CustomTable } from '../custom-table';
import { InfoCard } from '../info-card';
import { prefixCls } from '@bos-alpha/common';
/**
*
* @param {classDefined} 当前类定义
* @param {attributes} 当前类模型属性
* @returns
*/
export var DocTable = function (_a) {
var classDefined = _a.classDefined, attributes = _a.attributes;
// 可选属性列
var _b = useState([]), attrList = _b[0], setAttrList = _b[1];
// 表格列
var _c = useState([]), columns = _c[0], setColumns = _c[1];
// 菜单是否显示
var _d = useState(false), visible = _d[0], setVisible = _d[1];
// 搜索框检索词
var _e = useState(''), keywords = _e[0], setKeywords = _e[1];
// 当前类名
var curClassName = useRef('');
// 检索参数
var _f = useState({
noRelation: true,
page: 1,
per_page: 10,
conditions: [],
keyword: ''
}), searchParams = _f[0], setSearchParams = _f[1];
var _g = useState([]), tableData = _g[0], setTableData = _g[1];
var _h = useState(0), total = _h[0], setTotal = _h[1];
// 数据详情弹窗
var _j = useState(false), detailModalVisible = _j[0], setDetailModalVisible = _j[1];
// 数据详情
var _k = useState([]), detailInfo = _k[0], setDetailInfo = _k[1];
// 获取类数据列表
useEffect(function () {
if (!classDefined)
return;
// 暂存类切换 防止初始化时触发两次
// if (curClassName.current === classDefined.className) return;
curClassName.current = classDefined.className;
getDataList();
}, [searchParams]); // eslint-disable-line react-hooks/exhaustive-deps
// 切换类
useEffect(function () {
if (!classDefined)
return;
setSearchParams(__assign(__assign({}, searchParams), { page: 1, keyword: '' }));
setKeywords('');
}, [classDefined]); // eslint-disable-line react-hooks/exhaustive-deps
// doc对象类 可选属性列
useEffect(function () {
var list = attributes
.filter(function (item) { return item.code !== 'bosclass'; })
.map(function (item) {
item.checked = item.code === 'code';
return item;
});
setAttrList(list);
}, [attributes]); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(function () {
updateColumns(attrList);
}, [attrList]); // eslint-disable-line react-hooks/exhaustive-deps
// 更新columns
var updateColumns = function (list) {
var bosclassObj = attributes.find(function (item) { return item.code === 'bosclass'; });
var base = baseColumns(bosclassObj);
var appearKeys = attrList
.filter(function (item) { return item.checked; })
.map(function (item) { return item.code; });
var appends = list
.filter(function (item) { return appearKeys.indexOf(item.code) >= 0; })
.map(function (item) { return ({
dataIndex: item.code,
ellipsis: true,
title: (_jsxs("div", { children: [_jsx("div", { children: item.code }), _jsxs("div", { children: ["(", item.description, ")"] })] }))
}); });
setColumns(__spreadArray(__spreadArray([], base, true), appends, true));
};
// 获取类数据
var getDataList = function () { return __awaiter(void 0, void 0, void 0, function () {
var keyword, conditions, params, condition, className, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
keyword = searchParams.keyword, conditions = searchParams.conditions, params = __rest(searchParams, ["keyword", "conditions"]);
condition = [];
if (keyword) {
condition.push({
field: '_key',
operator: 'like',
value: keyword,
logic: 'and'
});
}
if (conditions.length) {
condition = conditions;
}
className = classDefined.className;
return [4 /*yield*/, api.queryEntity(className, {
data: {
condition: condition
},
params: params
})];
case 1:
res = _a.sent();
setTableData(res.data);
setTotal(res.count);
return [2 /*return*/];
}
});
}); };
var dataClick = function (record) {
var list = Object.keys(record).map(function (key) {
var curLabel = attributes.find(function (item) { return item.code === key; });
var label = key;
if (curLabel) {
label = "".concat(key, "(").concat(curLabel.description, ")");
}
var value = record[key];
if (typeof value === 'object' && value !== null) {
value = JSON.stringify(value);
}
return {
label: label,
value: value
};
});
setDetailInfo(list);
setDetailModalVisible(true);
};
// 基础列 区分对象类 和 关系类
var baseColumns = function (bosclassObj) {
return [
{
dataIndex: 'bosclass',
width: 200,
title: (_jsxs("div", { children: [_jsx("div", { children: "bosclass" }), (bosclassObj === null || bosclassObj === void 0 ? void 0 : bosclassObj.description) ? (_jsxs("div", { children: ["(", bosclassObj === null || bosclassObj === void 0 ? void 0 : bosclassObj.description, ")"] })) : null] }))
},
{
dataIndex: 'key',
title: 'id',
render: function (id, record) { return (_jsx(Link, __assign({ onClick: function () { return dataClick(record); } }, { children: id }))); }
}
];
};
// 选择显示列
var onAttrCheck = function (checked, record) {
setAttrList(attrList.map(function (item) {
if (item.code === record.code) {
return __assign(__assign({}, item), { checked: checked });
}
return item;
}));
};
// 高级搜索
var handleQuery = function (vals) {
setSearchParams(__assign(__assign({}, searchParams), { keyword: '', conditions: vals }));
// 清空快捷搜索 关闭高级搜索
setKeywords('');
};
return (_jsxs("div", { children: [_jsxs(TopBar, { children: [_jsxs(Search, { children: [_jsx(Input.Search, { className: "ipt", placeholder: "\u901A\u8FC7ID\u5FEB\u901F\u68C0\u7D22", value: keywords, onInput: function (e) {
return setKeywords(e.target.value);
}, onSearch: function (val) {
return setSearchParams(__assign(__assign({}, searchParams), { page: 1, keyword: val }));
} }), _jsx(AdvancedSearch, { isReset: true, modelData: [], modelKeys: [], fieldOptions: attributes.map(function (item) { return ({
label: item.code,
value: item.code
}); }), onQuery: handleQuery }), _jsx(Button, __assign({ type: "link", onClick: function (e) {
setKeywords('');
setSearchParams(__assign(__assign({}, searchParams), { conditions: [], page: 1, keyword: '' }));
} }, { children: "\u91CD\u7F6E" }))] }), _jsx(Dropdown, __assign({ overlay: _jsx(AttrMenu, { children: attrList.map(function (item, index) { return (_jsx(Menu.Item, { children: _jsxs(AttrItem, { children: [_jsxs("span", { children: [item.code, "(", item.description, ")"] }), _jsx(Switch, { checked: item.checked, onChange: function (checked) {
return onAttrCheck(checked, item);
} })] }) }, index)); }) }), trigger: ['click'], visible: visible, onVisibleChange: setVisible }, { children: _jsxs(Button, __assign({ className: "attr-btn" }, { children: ["\u8BBE\u7F6E\u9700\u8981\u663E\u793A\u7684\u5C5E\u6027\u5217", _jsx(Icon, { type: "iconicon_arrowdown" })] })) }))] }), _jsx(CustomTable, { rowKey: function () { return Math.random(); }, columns: columns, dataSource: tableData, scroll: { x: 'max-content' }, style: { width: '100%' }, pagination: {
total: total,
pageSize: searchParams.per_page,
current: searchParams.page,
hideOnSinglePage: true,
onChange: function (page) {
setSearchParams(__assign(__assign({}, searchParams), { page: page }));
}
} }), _jsxs(Modal, __assign({ visible: detailModalVisible, title: "\u6570\u636E\u8BE6\u60C5", width: 814, onCancel: function () { return setDetailModalVisible(false); }, footer: null }, { children: [_jsx(InfoCard, { curClass: classDefined, isDetail: true }), detailInfo.map(function (item, index) { return (_jsxs(DetailRow, { children: [_jsx("div", __assign({ className: "detail-label" }, { children: item.label })), _jsx("div", __assign({ className: "detail-value" }, { children: item.value }))] }, index)); })] }))] }));
};
var Search = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n margin-bottom: 16px;\n & > .ipt {\n width: 350px;\n margin-right: 15px;\n .", "-input-group > .", "-input:first-of-type {\n border-radius: 16px;\n border-bottom-right-radius: 16px;\n border-bottom-right-radius: 16px;\n position: relative;\n }\n .", "-input-group > .", "-input-group-addon:last-of-type {\n background: none;\n position: absolute;\n z-index: 2;\n left: inherit;\n right: 36px;\n .", "-btn {\n border: 0;\n background: none;\n }\n }\n }\n"], ["\n display: flex;\n margin-bottom: 16px;\n & > .ipt {\n width: 350px;\n margin-right: 15px;\n .", "-input-group > .", "-input:first-of-type {\n border-radius: 16px;\n border-bottom-right-radius: 16px;\n border-bottom-right-radius: 16px;\n position: relative;\n }\n .", "-input-group > .", "-input-group-addon:last-of-type {\n background: none;\n position: absolute;\n z-index: 2;\n left: inherit;\n right: 36px;\n .", "-btn {\n border: 0;\n background: none;\n }\n }\n }\n"])), prefixCls, prefixCls, prefixCls, prefixCls, prefixCls);
var Link = styled.span(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n color: #2878ff;\n cursor: pointer;\n"], ["\n color: #2878ff;\n cursor: pointer;\n"])));
var AttrMenu = styled(Menu)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n max-height: 300px;\n overflow-y: auto;\n"], ["\n max-height: 300px;\n overflow-y: auto;\n"])));
var TopBar = styled.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n display: flex;\n justify-content: space-between;\n .attr-btn {\n color: rgba(0, 0, 0, 0.65);\n }\n"], ["\n display: flex;\n justify-content: space-between;\n .attr-btn {\n color: rgba(0, 0, 0, 0.65);\n }\n"])));
var AttrItem = styled.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n display: flex;\n justify-content: space-between;\n"], ["\n display: flex;\n justify-content: space-between;\n"])));
var DetailRow = styled.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n display: flex;\n height: 40px;\n line-height: 40px;\n color: rgba(0, 0, 0, 0.65);\n border-bottom: 1px solid #e8e8e8;\n & > .detail-label {\n width: 30%;\n font-weight: 500;\n padding-left: 16px;\n color: rgba(0, 0, 0, 0.85);\n font-weight: 500;\n background: #fafafa;\n }\n & > .detail-value {\n background-color: #fff;\n width: 70%;\n padding-left: 16px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n"], ["\n display: flex;\n height: 40px;\n line-height: 40px;\n color: rgba(0, 0, 0, 0.65);\n border-bottom: 1px solid #e8e8e8;\n & > .detail-label {\n width: 30%;\n font-weight: 500;\n padding-left: 16px;\n color: rgba(0, 0, 0, 0.85);\n font-weight: 500;\n background: #fafafa;\n }\n & > .detail-value {\n background-color: #fff;\n width: 70%;\n padding-left: 16px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n"])));
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;