95 lines
2.4 KiB
Vue
95 lines
2.4 KiB
Vue
<script setup>
|
|
import { useI18n } from 'vue-i18n';
|
|
import { computed, ref } from 'vue';
|
|
import VnTable from 'components/VnTable/VnTable.vue';
|
|
import { useRoute } from 'vue-router';
|
|
import VnSearchbar from 'components/ui/VnSearchbar.vue';
|
|
import { useStateStore } from 'stores/useStateStore';
|
|
const route = useRoute();
|
|
const stateStore = useStateStore();
|
|
const { t } = useI18n();
|
|
const $props = defineProps({
|
|
id: {
|
|
type: Number,
|
|
default: 0,
|
|
},
|
|
});
|
|
const tableRef = ref();
|
|
const entityId = computed(() => $props.id || route.params.id);
|
|
|
|
const columns = computed(() => [
|
|
{
|
|
align: 'left',
|
|
name: 'id',
|
|
label: t('id'),
|
|
isId: true,
|
|
columnFilter: {
|
|
inWhere: true,
|
|
},
|
|
cardVisible: true,
|
|
},
|
|
{
|
|
align: 'left',
|
|
name: 'name',
|
|
label: t('name'),
|
|
cardVisible: true,
|
|
create: true,
|
|
},
|
|
{
|
|
align: 'left',
|
|
name: 'description',
|
|
label: t('description'),
|
|
cardVisible: true,
|
|
create: true,
|
|
},
|
|
]);
|
|
const exprBuilder = (param, value) => {
|
|
switch (param) {
|
|
case 'search':
|
|
return /^\d+$/.test(value)
|
|
? { id: value }
|
|
: {
|
|
or: [
|
|
{ name: { like: `%${value}%` } },
|
|
{ nickname: { like: `%${value}%` } },
|
|
],
|
|
};
|
|
case 'name':
|
|
case 'description':
|
|
return { [param]: { like: `%${value}%` } };
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<template v-if="stateStore.isHeaderMounted()">
|
|
<Teleport to="#searchbar">
|
|
<VnSearchbar
|
|
data-key="Roles"
|
|
:expr-builder="exprBuilder"
|
|
:label="t('role.searchRoles')"
|
|
:info="t('role.searchInfo')"
|
|
/>
|
|
</Teleport>
|
|
</template>
|
|
<VnTable
|
|
ref="tableRef"
|
|
data-key="Roles"
|
|
:url="`VnRoles`"
|
|
:create="{
|
|
urlCreate: 'VnRoles',
|
|
title: t('Create rol'),
|
|
onDataSaved: ({ id }) => tableRef.redirect(id),
|
|
formInitialData: {
|
|
editorFk: entityId,
|
|
},
|
|
}"
|
|
order="id ASC"
|
|
:columns="columns"
|
|
default-mode="table"
|
|
auto-load
|
|
redirect="account/role"
|
|
:is-editable="true"
|
|
/>
|
|
</template>
|