Skip to content

Commit

Permalink
[+] 新年更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Daiyangcheng committed Jan 26, 2025
1 parent 030e2c4 commit b3f1658
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 65 deletions.
5 changes: 5 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ declare module 'vue' {
NAvatar: typeof import('naive-ui')['NAvatar']
NButton: typeof import('naive-ui')['NButton']
NCard: typeof import('naive-ui')['NCard']
NCollapse: typeof import('naive-ui')['NCollapse']
NCollapseItem: typeof import('naive-ui')['NCollapseItem']
NDivider: typeof import('naive-ui')['NDivider']
NDrawer: typeof import('naive-ui')['NDrawer']
NDrawerContent: typeof import('naive-ui')['NDrawerContent']
NEl: typeof import('naive-ui')['NEl']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NGi: typeof import('naive-ui')['NGi']
NGrid: typeof import('naive-ui')['NGrid']
NGridItem: typeof import('naive-ui')['NGridItem']
NH1: typeof import('naive-ui')['NH1']
Expand All @@ -37,6 +40,8 @@ declare module 'vue' {
NModal: typeof import('naive-ui')['NModal']
NNumberAnimation: typeof import('naive-ui')['NNumberAnimation']
NP: typeof import('naive-ui')['NP']
NQrCode: typeof import('naive-ui')['NQrCode']
NSkeleton: typeof import('naive-ui')['NSkeleton']
NSpace: typeof import('naive-ui')['NSpace']
NSpin: typeof import('naive-ui')['NSpin']
NStatistic: typeof import('naive-ui')['NStatistic']
Expand Down
32 changes: 32 additions & 0 deletions src/api/v2/comment.api.ts
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
6 changes: 5 additions & 1 deletion src/api/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import notice from './notice'
import minecraft from './minecraft'
import app from './app'
import captcha from './captcha.api'
import prize from './prize'
import comment from './comment.api'

export default {
user: user,
Expand All @@ -25,5 +27,7 @@ export default {
notice: notice,
minecraft: minecraft,
app: app,
captcha: captcha
captcha: captcha,
prize: prize,
comment: comment
}
5 changes: 5 additions & 0 deletions src/api/v2/prize/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import root from "./root.api"

export default {
root: root
}
25 changes: 25 additions & 0 deletions src/api/v2/prize/root.api.ts
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
60 changes: 16 additions & 44 deletions src/components/sidebar/MainSidebar.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
<template>
<n-layout-sider
bordered
show-trigger
:collapsed="collapsed"
@collapse="collapsed = true"
@expand="collapsed = false"
collapse-mode="width"
:collapsed-width="64"
:native-scrollbar="false"
id="sider"
style="height: 100%; bottom: 0"
>
<n-menu
ref="menuInstRef"
:collapsed="collapsed"
:collapsed-width="64"
:collapsed-icon-size="22"
:options="menuOptions"
style=""
:value="active"
@update:value="handleUpdateValue"
/>
<n-layout-sider bordered show-trigger :collapsed="collapsed" @collapse="collapsed = true" @expand="collapsed = false"
collapse-mode="width" :collapsed-width="64" :native-scrollbar="false" id="sider" style="height: 100%; bottom: 0">
<n-menu ref="menuInstRef" :collapsed="collapsed" :collapsed-width="64" :collapsed-icon-size="22"
:options="menuOptions" style="" :value="active" @update:value="handleUpdateValue" />
</n-layout-sider>
</template>

Expand Down Expand Up @@ -65,28 +47,18 @@ const menuOptions = [
key: 'dashboard',
icon: renderIcon(CompassSharp)
},
// {
// label: '新春活动',
// key: 'yearly',
// show: false,
// icon: renderIcon(PlanetOutline),
// children: [
// {
// path: '/hello2024',
// label: '评价和祝福',
// show: true,
// key: 'new-year',
// icon: renderIcon(PlanetOutline)
// },
// {
// path: '/prize',
// label: '抽奖',
// show: true,
// key: 'prize',
// icon: renderIcon(PlanetOutline)
// }
// ]
// },
{
path: '/comment',
label: '留言',
key: 'comment',
icon: renderIcon(PencilSharp)
},
{
path: '/prize',
label: '抽奖',
key: 'prize',
icon: renderIcon(PencilSharp)
},
{
path: '/verification',
label: '身份认证',
Expand Down
40 changes: 20 additions & 20 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,26 @@ const routes = [
},
component: () => import('@views/VerificationView.vue')
},
// {
// path: '/hello2024',
// name: 'NewYear',
// meta: {
// title: '留言',
// keepAlive: true,
// needLogin: true
// },
// component: () => import('../../_deprecated/activities/NewYearView.vue')
// },
// {
// path: '/prize',
// name: 'Prize',
// meta: {
// title: '抽奖',
// keepAlive: true,
// needLogin: true
// },
// component: () => import('../../_deprecated/activities/PrizeView.vue')
// },
{
path: '/comment',
name: 'comment',
meta: {
title: '留言',
keepAlive: true,
needLogin: true
},
component: () => import('@views/NewYearView.vue')
},
{
path: '/prize',
name: 'Prize',
meta: {
title: '抽奖',
keepAlive: true,
needLogin: true
},
component: () => import('@views/PrizeView.vue')
},
{
path: '/donate',
name: 'Donate',
Expand Down
95 changes: 95 additions & 0 deletions src/views/NewYearView.vue
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>
Loading

0 comments on commit b3f1658

Please sign in to comment.