1
This commit is contained in:
41
Yes.Blog/wwwroot/admin/js/category/add.js
Normal file
41
Yes.Blog/wwwroot/admin/js/category/add.js
Normal file
@@ -0,0 +1,41 @@
|
||||
document.addEventListener('alpine:init', function () {
|
||||
Alpine.data('data', function () {
|
||||
|
||||
return {
|
||||
category: {
|
||||
name: "",
|
||||
slug: "",
|
||||
sort: 0,
|
||||
coverUrl: "",
|
||||
description: ""
|
||||
},
|
||||
isSubmitting: false,
|
||||
addCategory() {
|
||||
if (this.isSubmitting) {
|
||||
return;
|
||||
}
|
||||
this.isSubmitting = true;
|
||||
axios.post('categories', this.category)
|
||||
.then(data => {
|
||||
location.href = "/admin/category";
|
||||
})
|
||||
.finally(() => {
|
||||
this.isSubmitting = false;
|
||||
});
|
||||
},
|
||||
addIcon() {
|
||||
const fileinput = document.getElementById('img-file-input');
|
||||
if (fileinput) {
|
||||
fileinput.click();
|
||||
}
|
||||
},
|
||||
init() {
|
||||
this.loadCategory();
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
document.title = "添加分类 - " + window.config.name + "";
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
});
|
||||
50
Yes.Blog/wwwroot/admin/js/category/detail.js
Normal file
50
Yes.Blog/wwwroot/admin/js/category/detail.js
Normal file
@@ -0,0 +1,50 @@
|
||||
document.addEventListener('alpine:init', function () {
|
||||
Alpine.data('data', function () {
|
||||
|
||||
const id = getUrlParameter("id");
|
||||
return {
|
||||
category: {
|
||||
name: "",
|
||||
slug: "",
|
||||
sort: 0,
|
||||
coverUrl: "",
|
||||
description: "",
|
||||
id: id
|
||||
},
|
||||
isSubmitting: false,
|
||||
loadCategory() {
|
||||
axios.get('categories/' + id)
|
||||
.then(data => {
|
||||
this.category = data;
|
||||
});
|
||||
return this;
|
||||
},
|
||||
editCategory() {
|
||||
if (this.isSubmitting) {
|
||||
return;
|
||||
}
|
||||
this.isSubmitting = true;
|
||||
axios.put('categories', this.category)
|
||||
.then(data => {
|
||||
location.href = "/admin/category";
|
||||
})
|
||||
.finally(() => {
|
||||
this.isSubmitting = false;
|
||||
});
|
||||
},
|
||||
addIcon() {
|
||||
const fileinput = document.getElementById('img-file-input');
|
||||
if (fileinput) {
|
||||
fileinput.click();
|
||||
}
|
||||
},
|
||||
init() {
|
||||
this.loadCategory();
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
document.title = "编辑分类 - " + window.config.name + "";
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
});
|
||||
40
Yes.Blog/wwwroot/admin/js/category/index.js
Normal file
40
Yes.Blog/wwwroot/admin/js/category/index.js
Normal file
@@ -0,0 +1,40 @@
|
||||
document.addEventListener('alpine:init', function () {
|
||||
Alpine.data('data', function () {
|
||||
return {
|
||||
items: [],
|
||||
loading: false,
|
||||
loadItems() {
|
||||
if (this.loading) {
|
||||
return;
|
||||
}
|
||||
this.loading = true;
|
||||
axios.get('categories')
|
||||
.then(data => {
|
||||
this.items = data;
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
deleteId: 0,
|
||||
showModal: false,
|
||||
confirmAction() {
|
||||
this.isSubmitting = true;
|
||||
axios.delete('categories?id=' + this.deleteId)
|
||||
.then(data => {
|
||||
this.loadItems();
|
||||
})
|
||||
.finally(() => {
|
||||
this.isSubmitting = false;
|
||||
});
|
||||
},
|
||||
init() {
|
||||
this.loadItems(1);
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
document.title = "分类列表 - " + window.config.name + "";
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user