tav-ui
Version:
92 lines (87 loc) • 3.1 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var index = require('../../utils/index2.js');
function useCardActions(options) {
const { dataSource: _dataSource, setDataSource, loading } = options;
async function cardCreateRows(_options) {
const { rows, position = null, useLoading } = _options;
const dataSource = JSON.parse(JSON.stringify(_dataSource.value));
if (useLoading !== void 0 && useLoading)
loading.value.value = true;
let promiseAll;
if (Array.isArray(position)) {
promiseAll = vue.toRaw(rows).map(async (row, idx) => {
const _idx = dataSource.findIndex((d) => d.id === position[idx].id);
dataSource.splice(_idx, 0, row);
return Promise.resolve();
});
} else {
promiseAll = vue.toRaw(rows).map(async (row) => {
if (position === null) {
dataSource.splice(0, 0, row);
} else if (position === -1) {
dataSource.splice(dataSource.length, 0, row);
} else {
const idx = dataSource.findIndex((d) => d.id === position.id);
dataSource.splice(idx, 0, row);
}
return Promise.resolve();
});
}
await Promise.all(promiseAll);
setDataSource(dataSource);
if (useLoading !== void 0 && useLoading)
loading.value.value = false;
}
async function cardReadRows(_options = {}) {
const { useLoading } = _options;
const dataSource = JSON.parse(JSON.stringify(_dataSource.value));
if (useLoading !== void 0 && useLoading)
loading.value.value = true;
await index.sleep(150);
if (useLoading !== void 0 && useLoading)
loading.value.value = false;
return dataSource;
}
async function cardUpdateRows(_options) {
const { rows, deleteRows, useLoading } = _options;
const dataSource = JSON.parse(JSON.stringify(_dataSource.value));
if (useLoading !== void 0 && useLoading)
loading.value.value = true;
const promiseAll = vue.toRaw(rows).map((row, idx) => {
const _idx = dataSource.findIndex((d) => d.id === deleteRows[idx].id);
dataSource.splice(_idx, 1, row);
return Promise.resolve();
});
await Promise.all(promiseAll);
setDataSource(dataSource);
if (useLoading !== void 0 && useLoading)
loading.value.value = false;
}
async function cardDeleteRows(_options) {
const { rows, useLoading } = _options;
let dataSource = JSON.parse(JSON.stringify(_dataSource.value));
if (useLoading !== void 0 && useLoading)
loading.value.value = true;
if (rows === void 0) {
dataSource = [];
} else {
vue.toRaw(rows).forEach((row) => {
const idx = dataSource.findIndex((d) => d.id === row.id);
dataSource.splice(idx, 1);
});
}
setDataSource(dataSource);
if (useLoading !== void 0 && useLoading)
loading.value.value = false;
}
return {
cardCreateRows,
cardReadRows,
cardUpdateRows,
cardDeleteRows
};
}
exports.useCardActions = useCardActions;
//# sourceMappingURL=use-card-actions2.js.map