map to new back

This commit is contained in:
kandrusyak
2023-07-25 02:11:01 +03:00
parent dcaa7b7995
commit 35ff1150e7
5 changed files with 120 additions and 12497 deletions

12498
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -141,7 +141,7 @@ export default {
}, },
computed: { computed: {
dataClientsPresence() { dataClientsPresence() {
return this.dataClients[0]?.initialization; return this.dataClients?.[0]?.initialization;
}, },
}, },
methods: { methods: {
@@ -184,12 +184,11 @@ export default {
} }
}, },
async fetchDataClients() { async fetchDataClients() {
let response = {};
if (this.textSearch) { if (this.textSearch) {
response = await fetchWrapper.get( const response = await fetchWrapper.get(
`general/person/?last_name=${this.textSearch}&limit=${ `persons/?limit=${this.limit}&offset=${
this.limit (this.currentTablePage - 1) * this.limit
}&offset=${(this.currentTablePage - 1) * this.limit}` }`
); );
this.saveDataClients(response); this.saveDataClients(response);
this.saveFilteredClientsCount(response); this.saveFilteredClientsCount(response);
@@ -198,8 +197,8 @@ export default {
length: this.calculatePageCount(this.filteredClientsCount), length: this.calculatePageCount(this.filteredClientsCount),
}; };
} else { } else {
response = await fetchWrapper.get( const response = await fetchWrapper.get(
`general/person/?limit=${this.limit}&offset=${ `persons/?limit=${this.limit}&offset=${
(this.currentTablePage - 1) * this.limit (this.currentTablePage - 1) * this.limit
}` }`
); );
@@ -212,9 +211,7 @@ export default {
} }
}, },
async fetchCreatedClientData() { async fetchCreatedClientData() {
fetchWrapper fetchWrapper.get(`persons/${this.createdClientId}/`).then((response) => {
.get(`general/person/${this.createdClientId}/detail/`)
.then((response) => {
this.dataClients = [response]; this.dataClients = [response];
this.createdClientName = `${response.last_name ?? ""} ${ this.createdClientName = `${response.last_name ?? ""} ${
response?.first_name ?? "" response?.first_name ?? ""

View File

@@ -30,7 +30,7 @@
.flex.items-center.cursor-pointer(@click="changeView", v-if="!wrongData && user.password") .flex.items-center.cursor-pointer(@click="changeView", v-if="!wrongData && user.password")
img(:src="!isView ? eye_close : eye_open") img(:src="!isView ? eye_close : eye_open")
.flex.items-center.gap-x-8px.-ml-2 .flex.items-center.gap-x-8px.-ml-2
q-checkbox(@click="persist", v-model="person", type="checkbox") q-checkbox(v-model="person", type="checkbox")
.flex.non-italic.font-medium.base Запомнить меня .flex.non-italic.font-medium.base Запомнить меня
base-button( base-button(
:disable="disabledButton", :disable="disabledButton",
@@ -60,67 +60,49 @@ export default {
eye_close, eye_close,
eye_open, eye_open,
authorized: true, authorized: true,
user: { username: "", password: "" }, user: {},
userData: {}, userData: {},
person: false, person: false,
}; };
}, },
computed: { computed: {
wrongData() { wrongData() {
return !this.authorized && !this.user.username && !this.user.password; return !this.authorized;
}, },
changeType() { changeType() {
return !this.isView ? "password" : "text"; return !this.isView ? "password" : "text";
}, },
disabledButton() { disabledButton() {
return this.user.username && this.user.password ? false : true; return !(this.user.username && this.user.password);
}, },
showBorder() { showBorder() {
return !this.authorized && !this.user.username && !this.user.password return !this.authorized && !this.user.username && !this.user.password;
? true
: false;
}, },
}, },
methods: { methods: {
changeView() { changeView() {
this.isView = !this.isView; this.isView = !this.isView;
}, },
persist() {
if (!this.person) return;
localStorage.username = this.user.username;
localStorage.password = this.user.password;
},
async auth() { async auth() {
let res = await fetchWrapper.get("auth/users/me/"); this.userData = await fetchWrapper.get("users/me");
res = await res;
let data = await fetchWrapper.get(`accounts/users/${res.id}/detail`);
data = await data;
this.userData = data;
localStorage.setItem("userData", JSON.stringify(this.userData));
}, },
login() { login() {
fetchWrapper fetchWrapper
.post("auth/jwt/create/", { .post("auth/login", {
username: this.user.username, user_name: this.user.username,
password: this.user.password, password: this.user.password,
}) })
.then((token) => { .then(() => {
if (token.access) {
localStorage.setItem("tokenAccess", token.access);
this.auth().then(() => this.$router.push("/")); this.auth().then(() => this.$router.push("/"));
} else { })
.catch(() => {
this.authorized = false; this.authorized = false;
this.user.username = ""; this.user.username = "";
this.user.password = ""; this.user.password = "";
this.$router.push("/login"); this.$router.push("/login");
}
}); });
}, },
}, },
mounted() {
if (localStorage.username) this.user.username = localStorage.username;
if (localStorage.password) this.user.password = localStorage.password;
},
}; };
</script> </script>

View File

@@ -6,19 +6,19 @@ import TheMedcards from "@/pages/medcards/TheMedcards";
import TheLogin from "@/pages/login/TheLogin"; import TheLogin from "@/pages/login/TheLogin";
import LoggedInLayout from "@/components/LoggedInLayout"; import LoggedInLayout from "@/components/LoggedInLayout";
import TheMedicalCard from "@/pages/newMedicalCard/TheMedicalCard"; import TheMedicalCard from "@/pages/newMedicalCard/TheMedicalCard";
import { fetchWrapper } from "@/shared/fetchWrapper";
const ifNotAuthenticated = (to, from, next) => { const ifNotAuthenticated = async (to, from, next) => {
if (!localStorage.getItem("tokenAccess")) { const data = await fetchWrapper.get("users/me");
return next(); if (!data) return next();
} return next("/");
next("/");
}; };
const ifAuthenticated = (to, from, next) => { const ifAuthenticated = async (to, from, next) => {
if (localStorage.getItem("tokenAccess")) { const data = await fetchWrapper.get("users/me");
if (!data) return next("/login");
return next(); return next();
}
next("/login");
}; };
export default createRouter({ export default createRouter({

View File

@@ -1,5 +1,3 @@
import router from "@/router";
function prepareUrl(url) { function prepareUrl(url) {
if (url.startsWith("http")) return url; if (url.startsWith("http")) return url;
return `https://astra-dev.dopcore.com/api/${url}`; return `https://astra-dev.dopcore.com/api/${url}`;
@@ -15,8 +13,7 @@ function handleRequest(method, url, headers, attempts, body, type) {
}) })
.then((res) => { .then((res) => {
if (res.status === 401) { if (res.status === 401) {
localStorage.removeItem("tokenAccess"); //router.go("/login");
router.go("/login");
} else if (res) return res.json(); } else if (res) return res.json();
}) })
.catch((err) => { .catch((err) => {
@@ -33,13 +30,12 @@ function handleRequest(method, url, headers, attempts, body, type) {
* @param {string} type - request type * @param {string} type - request type
*/ */
function request(method, url, headers = {}, body, type = "") { function request(method, url, headers = {}, body, type = "") {
let token = localStorage.getItem("tokenAccess");
let requestOptions = {}; let requestOptions = {};
if (method === "GET" || method === "DELETE") { if (method === "GET" || method === "DELETE") {
requestOptions = { requestOptions = {
method: method, method: method,
credentials: "include",
headers: { headers: {
Authorization: `Bearer ${token}`,
...headers, ...headers,
"Content-Type": "application/json", "Content-Type": "application/json",
Accept: "application/json", Accept: "application/json",
@@ -54,21 +50,21 @@ function request(method, url, headers = {}, body, type = "") {
requestOptions = { requestOptions = {
method: method, method: method,
headers: { headers: {
Authorization: `Bearer ${token}`,
Accept: "application/json", Accept: "application/json",
...headers, ...headers,
}, },
body: body, body: body,
credentials: "include",
}; };
} else } else
requestOptions = { requestOptions = {
method: method, method: method,
headers: { headers: {
Authorization: `Bearer ${token}`,
Accept: "application/json", Accept: "application/json",
"Content-Type": "application/json", "Content-Type": "application/json",
...headers, ...headers,
}, },
credentials: "include",
body: JSON.stringify(body), body: JSON.stringify(body),
}; };
} }