AiragButton.data.ts
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { Switch } from 'ant-design-vue';
import { h, reactive } from 'vue';
import { saveOrUpdate } from '@/views/super/airag/airagbutton/AiragButton.api';
//列表数据
export const columns: BasicColumn[] = [
{
title: '按钮名称',
align: 'center',
dataIndex: 'buttonName',
},
{
title: '按钮开关',
align: 'center',
dataIndex: 'buttonSwitch',
customRender: ({ text, record }) => {
return h(Switch, {
checked: text === 'Y',
loading: switchLoading[record.id],
onChange: (checked: boolean) => handleSwitchChange(checked, record),
});
},
},
{
title: '按钮值',
align: 'center',
dataIndex: 'buttonValues',
},
];
// 定义开关状态映射
const switchLoading = reactive<Record<string, boolean>>({});
// 处理开关状态变化
async function handleSwitchChange(checked: boolean, record: Recordable) {
const newValue = checked ? 'Y' : 'N';
const oldValue = record.buttonSwitch;
// 立即更新本地状态
record.buttonSwitch = newValue;
switchLoading[record.id] = true;
try {
// 调用API更新后端
await saveOrUpdate(
{
id: record.id,
buttonSwitch: newValue,
},
true
);
} catch {
// 出错时回滚状态
record.buttonSwitch = oldValue;
} finally {
switchLoading[record.id] = false;
}
}
//查询数据
export const searchFormSchema: FormSchema[] = [
{
label: '按钮名称',
field: 'buttonName',
component: 'JInput',
},
{
label: '按钮值',
field: 'buttonValues',
component: 'JInput',
},
];
//表单数据
export const formSchema: FormSchema[] = [
{
label: '按钮名称',
field: 'buttonName',
component: 'Input',
required: true,
},
{
label: '按钮开关',
field: 'buttonSwitch',
component: 'JSwitch',
required: true,
componentProps: {},
},
{
label: '按钮值',
field: 'buttonValues',
component: 'Input',
required: true,
},
// TODO 主键隐藏字段,目前写死为ID
{
label: '',
field: 'id',
component: 'Input',
show: false,
},
];
// 高级查询数据
export const superQuerySchema = {
buttonName: { title: '按钮名称', order: 0, view: 'text', type: 'string' },
buttonSwitch: { title: '按钮开关', order: 1, view: 'switch', type: 'string' },
buttonValues: { title: '按钮值', order: 2, view: 'text', type: 'string' },
};
/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
// 默认和原始表单保持一致 如果流程中配置了权限数据,这里需要单独处理formSchema
return formSchema;
}