pwfe-dom
Version:
palmg web front end dom
97 lines (75 loc) • 3.9 kB
JavaScript
/**
* Created by chkui on 2017/5/27.
*/
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _router = require('../../router');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var outProps = ['match', 'location', 'history', 'staticContext', 'browser', 'server'];
/**
* 内置A标签。
* 1)标签提供服务器跳转和本地跳转2种模式。通过server参数配置。
* 2) support all <a> attribute
* @param {object} props{
* {boolean} server:是否经过服务器跳转,默认为false。
* }
*/
var A = (0, _router.reRoute)()(function (_React$Component) {
_inherits(_class, _React$Component);
function _class() {
var _ref;
_classCallCheck(this, _class);
for (var _len = arguments.length, props = Array(_len), _key = 0; _key < _len; _key++) {
props[_key] = arguments[_key];
}
var _this = _possibleConstructorReturn(this, (_ref = _class.__proto__ || Object.getPrototypeOf(_class)).call.apply(_ref, [this].concat(props)));
_this.hrefHandle = _this.hrefHandle.bind(_this);
return _this;
}
_createClass(_class, [{
key: 'hrefHandle',
value: function hrefHandle() {
var _props = this.props,
href = _props.href,
browser = _props.browser;
href && browser.forward(href);
}
}, {
key: 'checkHref',
value: function checkHref(props) {
var _props2 = this.props,
href = _props2.href,
server = _props2.server,
browser = _props2.browser;
if (server || browser.isServerInitPath()) {
props.href = href;
} else {
props.onClick = this.hrefHandle;
}
outProps.forEach(function (i) {
return delete props[i];
});
}
}, {
key: 'render',
value: function render() {
var props = Object.assign({}, this.props);
this.checkHref(props);
return _react2.default.createElement(
'a',
props,
this.props.children
);
}
}]);
return _class;
}(_react2.default.Component));
exports.default = A;