UNPKG

@wocwin/t-ui-plus

Version:

Page level components developed based on Element Plus.

343 lines (338 loc) 12.2 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); require('./moduleDetail.vue.js'); require('./moduleForm.vue.js'); var moduleForm_vue_vue_type_script_setup_true_lang = require('./moduleForm.vue2.js'); var moduleDetail_vue_vue_type_script_setup_true_lang = require('./moduleDetail.vue2.js'); const _hoisted_1 = { class: "scroll_wrap" }; const _hoisted_2 = { class: "sub_title" }; const _hoisted_3 = { class: "extra" }; const _hoisted_4 = { key: 0, class: "handle_wrap" }; const _hoisted_5 = { key: 0 }; var _sfc_main = /* @__PURE__ */ vue.defineComponent({ ...{ name: "TModuleForm" }, __name: "index", props: { handleType: { default: "edit" }, isShowHeader: { type: Boolean, default: false }, titleSlot: { type: Boolean, default: false }, isShowBack: { type: Boolean, default: false }, isGoBackEvent: { type: Boolean, default: false }, btnSaveBind: { default: () => ({}) }, btnCancelBind: { default: () => ({}) }, isTabMargin: { type: Boolean, default: false }, tabMarginNum: { default: 10 }, footer: {}, title: { default: "" }, subTitle: { default: "" }, tabs: { default: () => [] }, submit: { type: Function, default: async () => false } }, emits: ["validateError", "back", "tabsChange"], setup(__props, { expose: __expose, emit: __emit }) { var _a; const props = __props; const attrs = vue.useAttrs(); const slots = vue.useSlots(); const activeName = vue.ref(props.tabs && ((_a = props.tabs[0]) == null ? void 0 : _a.key)); const loading = vue.ref(false); const saveAttrs = vue.computed(() => { return { type: "primary", btnTxt: "\u4FDD\u5B58", ...props.btnSaveBind }; }); const cancelAttrs = vue.computed(() => { return { btnTxt: "\u53D6\u6D88", ...props.btnCancelBind }; }); const tForm = vue.ref(null); const emits = __emit; const saveHandle = async () => { let form = {}; let formError = {}; let formOpts = {}; let successLength = 0; loading.value = true; Object.keys(attrs.formOpts).forEach((key) => { if (attrs.formOpts[key].opts) { formOpts[key] = attrs.formOpts[key]; } }); Object.keys(formOpts).forEach(async (formIndex) => { const { valid } = await tForm.value.getChildRef(formIndex).selfValidate(); if (valid) { successLength = successLength + 1; form[formIndex] = attrs.formOpts[formIndex].opts.formData; } }); setTimeout(async () => { if (successLength === Object.keys(formOpts).length) { const isSuccess = await props.submit(form); if (isSuccess) { back(); } } else { Object.keys(formOpts).forEach((key) => { if (Object.keys(form).length > 0) { Object.keys(form).map((val) => { if (key !== val) { formError[key] = formOpts[key]; } }); } else { formError[key] = formOpts[key]; } }); emits("validateError", formError); } loading.value = false; }, 300); }; const back = () => { if (props.isShowBack) { return; } emits("back"); if (!props.isGoBackEvent) { history.go(-1); } }; const setSelectedTab = (key) => { activeName.value = key; }; const tabsChange = (tab) => { emits("tabsChange", tab); }; const resetFormFields = () => { let formOpts = {}; Object.keys(attrs.formOpts).forEach((key) => { if (attrs.formOpts[key].opts) { formOpts[key] = attrs.formOpts[key]; } }); Object.keys(formOpts).forEach((formIndex) => { tForm.value.getChildRef(formIndex).resetFields(); }); }; const clearValidate = () => { let formOpts = {}; Object.keys(attrs.formOpts).forEach((key) => { if (attrs.formOpts[key].opts) { formOpts[key] = attrs.formOpts[key]; } }); Object.keys(formOpts).forEach((formIndex) => { tForm.value.getChildRef(formIndex).clearValidate(); }); }; const updateFormFields = () => { let formOpts = {}; Object.keys(attrs.formOpts).forEach((key) => { if (attrs.formOpts[key].opts) { formOpts[key] = attrs.formOpts[key]; } }); Object.keys(formOpts).forEach((formIndex) => { tForm.value.getChildRef(formIndex).updateFields(false); }); }; __expose({ clearValidate, resetFormFields, updateFormFields, setSelectedTab, saveHandle }); return (_ctx, _cache) => { const _component_el_page_header = vue.resolveComponent("el-page-header"); const _component_el_tab_pane = vue.resolveComponent("el-tab-pane"); const _component_el_tabs = vue.resolveComponent("el-tabs"); const _component_el_button = vue.resolveComponent("el-button"); return vue.openBlock(), vue.createElementBlock( "div", { class: "t_module_form", style: vue.normalizeStyle({ marginBottom: _ctx.footer !== null ? "60px" : "" }) }, [ vue.createElementVNode("div", _hoisted_1, [ vue.createCommentVNode(" \u5934\u90E8 "), !_ctx.isShowHeader && (_ctx.title || _ctx.titleSlot) ? (vue.openBlock(), vue.createBlock(_component_el_page_header, { key: 0, title: _ctx.title, onBack: back, class: vue.normalizeClass({ noContent: !_ctx.subTitle, isShowBack: _ctx.isShowBack }) }, vue.createSlots({ content: vue.withCtx(() => [ vue.createElementVNode( "div", _hoisted_2, vue.toDisplayString(_ctx.subTitle), 1 /* TEXT */ ), vue.createElementVNode("div", _hoisted_3, [ vue.renderSlot(_ctx.$slots, "extra") ]) ]), _: 2 /* DYNAMIC */ }, [ _ctx.titleSlot ? { name: "title", fn: vue.withCtx(() => [ vue.renderSlot(_ctx.$slots, "title") ]), key: "0" } : void 0 ]), 1032, ["title", "class"])) : vue.createCommentVNode("v-if", true), vue.createCommentVNode(" \u8868\u5355\u9875\u9762 "), _ctx.handleType === "edit" ? (vue.openBlock(), vue.createBlock( moduleForm_vue_vue_type_script_setup_true_lang.default, vue.mergeProps({ key: 1 }, _ctx.$attrs, { ref_key: "tForm", ref: tForm }), vue.createSlots({ _: 2 /* DYNAMIC */ }, [ vue.renderList(vue.unref(slots), (_index, name) => { return { name, fn: vue.withCtx((data) => [ vue.renderSlot(_ctx.$slots, name, vue.normalizeProps(vue.guardReactiveProps(data))) ]) }; }) ]), 1040 /* FULL_PROPS, DYNAMIC_SLOTS */ )) : (vue.openBlock(), vue.createElementBlock( vue.Fragment, { key: 2 }, [ vue.createCommentVNode(" \u8BE6\u60C5\u9875\u9762 "), vue.createVNode( moduleDetail_vue_vue_type_script_setup_true_lang.default, vue.normalizeProps(vue.guardReactiveProps(_ctx.$attrs)), vue.createSlots({ _: 2 /* DYNAMIC */ }, [ vue.renderList(vue.unref(slots), (_index, name) => { return { name, fn: vue.withCtx((data) => [ vue.renderSlot(_ctx.$slots, name, vue.normalizeProps(vue.guardReactiveProps(data))) ]) }; }) ]), 1040 /* FULL_PROPS, DYNAMIC_SLOTS */ ) ], 2112 /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */ )), vue.createCommentVNode(" tabs "), _ctx.tabs.length ? (vue.openBlock(), vue.createElementBlock( "div", { key: 3, class: "tabs", style: vue.normalizeStyle({ "margin-top": _ctx.isTabMargin ? `${_ctx.tabMarginNum}px` : 0 }) }, [ _ctx.tabs && _ctx.tabs.length > 1 ? (vue.openBlock(), vue.createBlock(_component_el_tabs, { key: 0, modelValue: activeName.value, "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => activeName.value = $event), onTabChange: tabsChange }, { default: vue.withCtx(() => [ (vue.openBlock(true), vue.createElementBlock( vue.Fragment, null, vue.renderList(_ctx.tabs, (tab) => { return vue.openBlock(), vue.createBlock(_component_el_tab_pane, { key: tab.key, name: tab.key, label: tab.title }, { default: vue.withCtx(() => [ vue.renderSlot(_ctx.$slots, tab.key) ]), _: 2 /* DYNAMIC */ }, 1032, ["name", "label"]); }), 128 /* KEYED_FRAGMENT */ )) ]), _: 3 /* FORWARDED */ }, 8, ["modelValue"])) : vue.renderSlot(_ctx.$slots, _ctx.tabs && _ctx.tabs[0].key, { key: 1 }) ], 4 /* STYLE */ )) : vue.createCommentVNode("v-if", true), vue.renderSlot(_ctx.$slots, "default") ]), vue.createCommentVNode(" \u6309\u94AE "), _ctx.footer !== null ? (vue.openBlock(), vue.createElementBlock("footer", _hoisted_4, [ vue.renderSlot(_ctx.$slots, "footer"), !vue.unref(slots).footer ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_5, [ vue.createVNode( _component_el_button, vue.mergeProps({ onClick: back }, cancelAttrs.value), { default: vue.withCtx(() => [ vue.createTextVNode( vue.toDisplayString(cancelAttrs.value.btnTxt), 1 /* TEXT */ ) ]), _: 1 /* STABLE */ }, 16 /* FULL_PROPS */ ), _ctx.handleType === "edit" ? (vue.openBlock(), vue.createBlock(_component_el_button, vue.mergeProps({ key: 0 }, saveAttrs.value, { onClick: saveHandle, loading: loading.value }), { default: vue.withCtx(() => [ vue.createTextVNode( vue.toDisplayString(saveAttrs.value.btnTxt), 1 /* TEXT */ ) ]), _: 1 /* STABLE */ }, 16, ["loading"])) : vue.createCommentVNode("v-if", true) ])) : vue.createCommentVNode("v-if", true) ])) : vue.createCommentVNode("v-if", true) ], 4 /* STYLE */ ); }; } }); exports.default = _sfc_main;