@@ -5,7 +5,7 @@ import { PropType, reactive, watch, ref, unref } from 'vue'
5
5
import { useValidator } from ' @/hooks/web/useValidator'
6
6
import { useI18n } from ' @/hooks/web/useI18n'
7
7
import { getMenuListApi } from ' @/api/menu'
8
- import { ElTag } from ' element-plus'
8
+ import { ElButton , ElInput , ElPopconfirm , ElTable , ElTableColumn , ElTag } from ' element-plus'
9
9
import AddButtonPermission from ' ./AddButtonPermission.vue'
10
10
import { BaseButton } from ' @/components/Button'
11
11
import { cloneDeep } from ' lodash-es'
@@ -29,7 +29,23 @@ const handleClose = async (tag: any) => {
29
29
})
30
30
}
31
31
32
+ const handleEdit = async (row : any ) => {
33
+ // 深拷贝当前行数据到编辑行
34
+ permissionEditingRow .value = { ... row }
35
+ }
36
+
37
+ const handleSave = async () => {
38
+ const formData = await getFormData ()
39
+ const index = formData ?.permissionList ?.findIndex ((x ) => x .id === permissionEditingRow .value .id )
40
+ if (index !== - 1 ) {
41
+ formData .permissionList [index ] = { ... permissionEditingRow .value }
42
+ permissionEditingRow .value = null // 重置编辑状态
43
+ }
44
+ }
45
+
32
46
const showDrawer = ref (false )
47
+ // 存储正在编辑的行的数据
48
+ const permissionEditingRow = ref <any >(null )
33
49
34
50
const formSchema = reactive <FormSchema []>([
35
51
{
@@ -196,16 +212,73 @@ const formSchema = reactive<FormSchema[]>([
196
212
slots: {
197
213
default : (data : any ) => (
198
214
<>
199
- { data ?.permissionList ?.map ((v ) => {
200
- return (
201
- <ElTag class = " mr-1" key = { v .value } closable onClose = { () => handleClose (v )} >
202
- { v .label }
203
- </ElTag >
204
- )
205
- })}
206
- <BaseButton type = " primary" size = " small" onClick = { () => (showDrawer .value = true )} >
215
+ <BaseButton
216
+ class = " m-t-5px"
217
+ type = " primary"
218
+ size = " small"
219
+ onClick = { () => (showDrawer .value = true )}
220
+ >
207
221
添加权限
208
222
</BaseButton >
223
+ <ElTable data = { data ?.permissionList } >
224
+ <ElTableColumn type = " index" prop = " id" />
225
+ <ElTableColumn
226
+ prop = " value"
227
+ label = " Value"
228
+ v-slots = { {
229
+ default : ({ row }: any ) =>
230
+ permissionEditingRow .value && permissionEditingRow .value .id === row .id ? (
231
+ <ElInput v-model = { permissionEditingRow .value .value } size = " small" />
232
+ ) : (
233
+ <span >{ row .value } </span >
234
+ )
235
+ }}
236
+ />
237
+ <ElTableColumn
238
+ prop = " label"
239
+ label = " Label"
240
+ v-slots = { {
241
+ default : ({ row }: any ) =>
242
+ permissionEditingRow .value && permissionEditingRow .value .id === row .id ? (
243
+ <ElInput v-model = { permissionEditingRow .value .label } size = " small" />
244
+ ) : (
245
+ <ElTag class = " mr-1" key = { row .value } >
246
+ { row .label }
247
+ </ElTag >
248
+ )
249
+ }}
250
+ />
251
+ <ElTableColumn
252
+ label = " Operations"
253
+ width = " 180"
254
+ v-slots = { {
255
+ default : ({ row }: any ) =>
256
+ permissionEditingRow .value && permissionEditingRow .value .id === row .id ? (
257
+ <ElButton size = " small" type = " primary" onClick = { handleSave } >
258
+ 确定
259
+ </ElButton >
260
+ ) : (
261
+ <>
262
+ <ElButton size = " small" type = " primary" onClick = { () => handleEdit (row )} >
263
+ 编辑
264
+ </ElButton >
265
+ <ElPopconfirm
266
+ title = " Are you sure to delete this?"
267
+ onConfirm = { () => handleClose (row )}
268
+ >
269
+ { {
270
+ reference : () => (
271
+ <ElButton size = " small" type = " danger" >
272
+ 删除
273
+ </ElButton >
274
+ )
275
+ }}
276
+ </ElPopconfirm >
277
+ </>
278
+ )
279
+ }}
280
+ />
281
+ </ElTable >
209
282
</>
210
283
)
211
284
}
0 commit comments