@@ -70,7 +71,7 @@ export default function Render(
return (
onClick(id, action)}
diff --git a/src/components/pureList/index.json b/src/components/pureList/index.json
new file mode 100644
index 00000000..4bf9f4ab
--- /dev/null
+++ b/src/components/pureList/index.json
@@ -0,0 +1,9 @@
+{
+ "component": true,
+ "usingComponents": {
+ "l-dialog": "../../miniprogram_npm/lin-ui/dialog/index",
+ "l-button": "../../miniprogram_npm/lin-ui/button/index",
+ "popover": "../../miniprogram_npm/popover/popover",
+ "popover-item": "../../miniprogram_npm/popover/popover-item"
+ }
+}
\ No newline at end of file
diff --git a/src/components/pureList/index.ts b/src/components/pureList/index.ts
new file mode 100644
index 00000000..7a5f3e9f
--- /dev/null
+++ b/src/components/pureList/index.ts
@@ -0,0 +1,19 @@
+export default OakComponent({
+ isList: false,
+ formData({ props, features }) {
+ const colorDict = features.style.getColorDict();
+ const dataSchema = features.cache.getSchema();
+ return {
+ colorDict,
+ dataSchema,
+ }
+ },
+ properties: {
+ },
+ data: {
+ },
+ lifetimes: {
+ },
+ methods: {
+ },
+});
diff --git a/src/components/pureList/index.tsx b/src/components/pureList/web.tsx
similarity index 60%
rename from src/components/pureList/index.tsx
rename to src/components/pureList/web.tsx
index efa70abd..9a313751 100644
--- a/src/components/pureList/index.tsx
+++ b/src/components/pureList/web.tsx
@@ -3,11 +3,15 @@ import { useTranslation } from 'react-i18next';
import { Table, Tag, TableProps } from 'antd';
import type { ColumnsType, ColumnType, ColumnGroupType } from 'antd/es/table';
import assert from 'assert';
-import useFeatures from '../../hooks/useFeatures';
-import { getAttributes } from '../../utils/usefulFn';
+import { getAttributes, resolutionPath } from '../../utils/usefulFn';
import { get } from 'oak-domain/lib/utils/lodash';
import dayjs from 'dayjs';
import ActionBtnPanel from '../actionBtnPanel';
+import { EntityDict } from 'oak-domain/lib/types/Entity';
+import { WebComponentProps } from '../../types/Page';
+import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
+import { ColorDict } from 'oak-domain/lib/types/Style';
+import { StorageSchema } from 'oak-domain/lib/types/Storage';
type SelfColumn = {
path?: string;
@@ -15,15 +19,6 @@ type SelfColumn = {
type Column = SelfColumn & ColumnType;
-
-type Props = {
- entity: string;
- data: any[];
- columns: (Column | string)[];
- disableOp?: boolean;
- tableProps?: TableProps;
- handleClick?: (id: string, action: string) => void;
-}
type RenderCellProps = {
content: any;
@@ -31,6 +26,8 @@ type RenderCellProps = {
path: string;
attr: string;
attrType: string;
+ t: (value: string) => string;
+ colorDict: ColorDict
}
function decodeTitle(entity: string, attr: string) {
@@ -41,49 +38,17 @@ function decodeTitle(entity: string, attr: string) {
return t(`${entity}:attr.${attr}`)
}
-// 解析路径, 获取属性类型、属性值、以及实体名称
-function Fn(entity: string, path: string) {
- let _entity = entity;
- let attr: string;
- assert(!path.includes('['), '数组索引不需要携带[],请使用arr.0.value')
- const features = useFeatures();
- const dataSchema = features.cache.getSchema();
- if (!path.includes('.')) {
- attr = path;
- }
- else {
- const strs = path.split('.');
- // 最后一个肯定是属性
- attr = strs.pop()!;
- // 倒数第二个可能是类名可能是索引
- _entity = strs.pop()!;
- // 判断是否是数组索引
- if (!Number.isNaN(Number(_entity))) {
- _entity = strs.pop()!.split('$')[0];
- }
- }
- const attributes = getAttributes(dataSchema[_entity as keyof typeof dataSchema].attributes);
- const attribute = attributes[attr];
- return {
- entity: _entity,
- attr,
- attribute,
- }
-}
function RenderCell(props: RenderCellProps) {
- const { content, entity, path, attr, attrType } = props;
+ const { content, entity, path, attr, attrType, t, colorDict } = props;
const value = get(content, path);
- const { t } = useTranslation();
- const feature = useFeatures();
- const colorDict = feature.style.getColorDict();
if (!value) {
return (--
);
}
// 属性类型是enum要使用标签
else if (attrType === 'enum') {
return (
-
+
{t(`${entity}:v.${attr}.${value}`)}
)
@@ -96,9 +61,37 @@ function RenderCell(props: RenderCellProps) {
)
}
-function List(props: Props) {
- const { data, columns, entity, disableOp = false, tableProps } = props;
- const { t } = useTranslation();
+export default function Render(
+ props: WebComponentProps<
+ EntityDict & BaseEntityDict,
+ keyof EntityDict,
+ false,
+ {
+ entity: string;
+ data: any[];
+ columns: (Column | string)[];
+ disableOp?: boolean;
+ tableProps?: TableProps;
+ handleClick?: (id: string, action: string) => void;
+ colorDict: ColorDict;
+ dataSchema: StorageSchema;
+ },
+ {
+ }
+ >
+) {
+ const { methods, data: oakData } = props;
+ const { t } = methods;
+ const {
+ entity,
+ data,
+ columns,
+ disableOp = false,
+ tableProps,
+ handleClick,
+ colorDict,
+ dataSchema,
+ } = oakData;
const tableColumns: ColumnsType = columns.map((ele) => {
let title: string = '';
let render: (value: any, row: any) => React.ReactNode = () => <>>;
@@ -109,10 +102,10 @@ function List(props: Props) {
else {
path = ele.path;
}
- const { entity: useEntity, attr, attribute } = Fn(entity, path!) || {};
+ const { entity: useEntity, attr, attribute } = resolutionPath(dataSchema, entity, path!) || {};
title = decodeTitle(useEntity, attr);
render = (value, row) => (
-
+
);
const column = {
align: 'center',
@@ -141,15 +134,14 @@ function List(props: Props) {
render: (value, row) => {
const id = row?.id;
const oakActions = row?.oakActions;
+ assert(!!oakActions, '行数据中不存在oakActions, 请禁用(disableOp:true)或添加oakActions')
return (
-
+ handleClick && handleClick(id, action)} />
)
}
})
}
return (
-
+
);
}
-
-export default List;
diff --git a/src/utils/usefulFn.ts b/src/utils/usefulFn.ts
index 45bbc1f5..256cfdf3 100644
--- a/src/utils/usefulFn.ts
+++ b/src/utils/usefulFn.ts
@@ -1,3 +1,7 @@
+import assert from "assert";
+import { EntityDict } from "oak-domain/lib/types";
+import useFeatures from "../hooks/useFeatures";
+import { StorageSchema } from "oak-domain/lib/types";
export function getAttributes(attributes: Record) {
return Object.assign({}, attributes, {
@@ -17,4 +21,38 @@ export function getAttributes(attributes: Record) {
type: 'datetime',
},
});
+}
+
+export function resolutionPath(dataSchema: StorageSchema, entity: string, path: string) {
+ let _entity = entity;
+ let attr: string;
+ assert(!path.includes('['), '数组索引不需要携带[],请使用arr.0.value')
+ if (!dataSchema) {
+ return {
+ entity: _entity,
+ attr: '',
+ attribute: undefined,
+ }
+ }
+ if (!path.includes('.')) {
+ attr = path;
+ }
+ else {
+ const strs = path.split('.');
+ // 最后一个肯定是属性
+ attr = strs.pop()!;
+ // 倒数第二个可能是类名可能是索引
+ _entity = strs.pop()!;
+ // 判断是否是数组索引
+ if (!Number.isNaN(Number(_entity))) {
+ _entity = strs.pop()!.split('$')[0];
+ }
+ }
+ const attributes = getAttributes(dataSchema[_entity as keyof typeof dataSchema].attributes);
+ const attribute = attributes[attr];
+ return {
+ entity: _entity,
+ attr,
+ attribute,
+ }
}
\ No newline at end of file
diff --git a/tsconfig.json b/tsconfig.json
index ed111b42..4a6e7658 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -71,11 +71,9 @@
"miniprogram-api-typings"
],
"include": [
- "./**/*.ts",
- "./**/*.tsx",
- "./**/*.less",
- "./**/*.wxml",
- "./**/*.json"
+ "src/**/*.ts",
+ "src/**/*.tsx",
+ "./typings/*.d.ts"
],
"exclude": [
"lib",