-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
030e2c4
commit b3f1658
Showing
9 changed files
with
330 additions
and
65 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import base from '@/api/base' | ||
//@ts-ignore | ||
import { get, post } from '@/utils/request' | ||
|
||
/** | ||
* 获取评论列表 | ||
*/ | ||
const getCommentList = async (user_id: number) => { | ||
const rs = get(`${base.api_v2_url}/comment`, { | ||
user_id: user_id | ||
}) | ||
return base.buildResponse(await rs) | ||
} | ||
|
||
|
||
/** | ||
* 添加评论 | ||
*/ | ||
const postComment = async (user_id: number, comment: string) => { | ||
const rs = post(`${base.api_v2_url}/comment`, { | ||
user_id: user_id, | ||
comment: comment | ||
}) | ||
return base.buildResponse(await rs) | ||
} | ||
|
||
const comment = { | ||
get: getCommentList, | ||
post: postComment, | ||
} | ||
|
||
export default comment |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import root from "./root.api" | ||
|
||
export default { | ||
root: root | ||
} |
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,25 @@ | ||
import base from '@/api/base' | ||
//@ts-ignore | ||
import { get, post } from '@/utils/request' | ||
|
||
const getPrize = async (user_id: number) => { | ||
const rs = get(`${base.api_v2_url}/prize`, { | ||
user_id: user_id | ||
}) | ||
return base.buildResponse(await rs) | ||
} | ||
|
||
const joinPrize = async (user_id: number, prize_id: number) => { | ||
const rs = post(`${base.api_v2_url}/prize`, { | ||
user_id: user_id, | ||
prize_id: prize_id | ||
}) | ||
return base.buildResponse(await rs) | ||
} | ||
|
||
const prize = { | ||
get: getPrize, | ||
join: joinPrize | ||
} | ||
|
||
export default prize |
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
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,95 @@ | ||
<template> | ||
<n-h1 prefix="bar" style="margin-top: 30px"> | ||
<i class="twa twa-red-paper-lantern"></i> | ||
<n-text type="primary"> 新年祝福</n-text> | ||
</n-h1> | ||
<n-form :ref="formRef" :model="newYear" label-width="auto" size="large"> | ||
<n-grid cols="1" item-responsive> | ||
<n-grid-item span="1"> | ||
<n-form-item label="评论和祝福" path="comment"> | ||
<n-input v-model:value="newYear.comment" placeholder="您有什么想对 LoCyanFrp 全体用户说的吗" /> | ||
</n-form-item> | ||
</n-grid-item> | ||
<n-gi span="1"> | ||
<n-space justify="end"><n-button type="primary" @click="submitComment()"> 提交</n-button></n-space> | ||
</n-gi> | ||
</n-grid> | ||
</n-form> | ||
<n-grid cols="3" item-responsive> | ||
<n-grid-item v-for="item in commentList" id="item" span="0:3 950:1"> | ||
<n-space style="display: block"> | ||
<n-card :title="'ID: ' + item.id + ' - ' + item.username"> | ||
{{ item.comment }} | ||
<template #footer> 提交时间:{{ timestampToTime(item.time) }} </template> | ||
</n-card> | ||
</n-space> | ||
</n-grid-item> | ||
</n-grid> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from 'vue' | ||
import Message from '@/utils/dialog.js' | ||
import api from '@/api' | ||
import userData from '@/utils/stores/userData/store.js' | ||
const message = new Message() | ||
const commentList = ref([]) | ||
const formRef = ref(null) | ||
const newYear = ref({ | ||
comment: '' | ||
}) | ||
function timestampToTime(timestamp) { | ||
const date = new Date(timestamp * 1000) | ||
const Y = date.getFullYear() + '-' | ||
const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-' | ||
const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ' | ||
const h = date.getHours() + ':' | ||
const m = date.getMinutes() + ':' | ||
const s = date.getSeconds() | ||
return Y + M + D + h + m + s | ||
} | ||
async function submitComment() { | ||
let rs | ||
try { | ||
rs = await api.v2.comment.post(userData.getters.get_user_id, newYear.value.comment); | ||
} catch (e) { | ||
logger.error(e); | ||
message.error("接口请求失败:" + e); | ||
} | ||
if (!rs) return | ||
if (rs.status === 200) { | ||
message.success("提交成功"); | ||
getMessageList(); | ||
} else { | ||
message.error(rs.message); | ||
} | ||
} | ||
async function getMessageList() { | ||
let rs | ||
try { | ||
rs = await api.v2.comment.get(userData.getters.get_user_id) | ||
} catch (e) { | ||
logger.error(e); | ||
message.error("接口请求失败:" + e); | ||
} | ||
if (!rs) return | ||
if (rs.status === 200) { | ||
commentList.value = rs.data.list | ||
} else { | ||
message.error(rs.message); | ||
} | ||
} | ||
getMessageList() | ||
</script> | ||
<style scoped> | ||
#item { | ||
max-width: 100vw; | ||
margin: 20px; | ||
} | ||
</style> |
Oops, something went wrong.