asp-smart-ui-plus-test
Version:
A Component Library for Vue 3
257 lines (252 loc) • 9.77 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var iconsVue = require('@element-plus/icons-vue');
var formItem = require('./form-item.js');
var pluginVue_exportHelper = require('../../../../../_virtual/plugin-vue_export-helper.js');
const _hoisted_1 = { class: "asp-query-form" };
const _hoisted_2 = {
key: 0,
class: "btn-item"
};
const _hoisted_3 = {
key: 1,
class: "btn-item"
};
const _hoisted_4 = {
key: 2,
class: "add-btns"
};
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
__name: "query-form",
props: {
formFields: { type: Array, required: true, default: () => [] },
buttonList: { type: Array, required: true, default: () => [] },
showReset: { type: Boolean, required: true, default: true },
labelWidth: { type: [String, Number], required: true },
showSubmit: { type: Boolean, required: true, default: true },
submitBtnIcon: { type: String, required: true },
resetBtnIcon: { type: String, required: true }
},
emits: ["formSubmit", "reset"],
setup(__props, { expose, emit }) {
const props = __props;
const model = vue.reactive({});
const formItemRefs = vue.ref([]);
const validateFormRef = vue.ref(null);
const onSubmit = () => {
if (!validateFormRef.value) {
console.error("Form reference is not set.");
return;
}
validateFormRef.value.validate((valid) => {
if (valid) {
getModel();
emit("formSubmit", model);
} else {
return false;
}
});
};
const onReset = () => {
vue.nextTick(() => {
createModel();
emit("reset", model);
});
};
const getModel = () => {
props.formFields.forEach((item, index) => {
if (item.type === "radioGroupSelect") {
const formItemRef = formItemRefs.value[index];
if (formItemRef.modelValue) {
model[item.columnName] = formItemRef.modelValue.getModel();
}
}
});
return model;
};
const resetModel = () => {
vue.nextTick(() => {
createModel();
});
};
vue.onMounted(() => {
vue.nextTick(() => {
createModel();
});
});
const createModel = () => {
props.formFields.forEach((item, index) => {
if (item.show !== void 0 && !item.show)
return;
switch (item.type) {
case "selectTree":
handleSelectTree(item);
break;
case "radioGroup":
handleRadioGroup(item);
break;
case "radioGroupSelect":
handleRadioGroupSelect(item, index);
break;
default:
handleDefault(item);
break;
}
});
};
const handleSelectTree = (item) => {
var _a, _b;
model[item.columnName] = ((_a = item == null ? void 0 : item.attributes) == null ? void 0 : _a.currentNodeKey) || ((_b = item == null ? void 0 : item.attributes) == null ? void 0 : _b.defaultCheckedKeys);
};
const handleRadioGroup = (item) => {
var _a, _b;
item.value = (_a = item.defaultValue) != null ? _a : null;
model[item.columnName] = (_b = item.defaultValue) != null ? _b : item.defaultValue === 0 ? item.defaultValue : "";
};
const handleRadioGroupSelect = (item, index) => {
var _a, _b;
const radioGroupSelectRef = formItemRefs.value[index].radioGroupSelectRef;
radioGroupSelectRef.setValue(item.defaultValue || "");
if (item.defaultCheckedKeys && item.defaultCheckedKeys.length > 0) {
(_b = (_a = item.attributes) == null ? void 0 : _a.radioGroups) == null ? void 0 : _b.forEach(
(subItem, subIndex) => {
subItem.radioValue = item.defaultCheckedKeys[subIndex];
}
);
}
model[item.columnName] = radioGroupSelectRef.getModel();
};
const handleDefault = (item) => {
var _a;
model[item.columnName] = (_a = item.defaultValue) != null ? _a : item.defaultValue === 0 ? item.defaultValue : "";
};
const setValue = (columnName, value) => {
model[columnName] = value;
};
const setOptions = (columnName, options) => {
props.formFields.forEach((item) => {
if (item.columnName === columnName) {
item.options = options;
}
});
};
const setDisabled = (columnName, state) => {
props.formFields.forEach((item) => {
if (item.columnName === columnName) {
item.disabled = state;
}
});
};
const setFormField = (columnName, key, value) => {
props.formFields.forEach((item) => {
if (item.columnName === columnName) {
item[key] = value;
}
});
};
const returnLabelWidth = () => {
if (props.labelWidth) {
return props.labelWidth;
}
if (props.formFields && props.formFields.length > 0) {
let max = props.formFields[0];
props.formFields.forEach((cell) => {
if (cell.label.length > max.label.length && (cell.show === void 0 || cell.show)) {
max = cell;
}
});
const length = max.label.replace(/[^\u0020-\u007E]/g, "*").length;
const num = Number(14 * length) + 23;
return `${num}px`;
}
};
expose({
setValue,
setOptions,
setDisabled,
setFormField,
getModel,
resetModel
});
return (_ctx, _cache) => {
const _component_asp_button = vue.resolveComponent("asp-button");
const _component_asp_button_list = vue.resolveComponent("asp-button-list");
const _component_asp_form_item = vue.resolveComponent("asp-form-item");
const _component_asp_form = vue.resolveComponent("asp-form");
return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
vue.createVNode(_component_asp_form, vue.mergeProps({
ref_key: "validateFormRef",
ref: validateFormRef,
model,
size: "mini",
"label-width": returnLabelWidth(),
"label-position": "right"
}, _ctx.$attrs, { inline: true }), {
default: vue.withCtx(() => [
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(__props.formFields, (item, index) => {
return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
(item.show === void 0 ? true : item.show) ? (vue.openBlock(), vue.createBlock(formItem["default"], vue.mergeProps({ key: 0 }, item.attributes, {
ref_for: true,
ref: (el) => {
if (el)
formItemRefs.value[index] = el;
},
key: index,
modelValue: model[item.columnName],
"onUpdate:modelValue": ($event) => model[item.columnName] = $event,
item,
class: ["query-form-item", "asp-form-item__" + (item.type || "input")]
}, vue.toHandlers(item.methods)), null, 16, ["modelValue", "onUpdate:modelValue", "item", "class"])) : vue.createCommentVNode("v-if", true)
], 64);
}), 256)),
vue.createVNode(_component_asp_form_item, { class: "query-form-btns" }, {
default: vue.withCtx(() => [
__props.showSubmit ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2, [
vue.createVNode(_component_asp_button, {
class: "blue-solid-btn submit",
type: "primary",
size: "mini",
icon: __props.submitBtnIcon === void 0 ? vue.unref(iconsVue.Search) : __props.submitBtnIcon,
onClick: onSubmit
}, {
default: vue.withCtx(() => [
vue.createTextVNode("\u67E5\u8BE2")
]),
_: 1
}, 8, ["icon"])
])) : vue.createCommentVNode("v-if", true),
__props.showReset ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_3, [
vue.createVNode(_component_asp_button, {
class: "blue-hollow-btn reset",
style: { "margin-left": "10px" },
size: "mini",
icon: __props.resetBtnIcon === void 0 ? vue.unref(iconsVue.RefreshRight) : __props.resetBtnIcon,
onClick: onReset
}, {
default: vue.withCtx(() => [
vue.createTextVNode("\u91CD\u7F6E")
]),
_: 1
}, 8, ["icon"])
])) : vue.createCommentVNode("v-if", true),
__props.buttonList && __props.buttonList.length > 0 ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4, [
vue.renderSlot(_ctx.$slots, "default"),
__props.buttonList && __props.buttonList.length > 0 ? (vue.openBlock(), vue.createBlock(_component_asp_button_list, {
key: 0,
class: "asp-button-list",
"button-list": __props.buttonList
}, null, 8, ["button-list"])) : vue.createCommentVNode("v-if", true)
])) : vue.createCommentVNode("v-if", true)
]),
_: 3
})
]),
_: 3
}, 16, ["model", "label-width"])
]);
};
}
});
var QueryForm = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "E:\\code\\SmartUIPlus\\asp-packages\\components\\pc\\advanced\\query-form\\src\\query-form.vue"]]);
exports["default"] = QueryForm;