yanzhen-design-vue
Version:
40 lines (39 loc) • 1.05 kB
JavaScript
import { toRefs, ref, computed, unref } from "vue";
import { isEmptyValue, isEmptyArray } from "@yanzhen-libs/utils";
import { isString } from "lodash-es";
function useContactsItem(props, emit) {
const { isSelf, errorImg } = toRefs(props);
const _ref = ref();
const _avatar = computed(() => {
if (isEmptyValue(props.avatar) || !isString(props.avatar)) {
return unref(errorImg);
}
return props.avatar;
});
const _label = computed(() => props.label);
const _tags = computed(() => {
var _a;
const tags = (_a = props.tags) == null ? void 0 : _a.map(({ label }) => label).filter((v) => !isEmptyValue(v));
if (!isEmptyArray(tags)) return tags.join(";");
return false;
});
function handleClick() {
emit("item-click", props);
}
function handleSuffixClick() {
emit("suffix-click", props);
}
const ctx = {
_ref,
_tags,
_avatar,
_label,
isSelf,
errorImg
};
const methods = { handleClick, handleSuffixClick };
return { ctx, methods };
}
export {
useContactsItem
};