import html from "html"; import { ref, reactive, watch, onMounted } from "vue"; import { dayjs } from "element-plus"; import request, { post } from "../../request/index.js"; export default { template: html` `, props: ["modelValue", "schema", "prop", "isReadOnly", "mode"], emit: ["update:modelValue"], setup(props, context) { const model = reactive(props.modelValue); watch(model, (value) => { context.emit("update:modelValue", value); }); /*start*/ const getDisabled = () => { if (props.mode==='details') { return true; } if (props.mode === "update" && props.schema.readOnly) { return true; } return false; }; const getInput = (schema) => { return schema.input ?? schema.type; }; /*end*/ //options const selectProps = ref({}); const selectValues = ref([]); const options = ref([]); onMounted(async () => { if (props.schema.options) { options.value = props.schema.options; } else if (props.schema.url) { try { const url = `${props.schema.url}`; const result = await request(url, null, { method: "get" }); options.value = result.data?.items.map((o) => ({ value: o[props.schema.value], label: o[props.schema.label], })); } catch (error) { console.log(error); } } }); return { model, getDisabled, getInput, dayjs, selectProps, selectValues, options, }; }, };