scinote-web/app/javascript/vue/shared/datatable/row_menu_renderer.vue

66 lines
1.4 KiB
Vue
Raw Normal View History

2023-11-10 20:34:36 +08:00
<template>
2023-12-01 07:01:08 +08:00
<div>
2023-11-10 20:34:36 +08:00
<MenuDropdown
:listItems="this.formattedList"
2023-11-28 16:41:10 +08:00
btnClasses="bg-transparent w-6 h-6 border-0 p-0 flex"
2023-11-10 20:34:36 +08:00
:position="'right'"
:alwaysShow="true"
:btnIcon="'sn-icon sn-icon-more-hori'"
@open="loadActions"
2023-12-01 07:01:08 +08:00
@dtEvent="handleEvents"
2023-11-10 20:34:36 +08:00
></MenuDropdown>
</div>
</template>
<script>
2023-12-11 16:18:22 +08:00
import MenuDropdown from '../menu_dropdown.vue';
2023-11-10 20:34:36 +08:00
import axios from '../../../packs/custom_axios.js';
export default {
name: 'RowMenuRenderer',
props: {
params: {
2023-12-11 16:18:22 +08:00
required: true,
},
2023-11-10 20:34:36 +08:00
},
data() {
return {
2023-12-11 16:18:22 +08:00
actionsMenu: [],
};
2023-11-10 20:34:36 +08:00
},
components: {
2023-12-11 16:18:22 +08:00
MenuDropdown,
2023-11-10 20:34:36 +08:00
},
computed: {
formattedList() {
return this.actionsMenu.map((item) => {
2023-12-11 16:18:22 +08:00
const newItem = { text: item.label };
if (item.type === 'emit') {
newItem.emit = item.name;
2023-11-10 20:34:36 +08:00
}
2023-12-11 16:18:22 +08:00
if (item.type === 'link') {
newItem.url = item.path;
2023-11-10 20:34:36 +08:00
}
2023-12-11 16:18:22 +08:00
newItem.params = item;
2023-12-01 07:01:08 +08:00
2023-12-11 16:18:22 +08:00
return newItem;
});
},
2023-11-10 20:34:36 +08:00
},
methods: {
loadActions() {
2023-12-11 16:18:22 +08:00
if (this.actionsMenu.length > 0) return;
2023-11-10 20:34:36 +08:00
axios.get(this.params.data.urls.actions)
.then((response) => {
2023-12-11 16:18:22 +08:00
this.actionsMenu = response.data.actions;
});
2023-12-01 07:01:08 +08:00
},
handleEvents(event, option) {
2023-12-11 16:18:22 +08:00
const dt = this.params.dtComponent;
dt.$emit(event, option.params, [this.params.data]);
},
},
};
2023-11-10 20:34:36 +08:00
</script>