yanzhen-design-vue
Version:
147 lines (146 loc) • 5.35 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const shared = require("@vue/shared");
const lodashEs = require("lodash-es");
const utils = require("@yanzhen-libs/utils");
require("../constants/index.cjs");
const common = require("../constants/common.cjs");
const otherTableConfig = require("../constants/other-table-config.cjs");
const RELEVANCE = common.OTHER_TABLES_RELEVANCE;
const otherTableType = common.OTHER_TABLE_TYPE;
function useOtherTablesConfig() {
const config = vue.inject(otherTableConfig.otherTablesContextKey);
return vue.computed(() => {
return vue.unref(config);
});
}
const provideOtherTablesConfig = (context) => {
vue.provide(otherTableConfig.otherTablesContextKey, context);
};
const useOtherTable = (props, otherOptions) => {
const primaryCodeKey = "CX1PrimaryCode";
const associationModalRef = vue.ref(null);
const { ctx, provideConfig } = otherOptions;
const associationSubmit = (options) => {
console.log("[options]", options);
const isRadio = options.type === otherTableType.RADIO;
isRadio ? stagingCx1Data(options) : stagingTableData(options);
validateForm();
};
const stagingCx1Data = (options) => {
const {
selectRelBizObjectModelCode,
selectTheBizObjRelationTableColumnCode,
selectRecord,
tableColumnCode
} = options;
let transData = {};
let middleData = {};
if (Object.keys(selectRecord).length) {
transData = selectRecord["transData"] ?? {};
middleData = selectRecord["middleData"] ?? {};
}
if (!utils.isEmptyObject(props.model[primaryCodeKey])) {
handleUpdateModel(primaryCodeKey, {});
}
for (const custom of props.elements) {
const {
id,
relBizObjectColumnCode,
relBizObjectModelCode,
relBizObjectStorageMode,
theBizObjRelationTableColumnCode,
theSourceColumnCode,
sourceBizObjectModelCode,
hidden
} = custom.Attributes;
let modelCode = relBizObjectModelCode;
let ColumnCode = theBizObjRelationTableColumnCode;
let isSource = false;
if (sourceBizObjectModelCode && sourceBizObjectModelCode !== relBizObjectModelCode) {
modelCode = sourceBizObjectModelCode;
ColumnCode = theSourceColumnCode;
isSource = true;
}
if (modelCode === selectRelBizObjectModelCode && ColumnCode === selectTheBizObjRelationTableColumnCode) {
if (String(relBizObjectStorageMode) === RELEVANCE.TC) {
handleUpdateModel(id, transData[relBizObjectColumnCode] ?? "");
}
if (String(relBizObjectStorageMode) === RELEVANCE.CX1 && !hidden) {
if (isSource) {
handleUpdateModel(id, middleData[relBizObjectColumnCode] ?? "");
handleUpdateModel(`${primaryCodeKey}.${id}`, transData[relBizObjectColumnCode] ?? "");
} else {
handleUpdateModel(id, selectRecord[relBizObjectColumnCode] ?? "");
handleUpdateModel(`${primaryCodeKey}.${id}`, selectRecord[tableColumnCode] ?? "");
}
}
}
}
};
const stagingTableData = (options) => {
const { selectRecord, clickItemId } = options;
props.elements.forEach((item) => {
const { id } = item.Attributes;
if (id === clickItemId) {
handleUpdateModel(id, selectRecord.join(","));
}
});
};
const openAssociationModal = (raw) => {
var _a;
const { sceneID, bizObjectModelCode } = props;
const clickItemData = props.elements.find(
(item) => item.Attributes.id === raw.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 = props.model.CX1PrimaryCode ?? {};
const transData = props.model ?? {};
selectedRowKeys = CX1PrimaryCode[id] || transData[id] || "";
}
const option = {
clickItemData: vue.unref(clickItemData),
sceneID,
bizObjectModelCode,
selectType,
selectedRowKeys
};
(_a = associationModalRef.value) == null ? void 0 : _a.openModal(option);
};
function handleUpdateModel(key, value) {
const model = vue.unref(props.model);
if (!shared.isObject(model)) return;
const oldValue = lodashEs.get(model, key);
if (oldValue !== value) {
lodashEs.set(model, key, value);
}
}
const validateForm = async () => {
const valid = await ctx.formCtx.beforeSubmit({
edit: true,
isValid: true
});
console.log("valid-valid", valid);
};
vue.provide("openAssociationModal", openAssociationModal);
provideOtherTablesConfig({
component: provideConfig == null ? void 0 : provideConfig.component,
primaryCode: vue.computed(() => props.model.CX1PrimaryCode),
stagingCx1Data,
provideProps: props,
associationModalRef
});
return {
associationModalRef,
stagingCx1Data,
stagingTableData,
associationSubmit
};
};
exports.provideOtherTablesConfig = provideOtherTablesConfig;
exports.useOtherTable = useOtherTable;
exports.useOtherTablesConfig = useOtherTablesConfig;