1
This commit is contained in:
72
Yes.Blog/wwwroot/admin/js/page/add.js
Normal file
72
Yes.Blog/wwwroot/admin/js/page/add.js
Normal file
@@ -0,0 +1,72 @@
|
||||
document.addEventListener('alpine:init', function () {
|
||||
Alpine.data('data', function () {
|
||||
const editor = new toastui.Editor({
|
||||
el: document.querySelector('#editor'),
|
||||
language: 'zh-CN',
|
||||
previewStyle: 'vertical',
|
||||
height: '660px',
|
||||
initialEditType: 'wysiwyg',
|
||||
initialValue: ""
|
||||
});
|
||||
|
||||
|
||||
return {
|
||||
article: {
|
||||
title: "",
|
||||
slug: "",
|
||||
content: "",
|
||||
coverUrl: "",
|
||||
tags: [],
|
||||
categoryId: 0,
|
||||
summary: ""
|
||||
},
|
||||
tempfile: null,
|
||||
coverUrl:"",
|
||||
categories: [],
|
||||
isSubmitting: false,
|
||||
loadCategories() {
|
||||
if (this.loading) {
|
||||
return;
|
||||
}
|
||||
this.loading = true;
|
||||
axios.get('categories')
|
||||
.then(data => {
|
||||
this.categories = data;
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
createArticle() {
|
||||
if(this.isSubmitting){
|
||||
return;
|
||||
}
|
||||
this.isSubmitting = true;
|
||||
axios.post('pages', this.article)
|
||||
.then(data => {
|
||||
location.href = "/admin/page";
|
||||
})
|
||||
.finally(() => {
|
||||
this.isSubmitting = false;
|
||||
});
|
||||
},
|
||||
addIcon() {
|
||||
const fileinput = document.getElementById('img-file-input');
|
||||
if (fileinput) {
|
||||
fileinput.click();
|
||||
}
|
||||
},
|
||||
init() {
|
||||
editor.on('change', () => {
|
||||
this.article.content = editor.getMarkdown();
|
||||
});
|
||||
|
||||
this.loadCategories();
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
document.title = "添加单页 - " + window.config.name + "";
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
});
|
||||
81
Yes.Blog/wwwroot/admin/js/page/detail.js
Normal file
81
Yes.Blog/wwwroot/admin/js/page/detail.js
Normal file
@@ -0,0 +1,81 @@
|
||||
document.addEventListener('alpine:init', function () {
|
||||
Alpine.data('data', function () {
|
||||
const editor = new toastui.Editor({
|
||||
el: document.querySelector('#editor'),
|
||||
language: 'zh-CN',
|
||||
previewStyle: 'vertical',
|
||||
height: '660px',
|
||||
initialEditType: 'wysiwyg',
|
||||
initialValue: ""
|
||||
});
|
||||
|
||||
const id = getUrlParameter("id");
|
||||
|
||||
|
||||
return {
|
||||
article: {
|
||||
title: "",
|
||||
slug: "",
|
||||
content: "",
|
||||
coverUrl: "",
|
||||
tags: [],
|
||||
categoryId: 0,
|
||||
summary: "",
|
||||
id: id
|
||||
},
|
||||
tagInput:"",
|
||||
tempfile: null,
|
||||
coverUrl:"",
|
||||
categories: [],
|
||||
isSubmitting: false,
|
||||
loadCategories() {
|
||||
|
||||
axios.get('categories')
|
||||
.then(data => {
|
||||
this.categories = data;
|
||||
});
|
||||
return this;
|
||||
},
|
||||
loadPage() {
|
||||
axios.get('pages/' + id)
|
||||
.then(data => {
|
||||
this.article = data;
|
||||
editor.setMarkdown(this.article.content);
|
||||
});
|
||||
return this;
|
||||
},
|
||||
editArticle() {
|
||||
if(this.isSubmitting){
|
||||
return;
|
||||
}
|
||||
this.isSubmitting = true;
|
||||
axios.put('pages/', this.article)
|
||||
.then(data => {
|
||||
console.log('data:', data);
|
||||
location.href = "/admin/page";
|
||||
})
|
||||
.finally(() => {
|
||||
this.isSubmitting = false;
|
||||
});
|
||||
|
||||
},
|
||||
addIcon() {
|
||||
const fileinput = document.getElementById('img-file-input');
|
||||
if (fileinput) {
|
||||
fileinput.click();
|
||||
}
|
||||
},
|
||||
init() {
|
||||
editor.on('change', () => {
|
||||
this.article.content = editor.getMarkdown();
|
||||
});
|
||||
|
||||
this.loadCategories().loadPage();
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
document.title = "编辑单页 - " + window.config.name + "";
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
});
|
||||
40
Yes.Blog/wwwroot/admin/js/page/index.js
Normal file
40
Yes.Blog/wwwroot/admin/js/page/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('pages')
|
||||
.then(data => {
|
||||
this.items = data;
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
deleteId: 0,
|
||||
showModal: false,
|
||||
confirmAction() {
|
||||
this.isSubmitting = true;
|
||||
axios.delete('pages?id=' + this.deleteId)
|
||||
.then(data => {
|
||||
this.loadItems();
|
||||
})
|
||||
.finally(() => {
|
||||
this.isSubmitting = false;
|
||||
});
|
||||
},
|
||||
init() {
|
||||
this.loadItems();
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
document.title = "单页面列表 - " + window.config.name + "";
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user