kun-galgame-vue/src/views/edit/Edit.vue

354 lines
8.6 KiB
Vue
Raw Normal View History

2023-05-01 15:58:54 +00:00
<script setup lang="ts">
2023-05-02 15:22:46 +00:00
import '@wangeditor/editor/dist/css/style.css' // 引入 css
2023-05-01 15:58:54 +00:00
2023-05-02 15:22:46 +00:00
import { onBeforeUnmount, ref, shallowRef, onMounted } from 'vue'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
2023-05-01 15:58:54 +00:00
// 编辑器实例,必须用 shallowRef
2023-05-02 15:22:46 +00:00
const editorRef = shallowRef()
2023-05-01 15:58:54 +00:00
2023-05-01 17:01:00 +00:00
// 编辑器的模式
2023-05-02 15:22:46 +00:00
const mode = 'default'
2023-05-01 17:01:00 +00:00
2023-05-01 15:58:54 +00:00
// 内容 HTML
2023-05-02 15:22:46 +00:00
const valueHtml = ref('<p>hello</p>')
2023-05-01 15:58:54 +00:00
// 模拟 ajax 异步获取内容
onMounted(() => {
setTimeout(() => {
2023-05-02 15:22:46 +00:00
valueHtml.value = '<p>模拟 Ajax 异步设置内容</p>'
}, 1500)
})
2023-05-01 15:58:54 +00:00
2023-05-02 15:22:46 +00:00
const toolbarConfig = {}
const editorConfig = { placeholder: '请输入内容...' }
2023-05-01 15:58:54 +00:00
// 组件销毁时,也及时销毁编辑器
onBeforeUnmount(() => {
2023-05-02 15:22:46 +00:00
const editor = editorRef.value
if (editor == null) return
editor.destroy()
})
2023-05-01 15:58:54 +00:00
2023-05-01 17:01:00 +00:00
// TODO:
const handleCreated = (editor: any) => {
2023-05-02 15:22:46 +00:00
editorRef.value = editor // 记录 editor 实例,重要!
}
2023-05-01 15:58:54 +00:00
</script>
<template>
<div class="root">
<!-- 头部 -->
<div class="header">
<!-- 顶部左侧交互栏 -->
<div class="nav-top">
<div class="kungal-info">
<img src="../img/favicon.png" alt="KUNgal" />
<span>KUNGalgame</span>
</div>
<div class="top-bar">
<ul>
<li>所有帖子</li>
<li>发布帖子</li>
<li>技术交流</li>
<li>数据统计</li>
<div class="top-bar-box"></div>
</ul>
</div>
</div>
<div class="kungalgamer-info">
<img src="../img/KUN.jpg" alt="KUN" />
<span>KUN</span>
</div>
</div>
<!-- 内容区容器 -->
<div class="container">
<!-- 内容区容器 -->
<div class="content-wrapper">
<!-- 内容区的头部 -->
<div class="content-header">
<!-- 帖子的标题 -->
<div class="topic-title">
<input type="text" placeholder="请输入帖子的标题40字以内" />
</div>
</div>
<!-- 编辑器 -->
<div style="border: 1px solid #ccc">
<Toolbar
style="border-bottom: 1px solid #ccc"
:editor="editorRef"
:defaultConfig="toolbarConfig"
:mode="mode"
/>
<Editor
style="height: 500px; overflow-y: hidden"
v-model="valueHtml"
:defaultConfig="editorConfig"
:mode="mode"
@onCreated="handleCreated"
/>
</div>
</div>
<!-- 内容区的底部 -->
<div class="content-footer">
<!-- 标签的总容器 -->
<div class="tags-container">
<!-- 标签输入框 -->
<input
type="text"
placeholder="请输入帖子的关键词(至少选择一个、最多 7 个), 输入文字按下 ' Enter ' 创建关键词"
/>
<!-- 标签容器 -->
<div class="tags">
<!-- 标签的提示词 -->
<div class="tags-info">热门关键词点击选择:</div>
<span>啊这可海星</span>
<span>啊这可海星</span>
<span>啊这可海星</span>
<span>啊这可海星</span>
<span>啊这可海星</span>
<span>啊这可海星</span>
<span>啊这可海星</span>
<span>啊这可海星</span>
<span>啊这可海星</span>
<span>啊这可海星</span>
</div>
</div>
<!-- 话题分类的容器 -->
<div class="topic-group">
<div>点击选择帖子的分区可多选:</div>
<!-- 分类容器的按钮集合 -->
<div class="group-btn">
<button>galgame</button>
<button>技术交流</button>
<button>其它</button>
</div>
</div>
<!-- 按钮的容器 -->
<div class="btn-container">
<!-- 确认按钮 -->
<button class="confirm-btn">确认发布</button>
<!-- 保存按钮 -->
<button class="save-btn">保存草稿</button>
</div>
</div>
</div>
<!-- 版权 -->
<div class="copyright">
<span>Copyright © 2023 KUNgalgame</span>
<span>All rights reserved | Version 0.01</span>
</div>
</div>
</template>
2023-05-02 15:22:46 +00:00
<style lang="less" scoped>
2023-05-01 15:58:54 +00:00
* {
list-style: none;
padding: 0;
margin: 0;
text-decoration: none;
}
input:focus {
outline: none;
}
body::-webkit-scrollbar {
display: none;
}
.content-wrapper {
margin: 0 auto;
}
.root {
height: 100vh;
min-height: 1000px;
min-width: 800px;
display: flex;
flex-direction: column;
background-image: url(../img/bg/bg1.png);
background-repeat: no-repeat;
background-position: center;
background-attachment: fixed;
background-size: cover;
}
/* 编辑器的样式 */
#editorwrapper {
/* 编辑器的 border */
2023-05-02 15:22:46 +00:00
border: 1px solid @kungalgame-blue-4;
2023-05-01 15:58:54 +00:00
box-sizing: border-box;
/* 编辑器的宽度 */
width: 75vw;
margin: 0 auto;
z-index: 100; /* 按需定义 */
}
#toolbar-container {
2023-05-02 15:22:46 +00:00
border-bottom: 1px solid @kungalgame-blue-4;
2023-05-01 15:58:54 +00:00
}
/* 编辑器编辑部分 */
#editor-container {
height: 427px;
}
/* 内容部分的总容器 */
.container {
width: 77vw;
margin: auto;
/* 距离顶部 header 的距离 */
margin-top: 7px;
/* 容器的阴影 */
2023-05-02 15:22:46 +00:00
box-shadow: @shadow;
background-color: @kungalgame-trans-white-2;
color: @kungalgame-font-color-3;
2023-05-01 15:58:54 +00:00
}
/* 容器的顶部 */
.content-header {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
/* 顶部的固定高度 */
height: 90px;
}
/* 帖子的发布标题 */
.topic-title {
width: 75vw;
}
/* 帖子标题的输入框 */
.topic-title input {
2023-05-02 15:22:46 +00:00
color: @kungalgame-font-color-2;
2023-05-01 15:58:54 +00:00
/* 距离外轮廓的距离 */
padding: 7px;
/* 内边距盒子 */
box-sizing: border-box;
width: 100%;
/* 标题输入字体大小 */
font-size: 40px;
2023-05-02 15:22:46 +00:00
border: 1px solid @kungalgame-blue-4;
background-color: @kungalgame-trans-white-9;
2023-05-01 15:58:54 +00:00
}
/* 标题输入框 focus 之后的样式 */
.topic-title input:focus {
2023-05-02 15:22:46 +00:00
box-shadow: 0px 0px 5px @kungalgame-blue-4;
2023-05-01 15:58:54 +00:00
}
/* 内容区的底部样式 */
.content-footer {
/* 固定高度 */
height: 250px;
/* 距离内容区的距离 */
margin-top: 17px;
padding: 0 1vw;
display: flex;
flex-direction: column;
}
/* 标签的总容器 */
.tags-container {
flex-grow: 1;
}
/* 标签输入框 */
.tags-container input {
2023-05-02 15:22:46 +00:00
background-color: @kungalgame-trans-white-9;
2023-05-01 15:58:54 +00:00
/* 输入标签的字体 */
font-size: 17px;
width: 100%;
box-sizing: border-box;
2023-05-02 15:22:46 +00:00
border: 1px solid @kungalgame-blue-4;
2023-05-01 15:58:54 +00:00
padding: 5px;
}
/* 标签输入框 focus */
.tags-container input:focus {
2023-05-02 15:22:46 +00:00
box-shadow: 0px 0px 3px @kungalgame-blue-4;
2023-05-01 15:58:54 +00:00
}
/* 单个标签容器 */
.tags {
margin-top: 17px;
}
/* 标签的提示词 */
.tags div {
margin-bottom: 7px;
}
/* 单个标签的样式 */
.tags > span {
font-size: 14px;
padding: 3px;
2023-05-02 15:22:46 +00:00
background-color: @kungalgame-trans-blue-1;
2023-05-01 15:58:54 +00:00
cursor: pointer;
}
.tags > span:hover {
2023-05-02 15:22:46 +00:00
background-color: @kungalgame-trans-red-1;
2023-05-01 15:58:54 +00:00
}
/* 话题分类的容器 */
.topic-group {
/* 相对于标签容器的占比 */
flex-grow: 1;
}
/* 分类容器的按钮集合 */
.group-btn {
height: 100%;
display: flex;
justify-content: space-between;
margin-top: 10px;
}
/* 单个按钮的样式 */
.group-btn > button {
height: 30px;
width: 20%;
font-size: 17px;
cursor: pointer;
2023-05-02 15:22:46 +00:00
border: 1px solid @kungalgame-purple-4;
background-color: @kungalgame-trans-purple-1;
color: @kungalgame-purple-4;
2023-05-01 15:58:54 +00:00
}
/* 按钮的容器 */
.btn-container {
flex-grow: 1;
display: flex;
justify-content: space-between;
align-items: center;
/* 距离最底端的距离 */
margin-bottom: 10px;
}
/* 单个按钮的样式 */
.btn-container button {
height: 40px;
width: 27%;
font-size: 20px;
white-space: nowrap;
overflow: hidden;
cursor: pointer;
}
/* 确认按钮的样式 */
.confirm-btn {
2023-05-02 15:22:46 +00:00
color: @kungalgame-blue-4;
background-color: @kungalgame-trans-blue-1;
border: 1px solid @kungalgame-blue-4;
2023-05-01 15:58:54 +00:00
}
.confirm-btn:hover {
2023-05-02 15:22:46 +00:00
color: @kungalgame-trans-white-1;
background-color: @kungalgame-blue-4;
2023-05-01 15:58:54 +00:00
transition: 0.1s;
}
.confirm-btn:active {
2023-05-02 15:22:46 +00:00
background-color: @kungalgame-red-4;
border: 1px solid @kungalgame-red-4;
2023-05-01 15:58:54 +00:00
font-size: 17px;
}
/* 保存按钮的样式 */
.save-btn {
2023-05-02 15:22:46 +00:00
color: @kungalgame-orange-4;
background-color: @kungalgame-trans-orange-1;
border: 1px solid @kungalgame-orange-4;
2023-05-01 15:58:54 +00:00
}
.save-btn:hover {
2023-05-02 15:22:46 +00:00
color: @kungalgame-trans-white-1;
background-color: @kungalgame-orange-4;
2023-05-01 15:58:54 +00:00
transition: 0.1s;
}
.save-btn:active {
2023-05-02 15:22:46 +00:00
background-color: @kungalgame-trans-orange-1;
color: @kungalgame-orange-4;
2023-05-01 15:58:54 +00:00
}
/* 版权 */
.copyright {
margin: 0 auto;
margin-bottom: 17px;
}
</style>