Skip to content

Commit

Permalink
fix: Duplicate data appears when adding "button permissions" to the menu
Browse files Browse the repository at this point in the history
  • Loading branch information
westng committed Feb 20, 2025
1 parent ea3455e commit 86aa4d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 16 additions & 11 deletions web/src/modules/base/views/permission/menu/button-permission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ import type { MaTableExpose } from '@mineadmin/table'
import useTable from '@/hooks/useTable.ts'
import type { MenuVo } from '~/base/api/menu.ts'

const props = defineProps({
modelValue: {
type: Array as PropType<MenuVo[]>,
required: true,
},
})

const emit = defineEmits<{
(event: 'add-btn', value: MenuVo): void
(event: 'update:modelValue', value: MenuVo[]): void
}>()
const t = useTrans().globalTrans
const data = ref<any[]>([])
Expand All @@ -23,6 +31,12 @@ function addItem() {
emit('add-btn', { id: undefined, title: '', code: '', i18n: '', type: 'B' })
}

function deleteItem(index: number) {
const updatedData = [...props.modelValue] as MenuVo[]
updatedData.splice(index, 1)
emit('update:modelValue', updatedData)
}

useTable('buttonFormTable').then((table: MaTableExpose) => {
table.setColumns([
{
Expand All @@ -44,11 +58,7 @@ useTable('buttonFormTable').then((table: MaTableExpose) => {
size="small"
circle
type="danger"
onClick={() => {
if (data.value.length > 0) {
data.value.splice($index, 1)
}
}}
onClick={() => deleteItem($index)}
>
<ma-svg-icon name="ic:round-minus" size={20} />
</el-button>
Expand Down Expand Up @@ -76,12 +86,7 @@ useTable('buttonFormTable').then((table: MaTableExpose) => {
})

function setBtnData(btn: any[]) {
data.value = []
btn.map((item: any) => {
item.type === 'B' && data.value.push(item)
})

buttonFormTable.value?.setData(data.value)
buttonFormTable.value?.setData(btn.filter((item: any) => item.type === 'B'))
}

defineExpose({ setBtnData })
Expand Down
2 changes: 1 addition & 1 deletion web/src/modules/base/views/permission/menu/menu-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ const formItems = ref<MaFormItem[]>([
label: () => t('baseMenuManage.BtnPermission.label'),
prop: 'btnPermission',
show: (_, model) => model.meta.type === 'M',
render: () => <ButtonPermission model={form.value} />,
render: () => <ButtonPermission model={form.value.btnPermission} />,
renderProps: {
ref: (el: any) => {
btnPermissionRef.value = el
Expand Down

0 comments on commit 86aa4d6

Please sign in to comment.