feat: suite refactoring avec amélioration des perfs + suite gestion
chargement ajax via maj
This commit is contained in:
parent
30afd04c90
commit
aa7019fc4c
1 changed files with 42 additions and 41 deletions
|
@ -450,7 +450,6 @@ let triProps = ref([]);
|
||||||
let selectTr = ref([]);
|
let selectTr = ref([]);
|
||||||
let champ_search = ref("html");
|
let champ_search = ref("html");
|
||||||
let chargement = ref(true);
|
let chargement = ref(true);
|
||||||
let nameLocalStorage = ref(calculer_nameLocalStorage());
|
|
||||||
let quelleVue = ref(props.vueblocdefaut);
|
let quelleVue = ref(props.vueblocdefaut);
|
||||||
let vuebloc = ref(false);
|
let vuebloc = ref(false);
|
||||||
let model = ref([]);
|
let model = ref([]);
|
||||||
|
@ -459,11 +458,13 @@ let searchInputHead = ref("");
|
||||||
let searchInputVal = ref("");
|
let searchInputVal = ref("");
|
||||||
let loadingVueSelect = ref(true);
|
let loadingVueSelect = ref(true);
|
||||||
let ajaxCrayons = ref(false);
|
let ajaxCrayons = ref(false);
|
||||||
let maj = ref(0);
|
let maj = ref("");
|
||||||
|
|
||||||
|
let nameLocalStorage = calculer_nameLocalStorage();
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
localforage.setDriver(localforage[props.stockage.toUpperCase()]);
|
localforage.setDriver(localforage[props.stockage.toUpperCase()]);
|
||||||
chargerJson();
|
chargerJson("maj");
|
||||||
if (props.urlvuebloc) {
|
if (props.urlvuebloc) {
|
||||||
fetch(props.urlvuebloc)
|
fetch(props.urlvuebloc)
|
||||||
.then((response) => response.text())
|
.then((response) => response.text())
|
||||||
|
@ -577,9 +578,7 @@ watch(parPageSelect, (e) => {
|
||||||
});
|
});
|
||||||
watch(table, () => {
|
watch(table, () => {
|
||||||
saveHeader();
|
saveHeader();
|
||||||
let $table = [];
|
localforage.setItem(nameLocalStorage, JSON.stringify(table.value));
|
||||||
$table = table.value;
|
|
||||||
localforage.setItem(nameLocalStorage.value, JSON.stringify($table));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(tableau, () => {
|
watch(tableau, () => {
|
||||||
|
@ -617,7 +616,7 @@ watch(filtreColSelected, () => {
|
||||||
}
|
}
|
||||||
if (!ajaxCrayons) {
|
if (!ajaxCrayons) {
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
"filtreselect_" + nameLocalStorage.value,
|
"filtreselect_" + nameLocalStorage,
|
||||||
JSON.stringify(ObfiltreSelect)
|
JSON.stringify(ObfiltreSelect)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -633,7 +632,7 @@ function gererConfig(config) {
|
||||||
crayons.value = config.crayons;
|
crayons.value = config.crayons;
|
||||||
}
|
}
|
||||||
if (config.maj !== undefined) {
|
if (config.maj !== undefined) {
|
||||||
maj.value = config.maj?.lastMAJ;
|
maj.value = config.maj;
|
||||||
}
|
}
|
||||||
if (config.classes !== undefined) {
|
if (config.classes !== undefined) {
|
||||||
classes.value = config.classes;
|
classes.value = config.classes;
|
||||||
|
@ -654,7 +653,7 @@ function gererConfig(config) {
|
||||||
return filtreCol;
|
return filtreCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
function gererData(filtreColRecup, data, id = null) {
|
function gererData(data, id = null) {
|
||||||
if (parseInt(id) > 0) {
|
if (parseInt(id) > 0) {
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
let i = trouver_index(table.value, id);
|
let i = trouver_index(table.value, id);
|
||||||
|
@ -663,12 +662,8 @@ function gererData(filtreColRecup, data, id = null) {
|
||||||
let i = trouver_index(table.value, id);
|
let i = trouver_index(table.value, id);
|
||||||
table.value.splice(i, 1);
|
table.value.splice(i, 1);
|
||||||
}
|
}
|
||||||
localforage.setItem(
|
|
||||||
nameLocalStorage.value,
|
|
||||||
JSON.stringify(table.value)
|
|
||||||
);
|
|
||||||
} else if (id === "maj") {
|
} else if (id === "maj") {
|
||||||
console.log("table.value = ", table.value);
|
if (data.length) {
|
||||||
if (data[0] && data[0].search) {
|
if (data[0] && data[0].search) {
|
||||||
champ_search.value = "search";
|
champ_search.value = "search";
|
||||||
}
|
}
|
||||||
|
@ -678,16 +673,17 @@ function gererData(filtreColRecup, data, id = null) {
|
||||||
table.value[i] = data[index];
|
table.value[i] = data[index];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
localforage.setItem(
|
}
|
||||||
nameLocalStorage.value,
|
|
||||||
JSON.stringify(table.value)
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
table.value = data;
|
table.value = data;
|
||||||
if (data[0] && data[0].search) {
|
if (data[0] && data[0].search) {
|
||||||
champ_search.value = "search";
|
champ_search.value = "search";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
localforage.setItem(nameLocalStorage, JSON.stringify(table.value));
|
||||||
|
}
|
||||||
|
|
||||||
|
function filtrerCol(filtreColRecup) {
|
||||||
if (filtreColRecup !== undefined) {
|
if (filtreColRecup !== undefined) {
|
||||||
filtreColType.value = filtreColRecup;
|
filtreColType.value = filtreColRecup;
|
||||||
filtreCol.value = [];
|
filtreCol.value = [];
|
||||||
|
@ -713,18 +709,17 @@ function chargerJson(id) {
|
||||||
let url = props.apiuri;
|
let url = props.apiuri;
|
||||||
if (parseInt(id) > 0) {
|
if (parseInt(id) > 0) {
|
||||||
url += "&id=" + id;
|
url += "&id=" + id;
|
||||||
} else if (id === "maj") {
|
|
||||||
url += "&maj=" + maj.value;
|
|
||||||
} else {
|
} else {
|
||||||
let config = localStorage.getItem("header_" + nameLocalStorage.value);
|
let config = localStorage.getItem("header_" + nameLocalStorage);
|
||||||
config = recupJson(config);
|
config = recupJson(config);
|
||||||
if (config && config.header !== undefined) {
|
if (config && config.header !== undefined) {
|
||||||
let filtreColRecup = gererConfig(config);
|
|
||||||
localforage
|
localforage
|
||||||
.getItem(nameLocalStorage.value)
|
.getItem(nameLocalStorage)
|
||||||
.then(function (data) {
|
.then(function (data) {
|
||||||
data = recupJson(data);
|
data = recupJson(data);
|
||||||
gererData(filtreColRecup, data, id);
|
let filtreColRecup = gererConfig(config);
|
||||||
|
table.value = data;
|
||||||
|
filtrerCol(filtreColRecup);
|
||||||
if (props.nomblocajaxreload) {
|
if (props.nomblocajaxreload) {
|
||||||
ajaxReload(props.nomblocajaxreload);
|
ajaxReload(props.nomblocajaxreload);
|
||||||
}
|
}
|
||||||
|
@ -733,18 +728,27 @@ function chargerJson(id) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
console.log("config = ", config);
|
||||||
|
if (id === "maj") {
|
||||||
|
if (maj.value) {
|
||||||
|
url += "&maj=" + maj.value;
|
||||||
|
} else if (config && config.maj) {
|
||||||
|
url += "&maj=" + config.maj;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
let config = data.shift();
|
let config = data.shift();
|
||||||
let filtreColRecup = gererConfig(config);
|
let filtreColRecup = gererConfig(config);
|
||||||
gererData(filtreColRecup, data, id);
|
gererData(data, id);
|
||||||
|
filtrerCol(filtreColRecup);
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
chargement.value = false;
|
chargement.value = false;
|
||||||
let filtreselectLS = localStorage.getItem(
|
let filtreselectLS = localStorage.getItem(
|
||||||
"filtreselect_" + nameLocalStorage.value
|
"filtreselect_" + nameLocalStorage
|
||||||
);
|
);
|
||||||
let Tfiltres = [];
|
let Tfiltres = [];
|
||||||
if (props.filtreselect) {
|
if (props.filtreselect) {
|
||||||
|
@ -752,7 +756,7 @@ function chargerJson(id) {
|
||||||
decodeURIComponent(props.filtreselect)
|
decodeURIComponent(props.filtreselect)
|
||||||
);
|
);
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
"filtreselect_" + nameLocalStorage.value,
|
"filtreselect_" + nameLocalStorage,
|
||||||
JSON.stringify(Tfiltres)
|
JSON.stringify(Tfiltres)
|
||||||
);
|
);
|
||||||
} else if (filtreselectLS) {
|
} else if (filtreselectLS) {
|
||||||
|
@ -808,10 +812,7 @@ function saveHeader() {
|
||||||
ordreCol: ordreCol.value,
|
ordreCol: ordreCol.value,
|
||||||
maj: maj.value,
|
maj: maj.value,
|
||||||
};
|
};
|
||||||
localStorage.setItem(
|
localStorage.setItem("header_" + nameLocalStorage, JSON.stringify($header));
|
||||||
"header_" + nameLocalStorage.value,
|
|
||||||
JSON.stringify($header)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
function deleteInputSearch(head) {
|
function deleteInputSearch(head) {
|
||||||
loadingVueSelect.value = false;
|
loadingVueSelect.value = false;
|
||||||
|
@ -964,7 +965,7 @@ function checkboxValider(head, url) {
|
||||||
data: { data: Tcheckbox.value[head] },
|
data: { data: Tcheckbox.value[head] },
|
||||||
type: "POST",
|
type: "POST",
|
||||||
}).done(function () {
|
}).done(function () {
|
||||||
chargerJson();
|
chargerJson("maj");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const Tcheck = encodeURIComponent(
|
const Tcheck = encodeURIComponent(
|
||||||
|
@ -974,7 +975,7 @@ function checkboxValider(head, url) {
|
||||||
url += "&var_zajax=content";
|
url += "&var_zajax=content";
|
||||||
const data = {};
|
const data = {};
|
||||||
data.onClose = () => {
|
data.onClose = () => {
|
||||||
chargerJson();
|
chargerJson("maj");
|
||||||
};
|
};
|
||||||
$.modalbox(url, data);
|
$.modalbox(url, data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue