UNPKG

@wocwin/t-ui-plus

Version:

Page level components developed based on Element Plus.

456 lines (451 loc) 16.8 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); const _hoisted_1 = { key: 0, class: "cell-content" }; const _hoisted_2 = { key: 0 }; const _hoisted_3 = { key: 1 }; const _hoisted_4 = { key: 0 }; const _hoisted_5 = { key: 1 }; const _hoisted_6 = { key: 0 }; var _sfc_main = /* @__PURE__ */ vue.defineComponent({ ...{ name: "SingleEdit" }, __name: "singleEdit", props: { /** 编辑配置项说明 * label: '爱好', // placeholder显示 * editComponent: 'el-select', // 组件 * type: 'select-arr', // option显示 * list: 'hobbyList', // 下拉选择数据源 * arrLabel: 'label', // 下拉选择中文显示 * arrKey: 'value' // 下拉选择number显示(最终传后台) * bind:{} // 组件衍生属性(即第三方组件属性) */ configEdit: { type: Object, default: () => ({}) }, // 下拉选择数据源 listTypeInfo: { type: Object, default: () => ({}) }, scope: { type: Object, default: () => ({}) }, prop: { type: String, default: "prop" }, // 是否开启单击编辑 isClickEdit: { type: Boolean, default: false }, modelValue: { type: [String, Number, Object, Array, Date] }, // 列for index indexColumns: [String, Number] }, emits: ["handleEvent", "update:modelValue"], setup(__props, { expose: __expose, emit: __emit }) { const props = __props; const emits = __emit; const slots = vue.useSlots(); const childCom = vue.ref(["select-arr", "checkbox", "radio", "select-obj", "el-select-multiple"]); const editMode = vue.ref(false); const tselecttableref = vue.ref({}); const handleRef = (el) => { if (el) { tselecttableref.value[`tselecttableref-${props.indexColumns}`] = el; } }; const resetClickTselectTable = () => { const refList = Object.keys(tselecttableref.value).filter( (item) => item.includes("tselecttableref") ); if (refList.length > 0 && tselecttableref.value) { refList.map((val) => { tselecttableref.value[val].clear(); }); } }; let model = vue.computed({ get() { return props == null ? void 0 : props.modelValue; }, set(val) { emits("update:modelValue", val); } }); vue.watch( () => props.modelValue, (data) => { model.value = data; } ); const cEvent = vue.computed(() => { return ({ eventHandle }, type = "") => { let event = { ...eventHandle }; let changeEvent = {}; Object.keys(event).forEach((v) => { changeEvent[v] = (e, ids) => { if (type === "t-select-table") { const argument = { row: e, ids, prop: props.prop, scope: props.scope }; event[v] && event[v](argument); } else { if (typeof e === "number" && e === 0 || e) { event[v] && event[v]({ val: e, prop: props.prop, scope: props.scope }); } else { event[v] && event[v]({ prop: props.prop, scope: props.scope }); } } }; }); return { ...changeEvent }; }; }); const childVal = vue.computed({ get() { let valLabel; let checkboxVal = []; let selcetMultiple = []; props.listTypeInfo[props.configEdit.list] && props.listTypeInfo[props.configEdit.list].map((val) => { switch (props.configEdit.type) { case "checkbox": case "radio": if (model.value.join(",").includes(val.value)) { checkboxVal.push(val.label); } valLabel = checkboxVal.join(","); break; case "select-arr": if (model.value == val[props.configEdit.arrKey]) { valLabel = val[props.configEdit.arrLabel]; } break; case "el-select-multiple": if (model.value && model.value.join(",").includes(val[props.configEdit.arrKey])) { selcetMultiple.push(val[props.configEdit.arrLabel]); } valLabel = selcetMultiple.join(","); break; case "select-obj": valLabel = val; break; } }); return valLabel; }, set(val) { return val; } }); const compChildName = vue.computed(() => { return (configEdit) => { switch (configEdit.type) { case "checkbox": return "el-checkbox"; case "radio": return "el-radio"; case "el-select-multiple": case "select-arr": case "select-obj": return "el-option"; } }; }); const compChildLabel = vue.computed(() => { return (configEdit, value) => { switch (configEdit.type) { case "radio": case "checkbox": return value[configEdit.arrLabel || "label"]; case "el-select-multiple": case "select-arr": return value[configEdit.arrLabel || "label"]; case "select-obj": return value; } }; }); const compChildValue = vue.computed(() => { return (configEdit, value, key) => { switch (configEdit.type) { case "radio": case "checkbox": return value[configEdit.arrKey || "key"]; case "el-select-multiple": case "select-arr": return value[configEdit.arrKey || "key"]; case "select-obj": return key; } }; }); const compChildShowLabel = vue.computed(() => { return (configEdit, value) => { switch (configEdit.type) { case "radio": case "checkbox": return value[configEdit.arrLabel || "label"]; case "el-select-multiple": case "select-arr": return value[configEdit.arrLabel || "label"]; case "select-obj": return value; } }; }); const parentCom = vue.ref(); const onFieldClick = () => { if (props.isClickEdit) { editMode.value = true; vue.nextTick(() => { let parentRef = parentCom.value; if (parentRef && parentRef.focus) { parentRef.focus(); } }); } }; const onInputExit = () => { editMode.value = false; }; const getPlaceholder = (row) => { if (!row.editComponent || typeof row.editComponent !== "string") { return row.label; } const componentType = row.editComponent.toLowerCase(); if (componentType.includes("input")) { return "\u8BF7\u8F93\u5165" + row.label; } else if (componentType.includes("select") || componentType.includes("date")) { return "\u8BF7\u9009\u62E9" + row.label; } return row.label; }; const handleEvent = (type, val, comType) => { if (comType === "datetime") onInputExit(); setTimeout(() => { emits("handleEvent", { type, val }); }, 0); }; __expose({ resetClickTselectTable }); return (_ctx, _cache) => { const _component_el_tooltip = vue.resolveComponent("el-tooltip"); return vue.openBlock(), vue.createElementBlock("div", { onClick: onFieldClick, class: "single_edit_cell" }, [ !editMode.value ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [ __props.configEdit.isShowTips ? (vue.openBlock(), vue.createBlock( _component_el_tooltip, vue.mergeProps({ key: 0, class: "item" }, { effect: "light", content: "\u5355\u51FB\u53EF\u7F16\u8F91", placement: "top", ...__props.configEdit.tipbind }), { default: vue.withCtx(() => [ childCom.value.includes(__props.configEdit.type) ? (vue.openBlock(), vue.createElementBlock( "div", _hoisted_2, vue.toDisplayString(childVal.value) + "\xA0", 1 /* TEXT */ )) : (vue.openBlock(), vue.createElementBlock( "div", _hoisted_3, vue.toDisplayString(vue.unref(model)) + "\xA0", 1 /* TEXT */ )), vue.renderSlot(_ctx.$slots, "content") ]), _: 3 /* FORWARDED */ }, 16 /* FULL_PROPS */ )) : (vue.openBlock(), vue.createElementBlock( vue.Fragment, { key: 1 }, [ childCom.value.includes(__props.configEdit.type) ? (vue.openBlock(), vue.createElementBlock( "div", _hoisted_4, vue.toDisplayString(childVal.value) + "\xA0", 1 /* TEXT */ )) : (vue.openBlock(), vue.createElementBlock( "div", _hoisted_5, vue.toDisplayString(vue.unref(model)) + "\xA0", 1 /* TEXT */ )), vue.renderSlot(_ctx.$slots, "content") ], 64 /* STABLE_FRAGMENT */ )) ])) : vue.createCommentVNode("v-if", true), editMode.value ? (vue.openBlock(), vue.createElementBlock( vue.Fragment, { key: 1 }, [ __props.configEdit.editSlotName ? (vue.openBlock(), vue.createElementBlock( "div", { key: 0, class: vue.normalizeClass([__props.prop, "slot_edit_name"]) }, [ vue.renderSlot(_ctx.$slots, __props.configEdit.editSlotName, { scope: __props.scope }) ], 2 /* CLASS */ )) : vue.createCommentVNode("v-if", true), __props.configEdit.isSelfCom ? (vue.openBlock(), vue.createElementBlock( vue.Fragment, { key: 1 }, [ __props.configEdit.editComponent === "t-select-table" ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.configEdit.editComponent), vue.mergeProps( { key: 0, ref: (el) => handleRef(el), placeholder: __props.configEdit.placeholder || getPlaceholder(__props.configEdit) }, typeof __props.configEdit.bind == "function" ? __props.configEdit.bind(__props.scope) : { clearable: true, filterable: true, ...__props.configEdit.bind }, { style: { width: __props.configEdit.width || "100%" } }, vue.toHandlers(cEvent.value(__props.configEdit, "t-select-table")) ), null, 16, ["placeholder", "style"])) : (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.configEdit.editComponent), vue.mergeProps( { key: 1, modelValue: vue.unref(model), "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => vue.isRef(model) ? model.value = $event : model = $event), type: __props.configEdit.type, placeholder: __props.configEdit.placeholder || getPlaceholder(__props.configEdit), ref_key: "parentCom", ref: parentCom }, typeof __props.configEdit.bind == "function" ? __props.configEdit.bind(__props.scope) : { clearable: true, filterable: true, ...__props.configEdit.bind }, { onChange: _cache[1] || (_cache[1] = ($event) => handleEvent(__props.configEdit.event, vue.unref(model), __props.configEdit.type)), style: { width: __props.configEdit.width || "100%" } }, vue.toHandlers(cEvent.value(__props.configEdit)) ), null, 16, ["modelValue", "type", "placeholder", "style"])) ], 64 /* STABLE_FRAGMENT */ )) : vue.createCommentVNode("v-if", true), !__props.configEdit.editSlotName && !__props.configEdit.isSelfCom ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.configEdit.editComponent || "el-input"), vue.mergeProps( { key: 2, modelValue: vue.unref(model), "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => vue.isRef(model) ? model.value = $event : model = $event), type: __props.configEdit.type, placeholder: __props.configEdit.placeholder || getPlaceholder(__props.configEdit), class: __props.prop, ref_key: "parentCom", ref: parentCom, onChange: _cache[3] || (_cache[3] = ($event) => handleEvent(__props.configEdit.event, vue.unref(model), __props.configEdit.type)), onKeyup: vue.withKeys(onInputExit, ["enter", "native"]), onBlur: onInputExit }, typeof __props.configEdit.bind == "function" ? __props.configEdit.bind(__props.scope) : { clearable: true, filterable: true, ...__props.configEdit.bind }, { style: { width: __props.configEdit.width || "100%" } }, vue.toHandlers(cEvent.value(__props.configEdit)) ), vue.createSlots({ default: vue.withCtx(() => [ vue.renderSlot(_ctx.$slots, "editChild"), !_ctx.$slots.editChild ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_6, [ (vue.openBlock(true), vue.createElementBlock( vue.Fragment, null, vue.renderList(__props.listTypeInfo[__props.configEdit.list], (value, key, index) => { return vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(compChildName.value(__props.configEdit)), { key: index, disabled: value.disabled, label: compChildLabel.value(__props.configEdit, value), value: compChildValue.value(__props.configEdit, value, key) }, { default: vue.withCtx(() => [ vue.createTextVNode( vue.toDisplayString(compChildShowLabel.value(__props.configEdit, value)), 1 /* TEXT */ ) ]), _: 2 /* DYNAMIC */ }, 1032, ["disabled", "label", "value"]); }), 128 /* KEYED_FRAGMENT */ )) ])) : vue.createCommentVNode("v-if", true) ]), _: 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))) ]) }; }), __props.configEdit.prepend ? { name: "prepend", fn: vue.withCtx(() => [ vue.createTextVNode( vue.toDisplayString(__props.configEdit.prepend), 1 /* TEXT */ ) ]), key: "0" } : void 0, __props.configEdit.append ? { name: "append", fn: vue.withCtx(() => [ vue.createTextVNode( vue.toDisplayString(__props.configEdit.append), 1 /* TEXT */ ) ]), key: "1" } : void 0 ]), 1040, ["modelValue", "type", "placeholder", "class", "style"])) : vue.createCommentVNode("v-if", true) ], 64 /* STABLE_FRAGMENT */ )) : vue.createCommentVNode("v-if", true) ]); }; } }); exports.default = _sfc_main;