UNPKG

yanzhen-design-vue

Version:

77 lines (76 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const vue = require("vue"); const core = require("@vueuse/core"); const utils = require("@yanzhen-libs/utils"); const utilsVue = require("@yanzhen-libs/utils-vue"); const lodashEs = require("lodash-es"); const avatar = require("./avatar.cjs"); const useAvatar = (props, emit) => { const $slots = vue.useSlots(); const _ref = vue.ref(); const attrs = vue.useAttrs(); const { src, errSrc, text, max } = vue.toRefs(props); const _loadError = vue.ref(false); const config = vue.computed(() => lodashEs.pick(props, ...Object.keys(avatar.AntAvatar.props))); const proxyProps = utilsVue.useProxyProps(config, avatar.AntAvatar.emits, { emit, exclude: ["src", "errSrc"], filter: true }); const loadErrors = vue.ref({}); const _props = vue.computed(() => vue.mergeProps(vue.unref(attrs), vue.unref(proxyProps))); const [DefineAvatarSlotTemplate, ReusableAvatarSlotTemplate] = core.createReusableTemplate(); const _text = vue.computed(() => { if (lodashEs.isString(vue.unref(text)) && !utils.isEmptyValue(vue.unref(text))) { return String(vue.unref(text)).slice(0, vue.unref(max)); } return void 0; }); const _slots = vue.computed(() => { return lodashEs.merge( { default: void 0 }, $slots ); }); function handleImageError(key) { if (lodashEs.isString(key)) vue.unref(loadErrors)[key] = false; emit("error"); return true; } function isLoadSuccessfully(key) { if (lodashEs.isString(key) && !utils.isEmptyValue(key)) { const flag = vue.unref(loadErrors)[key]; return flag !== false; } return false; } const ctx = { attrs, config, _ref, _text, text, _props, proxyProps, _loadError, $slots, _slots, loadErrors, src, errSrc }; const templates = { DefineAvatarSlotTemplate, ReusableAvatarSlotTemplate }; return { ctx, templates, handleImageError, isLoadSuccessfully }; }; exports.useAvatar = useAvatar;