ming-demo3
Version:
mdf metaui web
125 lines (104 loc) • 4.67 kB
JavaScript
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _baseui = require("@mdf/baseui");
var UpLoadFace = function (_Component) {
(0, _inherits2["default"])(UpLoadFace, _Component);
function UpLoadFace(props) {
var _this;
(0, _classCallCheck2["default"])(this, UpLoadFace);
_this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(UpLoadFace).call(this, props));
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getBase64", function (img, callback) {
var reader = new FileReader();
reader.addEventListener('load', function () {
return callback(reader.result);
});
reader.readAsDataURL(img);
});
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "beforeUpload", function (file) {
var isJPG = file.type === 'image/jpeg' || 'image/png';
if (!isJPG) {
_baseui.message.error('You can only upload JPG/PNG file!');
}
var isLt1M = file.size / 1024 / 1024 < 1;
if (!isLt1M) {
_baseui.message.error('图片大小要小于 1MB!');
}
return isJPG && isLt1M;
});
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleChange", function (info) {
if (info.file.status === 'done') {
if (info.file.response.code == 200) {
if (_this.props.imageChange) _this.props.imageChange(_this.url + info.file.response.data);
}
}
});
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getFaceUploadControl", function () {
var imageUrl = _this.props.imgUrl;
var context = cb.rest.AppContext;
var action = '/upload?token=' + context.token;
var toolClass = _this.props.toolClass;
return _react["default"].createElement(_baseui.Upload, {
className: "avatar-uploader",
showUploadList: false,
action: action,
beforeUpload: _this.beforeUpload,
onChange: _this.handleChange,
accept: "image/jpeg,image/png"
}, imageUrl ? _react["default"].createElement("div", {
className: toolClass
}, _react["default"].createElement("img", {
src: imageUrl,
alt: ""
}), _react["default"].createElement("div", {
className: "info-person-mask"
}, _react["default"].createElement(_baseui.Icon, {
type: "uploadimg"
}), _react["default"].createElement("p", null, "\u70B9\u51FB\u4E0A\u4F20"))) : _react["default"].createElement("div", {
className: toolClass
}, _react["default"].createElement("div", {
className: "info-person-mask"
}, _react["default"].createElement(_baseui.Icon, {
type: "uploadimg"
}), _react["default"].createElement("p", null, "\u70B9\u51FB\u4E0A\u4F20"))));
});
_this.url;
var proxy = cb.rest.DynamicProxy.create({
getFileServerUrl: {
url: '/pub/fileupload/getFileServerUrl',
method: 'GET',
options: {
token: true
}
}
});
proxy.getFileServerUrl({}, function (err, result) {
if (!err) this.url = result;
}, (0, _assertThisInitialized2["default"])(_this));
return _this;
}
(0, _createClass2["default"])(UpLoadFace, [{
key: "render",
value: function render() {
var control = this.getFaceUploadControl();
return _react["default"].createElement("div", {
className: "uploadFace_component ".concat(this.props.class_name)
}, control);
}
}]);
return UpLoadFace;
}(_react.Component);
exports["default"] = UpLoadFace;
//# sourceMappingURL=UploadFace.js.map
;