-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add page search and configure switch
- Loading branch information
1 parent
ffab29c
commit d217235
Showing
26 changed files
with
628 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,4 +49,4 @@ export default (page: number, totalPages: number, totalVisible: number) => ({ | |
|
||
return range; | ||
}, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,75 @@ | ||
import axios from "axios"; | ||
|
||
export default (postId: any,likeNum: string) => ({ | ||
export default (postId: any, likeNum: string) => ({ | ||
postId: postId, | ||
likeNum: likeNum, | ||
loading: false, | ||
liked: false, | ||
get upvote() { | ||
this.init() | ||
this.init(); | ||
if (this.loading || this.liked) return; | ||
|
||
this.loading = true; | ||
axios.post( | ||
'/apis/api.halo.run/v1alpha1/trackers/upvote', | ||
{ | ||
axios | ||
.post( | ||
"/apis/api.halo.run/v1alpha1/trackers/upvote", | ||
{ | ||
group: "content.halo.run", | ||
plural: "posts", | ||
name: this.postId, | ||
}, | ||
{ | ||
headers: { | ||
'Content-Type': 'application/json; charset=utf-8' | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json; charset=utf-8", | ||
}, | ||
} | ||
} | ||
).then(() => { | ||
this.liked = true; | ||
this.loading = false; | ||
localStorage.setItem("likeNum:" + this.postId, String(Number(this.likeNum) + 1)) | ||
this.likeNum = String(Number(this.likeNum) + 1) | ||
}).catch(() => { | ||
) | ||
.then(() => { | ||
this.liked = true; | ||
this.loading = false; | ||
localStorage.setItem("likeNum:" + this.postId, String(Number(this.likeNum) + 1)); | ||
this.likeNum = String(Number(this.likeNum) + 1); | ||
}) | ||
.catch(() => { | ||
this.loading = false; | ||
}); | ||
}, | ||
get downvote() { | ||
if (this.loading || !this.liked) return; | ||
|
||
this.loading = true; | ||
axios.post( | ||
'/apis/api.halo.run/v1alpha1/trackers/downvote', | ||
{ | ||
group: "content.halo.run", | ||
plural: "posts", | ||
name: this.postId, | ||
}, | ||
{ | ||
headers: { | ||
'Content-Type': 'application/json; charset=utf-8' | ||
axios | ||
.post( | ||
"/apis/api.halo.run/v1alpha1/trackers/downvote", | ||
{ | ||
group: "content.halo.run", | ||
plural: "posts", | ||
name: this.postId, | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json; charset=utf-8", | ||
}, | ||
} | ||
} | ||
).then(() => { | ||
let num = Number(this.likeNum) - 1 | ||
this.likeNum = String(num < 0 ? 0 : num) | ||
localStorage.removeItem("likeNum:" + this.postId) | ||
this.loading = false; | ||
this.liked = !this.liked | ||
}).catch(() => { | ||
this.loading = false; | ||
}); | ||
) | ||
.then(() => { | ||
let num = Number(this.likeNum) - 1; | ||
this.likeNum = String(num < 0 ? 0 : num); | ||
localStorage.removeItem("likeNum:" + this.postId); | ||
this.loading = false; | ||
this.liked = !this.liked; | ||
}) | ||
.catch(() => { | ||
this.loading = false; | ||
}); | ||
}, | ||
init() { | ||
if(this.likeNumExists(this.postId) !== null && Number(this.likeNumExists(this.postId)) > 0){ | ||
this.liked = true | ||
if (this.likeNumExists(this.postId) !== null && Number(this.likeNumExists(this.postId)) > 0) { | ||
this.liked = true; | ||
} | ||
return this.liked | ||
return this.liked; | ||
}, | ||
likeNumExists(id: any) { | ||
return localStorage.getItem("likeNum:" + id); | ||
}, | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import axios from "axios"; | ||
|
||
export default () => ({ | ||
loading: false, | ||
isSearch: false, | ||
keys: "", | ||
searchData: {}, | ||
init() { | ||
this.searchData = {}; | ||
this.isSearch = false; | ||
}, | ||
get keywords() { | ||
if (this.loading || this.keys == "") { | ||
this.keyClear | ||
return; | ||
} | ||
this.loading = true; | ||
axios | ||
.get("/apis/api.halo.run/v1alpha1/indices/post", { | ||
params: { | ||
limit: 20, | ||
keyword: this.keys, | ||
highlightPreTag: "<b style='background-color:#D8EAFD;color:#1077D1'>", | ||
highlightPostTag: "</b>", | ||
}, | ||
headers: { | ||
"Content-Type": "application/json; charset=utf-8", | ||
}, | ||
}) | ||
.then((res) => { | ||
this.loading = false; | ||
this.searchData = res.data; | ||
this.isSearch = true; | ||
}) | ||
.catch(() => { | ||
this.isSearch = false; | ||
this.loading = false; | ||
}); | ||
}, | ||
get keyClear() { | ||
this.keys = ""; | ||
this.searchData = {}; | ||
this.isSearch = false; | ||
return; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.