feat(阶段1): 搬入 ojnext 为 apps/web,未改业务代码

This commit is contained in:
2026-08-06 21:18:16 -06:00
parent 3c975e85ee
commit ae1fb329b5
258 changed files with 40490 additions and 91 deletions
@@ -0,0 +1,39 @@
<script lang="ts" setup>
import { deleteAnnouncement } from "admin/api"
interface Props {
announcementID: number
}
const props = defineProps<Props>()
const emit = defineEmits(["deleted"])
const router = useRouter()
const message = useMessage()
function goEdit() {
router.push({
name: "admin announcement edit",
params: { announcementID: props.announcementID },
})
}
async function handleDelete() {
await deleteAnnouncement(props.announcementID)
message.success("删除成功")
emit("deleted")
}
</script>
<template>
<n-flex>
<n-button size="small" type="success" secondary @click="goEdit">
编辑
</n-button>
<n-popconfirm @positive-click="handleDelete">
<template #trigger>
<n-button size="small" type="error" secondary>删除</n-button>
</template>
确定删除这条公告吗
</n-popconfirm>
</n-flex>
</template>
<style scoped></style>
+117
View File
@@ -0,0 +1,117 @@
<script lang="ts" setup>
import TextEditor from "shared/components/TextEditor.vue"
import type { AnnouncementEdit } from "utils/types"
import { createAnnouncement, editAnnouncement, getAnnouncement } from "../api"
interface Props {
announcementID?: string
}
const route = useRoute()
const router = useRouter()
const message = useMessage()
const props = defineProps<Props>()
const [ready, toggleReady] = useToggle()
const announcement = reactive<AnnouncementEdit>({
id: 0,
title: "",
tag: "公告",
content: "",
visible: false,
top: false,
})
const tags: SelectOption[] = [
{ label: "公告", value: "公告" },
{ label: "更新", value: "更新" },
]
async function init() {
if (!props.announcementID) {
toggleReady(true)
return
}
const id = parseInt(route.params.announcementID as string)
const res = await getAnnouncement(id)
toggleReady(true)
announcement.id = id
announcement.title = res.data.title
announcement.content = res.data.content
announcement.visible = res.data.visible
announcement.tag = res.data.tag
announcement.top = res.data.top
}
async function submit() {
if (announcement.content === "<p><br></p>") {
announcement.content = ""
}
if (!announcement.title || !announcement.content) {
message.error("标题和正文必填")
return
}
const api = {
"admin announcement create": createAnnouncement,
"admin announcement edit": editAnnouncement,
}[route.name as string]
try {
await api!(announcement)
if (route.name === "admin announcement create") {
message.success("成功新建公告 💐")
} else {
message.success("修改已保存")
}
router.push({ name: "admin announcement list" })
} catch (err: any) {
message.error(err.data)
}
}
onMounted(init)
</script>
<template>
<h2 class="title">
{{ route.name === "admin announcement create" ? "新建公告" : "编辑公告" }}
</h2>
<n-form inline>
<n-form-item label="标题">
<n-input class="contestTitle" v-model:value="announcement.title" />
</n-form-item>
<n-form-item label="标签">
<n-select
class="select"
v-model:value="announcement.tag"
:options="tags"
/>
</n-form-item>
<n-form-item label="可见">
<n-switch v-model:value="announcement.visible" />
</n-form-item>
<n-form-item label="置顶">
<n-switch v-model:value="announcement.top" />
</n-form-item>
</n-form>
<TextEditor
v-if="ready"
title="正文"
v-model:value="announcement.content"
:min-height="200"
/>
<n-flex style="margin-bottom: 100px" justify="end">
<n-button type="primary" @click="submit">保存</n-button>
</n-flex>
</template>
<style scoped>
.title {
margin-top: 0;
}
.select {
width: 100px;
}
.contestTitle {
width: 400px;
}
</style>
+113
View File
@@ -0,0 +1,113 @@
<script setup lang="ts">
import { NSwitch } from "naive-ui"
import Pagination from "shared/components/Pagination.vue"
import { parseTime } from "utils/functions"
import type { Announcement } from "utils/types"
import { editAnnouncement, getAnnouncementList } from "../api"
import Actions from "./components/Actions.vue"
const total = ref(0)
const query = reactive({
limit: 10,
page: 1,
})
const announcements = ref<Announcement[]>([])
const columns: DataTableColumn<Announcement>[] = [
{ title: "ID", key: "id", width: 60 },
{ title: "标题", key: "title", minWidth: 300 },
{ title: "标签", key: "tag", width: 80 },
{
title: "置顶",
key: "top",
render: (row) => (row.top ? "置顶" : ""),
width: 80,
},
{
title: "创建时间",
key: "create_time",
width: 180,
render: (row) => parseTime(row.create_time, "YYYY-MM-DD HH:mm:ss"),
},
{
title: "上次更新时间",
key: "last_update_time",
width: 180,
render: (row) => parseTime(row.last_update_time, "YYYY-MM-DD HH:mm:ss"),
},
{
title: "作者",
key: "created_by",
render: (row) => row.created_by.username,
width: 80,
},
{
title: "可见",
key: "visible",
render: (row) =>
h(NSwitch, {
value: row.visible,
size: "small",
rubberBand: false,
onUpdateValue: () => toggleVisible(row),
}),
},
{
title: "选项",
key: "actions",
width: 140,
render: (row) =>
h(Actions, { announcementID: row.id, onDeleted: listAnnouncements }),
},
]
async function toggleVisible(announcement: Announcement) {
announcement.visible = !announcement.visible
editAnnouncement({
id: announcement.id,
title: announcement.title,
tag: announcement.tag,
content: announcement.content,
visible: announcement.visible,
top: announcement.top,
})
}
async function listAnnouncements() {
const offset = (query.page - 1) * query.limit
const res = await getAnnouncementList(offset, query.limit)
announcements.value = res.data.results
total.value = res.data.total
}
onMounted(listAnnouncements)
watch(query, listAnnouncements, { deep: true })
</script>
<template>
<n-flex align="center" class="titleWrapper">
<h2 class="title">网站公告</h2>
<n-button
type="primary"
@click="$router.push({ name: 'admin announcement create' })"
>
新建
</n-button>
</n-flex>
<n-data-table striped :columns="columns" :data="announcements" />
<Pagination
:total="total"
v-model:limit="query.limit"
v-model:page="query.page"
/>
</template>
<style scoped>
.titleWrapper {
margin-bottom: 16px;
}
.title {
margin: 0;
}
</style>