diff --git a/quasar.config.js b/quasar.config.js index 6e8a8f21c..e9f7a1929 100644 --- a/quasar.config.js +++ b/quasar.config.js @@ -29,7 +29,7 @@ module.exports = configure(function (/* ctx */) { // app boot file (/src/boot) // --> boot files are part of "main.js" // https://v2.quasar.dev/quasar-cli/boot-files - boot: ['i18n', 'axios'], + boot: ['i18n', 'axios', 'vnDate'], // https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#css css: ['app.scss'], diff --git a/src/boot/vnDate.js b/src/boot/vnDate.js new file mode 100644 index 000000000..c78886b57 --- /dev/null +++ b/src/boot/vnDate.js @@ -0,0 +1,18 @@ +import { boot } from 'quasar/wrappers'; + +export default boot(() => { + Date.vnUTC = () => { + const env = process.env.NODE_ENV; + if (!env || env === 'development') return new Date(Date.UTC(2001, 0, 1, 11)); + + return new Date(); + }; + + Date.vnNew = () => { + return new Date(Date.vnUTC()); + }; + + Date.vnNow = () => { + return new Date(Date.vnUTC()).getTime(); + }; +}); diff --git a/src/components/PaginateData.vue b/src/components/PaginateData.vue index 849cadb98..e561af6b1 100644 --- a/src/components/PaginateData.vue +++ b/src/components/PaginateData.vue @@ -38,6 +38,10 @@ const props = defineProps({ type: Number, default: 10, }, + userParams: { + type: Object, + default: null, + }, offset: { type: Number, default: 500, @@ -58,6 +62,7 @@ const arrayData = useArrayData(props.dataKey, { where: props.where, limit: props.limit, order: props.order, + userParams: props.userParams }); const store = arrayData.store; @@ -123,12 +128,20 @@ async function onLoad(...params) { + + +es: + No data to display: Sin datos que mostrar + No results found: No se han encontrado resultados + diff --git a/src/components/ui/VnFilterPanel.vue b/src/components/ui/VnFilterPanel.vue index 06bd16723..f970e2200 100644 --- a/src/components/ui/VnFilterPanel.vue +++ b/src/components/ui/VnFilterPanel.vue @@ -15,17 +15,23 @@ const props = defineProps({ required: false, default: false, }, + params: { + type: Object, + required: false, + default: null, + }, }); const emit = defineEmits(['refresh', 'clear']); const arrayData = useArrayData(props.dataKey); const store = arrayData.store; -const userParams = ref({}); +const userParams = ref(props.params); onMounted(() => { const params = store.userParams; - if (params) { + + if (Object.keys(params).length > 0) { userParams.value = Object.assign({}, params); } }); diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index 53eccc5b5..adee5921e 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -20,20 +20,27 @@ export function useArrayData(key, userOptions) { const page = ref(1); - if (typeof userOptions === 'object') { - if (userOptions.filter) store.filter = userOptions.filter; - if (userOptions.url) store.url = userOptions.url; - if (userOptions.limit) store.limit = userOptions.limit; - if (userOptions.order) store.order = userOptions.order; - } - onMounted(() => { + setOptions() + const query = route.query; if (query.params) { store.userParams = JSON.parse(query.params); } }); + function setOptions() { + if (typeof userOptions === 'object') { + for (const option in userOptions) { + if (userOptions[option] == null) continue + + if (Object.prototype.hasOwnProperty.call(store, option)) { + store[option] = userOptions[option]; + } + } + } + } + async function fetch({ append = false }) { if (!store.url) return; diff --git a/src/filters/index.js b/src/filters/index.js index 5fa3bd9c3..4d24d9f67 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,5 +1,6 @@ import toLowerCase from './toLowerCase'; import toDate from './toDate'; +import toDateString from './toDateString'; import toCurrency from './toCurrency'; import toPercentage from './toPercentage'; import toLowerCamel from './toLowerCamel'; @@ -9,6 +10,7 @@ export { toLowerCase, toLowerCamel, toDate, + toDateString, toCurrency, toPercentage, dashIfEmpty, diff --git a/src/filters/toDateString.js b/src/filters/toDateString.js new file mode 100644 index 000000000..86d2a68e1 --- /dev/null +++ b/src/filters/toDateString.js @@ -0,0 +1,10 @@ +export default function toDateString(date) { + let day = date.getDate(); + let month = date.getMonth() + 1; + let year = date.getFullYear(); + + if (day < 10) day = `0${day}`; + if (month < 10) month = `0${month}`; + + return `${year}-${month}-${day}` +} \ No newline at end of file diff --git a/src/i18n/en/index.js b/src/i18n/en/index.js index e61bbaab0..be4603ea8 100644 --- a/src/i18n/en/index.js +++ b/src/i18n/en/index.js @@ -393,7 +393,6 @@ export default { logOut: 'Log Out', }, smartCard: { - noData: 'No data to display', openCard: 'View card', openSummary: 'Open summary', viewDescription: 'View description', diff --git a/src/i18n/es/index.js b/src/i18n/es/index.js index 2ca9d5ee9..b3336ca7a 100644 --- a/src/i18n/es/index.js +++ b/src/i18n/es/index.js @@ -393,7 +393,6 @@ export default { logOut: 'Cerrar sesiĆ³n', }, smartCard: { - noData: 'Sin datos que mostrar', openCard: 'Ver ficha', openSummary: 'Abrir detalles', viewDescription: 'Ver descripciĆ³n', diff --git a/src/pages/Claim/ClaimRmaList.vue b/src/pages/Claim/ClaimRmaList.vue index 2dbe113be..dcb586e73 100644 --- a/src/pages/Claim/ClaimRmaList.vue +++ b/src/pages/Claim/ClaimRmaList.vue @@ -16,7 +16,7 @@ const input = ref(); const newRma = ref({ code: '', - crated: new Date(), + crated: Date.vnNew(), }); function onInputUpdate(value) { @@ -35,7 +35,7 @@ async function submit() { newRma.value = { code: '', - created: new Date(), + created: Date.vnNew(), }; } diff --git a/src/pages/Ticket/TicketFilter.vue b/src/pages/Ticket/TicketFilter.vue index 9bbc6b7b3..9839c774c 100644 --- a/src/pages/Ticket/TicketFilter.vue +++ b/src/pages/Ticket/TicketFilter.vue @@ -3,6 +3,7 @@ import { ref } from 'vue'; import { useI18n } from 'vue-i18n'; import FetchData from 'components/FetchData.vue'; import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue'; +import toDateString from 'filters/toDateString'; const { t } = useI18n(); const props = defineProps({ @@ -12,6 +13,15 @@ const props = defineProps({ }, }); +const from = Date.vnNew() +const to = Date.vnNew(); +to.setDate(to.getDate() + 1) + +const defaultParams = { + from: toDateString(from), + to: toDateString(to), +}; + const workers = ref(); const provinces = ref(); const states = ref(); @@ -30,7 +40,11 @@ const warehouses = ref(); @on-fetch="(data) => (workers = data)" auto-load /> - +