Skip to content

Commit

Permalink
Merge pull request #140 from cshaptx4869/patch-96
Browse files Browse the repository at this point in the history
feat(PageContent): ✨ 操作栏增加render配置参数
  • Loading branch information
haoxianrui authored Jun 14, 2024
2 parents 182e37d + a96aad0 commit 66b913e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/components/CURD/PageContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,10 @@
<!-- 其他 -->
<template v-else-if="typeof item === 'object'">
<el-button
v-if="item.render === undefined || item.render(scope.row)"
v-hasPerm="[`${contentConfig.pageName}:${item.auth}`]"
:icon="item.icon"
type="primary"
:type="item.type ?? 'primary'"
size="small"
link
@click="
Expand Down
8 changes: 5 additions & 3 deletions src/components/CURD/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export type IObject = Record<string, any>;

export interface IOperatData {
name: string;
row: any;
column: any;
row: IObject;
column: IObject;
$index: number;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ export interface IContentConfig<T = any> {
imageWidth?: number;
imageHeight?: number;
// list模板相关参数
selectList?: Record<string, any>;
selectList?: IObject;
// switch模板相关参数
activeValue?: boolean | string | number;
inactiveValue?: boolean | string | number;
Expand All @@ -173,6 +173,8 @@ export interface IContentConfig<T = any> {
icon?: string;
name: string;
text: string;
type?: "primary" | "success" | "warning" | "danger" | "info";
render?: (row: IObject) => boolean;
}
>;
// filter值拼接符
Expand Down
1 change: 1 addition & 0 deletions src/views/demo/curd/config/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const contentConfig: IContentConfig<UserQuery> = {
{ label: "创建时间", align: "center", prop: "createTime", width: 180 },
{
label: "操作",
align: "center",
fixed: "right",
width: 220,
templet: "tool",
Expand Down
29 changes: 24 additions & 5 deletions src/views/demo/curd/config/content2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const contentConfig: IContentConfig = {
cols: [
{ type: "index", width: 50, align: "center" },
{ label: "ID", align: "center", prop: "id", show: false },
{ label: "用户名", align: "center", prop: "username" },
{ label: "文本", align: "center", prop: "username" },
{ label: "图片", align: "center", prop: "avatar", templet: "image" },
{
label: "百分比",
Expand All @@ -63,7 +63,7 @@ const contentConfig: IContentConfig = {
templet: "percent",
},
{
label: "价格",
label: "货币符",
align: "center",
prop: "price",
templet: "price",
Expand All @@ -86,7 +86,7 @@ const contentConfig: IContentConfig = {
slotName: "status",
},
{
label: "状态",
label: "Switch",
align: "center",
prop: "status2",
templet: "switch",
Expand All @@ -96,20 +96,39 @@ const contentConfig: IContentConfig = {
inactiveText: "禁用",
},
{
label: "排序",
label: "输入框",
align: "center",
prop: "sort",
templet: "input",
inputType: "number",
},
{
label: "创建时间",
label: "日期格式化",
align: "center",
prop: "createTime",
minWidth: 120,
templet: "date",
dateFormat: "YYYY/MM/DD HH:mm:ss",
},
{
label: "操作栏",
align: "center",
fixed: "right",
width: 220,
templet: "tool",
operat: [
{
name: "reset_pwd",
auth: "password:reset",
icon: "refresh-left",
text: "重置密码",
type: "primary",
render(row) {
return row.id === 1;
},
},
],
},
],
};

Expand Down
6 changes: 5 additions & 1 deletion src/views/demo/curd/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
</page-modal>
</template>
<template v-else>
<page-content ref="contentRef" :content-config="contentConfig2">
<page-content
ref="contentRef"
:content-config="contentConfig2"
@operat-click="handleOperatClick"
>
<template #status="scope">
<el-tag :type="scope.row[scope.prop] == 1 ? 'success' : 'info'">
{{ scope.row[scope.prop] == 1 ? "启用" : "禁用" }}
Expand Down

0 comments on commit 66b913e

Please sign in to comment.