Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
K
kiaisoft_tuananh_nuxt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TTS Tran Viet Anh
kiaisoft_tuananh_nuxt
Commits
81fc4c62
Commit
81fc4c62
authored
Jan 27, 2023
by
TTS Kieu Tuan Anh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix 6/8 options
parent
65376418
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
187 additions
and
187 deletions
+187
-187
index.vue
pages/categories/index.vue
+63
-63
index.vue
pages/posts/index.vue
+80
-80
index.vue
pages/products/index.vue
+44
-44
No files found.
pages/categories/index.vue
View file @
81fc4c62
...
@@ -5,10 +5,10 @@
...
@@ -5,10 +5,10 @@
<b-icon
icon=
"house-fill"
scale=
"1.25"
shift-v=
"1.25"
aria-hidden=
"true"
></b-icon>
<b-icon
icon=
"house-fill"
scale=
"1.25"
shift-v=
"1.25"
aria-hidden=
"true"
></b-icon>
Home
Home
</b-breadcrumb-item>
</b-breadcrumb-item>
<b-breadcrumb-item
href=
"/
home/
categories"
>
Category
</b-breadcrumb-item>
<b-breadcrumb-item
href=
"/categories"
>
Category
</b-breadcrumb-item>
</b-breadcrumb>
</b-breadcrumb>
<div
style=
"float: right"
>
<div
style=
"float: right"
>
<b-button
v-b-modal
.
modal-create
>
New Category
</b-button></div>
<b-button
v-b-modal
.
modal-create
class=
"text-white"
>
New Category
</b-button></div>
<!-- create modal -->
<!-- create modal -->
<b-modal
id=
"modal-create"
title=
"Create Category"
class=
"modal fade"
>
<b-modal
id=
"modal-create"
title=
"Create Category"
class=
"modal fade"
>
<p
class=
"my-4"
>
<p
class=
"my-4"
>
...
@@ -192,7 +192,7 @@
...
@@ -192,7 +192,7 @@
<
script
>
<
script
>
import
Nav
from
"
@/components/Nav
"
;
import
Nav
from
"
@/components/Nav
"
;
import
axios
from
"
axios
"
;
import
axios
from
"
axios
"
;
import
{
BootstrapVue
,
BootstrapVueIcons
}
from
'
bootstrap-vue
'
import
{
BootstrapVue
,
BootstrapVueIcons
}
from
'
bootstrap-vue
'
;
export
default
{
export
default
{
layout
:
'
admin
'
,
layout
:
'
admin
'
,
...
@@ -250,76 +250,76 @@ export default {
...
@@ -250,76 +250,76 @@ export default {
},
},
computed
:
{
computed
:
{
formTitle
()
{
formTitle
()
{
return
this
.
editedIndex
===
-
1
?
"
New Item
"
:
"
Edit Item
"
;
return
this
.
editedIndex
===
-
1
?
"
New Item
"
:
"
Edit Item
"
},
},
},
},
watch
:
{
watch
:
{
dialog
(
val
)
{
dialog
(
val
)
{
val
||
this
.
close
()
;
val
||
this
.
close
()
},
},
dialogDelete
(
val
)
{
dialogDelete
(
val
)
{
val
||
this
.
closeDelete
()
;
val
||
this
.
closeDelete
()
},
},
},
},
created
()
{
created
()
{
this
.
initialize
()
;
this
.
initialize
()
this
.
getCategories
()
;
this
.
getCategories
()
},
},
methods
:
{
methods
:
{
initialize
()
{
initialize
()
{
this
.
users
=
[]
;
this
.
users
=
[]
this
.
categories
=
[]
;
this
.
categories
=
[]
},
},
editItem
(
item
)
{
editItem
(
item
)
{
this
.
editedIndex
=
this
.
categories
.
indexOf
(
item
)
;
this
.
editedIndex
=
this
.
categories
.
indexOf
(
item
)
this
.
editedItem
=
Object
.
assign
({},
item
)
;
this
.
editedItem
=
Object
.
assign
({},
item
)
this
.
dialog
=
true
;
this
.
dialog
=
true
},
},
deleteItem
(
item
)
{
deleteItem
(
item
)
{
this
.
editedIndex
=
this
.
categories
.
indexOf
(
item
)
;
this
.
editedIndex
=
this
.
categories
.
indexOf
(
item
)
this
.
editedItem
=
Object
.
assign
({},
item
)
;
this
.
editedItem
=
Object
.
assign
({},
item
)
this
.
dialogDelete
=
true
;
this
.
dialogDelete
=
true
},
},
deleteItemConfirm
()
{
deleteItemConfirm
()
{
this
.
categories
.
splice
(
this
.
editedIndex
,
1
)
;
this
.
categories
.
splice
(
this
.
editedIndex
,
1
)
this
.
closeDelete
()
;
this
.
closeDelete
()
},
},
close
()
{
close
()
{
this
.
dialog
=
false
;
this
.
dialog
=
false
this
.
$nextTick
(()
=>
{
this
.
$nextTick
(()
=>
{
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
)
;
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
)
this
.
editedIndex
=
-
1
;
this
.
editedIndex
=
-
1
})
;
})
},
},
closeDelete
()
{
closeDelete
()
{
this
.
dialogDelete
=
false
;
this
.
dialogDelete
=
false
this
.
$nextTick
(()
=>
{
this
.
$nextTick
(()
=>
{
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
)
;
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
)
this
.
editedIndex
=
-
1
;
this
.
editedIndex
=
-
1
})
;
})
},
},
save
()
{
save
()
{
if
(
this
.
editedIndex
>
-
1
)
{
if
(
this
.
editedIndex
>
-
1
)
{
Object
.
assign
(
this
.
categories
[
this
.
editedIndex
],
this
.
editedItem
)
;
Object
.
assign
(
this
.
categories
[
this
.
editedIndex
],
this
.
editedItem
)
}
else
{
}
else
{
this
.
categories
.
push
(
this
.
editedItem
)
;
this
.
categories
.
push
(
this
.
editedItem
)
}
}
this
.
close
()
;
this
.
close
()
},
},
getCategories
()
{
getCategories
()
{
axios
this
.
$
axios
.
get
(
"
http://127.0.0.1:8000/api
/categories/
"
)
.
get
(
"
/categories/
"
)
.
then
((
response
)
=>
(
this
.
categories
=
response
.
data
.
data
))
.
then
((
response
)
=>
(
this
.
categories
=
response
.
data
.
data
))
.
catch
(
function
(
error
)
{
.
catch
(
function
(
error
)
{
console
.
log
(
error
)
;
console
.
log
(
error
)
})
;
})
},
},
createCategory
()
{
createCategory
()
{
const
set
=
new
Set
([
this
.
image
])
;
const
set
=
new
Set
([
this
.
image
])
const
image
=
Array
.
from
(
set
)
;
const
image
=
Array
.
from
(
set
)
const
self
=
this
;
const
self
=
this
axios
this
.
$
axios
.
post
(
'
http://127.0.0.1:8000/api
/categories/
'
,{
.
post
(
'
/categories/
'
,{
name
:
this
.
name
,
name
:
this
.
name
,
ordering
:
this
.
ordering
,
ordering
:
this
.
ordering
,
parent_id
:
this
.
parent_id
,
parent_id
:
this
.
parent_id
,
...
@@ -341,8 +341,8 @@ export default {
...
@@ -341,8 +341,8 @@ export default {
})
})
.
catch
(
errors
=>
{
.
catch
(
errors
=>
{
this
.
$bvModal
.
hide
(
'
modal-create
'
)
this
.
$bvModal
.
hide
(
'
modal-create
'
)
console
.
log
(
errors
.
response
.
data
.
message
)
;
console
.
log
(
errors
.
response
.
data
.
message
)
this
.
message
=
errors
.
response
.
data
.
message
;
this
.
message
=
errors
.
response
.
data
.
message
self
.
$toast
.
error
(
'
something went wrong while trying create!
'
,{
self
.
$toast
.
error
(
'
something went wrong while trying create!
'
,{
duration
:
3000
duration
:
3000
})
})
...
@@ -350,24 +350,24 @@ export default {
...
@@ -350,24 +350,24 @@ export default {
},
},
fileSelected
(
event
){
fileSelected
(
event
){
console
.
log
(
event
)
console
.
log
(
event
)
const
file
=
event
.
target
.
files
[
0
]
;
const
file
=
event
.
target
.
files
[
0
]
this
.
url
=
URL
.
createObjectURL
(
file
)
;
this
.
url
=
URL
.
createObjectURL
(
file
)
this
.
image
=
file
;
this
.
image
=
file
;
console
.
log
(
file
)
console
.
log
(
file
)
console
.
log
(
this
.
image
)
console
.
log
(
this
.
image
)
},
},
deleteCategory
(
ID
,
index
)
{
deleteCategory
(
ID
,
index
)
{
const
self
=
this
const
self
=
this
this
.
editedIndex
=
this
.
categories
.
indexOf
(
index
)
;
this
.
editedIndex
=
this
.
categories
.
indexOf
(
index
)
if
(
confirm
(
"
Do you really want to delete?
"
)){
if
(
confirm
(
"
Do you really want to delete?
"
)){
try
{
try
{
axios
this
.
$
axios
.
delete
(
`
http://127.0.0.1:8000/api
/categories/
${
ID
}
`
)
.
delete
(
`/categories/
${
ID
}
`
)
.
then
(
response
=>
{
.
then
(
response
=>
{
this
.
categories
.
splice
(
this
.
editedIndex
,
1
);
this
.
categories
.
splice
(
this
.
editedIndex
,
1
);
self
.
$toast
.
success
(
'
Category deleted successfully!
'
,{
self
.
$toast
.
success
(
'
Category deleted successfully!
'
,{
duration
:
3000
duration
:
3000
})
;
})
})
})
}
catch
(
error
){
}
catch
(
error
){
console
.
log
(
error
)
console
.
log
(
error
)
...
@@ -378,26 +378,26 @@ export default {
...
@@ -378,26 +378,26 @@ export default {
console
.
log
(
this
.
categories
.
indexOf
(
item
))
console
.
log
(
this
.
categories
.
indexOf
(
item
))
},
},
editCategory
(
item
)
{
editCategory
(
item
)
{
this
.
$bvModal
.
show
(
'
modal-edit
'
)
;
this
.
$bvModal
.
show
(
'
modal-edit
'
)
this
.
eID
=
item
.
id
;
this
.
eID
=
item
.
id
this
.
eName
=
item
.
name
,
this
.
eName
=
item
.
name
this
.
eOrdering
=
item
.
ordering
,
this
.
eOrdering
=
item
.
ordering
this
.
eParentId
=
item
.
parent_id
,
this
.
eParentId
=
item
.
parent_id
this
.
eImage
=
item
.
images
,
this
.
eImage
=
item
.
images
this
.
editedIndex
=
this
.
categories
.
indexOf
(
item
)
,
this
.
editedIndex
=
this
.
categories
.
indexOf
(
item
)
console
.
log
(
this
?.
eID
)
;
console
.
log
(
this
?.
eID
)
console
.
log
(
item
)
;
console
.
log
(
item
)
},
},
updateCategory
(
userID
)
{
updateCategory
(
userID
)
{
const
set
=
new
Set
([
this
.
eImage
])
;
const
set
=
new
Set
([
this
.
eImage
])
const
image
=
Array
.
from
(
set
)
;
const
image
=
Array
.
from
(
set
)
const
self
=
this
const
self
=
this
console
.
log
(
this
.
eName
)
;
console
.
log
(
this
.
eName
)
console
.
log
(
this
.
eOrdering
)
;
console
.
log
(
this
.
eOrdering
)
console
.
log
(
this
?.
eID
)
;
console
.
log
(
this
?.
eID
)
try
{
try
{
axios
this
.
$
axios
.
post
(
`
http://127.0.0.1:8000/api/
categories/update/
${
this
?.
eID
}
`,{
.
post
(
`categories/update/
${
this
?.
eID
}
`,{
name: this.eName,
name: this.eName,
ordering: this.eOrdering,
ordering: this.eOrdering,
parent_id: this.eParentId,
parent_id: this.eParentId,
...
@@ -410,7 +410,7 @@ export default {
...
@@ -410,7 +410,7 @@ export default {
.then(response => {
.then(response => {
self.$toast.success('User updated successfully!',{
self.$toast.success('User updated successfully!',{
duration: 3000
duration: 3000
})
;
})
console.log(response)
console.log(response)
this.editedItem = response.data.data
this.editedItem = response.data.data
this.$bvModal.hide('modal-edit')
this.$bvModal.hide('modal-edit')
...
...
pages/posts/index.vue
View file @
81fc4c62
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
></b-icon>
></b-icon>
Home
Home
</b-breadcrumb-item>
</b-breadcrumb-item>
<b-breadcrumb-item
href=
"/
home/
posts"
>
Post
</b-breadcrumb-item>
<b-breadcrumb-item
href=
"/posts"
>
Post
</b-breadcrumb-item>
</b-breadcrumb>
</b-breadcrumb>
<div
style=
"float: right"
>
<div
style=
"float: right"
>
<b-button
class=
"text-white"
v-b-modal
.
modal-create
>
New Post
</b-button>
<b-button
class=
"text-white"
v-b-modal
.
modal-create
>
New Post
</b-button>
...
@@ -315,26 +315,26 @@ export default {
...
@@ -315,26 +315,26 @@ export default {
created_at
:
""
,
created_at
:
""
,
updated_at
:
""
,
updated_at
:
""
,
},
},
}
;
}
},
},
computed
:
{
computed
:
{
formTitle
()
{
formTitle
()
{
return
this
.
editedIndex
===
-
1
?
"
New Item
"
:
"
Edit Item
"
;
return
this
.
editedIndex
===
-
1
?
"
New Item
"
:
"
Edit Item
"
},
},
nameState
()
{
nameState
()
{
return
this
.
name
.
length
>
2
?
true
:
false
;
return
this
.
name
.
length
>
2
?
true
:
false
},
},
},
},
watch
:
{
watch
:
{
dialog
(
val
)
{
dialog
(
val
)
{
val
||
this
.
close
()
;
val
||
this
.
close
()
},
},
dialogDelete
(
val
)
{
dialogDelete
(
val
)
{
val
||
this
.
closeDelete
()
;
val
||
this
.
closeDelete
()
},
},
},
},
created
()
{
created
()
{
this
.
initialize
(),
this
.
getposts
(),
this
.
getCategories
()
;
this
.
initialize
(),
this
.
getposts
(),
this
.
getCategories
()
},
},
methods
:
{
methods
:
{
initialize
()
{
initialize
()
{
...
@@ -349,62 +349,61 @@ export default {
...
@@ -349,62 +349,61 @@ export default {
this
.
sImages
=
null
this
.
sImages
=
null
},
},
editItem
(
item
)
{
editItem
(
item
)
{
this
.
editedIndex
=
this
.
posts
.
indexOf
(
item
)
;
this
.
editedIndex
=
this
.
posts
.
indexOf
(
item
)
this
.
editedItem
=
Object
.
assign
({},
item
)
;
this
.
editedItem
=
Object
.
assign
({},
item
)
this
.
dialog
=
true
;
this
.
dialog
=
true
},
},
deleteItem
(
item
)
{
deleteItem
(
item
)
{
this
.
editedIndex
=
this
.
posts
.
indexOf
(
item
)
;
this
.
editedIndex
=
this
.
posts
.
indexOf
(
item
)
this
.
editedItem
=
Object
.
assign
({},
item
)
;
this
.
editedItem
=
Object
.
assign
({},
item
)
this
.
dialogDelete
=
true
;
this
.
dialogDelete
=
true
},
},
deleteItemConfirm
()
{
deleteItemConfirm
()
{
this
.
posts
.
splice
(
this
.
editedIndex
,
1
)
;
this
.
posts
.
splice
(
this
.
editedIndex
,
1
)
this
.
closeDelete
()
;
this
.
closeDelete
()
},
},
close
()
{
close
()
{
this
.
dialog
=
false
;
this
.
dialog
=
false
this
.
$nextTick
(()
=>
{
this
.
$nextTick
(()
=>
{
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
)
;
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
)
this
.
editedIndex
=
-
1
;
this
.
editedIndex
=
-
1
})
;
})
},
},
closeDelete
()
{
closeDelete
()
{
this
.
dialogDelete
=
false
;
this
.
dialogDelete
=
false
this
.
$nextTick
(()
=>
{
this
.
$nextTick
(()
=>
{
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
)
;
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
)
this
.
editedIndex
=
-
1
;
this
.
editedIndex
=
-
1
})
;
})
},
},
save
()
{
save
()
{
if
(
this
.
editedIndex
>
-
1
)
{
if
(
this
.
editedIndex
>
-
1
)
{
Object
.
assign
(
this
.
posts
[
this
.
editedIndex
],
this
.
editedItem
)
;
Object
.
assign
(
this
.
posts
[
this
.
editedIndex
],
this
.
editedItem
)
}
else
{
}
else
{
this
.
posts
.
push
(
this
.
editedItem
)
;
this
.
posts
.
push
(
this
.
editedItem
)
}
}
this
.
close
()
;
this
.
close
()
},
},
getCategories
()
{
getCategories
()
{
axios
this
.
$
axios
.
get
(
"
http://127.0.0.1:8000/api
/categories/
"
)
.
get
(
"
/categories/
"
)
.
then
((
response
)
=>
(
this
.
categories
=
response
.
data
.
data
))
.
then
((
response
)
=>
(
this
.
categories
=
response
.
data
.
data
))
.
catch
(
function
(
error
)
{
.
catch
(
function
(
error
)
{
console
.
log
(
error
)
;
console
.
log
(
error
)
})
;
})
},
},
getposts
()
{
getposts
()
{
axios
this
.
$
axios
.
get
(
"
http://127.0.0.1:8000/api
/posts/
"
)
.
get
(
"
/posts/
"
)
.
then
((
response
)
=>
(
this
.
posts
=
response
.
data
.
data
))
.
then
((
response
)
=>
(
this
.
posts
=
response
.
data
.
data
))
.
catch
(
function
(
error
)
{
.
catch
(
function
(
error
)
{
console
.
log
(
error
)
;
console
.
log
(
error
)
})
;
})
},
},
createPost
()
{
createPost
()
{
const
self
=
this
;
const
self
=
this
axios
this
.
$axios
.
post
(
.
post
(
"
/posts/
"
,
"
http://127.0.0.1:8000/api/posts/
"
,
{
{
title
:
this
.
title
,
title
:
this
.
title
,
category_id
:
this
.
category_id
,
category_id
:
this
.
category_id
,
...
@@ -421,7 +420,7 @@ export default {
...
@@ -421,7 +420,7 @@ export default {
}
}
)
)
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
this
.
$bvModal
.
hide
(
"
modal-create
"
)
;
this
.
$bvModal
.
hide
(
"
modal-create
"
)
self
.
$toast
.
success
(
"
Post created successfully!
"
,
{
self
.
$toast
.
success
(
"
Post created successfully!
"
,
{
duration
:
3000
,
duration
:
3000
,
})
})
...
@@ -430,36 +429,36 @@ export default {
...
@@ -430,36 +429,36 @@ export default {
this
.
posts
.
push
(
this
.
editedItem
)
this
.
posts
.
push
(
this
.
editedItem
)
})
})
.
catch
((
errors
)
=>
{
.
catch
((
errors
)
=>
{
this
.
$bvModal
.
hide
(
"
modal-create
"
)
;
this
.
$bvModal
.
hide
(
"
modal-create
"
)
console
.
log
(
errors
.
response
.
data
.
message
)
;
console
.
log
(
errors
.
response
.
data
.
message
)
this
.
message
=
errors
.
response
.
data
.
message
;
this
.
message
=
errors
.
response
.
data
.
message
self
.
$toast
.
error
(
"
something went wrong while trying create!
"
,
{
self
.
$toast
.
error
(
"
something went wrong while trying create!
"
,
{
duration
:
3000
,
duration
:
3000
,
})
;
})
})
;
})
},
},
deletePost
(
ID
,
index
)
{
deletePost
(
ID
,
index
)
{
const
self
=
this
;
const
self
=
this
this
.
editedIndex
=
this
.
posts
.
indexOf
(
index
)
;
this
.
editedIndex
=
this
.
posts
.
indexOf
(
index
)
if
(
confirm
(
"
Do you really want to delete?
"
))
{
if
(
confirm
(
"
Do you really want to delete?
"
))
{
axios
this
.
$
axios
.
delete
(
`
http://127.0.0.1:8000/api
/posts/
${
ID
}
`
)
.
delete
(
`/posts/
${
ID
}
`
)
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
this
.
posts
.
splice
(
this
.
editedIndex
,
1
)
;
this
.
posts
.
splice
(
this
.
editedIndex
,
1
)
self
.
$toast
.
success
(
"
Post deleted successfully!
"
,
{
self
.
$toast
.
success
(
"
Post deleted successfully!
"
,
{
duration
:
3000
,
duration
:
3000
,
})
;
})
})
})
.
catch
((
error
)
=>
{
.
catch
((
error
)
=>
{
console
.
log
(
error
)
;
console
.
log
(
error
)
self
.
$toast
.
error
(
"
Error!
"
,
{
self
.
$toast
.
error
(
"
Error!
"
,
{
duration
:
3000
,
duration
:
3000
,
})
;
})
})
;
})
}
}
},
},
async
showPost
(
item
)
{
async
showPost
(
item
)
{
const
ID
=
item
.
id
;
const
ID
=
item
.
id
try
{
try
{
const
resp
=
await
fetch
(
`http://127.0.0.1:8000/api/posts/
${
ID
}
`
,
{
const
resp
=
await
fetch
(
`http://127.0.0.1:8000/api/posts/
${
ID
}
`
,
{
method
:
"
GET
"
,
method
:
"
GET
"
,
...
@@ -468,34 +467,34 @@ export default {
...
@@ -468,34 +467,34 @@ export default {
Authorization
:
this
.
$auth
.
$storage
.
getUniversal
(
"
token
"
),
Authorization
:
this
.
$auth
.
$storage
.
getUniversal
(
"
token
"
),
},
},
}).
then
((
response
)
=>
{
}).
then
((
response
)
=>
{
return
response
.
json
()
;
return
response
.
json
()
})
;
})
this
.
sTitle
=
resp
.
data
.
title
;
this
.
sTitle
=
resp
.
data
.
title
this
.
sContent
=
resp
.
data
.
content
;
this
.
sContent
=
resp
.
data
.
content
this
.
sCategoryId
=
resp
.
data
.
category_id
;
this
.
sCategoryId
=
resp
.
data
.
category_id
this
.
sUserId
=
resp
.
data
.
user_id
;
this
.
sUserId
=
resp
.
data
.
user_id
this
.
sStatus
=
resp
.
data
.
status
;
this
.
sStatus
=
resp
.
data
.
status
this
.
sImages
=
resp
.
data
.
images
;
this
.
sImages
=
resp
.
data
.
images
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
;
console
.
log
(
error
)
}
}
this
.
$bvModal
.
show
(
"
modal-show
"
)
;
this
.
$bvModal
.
show
(
"
modal-show
"
)
},
},
editPost
(
item
)
{
editPost
(
item
)
{
this
.
$bvModal
.
show
(
"
modal-edit
"
)
;
this
.
$bvModal
.
show
(
"
modal-edit
"
)
this
.
eId
=
item
.
id
;
this
.
eId
=
item
.
id
this
.
eTitle
=
item
.
title
;
this
.
eTitle
=
item
.
title
this
.
eCategoryId
=
item
.
category_id
;
this
.
eCategoryId
=
item
.
category_id
this
.
eContent
=
item
.
content
;
this
.
eContent
=
item
.
content
this
.
eStatus
=
item
.
status
;
this
.
eStatus
=
item
.
status
this
.
eUserId
=
item
.
user_id
;
this
.
eUserId
=
item
.
user_id
this
.
editedIndex
=
this
.
posts
.
indexOf
(
item
)
this
.
editedIndex
=
this
.
posts
.
indexOf
(
item
)
},
},
updatePost
()
{
updatePost
()
{
const
self
=
this
;
const
self
=
this
axios
axios
.
post
(
.
post
(
`
http://127.0.0.1:8000/api
/posts/update/
${
this
?.
eId
}
`,
`/posts/update/
${
this
?.
eId
}
`,
{
{
title: this.eTitle,
title: this.eTitle,
category_id: this.eCategoryId,
category_id: this.eCategoryId,
...
@@ -512,25 +511,26 @@ export default {
...
@@ -512,25 +511,26 @@ export default {
}
}
)
)
.then((response) => {
.then((response) => {
this.$bvModal.hide("modal-edit")
;
this.$bvModal.hide("modal-edit")
self.$toast.success("Post updated successfully!", {
self.$toast.success("Post updated successfully!", {
duration: 3000,
duration: 3000,
})
;
})
console.log(response)
console.log(response)
this.editedItem = response.data.data
this.editedItem = response.data.data
this.$bvModal.hide('modal-edit')
this.$bvModal.hide('modal-edit')
Object.assign(this.posts[this.editedIndex], this.editedItem)
Object.assign(this.posts[this.editedIndex], this.editedItem)
})
})
.catch((error) => {
.catch((error) => {
console.log(error)
;
console.log(error)
this.$bvModal.hide("modal-edit")
;
this.$bvModal.hide("modal-edit")
self.$toast.error("something went wrong while trying create!", {
self.$toast.error("something went wrong while trying create!", {
duration: 3000,
duration: 3000,
})
;
})
})
;
})
},
},
},
},
};
};
</
script
>
</
script
>
<
style
></
style
>
<
style
>
</
style
>
pages/products/index.vue
View file @
81fc4c62
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<b-icon
icon=
"house-fill"
scale=
"1.25"
shift-v=
"1.25"
aria-hidden=
"true"
></b-icon>
<b-icon
icon=
"house-fill"
scale=
"1.25"
shift-v=
"1.25"
aria-hidden=
"true"
></b-icon>
Home
Home
</b-breadcrumb-item>
</b-breadcrumb-item>
<b-breadcrumb-item
href=
"/
home/
products"
>
Product
</b-breadcrumb-item>
<b-breadcrumb-item
href=
"/products"
>
Product
</b-breadcrumb-item>
</b-breadcrumb>
</b-breadcrumb>
<div
style=
"float: right"
>
<div
style=
"float: right"
>
<b-button
class=
"text-white"
v-b-modal
.
modal-create
>
New Product
</b-button></div>
<b-button
class=
"text-white"
v-b-modal
.
modal-create
>
New Product
</b-button></div>
...
@@ -447,7 +447,7 @@ export default {
...
@@ -447,7 +447,7 @@ export default {
quantity
:
""
,
quantity
:
""
,
},
},
]
;
]
},
},
editItem
(
item
)
{
editItem
(
item
)
{
this
.
editedIndex
=
this
.
products
.
indexOf
(
item
)
this
.
editedIndex
=
this
.
products
.
indexOf
(
item
)
...
@@ -455,12 +455,12 @@ export default {
...
@@ -455,12 +455,12 @@ export default {
this
.
dialog
=
true
this
.
dialog
=
true
},
},
deleteItem
(
item
)
{
deleteItem
(
item
)
{
this
.
editedIndex
=
this
.
products
.
indexOf
(
item
)
;
this
.
editedIndex
=
this
.
products
.
indexOf
(
item
)
this
.
editedItem
=
Object
.
assign
({},
item
)
;
this
.
editedItem
=
Object
.
assign
({},
item
)
this
.
dialogDelete
=
true
;
this
.
dialogDelete
=
true
},
},
deleteItemConfirm
()
{
deleteItemConfirm
()
{
this
.
products
.
splice
(
this
.
editedIndex
,
1
)
;
this
.
products
.
splice
(
this
.
editedIndex
,
1
)
this
.
closeDelete
()
this
.
closeDelete
()
},
},
close
()
{
close
()
{
...
@@ -468,45 +468,45 @@ export default {
...
@@ -468,45 +468,45 @@ export default {
this
.
$nextTick
(()
=>
{
this
.
$nextTick
(()
=>
{
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
)
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
)
this
.
editedIndex
=
-
1
this
.
editedIndex
=
-
1
})
;
})
},
},
closeDelete
()
{
closeDelete
()
{
this
.
dialogDelete
=
false
this
.
dialogDelete
=
false
this
.
$nextTick
(()
=>
{
this
.
$nextTick
(()
=>
{
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
)
;
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
)
this
.
editedIndex
=
-
1
this
.
editedIndex
=
-
1
})
;
})
},
},
save
()
{
save
()
{
if
(
this
.
editedIndex
>
-
1
)
{
if
(
this
.
editedIndex
>
-
1
)
{
Object
.
assign
(
this
.
products
[
this
.
editedIndex
],
this
.
editedItem
)
;
Object
.
assign
(
this
.
products
[
this
.
editedIndex
],
this
.
editedItem
)
}
else
{
}
else
{
this
.
products
.
push
(
this
.
editedItem
)
;
this
.
products
.
push
(
this
.
editedItem
)
}
}
this
.
close
()
this
.
close
()
},
},
getCategories
()
{
getCategories
()
{
axios
this
.
$
axios
.
get
(
"
http://127.0.0.1:8000/api
/categories/
"
)
.
get
(
"
/categories/
"
)
.
then
((
response
)
=>
(
this
.
categories
=
response
.
data
.
data
))
.
then
((
response
)
=>
(
this
.
categories
=
response
.
data
.
data
))
.
catch
(
function
(
error
)
{
.
catch
(
function
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
})
;
})
},
},
getProducts
()
{
getProducts
()
{
axios
this
.
$
axios
.
get
(
"
http://127.0.0.1:8000/api
/products/
"
)
.
get
(
"
/products/
"
)
.
then
((
response
)
=>
(
this
.
products
=
response
.
data
.
data
))
.
then
((
response
)
=>
(
this
.
products
=
response
.
data
.
data
))
.
catch
(
function
(
error
)
{
.
catch
(
function
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
})
;
})
},
},
createProduct
()
{
createProduct
()
{
const
self
=
this
;
const
self
=
this
// const set = new Set([this.images]);
// const set = new Set([this.images]);
// const images = Array.from(set);
// const images = Array.from(set);
axios
this
.
$
axios
.
post
(
'
http://127.0.0.1:8000/api
/products/
'
,{
.
post
(
'
/products/
'
,{
name
:
this
.
name
,
name
:
this
.
name
,
price
:
this
.
price
,
price
:
this
.
price
,
category_id
:
this
.
category_id
,
category_id
:
this
.
category_id
,
...
@@ -531,25 +531,25 @@ export default {
...
@@ -531,25 +531,25 @@ export default {
.
catch
(
errors
=>
{
.
catch
(
errors
=>
{
this
.
$bvModal
.
hide
(
'
modal-create
'
)
this
.
$bvModal
.
hide
(
'
modal-create
'
)
console
.
log
(
errors
.
response
.
data
.
message
)
console
.
log
(
errors
.
response
.
data
.
message
)
this
.
message
=
errors
.
response
.
data
.
message
;
this
.
message
=
errors
.
response
.
data
.
message
self
.
$toast
.
error
(
'
something went wrong while trying create!
'
,{
self
.
$toast
.
error
(
'
something went wrong while trying create!
'
,{
duration
:
3000
duration
:
3000
})
})
})
})
},
},
deleteProduct
(
ID
,
index
)
{
deleteProduct
(
ID
,
index
)
{
const
self
=
this
;
const
self
=
this
this
.
editedIndex
=
this
.
products
.
indexOf
(
index
)
;
this
.
editedIndex
=
this
.
products
.
indexOf
(
index
)
if
(
confirm
(
"
Do you really want to delete?
"
)){
if
(
confirm
(
"
Do you really want to delete?
"
)){
try
{
try
{
axios
this
.
$
axios
.
delete
(
`http://127.0.0.1:8000/api
/products/
${
ID
}
`
)
.
delete
(
`
/products/
${
ID
}
`
)
.
then
(
response
=>
{
.
then
(
response
=>
{
this
.
products
.
splice
(
this
.
editedIndex
,
1
);
this
.
products
.
splice
(
this
.
editedIndex
,
1
)
self
.
$toast
.
success
(
'
Category deleted successfully!
'
,{
self
.
$toast
.
success
(
'
Category deleted successfully!
'
,{
duration
:
3000
duration
:
3000
});
})
})
})
}
catch
(
error
){
}
catch
(
error
){
console
.
log
(
error
)
console
.
log
(
error
)
}
}
...
@@ -566,7 +566,7 @@ export default {
...
@@ -566,7 +566,7 @@ export default {
}
}
}).
then
((
response
)
=>
{
}).
then
((
response
)
=>
{
return
response
.
json
()
return
response
.
json
()
})
;
})
this
.
sName
=
resp
.
data
.
name
this
.
sName
=
resp
.
data
.
name
this
.
sPrice
=
resp
.
data
.
price
this
.
sPrice
=
resp
.
data
.
price
this
.
sCategoryId
=
resp
.
data
.
category_id
this
.
sCategoryId
=
resp
.
data
.
category_id
...
@@ -595,15 +595,15 @@ export default {
...
@@ -595,15 +595,15 @@ export default {
updateProduct
(
ID
)
{
updateProduct
(
ID
)
{
const
self
=
this
const
self
=
this
try
{
try
{
axios
this
.
$
axios
.
post
(
`http://127.0.0.1:8000/api
/products/update/
${
this
?.
eId
}
`,{
.
post
(
`
/products/update/
${
this
?.
eId
}
`,{
name: this.eName,
name: this.eName,
price: this.ePrice,
price: this.ePrice,
category_id: this.eCategoryId,
category_id: this.eCategoryId,
description: this.eDescription,
description: this.eDescription,
images: this.eImages,
images: this.eImages,
variants: this.eVariants,
variants: this.eVariants,
}, {
}, {
headers: {
headers: {
"Content-Type": "multipart/form-data",
"Content-Type": "multipart/form-data",
"Authorization": this.$auth.$storage.getUniversal("token")
"Authorization": this.$auth.$storage.getUniversal("token")
...
@@ -612,7 +612,7 @@ export default {
...
@@ -612,7 +612,7 @@ export default {
.then(response => {
.then(response => {
self.$toast.success('User updated successfully!',{
self.$toast.success('User updated successfully!',{
duration: 3000
duration: 3000
})
;
})
console.log(response)
console.log(response)
this.editedItem = response.data.data
this.editedItem = response.data.data
this.$bvModal.hide('modal-edit')
this.$bvModal.hide('modal-edit')
...
@@ -627,14 +627,14 @@ export default {
...
@@ -627,14 +627,14 @@ export default {
color: "",
color: "",
size: "",
size: "",
quantity: "",
quantity: "",
})
;
})
},
},
addMoreVariant() {
addMoreVariant() {
this.eVariants.push({
this.eVariants.push({
color: "",
color: "",
size: "",
size: "",
quantity: "",
quantity: "",
})
;
})
},
},
remove(index) {
remove(index) {
this.variants.splice(index, 1)
this.variants.splice(index, 1)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment