tdesign-vue
Version:
168 lines (164 loc) • 6.44 kB
JavaScript
/**
* tdesign v1.14.1
* (c) 2025 tdesign
* @license MIT
*/
import { h as helper } from '../_chunks/dep-6a4dc7bb.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import props from './props.js';
import { renderContent, renderTNodeJSX } from '../utils/render-tnode.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import { Image } from '../image/index.js';
import mixins from '../utils/mixins.js';
import '@babel/runtime/helpers/readOnlyError';
import '@babel/runtime/helpers/typeof';
import '@vue/composition-api';
import 'lodash-es';
import '../config-provider/context.js';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-ba613a02.js';
import '../_chunks/dep-fdb1b253.js';
import 'dayjs';
import '../_common/js/global-config/t.js';
import '@babel/runtime/helpers/slicedToArray';
import '../image/image.js';
import 'tdesign-icons-vue';
import '../_common/js/utils/observe.js';
import '../config-provider/useConfig.js';
import '../image/props.js';
import '../space/index.js';
import '../space/space.js';
import '../space/props.js';
import '../hooks/useConfig.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../utils/withInstall.js';
import '../hooks/useImagePreviewUrl.js';
import '../_common/js/upload/utils.js';
import '../_common/js/log/log.js';
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(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 = getClassPrefixMixins("avatar");
var _Avatar = mixins(Vue, classPrefixMixins).extend({
name: "TAvatar",
props: _objectSpread({}, props),
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 = renderContent(this, "default", "content");
var icon = 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(_defineProperty(_defineProperty({}, "".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, 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]);
}
});
export { _Avatar as default };
//# sourceMappingURL=avatar.js.map