@bos-alpha/progress
Version:
进度管理
178 lines (177 loc) • 10.7 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 };
}
};
import { jsx as _jsx } from "react/jsx-runtime";
import React, { useEffect } from 'react';
import { Form, Row, Col, Input, Select, DatePicker, message } from 'antd';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import locale from 'antd/es/date-picker/locale/zh_CN';
import { Icon } from '@bos-alpha/common';
import styled from '@emotion/styled';
var RangePicker = DatePicker.RangePicker;
var fileSizeFix = function (size) {
return size ? "".concat(Number.parseFloat((size / 1024 / 1024).toFixed(2)), "M") : '';
};
/**
*
* 管理员中心 表格数据条件筛选
*/
export var CustomForm = function (_a) {
var readOnly = _a.readOnly, _b = _a.span, span = _b === void 0 ? 24 : _b, _c = _a.labelCol, labelCol = _c === void 0 ? 4 : _c, items = _a.items, _d = _a.values, values = _d === void 0 ? {} : _d, _e = _a.isReset, isReset = _e === void 0 ? false : _e, _f = _a.isFooterBtns, isFooterBtns = _f === void 0 ? true : _f, onSubmit = _a.onSubmit, onCancel = _a.onCancel;
// 表单
var form = Form.useForm()[0];
// 表单值发生变化,填充表单数据
useEffect(function () {
var newValues = __assign({}, values);
// 表单数据展示格式化
items.forEach(function (item) {
var name = item.name, inputType = item.inputType, disabled = item.disabled;
// 编辑模式下 DatePicker数据初始化只接收monent时间格式
if (inputType === 'dateTime' && !disabled) {
newValues[name] = dayjs(Number(values[name]));
}
// 查看模式 或 字段disabled只读模式下,所有字段格式化显示
if (readOnly || disabled) {
newValues[name] = dataFormat(item, values[name]);
}
});
form.setFieldsValue(newValues);
}, [values]); // eslint-disable-line react-hooks/exhaustive-deps
// 只读数据格式化
var dataFormat = function (_a, data) {
var dataType = _a.dataType, format = _a.format;
switch (dataType) {
case 'fileSize':
return fileSizeFix(data);
case 'dateTime':
return dayjs(Number(data)).format(format || 'YYYY-MM-DD HH:mm');
default:
return data;
}
};
// 表单提交
var handleSubmit = function (vals) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
// 查询字段处理 1.日期区间转时间戳 2.输出附加别名字段
Object.keys(vals).forEach(function (vname) {
// 判断查找是否是日期区间选择
var isDateRange = items.find(function (_a) {
var name = _a.name, inputType = _a.inputType;
return name === vname && inputType === 'dateRange';
});
// 判断查找是否设置别名
var isExtra = items.find(function (_a) {
var name = _a.name, extra = _a.extra;
return name === vname && !!extra;
});
// 判断当前数据项是不是dateTime,提交时需要转为时间戳
var isDateTime = items.find(function (_a) {
var name = _a.name, inputType = _a.inputType;
return name === vname && inputType === 'dateTime';
});
var rangeDate = vals[vname];
// 日期区间转换为时间戳
if (isDateRange && rangeDate && rangeDate.length === 2) {
var timeBegin = rangeDate[0], timeEnd = rangeDate[1];
var _a = isDateRange.dateRangeNames, beginName = _a[0], endName = _a[1];
// 取选中日期的零点时间戳
vals[beginName] = dayjs(timeBegin)
.millisecond(0)
.second(0)
.minute(0)
.hour(0)
.valueOf();
vals[endName] = dayjs(timeEnd)
.millisecond(0)
.second(59)
.minute(59)
.hour(23)
.valueOf();
delete vals[vname];
}
// 附加别名字段输出
else if (isExtra) {
vals[isExtra.extra] = vals[vname];
}
// dateTime日期时间格式,提交时转为时间戳
else if (isDateTime) {
vals[vname] = dayjs(vals[vname]).valueOf();
}
// 清除空值项
else if (vals[vname] === '') {
delete vals[vname];
}
});
onSubmit && onSubmit(vals);
return [2 /*return*/];
});
}); };
return (_jsx(FilterCard, { children: _jsx(Form, __assign({ form: form, onFinish: handleSubmit, labelCol: { span: labelCol } }, { children: _jsx(Row, __assign({ gutter: 20 }, { children: items.map(function (_a, index) {
var name = _a.name, label = _a.label, inputType = _a.inputType, placeholder = _a.placeholder, options = _a.options, disabled = _a.disabled, copy = _a.copy, allowClear = _a.allowClear, rules = _a.rules, colSpan = _a.colSpan, buttons = _a.buttons;
// 是否可复制
var copyAttr = copy
? {
addonAfter: (_jsx(CopyToClipboard, __assign({ text: values[name] }, { children: _jsx(Icon, { className: "copy-icon", type: "iconicon_copynumber", title: "\u590D\u5236", onClick: function () {
return message.success('复制成功');
} }, void 0) }), void 0))
}
: {};
return (_jsx(Col, __assign({ span: colSpan || span }, { children: _jsx(Form.Item, __assign({ name: name, label: label, rules: rules }, { children: readOnly || disabled ? (_jsx(Input, __assign({ disabled: true }, copyAttr), void 0)) : inputType === 'select' ? (_jsx(Select, { placeholder: placeholder, allowClear: allowClear, options: options }, void 0)) : inputType === 'dateRange' ? (
// @ts-ignore
_jsx(RangePicker, { locale: locale, placeholder: placeholder, style: { width: '100%' } }, void 0)) : inputType === 'dateTime' ? (
// @ts-ignore
_jsx(DatePicker, { showTime: true, style: { width: '100%' } }, void 0)) : inputType === 'buttons' ? (buttons === null || buttons === void 0 ? void 0 : buttons.map(function (button, index) { return (_jsx(React.Fragment, { children: button }, index)); })) : (_jsx(Input, __assign({ allowClear: allowClear, placeholder: placeholder }, copyAttr), void 0)) }), void 0) }), index));
}) }), void 0) }), void 0) }, void 0));
};
var FilterCard = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n .copy-icon {\n cursor: pointer;\n color: initial;\n font-size: 16px;\n }\n .footer-btn {\n min-width: 106px;\n border-radius: 20px;\n }\n"], ["\n .copy-icon {\n cursor: pointer;\n color: initial;\n font-size: 16px;\n }\n .footer-btn {\n min-width: 106px;\n border-radius: 20px;\n }\n"])));
var templateObject_1;