@fmdevui/fm-dev
Version:
Page level components developed based on Element Plus.
105 lines (102 loc) • 2.59 kB
JavaScript
import { computed } from 'vue';
function useComputed() {
const compChildName = computed(() => {
return (opt) => {
switch (opt.type) {
case "checkbox":
return "el-checkbox";
case "radio":
return "el-radio";
case "select-arr":
case "select-obj":
return "el-option";
}
};
});
const selectListType = computed(() => {
return (opt) => {
if (opt.listTypeInfo) {
return opt.listTypeInfo[opt.list];
} else {
return [];
}
};
});
const compChildLabel = computed(() => {
return (opt, value) => {
switch (opt.type) {
case "radio":
case "checkbox":
return value[opt.arrLabel || "label"];
case "el-select-multiple":
case "select-arr":
return value[opt.arrLabel || "label"];
case "select-obj":
return value;
}
};
});
const compChildValue = computed(() => {
return (opt, value, key) => {
switch (opt.type) {
case "radio":
case "checkbox":
return value[opt.arrKey || "key"];
case "el-select-multiple":
case "select-arr":
return value[opt.arrKey || "key"];
case "select-obj":
return key;
}
};
});
const compChildShowLabel = computed(() => {
return (opt, value) => {
switch (opt.type) {
case "radio":
case "checkbox":
return value[opt.arrLabel || "label"];
case "el-select-multiple":
case "select-arr":
return value[opt.arrLabel || "label"];
case "select-obj":
return value;
}
};
});
const getPlaceholder = (row) => {
let placeholder;
if (row.comp && typeof row.comp == "string") {
if (row.comp.includes("input")) {
placeholder = "\u8BF7\u8F93\u5165" + row.label;
} else if (row.comp.includes("select") || row.comp.includes("date")) {
placeholder = "\u8BF7\u9009\u62E9" + row.label;
} else {
placeholder = row.label;
}
}
return placeholder;
};
const getColLength = () => {
const width = window.innerWidth;
let colLength = 4;
if (width > 1e3 && width < 1280) {
colLength = 3;
} else if (width > 768 && width <= 1e3) {
colLength = 2;
} else if (width <= 768) {
colLength = 1;
}
return colLength;
};
return {
compChildName,
selectListType,
compChildLabel,
compChildValue,
compChildShowLabel,
getPlaceholder,
getColLength
};
}
export { useComputed };