yanzhen-design-vue
Version:
271 lines (270 loc) • 10.7 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const antDesignVue = require("ant-design-vue");
const lodashEs = require("lodash-es");
const otherTableSelect = require("./other-table-select.cjs");
require("./hooks/index.cjs");
const useOtherTableApis = require("./hooks/use-other-table-apis.cjs");
const useOtherTableConfig = require("./hooks/use-other-table-config.cjs");
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
...{ name: otherTableSelect.otherTableSelectName },
__name: "other-table-select",
props: otherTableSelect.otherTableSelectProps,
emits: otherTableSelect.otherTableSelectEmits,
setup(__props, { emit: __emit }) {
const { ns } = otherTableSelect.otherTableSelectOptions;
const props = __props;
const emit = __emit;
const { getBizObjectParams, getSearchRelBizObjectDataListV3 } = useOtherTableApis.provideOtherTableBizObjectParamsApi(props);
const VNodes = vue.defineComponent({
props: {
vnodes: {
type: Object,
required: true
}
},
render() {
return this.vnodes;
}
});
const config = useOtherTableConfig.useOtherTablesConfig();
const selcetValue = vue.ref(void 0);
const optionsTitle = vue.ref("");
const searchKeyword = vue.ref("");
const fetching = vue.ref(false);
const pagination = vue.ref({ current: 1, defaultCurrent: 1, pageSize: 50, total: 0 });
const options = vue.ref([]);
const tableColumns = vue.ref([]);
const dataSource = vue.ref([]);
const columnClassify = vue.ref({});
const optionsTitleColumn = vue.ref([]);
const otherTablePrimaryCode = vue.ref({});
const columnCode = vue.computed(() => {
var _a;
return ((_a = props.originAttributes) == null ? void 0 : _a.id) || props.columnCode;
});
const bizObjectModelCode = vue.computed(() => {
var _a;
return ((_a = props.originAttributes) == null ? void 0 : _a.bizObjectModelCode) || props.bizObjectModelCode;
});
const relBizObjectModelCode = vue.computed(() => {
return props.relBizObjectModelCode;
});
const propsValue = vue.computed(() => {
return props.value;
});
const theBizObjRelationTableColumnCode = vue.computed(() => {
return props.theBizObjRelationTableColumnCode;
});
const selectValInit = () => {
const name2 = propsValue.value;
const key = otherTablePrimaryCode.value[columnCode.value] || void 0;
options.value = [{ key, name: name2, label: name2 }];
selcetValue.value = key;
};
const queryData = async (reset) => {
if (fetching.value) return;
if (reset) {
pagination.value.current = 1;
dataSource.value = [];
options.value = [];
}
fetching.value = true;
await queryTableColumns();
await queryTableData();
initData();
fetching.value = false;
};
const queryTableColumns = async () => {
if (tableColumns.value.length > 0) return;
const res = await getBizObjectParams({
data: {
bizObjectModelCode: relBizObjectModelCode.value
}
});
tableColumns.value = res.data;
columnClassify.value = res.data.find(
(item) => item.columnClassify === "primary"
);
};
const queryTableData = async () => {
const res = await getSearchRelBizObjectDataListV3({
data: {
bizObjectModelCode: bizObjectModelCode.value,
columnCode: columnCode.value,
orderByPrimaryKeyValues: selcetValue.value,
pageNo: pagination.value.current,
pageSize: pagination.value.pageSize,
searchKeyword: searchKeyword.value
}
});
const splicingColumnCodeList = res.data["splicingColumnCodeList"] || [];
optionsTitleColumn.value = splicingColumnCodeList.map(
(spcode) => tableColumns.value.find((column) => column.columnCode === spcode) || {}
);
optionsTitle.value = optionsTitleColumn.value.map((item) => item.columnName || "-").join(" | ");
const tableColumnValues = res.data["transValueList"] || [];
const transData = res.data["rawDataList"] || {};
const middleData = res.data["middleValueList"] || {};
const evalData = res.data["evalValueList"] || {};
const totalNumber = res.data["totalNumber"] || 0;
tableColumnValues.forEach(
(element, index) => {
element.transData = transData[index] || {};
element.middleData = middleData[index] || {};
element.evalData = evalData[index] || {};
}
);
dataSource.value = dataSource.value.concat(tableColumnValues);
const timestamp = Date.now();
const columnClassifyCode = columnClassify.value.columnCode || "";
dataSource.value.forEach((item, index) => {
item._index = index;
item.key = item[columnClassifyCode] || `${index}_${timestamp}`;
});
pagination.value.total = Number(totalNumber);
};
const initData = () => {
options.value = [];
const dataSourceConvert = dataSource.value.map((item) => {
const option = {
key: item[columnClassify.value.columnCode]
};
const values = [];
for (const tab of optionsTitleColumn.value) {
values.push(item[tab.columnCode] || "-");
}
option.name = values.join(" | ");
option.label = item[optionsTitleColumn.value[0].columnCode];
return option;
});
options.value = dataSourceConvert;
};
const handleChange = (val) => {
var _a, _b;
const key = typeof val === "object" ? val.key : val;
const primaryColumnCode = columnClassify.value.columnCode;
const selectRecord = dataSource.value.find((item) => item[primaryColumnCode] === key) || {};
const options2 = {
selectRelBizObjectModelCode: relBizObjectModelCode.value,
selectTheBizObjRelationTableColumnCode: theBizObjRelationTableColumnCode.value,
tableColumnCode: primaryColumnCode,
selectRecord
};
if (lodashEs.isFunction((_a = vue.unref(config)) == null ? void 0 : _a.stagingCx1Data)) {
(_b = vue.unref(config)) == null ? void 0 : _b.stagingCx1Data(options2);
}
emit("cx1Change", options2);
};
const handleBlur = () => {
searchKeyword.value = "";
};
const handleSearch = (value) => {
searchKeyword.value = value;
queryData(true);
};
const debounceSearch = lodashEs.debounce(handleSearch, 500);
const popupScroll = (e) => {
if (dataSource.value.length >= pagination.value.total) return;
const { target } = e;
const { scrollTop, scrollHeight, clientHeight } = target;
if (scrollTop + 2 + clientHeight >= scrollHeight) {
pagination.value.current += 1;
queryData();
}
};
const dropdownVisibleChange = (open) => {
if (open) {
queryData(true);
}
};
vue.watch(
() => {
var _a;
return (_a = vue.unref(config)) == null ? void 0 : _a.primaryCode;
},
(val) => {
const primaryCodes = val || {};
if (!Object.keys(primaryCodes).includes(columnCode.value)) return;
otherTablePrimaryCode.value = primaryCodes;
selectValInit();
},
{ immediate: true, deep: true }
);
vue.watch(
() => props.dataCommon,
(val) => {
const primaryCodes = (val == null ? void 0 : val.CX1PrimaryCode) || {};
if (!Object.keys(primaryCodes).includes(columnCode.value)) return;
otherTablePrimaryCode.value = primaryCodes;
selectValInit();
},
{ immediate: true, deep: true, once: true }
);
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("div", {
class: vue.normalizeClass([vue.unref(ns).b()])
}, [
vue.createVNode(vue.unref(antDesignVue.Select), {
value: selcetValue.value,
"onUpdate:value": _cache[1] || (_cache[1] = ($event) => selcetValue.value = $event),
placeholder: "请选择",
virtual: "",
disabled: props.disabled,
"filter-option": false,
"not-found-content": fetching.value ? void 0 : null,
"dropdown-class-name": "cx1-select-dropdown",
"show-search": "",
"allow-clear": "",
"option-label-prop": "label",
onChange: handleChange,
onBlur: handleBlur,
onSearch: vue.unref(debounceSearch),
onPopupScroll: popupScroll,
onDropdownVisibleChange: dropdownVisibleChange
}, {
notFoundContent: vue.withCtx(() => [
fetching.value ? (vue.openBlock(), vue.createBlock(vue.unref(antDesignVue.Spin), {
key: 0,
size: "small"
})) : vue.createCommentVNode("", true)
]),
dropdownRender: vue.withCtx(({ menuNode: menu }) => [
vue.createElementVNode("div", {
style: { "padding": "4px 8px" },
onMousedown: _cache[0] || (_cache[0] = (e) => e.preventDefault())
}, vue.toDisplayString(optionsTitle.value), 33),
vue.createVNode(vue.unref(antDesignVue.Divider), { style: { "margin": "4px 0" } }),
vue.createVNode(vue.unref(VNodes), { vnodes: menu }, null, 8, ["vnodes"]),
!fetching.value && options.value.length === 0 ? (vue.openBlock(), vue.createBlock(vue.unref(antDesignVue.Empty), { key: 0 })) : vue.createCommentVNode("", true)
]),
default: vue.withCtx(() => [
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(options.value, (item) => {
return vue.openBlock(), vue.createBlock(vue.unref(antDesignVue.SelectOption), {
key: item.key,
value: item.key,
label: item.label
}, {
default: vue.withCtx(() => [
vue.createVNode(vue.unref(antDesignVue.Tooltip), null, {
title: vue.withCtx(() => [
vue.createTextVNode(vue.toDisplayString(item.name), 1)
]),
default: vue.withCtx(() => [
vue.createTextVNode(" " + vue.toDisplayString(item.name), 1)
]),
_: 2
}, 1024)
]),
_: 2
}, 1032, ["value", "label"]);
}), 128))
]),
_: 1
}, 8, ["value", "disabled", "not-found-content", "onSearch"])
], 2);
};
}
});
exports.default = _sfc_main;