wad-lab 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/controller/CompanyController.java +88 -74
- package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/model/Employee.java +73 -73
- package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/service/CompanyService.java +90 -60
- package/templates/fullstack-springboot-vue/frontend/vue-axios-basic/src/App.vue +429 -405
- package/templates/fullstack-springboot-vue/frontend/vue-axios-interceptor/src/App.vue +177 -159
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/App.vue +441 -427
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/stores/companyStore.js +126 -96
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/App.vue +84 -69
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/App.vue +191 -167
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentForm.vue +98 -98
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentList.vue +92 -91
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeForm.vue +128 -128
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeList.vue +95 -94
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/App.vue +90 -90
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/AddEmployeeView.vue +247 -247
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/DepartmentView.vue +296 -273
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/EmployeeView.vue +219 -196
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/HomeDashboardView.vue +263 -263
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/App.vue +59 -59
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/components/DataCard.vue +72 -53
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
- package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/controller/CompanyController.java +88 -74
- package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/model/Employee.java +73 -73
- package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/service/CompanyService.java +90 -60
- package/templates/springboot-course-registration/src/main/java/com/example/coursereg/controller/CourseController.java +46 -42
- package/templates/springboot-course-registration/src/main/java/com/example/coursereg/service/CourseService.java +70 -60
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/controller/HospitalController.java +54 -50
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/service/HospitalService.java +65 -54
- package/templates/springboot-library-api/src/main/java/com/example/library/controller/LibraryController.java +57 -51
- package/templates/springboot-library-api/src/main/java/com/example/library/service/LibraryService.java +70 -60
- package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/controller/ItemController.java +45 -41
- package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/service/ItemService.java +48 -38
- package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
- package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/service/ItemService.java +48 -38
- package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/controller/ItemController.java +45 -41
- package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/service/ItemService.java +48 -38
- package/templates/springboot-mongo-crud/src/main/java/com/example/crud/controller/ItemController.java +45 -41
- package/templates/springboot-mongo-crud/src/main/java/com/example/crud/service/ItemService.java +48 -38
- package/templates/vue-axios/src/App.vue +264 -243
- package/templates/vue-axios/src/services/ItemService.js +27 -21
- package/templates/vue-axios-basic/src/App.vue +24 -0
- package/templates/vue-axios-interceptor/src/App.vue +177 -159
- package/templates/vue-axios-pinia/src/App.vue +14 -0
- package/templates/vue-axios-pinia/src/stores/companyStore.js +126 -96
- package/templates/vue-axios-pinia-props/src/App.vue +84 -69
- package/templates/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
- package/templates/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
- package/templates/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
- package/templates/vue-axios-props-emits/src/App.vue +24 -0
- package/templates/vue-axios-props-emits/src/components/DepartmentList.vue +2 -1
- package/templates/vue-axios-props-emits/src/components/EmployeeList.vue +2 -1
- package/templates/vue-axios-router/src/views/DepartmentView.vue +23 -0
- package/templates/vue-axios-router/src/views/EmployeeView.vue +23 -0
- package/templates/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
- package/templates/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
- package/templates/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
- package/templates/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
- package/templates/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
- package/templates/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
- package/templates/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
- package/templates/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
- package/templates/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
- package/templates/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
- package/templates/vue-axios-router-props/src/components/DataCard.vue +72 -53
- package/templates/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
- package/templates/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
- package/templates/vue-fetch/src/App.vue +285 -259
- package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
- package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
- package/templates/vue-router-pinia-springboot/frontend/src/services/ItemService.js +24 -21
- package/templates/vue-router-pinia-springboot/frontend/src/stores/itemStore.js +42 -37
- package/templates/vue-router-pinia-springboot/frontend/src/views/ListView.vue +76 -67
- package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
- package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/service/ItemService.java +45 -35
- package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
- package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
- package/templates/vue-springboot-mongo-crud/frontend/src/App.vue +158 -149
- package/templates/vue-springboot-mongo-crud/frontend/src/services/ItemService.js +24 -21
|
@@ -1,70 +1,137 @@
|
|
|
1
|
-
import { defineStore } from 'pinia'
|
|
2
|
-
import api from '../services/api'
|
|
3
|
-
|
|
4
|
-
export const useCompanyStore = defineStore('company', {
|
|
5
|
-
state: () => ({
|
|
6
|
-
departments: [],
|
|
7
|
-
employees: []
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
await
|
|
56
|
-
|
|
57
|
-
} catch (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
})
|
|
1
|
+
import { defineStore } from 'pinia'
|
|
2
|
+
import api from '../services/api'
|
|
3
|
+
|
|
4
|
+
export const useCompanyStore = defineStore('company', {
|
|
5
|
+
state: () => ({
|
|
6
|
+
departments: [],
|
|
7
|
+
employees: [],
|
|
8
|
+
loading: false,
|
|
9
|
+
error: null
|
|
10
|
+
}),
|
|
11
|
+
getters: {
|
|
12
|
+
totalDepts: (state) => state.departments.length,
|
|
13
|
+
totalDepartments: (state) => state.departments.length,
|
|
14
|
+
totalEmployees: (state) => state.employees.length,
|
|
15
|
+
totalPayroll: (state) => state.employees.reduce((sum, emp) => sum + (Number(emp.salary) || 0), 0),
|
|
16
|
+
getDepartmentName: (state) => (deptId) => {
|
|
17
|
+
const dept = state.departments.find((d) => d.id === deptId)
|
|
18
|
+
return dept ? dept.name : `Dept #${deptId}`
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
actions: {
|
|
22
|
+
async fetchDepartments() {
|
|
23
|
+
this.loading = true
|
|
24
|
+
this.error = null
|
|
25
|
+
try {
|
|
26
|
+
const response = await api.get('/departments')
|
|
27
|
+
this.departments = response.data
|
|
28
|
+
} catch (err) {
|
|
29
|
+
this.error = err.response?.data?.message || err.message
|
|
30
|
+
} finally {
|
|
31
|
+
this.loading = false
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
async addDepartment(dept) {
|
|
35
|
+
return this.createDepartment(dept)
|
|
36
|
+
},
|
|
37
|
+
async createDepartment(data) {
|
|
38
|
+
this.loading = true
|
|
39
|
+
this.error = null
|
|
40
|
+
try {
|
|
41
|
+
const response = await api.post('/departments', data)
|
|
42
|
+
this.departments.push(response.data)
|
|
43
|
+
return response.data
|
|
44
|
+
} catch (err) {
|
|
45
|
+
this.error = err.response?.data?.message || err.message
|
|
46
|
+
throw err
|
|
47
|
+
} finally {
|
|
48
|
+
this.loading = false
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
async deleteDepartment(id) {
|
|
52
|
+
this.loading = true
|
|
53
|
+
this.error = null
|
|
54
|
+
try {
|
|
55
|
+
await api.delete(`/departments/${id}`)
|
|
56
|
+
this.departments = this.departments.filter(dept => dept.id !== id)
|
|
57
|
+
} catch (err) {
|
|
58
|
+
this.error = err.response?.data?.message || err.message
|
|
59
|
+
throw err
|
|
60
|
+
} finally {
|
|
61
|
+
this.loading = false
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
async fetchEmployees() {
|
|
65
|
+
this.loading = true
|
|
66
|
+
this.error = null
|
|
67
|
+
try {
|
|
68
|
+
const response = await api.get('/employees')
|
|
69
|
+
this.employees = response.data
|
|
70
|
+
} catch (err) {
|
|
71
|
+
this.error = err.response?.data?.message || err.message
|
|
72
|
+
} finally {
|
|
73
|
+
this.loading = false
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
async addEmployee(emp) {
|
|
77
|
+
return this.createEmployee(emp)
|
|
78
|
+
},
|
|
79
|
+
async createEmployee(data) {
|
|
80
|
+
this.loading = true
|
|
81
|
+
this.error = null
|
|
82
|
+
try {
|
|
83
|
+
const response = await api.post('/employees', data)
|
|
84
|
+
this.employees.push(response.data)
|
|
85
|
+
return response.data
|
|
86
|
+
} catch (err) {
|
|
87
|
+
this.error = err.response?.data?.message || err.message
|
|
88
|
+
throw err
|
|
89
|
+
} finally {
|
|
90
|
+
this.loading = false
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
async deleteEmployee(id) {
|
|
94
|
+
this.loading = true
|
|
95
|
+
this.error = null
|
|
96
|
+
try {
|
|
97
|
+
await api.delete(`/employees/${id}`)
|
|
98
|
+
this.employees = this.employees.filter(emp => emp.id !== id)
|
|
99
|
+
} catch (err) {
|
|
100
|
+
this.error = err.response?.data?.message || err.message
|
|
101
|
+
throw err
|
|
102
|
+
} finally {
|
|
103
|
+
this.loading = false
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
async patchDepartment(id, data) {
|
|
107
|
+
this.loading = true
|
|
108
|
+
this.error = null
|
|
109
|
+
try {
|
|
110
|
+
const response = await api.patch(`/departments/${id}`, data)
|
|
111
|
+
const idx = this.departments.findIndex(dept => dept.id === id)
|
|
112
|
+
if (idx !== -1) this.departments[idx] = response.data
|
|
113
|
+
return response.data
|
|
114
|
+
} catch (err) {
|
|
115
|
+
this.error = err.response?.data?.message || err.message
|
|
116
|
+
throw err
|
|
117
|
+
} finally {
|
|
118
|
+
this.loading = false
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
async patchEmployee(id, data) {
|
|
122
|
+
this.loading = true
|
|
123
|
+
this.error = null
|
|
124
|
+
try {
|
|
125
|
+
const response = await api.patch(`/employees/${id}`, data)
|
|
126
|
+
const idx = this.employees.findIndex(emp => emp.id === id)
|
|
127
|
+
if (idx !== -1) this.employees[idx] = response.data
|
|
128
|
+
return response.data
|
|
129
|
+
} catch (err) {
|
|
130
|
+
this.error = err.response?.data?.message || err.message
|
|
131
|
+
throw err
|
|
132
|
+
} finally {
|
|
133
|
+
this.loading = false
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
})
|
|
@@ -1,209 +1,229 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="department-view">
|
|
3
|
-
<h2>Departments Management</h2>
|
|
4
|
-
|
|
5
|
-
<section class="card">
|
|
6
|
-
<h3>Add Department</h3>
|
|
7
|
-
<form @submit.prevent="handleSubmit" class="form">
|
|
8
|
-
<div class="form-group">
|
|
9
|
-
<label for="dept-name">Department Name</label>
|
|
10
|
-
<input
|
|
11
|
-
id="dept-name"
|
|
12
|
-
v-model="form.name"
|
|
13
|
-
type="text"
|
|
14
|
-
required
|
|
15
|
-
placeholder="e.g. Engineering"
|
|
16
|
-
/>
|
|
17
|
-
</div>
|
|
18
|
-
<div class="form-group">
|
|
19
|
-
<label for="dept-code">Department Code</label>
|
|
20
|
-
<input
|
|
21
|
-
id="dept-code"
|
|
22
|
-
v-model="form.code"
|
|
23
|
-
type="text"
|
|
24
|
-
required
|
|
25
|
-
placeholder="e.g. ENG"
|
|
26
|
-
/>
|
|
27
|
-
</div>
|
|
28
|
-
<button type="submit" class="btn btn-primary">Add Department</button>
|
|
29
|
-
</form>
|
|
30
|
-
</section>
|
|
31
|
-
|
|
32
|
-
<section class="card table-card">
|
|
33
|
-
<h3>Department List</h3>
|
|
34
|
-
<div class="table-wrapper">
|
|
35
|
-
<table>
|
|
36
|
-
<thead>
|
|
37
|
-
<tr>
|
|
38
|
-
<th>ID</th>
|
|
39
|
-
<th>Name</th>
|
|
40
|
-
<th>Code</th>
|
|
41
|
-
<th>Action</th>
|
|
42
|
-
</tr>
|
|
43
|
-
</thead>
|
|
44
|
-
<tbody>
|
|
45
|
-
<tr v-if="companyStore.departments.length === 0">
|
|
46
|
-
<td colspan="4" class="empty">No departments found</td>
|
|
47
|
-
</tr>
|
|
48
|
-
<tr v-for="dept in companyStore.departments" :key="dept.id">
|
|
49
|
-
<td>{{ dept.id }}</td>
|
|
50
|
-
<td>{{ dept.name }}</td>
|
|
51
|
-
<td><code>{{ dept.code }}</code></td>
|
|
52
|
-
<td>
|
|
53
|
-
<button @click="
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
</
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
import {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
form.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
font-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
background-color: #
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
padding:
|
|
208
|
-
|
|
209
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<div class="department-view">
|
|
3
|
+
<h2>Departments Management</h2>
|
|
4
|
+
|
|
5
|
+
<section class="card">
|
|
6
|
+
<h3>Add Department</h3>
|
|
7
|
+
<form @submit.prevent="handleSubmit" class="form">
|
|
8
|
+
<div class="form-group">
|
|
9
|
+
<label for="dept-name">Department Name</label>
|
|
10
|
+
<input
|
|
11
|
+
id="dept-name"
|
|
12
|
+
v-model="form.name"
|
|
13
|
+
type="text"
|
|
14
|
+
required
|
|
15
|
+
placeholder="e.g. Engineering"
|
|
16
|
+
/>
|
|
17
|
+
</div>
|
|
18
|
+
<div class="form-group">
|
|
19
|
+
<label for="dept-code">Department Code</label>
|
|
20
|
+
<input
|
|
21
|
+
id="dept-code"
|
|
22
|
+
v-model="form.code"
|
|
23
|
+
type="text"
|
|
24
|
+
required
|
|
25
|
+
placeholder="e.g. ENG"
|
|
26
|
+
/>
|
|
27
|
+
</div>
|
|
28
|
+
<button type="submit" class="btn btn-primary">Add Department</button>
|
|
29
|
+
</form>
|
|
30
|
+
</section>
|
|
31
|
+
|
|
32
|
+
<section class="card table-card">
|
|
33
|
+
<h3>Department List</h3>
|
|
34
|
+
<div class="table-wrapper">
|
|
35
|
+
<table>
|
|
36
|
+
<thead>
|
|
37
|
+
<tr>
|
|
38
|
+
<th>ID</th>
|
|
39
|
+
<th>Name</th>
|
|
40
|
+
<th>Code</th>
|
|
41
|
+
<th>Action</th>
|
|
42
|
+
</tr>
|
|
43
|
+
</thead>
|
|
44
|
+
<tbody>
|
|
45
|
+
<tr v-if="companyStore.departments.length === 0">
|
|
46
|
+
<td colspan="4" class="empty">No departments found</td>
|
|
47
|
+
</tr>
|
|
48
|
+
<tr v-for="dept in companyStore.departments" :key="dept.id">
|
|
49
|
+
<td>{{ dept.id }}</td>
|
|
50
|
+
<td>{{ dept.name }}</td>
|
|
51
|
+
<td><code>{{ dept.code }}</code></td>
|
|
52
|
+
<td>
|
|
53
|
+
<button @click="handlePatchDepartment(dept.id, dept.code)" class="btn btn-warning">Patch</button>
|
|
54
|
+
<button @click="handleDelete(dept.id)" class="btn btn-danger">Delete</button>
|
|
55
|
+
</td>
|
|
56
|
+
</tr>
|
|
57
|
+
</tbody>
|
|
58
|
+
</table>
|
|
59
|
+
</div>
|
|
60
|
+
</section>
|
|
61
|
+
</div>
|
|
62
|
+
</template>
|
|
63
|
+
|
|
64
|
+
<script setup>
|
|
65
|
+
import { reactive, onMounted } from 'vue'
|
|
66
|
+
import { useCompanyStore } from '../stores/companyStore'
|
|
67
|
+
|
|
68
|
+
const companyStore = useCompanyStore()
|
|
69
|
+
|
|
70
|
+
const form = reactive({
|
|
71
|
+
name: '',
|
|
72
|
+
code: ''
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
const handleSubmit = async () => {
|
|
76
|
+
await companyStore.addDepartment({
|
|
77
|
+
name: form.name,
|
|
78
|
+
code: form.code
|
|
79
|
+
})
|
|
80
|
+
form.name = ''
|
|
81
|
+
form.code = ''
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const handleDelete = async (id) => {
|
|
85
|
+
await companyStore.deleteDepartment(id)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const handlePatchDepartment = async (id, code) => {
|
|
89
|
+
const newCode = prompt('New code:', code)
|
|
90
|
+
if (newCode) {
|
|
91
|
+
await companyStore.patchDepartment(id, { code: newCode })
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
onMounted(() => {
|
|
96
|
+
companyStore.fetchDepartments()
|
|
97
|
+
})
|
|
98
|
+
</script>
|
|
99
|
+
|
|
100
|
+
<style scoped>
|
|
101
|
+
.department-view h2 {
|
|
102
|
+
font-size: 22px;
|
|
103
|
+
margin-bottom: 20px;
|
|
104
|
+
color: #1a1a1a;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.card {
|
|
108
|
+
background: #ffffff;
|
|
109
|
+
border: 1px solid #e1e4e8;
|
|
110
|
+
border-radius: 8px;
|
|
111
|
+
padding: 20px;
|
|
112
|
+
margin-bottom: 24px;
|
|
113
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.card h3 {
|
|
117
|
+
font-size: 16px;
|
|
118
|
+
margin-bottom: 16px;
|
|
119
|
+
color: #333333;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.form {
|
|
123
|
+
display: flex;
|
|
124
|
+
flex-direction: column;
|
|
125
|
+
gap: 12px;
|
|
126
|
+
max-width: 400px;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.form-group {
|
|
130
|
+
display: flex;
|
|
131
|
+
flex-direction: column;
|
|
132
|
+
gap: 4px;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.form-group label {
|
|
136
|
+
font-size: 13px;
|
|
137
|
+
font-weight: 600;
|
|
138
|
+
color: #444444;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.form-group input {
|
|
142
|
+
padding: 8px 10px;
|
|
143
|
+
border: 1px solid #cccccc;
|
|
144
|
+
border-radius: 4px;
|
|
145
|
+
font-size: 14px;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.form-group input:focus {
|
|
149
|
+
outline: none;
|
|
150
|
+
border-color: #0066cc;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.btn {
|
|
154
|
+
padding: 8px 14px;
|
|
155
|
+
border: none;
|
|
156
|
+
border-radius: 4px;
|
|
157
|
+
cursor: pointer;
|
|
158
|
+
font-size: 13px;
|
|
159
|
+
font-weight: 600;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.btn-primary {
|
|
163
|
+
background-color: #0066cc;
|
|
164
|
+
color: #ffffff;
|
|
165
|
+
align-self: flex-start;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.btn-primary:hover {
|
|
169
|
+
background-color: #0052a3;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.btn-danger {
|
|
173
|
+
background-color: #d9383a;
|
|
174
|
+
color: #ffffff;
|
|
175
|
+
padding: 4px 8px;
|
|
176
|
+
font-size: 12px;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.btn-danger:hover {
|
|
180
|
+
background-color: #b8282a;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.btn-warning {
|
|
184
|
+
background-color: #f0ad4e;
|
|
185
|
+
color: #ffffff;
|
|
186
|
+
padding: 4px 8px;
|
|
187
|
+
font-size: 12px;
|
|
188
|
+
margin-right: 6px;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.btn-warning:hover {
|
|
192
|
+
background-color: #ec971f;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.table-wrapper {
|
|
196
|
+
overflow-x: auto;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
table {
|
|
200
|
+
width: 100%;
|
|
201
|
+
border-collapse: collapse;
|
|
202
|
+
font-size: 13px;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
th, td {
|
|
206
|
+
text-align: left;
|
|
207
|
+
padding: 8px 10px;
|
|
208
|
+
border-bottom: 1px solid #eeeeee;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
th {
|
|
212
|
+
background-color: #fafbfc;
|
|
213
|
+
color: #555555;
|
|
214
|
+
font-weight: 600;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
code {
|
|
218
|
+
background: #f0f0f0;
|
|
219
|
+
padding: 2px 4px;
|
|
220
|
+
border-radius: 3px;
|
|
221
|
+
font-size: 12px;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.empty {
|
|
225
|
+
text-align: center;
|
|
226
|
+
color: #888888;
|
|
227
|
+
padding: 16px;
|
|
228
|
+
}
|
|
229
|
+
</style>
|