UNPKG

@opentiny/vue-renderless

Version:

An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.

103 lines (102 loc) 3.39 kB
import "../chunk-G2ADBYYC.js"; const fetchDefaultData = ({ emit, fetchArea, nextTick, props, vm, state }) => () => { let parent = ""; nextTick(() => { emit("change-jcr", parent, vm.$refs.refInstance.$parent); }); let promise; if (props.fetchJcr) { promise = props.fetchJcr(); } else { if (typeof fetchArea !== "function") { throw new TypeError("[TINY Error][Area] Prop fetchJcr is mandatory when the framework service is not used"); } promise = fetchArea({ label: "JCR", parent }); } promise.then((data) => state.jcrData = data); state.jcr = ""; state.region = ""; state.rep = ""; state.office = ""; emit("update:modelValue", [state.jcr, state.region, state.rep, state.office]); }; const getRegion = ({ emit, fetchArea, nextTick, props, vm, state }) => (value) => { state.jcr = value; nextTick(() => { emit("change-region", value, vm.$refs.refInstance.$parent); }); let promise; if (props.fetchRegion) { promise = props.fetchRegion(); } else { if (typeof fetchArea !== "function") { throw new TypeError("[TINY Error][Area] Prop fetchRegion is mandatory when the framework service is not used"); } promise = fetchArea({ label: "Region", parent: value }); } promise.then((data) => state.regionData = data); state.region = ""; state.office = ""; state.rep = ""; emit("update:modelValue", [state.jcr, state.region, state.rep, state.office]); }; const getRep = ({ emit, fetchArea, nextTick, props, vm, state }) => (value) => { state.region = value; nextTick(() => { emit("change-rep", value, vm.$refs.refInstance.$parent); }); let promise; if (props.fetchRep) { promise = props.fetchRep(); } else { if (typeof fetchArea !== "function") { throw new TypeError("[TINY Error][Area] Prop fetchRep is mandatory when the framework service is not used"); } promise = fetchArea({ label: "Rep. Office", parent: value }); } promise.then((data) => state.repData = data); state.office = ""; state.rep = ""; emit("update:modelValue", [state.jcr, state.region, state.rep, state.office]); }; const getOffice = ({ emit, fetchArea, nextTick, props, vm, state }) => (value) => { state.rep = value; nextTick(() => { emit("change-office", value, vm.$refs.refInstance.$parent); }); let promise; if (props.fetchOffice) { promise = props.fetchOffice(); } else { if (typeof fetchArea !== "function") { throw new TypeError("[TINY Error][Area] Prop fetchOffice is mandatory when the framework service is not used"); } promise = fetchArea({ label: "Office", parent: value }); } promise.then((data) => state.officeData = data); state.office = ""; emit("update:modelValue", [state.jcr, state.region, state.rep, state.office]); }; const changeOffice = ({ emit, state }) => (value) => { state.office = value; emit("update:modelValue", [state.jcr, state.region, state.rep, state.office]); }; const beforeMount = ({ api, props }) => () => { api.fetchDefaultData(); let { modelValue } = props; if (Array.isArray(modelValue) && modelValue.length) { let [jcr = "", region = "", rep = "", office = ""] = modelValue; api.getRegion(jcr); api.getRep(region); api.getOffice(rep); api.changeOffice(office); } }; export { beforeMount, changeOffice, fetchDefaultData, getOffice, getRegion, getRep };