UNPKG

yuang-framework-ui-pc

Version:

yuang-framework-ui-pc Library

149 lines (148 loc) 4.81 kB
"use strict"; const vue = require("vue"); const _sfc_main = vue.defineComponent({ name: "FileGridItem", props: { /** 数据 */ item: { type: Object, required: true }, /** 选择框类型 */ selectionType: String, /** 多选选中数据 */ selections: Array, /** 单选选中数据 */ current: Object, /** 后缀对应的图标 */ icons: Array, /** 右键下拉菜单是否显示 */ ctxMenuDropdownVisible: Boolean }, emits: { click: (_item) => true, checkChange: (_item) => true, contextOpen: (_option) => true }, setup(props, { emit }) { const dropdownTriggerRef = vue.ref(null); const selectable = vue.computed(() => { return props.selectionType === "checkbox" || props.selectionType === "radio"; }); const selected = vue.computed(() => { if (!selectable.value || !props.item) { return false; } if (props.selectionType === "checkbox") { return !!(props.selections && props.selections.some((t) => t.key === props.item.key)); } return !!(props.current && props.current.key === props.item.key); }); const icon = vue.computed(() => { var _a, _b, _c; if (props.item.thumbnail) { return props.item.thumbnail; } if (!props.icons) { return; } if (props.item.isDirectory) { return (_a = props.icons.find((d) => d.type === "dir")) == null ? void 0 : _a.icon; } if (props.item.name) { const icon2 = (_b = props.icons.find((d) => { if (!d.suffixes) { return false; } return !!d.suffixes.find((t) => !!props.item.name.endsWith(t)); })) == null ? void 0 : _b.icon; if (icon2) { return icon2; } } return (_c = props.icons.find((d) => d.type === "file")) == null ? void 0 : _c.icon; }); const handleClick = () => { emit("click", props.item); }; const handleCheckChange = () => { emit("checkChange", props.item); }; const handleContextmenu = (e) => { if (dropdownTriggerRef.value != null) { emit("contextOpen", { item: props.item, triggerEl: dropdownTriggerRef.value, e }); } }; return { dropdownTriggerRef, selectable, selected, icon, handleClick, handleCheckChange, handleContextmenu }; } }); const _export_sfc = (sfc, props) => { const target = sfc.__vccOpts || sfc; for (const [key, val] of props) { target[key] = val; } return target; }; const _hoisted_1 = { class: "ele-file-list-item-icon" }; const _hoisted_2 = ["src"]; const _hoisted_3 = ["title"]; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return vue.openBlock(), vue.createElementBlock("div", { class: vue.normalizeClass([ "ele-file-list-item", { "is-checked": _ctx.selected }, { "is-active": _ctx.ctxMenuDropdownVisible } ]), onClick: _cache[3] || (_cache[3] = vue.withModifiers((...args) => _ctx.handleClick && _ctx.handleClick(...args), ["stop"])) }, [ vue.createElementVNode("div", { class: "ele-file-list-item-body", onContextmenu: _cache[0] || (_cache[0] = (...args) => _ctx.handleContextmenu && _ctx.handleContextmenu(...args)) }, [ vue.createElementVNode("div", _hoisted_1, [ vue.renderSlot(_ctx.$slots, "icon", { icon: _ctx.icon, item: _ctx.item }, () => [ vue.createElementVNode("img", { src: _ctx.icon, class: vue.normalizeClass({ "ele-file-list-item-image": !!_ctx.item.thumbnail }) }, null, 10, _hoisted_2) ]) ]), vue.renderSlot(_ctx.$slots, "title", { item: _ctx.item }, () => [ vue.createElementVNode("div", { title: _ctx.item.name, class: "ele-file-list-item-title" }, vue.toDisplayString(_ctx.item.name), 9, _hoisted_3) ]) ], 32), _ctx.selectable ? (vue.openBlock(), vue.createElementBlock("div", { key: 0, class: "ele-file-list-item-checkbox", onClick: _cache[1] || (_cache[1] = vue.withModifiers((...args) => _ctx.handleCheckChange && _ctx.handleCheckChange(...args), ["stop"])) }, _cache[4] || (_cache[4] = [ vue.createElementVNode("i", { class: "ele-file-list-checkbox is-checked" }, null, -1) ]))) : vue.createCommentVNode("", true), vue.createElementVNode("div", { ref: "dropdownTriggerRef", class: "ele-file-list-item-dropdown", onClick: _cache[2] || (_cache[2] = vue.withModifiers(() => { }, ["stop"])) }, null, 512) ], 2); } const fileGridItem = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); module.exports = fileGridItem;