vue-admin-core
Version:
A Component Library for Vue 3
227 lines (222 loc) • 7.23 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var elementPlus = require('element-plus');
var vue$1 = require('@formily/vue');
var reactiveVue = require('@formily/reactive-vue');
var index = require('../../__builtins__/configs/index.js');
var index$1 = require('../../array-base/src/index.js');
require('../../__builtins__/shared/index.js');
var utils = require('../../__builtins__/shared/utils.js');
const isAdditionComponent = (schema) => {
var _a;
if (typeof schema["x-component"] !== "string")
return false;
return ((_a = schema["x-component"]) == null ? void 0 : _a.indexOf("Addition")) > -1;
};
const isIndexComponent = (schema) => {
var _a;
if (typeof schema["x-component"] !== "string")
return false;
return ((_a = schema["x-component"]) == null ? void 0 : _a.indexOf("Index")) > -1;
};
const isRemoveComponent = (schema) => {
var _a;
if (typeof schema["x-component"] !== "string")
return false;
return ((_a = schema["x-component"]) == null ? void 0 : _a.indexOf("Remove")) > -1;
};
const isMoveUpComponent = (schema) => {
var _a;
if (typeof schema["x-component"] !== "string")
return false;
return ((_a = schema["x-component"]) == null ? void 0 : _a.indexOf("MoveUp")) > -1;
};
const isMoveDownComponent = (schema) => {
var _a;
if (typeof schema["x-component"] !== "string")
return false;
return ((_a = schema["x-component"]) == null ? void 0 : _a.indexOf("MoveDown")) > -1;
};
const isOperationComponent = (schema) => {
return isAdditionComponent(schema) || isRemoveComponent(schema) || isMoveDownComponent(schema) || isMoveUpComponent(schema);
};
const ArrayCardsInner = reactiveVue.observer(
vue.defineComponent({
name: "FArrayCards",
inheritAttrs: false,
props: ["onChange"],
setup(props, { attrs }) {
const fieldRef = vue$1.useField();
const schemaRef = vue$1.useFieldSchema();
const prefixCls = `${index.stylePrefix}-array-cards`;
const { getKey, keyMap } = index$1.ArrayBase.useKey(schemaRef.value);
return () => {
const field = fieldRef.value;
const schema = schemaRef.value;
const dataSource = Array.isArray(field.value) ? field.value : [];
if (!schema)
throw new Error("can not found schema object");
const renderItems = () => {
return dataSource == null ? void 0 : dataSource.map((item, index) => {
const items = Array.isArray(schema.items) ? schema.items[index] || schema.items[0] : schema.items;
const title = vue.h(
"span",
{},
{
default: () => [
vue.h(
vue$1.RecursionField,
{
schema: items,
name: index,
filterProperties: (schema2) => {
if (!isIndexComponent(schema2))
return false;
return true;
},
onlyRenderProperties: true
},
{}
),
attrs.title || field.title
]
}
);
const extra = vue.h(
"span",
{},
{
default: () => [
vue.h(
vue$1.RecursionField,
{
schema: items,
name: index,
filterProperties: (schema2) => {
if (!isOperationComponent(schema2))
return false;
return true;
},
onlyRenderProperties: true
},
{}
),
attrs.extra
]
}
);
const content = vue.h(
vue$1.RecursionField,
{
schema: items,
name: index,
filterProperties: (schema2) => {
if (isIndexComponent(schema2))
return false;
if (isOperationComponent(schema2))
return false;
return true;
}
},
{}
);
return vue.h(
index$1.ArrayBase.Item,
{
key: getKey(item, index),
index,
record: item
},
{
default: () => vue.h(
elementPlus.ElCard,
{
shadow: "never",
...attrs,
class: [`${prefixCls}-item`].concat(attrs.class)
},
{
default: () => [content],
header: () => vue.h(
elementPlus.ElRow,
{
type: "flex",
justify: "space-between"
},
{
default: () => [title, extra]
}
)
}
)
}
);
});
};
const renderAddition = () => {
return schema.reduceProperties((addition, schema2) => {
if (isAdditionComponent(schema2)) {
return vue.h(
vue$1.RecursionField,
{
schema: schema2,
name: "addition"
},
{}
);
}
return addition;
}, null);
};
const renderEmpty = () => {
if (dataSource == null ? void 0 : dataSource.length)
return;
return vue.h(
elementPlus.ElCard,
{
class: [`${prefixCls}-item`],
shadow: "never",
...attrs,
header: attrs.title || field.title
},
{
default: () => vue.h(elementPlus.ElEmpty, { props: { description: "No Data", imageSize: 100 } }, {})
}
);
};
return vue.h(
"div",
{
class: [prefixCls]
},
vue.h(
index$1.ArrayBase,
{
keyMap
},
{
default: () => {
return [renderEmpty(), renderItems(), renderAddition()];
}
}
)
);
};
}
})
);
const ArrayCards = utils.composeExport(ArrayCardsInner, {
Index: index$1.ArrayBase.Index,
SortHandle: index$1.ArrayBase.SortHandle,
Addition: index$1.ArrayBase.Addition,
Remove: index$1.ArrayBase.Remove,
MoveDown: index$1.ArrayBase.MoveDown,
MoveUp: index$1.ArrayBase.MoveUp,
useArray: index$1.ArrayBase.useArray,
useIndex: index$1.ArrayBase.useIndex,
useRecord: index$1.ArrayBase.useRecord
});
exports.ArrayCards = ArrayCards;
exports.default = ArrayCards;
//# sourceMappingURL=index.js.map