更新readme

master
barney 2 years ago
parent f2d3b6632b
commit d3886ae21d
  1. 10
      README.md
  2. 11
      frontend/src/components/ArticleList.vue
  3. 11
      frontend/src/components/BlogHeader.vue
  4. 37
      frontend/src/components/CommentView.vue
  5. 2
      frontend/src/router/index.js
  6. 4
      frontend/src/store/index.js
  7. 4
      frontend/src/utils/authorization.js
  8. 18
      frontend/src/views/ArticleCreate.vue
  9. 6
      frontend/src/views/ArticleDetailView.vue
  10. 17
      frontend/src/views/ArticleEdit.vue
  11. 4
      frontend/src/views/LoginView.vue

@ -2,20 +2,20 @@
#### 1、博客首页展示 #### 1、博客首页展示
![image-20221003002818644](C:\Users\15270\AppData\Roaming\Typora\typora-user-images\image-20221003002818644.png) ![博客首页](https://cdn.jsdelivr.net/gh/JokerZhang66/images@master//img/image-20221003002818644.png)
#### 2.发布文章界面 #### 2.发布文章界面
![image-20221003002550725](C:\Users\15270\AppData\Roaming\Typora\typora-user-images\image-20221003002550725.png) ![](https://cdn.jsdelivr.net/gh/JokerZhang66/images@master//img/image-20221003002550725.png)
#### 3.登录、注册界面 #### 3.登录、注册界面
![image-20221003002956157](C:\Users\15270\AppData\Roaming\Typora\typora-user-images\image-20221003002956157.png) ![](https://cdn.jsdelivr.net/gh/JokerZhang66/images@master//img/image-20221003002956157.png)
#### 4.用户管理界面 #### 4.用户管理界面
![image-20221003002845601](C:\Users\15270\AppData\Roaming\Typora\typora-user-images\image-20221003002845601.png) ![](https://cdn.jsdelivr.net/gh/JokerZhang66/images@master//img/image-20221003002845601.png)
#### 5.更新文章界面 #### 5.更新文章界面
![image-20221003003047933](C:\Users\15270\AppData\Roaming\Typora\typora-user-images\image-20221003003047933.png) ![](https://cdn.jsdelivr.net/gh/JokerZhang66/images@master//img/image-20221003003047933.png)

@ -17,11 +17,7 @@
{{ article.category.title }} {{ article.category.title }}
</span> </span>
<span <span v-for="tag in article.tags" v-bind:key="tag" class="tag">
v-for="tag in article.tags"
v-bind:key="tag"
class="tag"
>
{{ tag }} {{ tag }}
</span> </span>
<!-- 路由链接:to的两个参数分别是: 路由名称和传入的id --> <!-- 路由链接:to的两个参数分别是: 路由名称和传入的id -->
@ -200,7 +196,6 @@ export default {
</script> </script>
<style scoped> <style scoped>
#articles { #articles {
padding: 0.4rem; padding: 0.4rem;
} }
@ -210,17 +205,15 @@ export default {
border-radius: 10px; border-radius: 10px;
box-shadow: darkslategrey 0 0 12px; box-shadow: darkslategrey 0 0 12px;
user-select: none; user-select: none;
} }
.image-container { .image-container {
width: 100%; width: 100%;
display: grid; display: grid;
place-items: center; place-items: center;
} }
.article-info { .article-info {
width:90%; width: 90%;
border-radius: 10px; border-radius: 10px;
background-color: lightgray; background-color: lightgray;
display: grid; display: grid;

@ -90,14 +90,14 @@ export default {
}); });
onMounted(() => { onMounted(() => {
authorization().then( authorization().then((data) => {
(data) => {[haslogin.value, username.value] = data} [haslogin.value, username.value] = data;
); });
}); });
const refresh = () => { const refresh = () => {
username.value = localStorage.getItem("username_blog"); username.value = localStorage.getItem("username_blog");
} };
return { return {
username, username,
@ -106,7 +106,7 @@ export default {
homePage, homePage,
quit, quit,
}; };
} },
}; };
</script> </script>
@ -155,7 +155,6 @@ export default {
background-color: lightblue; background-color: lightblue;
z-index: 10; z-index: 10;
} }
</style> </style>
<style scoped> <style scoped>

@ -52,23 +52,23 @@
</template> </template>
<script> <script>
import $ from 'jquery'; import $ from "jquery";
import authorization from '@/utils/authorization' import authorization from "@/utils/authorization";
import { ref, watchEffect } from 'vue'; import { ref, watchEffect } from "vue";
export default { export default {
name: "CommentView", name: "CommentView",
props: { props: {
article: { article: {
required: true, required: true,
} },
}, },
setup(props) { setup(props) {
// //
let comments = ref([]); let comments = ref([]);
// //
let message = ref(''); let message = ref("");
let placeholder = ref('说点啥吧...'); let placeholder = ref("说点啥吧...");
// //
let parentId = ref(null); let parentId = ref(null);
// //
@ -76,25 +76,25 @@ export default {
authorization().then((response) => { authorization().then((response) => {
if (response[0]) { if (response[0]) {
$.ajax({ $.ajax({
url: 'http://127.0.0.1:6789/api/comment/', url: "http://127.0.0.1:6789/api/comment/",
type: 'POST', type: "POST",
data: { data: {
content: message.value, content: message.value,
article_id: props.article.id, article_id: props.article.id,
parent_id: parentId.value, parent_id: parentId.value,
}, },
headers: { headers: {
authorization: "Bearer " + localStorage.getItem('access_blog') authorization:
"Bearer " + localStorage.getItem("access_blog"),
}, },
success(resp) { success(resp) {
// //
comments.value.unshift(resp); comments.value.unshift(resp);
message.value = ''; message.value = "";
window.alert("留言成功"); window.alert("留言成功");
} },
}) });
}else { } else {
window.alert("请登录后再评论!"); window.alert("请登录后再评论!");
} }
}); });
@ -102,16 +102,17 @@ export default {
const replyTo = (comment) => { const replyTo = (comment) => {
parentId.value = comment.id; parentId.value = comment.id;
placeholder.value = '对' + comment.author.username + '说'; placeholder.value = "对" + comment.author.username + "说";
}; };
const formatted_time = (iso_date_string) => { const formatted_time = (iso_date_string) => {
const date = new Date(iso_date_string); const date = new Date(iso_date_string);
return date.toLocaleDateString() + ' ' + date.toLocaleTimeString(); return date.toLocaleDateString() + " " + date.toLocaleTimeString();
}; };
watchEffect(() => { watchEffect(() => {
comments.value = props.article !== null ? props.article.comments : []; comments.value =
props.article !== null ? props.article.comments : [];
}); });
return { return {
@ -122,7 +123,7 @@ export default {
submit, submit,
replyTo, replyTo,
formatted_time, formatted_time,
} };
}, },
}; };
</script> </script>

@ -34,7 +34,7 @@ const routes = [
component: UserCenter, component: UserCenter,
}, },
{ {
path : "/article/create/", path: "/article/create/",
name: "ArticleCreate", name: "ArticleCreate",
component: ArticleCreate, component: ArticleCreate,
}, },

@ -9,9 +9,9 @@ export default createStore({
}, },
mutations: { mutations: {
updateIsLogin(state,islogin) { updateIsLogin(state, islogin) {
state.islogin = islogin; state.islogin = islogin;
},updateIsSuperUser(state, isSuperUser){ }, updateIsSuperUser(state, isSuperUser) {
state.isSuperUser = isSuperUser; state.isSuperUser = isSuperUser;
} }
}, },

@ -28,7 +28,7 @@ const authorization = async () => {
refresh: refreshToken, refresh: refreshToken,
}, },
success(resp) { success(resp) {
const nextExpiredTime = new Date().getTime() + 24*3600*1000; const nextExpiredTime = new Date().getTime() + 24 * 3600 * 1000;
storage.setItem("access_blog", resp.access); storage.setItem("access_blog", resp.access);
storage.removeItem("refresh_blog"); // 移除刷新令牌 storage.removeItem("refresh_blog"); // 移除刷新令牌
console.log( console.log(
@ -39,7 +39,7 @@ const authorization = async () => {
haslogin = true; haslogin = true;
}, },
}); });
}catch(err){ } catch (err) {
storage.clear(); storage.clear();
haslogin = false; haslogin = false;
// console.log('authorization err'); // console.log('authorization err');

@ -43,7 +43,7 @@
</div> </div>
<div class="form-elem"> <div class="form-elem">
<div style="margin-bottom: 10px;">正文</div> <div style="margin-bottom: 10px">正文</div>
<textarea <textarea
v-model="body" v-model="body"
placeholder="输入正文" placeholder="输入正文"
@ -66,7 +66,7 @@ import BlogFooter from "@/components/BlogFooter.vue";
import authorization from "@/utils/authorization"; import authorization from "@/utils/authorization";
import $ from "jquery"; import $ from "jquery";
import { onMounted } from "@vue/runtime-core"; import { onMounted } from "@vue/runtime-core";
import { useRouter } from 'vue-router'; import { useRouter } from "vue-router";
import { ref } from "vue"; import { ref } from "vue";
export default { export default {
name: "ArticleCreate", name: "ArticleCreate",
@ -140,12 +140,12 @@ export default {
processData: false, processData: false,
contentType: false, contentType: false,
headers: { headers: {
"Authorization": Authorization:
"Bearer " + localStorage.getItem("access_blog"), "Bearer " + localStorage.getItem("access_blog"),
}, },
success(resp) { success(resp) {
avatarID.value = resp.id; avatarID.value = resp.id;
} },
}); });
}; };
@ -183,8 +183,8 @@ export default {
url: "http://127.0.0.1:6789/api/article/", url: "http://127.0.0.1:6789/api/article/",
type: "POST", type: "POST",
data: JSON.stringify(data), data: JSON.stringify(data),
contentType: 'application/json', contentType: "application/json",
dataType: 'json', dataType: "json",
headers: { headers: {
Authorization: "Bearer " + token, Authorization: "Bearer " + token,
}, },
@ -199,8 +199,7 @@ export default {
window.alert("令牌过期,请重新登录。"); window.alert("令牌过期,请重新登录。");
} }
}); });
} };
return { return {
categories, categories,
@ -213,8 +212,7 @@ export default {
chooseCategory, chooseCategory,
onFileChange, onFileChange,
submit, submit,
} };
}, },
}; };
</script> </script>

@ -56,7 +56,7 @@ export default {
type: "GET", type: "GET",
success(resp) { success(resp) {
article.value = resp; article.value = resp;
} },
}); });
}); });
@ -66,9 +66,9 @@ export default {
}; };
// vue3使computed // vue3使computed
// //
let isSuperUser = computed(()=> { let isSuperUser = computed(() => {
return localStorage.getItem("is_superuser_blog") === "true"; return localStorage.getItem("is_superuser_blog") === "true";
}) });
return { return {
article, article,

@ -21,7 +21,12 @@
</button> </button>
</span> </span>
<div v-if="selectedCategory !== null" style="margin-top:5px; color:red;">:&nbsp;不选分类时可创建新分类!</div> <div
v-if="selectedCategory !== null"
style="margin-top: 5px; color: red"
>
:&nbsp;不选分类时可创建新分类!
</div>
<div class="newCategory" v-if="selectedCategory === null"> <div class="newCategory" v-if="selectedCategory === null">
<div>创建新分类:&nbsp;</div> <div>创建新分类:&nbsp;</div>
@ -172,7 +177,6 @@ export default {
// //
.filter((x) => x.charAt(0) !== ""); .filter((x) => x.charAt(0) !== "");
// //
if ( if (
selectedCategory.value === null && selectedCategory.value === null &&
@ -186,12 +190,13 @@ export default {
title: newCategory.value, title: newCategory.value,
}, },
headers: { headers: {
Authorization: "Bearer " + localStorage.getItem("access_blog"), Authorization:
"Bearer " +
localStorage.getItem("access_blog"),
}, },
success(resp) { success(resp) {
selectedCategory.value = resp; selectedCategory.value = resp;
}, },
}); });
} }
@ -199,7 +204,6 @@ export default {
? selectedCategory.value.id ? selectedCategory.value.id
: null; : null;
$.ajax({ $.ajax({
url: url:
"http://127.0.0.1:6789/api/article/" + "http://127.0.0.1:6789/api/article/" +
@ -210,7 +214,8 @@ export default {
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(data), data: JSON.stringify(data),
headers: { headers: {
Authorization: "Bearer " + localStorage.getItem("access_blog"), Authorization:
"Bearer " + localStorage.getItem("access_blog"),
}, },
success(resp) { success(resp) {
router.push({ router.push({

@ -28,7 +28,7 @@
</div> </div>
<div v-if="!haslogin"> <div v-if="!haslogin">
<div class="error">{{error_msg}}</div> <div class="error">{{ error_msg }}</div>
</div> </div>
</form> </form>
</div> </div>
@ -101,7 +101,7 @@ export default {
error(resp) { error(resp) {
error_msg.value = resp.responseText; error_msg.value = resp.responseText;
haslogin.value = false; haslogin.value = false;
} },
}); });
}; };

Loading…
Cancel
Save