UNPKG

tdesign-vue

Version:
218 lines (214 loc) 7.27 kB
/** * tdesign v1.14.1 * (c) 2025 tdesign * @license MIT */ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray'; import { defineComponent, ref, computed, reactive, provide, watch, onMounted } from '@vue/composition-api'; import props from './head-menu-props.js'; import { Tabs, TabPanel } from '../tabs/index.js'; import { renderContent, renderTNodeJSX } from '../utils/render-tnode.js'; import VMenu from './v-menu.js'; import { usePrefixClass } from '../hooks/useConfig.js'; import '../tabs/tabs.js'; import '../_chunks/dep-6a4dc7bb.js'; import '@babel/runtime/helpers/defineProperty'; import 'vue'; import '../utils/helper.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '@babel/runtime/helpers/slicedToArray'; import 'lodash-es'; import '../tabs/props.js'; import '../tabs/tab-panel.js'; import '../tabs/tab-panel-props.js'; import '../hooks/useDestroyOnClose.js'; import '../config-provider/config-receiver.js'; 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 '@babel/runtime/helpers/typeof'; import '../_chunks/dep-fdb1b253.js'; import 'dayjs'; import '../_common/js/global-config/t.js'; import '../utils/mixins.js'; import '../tabs/tab-nav.js'; import 'tdesign-icons-vue'; import '../tabs/utils/handleDragSort.js'; import '../tabs/tab-nav-item.js'; import '../utils/event.js'; import '../utils/ripple.js'; import '../_common/js/utils/setStyle.js'; import '../config.js'; import '../_common/js/tabs/base.js'; import '../utils/map-props.js'; import '../utils/withInstall.js'; import '@babel/runtime/helpers/readOnlyError'; import '@babel/runtime/helpers/classCallCheck'; import '@babel/runtime/helpers/createClass'; import '../config-provider/useConfig.js'; var _HeadMenu = defineComponent({ name: "THeadMenu", props: props, model: { prop: "value", event: "change" }, components: { Tabs: Tabs, TabPanel: TabPanel }, setup: function setup(props2, ctx) { var activeValue = ref(props2.defaultValue || props2.value); var activeValues = ref([]); var expandValues = ref(props2.defaultExpanded || props2.expanded || []); var classPrefix = usePrefixClass(); var theme = computed(function () { return props2.theme; }); var menuClass = computed(function () { return ["".concat(classPrefix.value, "-menu"), "".concat(classPrefix.value, "-head-menu"), "".concat(classPrefix.value, "-menu--").concat(props2.theme)]; }); var mode = ref(props2.expandType); var submenu = reactive([]); var deliver = function deliver(evt) { var func = "on".concat(evt[0].toUpperCase() + evt.slice(1)); return function (val) { if (typeof props2[func] === "function") { props2[func](val); } ctx.emit(evt, val); }; }; var emitChange = deliver("change"); var emitExpand = deliver("expand"); var vMenu = new VMenu({ isMutex: true, expandValues: expandValues.value }); provide("TdMenu", { mode: mode, theme: theme, vMenu: vMenu, isHead: true, expandValues: expandValues, activeValue: activeValue, activeValues: activeValues, select: function select(value) { emitChange(value); }, open: function open(value, type) { var expanded = _toConsumableArray(expandValues.value); var index = expanded.indexOf(value); if (mode.value === "popup") { if (type === "add") { if (index === -1) { expanded.push(value); } } else if (type === "remove") { expanded.splice(index, 1); } } else { expanded.splice(0, 1); if (index === -1) { expanded.push(value); } } emitExpand(expanded); } }); var handleTabChange = function handleTabChange(value) { emitChange(value); }; var handleSubmenuExpand = function handleSubmenuExpand(value) { var ans = vMenu.getChild(value); submenu.length = 0; submenu.push.apply(submenu, _toConsumableArray(ans)); }; watch(function () { return props2.expanded; }, function (value) { expandValues.value = value; if (mode.value === "normal") { handleSubmenuExpand(value[0]); } }); var updateActiveValues = function updateActiveValues(value) { activeValue.value = value; activeValues.value = vMenu.select(value); }; watch(function () { return props2.value; }, updateActiveValues); watch(function () { return props2.defaultValue; }, updateActiveValues); watch(function () { return props2.expandType; }, function (value) { mode.value = value; }); onMounted(function () { var _expandValues$value; activeValues.value = vMenu.select(activeValue.value); if (((_expandValues$value = expandValues.value) === null || _expandValues$value === void 0 ? void 0 : _expandValues$value.length) > 0) { handleSubmenuExpand(expandValues.value[0]); } }); return { mode: mode, menuClass: menuClass, expandValues: expandValues, activeValue: activeValue, activeValues: activeValues, submenu: submenu, handleTabChange: handleTabChange, classPrefix: classPrefix }; }, methods: { renderNormalSubmenu: function renderNormalSubmenu(node, depth) { var _this = this; var h = this.$createElement; if (node.length === 0) return null; return h("ul", { "class": ["".concat(this.classPrefix, "-head-menu__submenu"), "".concat(this.classPrefix, "-submenu")] }, [h("t-tabs", { "attrs": { "value": this.activeValues[depth] }, "on": { "change": this.handleTabChange } }, [node.map(function (item) { return h("t-tab-panel", { "attrs": { "value": item.value, "label": typeof item.vnode === "string" ? item.vnode : item.vnode[0].text } }, [item.children && item.children.length > 0 ? _this.renderNormalSubmenu(item.children, depth + 1) : null]); })])]); } }, render: function render() { var h = arguments[0]; if (this.$slots.options) { console.warn("TDesign Warn: `options` slot is going to be deprecated, please use `operations` for slot instead."); } var operations = renderContent(this, "operations", "options"); var logo = renderTNodeJSX(this, "logo"); return h("div", { "class": this.menuClass }, [h("div", { "class": "".concat(this.classPrefix, "-head-menu__inner") }, [logo && h("div", { "class": "".concat(this.classPrefix, "-menu__logo") }, [logo]), h("ul", { "class": "".concat(this.classPrefix, "-menu") }, [renderContent(this, "default", "content")]), operations && h("div", { "class": "".concat(this.classPrefix, "-menu__operations") }, [operations])]), this.mode === "normal" && this.renderNormalSubmenu(this.submenu, 1)]); } }); export { _HeadMenu as default }; //# sourceMappingURL=head-menu.js.map