Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Duplicate data appears when adding "button permissions" to the menu #548

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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