ну чето есть
This commit is contained in:
parent
e4b3e01c37
commit
b3b5f24f65
@ -1,85 +1,19 @@
|
||||
<script setup>
|
||||
import { RouterLink, RouterView } from 'vue-router'
|
||||
import HelloWorld from './components/HelloWorld.vue'
|
||||
<script>
|
||||
import Header from './components/Header.vue';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Header
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<header>
|
||||
<img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="125" height="125" />
|
||||
|
||||
<div class="wrapper">
|
||||
<HelloWorld msg="You did it!" />
|
||||
|
||||
<nav>
|
||||
<RouterLink to="/">Home</RouterLink>
|
||||
<RouterLink to="/about">About</RouterLink>
|
||||
</nav>
|
||||
<Header></Header>
|
||||
<div class="container-fluid">
|
||||
<router-view></router-view>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<RouterView />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
header {
|
||||
line-height: 1.5;
|
||||
max-height: 100vh;
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: block;
|
||||
margin: 0 auto 2rem;
|
||||
}
|
||||
|
||||
nav {
|
||||
width: 100%;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
nav a.router-link-exact-active {
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
nav a.router-link-exact-active:hover {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
nav a {
|
||||
display: inline-block;
|
||||
padding: 0 1rem;
|
||||
border-left: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
nav a:first-of-type {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
header {
|
||||
display: flex;
|
||||
place-items: center;
|
||||
padding-right: calc(var(--section-gap) / 2);
|
||||
}
|
||||
|
||||
.logo {
|
||||
margin: 0 2rem 0 0;
|
||||
}
|
||||
|
||||
header .wrapper {
|
||||
display: flex;
|
||||
place-items: flex-start;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
nav {
|
||||
text-align: left;
|
||||
margin-left: -1rem;
|
||||
font-size: 1rem;
|
||||
|
||||
padding: 1rem 0;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
}
|
||||
</style>
|
71
front/vue-project/src/components/Components.vue
Normal file
71
front/vue-project/src/components/Components.vue
Normal file
@ -0,0 +1,71 @@
|
||||
<script>
|
||||
import axios from 'axios';
|
||||
import CatalogMixins from '../mixins/CatalogMixins.js';
|
||||
import Component from '../models/Component.js';
|
||||
import DataService from '../services/DataService';
|
||||
|
||||
export default {
|
||||
mixins: [
|
||||
CatalogMixins
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
getAllUrl: 'component/',
|
||||
dataUrl: 'component',
|
||||
transformer: (data) => new Comment(data),
|
||||
headers: [
|
||||
{ name: 'componentName', label: 'Название компонента' }
|
||||
],
|
||||
dataFilterUrl: 'component/filter?'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
filter() {
|
||||
let urlParams = ""
|
||||
if (document.getElementById('componentNameFilterInput').value != "") {
|
||||
urlParams += "componentName=" + this.componentName;
|
||||
}
|
||||
DataService.readAll(this.dataFilterUrl + urlParams, (data) => new Component(data))
|
||||
.then(data => {
|
||||
this.items = data;
|
||||
});
|
||||
},
|
||||
clearFilters() {
|
||||
this.loadItems();
|
||||
this.id = null;
|
||||
this.componentName = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control" id="componentNameFilterInput" placeholder="Name" required v-model="componentName">
|
||||
<button class="btn btn-primary" type="button" id="report-button"
|
||||
@click.prevent="filter">Сформировать</button>
|
||||
<button class="btn btn-outline-secondary" type="button" id="report-button"
|
||||
@click.prevent="clearFilters">Очистить</button>
|
||||
</div>
|
||||
<ToolBar
|
||||
@add="showAddModal"
|
||||
@edit="showEditModal"
|
||||
@remove="removeSelectedItems">
|
||||
</ToolBar>
|
||||
<DataTable
|
||||
:headers="this.headers"
|
||||
:items="this.items"
|
||||
:selectedItems="this.selectedItems"
|
||||
@dblclick="showEditModalDblClick">
|
||||
</DataTable>
|
||||
<Modal
|
||||
:header="this.modal.header"
|
||||
:confirm="this.modal.confirm"
|
||||
v-model:visible="this.modalShow"
|
||||
@done="saveItem">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Name</label>
|
||||
<input type="text" class="form-control" id="name" required v-model="data.componentName">
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
175
front/vue-project/src/components/Favors.vue
Normal file
175
front/vue-project/src/components/Favors.vue
Normal file
@ -0,0 +1,175 @@
|
||||
<script>
|
||||
import axios from 'axios';
|
||||
import CatalogMixins from '../mixins/CatalogMixins.js';
|
||||
import Favor from "../models/Favor";
|
||||
import Component from '../models/Component';
|
||||
import Order from '../models/Order';
|
||||
import DataService from '../services/DataService';
|
||||
|
||||
export default {
|
||||
mixins: [
|
||||
CatalogMixins
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
getAllUrl: 'favor/',
|
||||
dataUrl: 'favor',
|
||||
transformer: (data) => new Favor(data),
|
||||
headers: [
|
||||
{ name: 'favorName', label: 'name' },
|
||||
{ name: 'price', label: 'price' },
|
||||
],
|
||||
dataFilterUrl: 'favor/filter?',
|
||||
cabinetUrl: 'cabinet/',
|
||||
cabinets: [],
|
||||
monitorUrl: 'monitor/',
|
||||
monitors: []
|
||||
}
|
||||
},
|
||||
created() {
|
||||
DataService.readAll(this.cabinetUrl, (data) => new Cabinet(data))
|
||||
.then(data => {
|
||||
this.cabinets = data;
|
||||
});
|
||||
DataService.readAll(this.monitorUrl, (data) => new Monitor(data))
|
||||
.then(data => {
|
||||
this.monitors = data;
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
filter() {
|
||||
let urlParams = ""
|
||||
if (document.getElementById('modelNameFilterInput').value != "") {
|
||||
if (urlParams != "") {
|
||||
urlParams += "&";
|
||||
}
|
||||
urlParams += "modelName=" + this.modelName;
|
||||
}
|
||||
if (document.getElementById('serialNumberFilterInput').value != "") {
|
||||
if (urlParams != "") {
|
||||
urlParams += "&";
|
||||
}
|
||||
urlParams += "serialNum=" + this.serialNumber;
|
||||
}
|
||||
if (document.getElementById('monitorFilterSelect').value != "") {
|
||||
if (urlParams != "") {
|
||||
urlParams += "&";
|
||||
}
|
||||
urlParams += "monitorId=" + this.monitorId;
|
||||
}
|
||||
if (document.getElementById('cabinetFilterSelect').value != "") {
|
||||
if (urlParams != "") {
|
||||
urlParams += "&";
|
||||
}
|
||||
urlParams += "cabinetId=" + this.cabinetId;
|
||||
}
|
||||
DataService.readAll(this.dataFilterUrl + urlParams, (data) => new Favor(data))
|
||||
.then(data => {
|
||||
this.items = data;
|
||||
});
|
||||
},
|
||||
clearFilters() {
|
||||
this.loadItems();
|
||||
this.id = null;
|
||||
this.modelName = null;
|
||||
this.serialNumber = null;
|
||||
this.monitorId = null;
|
||||
this.cabinetId = null;
|
||||
},
|
||||
addCabinetToFavor(favorId) {
|
||||
let cabinetId = document.getElementById('cabinets').value;
|
||||
let response = axios.post(`http://localhost:8080/api/favor/${favorId}/cabinet?cabinetId=${cabinetId}`);
|
||||
},
|
||||
itemsComps(favors) {
|
||||
if (typeof favors === 'undefined') {
|
||||
return;
|
||||
}
|
||||
favors.forEach(favor => {
|
||||
this.monitors.forEach(monitor => {
|
||||
if (favor.monitorId === monitor.id) {
|
||||
favor.monitor = monitor;
|
||||
}
|
||||
});
|
||||
this.cabinets.forEach(cabinet => {
|
||||
cabinet.favorIds.forEach(favorId => {
|
||||
if (favor.id === favorId) {
|
||||
favor.cabinet = cabinet;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
return favors;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control" id="modelNameFilterInput" placeholder="Модель" required v-model="modelName">
|
||||
|
||||
<input type="text" class="form-control" id="serialNumberFilterInput" placeholder="Серийный номер" required v-model="serialNumber">
|
||||
|
||||
<select class="form-select" id="monitorFilterSelect" v-model="monitorId">
|
||||
<option disabled value="" selected>Выберите монитор</option>
|
||||
<option v-for="monitor in monitors" :value="monitor.id">{{ monitor.modelName }}</option>
|
||||
</select>
|
||||
|
||||
<select class="form-select" id="cabinetFilterSelect" v-model="cabinetId">
|
||||
<option disabled value="" selected>Выберите номер кабинета</option>
|
||||
<option v-for="cabinet in cabinets" :value="cabinet.id">{{ cabinet.number }}</option>
|
||||
</select>
|
||||
|
||||
<button class="btn btn-primary" type="button" id="report-button"
|
||||
@click.prevent="filter">Сформировать</button>
|
||||
<button class="btn btn-outline-secondary" type="button" id="report-button"
|
||||
@click.prevent="clearFilters">Очистить</button>
|
||||
</div>
|
||||
<ToolBar
|
||||
@add="showAddModal"
|
||||
@edit="showEditModal"
|
||||
@remove="removeSelectedItems">
|
||||
</ToolBar>
|
||||
<DataTable
|
||||
:headers="this.headers"
|
||||
:items="itemsComps(this.items)"
|
||||
:selectedItems="this.selectedItems"
|
||||
@dblclick="showEditModalDblClick">
|
||||
</DataTable>
|
||||
<Modal
|
||||
:header="this.modal.header"
|
||||
:confirm="this.modal.confirm"
|
||||
v-model:visible="this.modalShow"
|
||||
@done="saveItem">
|
||||
<div class="mb-3">
|
||||
<label for="model" class="form-label">Модель</label>
|
||||
<input type="text" class="form-control" id="model" required v-model="data.modelName">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="serialNum" class="form-label">Серийный номер</label>
|
||||
<input type="text" class="form-control" id="serialNum" required v-model="data.serialNum">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="monitor" class="form-label">Монитор</label>
|
||||
<select class="form-select" id="monitor" v-model="data.monitorId">
|
||||
<option disabled value="">Выберите монитор</option>
|
||||
<option v-for="monitor in this.monitors"
|
||||
:value="monitor.id"
|
||||
:selected="data.monitorId && monitor.id === data.monitorId">
|
||||
{{ monitor.modelName }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- <div class="mb-3">
|
||||
<label for="cabinet" class="form-label">Номер кабинета</label>
|
||||
<select class="form-select" id="cabinet" v-model="data.cabinetId">
|
||||
<option disabled value="">Выберите номер кабинета</option>
|
||||
<option v-for="cabinet in this.cabinets"
|
||||
:value="cabinet.id"
|
||||
:selected="data.cabinetId && cabinet.id === data.cabinetId">
|
||||
{{ cabinet.number }}
|
||||
</option>
|
||||
</select>
|
||||
</div> -->
|
||||
</Modal>
|
||||
</template>
|
35
front/vue-project/src/components/Header.vue
Normal file
35
front/vue-project/src/components/Header.vue
Normal file
@ -0,0 +1,35 @@
|
||||
<script>
|
||||
export default {
|
||||
methods: {
|
||||
getRoutes() {
|
||||
return this.$router.options.routes.filter(route => route.meta?.hasOwnProperty('label'));
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<nav class="navbar navbar-expand-lg bg-light">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/">
|
||||
<i class="fa-solid fa-book"></i>
|
||||
Рабочее место оператора пункта выдачи заказов
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item"
|
||||
v-for="route in this.getRoutes()">
|
||||
<router-link class="nav-link" :to="route.path">{{ route.meta.label }}</router-link>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
</style>
|
@ -1,43 +0,0 @@
|
||||
<script setup>
|
||||
defineProps({
|
||||
msg: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="greetings">
|
||||
<h1 class="green">{{ msg }}</h1>
|
||||
<h3>
|
||||
You’ve successfully created a project with
|
||||
<a href="https://vitejs.dev/" target="_blank" rel="noopener">Vite</a> +
|
||||
<a href="https://vuejs.org/" target="_blank" rel="noopener">Vue 3</a>.
|
||||
</h3>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
h1 {
|
||||
font-weight: 500;
|
||||
font-size: 2.6rem;
|
||||
top: -10px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.greetings h1,
|
||||
.greetings h3 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.greetings h1,
|
||||
.greetings h3 {
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
</style>
|
@ -1,86 +0,0 @@
|
||||
<script setup>
|
||||
import WelcomeItem from './WelcomeItem.vue'
|
||||
import DocumentationIcon from './icons/IconDocumentation.vue'
|
||||
import ToolingIcon from './icons/IconTooling.vue'
|
||||
import EcosystemIcon from './icons/IconEcosystem.vue'
|
||||
import CommunityIcon from './icons/IconCommunity.vue'
|
||||
import SupportIcon from './icons/IconSupport.vue'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<DocumentationIcon />
|
||||
</template>
|
||||
<template #heading>Documentation</template>
|
||||
|
||||
Vue’s
|
||||
<a href="https://vuejs.org/" target="_blank" rel="noopener">official documentation</a>
|
||||
provides you with all information you need to get started.
|
||||
</WelcomeItem>
|
||||
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<ToolingIcon />
|
||||
</template>
|
||||
<template #heading>Tooling</template>
|
||||
|
||||
This project is served and bundled with
|
||||
<a href="https://vitejs.dev/guide/features.html" target="_blank" rel="noopener">Vite</a>. The
|
||||
recommended IDE setup is
|
||||
<a href="https://code.visualstudio.com/" target="_blank" rel="noopener">VSCode</a> +
|
||||
<a href="https://github.com/johnsoncodehk/volar" target="_blank" rel="noopener">Volar</a>. If
|
||||
you need to test your components and web pages, check out
|
||||
<a href="https://www.cypress.io/" target="_blank" rel="noopener">Cypress</a> and
|
||||
<a href="https://on.cypress.io/component" target="_blank">Cypress Component Testing</a>.
|
||||
|
||||
<br />
|
||||
|
||||
More instructions are available in <code>README.md</code>.
|
||||
</WelcomeItem>
|
||||
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<EcosystemIcon />
|
||||
</template>
|
||||
<template #heading>Ecosystem</template>
|
||||
|
||||
Get official tools and libraries for your project:
|
||||
<a href="https://pinia.vuejs.org/" target="_blank" rel="noopener">Pinia</a>,
|
||||
<a href="https://router.vuejs.org/" target="_blank" rel="noopener">Vue Router</a>,
|
||||
<a href="https://test-utils.vuejs.org/" target="_blank" rel="noopener">Vue Test Utils</a>, and
|
||||
<a href="https://github.com/vuejs/devtools" target="_blank" rel="noopener">Vue Dev Tools</a>. If
|
||||
you need more resources, we suggest paying
|
||||
<a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">Awesome Vue</a>
|
||||
a visit.
|
||||
</WelcomeItem>
|
||||
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<CommunityIcon />
|
||||
</template>
|
||||
<template #heading>Community</template>
|
||||
|
||||
Got stuck? Ask your question on
|
||||
<a href="https://chat.vuejs.org" target="_blank" rel="noopener">Vue Land</a>, our official
|
||||
Discord server, or
|
||||
<a href="https://stackoverflow.com/questions/tagged/vue.js" target="_blank" rel="noopener"
|
||||
>StackOverflow</a
|
||||
>. You should also subscribe to
|
||||
<a href="https://news.vuejs.org" target="_blank" rel="noopener">our mailing list</a> and follow
|
||||
the official
|
||||
<a href="https://twitter.com/vuejs" target="_blank" rel="noopener">@vuejs</a>
|
||||
twitter account for latest news in the Vue world.
|
||||
</WelcomeItem>
|
||||
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<SupportIcon />
|
||||
</template>
|
||||
<template #heading>Support Vue</template>
|
||||
|
||||
As an independent project, Vue relies on community backing for its sustainability. You can help
|
||||
us by
|
||||
<a href="https://vuejs.org/sponsor/" target="_blank" rel="noopener">becoming a sponsor</a>.
|
||||
</WelcomeItem>
|
||||
</template>
|
46
front/vue-project/src/components/ToolBar.vue
Normal file
46
front/vue-project/src/components/ToolBar.vue
Normal file
@ -0,0 +1,46 @@
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
|
||||
},
|
||||
emits: {
|
||||
add: null,
|
||||
edit: null,
|
||||
remove: null
|
||||
},
|
||||
methods: {
|
||||
add() {
|
||||
this.$emit('add');
|
||||
},
|
||||
edit() {
|
||||
this.$emit('edit');
|
||||
},
|
||||
remove() {
|
||||
this.$emit('remove');
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="btn-group mt-2" role="group">
|
||||
<button type="button" class="btn btn-success"
|
||||
@click.prevent="add">
|
||||
Добавить
|
||||
</button>
|
||||
<button type="button" class="btn btn-warning"
|
||||
@click.prevent="edit">
|
||||
Изменить
|
||||
</button>
|
||||
<button type="button" class="btn btn-danger"
|
||||
@click.prevent="remove">
|
||||
Удалить
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.btn {
|
||||
min-width: 140px;
|
||||
}
|
||||
</style>
|
@ -1,85 +0,0 @@
|
||||
<template>
|
||||
<div class="item">
|
||||
<i>
|
||||
<slot name="icon"></slot>
|
||||
</i>
|
||||
<div class="details">
|
||||
<h3>
|
||||
<slot name="heading"></slot>
|
||||
</h3>
|
||||
<slot></slot>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.item {
|
||||
margin-top: 2rem;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.details {
|
||||
flex: 1;
|
||||
margin-left: 1rem;
|
||||
}
|
||||
|
||||
i {
|
||||
display: flex;
|
||||
place-items: center;
|
||||
place-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 500;
|
||||
margin-bottom: 0.4rem;
|
||||
color: var(--color-heading);
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.item {
|
||||
margin-top: 0;
|
||||
padding: 0.4rem 0 1rem calc(var(--section-gap) / 2);
|
||||
}
|
||||
|
||||
i {
|
||||
top: calc(50% - 25px);
|
||||
left: -26px;
|
||||
position: absolute;
|
||||
border: 1px solid var(--color-border);
|
||||
background: var(--color-background);
|
||||
border-radius: 8px;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.item:before {
|
||||
content: ' ';
|
||||
border-left: 1px solid var(--color-border);
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: calc(50% + 25px);
|
||||
height: calc(50% - 25px);
|
||||
}
|
||||
|
||||
.item:after {
|
||||
content: ' ';
|
||||
border-left: 1px solid var(--color-border);
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: calc(50% + 25px);
|
||||
height: calc(50% - 25px);
|
||||
}
|
||||
|
||||
.item:first-of-type:before {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.item:last-of-type:after {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
@ -1,11 +1,20 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import Cabinets from './components/Components.vue'
|
||||
import Computers from './components/Favors.vue.vue'
|
||||
import Monitors from './components/Orders.vue'
|
||||
|
||||
import './assets/main.css'
|
||||
const routes = [
|
||||
{ path: '/', redirect: '/components' },
|
||||
{ path: '/components', component: Components, meta: { label: 'Компоненты' } },
|
||||
{ path: '/favors', component: Favors, meta: { label: 'Услуги' } },
|
||||
{ path: '/orders', component: Orders, meta: { label: 'Заказы' } }
|
||||
]
|
||||
|
||||
const app = createApp(App)
|
||||
|
||||
app.use(router)
|
||||
|
||||
app.mount('#app')
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
linkActiveClass: 'active',
|
||||
routes
|
||||
})
|
||||
createApp(App).use(router).mount('#app')
|
102
front/vue-project/src/mixins/CatalogMixins.js
Normal file
102
front/vue-project/src/mixins/CatalogMixins.js
Normal file
@ -0,0 +1,102 @@
|
||||
import ToolBar from '../components/ToolBar.vue';
|
||||
import DataTable from '../components/DataTable.vue';
|
||||
import Modal from '../components/Modal.vue';
|
||||
import DataService from '../services/DataService';
|
||||
|
||||
const CatalogMixin = {
|
||||
components: {
|
||||
ToolBar, DataTable, Modal
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
getAllUrl: undefined,
|
||||
dataUrl: undefined,
|
||||
transformer: undefined,
|
||||
headers: [],
|
||||
items: [],
|
||||
selectedItems: [],
|
||||
modal: {
|
||||
header: undefined,
|
||||
confirm: undefined,
|
||||
},
|
||||
modalShow: false,
|
||||
data: undefined,
|
||||
isEdit: false
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.loadItems();
|
||||
},
|
||||
methods: {
|
||||
loadItems() {
|
||||
this.getItems();
|
||||
this.data = this.transformer();
|
||||
},
|
||||
getItems() {
|
||||
DataService.readAll(this.getAllUrl, this.transformer)
|
||||
.then(data => {
|
||||
this.items = data;
|
||||
});
|
||||
},
|
||||
showAddModal() {
|
||||
this.isEdit = false;
|
||||
this.data = this.transformer();
|
||||
this.modal.header = 'Добавление элемента';
|
||||
this.modal.confirm = 'Добавить';
|
||||
this.modalShow = true;
|
||||
},
|
||||
showEditModal() {
|
||||
if (this.selectedItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
this.showEditModalDblClick(this.selectedItems[0]);
|
||||
},
|
||||
showEditModalDblClick(editId) {
|
||||
DataService.read(this.dataUrl + "/" + editId, this.transformer)
|
||||
.then(data => {
|
||||
this.data = data;
|
||||
this.isEdit = true;
|
||||
this.modal.header = 'Редактирование элемента';
|
||||
this.modal.confirm = 'Сохранить';
|
||||
this.modalShow = true;
|
||||
});
|
||||
},
|
||||
saveItem() {
|
||||
if (!this.isEdit) {
|
||||
DataService.create(this.dataUrl + "/", this.data)
|
||||
.then(() => {
|
||||
this.getItems();
|
||||
});
|
||||
} else {
|
||||
DataService.update(this.dataUrl + "/" + this.data.id, this.data)
|
||||
.then(() => {
|
||||
this.getItems();
|
||||
});
|
||||
}
|
||||
},
|
||||
removeSelectedItems() {
|
||||
if (this.selectedItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (confirm('Удалить выбранные элементы?')) {
|
||||
const promises = [];
|
||||
const self = this;
|
||||
this.selectedItems.forEach(item => {
|
||||
promises.push(DataService.delete(this.dataUrl + "/" + item));
|
||||
});
|
||||
Promise.all(promises).then((results) => {
|
||||
results.forEach(function (id) {
|
||||
const index = self.selectedItems.indexOf(id);
|
||||
if (index === - 1) {
|
||||
return;
|
||||
}
|
||||
self.selectedItems.splice(index, 1);
|
||||
});
|
||||
this.getItems();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default CatalogMixin;
|
@ -2,6 +2,7 @@ export default class Component {
|
||||
constructor(data) {
|
||||
this._id = data?.id;
|
||||
this._amount = data?.amount;
|
||||
this._componentName = data?.componentName;
|
||||
this._favorIds = data?._favorIds;
|
||||
}
|
||||
|
||||
@ -17,7 +18,18 @@ export default class Component {
|
||||
if (typeof value !== 'string' || value === null || value.length == 0) {
|
||||
throw 'New amount value ' + value + ' is not a string or empty';
|
||||
}
|
||||
this._number = value;
|
||||
this._amount = value;
|
||||
}
|
||||
|
||||
get componentName() {
|
||||
return this._componentName;
|
||||
}
|
||||
|
||||
set componentName(value) {
|
||||
if (typeof value !== 'string' || value === null || value.length == 0) {
|
||||
throw 'New name value ' + value + ' is not a string or empty';
|
||||
}
|
||||
this._componentName = value;
|
||||
}
|
||||
|
||||
get favorIds() {
|
||||
|
@ -1,6 +1,7 @@
|
||||
export default class Favor {
|
||||
constructor(data) {
|
||||
this._id = data?.id;
|
||||
this._favorName = data?.favorName;
|
||||
this._price = data?.price;
|
||||
this._componentIds = data?.componentIds;
|
||||
this._orderIds = data?.orderIds;
|
||||
@ -11,6 +12,17 @@ export default class Favor {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get favorName() {
|
||||
return this._favorName;
|
||||
}
|
||||
|
||||
set favorName(value) {
|
||||
if (typeof value !== 'string' || value === null || value.length == 0) {
|
||||
throw 'New name value ' + value + ' is not a string or empty';
|
||||
}
|
||||
this._favorName = value;
|
||||
}
|
||||
|
||||
get price() {
|
||||
return this._price;
|
||||
}
|
||||
|
42
front/vue-project/src/services/DataService.js
Normal file
42
front/vue-project/src/services/DataService.js
Normal file
@ -0,0 +1,42 @@
|
||||
import axios from 'axios';
|
||||
|
||||
function toJSON(data) {
|
||||
const jsonObj = {};
|
||||
const fields = Object.getOwnPropertyNames(data);
|
||||
for (const field of fields) {
|
||||
if (data[field] === undefined) {
|
||||
continue;
|
||||
}
|
||||
jsonObj[field.substring(1)] = data[field];
|
||||
}
|
||||
return jsonObj;
|
||||
}
|
||||
|
||||
export default class DataService {
|
||||
static dataUrlPrefix = 'http://localhost:8080/';
|
||||
|
||||
static async readAll(url, transformer) {
|
||||
const response = await axios.get(this.dataUrlPrefix + url);
|
||||
return response.data.map(item => transformer(item));
|
||||
}
|
||||
|
||||
static async read(url, transformer) {
|
||||
const response = await axios.get(this.dataUrlPrefix + url);
|
||||
return transformer(response.data);
|
||||
}
|
||||
|
||||
static async create(url, data) {
|
||||
const response = await axios.post(this.dataUrlPrefix + url, toJSON(data));
|
||||
return true;
|
||||
}
|
||||
|
||||
static async update(url, data) {
|
||||
const response = await axios.put(this.dataUrlPrefix + url, toJSON(data));
|
||||
return true;
|
||||
}
|
||||
|
||||
static async delete(url) {
|
||||
const response = await axios.delete(this.dataUrlPrefix + url);
|
||||
return response.data.id;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user