Merge pull request #101 from cshaptx4869/patch-63
feat(PageContent): ✨ 支持switch属性修改
This commit is contained in:
@@ -144,6 +144,23 @@
|
|||||||
{{ scope.row[col.prop] }}
|
{{ scope.row[col.prop] }}
|
||||||
</el-link>
|
</el-link>
|
||||||
</template>
|
</template>
|
||||||
|
<!-- 生成开关组件 -->
|
||||||
|
<template v-else-if="col.templet === 'switch'">
|
||||||
|
<!-- pageData.length>0: 解决el-switch组件会在表格初始化的时候触发一次change事件 -->
|
||||||
|
<el-switch
|
||||||
|
v-model="scope.row[col.prop]"
|
||||||
|
:active-value="col.activeValue ?? 1"
|
||||||
|
:inactive-value="col.inactiveValue ?? 0"
|
||||||
|
:inline-prompt="true"
|
||||||
|
:active-text="col.activeText ?? ''"
|
||||||
|
:inactive-text="col.inactiveText ?? ''"
|
||||||
|
:validate-event="false"
|
||||||
|
@change="
|
||||||
|
pageData.length > 0 &&
|
||||||
|
handleSwitchChange(col.prop, scope.row[col.prop], scope.row)
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
<!-- 格式化为价格 -->
|
<!-- 格式化为价格 -->
|
||||||
<template v-else-if="col.templet === 'price'">
|
<template v-else-if="col.templet === 'price'">
|
||||||
{{ `${col.priceFormat ?? "¥"}${scope.row[col.prop]}` }}
|
{{ `${col.priceFormat ?? "¥"}${scope.row[col.prop]}` }}
|
||||||
@@ -274,6 +291,12 @@ export interface IContentConfig<T = any> {
|
|||||||
deleteAction?: (ids: string) => Promise<any>;
|
deleteAction?: (ids: string) => Promise<any>;
|
||||||
// 导出的网络请求函数(需返回promise)
|
// 导出的网络请求函数(需返回promise)
|
||||||
exportAction?: (queryParams: T) => Promise<any>;
|
exportAction?: (queryParams: T) => Promise<any>;
|
||||||
|
// 修改属性的网络请求函数(需返回promise)
|
||||||
|
modifyAction?: (data: {
|
||||||
|
[key: string]: any;
|
||||||
|
field: string;
|
||||||
|
value: boolean | string | number;
|
||||||
|
}) => Promise<any>;
|
||||||
// 主键名(默认为id)
|
// 主键名(默认为id)
|
||||||
pk?: string;
|
pk?: string;
|
||||||
// 表格工具栏(默认支持add,delete,export,也可自定义)
|
// 表格工具栏(默认支持add,delete,export,也可自定义)
|
||||||
@@ -301,6 +324,7 @@ export interface IContentConfig<T = any> {
|
|||||||
| "image"
|
| "image"
|
||||||
| "list"
|
| "list"
|
||||||
| "url"
|
| "url"
|
||||||
|
| "switch"
|
||||||
| "price"
|
| "price"
|
||||||
| "percent"
|
| "percent"
|
||||||
| "icon"
|
| "icon"
|
||||||
@@ -310,6 +334,10 @@ export interface IContentConfig<T = any> {
|
|||||||
imageWidth?: number;
|
imageWidth?: number;
|
||||||
imageHeight?: number;
|
imageHeight?: number;
|
||||||
selectList?: Record<string, any>;
|
selectList?: Record<string, any>;
|
||||||
|
activeValue?: boolean | string | number;
|
||||||
|
inactiveValue?: boolean | string | number;
|
||||||
|
activeText?: string;
|
||||||
|
inactiveText?: string;
|
||||||
priceFormat?: string;
|
priceFormat?: string;
|
||||||
dateFormat?: string;
|
dateFormat?: string;
|
||||||
operat?: Array<
|
operat?: Array<
|
||||||
@@ -479,6 +507,22 @@ function exportPageData(queryParams: IObject = {}) {
|
|||||||
ElMessage.error("未配置exportAction");
|
ElMessage.error("未配置exportAction");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 属性修改
|
||||||
|
function handleSwitchChange(
|
||||||
|
field: string,
|
||||||
|
value: boolean | string | number,
|
||||||
|
row: Record<string, any>
|
||||||
|
) {
|
||||||
|
if (props.contentConfig.modifyAction) {
|
||||||
|
props.contentConfig.modifyAction({
|
||||||
|
[pk]: row[pk],
|
||||||
|
field: field,
|
||||||
|
value: value,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ElMessage.error("未配置modifyAction");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 列设置类型声明
|
// 列设置类型声明
|
||||||
interface IColumnSetting {
|
interface IColumnSetting {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type { IContentConfig } from "@/components/PageContent/index.vue";
|
|||||||
const contentConfig: IContentConfig = {
|
const contentConfig: IContentConfig = {
|
||||||
pageName: "sys:user",
|
pageName: "sys:user",
|
||||||
indexAction: function (params) {
|
indexAction: function (params) {
|
||||||
|
// console.log("indexAction:", params);
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
total: 2,
|
total: 2,
|
||||||
list: [
|
list: [
|
||||||
@@ -17,6 +18,7 @@ const contentConfig: IContentConfig = {
|
|||||||
icon: "el-icon-setting",
|
icon: "el-icon-setting",
|
||||||
gender: 1,
|
gender: 1,
|
||||||
status: 1,
|
status: 1,
|
||||||
|
status2: 1,
|
||||||
createTime: 1715647982437,
|
createTime: 1715647982437,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -30,11 +32,16 @@ const contentConfig: IContentConfig = {
|
|||||||
icon: "el-icon-user",
|
icon: "el-icon-user",
|
||||||
gender: 0,
|
gender: 0,
|
||||||
status: 0,
|
status: 0,
|
||||||
|
status2: 0,
|
||||||
createTime: 1715648977426,
|
createTime: 1715648977426,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
modifyAction(data) {
|
||||||
|
// console.log("modifyAction:", data);
|
||||||
|
return Promise.resolve(null);
|
||||||
|
},
|
||||||
cols: [
|
cols: [
|
||||||
{ type: "selection", width: 50, align: "center" },
|
{ type: "selection", width: 50, align: "center" },
|
||||||
{ label: "ID", align: "center", prop: "id" },
|
{ label: "ID", align: "center", prop: "id" },
|
||||||
@@ -69,6 +76,16 @@ const contentConfig: IContentConfig = {
|
|||||||
templet: "custom",
|
templet: "custom",
|
||||||
slotName: "status",
|
slotName: "status",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "状态",
|
||||||
|
align: "center",
|
||||||
|
prop: "status2",
|
||||||
|
templet: "switch",
|
||||||
|
activeValue: 1,
|
||||||
|
inactiveValue: 0,
|
||||||
|
activeText: "启用",
|
||||||
|
inactiveText: "禁用",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "创建时间",
|
label: "创建时间",
|
||||||
align: "center",
|
align: "center",
|
||||||
|
|||||||
Reference in New Issue
Block a user