Skip to content

Commit cd34f8c

Browse files
authored
Merge branch 'youlaitech:master' into master
2 parents c82768b + 5dd0185 commit cd34f8c

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Diff for: src/components/PageContent/index.vue

+44
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,23 @@
144144
{{ scope.row[col.prop] }}
145145
</el-link>
146146
</template>
147+
<!-- 生成开关组件 -->
148+
<template v-else-if="col.templet === 'switch'">
149+
<!-- pageData.length>0: 解决el-switch组件会在表格初始化的时候触发一次change事件 -->
150+
<el-switch
151+
v-model="scope.row[col.prop]"
152+
:active-value="col.activeValue ?? 1"
153+
:inactive-value="col.inactiveValue ?? 0"
154+
:inline-prompt="true"
155+
:active-text="col.activeText ?? ''"
156+
:inactive-text="col.inactiveText ?? ''"
157+
:validate-event="false"
158+
@change="
159+
pageData.length > 0 &&
160+
handleSwitchChange(col.prop, scope.row[col.prop], scope.row)
161+
"
162+
/>
163+
</template>
147164
<!-- 格式化为价格 -->
148165
<template v-else-if="col.templet === 'price'">
149166
{{ `${col.priceFormat ?? "¥"}${scope.row[col.prop]}` }}
@@ -274,6 +291,12 @@ export interface IContentConfig<T = any> {
274291
deleteAction?: (ids: string) => Promise<any>;
275292
// 导出的网络请求函数(需返回promise)
276293
exportAction?: (queryParams: T) => Promise<any>;
294+
// 修改属性的网络请求函数(需返回promise)
295+
modifyAction?: (data: {
296+
[key: string]: any;
297+
field: string;
298+
value: boolean | string | number;
299+
}) => Promise<any>;
277300
// 主键名(默认为id)
278301
pk?: string;
279302
// 表格工具栏(默认支持add,delete,export,也可自定义)
@@ -301,6 +324,7 @@ export interface IContentConfig<T = any> {
301324
| "image"
302325
| "list"
303326
| "url"
327+
| "switch"
304328
| "price"
305329
| "percent"
306330
| "icon"
@@ -310,6 +334,10 @@ export interface IContentConfig<T = any> {
310334
imageWidth?: number;
311335
imageHeight?: number;
312336
selectList?: Record<string, any>;
337+
activeValue?: boolean | string | number;
338+
inactiveValue?: boolean | string | number;
339+
activeText?: string;
340+
inactiveText?: string;
313341
priceFormat?: string;
314342
dateFormat?: string;
315343
operat?: Array<
@@ -479,6 +507,22 @@ function exportPageData(queryParams: IObject = {}) {
479507
ElMessage.error("未配置exportAction");
480508
}
481509
}
510+
// 属性修改
511+
function handleSwitchChange(
512+
field: string,
513+
value: boolean | string | number,
514+
row: Record<string, any>
515+
) {
516+
if (props.contentConfig.modifyAction) {
517+
props.contentConfig.modifyAction({
518+
[pk]: row[pk],
519+
field: field,
520+
value: value,
521+
});
522+
} else {
523+
ElMessage.error("未配置modifyAction");
524+
}
525+
}
482526
483527
// 列设置类型声明
484528
interface IColumnSetting {

Diff for: src/views/demo/curd/config/content2.ts

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { IContentConfig } from "@/components/PageContent/index.vue";
33
const contentConfig: IContentConfig = {
44
pageName: "sys:user",
55
indexAction: function (params) {
6+
// console.log("indexAction:", params);
67
return Promise.resolve({
78
total: 2,
89
list: [
@@ -17,6 +18,7 @@ const contentConfig: IContentConfig = {
1718
icon: "el-icon-setting",
1819
gender: 1,
1920
status: 1,
21+
status2: 1,
2022
createTime: 1715647982437,
2123
},
2224
{
@@ -30,11 +32,16 @@ const contentConfig: IContentConfig = {
3032
icon: "el-icon-user",
3133
gender: 0,
3234
status: 0,
35+
status2: 0,
3336
createTime: 1715648977426,
3437
},
3538
],
3639
});
3740
},
41+
modifyAction(data) {
42+
// console.log("modifyAction:", data);
43+
return Promise.resolve(null);
44+
},
3845
cols: [
3946
{ type: "selection", width: 50, align: "center" },
4047
{ label: "ID", align: "center", prop: "id" },
@@ -69,6 +76,16 @@ const contentConfig: IContentConfig = {
6976
templet: "custom",
7077
slotName: "status",
7178
},
79+
{
80+
label: "状态",
81+
align: "center",
82+
prop: "status2",
83+
templet: "switch",
84+
activeValue: 1,
85+
inactiveValue: 0,
86+
activeText: "启用",
87+
inactiveText: "禁用",
88+
},
7289
{
7390
label: "创建时间",
7491
align: "center",

0 commit comments

Comments
 (0)