refactor: chech role
This commit is contained in:
parent
1df80aeb02
commit
db12f4f75e
2 changed files with 18 additions and 83 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
|
import { getRole } from 'src/services/keycloak';
|
||||||
|
|
||||||
import { createSelect, SelectProps } from './select';
|
import { createSelect, SelectProps } from './select';
|
||||||
import SelectInput from '../SelectInput.vue';
|
import SelectInput from '../SelectInput.vue';
|
||||||
|
|
@ -29,6 +30,7 @@ type ExclusiveProps = {
|
||||||
codeOnly?: boolean;
|
codeOnly?: boolean;
|
||||||
selectFirstValue?: boolean;
|
selectFirstValue?: boolean;
|
||||||
branchVirtual?: boolean;
|
branchVirtual?: boolean;
|
||||||
|
checkRole?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const props = defineProps<SelectProps<typeof getList> & ExclusiveProps>();
|
const props = defineProps<SelectProps<typeof getList> & ExclusiveProps>();
|
||||||
|
|
@ -98,7 +100,12 @@ function setDefaultValue() {
|
||||||
"
|
"
|
||||||
:hide-selected="false"
|
:hide-selected="false"
|
||||||
:fill-input="false"
|
:fill-input="false"
|
||||||
:rules="[(v: string) => !!v || $t('form.error.required')]"
|
:rules="[
|
||||||
|
(v: string) =>
|
||||||
|
checkRole?.some((v) => getRole()?.includes(v)) ||
|
||||||
|
!!v ||
|
||||||
|
$t('form.error.required'),
|
||||||
|
]"
|
||||||
@filter="filter"
|
@filter="filter"
|
||||||
>
|
>
|
||||||
<template #append v-if="clearable">
|
<template #append v-if="clearable">
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,6 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, watch } from 'vue';
|
|
||||||
import { QSelect } from 'quasar';
|
|
||||||
import { selectFilterOptionRefMod } from 'stores/utils';
|
|
||||||
import { getRole } from 'src/services/keycloak';
|
|
||||||
import useOptionStore from 'stores/options';
|
import useOptionStore from 'stores/options';
|
||||||
import { onMounted } from 'vue';
|
import SelectBranch from 'src/components/shared/select/SelectBranch.vue';
|
||||||
|
|
||||||
import {
|
|
||||||
SaveButton,
|
|
||||||
EditButton,
|
|
||||||
DeleteButton,
|
|
||||||
UndoButton,
|
|
||||||
} from 'components/button';
|
|
||||||
|
|
||||||
withDefaults(
|
withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
|
|
@ -48,36 +37,6 @@ const legalPersonNo = defineModel<string>('legalPersonNo', { default: '' });
|
||||||
const businessType = defineModel<string>('businessType');
|
const businessType = defineModel<string>('businessType');
|
||||||
const jobPosition = defineModel<string>('jobPosition');
|
const jobPosition = defineModel<string>('jobPosition');
|
||||||
const telephoneNo = defineModel<string>('telephoneNo', { default: '' });
|
const telephoneNo = defineModel<string>('telephoneNo', { default: '' });
|
||||||
|
|
||||||
const branchOptions = defineModel<{ id: string; name: string }[]>(
|
|
||||||
'branchOptions',
|
|
||||||
{ default: [] },
|
|
||||||
);
|
|
||||||
const filteredBranchOptions = ref<Record<string, unknown>[]>([]);
|
|
||||||
|
|
||||||
let branchFilter: (
|
|
||||||
value: string,
|
|
||||||
update: (callbackFn: () => void, afterFn?: (ref: QSelect) => void) => void,
|
|
||||||
) => void;
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
branchFilter = selectFilterOptionRefMod(
|
|
||||||
branchOptions,
|
|
||||||
filteredBranchOptions,
|
|
||||||
'name',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => branchOptions.value,
|
|
||||||
() => {
|
|
||||||
branchFilter = selectFilterOptionRefMod(
|
|
||||||
branchOptions,
|
|
||||||
filteredBranchOptions,
|
|
||||||
'name',
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -137,47 +96,16 @@ watch(
|
||||||
|
|
||||||
<div class="col-12 row q-col-gutter-sm">
|
<div class="col-12 row q-col-gutter-sm">
|
||||||
<div class="col-12 row q-col-gutter-sm">
|
<div class="col-12 row q-col-gutter-sm">
|
||||||
<q-select
|
<SelectBranch
|
||||||
outlined
|
:for="`${prefixId}-input-source-registered-branch`"
|
||||||
use-input
|
v-model:value="registeredBranchId"
|
||||||
fill-input
|
|
||||||
emit-value
|
|
||||||
map-options
|
|
||||||
hide-selected
|
|
||||||
hide-bottom-space
|
|
||||||
dense
|
|
||||||
class="col-6"
|
|
||||||
option-value="id"
|
|
||||||
input-debounce="0"
|
|
||||||
option-label="name"
|
|
||||||
v-model="registeredBranchId"
|
|
||||||
:readonly="readonly"
|
|
||||||
:options="filteredBranchOptions"
|
|
||||||
:hide-dropdown-icon="readonly"
|
|
||||||
:label="$t('customer.form.registeredBranch')"
|
:label="$t('customer.form.registeredBranch')"
|
||||||
:for="`${prefixId}-input-source-nationality`"
|
class="col-md-6"
|
||||||
:rules="[
|
simple
|
||||||
(val) => {
|
required
|
||||||
const roles = getRole() || [];
|
:readonly
|
||||||
return (
|
:check-role="['admin', 'system', 'head_of_admin']"
|
||||||
['admin', 'system', 'head_of_admin'].some((v) =>
|
/>
|
||||||
roles.includes(v),
|
|
||||||
) ||
|
|
||||||
!!val ||
|
|
||||||
$t('form.error.required')
|
|
||||||
);
|
|
||||||
},
|
|
||||||
]"
|
|
||||||
@filter="branchFilter"
|
|
||||||
>
|
|
||||||
<template v-slot:no-option>
|
|
||||||
<q-item>
|
|
||||||
<q-item-section class="text-grey">
|
|
||||||
{{ $t('general.noData') }}
|
|
||||||
</q-item-section>
|
|
||||||
</q-item>
|
|
||||||
</template>
|
|
||||||
</q-select>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue