ukelli-ui
Version:
ukelli-ui 是基于 React 的 UI 库,提供简约和功能齐全的组件,可高度定制的组件接口,灵活的配置,提供给开发者另一种开发思路,也致力于尝试不同的组件使用和开发方向。
116 lines (80 loc) • 5.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _basicHelper = require("basic-helper");
var _datetimeHelper = require("basic-helper/datetime-helper");
var _ukeUtils = require("../uke-utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var DateBaisc =
/*#__PURE__*/
function (_UkePureComponent) {
_inherits(DateBaisc, _UkePureComponent);
function DateBaisc() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, DateBaisc);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(DateBaisc)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_this), "dateFormat", 'YYYY-MM-DD');
_defineProperty(_assertThisInitialized(_this), "timeFormat", 'hh:mm:ss');
_defineProperty(_assertThisInitialized(_this), "emitChangeValue", function (val) {
/** 统一处理过滤所有的 value 格式 */
var _this$props = _this.props,
needTime = _this$props.needTime,
enableTime = _this$props.enableTime,
outputAsString = _this$props.outputAsString,
defaultTimes = _this$props.defaultTimes,
_this$props$toUTC = _this$props.toUTC,
toUTC = _this$props$toUTC === void 0 ? true : _this$props$toUTC,
onChange = _this$props.onChange;
/** 确保只有一个值的时候的时分秒为 23:59:59 */
var emitVal = Array.isArray(val) ? val : [null, val];
var resVal = [];
emitVal.forEach(function (_val, idx) {
if (!_val) return; // let resDate = DateFormat(_val, this.dateFormat) + (needTime ? ' ' + defaultTimes[idx] : '');;
var resDate = (0, _basicHelper.DateFormat)(_val, needTime ? _this.dateFormat + ' ' + _this.timeFormat : _this.dateFormat); // if(enableTime) {
// resDate = DateFormat(_val, `${this.dateFormat} ${this.timeFormat}`);
// } else {
// }
// resDate = DateFormat(_val, this.dateFormat) + (needTime ? ' ' + defaultTimes[idx] : '');
if (!outputAsString) {
if (toUTC) {
resDate = (0, _datetimeHelper.ToUTC)(resDate);
}
}
resVal.push(resDate);
});
resVal = resVal.length === 1 ? resVal[0] : resVal;
(0, _basicHelper.Call)(onChange, resVal);
return resVal;
});
return _this;
}
return DateBaisc;
}(_ukeUtils.UkePureComponent);
exports["default"] = DateBaisc;
_defineProperty(DateBaisc, "propTypes", {
onChange: _propTypes["default"].func,
/** 是否需要时分秒 */
needTime: _propTypes["default"].bool,
/** 是否转换成标准 UTC 时间 */
toUTC: _propTypes["default"].bool,
/** 默认的时分秒的值 */
defaultTimes: _propTypes["default"].arrayOf(_propTypes["default"].string),
/** 是否输出字符串格式,默认为原生 Date 对象 */
outputAsString: _propTypes["default"].bool
});