rebuild: store

This commit is contained in:
KUN1007 2023-09-28 21:07:12 +08:00
parent 2d7218e34a
commit 3c86a505a7
16 changed files with 289 additions and 325 deletions

View file

@ -42,6 +42,8 @@ const handelInput = () => {
// //
if (topicTitle.value.trim() === '') { if (topicTitle.value.trim() === '') {
title.value = ''
topicRewrite.value.title = ''
return return
} }
@ -52,7 +54,6 @@ const handelInput = () => {
*/ */
// edit store // edit store
if (!topicRewrite.value.isTopicRewriting) { if (!topicRewrite.value.isTopicRewriting) {
// xss
title.value = topicTitle.value title.value = topicTitle.value
} }
/** /**

View file

@ -1,26 +1,52 @@
/**
* KUNGalgame pinia pinia-plugin-persistedstate
*
*/
import { createPinia } from 'pinia' import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import type { App } from 'vue' import type { App } from 'vue'
// 导入编辑界面 store
import { useKUNGalgameEditStore } from './modules/edit'
// 导入 home store
import { useKUNGalgameHomeStore } from './modules/home'
// 导入用户 store // 导入用户 store
import { useKUNGalgameUserStore } from '@/store/modules/kungalgamer' import { useKUNGalgameUserStore } from '@/store/modules/kungalgamer'
// 导入 message store
import { useKUNGalgameMessageStore } from './modules/message'
// 导入网站设置面板 store // 导入网站设置面板 store
import { useKUNGalgameSettingsStore } from '@/store/modules/settings' import { useKUNGalgameSettingsStore } from '@/store/modules/settings'
// 导入话题详情页面的 store
import { useKUNGalgameTopicStore } from './modules/topic'
const store = createPinia() const store = createPinia()
// 设置 pinia 的函数,在 main.ts 挂载
export function setupPinia(app: App<Element>) { export function setupPinia(app: App<Element>) {
store.use(piniaPluginPersistedstate) store.use(piniaPluginPersistedstate)
app.use(store) app.use(store)
} }
// 重置所有 store用于登出
export function storeReset() { export function storeReset() {
const editStore = useKUNGalgameEditStore()
const homeStore = useKUNGalgameHomeStore()
const userStore = useKUNGalgameUserStore() const userStore = useKUNGalgameUserStore()
const messageStore = useKUNGalgameMessageStore()
const settingsStore = useKUNGalgameSettingsStore() const settingsStore = useKUNGalgameSettingsStore()
const topicStore = useKUNGalgameTopicStore()
editStore.$reset()
homeStore.$reset()
userStore.$reset() userStore.$reset()
messageStore.$reset()
settingsStore.$reset() settingsStore.$reset()
topicStore.$reset()
} }
export { store } export { store }

View file

@ -16,14 +16,14 @@ import {
EditGetHotTagsResponseData, EditGetHotTagsResponseData,
} from '@/api' } from '@/api'
// store interface // store interface
import { Topic } from '../types/edit' import { EditStore } from '../types/edit'
// some utils to check topic publish data is valid // some utils to check topic publish data is valid
import { checkTopicPublish } from '../utils/checkTopicPublish' import { checkTopicPublish } from '../utils/checkTopicPublish'
export const useKUNGalgameEditStore = defineStore({ export const useKUNGalgameEditStore = defineStore({
id: 'edit', id: 'edit',
persist: true, persist: true,
state: (): Topic => ({ state: (): EditStore => ({
editorHeight: 300, editorHeight: 300,
textCount: 0, textCount: 0,
mode: '', mode: '',
@ -49,7 +49,7 @@ export const useKUNGalgameEditStore = defineStore({
getters: {}, getters: {},
actions: { actions: {
// 创建话题 // 创建话题
createNewTopic(): Promise<EditCreateTopicResponseData> | undefined { async createNewTopic(): Promise<EditCreateTopicResponseData | undefined> {
// 当前话题的数据 // 当前话题的数据
const requestData: EditCreateTopicRequestData = { const requestData: EditCreateTopicRequestData = {
title: this.title, title: this.title,
@ -63,18 +63,10 @@ export const useKUNGalgameEditStore = defineStore({
return return
} }
// 合法则请求接口发布话题 // 合法则请求接口发布话题
return new Promise((resolve, reject) => { return await postEditNewTopicApi(requestData)
postEditNewTopicApi(requestData)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}, },
// 更新话题 // 更新话题
async rewriteTopic(): Promise<EditUpdateTopicResponseData> { async rewriteTopic(): Promise<EditUpdateTopicResponseData | undefined> {
const requestData: EditUpdateTopicRequestData = { const requestData: EditUpdateTopicRequestData = {
tid: this.topicRewrite.tid, tid: this.topicRewrite.tid,
title: this.topicRewrite.title, title: this.topicRewrite.title,
@ -82,20 +74,16 @@ export const useKUNGalgameEditStore = defineStore({
tags: this.topicRewrite.tags, tags: this.topicRewrite.tags,
category: this.topicRewrite.category, category: this.topicRewrite.category,
} }
// 检查话题数据不合法直接返回
if (!checkTopicPublish(this.textCount, requestData)) {
return
}
return await updateEditNewTopicApi(requestData) return await updateEditNewTopicApi(requestData)
}, },
// 获取热门 tags // 获取热门 tags
getHotTags(limit: number): Promise<EditGetHotTagsResponseData> { async getHotTags(limit: number): Promise<EditGetHotTagsResponseData> {
return new Promise((resolve, reject) => { const requestData: EditGetHotTagsRequestData = { limit }
const requestData: EditGetHotTagsRequestData = { limit } return await getTopTagsApi(requestData)
getTopTagsApi(requestData)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}, },
// 重置话题草稿数据,用于发布时 // 重置话题草稿数据,用于发布时
resetTopicData() { resetTopicData() {
@ -109,6 +97,7 @@ export const useKUNGalgameEditStore = defineStore({
}, },
// 重置重新发布话题数据,用于重新编辑 // 重置重新发布话题数据,用于重新编辑
resetRewriteTopicData() { resetRewriteTopicData() {
this.textCount = 0
this.topicRewrite.title = '' this.topicRewrite.title = ''
this.topicRewrite.content = '' this.topicRewrite.content = ''
this.topicRewrite.tags = [] this.topicRewrite.tags = []

View file

@ -1,27 +1,12 @@
/* 主页的 store */ /* 主页的 store */
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
// api
import { getHomeTopicApi } from '@/api/index' import { getHomeTopicApi } from '@/api/index'
// 数据接口的类型
import { HomeTopicRequestData, HomeTopicResponseData } from '@/api/index' import { HomeTopicRequestData, HomeTopicResponseData } from '@/api/index'
interface HomeStore { // home store 的类型
keywords: string import { HomeStore } from '../types/home'
category: string
page: number
limit: number
sortField: string
sortOrder: string
// 加载完了是否还需要加载
isLoading: boolean
// 其它的 store
// 是否激活主页的左侧交互面板
isActiveMainPageAside: boolean
// 搜索历史存储
searchHistory: string[]
}
export const useKUNGalgameHomeStore = defineStore({ export const useKUNGalgameHomeStore = defineStore({
id: 'home', id: 'home',
@ -55,7 +40,7 @@ export const useKUNGalgameHomeStore = defineStore({
getters: {}, getters: {},
actions: { actions: {
// 获取首页话题 // 获取首页话题
getHomeTopic(): Promise<HomeTopicResponseData> { async getHomeTopic(): Promise<HomeTopicResponseData> {
// 这里的值用于初始化 // 这里的值用于初始化
const requestData: HomeTopicRequestData = { const requestData: HomeTopicRequestData = {
keywords: this.keywords, keywords: this.keywords,
@ -65,15 +50,7 @@ export const useKUNGalgameHomeStore = defineStore({
sortField: this.sortField, sortField: this.sortField,
sortOrder: this.sortOrder, sortOrder: this.sortOrder,
} }
return new Promise((resolve, reject) => { return await getHomeTopicApi(requestData)
getHomeTopicApi(requestData)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}, },
// 重置页数,是否加载,这样排序才能生效 // 重置页数,是否加载,这样排序才能生效
resetPageStatus() { resetPageStatus() {

View file

@ -14,19 +14,14 @@ import {
sendVerificationCodeMailApi, sendVerificationCodeMailApi,
} from '@/api' } from '@/api'
// 用户信息接口 // kungalgame store 类型
interface UserState { import { KUNGalgamerStore } from '../types/kungalgamer'
uid: number
name: string
avatar: string
moemoeAccessToken: string
}
// 这里用了 pinia-plugin-persistedstate直接存储即可 // 这里用了 pinia-plugin-persistedstate直接存储即可
export const useKUNGalgameUserStore = defineStore({ export const useKUNGalgameUserStore = defineStore({
id: 'kungalgamer', id: 'kungalgamer',
persist: true, persist: true,
state: (): UserState => ({ state: (): KUNGalgamerStore => ({
uid: 0, uid: 0,
name: '', name: '',
avatar: '', avatar: '',
@ -50,56 +45,36 @@ export const useKUNGalgameUserStore = defineStore({
this.moemoeAccessToken = '' this.moemoeAccessToken = ''
}, },
// 登陆 // 登陆
login(request: LoginRequestData): Promise<LoginResponseData> { async login(request: LoginRequestData): Promise<LoginResponseData> {
return new Promise((resolve, reject) => { const res = await postLoginDataApi(request)
// 这里是向后端发请求的函数 if (res.code === 200) {
postLoginDataApi(request) this.setUserInfo(res.data.uid, res.data.name, res.data.avatar)
.then((res) => { this.setToken(res.data.token)
if (res.data) { } else if (res.code === 500) {
this.setUserInfo(res.data.uid, res.data.name, res.data.avatar) console.log(res.message)
this.setToken(res.data.token) } else {
} else throw new Error('500 Server ERROR')
(error: Error) => { }
throw new Error('500 Server ERROR', error) return res
}
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}, },
// 发送验证码 // 发送验证码
sendCode(email: string): Promise<void> { async sendCode(email: string): Promise<void> {
return new Promise((resolve, reject) => { const request: VerificationCodeMailRequestData = { email }
const request: VerificationCodeMailRequestData = { email } return await sendVerificationCodeMailApi(request)
sendVerificationCodeMailApi(request)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}, },
// 注册 // 注册
register(request: RegisterRequestData): Promise<LoginResponseData> { async register(request: RegisterRequestData): Promise<LoginResponseData> {
return new Promise((resolve, reject) => { const res = await postRegisterDataApi(request)
postRegisterDataApi(request)
.then((res) => { if (res.code === 200) {
if (res.data) { this.setUserInfo(res.data.uid, res.data.name, res.data.avatar)
this.setUserInfo(res.data.uid, res.data.name, res.data.avatar) this.setToken(res.data.token)
this.setToken(res.data.token) } else if (res.code === 500) {
} else console.log(res.message)
(error: Error) => { } else {
throw new Error('500 Server ERROR', error) throw new Error('500 Server ERROR')
} }
resolve(res) return res
})
.catch((error) => {
reject(error)
})
})
}, },
}, },
}) })

View file

@ -1,31 +1,13 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
interface Message { // message store 的类型
// 是否展示通知消息 import { MessageStore } from '../types/message'
showInfo: boolean
// 是否展示警告消息
showAlert: boolean
// 通知消息的内容
infoMsg: string
// 警告消息的内容
alertMsg: string
// 是否展示取消按钮Alert 组件专用
isShowCancel: boolean
// 返回确认信息Alert 组件专用
confirm: boolean
// 人机验证组件
// 是否显示人机验证
isShowCapture: boolean
// 是否验证通过
isCaptureSuccessful: boolean
}
export const useKUNGalgameMessageStore = defineStore({ export const useKUNGalgameMessageStore = defineStore({
id: 'message', id: 'message',
// 所有消息组件均不需要持久存储 // 所有消息组件均不需要持久存储
persist: false, persist: false,
state: (): Message => ({ state: (): MessageStore => ({
showInfo: false, showInfo: false,
showAlert: false, showAlert: false,
infoMsg: '', infoMsg: '',

View file

@ -4,30 +4,14 @@ import { defineStore } from 'pinia'
// 网站的默认设置 // 网站的默认设置
import { KUNGalgameLanguage, mode } from '@/utils/getDefaultEnv' import { KUNGalgameLanguage, mode } from '@/utils/getDefaultEnv'
// 设置面板配置 // settings store 的类型
interface KUNGalgameSettings { import { KUNGalgameSettingsStore } from '../types/settings'
// 白天黑夜模式切换
showKUNGalgameMode: string
// 网站显示语言
showKUNGalgameLanguage: string
// 主页宽度
showKUNGalgamePageWidth: Record<string, number>
// 网站字体
showKUNGalgameFontStyle: string
// 背景图
showKUNGalgameBackground: string
// 自定义背景图
showKUNGalgameCustomBackground: string
// 显示页面宽度还是显示字体设置
isShowPageWidth: boolean
}
export const useKUNGalgameSettingsStore = defineStore({ export const useKUNGalgameSettingsStore = defineStore({
id: 'KUNGalgame-settings', id: 'KUNGalgame-settings',
persist: true, persist: true,
// 默认值 // 默认值
state: (): KUNGalgameSettings => ({ state: (): KUNGalgameSettingsStore => ({
showKUNGalgameMode: mode, showKUNGalgameMode: mode,
showKUNGalgameLanguage: KUNGalgameLanguage, showKUNGalgameLanguage: KUNGalgameLanguage,
showKUNGalgamePageWidth: { showKUNGalgamePageWidth: {

View file

@ -28,91 +28,13 @@ import {
TopicCreateCommentResponseData, TopicCreateCommentResponseData,
} from '@/api' } from '@/api'
// 回复的缓存 // 导入 topic store 的类型
interface ReplyDraft { import { TopicStore } from '../types/topic'
/**
*
* @param {number} editorHeight -
* @param {'' | 'essential' | 'minimal' | 'full'} mode - toolbar
* @param {'snow' | 'bubble'} theme -
*/
editorHeight: number
textCount: number
// 这里仅支持三种模式
mode: '' | 'essential' | 'minimal'
theme: 'snow' | 'bubble'
// 是否显示热门关键词
isShowHotKeywords: boolean
// 当前话题的 id
tid: number
r_uid: number
// 回复给谁,用于回复面板展示
replyUserName: string
to_uid: number
content: string
tags: string[]
// 被回复的人的楼层数,用于跳转
to_floor: number
// 是否保存回复
isSaveReply: boolean
// 回复发布的状态,如果状态有变化则将发布好的回复数据添加在回复数组里
// 这里与 true 和 false 无关,关心的是它的状态改变
publishStatus: boolean
}
// 获取回复的请求
interface ReplyRequest {
page: number
limit: number
sortField: string
sortOrder: 'asc' | 'desc'
}
// 评论的缓存
interface CommentDraft {
// 评论的内容
tid: number
rid: number
c_uid: number
to_uid: number
content: string
// 显示哪个评论的评论面板
isShowCommentPanelRid: number
}
// 话题页面的 store
interface Topic {
// 是否正在被编辑
isEdit: boolean
// 是否显示高级编辑模式
isShowAdvance: boolean
// 是否激活左侧交互面板
isActiveAside: boolean
// 是否滚动到顶部
isScrollToTop: boolean
// 加载完了是否还需要加载
isLoading: boolean
// 要滚动到的回复 id
scrollToReplyId: number
// 回复面板的宽度
replyPanelWidth: number
// 回复的缓存
replyDraft: ReplyDraft
// 获取回复的请求接口格式
replyRequest: ReplyRequest
// 评论的缓存
commentDraft: CommentDraft
}
export const useKUNGalgameTopicStore = defineStore({ export const useKUNGalgameTopicStore = defineStore({
id: 'topic', id: 'topic',
persist: true, persist: true,
state: (): Topic => ({ state: (): TopicStore => ({
isEdit: false, isEdit: false,
isShowAdvance: false, isShowAdvance: false,
isActiveAside: false, isActiveAside: false,
@ -158,115 +80,66 @@ export const useKUNGalgameTopicStore = defineStore({
}), }),
actions: { actions: {
// 左侧相同标签下的其它话题 // 左侧相同标签下的其它话题
getRelatedTopicsByTags( async getRelatedTopicsByTags(
request: TopicAsideOtherTagRequestData request: TopicAsideOtherTagRequestData
): Promise<TopicAsideResponseData> { ): Promise<TopicAsideResponseData> {
return new Promise((resolve, reject) => { return await getRelatedTopicsByTagsApi(request)
getRelatedTopicsByTagsApi(request)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}, },
// 楼主的其它话题 // 楼主的其它话题
getPopularTopicsByUserUid( async getPopularTopicsByUserUid(
request: TopicAsideMasterRequestData request: TopicAsideMasterRequestData
): Promise<TopicAsideResponseData> { ): Promise<TopicAsideResponseData> {
return new Promise((resolve, reject) => { return await getPopularTopicsByUserUidApi(request)
getPopularTopicsByUserUidApi(request)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}, },
// 获取单个话题 // 获取单个话题
getTopicByTid(tid: number): Promise<TopicDetailResponseData> { async getTopicByTid(tid: number): Promise<TopicDetailResponseData> {
return new Promise((resolve, reject) => { return await getTopicByTidApi(tid)
getTopicByTidApi(tid)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}, },
// 获取回复 // 获取回复
getReplies(tid: number): Promise<TopicReplyResponseData> { async getReplies(tid: number): Promise<TopicReplyResponseData> {
return new Promise((resolve, reject) => { // 这里的默认值用于初始化
// 这里的默认值用于初始化 const requestData: TopicReplyRequestData = {
const requestData: TopicReplyRequestData = { tid: tid,
tid: tid, page: this.replyRequest.page,
page: this.replyRequest.page, limit: this.replyRequest.limit,
limit: this.replyRequest.limit, sortField: this.replyRequest.sortField || 'floor',
sortField: this.replyRequest.sortField || 'floor', sortOrder: this.replyRequest.sortOrder || 'desc',
sortOrder: this.replyRequest.sortOrder || 'desc', }
} return await getRepliesByPidApi(requestData)
getRepliesByPidApi(requestData)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}, },
// 创建回复 // 创建回复
postNewReply(): Promise<TopicCreateReplyResponseData> { async postNewReply(): Promise<TopicCreateReplyResponseData> {
return new Promise((resolve, reject) => { // 这里的值用于初始化回复
// 这里的值用于初始化回复 const requestData: TopicCreateReplyRequestData = {
const requestData: TopicCreateReplyRequestData = { tid: this.replyDraft.tid,
tid: this.replyDraft.tid, to_uid: this.replyDraft.to_uid,
to_uid: this.replyDraft.to_uid, to_floor: this.replyDraft.to_floor,
to_floor: this.replyDraft.to_floor, tags: this.replyDraft.tags,
tags: this.replyDraft.tags, content: this.replyDraft.content,
content: this.replyDraft.content, }
} return await postReplyByPidApi(requestData)
postReplyByPidApi(requestData)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}, },
// 获取评论 // 获取评论
getComments(rid: number): Promise<TopicCommentResponseData> { async getComments(rid: number): Promise<TopicCommentResponseData> {
return new Promise((resolve, reject) => { return await getCommentsByReplyRidApi(rid)
getCommentsByReplyRidApi(rid)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}, },
// 创建一个评论 // 创建一个评论
postNewComment(): Promise<TopicCreateCommentResponseData> { async postNewComment(): Promise<TopicCreateCommentResponseData> {
return new Promise((resolve, reject) => { const requestData: TopicCreateCommentRequestData = {
const requestData: TopicCreateCommentRequestData = { tid: this.commentDraft.tid,
tid: this.commentDraft.tid, rid: this.commentDraft.rid,
rid: this.commentDraft.rid, to_uid: this.commentDraft.to_uid,
to_uid: this.commentDraft.to_uid, content: this.commentDraft.content,
content: this.commentDraft.content, }
} return await postCommentByPidAndRidApi(requestData)
postCommentByPidAndRidApi(requestData)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}, },
// 设置回复草稿为原始值,用于回复发布按钮 // 设置回复草稿为原始值,用于回复发布按钮
resetReplyDraft() { resetReplyDraft() {
this.replyDraft.textCount = 0 this.replyDraft.textCount = 0

View file

@ -15,7 +15,7 @@ interface TopicRewrite {
isTopicRewriting: boolean isTopicRewriting: boolean
} }
export interface Topic { export interface EditStore {
/** /**
* *
* @param {number} editorHeight - * @param {number} editorHeight -

17
src/store/types/home.d.ts vendored Normal file
View file

@ -0,0 +1,17 @@
export interface HomeStore {
keywords: string
category: string
page: number
limit: number
sortField: string
sortOrder: string
// 加载完了是否还需要加载
isLoading: boolean
// 其它的 store
// 是否激活主页的左侧交互面板
isActiveMainPageAside: boolean
// 搜索历史存储
searchHistory: string[]
}

7
src/store/types/kungalgamer.d.ts vendored Normal file
View file

@ -0,0 +1,7 @@
// 用户信息接口
export interface KUNGalgamerStore {
uid: number
name: string
avatar: string
moemoeAccessToken: string
}

20
src/store/types/message.d.ts vendored Normal file
View file

@ -0,0 +1,20 @@
export interface MessageStore {
// 是否展示通知消息
showInfo: boolean
// 是否展示警告消息
showAlert: boolean
// 通知消息的内容
infoMsg: string
// 警告消息的内容
alertMsg: string
// 是否展示取消按钮Alert 组件专用
isShowCancel: boolean
// 返回确认信息Alert 组件专用
confirm: boolean
// 人机验证组件
// 是否显示人机验证
isShowCapture: boolean
// 是否验证通过
isCaptureSuccessful: boolean
}

18
src/store/types/settings.d.ts vendored Normal file
View file

@ -0,0 +1,18 @@
// 设置面板配置
export interface KUNGalgameSettingsStore {
// 白天黑夜模式切换
showKUNGalgameMode: string
// 网站显示语言
showKUNGalgameLanguage: string
// 主页宽度
showKUNGalgamePageWidth: Record<string, number>
// 网站字体
showKUNGalgameFontStyle: string
// 背景图
showKUNGalgameBackground: string
// 自定义背景图
showKUNGalgameCustomBackground: string
// 显示页面宽度还是显示字体设置
isShowPageWidth: boolean
}

80
src/store/types/topic.d.ts vendored Normal file
View file

@ -0,0 +1,80 @@
// 回复的缓存
interface ReplyDraft {
/**
*
* @param {number} editorHeight -
* @param {'' | 'essential' | 'minimal' | 'full'} mode - toolbar
* @param {'snow' | 'bubble'} theme -
*/
editorHeight: number
textCount: number
// 这里仅支持三种模式
mode: '' | 'essential' | 'minimal'
theme: 'snow' | 'bubble'
// 是否显示热门关键词
isShowHotKeywords: boolean
// 当前话题的 id
tid: number
r_uid: number
// 回复给谁,用于回复面板展示
replyUserName: string
to_uid: number
content: string
tags: string[]
// 被回复的人的楼层数,用于跳转
to_floor: number
// 是否保存回复
isSaveReply: boolean
// 回复发布的状态,如果状态有变化则将发布好的回复数据添加在回复数组里
// 这里与 true 和 false 无关,关心的是它的状态改变
publishStatus: boolean
}
// 获取回复的请求
interface ReplyRequest {
page: number
limit: number
sortField: string
sortOrder: 'asc' | 'desc'
}
// 评论的缓存
interface CommentDraft {
// 评论的内容
tid: number
rid: number
c_uid: number
to_uid: number
content: string
// 显示哪个评论的评论面板
isShowCommentPanelRid: number
}
// 话题页面的 store
export interface TopicStore {
// 是否正在被编辑
isEdit: boolean
// 是否显示高级编辑模式
isShowAdvance: boolean
// 是否激活左侧交互面板
isActiveAside: boolean
// 是否滚动到顶部
isScrollToTop: boolean
// 加载完了是否还需要加载
isLoading: boolean
// 要滚动到的回复 id
scrollToReplyId: number
// 回复面板的宽度
replyPanelWidth: number
// 回复的缓存
replyDraft: ReplyDraft
// 获取回复的请求接口格式
replyRequest: ReplyRequest
// 评论的缓存
commentDraft: CommentDraft
}

View file

@ -1,15 +1,24 @@
// api 请求格式 // api 请求格式
import { EditCreateTopicRequestData } from '@/api' import { EditCreateTopicRequestData, EditUpdateTopicRequestData } from '@/api'
// 全局消息组件(顶部) // 全局消息组件(顶部)
import message from '@/components/alert/Message' import message from '@/components/alert/Message'
// 类型守卫,确定 EditUpdateTopicRequestData 含有 tid
const isEditUpdateTopicData = (data: any): data is EditUpdateTopicRequestData =>
typeof data.tid !== 'undefined'
// 发布时检测用户输入是否合法 // 发布时检测用户输入是否合法
export const checkTopicPublish = ( export const checkTopicPublish = (
textCount: number, textCount: number,
topicData: EditCreateTopicRequestData topicData: EditCreateTopicRequestData | EditUpdateTopicRequestData
) => { ) => {
if (!topicData.title.trim()) { if (isEditUpdateTopicData(topicData)) {
// 话题 id 为零,应该。。。。不存在吧(
if (!topicData.tid) {
message('Failed to resolve topic', '未能解析话题 ID', 'error')
}
} else if (!topicData.title.trim()) {
// 标题为空的话,警告 // 标题为空的话,警告
message('Title cannot be empty!', '标题不可为空!', 'warn') message('Title cannot be empty!', '标题不可为空!', 'warn')
return false return false

View file

@ -28,3 +28,9 @@ button,
select { select {
font-family: inherit; font-family: inherit;
} }
/* 鼠标选中文字的颜色 */
*::selection {
background-color: var(--kungalgame-blue-1); /* 选中文本的背景颜色 */
color: var(--kungalgame-blue-4); /* 选中文本的文本颜色 */
}