perf: remove unnecessay code
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
217b26fbe8
commit
cdee2155b2
|
@ -35,6 +35,7 @@ const $props = defineProps({
|
|||
|
||||
const emit = defineEmits(['onFetch']);
|
||||
defineExpose({ fetch });
|
||||
|
||||
onMounted(async () => {
|
||||
if ($props.autoLoad) {
|
||||
await fetch();
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
import axios from 'axios';
|
||||
|
||||
export function useAxios(props, url) {
|
||||
if (!url) url = props.url;
|
||||
const handleFilter = (filter) => {
|
||||
filter = Object.assign(filter, props.filter);
|
||||
if (props.where && !filter.where) filter.where = props.where;
|
||||
if (props.sortBy) filter.order = props.sortBy;
|
||||
if (props.limit) filter.limit = props.limit;
|
||||
return JSON.stringify(filter);
|
||||
};
|
||||
const fetch = async (filter) =>
|
||||
(
|
||||
await axios.get(url, {
|
||||
params: { filter: handleFilter(filter), ...props.params },
|
||||
})
|
||||
).data;
|
||||
|
||||
const push = async (method = 'PUT', filter, data) =>
|
||||
axios({
|
||||
url,
|
||||
method,
|
||||
data,
|
||||
params: { filter: handleFilter(filter), ...props.params },
|
||||
});
|
||||
|
||||
const pop = async (filter) =>
|
||||
axios.delete(url, { params: { filter: handleFilter(filter), ...props.params } });
|
||||
|
||||
return {
|
||||
fetch,
|
||||
push,
|
||||
pop,
|
||||
};
|
||||
}
|
|
@ -7,10 +7,11 @@ import { useRole } from 'src/composables/useRole';
|
|||
import FormModel from 'components/FormModel.vue';
|
||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||
import { useArrayData } from 'src/composables/useArrayData';
|
||||
import { useAxios } from 'src/composables/useAxios';
|
||||
import FetchData from 'components/FetchData.vue';
|
||||
|
||||
const { hasAny } = useRole();
|
||||
const { t } = useI18n();
|
||||
const fetchData = ref();
|
||||
const originaLockerId = ref();
|
||||
const lockers = ref([]);
|
||||
const { store } = useArrayData('Worker');
|
||||
|
@ -26,14 +27,21 @@ const save = async (data) => {
|
|||
const lockerId = data.id ?? originaLockerId.value;
|
||||
const workerFk = lockerId == originaLockerId.value ? null : entityId.value;
|
||||
|
||||
return useAxios(`Lockers/${lockerId}`).push('PATCH', { workerFk });
|
||||
return axios.patch(`Lockers/${lockerId}`, { workerFk });
|
||||
};
|
||||
|
||||
const init = async (data) => {
|
||||
await fetchData.value.fetch();
|
||||
originaLockerId.value = data.id;
|
||||
};
|
||||
</script>
|
||||
<template>
|
||||
<FetchData
|
||||
ref="fetchData"
|
||||
url="Lockers/codes"
|
||||
:filter="filter"
|
||||
@on-fetch="(data) => (lockers = data)"
|
||||
/>
|
||||
<FormModel
|
||||
:url="`Workers/${entityId}/locker`"
|
||||
model="worker"
|
||||
|
@ -43,8 +51,6 @@ const init = async (data) => {
|
|||
>
|
||||
<template #form="{ data }">
|
||||
<VnSelect
|
||||
url="Lockers/codes"
|
||||
:filter="filter"
|
||||
:label="t('Locker')"
|
||||
v-model="data.id"
|
||||
:options="lockers"
|
||||
|
|
Loading…
Reference in New Issue