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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
| :task-config.vue
| <template>
| <el-bus-crud ref="crud" v-bind="tableConfig">
| <!-- 不再需要自定义插槽 -->
| </el-bus-crud>
| </template>
|
| <script>
| // 不再需要导入 CronGenerator,因为现在通过全局注册使用
|
| export default {
| data() {
| return {
| tableConfig: {
| defaultForm: {
| taskName: '',
| aiParams: '',
| cron: '',
| isEnabled: false
| },
| url: 'flower/api/filmTaskConfig/list',
| newUrl: 'flower/api/filmTaskConfig/new',
| editUrl: 'flower/api/filmTaskConfig/edit',
| deleteUrl: 'flower/api/filmTaskConfig/delete',
| dialogNeedRequest: false,
| persistSelection: true,
| hasNew:false,
| hasEdit:false,
| hasOperation:false,
| columns: [
| { type: 'selection' },
| { label: '任务名称', prop: 'taskName' },
| { label: 'AI参数', prop: 'aiParams' },
| { label: 'cron表达式', prop: 'cron' },
| {
| label: '启用/禁用',
| formatter: (row) => (
| <el-switch
| value={row.isEnabled}
| onChange={(val) => this.onEnabledChange(row, val)}
| ></el-switch>
| ),
| minWidth: 120,
| fixed: 'right',
| },
| ],
| searchForm: [
| {
| type: 'row',
| items: [
| { label: '任务名称', id: 'taskName', type: 'input' },
| {
| label: '启用/禁用',
| id: 'isEnabled',
| type: 'bus-select-dict',
| default: '1',
| el: {
| code: 'USER_ENABLED_OR_DISABLED',
| clearable: true,
| style: 'width:100%',
| },
| },
| ]
| }
| ],
| form: [
| // { label: '任务名称', id: 'taskName', type: 'input', rules: { required: true, message: '请输入任务名称', trigger: 'blur' } },
| // { label: 'AI参数', id: 'aiParams', type: 'input', rules: { required: true, message: '请输入AI参数', trigger: 'blur' } },
| // {
| // label: '定时配置',
| // id: 'cron',
| // type: 'input',
| // // hidden: () => true, // 改为函数形式
| // rules: { required: true }
| // },
| // { label: '是否启用', id: 'isEnabled', type: 'switch' }
| ],
| extraButtons: [],
| headerButtons: [
| {
| text: '批量删除',
| type: 'danger',
| disabled: selected => selected.length === 0,
| atClick: async (selected) => {
| if (!selected.length) return
|
| try {
| await this.$elBusUtil.confirm(`确定要批量删除这${selected.length}个任务吗?`)
| const ids = selected.map(item => item.id)
| await this.$elBusHttp.request('flower/api/filmTaskConfig/delete/batch', {
| method: 'post',
| data: { ids }
| })
| this.$refs.crud.getList()
| this.$message.success('删除成功')
| } catch (error) {
| if (error !== 'cancel') {
| this.$message.error('删除失败')
| }
| }
| }
| }
| ],
| extraDialogs: [
| {
| title: '任务配置',
| form: [
| { label: '任务名称', id: 'taskName', type: 'input', rules: { required: true, message: '请输入任务名称', trigger: 'blur' } },
| { label: 'AI参数', id: 'aiParams', type: 'input', rules: { required: true, message: '请输入AI参数', trigger: 'blur' } },
| {
| label: '定时配置',
| id: 'cron',
| component: 'cron-generator', // 使用组件名称字符串
| rules: { required: true, message: '请配置定时规则', trigger: 'change' },
| // hidden: () => false, // 明确显示
| props: {
| value: '{{cron}}'
| },
| on: {
| input: (value, form) => {
| form.cron = value;
| }
| }
| },
| { label: '是否启用', id: 'isEnabled', type: 'switch' }
| ],
| atConfirm: async (form) => {
| const url = form.id ? this.tableConfig.editUrl : this.tableConfig.newUrl;
| const { code } = await this.$elBusHttp.request(url, {
| method: 'post',
| data: form
| });
| if (code === 0) {
| this.$message.success('保存成功');
| this.$refs.crud.getList();
| return true;
| }
| return false;
| }
| }
| ]
| }
| }
| },
| head() {
| return {
| title: '模型任务管理',
| }
| },
| methods: {
| onEnabledChange(row, newValue) {
| const url = 'flower/api/aiTaskConfig/isEnable'
| const text = newValue ? '启用' : '禁用'
| this.$elBusUtil
| .confirm(`确定要${text}这个模型任务吗?`)
| .then(async () => {
| const { code } = await this.$elBusHttp.request(url, {
| method: 'post',
| data: {
| id: row.id,
| isEnabled: newValue
| }
| })
|
| if (code === 0) {
| this.$message.success(`${text}成功`)
| this.$refs.crud.getList()
| }
| })
| .catch(() => {
| row.isEnabled = !newValue
| })
| },
| onEdit(row) {
| this.$refs.crud.$refs.extraDialog[0].show(row);
| },
| onNew() {
| this.$refs.crud.$refs.extraDialog[0].show(this.tableConfig.defaultForm);
| }
| },
| mounted() {
| // 配置按钮触发
| this.tableConfig.headerButtons.push(
| {
| text: '新增',
| type: 'primary',
| atClick: () => this.onNew()
| }
| );
|
| // 修改列配置添加操作按钮
| this.tableConfig.columns.push({
| label: '操作',
| fixed: 'right',
| width: 120,
| formatter: (row) => (
| <el-button type="text" onClick={() => this.onEdit(row)}>编辑</el-button>
| )
| });
| }
| }
| </script>
|
| <style scoped>
| /* 可以添加一些样式调整 */
| </style>
|
|