tdesign-vue
Version:
219 lines (211 loc) • 8.71 kB
JavaScript
/**
* tdesign v1.11.2
* (c) 2025 tdesign
* @license MIT
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var helper = require('../_chunks/dep-ece3c062.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var avatar_props = require('./props.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var image_index = require('../image/index.js');
var utils_mixins = require('../utils/mixins.js');
require('@babel/runtime/helpers/readOnlyError');
require('@babel/runtime/helpers/typeof');
require('@vue/composition-api');
require('../_chunks/dep-7c854ec6.js');
require('../_chunks/dep-eceed11d.js');
require('../_chunks/dep-201f7798.js');
require('../_chunks/dep-a4308f57.js');
require('../_chunks/dep-fcf0662d.js');
require('../_chunks/dep-d3015b4c.js');
require('../_chunks/dep-e4278c54.js');
require('../_chunks/dep-f8a85d6a.js');
require('../_chunks/dep-5b117689.js');
require('../_chunks/dep-6478392e.js');
require('../_chunks/dep-47bca35e.js');
require('../_chunks/dep-07fb8c0e.js');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-a4a18104.js');
require('../_chunks/dep-27dd8cc6.js');
require('dayjs');
require('../_chunks/dep-87c765cc.js');
require('../_chunks/dep-75cd6d52.js');
require('../_chunks/dep-b1a02818.js');
require('../_chunks/dep-3d8ab37d.js');
require('../_chunks/dep-ecccff93.js');
require('../_chunks/dep-a4cecac4.js');
require('../_chunks/dep-ab142eaf.js');
require('../_chunks/dep-6ad3de7c.js');
require('../_chunks/dep-8b1e056e.js');
require('../_chunks/dep-5db8defc.js');
require('../_chunks/dep-6e4c473c.js');
require('../_chunks/dep-234b7c02.js');
require('../_chunks/dep-a4747856.js');
require('../_chunks/dep-932dd69e.js');
require('../_chunks/dep-9f4caea4.js');
require('../_chunks/dep-dbd838d6.js');
require('../_chunks/dep-b3120c1b.js');
require('../_chunks/dep-68ba2357.js');
require('../_chunks/dep-173eb46c.js');
require('../image/image.js');
require('@babel/runtime/helpers/slicedToArray');
require('tdesign-icons-vue');
require('../_common/js/utils/observe.js');
require('../config-provider/useConfig.js');
require('../image/props.js');
require('../space/index.js');
require('../space/space.js');
require('../space/props.js');
require('../hooks/useConfig.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../_chunks/dep-62de1188.js');
require('../_chunks/dep-867c284e.js');
require('../_chunks/dep-738b4f21.js');
require('../_chunks/dep-aa0a4aac.js');
require('../utils/withInstall.js');
require('../_chunks/dep-6dc0a916.js');
require('../_chunks/dep-f33eb57d.js');
require('../_chunks/dep-63b02f7b.js');
require('../_chunks/dep-bebcd284.js');
require('../_chunks/dep-3eec664c.js');
require('../_chunks/dep-eeb2e214.js');
require('../_chunks/dep-362bc4d7.js');
require('../_chunks/dep-b5c96567.js');
require('../_chunks/dep-a9e7deb2.js');
require('../hooks/useImagePreviewUrl.js');
require('../_common/js/upload/utils.js');
require('../_common/js/log/log.js');
require('../utils/map-props.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty__default["default"](e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var classPrefixMixins = configProvider_configReceiver.getClassPrefixMixins("avatar");
var _Avatar = utils_mixins["default"](Vue__default["default"], classPrefixMixins).extend({
name: "TAvatar",
props: _objectSpread({}, avatar_props["default"]),
data: function data() {
return {
isImgExist: true,
gap: 4,
scale: ""
};
},
inject: {
avatarGroup: {
"default": void 0
}
},
computed: {
sizeValue: function sizeValue() {
var _this$avatarGroup;
return this.size || ((_this$avatarGroup = this.avatarGroup) === null || _this$avatarGroup === void 0 ? void 0 : _this$avatarGroup.size);
},
customAvatarSize: function customAvatarSize() {
return this.isCustomSize() ? {
width: this.sizeValue,
height: this.sizeValue,
"font-size": "".concat(Number.parseInt(this.sizeValue, 10) / 2, "px")
} : {};
},
customImageSize: function customImageSize() {
return this.isCustomSize() ? {
height: this.sizeValue,
width: this.sizeValue
} : {};
},
customCharacterSize: function customCharacterSize() {
return {
transform: this.scale
};
}
},
mounted: function mounted() {
var _this = this;
this.$nextTick(function () {
_this.setScaleParams();
});
},
methods: {
handleImgLoadError: function handleImgLoadError(context) {
var onError = this.onError,
hideOnLoadFailed = this.hideOnLoadFailed;
this.isImgExist = !hideOnLoadFailed;
this.$emit("error", context);
onError && onError(context);
},
setScaleParams: function setScaleParams() {
var avatar = this.$refs.avatar;
var avatarChild = this.$refs.avatarChild;
var avatarWidth = avatar === null || avatar === void 0 ? void 0 : avatar.offsetWidth;
var avatarChildWidth = avatarChild === null || avatarChild === void 0 ? void 0 : avatarChild.offsetWidth;
if (this.gap * 2 < avatarWidth) {
this.scale = avatarChildWidth > avatarWidth - this.gap * 2 ? "scale(".concat((avatarWidth - this.gap * 2) / avatarChildWidth, ")") : "scale(1)";
}
},
isCustomSize: function isCustomSize() {
return this.sizeValue && !this.commonSizeClassName[this.sizeValue];
}
},
updated: function updated() {
var _this2 = this;
this.$nextTick(function () {
_this2.setScaleParams();
});
},
render: function render() {
var h = arguments[0];
var content = utils_renderTnode.renderContent(this, "default", "content");
var icon = utils_renderTnode.renderTNodeJSX(this, "icon");
var isIconOnly = icon && !content;
var _this$$props = this.$props,
shape = _this$$props.shape,
image = _this$$props.image,
alt = _this$$props.alt;
var avatarClass = [this.componentName, this.commonSizeClassName[this.sizeValue], _defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"]({}, "".concat(this.componentName, "--circle"), shape === "circle"), "".concat(this.componentName, "--round"), shape === "round"), "".concat(this.componentName, "__icon"), !!isIconOnly)];
content = h("span", {
"ref": "avatarChild",
"style": _objectSpread({}, this.customCharacterSize)
}, [content]);
if (icon) {
content = [icon, !isIconOnly ? content : ""];
}
if (image && this.isImgExist) {
var _this$imageProps, _this$imageProps2;
content = h(image_index.Image, helper.helper([{
"style": _objectSpread({}, this.customImageSize),
"attrs": {
"src": image,
"alt": alt
}
}, {
"props": this.imageProps
}, {
"attrs": {
"error": !this.$scopedSlots.error && !((_this$imageProps = this.imageProps) !== null && _this$imageProps !== void 0 && _this$imageProps.error) ? " " : void 0,
"loading": !this.$scopedSlots.loading && !((_this$imageProps2 = this.imageProps) !== null && _this$imageProps2 !== void 0 && _this$imageProps2.loading) ? " " : void 0
},
"scopedSlots": this.$scopedSlots
}, {
"on": {
error: this.handleImgLoadError
}
}]));
}
return h("div", {
"ref": "avatar",
"class": avatarClass,
"style": this.customAvatarSize
}, [content]);
}
});
exports["default"] = _Avatar;
//# sourceMappingURL=avatar.js.map