UNPKG

vue-admin-core

Version:
96 lines (92 loc) 2.81 kB
'use strict'; var vue = require('vue'); var lodashEs = require('lodash-es'); var elementPlus = require('element-plus'); const useTable = (props, { attrs, emit }, { key, table }) => { const data = vue.ref([]); const originData = vue.ref([]); vue.watch( () => props.data, (value) => { data.value = value; originData.value = value; }, { immediate: true, deep: true } ); const optionProxy = {}; const cacheOptions = vue.computed( () => { var _a, _b; const options = []; const { label, value } = props.props; (_b = (_a = data.value) == null ? void 0 : _a.forEach) == null ? void 0 : _b.call(_a, (item) => { var _a2, _b2, _c, _d; options.push({ value: item[value], currentLabel: item[label], isDisabled: lodashEs.isFunction((_a2 = props.props) == null ? void 0 : _a2.disabled) ? (_c = (_b2 = props.props) == null ? void 0 : _b2.disabled) == null ? void 0 : _c.call(_b2, item) : item[(_d = props.props) == null ? void 0 : _d.disabled] }); }); return options; }, { immediate: true } ); const cacheOptionsMap = vue.computed(() => { return cacheOptions.value.reduce((prev, next) => ({ ...prev, [next.value]: next }), {}); }); const setOptionProxy = (key2, vm) => { optionProxy[key2] = vm; }; const filter = (query) => { if (query) { data.value = originData.value.filter( (item) => item[props.props.label].toLowerCase().includes(query.toLowerCase()) ); } else { data.value = originData.value; } }; const result = { ...lodashEs.pick(vue.toRefs(props), Object.keys(elementPlus.ElTable.props)), size: "small", data, border: true, highlightCurrentRow: props.multiple ? false : true, rowKey: key, rowClassName: ({ row }) => { var _a, _b; if (lodashEs.isFunction((_a = props.props) == null ? void 0 : _a.disabled)) { if (props.props.disabled(row)) { return "disabled-row"; } } else if (row[(_b = props.props) == null ? void 0 : _b.disabled]) { return "disabled-row"; } }, onRowClick: (row, column, event) => { var _a, _b; (_a = attrs.onRowClick) == null ? void 0 : _a.call(attrs, row, column, event); optionProxy[row[key.value]].selectOptionClick(); if (props.multiple) { (_b = table.value) == null ? void 0 : _b.toggleRowSelection(row); } }, onSelectAll: (selection) => { emit( elementPlus.UPDATE_MODEL_EVENT, selection.map((item) => item[key.value]) ); } }; return { tableProps: result, setOptionProxy, cacheOptions, cacheOptionsMap, filter }; }; exports.useTable = useTable; //# sourceMappingURL=table.js.map