import html from "html";
import { ref, reactive, watch } from "vue";
import { dayjs } from "element-plus";
import { post } from "../../request/index.js";
export default {
template: html`
{{dayjs(model[prop]).format('YYYY-MM-DD HH:mm:ss')}}
{{dayjs(model[prop]).format('YYYY-MM-DD')}}
{{model[prop]}}
`,
props: ["modelValue", "schema", "prop", "isReadOnly"],
emit: ["update:modelValue"],
async setup(props, context) {
const model = reactive(props.modelValue);
watch(model, (value) => {
context.emit("update:modelValue", value);
});
/*start*/
const getDisabled = () => {
if (props.isReadOnly && props.isReadOnly === true) {
return true;
}
if (props.schema.displayOnly) {
return true;
}
if (props.mode === "update" && props.schema.addOnly) {
return true;
}
return false;
};
const getInput = (schema) => {
return schema.input ?? schema.type;
};
/*end*/
//options
const selectProps = ref({});
const selectValues = ref([]);
const options = ref([]);
if (props.schema.options) {
options.value = props.schema.options;
} else if (props.schema.url) {
try {
const url = `${props.schema.url}`;
const result = await post(url, { queryAll: true, query: { isReadonly: null, isDisabled: null, order: null } });
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,
};
},
};