Merge branch 'beta' into 8197-VnCardMain
gitea/salix-front/pipeline/pr-beta There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-beta There was a failure building this commit
Details
This commit is contained in:
commit
6fa4269eae
|
@ -74,6 +74,10 @@ const props = defineProps({
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
mapKey: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['onFetch', 'onPaginate', 'onChange']);
|
const emit = defineEmits(['onFetch', 'onPaginate', 'onChange']);
|
||||||
|
@ -96,6 +100,7 @@ const arrayData = useArrayData(props.dataKey, {
|
||||||
exprBuilder: props.exprBuilder,
|
exprBuilder: props.exprBuilder,
|
||||||
keepOpts: props.keepOpts,
|
keepOpts: props.keepOpts,
|
||||||
searchUrl: props.searchUrl,
|
searchUrl: props.searchUrl,
|
||||||
|
mapKey: props.mapKey,
|
||||||
});
|
});
|
||||||
const store = arrayData.store;
|
const store = arrayData.store;
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,10 @@ const props = defineProps({
|
||||||
type: Function,
|
type: Function,
|
||||||
default: undefined,
|
default: undefined,
|
||||||
},
|
},
|
||||||
|
searchRemoveParams: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const searchText = ref();
|
const searchText = ref();
|
||||||
|
@ -101,12 +105,18 @@ async function search() {
|
||||||
|
|
||||||
const filter = {
|
const filter = {
|
||||||
params: {
|
params: {
|
||||||
...Object.fromEntries(staticParams),
|
|
||||||
search: searchText.value,
|
search: searchText.value,
|
||||||
},
|
},
|
||||||
...{ filter: props.filter },
|
filter: props.filter,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!props.searchRemoveParams || !searchText.value) {
|
||||||
|
filter.params = {
|
||||||
|
...Object.fromEntries(staticParams),
|
||||||
|
search: searchText.value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (props.whereFilter) {
|
if (props.whereFilter) {
|
||||||
filter.filter = {
|
filter.filter = {
|
||||||
where: props.whereFilter(searchText.value),
|
where: props.whereFilter(searchText.value),
|
||||||
|
|
|
@ -52,6 +52,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
||||||
'exprBuilder',
|
'exprBuilder',
|
||||||
'searchUrl',
|
'searchUrl',
|
||||||
'navigate',
|
'navigate',
|
||||||
|
'mapKey',
|
||||||
];
|
];
|
||||||
if (typeof userOptions === 'object') {
|
if (typeof userOptions === 'object') {
|
||||||
for (const option in userOptions) {
|
for (const option in userOptions) {
|
||||||
|
@ -121,17 +122,12 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
||||||
const { limit } = filter;
|
const { limit } = filter;
|
||||||
store.hasMoreData = limit && response.data.length >= limit;
|
store.hasMoreData = limit && response.data.length >= limit;
|
||||||
|
|
||||||
if (append) {
|
processData(response.data, { map: !!store.mapKey, append });
|
||||||
if (!store.data) store.data = [];
|
if (!append && !isDialogOpened()) updateRouter && updateStateParams();
|
||||||
for (const row of response.data) store.data.push(row);
|
|
||||||
} else {
|
|
||||||
store.data = response.data;
|
|
||||||
if (!isDialogOpened()) updateRouter && updateStateParams();
|
|
||||||
}
|
|
||||||
|
|
||||||
store.isLoading = false;
|
store.isLoading = false;
|
||||||
|
|
||||||
canceller = null;
|
canceller = null;
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,6 +289,31 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
|
||||||
router.replace(newUrl);
|
router.replace(newUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processData(data, { map = true, append = true }) {
|
||||||
|
if (!append) {
|
||||||
|
store.data = [];
|
||||||
|
store.map = new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Array.isArray(data)) store.data = data;
|
||||||
|
else if (!map && append) for (const row of data) store.data.push(row);
|
||||||
|
else
|
||||||
|
for (const row of data) {
|
||||||
|
const key = row[store.mapKey];
|
||||||
|
const val = { ...row, key };
|
||||||
|
if (store.map.has(key)) {
|
||||||
|
const { position } = store.map.get(key);
|
||||||
|
val.position = position;
|
||||||
|
store.map.set(key, val);
|
||||||
|
store.data[position] = val;
|
||||||
|
} else {
|
||||||
|
val.position = store.map.size;
|
||||||
|
store.map.set(key, val);
|
||||||
|
store.data.push(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const totalRows = computed(() => (store.data && store.data.length) || 0);
|
const totalRows = computed(() => (store.data && store.data.length) || 0);
|
||||||
const isLoading = computed(() => store.isLoading || false);
|
const isLoading = computed(() => store.isLoading || false);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useStateStore } from 'stores/useStateStore';
|
import { useStateStore } from 'stores/useStateStore';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { onMounted, onUnmounted, ref, computed, watch, provide, nextTick } from 'vue';
|
import { onMounted, onUnmounted, ref, computed, watch, provide } from 'vue';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import VnPaginate from 'src/components/ui/VnPaginate.vue';
|
import VnPaginate from 'src/components/ui/VnPaginate.vue';
|
||||||
|
@ -101,6 +101,7 @@ provide('onItemSaved', onItemSaved);
|
||||||
url="Orders/CatalogFilter"
|
url="Orders/CatalogFilter"
|
||||||
:label="t('Search items')"
|
:label="t('Search items')"
|
||||||
:info="t('You can search items by name or id')"
|
:info="t('You can search items by name or id')"
|
||||||
|
:search-remove-params="false"
|
||||||
/>
|
/>
|
||||||
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above>
|
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above>
|
||||||
<QScrollArea class="fit text-grey-8">
|
<QScrollArea class="fit text-grey-8">
|
||||||
|
|
|
@ -441,6 +441,7 @@ watch(
|
||||||
<QPage class="column items-center q-pa-md">
|
<QPage class="column items-center q-pa-md">
|
||||||
<VnTable
|
<VnTable
|
||||||
data-key="advanceTickets"
|
data-key="advanceTickets"
|
||||||
|
:map-key="false"
|
||||||
ref="vnTableRef"
|
ref="vnTableRef"
|
||||||
url="Tickets/getTicketsAdvance"
|
url="Tickets/getTicketsAdvance"
|
||||||
search-url="advanceTickets"
|
search-url="advanceTickets"
|
||||||
|
|
|
@ -163,7 +163,13 @@ onUnmounted(() => {
|
||||||
<QBtn color="primary" icon="search" dense flat @click="reFetch()" />
|
<QBtn color="primary" icon="search" dense flat @click="reFetch()" />
|
||||||
</template>
|
</template>
|
||||||
</VnInput>
|
</VnInput>
|
||||||
<VnSearchbar v-if="!showSearchBar" :data-key="datakey" :url="url" :redirect="false" />
|
<VnSearchbar
|
||||||
|
v-if="!showSearchBar"
|
||||||
|
:data-key="datakey"
|
||||||
|
:url="url"
|
||||||
|
:redirect="false"
|
||||||
|
:search-remove-params="false"
|
||||||
|
/>
|
||||||
<QTree
|
<QTree
|
||||||
ref="treeRef"
|
ref="treeRef"
|
||||||
:nodes="nodes"
|
:nodes="nodes"
|
||||||
|
|
|
@ -17,6 +17,7 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => {
|
||||||
searchUrl: 'params',
|
searchUrl: 'params',
|
||||||
navigate: null,
|
navigate: null,
|
||||||
page: 1,
|
page: 1,
|
||||||
|
mapKey: 'id',
|
||||||
};
|
};
|
||||||
|
|
||||||
function get(key) {
|
function get(key) {
|
||||||
|
@ -46,6 +47,7 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => {
|
||||||
function getDefaultState() {
|
function getDefaultState() {
|
||||||
return Object.assign(JSON.parse(JSON.stringify(defaultOpts)), {
|
return Object.assign(JSON.parse(JSON.stringify(defaultOpts)), {
|
||||||
data: ref(),
|
data: ref(),
|
||||||
|
map: ref(new Map()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,11 @@ import VnPaginate from 'src/components/ui/VnPaginate.vue';
|
||||||
|
|
||||||
describe('VnPaginate', () => {
|
describe('VnPaginate', () => {
|
||||||
const expectedUrl = '/api/customers';
|
const expectedUrl = '/api/customers';
|
||||||
|
const defaultData = [
|
||||||
|
{ id: 1, name: 'Tony Stark' },
|
||||||
|
{ id: 2, name: 'Jessica Jones' },
|
||||||
|
{ id: 3, name: 'Bruce Wayne' },
|
||||||
|
];
|
||||||
let vm;
|
let vm;
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
const options = {
|
const options = {
|
||||||
|
@ -28,11 +32,7 @@ describe('VnPaginate', () => {
|
||||||
describe('paginate()', () => {
|
describe('paginate()', () => {
|
||||||
it('should call to the paginate() method and set the data on the rows property', async () => {
|
it('should call to the paginate() method and set the data on the rows property', async () => {
|
||||||
vi.spyOn(vm.arrayData, 'loadMore');
|
vi.spyOn(vm.arrayData, 'loadMore');
|
||||||
vm.store.data = [
|
vm.store.data = defaultData;
|
||||||
{ id: 1, name: 'Tony Stark' },
|
|
||||||
{ id: 2, name: 'Jessica Jones' },
|
|
||||||
{ id: 3, name: 'Bruce Wayne' },
|
|
||||||
];
|
|
||||||
|
|
||||||
await vm.paginate();
|
await vm.paginate();
|
||||||
|
|
||||||
|
@ -42,26 +42,25 @@ describe('VnPaginate', () => {
|
||||||
|
|
||||||
it('should call to the paginate() method and then call it again to paginate', async () => {
|
it('should call to the paginate() method and then call it again to paginate', async () => {
|
||||||
vi.spyOn(axios, 'get').mockResolvedValue({
|
vi.spyOn(axios, 'get').mockResolvedValue({
|
||||||
data: [
|
data: defaultData,
|
||||||
{ id: 1, name: 'Tony Stark' },
|
|
||||||
{ id: 2, name: 'Jessica Jones' },
|
|
||||||
{ id: 3, name: 'Bruce Wayne' },
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
vm.store.hasMoreData = true;
|
vm.store.hasMoreData = true;
|
||||||
await vm.$nextTick();
|
await vm.$nextTick();
|
||||||
|
|
||||||
vm.store.data = [
|
vm.store.data = defaultData;
|
||||||
{ id: 1, name: 'Tony Stark' },
|
|
||||||
{ id: 2, name: 'Jessica Jones' },
|
|
||||||
{ id: 3, name: 'Bruce Wayne' },
|
|
||||||
];
|
|
||||||
|
|
||||||
await vm.paginate();
|
await vm.paginate();
|
||||||
|
|
||||||
expect(vm.store.skip).toEqual(3);
|
expect(vm.store.skip).toEqual(3);
|
||||||
expect(vm.store.data.length).toEqual(6);
|
expect(vm.store.data.length).toEqual(6);
|
||||||
|
|
||||||
|
vi.spyOn(axios, 'get').mockResolvedValue({
|
||||||
|
data: [
|
||||||
|
{ id: 4, name: 'Peter Parker' },
|
||||||
|
{ id: 5, name: 'Clark Kent' },
|
||||||
|
{ id: 6, name: 'Barry Allen' },
|
||||||
|
],
|
||||||
|
});
|
||||||
await vm.paginate();
|
await vm.paginate();
|
||||||
|
|
||||||
expect(vm.store.skip).toEqual(6);
|
expect(vm.store.skip).toEqual(6);
|
||||||
|
@ -85,11 +84,7 @@ describe('VnPaginate', () => {
|
||||||
|
|
||||||
const index = 1;
|
const index = 1;
|
||||||
const done = vi.fn();
|
const done = vi.fn();
|
||||||
vm.store.data = [
|
vm.store.data = defaultData;
|
||||||
{ id: 1, name: 'Tony Stark' },
|
|
||||||
{ id: 2, name: 'Jessica Jones' },
|
|
||||||
{ id: 3, name: 'Bruce Wayne' },
|
|
||||||
];
|
|
||||||
|
|
||||||
await vm.onLoad(index, done);
|
await vm.onLoad(index, done);
|
||||||
|
|
||||||
|
@ -105,11 +100,7 @@ describe('VnPaginate', () => {
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
vm.store.data = [
|
vm.store.data = defaultData;
|
||||||
{ id: 1, name: 'Tony Stark' },
|
|
||||||
{ id: 2, name: 'Jessica Jones' },
|
|
||||||
{ id: 3, name: 'Bruce Wayne' },
|
|
||||||
];
|
|
||||||
|
|
||||||
expect(vm.pagination.page).toEqual(1);
|
expect(vm.pagination.page).toEqual(1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue