diff --git a/client/src/components/ymap.vue b/client/src/components/ymap.vue new file mode 100644 index 0000000..044e0bc --- /dev/null +++ b/client/src/components/ymap.vue @@ -0,0 +1,62 @@ + + + diff --git a/client/src/router/index.js b/client/src/router/index.js index 200f989..9e29984 100644 --- a/client/src/router/index.js +++ b/client/src/router/index.js @@ -49,7 +49,9 @@ export default route(function (/* { store, ssrContext } */) { }); Router.beforeEach((to, from, next) => { - if (to.meta.isAuth) { + console.log(process.env.SERVER); + //уточнить зачем нужен process.env.SERVER + if (to.meta.isAuth && !process.env.SERVER) { if (store.state.user) { next(); } else { diff --git a/client/src/services/app.js b/client/src/services/app.js index 2781502..94b24bd 100644 --- a/client/src/services/app.js +++ b/client/src/services/app.js @@ -5,6 +5,8 @@ import { REST, RESTError } from './rest'; // console.log(settings); export default class extends REST { + // export default class Django extends REST { + static get settings() { return settings; } @@ -237,4 +239,16 @@ export default class extends REST { ); }); } + + static getSupportInfo() { + return this._get('radio/support_info', {}, {}) + .then((data) => { + return data; + }) + .catch((error) => { + throw new RESTError(error, 'Ошибка при получении контактов'); + }); + } } + +// window.django = Django; diff --git a/client/src/views/contacts.vue b/client/src/views/contacts.vue index 7d41275..94fc10d 100644 --- a/client/src/views/contacts.vue +++ b/client/src/views/contacts.vue @@ -8,29 +8,29 @@ />

Контакты

-
-
- Телефон - +7 (900) 000-00-00 -
-
- Почта - it-radio@info.org -
-
- Адрес - г. Челябинск, Адрес -
-
- Соц. сети - import AppBreadcrumbs from '@/components/app-breadcrumbs.vue'; import SupportBlock from '@/components/support-block.vue'; +import YandexMap from '@/components/ymap.vue'; +import { app } from '@/services'; export default { name: 'contacts', - components: { SupportBlock, AppBreadcrumbs }, + components: { SupportBlock, AppBreadcrumbs, YandexMap }, data() { return { formData: {}, @@ -104,12 +103,11 @@ export default { outerClass: 'field--required', }, { - $formkit: 'maska', - name: 'phone', - maska: { mask: '+7 (###) ###-##-##' }, - label: 'Контактный телефон', - placeholder: '+7 (###) ###-##-##', - validation: 'required', + $formkit: 'text', + name: 'email', + label: 'Электронная почта', + placeholder: 'example@example.com', + validation: 'required|email', outerClass: 'field--required', }, { @@ -122,10 +120,72 @@ export default { }, ], showLoaderSending: false, + contacts: null, + dictionaryFields: { + phone: 'Телефон', + address: 'Адрес', + email: 'Почта', + socials: 'Соц. сети', + }, }; }, + computed: { + contactsField() { + const address = this.formatAddress(this.contacts); + const phone = this.contacts.phone; + const email = this.contacts.email; + const socials = { + ['m--telegram']: this.contacts.telegram_url, + ['m--vk']: this.contacts.vk_url, + }; + + const fields = { + address, + phone, + email, + socials, + }; + + const fieldsWithoutNull = this.removeNullFields(fields); + return this.createArrayContacts(this.dictionaryFields, fieldsWithoutNull); + }, + }, + created() { + app.getSupportInfo().then((responce) => { + this.contacts = { ...responce }; + }); + }, + mounted() {}, methods: { submitHandler() {}, + removeNullFields(obj) { + const result = {}; + for (const key in obj) { + if (obj[key] !== null) { + if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) { + result[key] = this.removeNullFields(obj[key]); + } else { + result[key] = obj[key]; + } + } + } + return result; + }, + createArrayContacts(dictionary, fields) { + const result = []; + for (const key in fields) { + if (dictionary[key]) { + result.push({ title: dictionary[key], data: fields[key] }); + } + } + return result; + }, + formatAddress(contacts) { + if (contacts.city && contacts.street && contacts.house) { + return `г. ${contacts.city}, ул. ${contacts.street}, д. ${contacts.house}`; + } + return null; + }, }, };