song-ui-u
Version:
vue3 + js的PC前端组件库
187 lines (177 loc) • 6.65 kB
JavaScript
import { computed, ref, openBlock, createElementBlock, normalizeClass, createBlock, withCtx, createVNode, Fragment, createCommentVNode, resolveDynamicComponent, renderSlot } from 'vue';
import { useNamespace } from '../../../hook/use-namespace/index.mjs';
import { useParent } from '../../../hook/use-parent/index.mjs';
import { Loader } from 'song-ui-pro-icon';
import '../../../hook/use-zindex/index.mjs';
import '../index.mjs';
import '../../buttonGroup/index.mjs';
import { XIcon } from '../../icon/index.mjs';
import '../../input/index.mjs';
import '../../textarea/index.mjs';
import '../../row/index.mjs';
import '../../col/index.mjs';
import '../../container/index.mjs';
import '../../checkbox/index.mjs';
import '../../switch/index.mjs';
import '../../form/index.mjs';
import '../../message/index.mjs';
import '../../mask/src/mask.mjs';
import '../../modal/index.mjs';
import '../../messageBox/index.mjs';
import '../../drawer/index.mjs';
import '../../badge/index.mjs';
import '../../space/index.mjs';
import '../../image/index.mjs';
import '../../radio/index.mjs';
import '../../divider/index.mjs';
import '../../chat/index.mjs';
import '../../progress/index.mjs';
import '../../upload/index.mjs';
import '../../vTree/index.mjs';
import '../../table/index.mjs';
import '../../tabs/index.mjs';
import '../../menu/index.mjs';
import '../../steps/index.mjs';
import '../../header/index.mjs';
import '../../breadcrumble/index.mjs';
import '../../datePicker/index.mjs';
import '../../tooltip/index.mjs';
import '../../popover/index.mjs';
import '../../timePicker/index.mjs';
import '../../select/index.mjs';
import '../../collapse/index.mjs';
import '../../card/index.mjs';
import '../../timeline/index.mjs';
import '../../tag/index.mjs';
import '../../result/index.mjs';
import '../../sender/index.mjs';
import _export_sfc from '../../../_virtual/_plugin-vue_export-helper.mjs';
import { useFormItem } from '../../form/src/composables/use-form-item.mjs';
// useFormItem
const __default__ = { name: "x-button" };
const _sfc_main = /*#__PURE__*/Object.assign(__default__, {
props: {
type: {
type: String,
default: "default",
},
size: {
type: String,
default: "default",
},
icon: {
type: [String, Object],
default: "",
},
iconfont: {
type: String,
default: "",
},
round: Boolean, // 圆形按钮
disabled: Boolean, // 禁用按钮
text: Boolean, // 文字按钮
link: Boolean, // 链接按钮
border: Boolean, // 边框按钮
dashed: Boolean, // 虚线边框按钮
block: Boolean, // 块级按钮
circle: Boolean, // 圆形按钮
loading: Boolean, // 加载按钮
beforeChange: Function,
},
emits: ["click"],
setup(__props, { expose: __expose, emit: __emit }) {
__expose();
const { formContent, fromItemContent } = useFormItem();
const ns = useNamespace("button");
const parent = useParent("button-group");
/** emit */
const emit = __emit;
/** props */
const props = __props;
/** computed */
const isGroup = parent.group();
const isGroupSize = parent.props("size");
const controlSize = computed(
() => isGroupSize || formContent?.size?.value || props.size
);
/** loading */
const _loading = ref(false);
/**
* 点击事件
*/
const handlerChange = (ev) => {
const isFunction =
Object.prototype.toString.call(props.beforeChange) === "[object Function]";
if (!isFunction) {
emit("click", ev);
return false;
}
// 启用加载
_loading.value = true;
props.beforeChange().finally(() => (_loading.value = false));
};
const __returned__ = { formContent, fromItemContent, ns, parent, emit, props, isGroup, isGroupSize, controlSize, _loading, handlerChange, ref, computed, get useNamespace() { return useNamespace }, get useParent() { return useParent }, get useFormItem() { return useFormItem }, get XIcon() { return XIcon }, get Loader() { return Loader } };
Object.defineProperty(__returned__, '__isScriptSetup', { enumerable: false, value: true });
return __returned__
}
});
const _hoisted_1 = ["disabled"];
const _hoisted_2 = { key: 2 };
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return (openBlock(), createElementBlock("button", {
disabled: $props.disabled || $props.loading || $setup._loading,
class: normalizeClass([
$setup.ns.b(),
$setup.ns.m($props.type),
$setup.ns.m('size', $setup.controlSize),
$setup.ns.is('round', $props.round),
$setup.ns.is('disabled', $props.disabled),
$setup.ns.is('loading', $props.loading || $setup._loading),
$setup.ns.is('text', $props.text),
$setup.ns.is('link', $props.link),
$setup.ns.is('border', $props.border),
$setup.ns.is('block', $props.block),
$setup.ns.is('dashed', $props.dashed),
$setup.ns.is('circle', $props.circle),
$setup.ns.is('button-group', $setup.isGroup),
]),
onClick: $setup.handlerChange,
type: "button"
}, [
($props.loading || $setup._loading)
? (openBlock(), createBlock($setup["XIcon"], { key: 0 }, {
default: withCtx(() => [
createVNode($setup["Loader"], {
class: normalizeClass([`${$setup.ns.is('loading-transition', $props.loading || $setup._loading)}`])
}, null, 8 /* PROPS */, ["class"])
]),
_: 1 /* STABLE */
}))
: (openBlock(), createElementBlock(Fragment, { key: 1 }, [
($props.icon || $props.iconfont)
? (openBlock(), createBlock($setup["XIcon"], { key: 0 }, {
default: withCtx(() => [
($props.iconfont)
? (openBlock(), createElementBlock("i", {
key: 0,
class: normalizeClass(["iconfont", $props.iconfont])
}, null, 2 /* CLASS */))
: createCommentVNode("v-if", true),
($props.icon)
? (openBlock(), createBlock(resolveDynamicComponent($props.icon), { key: 1 }))
: createCommentVNode("v-if", true)
]),
_: 1 /* STABLE */
}))
: createCommentVNode("v-if", true)
], 64 /* STABLE_FRAGMENT */)),
(_ctx.$slots.default)
? (openBlock(), createElementBlock("span", _hoisted_2, [
renderSlot(_ctx.$slots, "default")
]))
: createCommentVNode("v-if", true)
], 10 /* CLASS, PROPS */, _hoisted_1))
}
var Button = /*#__PURE__*/_export_sfc(_sfc_main, [['render',_sfc_render],['__file',"E:\\code\\my-code\\song-ui-ultra\\packages\\components\\button\\src\\index.vue"]]);
export { Button as default };
//# sourceMappingURL=index.vue.mjs.map