UNPKG

tav-ui

Version:
78 lines (75 loc) 3.4 kB
import { defineComponent, computed, unref, resolveComponent, withDirectives, openBlock, createBlock, mergeProps, withCtx, createCommentVNode, renderSlot, normalizeProps, vShow } from 'vue'; import { Button as Button$1 } from 'ant-design-vue'; import { useAttrs } from '../../../hooks/core/useAttrs2.mjs'; import { TaIcon } from '../../icon/index2.mjs'; import '../../permission/index2.mjs'; import { useGlobalConfig } from '../../../hooks/global/useGlobalConfig2.mjs'; import '../../../utils/index2.mjs'; import { buttonProps } from './types2.mjs'; import _export_sfc from '../../../../_virtual/plugin-vue_export-helper.mjs'; import { isUnDef } from '../../../utils/is2.mjs'; import { usePermissionMatchedByParent } from '../../permission/src/utils2.mjs'; const _sfc_main = defineComponent({ name: "TaButton", components: { Button: Button$1, Icon: TaIcon }, inheritAttrs: false, props: buttonProps, setup(props) { const attrs = useAttrs({ excludeDefaultKeys: false }); const getButtonClass = computed(() => { const { color, disabled } = props; return [ { [`ant-btn-${color}`]: !!color, "is-disabled": disabled } ]; }); const getBindValue = computed(() => ({ ...unref(attrs), ...props })); const IfShow = computed(() => (code) => { const permissions = useGlobalConfig("permissions"); const PermissionFlag = isUnDef(code) ? true : unref(permissions)[code]?.ifShow; const PermisionCodeFlag = isUnDef(props.permissionCode) ? true : props.permissionCode === 1; return PermissionFlag && PermisionCodeFlag && props.ifShow; }); const computedUsePermission = computed(() => { if (props.usePermission) { return usePermissionMatchedByParent({ ...props.usePermission }).value; } return true; }); return { getButtonClass, getBindValue, IfShow, computedUsePermission }; } }); function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { const _component_Icon = resolveComponent("Icon"); const _component_Button = resolveComponent("Button", true); return withDirectives((openBlock(), createBlock(_component_Button, mergeProps(_ctx.getBindValue, { class: [_ctx.getButtonClass, "ta-basic-button"], onClick: _ctx.onClick }), { default: withCtx((data) => [ !_ctx.loading && _ctx.preIcon ? (openBlock(), createBlock(_component_Icon, { key: 0, icon: _ctx.preIcon, size: _ctx.iconSize, color: _ctx.preIconColor }, null, 8, ["icon", "size", "color"])) : createCommentVNode("v-if", true), !_ctx.loading ? renderSlot(_ctx.$slots, "default", normalizeProps(mergeProps({ key: 1 }, data || {}))) : createCommentVNode("v-if", true), !_ctx.loading && _ctx.postIcon ? (openBlock(), createBlock(_component_Icon, { key: 2, icon: _ctx.postIcon, size: _ctx.iconSize, color: _ctx.postIconColor }, null, 8, ["icon", "size", "color"])) : createCommentVNode("v-if", true) ]), _: 3 }, 16, ["class", "onClick"])), [ [vShow, _ctx.computedUsePermission && _ctx.IfShow(_ctx.permission)] ]); } var Button = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/home/runner/work/tav-ui/tav-ui/packages/components/button/src/button.vue"]]); export { Button as default }; //# sourceMappingURL=button2.mjs.map