Skip to content

Commit

Permalink
refactor: ♻️ 权限管理=>菜单管理=>按钮权限重构,可以对已添加的权限按钮进行编辑
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanYi-Hui committed Jun 25, 2024
1 parent 180ae87 commit 0e2f0a3
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 9 deletions.
13 changes: 13 additions & 0 deletions mock/menu/index.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ export default [
title: '分析页',
permissionList: [
{
id: 1,
label: '新增',
value: 'add'
},
{
id: 2,
label: '编辑',
value: 'edit'
}
Expand All @@ -66,14 +68,17 @@ export default [
title: '工作台',
permissionList: [
{
id: 1,
label: '新增',
value: 'add'
},
{
id: 2,
label: '编辑',
value: 'edit'
},
{
id: 3,
label: '删除',
value: 'delete'
}
Expand Down Expand Up @@ -229,18 +234,22 @@ export default [
title: '综合示例-弹窗',
permissionList: [
{
id: 1,
label: '新增',
value: 'add'
},
{
id: 2,
label: '编辑',
value: 'edit'
},
{
id: 3,
label: '删除',
value: 'delete'
},
{
id: 4,
label: '查看',
value: 'view'
}
Expand All @@ -260,18 +269,22 @@ export default [
title: '综合示例-页面',
permissionList: [
{
id: 1,
label: '新增',
value: 'edit'
},
{
id: 2,
label: '编辑',
value: 'edit'
},
{
id: 3,
label: '删除',
value: 'delete'
},
{
id: 4,
label: '查看',
value: 'view'
}
Expand Down
93 changes: 84 additions & 9 deletions src/views/Authorization/Menu/components/Write.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useForm } from '@/hooks/web/useForm'
import { type PropType, reactive, watch, ref, unref } from 'vue'
import { useValidator } from '@/hooks/web/useValidator'
import { getMenuListApi } from '@/api/menu'
import { ElTag } from 'element-plus'
import { ElButton, ElInput, ElPopconfirm, ElTable, ElTableColumn, ElTag } from 'element-plus'
import AddButtonPermission from './AddButtonPermission.vue'
import { BaseButton } from '@/components/Button'
import { cloneDeep } from 'lodash-es'
Expand All @@ -26,7 +26,25 @@ const handleClose = async (tag: any) => {
})
}
const handleEdit = async (row: any) => {
// 深拷贝当前行数据到编辑行
permissionEditingRow.value = { ...row }
}
const handleSave = async () => {
const formData = await getFormData()
const index = formData?.permissionList?.findIndex(
(x: any) => x.id === permissionEditingRow.value.id
)
if (index !== -1) {
formData.permissionList[index] = { ...permissionEditingRow.value }
permissionEditingRow.value = null // 重置编辑状态
}
}
const showDrawer = ref(false)
// 存储正在编辑的行的数据
const permissionEditingRow = ref<any>(null)
const formSchema = reactive<FormSchema[]>([
{
Expand Down Expand Up @@ -193,16 +211,73 @@ const formSchema = reactive<FormSchema[]>([
slots: {
default: (data: any) => (
<>
{data?.permissionList?.map((v: any) => {
return (
<ElTag class="mr-1" key={v.value} closable onClose={() => handleClose(v)}>
{v.label}
</ElTag>
)
})}
<BaseButton type="primary" size="small" onClick={() => (showDrawer.value = true)}>
<BaseButton
class="m-t-5px"
type="primary"
size="small"
onClick={() => (showDrawer.value = true)}
>
添加权限
</BaseButton>
<ElTable data={data?.permissionList}>
<ElTableColumn type="index" prop="id" />
<ElTableColumn
prop="value"
label="Value"
v-slots={{
default: ({ row }: any) =>
permissionEditingRow.value && permissionEditingRow.value.id === row.id ? (
<ElInput v-model={permissionEditingRow.value.value} size="small" />
) : (
<span>{row.value}</span>
)
}}
/>
<ElTableColumn
prop="label"
label="Label"
v-slots={{
default: ({ row }: any) =>
permissionEditingRow.value && permissionEditingRow.value.id === row.id ? (
<ElInput v-model={permissionEditingRow.value.label} size="small" />
) : (
<ElTag class="mr-1" key={row.value}>
{row.label}
</ElTag>
)
}}
/>
<ElTableColumn
label="Operations"
width="180"
v-slots={{
default: ({ row }: any) =>
permissionEditingRow.value && permissionEditingRow.value.id === row.id ? (
<ElButton size="small" type="primary" onClick={handleSave}>
确定
</ElButton>
) : (
<>
<ElButton size="small" type="primary" onClick={() => handleEdit(row)}>
编辑
</ElButton>
<ElPopconfirm
title="Are you sure to delete this?"
onConfirm={() => handleClose(row)}
>
{{
reference: () => (
<ElButton size="small" type="danger">
删除
</ElButton>
)
}}
</ElPopconfirm>
</>
)
}}
/>
</ElTable>
</>
)
}
Expand Down

0 comments on commit 0e2f0a3

Please sign in to comment.