yanzhen-design-vue
Version:
123 lines (122 loc) • 5.14 kB
JavaScript
import { defineComponent, ref, watch, computed, unref, onMounted, openBlock, createElementBlock, normalizeClass, createCommentVNode, createVNode, isRef } from "vue";
import { useVModel } from "@vueuse/core";
import { useBizObject } from "@yanzhen-libs/utils-biz-object";
import { isFunction } from "lodash-es";
import { YzFormProviderItem } from "../../form-provider-item/index.mjs";
import { otherTableName, otherTableProps, otherTableEmits, otherTableOptions } from "./other-table.mjs";
import "./hooks/index.mjs";
import { OTHER_TABLES_RELEVANCE, OTHER_TABLE_TYPE, COLUMN_BIZ_TYPE } from "./constants/common.mjs";
import { provideOtherTableBizObjectParamsApi } from "./hooks/use-other-table-apis.mjs";
import { useOtherTablesConfig } from "./hooks/use-other-table-config.mjs";
const _sfc_main = /* @__PURE__ */ defineComponent({
...{ name: otherTableName },
__name: "other-table",
props: otherTableProps,
emits: otherTableEmits,
setup(__props, { emit: __emit }) {
const RELEVANCE = OTHER_TABLES_RELEVANCE;
const otherTableType = OTHER_TABLE_TYPE;
const { ns } = otherTableOptions;
const props = __props;
const emit = __emit;
const _modelValue = useVModel(props, "value", emit);
const schemaBody = ref({});
const { getBizObjectParams } = provideOtherTableBizObjectParamsApi(props);
const getSchema = async () => {
const result = await getBizObjectParams({
data: {
bizObjectModelCode: props.relBizObjectModelCode
}
});
const originAttributes = props.originAttributes;
if (originAttributes) {
originAttributes.disabled = true;
}
const elementObjet = {
Attributes: originAttributes,
columnBizType: String(originAttributes == null ? void 0 : originAttributes.relBizObjectColumnBizType),
noData: false,
orderNo: originAttributes == null ? void 0 : originAttributes.orderNo,
type: "ClTable"
};
const nowField = result == null ? void 0 : result.data.find(
(item) => item.columnCode === props.relBizObjectColumnCode
);
const options = {
fields: [nowField],
elements: [elementObjet],
widthRatio: 1
};
const { _schema } = useBizObject(null, options);
watch(_schema, (val) => {
if (val.body.length > 0) {
const body = val.body[0];
body.field.label = "";
schemaBody.value = body;
}
});
return _schema;
};
const cx1IsUpload = computed(() => {
var _a;
const { image, file } = COLUMN_BIZ_TYPE;
return [image, file].includes((_a = props.originAttributes) == null ? void 0 : _a.relBizObjectColumnBizType);
});
const isSourceBizObject = computed(() => {
return props.sourceBizObjectModelCode !== props.relBizObjectModelCode;
});
const config = useOtherTablesConfig();
const onMaskingClick = () => {
var _a, _b;
const associationModalRef = (_a = unref(config)) == null ? void 0 : _a.associationModalRef;
const provideProps = (_b = unref(config)) == null ? void 0 : _b.provideProps;
if (isFunction(associationModalRef == null ? void 0 : associationModalRef.value.openModal)) {
const { sceneID, bizObjectModelCode } = provideProps;
const clickItemData = provideProps.elements.find(
(item) => {
var _a2;
return item.Attributes.id === ((_a2 = props.originAttributes) == null ? void 0 : _a2.columnCode);
}
);
const { id, relBizObjectStorageMode } = clickItemData.Attributes;
const selectType = [RELEVANCE.CX2, RELEVANCE.KZ].includes(relBizObjectStorageMode) ? otherTableType.CHECKBOX : otherTableType.RADIO;
let selectedRowKeys = "";
if ([RELEVANCE.CX1, RELEVANCE.CX2].includes(relBizObjectStorageMode)) {
const CX1PrimaryCode = provideProps.model.CX1PrimaryCode ?? {};
const transData = provideProps.model ?? {};
selectedRowKeys = CX1PrimaryCode[id] || transData[id] || "";
}
const option = {
clickItemData: unref(clickItemData),
sceneID,
bizObjectModelCode,
selectType,
selectedRowKeys
};
associationModalRef.value.openModal(option);
}
};
onMounted(() => {
getSchema();
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", {
class: normalizeClass([unref(ns).b()])
}, [
!isSourceBizObject.value ? (openBlock(), createElementBlock("div", {
key: 0,
class: normalizeClass(["cx1-masking", { "cx1-masking-upload": cx1IsUpload.value }]),
onClick: onMaskingClick
}, null, 2)) : createCommentVNode("", true),
createVNode(unref(YzFormProviderItem), {
modelValue: unref(_modelValue),
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(_modelValue) ? _modelValue.value = $event : null),
schema: schemaBody.value
}, null, 8, ["modelValue", "schema"])
], 2);
};
}
});
export {
_sfc_main as default
};