UNPKG

@opentiny/vue-renderless

Version:

An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.

83 lines (82 loc) 2.92 kB
import { __spreadProps, __spreadValues } from "../chunk-G2ADBYYC.js"; const buildSelectConfig = ({ props, state }) => () => { const checkRowKeys = state.gridCheckedData; const selectConfig = props.selectConfig; return Object.assign({}, selectConfig, { checkRowKeys }); }; const buildRadioConfig = ({ props, state }) => () => { const checkRowKey = state.currentKey; const highlight = true; const radioConfig = props.radioConfig; return Object.assign({}, radioConfig, { checkRowKey, highlight }); }; const filter = ({ props, state, vm }) => (value) => { const { multiple, valueField, filterMethod, remote, remoteMethod } = props; if ((props.filterable || props.searchable) && typeof filterMethod === "function") { const table = vm.$refs.gridRef.$refs.tinyTable; const fullData = table.getTableData().fullData; vm.$refs.gridRef.scrollTo(null, 0); table.loadTableData(filterMethod(value, fullData) || []); vm.$refs.gridRef.handleTableData(!value); state.previousQuery = value; } else if (remote && typeof remoteMethod === "function") { state.previousQuery = value; remoteMethod(value, props.extraQueryParams).then((data) => { if (multiple) { const selectedIds = state.selected.map((sel) => sel[valueField]); vm.$refs.gridRef.clearSelection(); vm.$refs.gridRef.setSelection( data.filter((row) => ~selectedIds.indexOf(row[valueField])), true ); state.remoteData = data.filter((row) => !~selectedIds.indexOf(row[valueField])).concat(state.selected); } else { vm.$refs.gridRef.clearRadioRow(); vm.$refs.gridRef.setRadioRow(find(data, (item) => props.modelValue === item[props.valueField])); state.remoteData = data; } vm.$refs.gridRef.$refs.tinyTable.lastScrollTop = 0; vm.$refs.gridRef.loadData(data); vm.$refs.gridRef.handleTableData(!value); }); } }; const radioChange = ({ props, vm, emit }) => ({ row }) => { if (!props.multiple) { vm.$refs.baseSelectRef.updateSelectedData(__spreadProps(__spreadValues({}, row), { currentLabel: row[props.textField], value: row[props.valueField], state: { currentLabel: row[props.textField] } })); vm.$refs.baseSelectRef.hidePanel(); emit("update:modelValue", row); emit("change", row); } }; const selectChange = ({ props, vm, emit }) => ({ $table, selection, checked, row }) => { if (props.multiple) { vm.$refs.baseSelectRef.updateSelectedData( selection.map((node) => { return __spreadProps(__spreadValues({}, node), { currentLabel: node[props.textField], value: node[props.valueField], isGrid: true }); }) ); emit("update:modelValue", selection); emit("change", selection); } }; export { buildRadioConfig, buildSelectConfig, filter, radioChange, selectChange };