1
This commit is contained in:
78
Yes.Blog/TempFiles/admin/js/article/add.js
Normal file
78
Yes.Blog/TempFiles/admin/js/article/add.js
Normal file
@@ -0,0 +1,78 @@
|
||||
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 {
|
||||
pageTitle: "撰写新文章 - " + window.config.name + "",
|
||||
article: {
|
||||
title: "",
|
||||
slug: "",
|
||||
content: "",
|
||||
coverUrl: "",
|
||||
tags: [],
|
||||
categoryId: 0,
|
||||
summary: ""
|
||||
},
|
||||
tempfile :null,
|
||||
categories: [],
|
||||
isSubmitting: false,
|
||||
tagInputText:"",
|
||||
loadCategories() {
|
||||
if (this.loading) {
|
||||
return;
|
||||
}
|
||||
this.loading = true;
|
||||
axios.get('categories')
|
||||
.then(data => {
|
||||
this.categories = data;
|
||||
});
|
||||
},
|
||||
saveTags() {
|
||||
this.tagInputText = document.getElementById('tag-input').innerText;
|
||||
if (this.tagInputText) {
|
||||
this.tagInputText.replace(/,/g, ",").replace(/ /g, ",").split(',').forEach(x => this.article.tags.push(x));
|
||||
document.getElementById('tag-input').innerText = '';
|
||||
}
|
||||
},
|
||||
createArticle() {
|
||||
this.saveTags();
|
||||
if(this.isSubmitting){
|
||||
return;
|
||||
}
|
||||
this.isSubmitting = true;
|
||||
axios.post('articles', this.article)
|
||||
.then(data => {
|
||||
location.href = "/admin/article";
|
||||
})
|
||||
.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 = this.pageTitle;
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
});
|
||||
83
Yes.Blog/TempFiles/admin/js/article/detail.js
Normal file
83
Yes.Blog/TempFiles/admin/js/article/detail.js
Normal file
@@ -0,0 +1,83 @@
|
||||
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
|
||||
},
|
||||
tempfile :null,
|
||||
tagInput:"",
|
||||
categories: [],
|
||||
isSubmitting: false,
|
||||
loadCategories() {
|
||||
axios.get('categories')
|
||||
.then(data => {
|
||||
this.categories = data;
|
||||
});
|
||||
return this;
|
||||
},
|
||||
loadArticle() {
|
||||
axios.get('articles/' + id)
|
||||
.then(data => {
|
||||
this.article = data;
|
||||
editor.setMarkdown(this.article.content);
|
||||
});
|
||||
return this;
|
||||
},
|
||||
saveTags() {
|
||||
this.tagInputText = document.getElementById('tag-input').innerText;
|
||||
if (this.tagInputText) {
|
||||
this.tagInputText.replace(/,/g, ",").replace(/ /g, ",").split(',').forEach(x => this.article.tags.push(x));
|
||||
document.getElementById('tag-input').innerText = '';
|
||||
}
|
||||
},
|
||||
editArticle() {
|
||||
this.saveTags();
|
||||
if(this.isSubmitting){
|
||||
return;
|
||||
}
|
||||
this.isSubmitting = true;
|
||||
axios.put('articles/', this.article)
|
||||
.then(data => {
|
||||
location.href = "/admin/article";
|
||||
})
|
||||
.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().loadArticle();
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
document.title = "编辑文章 - " + window.config.name + "";
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
});
|
||||
49
Yes.Blog/TempFiles/admin/js/article/index.js
Normal file
49
Yes.Blog/TempFiles/admin/js/article/index.js
Normal file
@@ -0,0 +1,49 @@
|
||||
document.addEventListener('alpine:init', function () {
|
||||
Alpine.data('data', function () {
|
||||
return {
|
||||
pageinfo: {
|
||||
items: []
|
||||
},
|
||||
loading: false,
|
||||
loadItems(pageIndex = 1) {
|
||||
if (this.loading) {
|
||||
return;
|
||||
}
|
||||
this.loading = true;
|
||||
axios.get('articles?pageIndex=' + pageIndex)
|
||||
.then(data => {
|
||||
this.pageinfo = data;
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
getVisiblePages() {
|
||||
const visiblePages = [];
|
||||
const startPage = Math.max(1, this.pageinfo.pageIndex - 3);
|
||||
const endPage = Math.min(this.pageinfo.totalPage, this.pageinfo.pageIndex + 3);
|
||||
|
||||
for (let i = startPage; i <= endPage; i++) {
|
||||
visiblePages.push(i);
|
||||
}
|
||||
|
||||
return visiblePages;
|
||||
},
|
||||
deleteId: 0,
|
||||
showModal: false,
|
||||
confirmAction() {
|
||||
axios.delete('articles?id=' + this.deleteId)
|
||||
.then(data => {
|
||||
this.loadItems(this.pageinfo.pageIndex);
|
||||
});
|
||||
},
|
||||
init() {
|
||||
this.loadItems(1);
|
||||
window.addEventListener('load', () => {
|
||||
document.title = "文章列表 - " + window.config.name + "";
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user