This commit is contained in:
@zuopngfei 2025-05-21 15:30:26 +08:00
parent 2def4b3546
commit f2329bec77
10 changed files with 144 additions and 1016 deletions

View File

@ -1,5 +1,5 @@
# 变量必须以 VITE_ 为前缀才能暴露给外部读取
NODE_ENV = 'development'
VITE_APP_BASE_API = 'https://tools.1024tool.vip/'
VITE_SERVE = "https://tools.1024tool.vip/"
VITE_APP_BASE_API = 'https://ddbs.1024tool.vip/'
VITE_SERVE = "https://ddbs.1024tool.vip/"
# VITE_SERVE = "http://192.168.210.29:18100/"

View File

@ -25,6 +25,7 @@
"element-plus": "^2.8.0",
"mitt": "^3.0.1",
"moment": "^2.29.4",
"js-md5": "^0.8.3",
"nprogress": "^0.2.0",
"pinia": "^2.1.6",
"pinia-plugin-persistedstate": "^3.2.0",

View File

@ -57,7 +57,7 @@ const cachedComponents = computed(() =>
.el-main {
height: 100%;
background-color: #fff;
min-width: 1250px;
// min-width: 1250px;
padding: 20px;
overflow: hidden;
}

View File

@ -5,10 +5,10 @@
// --my-shadow: 0 1px 3px 0 rgba(0, 0, 0, .1);
// --my-shadow-large: 0px 0px 3px 5px var(--el-border-color);
// --my-shadow-small: 0px 0px 0px 1px var(--el-border-color);
--my-border-radius: 8px;
--my-border-radius-large: 16px;
--my-border-radius-small: 4px;
--el-fill-color-blank: rgba(240, 245, 245, 1) !important;
// --my-border-radius: 8px;
// --my-border-radius-large: 16px;
// --my-border-radius-small: 4px;
// --el-fill-color-blank: rgba(240, 245, 245, 1) !important;
}
//滚动条外观设置
@ -23,89 +23,89 @@
border-radius: 10px;
}
.el-popover.el-popper {
border-radius: var(--my-border-radius) !important;
}
// .el-popover.el-popper {
// border-radius: var(--my-border-radius) !important;
// }
.el-popper__arrow {
display: none;
}
// .el-popper__arrow {
// display: none;
// }
.el-popper.is-light {
border: 0;
}
// .el-popper.is-light {
// border: 0;
// }
.pagination-box {
// overflow: hidden;
margin-top: 25px;
text-align: right;
height: 30px;
// .pagination-box {
// // overflow: hidden;
// margin-top: 25px;
// text-align: right;
// height: 30px;
.el-pagination {
float: right;
}
}
.el-table {
--el-table-header-text-color: var(--el-color-primary) !important;
--el-table-bg-color: var(--el-bg-color) !important;
}
// .el-pagination {
// float: right;
// }
// }
// .el-table {
// --el-table-header-text-color: var(--el-color-primary) !important;
// --el-table-bg-color: var(--el-bg-color) !important;
// }
.el-input {
--el-select-input-focus-border-color: none !important;
--el-input-bg-color: rgba(240, 245, 245, 1) !important;
--el-input-focus-border-color: none;
--el-input-border-color: none !important;
}
// .el-input {
// --el-select-input-focus-border-color: none !important;
// --el-input-bg-color: rgba(240, 245, 245, 1) !important;
// --el-input-focus-border-color: none;
// --el-input-border-color: none !important;
// }
.el-input__wrapper.is-focus,
.el-select__wrapper.is-focused,
.el-select__wrapper {
box-shadow: none !important;
}
// .el-input__wrapper.is-focus,
// .el-select__wrapper.is-focused,
// .el-select__wrapper {
// box-shadow: none !important;
// }
.el-textarea,
.el-date-editor,
.el-cascader {
--el-input-focus-border-color: none !important;
--el-input-bg-color: rgba(240, 245, 245, 1) !important;
--el-input-border-color: none !important;
}
// .el-textarea,
// .el-date-editor,
// .el-cascader {
// --el-input-focus-border-color: none !important;
// --el-input-bg-color: rgba(240, 245, 245, 1) !important;
// --el-input-border-color: none !important;
// }
.el-input__wrapper:hover,
.el-textarea__inner:hover,
.el-input-group__append:hover,
.el-input-group__prepend:hover {
box-shadow: none !important;
// .el-input__wrapper:hover,
// .el-textarea__inner:hover,
// .el-input-group__append:hover,
// .el-input-group__prepend:hover {
// box-shadow: none !important;
}
// }
.el-input__wrapper.is-focus,
.el-textarea__inner:focus,
.el-date-editor.is-active {
box-shadow: none !important;
// .el-input__wrapper.is-focus,
// .el-textarea__inner:focus,
// .el-date-editor.is-active {
// box-shadow: none !important;
}
// }
.el-input-group__append,
.el-input-group__prepend {
background: var(--el-input-bg-color) !important;
box-shadow: none !important;
padding: 0 10px !important;
}
// .el-input-group__append,
// .el-input-group__prepend {
// background: var(--el-input-bg-color) !important;
// box-shadow: none !important;
// padding: 0 10px !important;
// }
.el-textarea,
.el-date-editor,
.el-cascader {
--el-input-focus-border-color: none !important;
--el-input-border-color: none !important;
}
// .el-textarea,
// .el-date-editor,
// .el-cascader {
// --el-input-focus-border-color: none !important;
// --el-input-border-color: none !important;
// }
.el-radio{
--el-radio-input-bg-color: #fff!important;
}
// .el-radio{
// --el-radio-input-bg-color: #fff!important;
// }
.el-descriptions__body {
background-color: #fff!important;
}
// .el-descriptions__body {
// background-color: #fff!important;
// }

View File

@ -1,769 +0,0 @@
<template>
<div class="container">
<div class="ai-box">
<div class="editor-box">
<div class="toolbar-box">
<Toolbar style="" :editor="editorRef" :defaultConfig="toolbarConfig" :mode="mode" />
</div>
<div class="title-box">
<input type="text" v-model="newTitle" class="title-input" placeholder="请输入文章标题" />
</div>
<Editor class="editor" style="height: calc(100% - 190px); overflow-y: hidden;" v-model="valueHtml"
:defaultConfig="editorConfig" :mode="mode" @onCreated="handleCreated" />
<!-- 添加字数统计显示 -->
<div class="editor-btn-box">
<div class="character-count">
字数: {{ characterCount }}
</div>
<el-button type="primary" @click="handleSaveArticle(1)">保存</el-button>
<el-button type="primary" @click="handleSaveArticle(2)">存草稿</el-button>
<el-button type="primary" @click="handlePreviewArticle">预览</el-button>
</div>
</div>
</div>
<el-dialog v-model="dialogPreview" title="文章预览" width="1000px">
<div class="dialog-preview" style="padding: 20px;">
<div class="preview-title">{{ newTitle }}</div>
<div class="preview-content" v-html="valueHtml">
</div>
</div>
<template #footer>
<el-button type="primary" @click="dialogPreview = false">关闭</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup>
import '@wangeditor/editor/dist/css/style.css' // css
import { Loading } from '@element-plus/icons-vue'
import { onBeforeUnmount, onUnmounted , ref, reactive, shallowRef, onMounted, computed, getCurrentInstance, nextTick } from 'vue'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import { title, inspiration, configList, writeOutline, models, generateArticle, analysisStyle, saveStyle, saveArticle, editArticle, customerTool } from '@/api/AICreation'
import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter()
const generating = ref(1)
// shallowRef
const editorRef = shallowRef()
// HTML
const valueHtml = ref('')
const mode = ref('default')
//
const valueText = ref('')
//
const characterCount = ref(0)
const toolbarConfig = {}
const editorConfig = {
placeholder: '请输入内容...',
MENU_CONF: {}, // Initialize MENU_CONF as an empty object
}
editorConfig.MENU_CONF['uploadImage'] = {
//
server: import.meta.env.VITE_API_BASE_URL + '/api/upload', // 使APIURL
// 10M
maxFileSize: 5 * 1024 * 1024, // 5M
//
allowedFileTypes: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
//
meta: {
token: localStorage.getItem('token') || ''
},
// http
headers: {
Authorization: 'Bearer ' + (localStorage.getItem('token') || '')
},
//
onBeforeUpload(file) {
console.log('准备上传图片', file)
return file // file
},
//
onSuccess(file, res) {
console.log('图片上传成功', file, res)
},
//
onError(file, err, res) {
console.log('图片上传失败', file, err, res)
//
ElNotification.error('图片上传失败,请重试')
},
//
customInsert(res, insertFn) {
// res
if (res.code === 200 && res.data) {
// URL
const url = res.data.url || res.data
//
insertFn(url)
} else {
ElNotification.error('图片插入失败')
}
}
}
editorConfig.MENU_CONF['uploadVideo'] = {
server: import.meta.env.VITE_API_BASE_URL + '/api/upload', // 使APIURL
maxFileSize: 5 * 1024 * 1024, // 5M
onBeforeUpload: (file) => {
console.log('准备上传视频', file)
return file // file
},
onSuccess: (file, res) => {
console.log('视频上传成功', file, res)
},
onError: (file, err, res) => {
console.log('视频上传失败', file, err, res)
ElNotification.error('视频上传失败,请重试')
},
}
//
onBeforeUnmount(() => {
const editor = editorRef.value
if (editor == null) return
editor.destroy()
})
const handleCreated = (editor) => {
editorRef.value = editor // editor
if (route.query.id) {
editor.setHtml(sessionStorage.getItem('works'))
// valueHtml.value = sessionStorage.getItem('works')
}
//
editor.on('change', (e) => {
//
valueText.value = editor.getText()
//
characterCount.value = valueText.value.length
})
}
const newTitle = ref('')
onMounted(() => {
})
// Auto-resize directive
const vAutoResize = {
mounted: (el) => {
const resize = () => {
el.style.height = 'auto'
el.style.height = `${el.scrollHeight}px`
}
// Initial resize
resize()
// Add event listeners
el.addEventListener('input', resize)
window.addEventListener('resize', resize)
// Cleanup
onBeforeUnmount(() => {
el.removeEventListener('input', resize)
window.removeEventListener('resize', resize)
})
}
}
// Register directive
const app = getCurrentInstance()
app.appContext.app.directive('auto-resize', vAutoResize)
</script>
<style lang="scss" scoped>
.container {
width: 100%;
height: 100%;
.toolbar-box{
height: 80px;
}
:deep(.el-radio__label) {
white-space: normal;
}
.title-input {
width: 100%;
height: 50px;
border: none;
// margin: 20px 0;
font-size: 20px;
}
.ai-box {
width: 100%;
height: 100%;
display: flex;
.editor-box {
height: 100%;
flex: 1;
padding-right: 60px;
position: relative;
&::after {
content: '';
width: 1px;
height: 100%;
background-color: var(--el-border-color);
position: absolute;
right: 30px;
top: 0;
}
.editor {
height: calc(100% - 300px);
}
.editor-btn-box {
width: 100%;
text-align: center;
margin-top: 15px;
position: relative;
}
.character-count {
position: absolute;
right: 0;
bottom: 15px;
text-align: right;
color: #909399;
font-size: 12px;
margin-top: 5px;
padding-right: 10px;
}
.title-box {
display: flex;
border-bottom: 1px solid var(--el-border-color);
margin-bottom: 10px;
.title-input {
flex: 1;
}
.title-btn {
flex: none;
width: 100px;
}
}
}
.active-box {
width: 350px;
flex: none;
overflow: hidden;
.el-scrollbar {
overflow-x: hidden;
}
}
}
.tab-item {
margin-top: 10px;
margin-bottom: 15px;
.tab-item-label {
margin-top: 15px;
font-size: 14px;
margin-bottom: 15px;
}
}
.tab-item-btn {
// margin-top: 15px;
}
.tab-item-radio-box {
padding: 20px;
border-radius: 4px;
background-color: var(--el-fill-color-blank);
margin-bottom: 15px;
display: flex;
height: 160px;
overflow-y: auto;
:deep(.el-radio-group) {
display: block;
overflow: auto;
}
:deep(.el-radio) {
display: flex;
height: auto;
line-height: 18px;
margin: 5px 0;
}
}
.tab-item-label {
display: block;
margin-top: 15px;
font-size: 14px;
font-weight: 600;
margin-bottom: 15px;
}
.model-label {
display: flex;
justify-content: space-between;
margin-top: 15px;
font-size: 14px;
font-weight: 600;
margin-bottom: 15px;
}
.model-box {
margin-top: 15px;
border-radius: 4px;
background-color: var(--el-fill-color-blank);
padding: 15px 20px;
div {
height: 30px;
line-height: 30px;
// border: 1px solid var(--el-border-color);
cursor: pointer;
// border-radius: 4px;
font-size: 14px;
display: flex;
align-items: center;
// margin-bottom: 10px;
span {
color: rgb(239, 53, 53);
font-size: 14px;
margin-left: 15px;
font-style: italic;
vertical-align: middle;
.el-icon {
font-size: 28px;
position: relative;
top: 6px;
}
}
&:hover {
color: var(--el-color-warning);
}
}
.active {
color: var(--el-color-warning);
}
}
.model-item {
padding: 15px;
border-radius: 4px;
background-color: var(--el-fill-color-blank);
cursor: pointer;
label {
font-size: 15px;
font-weight: 600;
line-height: 24px;
}
p {
font-size: 13px;
line-height: 24px;
}
&.active {
background-color: var(--el-color-primary);
label {
color: #fff;
}
p {
color: #fff;
}
}
}
.tab-item-select-box {
.el-select {
margin-bottom: 15px;
}
}
.tab-item-text {
margin: 15px 0;
}
.dialog-content {
margin: 20px;
}
.dialog-title {
margin: 20px 0;
}
.dialog-content-title {
// height: 200px;
min-height: 200px;
border-radius: 6px;
background-color: var(--el-fill-color-blank);
margin-bottom: 20px;
padding: 20px 15px;
p {
line-height: 20px;
padding-right: 50px;
position: relative;
margin-bottom: 20px;
&:last-child {
margin-bottom: 0;
}
.dialog-content-title-span {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
}
}
}
.drawer-title {
display: flex;
justify-content: center;
.serial-number {
height: 30px;
width: 30px;
border-radius: 30px;
background-color: var(--el-color-primary-light-9);
color: var(--el-color-primary-light-5);
display: flex;
justify-content: center;
align-items: center;
margin-right: 15px;
}
.drawer-title-text {
line-height: 30px;
font-size: 14px;
margin-right: 15px;
color: var(--el-color-primary-light-5);
}
.steps-item {
&::after {
border-radius: 50%;
box-shadow: -10px -8px 0 -2px var(--el-color-primary), 0 -8px 0 -1px var(--el-color-primary-light-5), 10px -8px 0 -2px var(--el-color-primary-light-5);
content: " ";
display: inline-block;
height: 8px;
margin: 0 10px;
position: relative;
transform: translateY(calc(100% - 1px)) translateX(8px);
width: 8px;
}
}
.active {
color: var(--el-color-primary);
}
}
:deep(.el-drawer__header) {
margin-bottom: 0;
}
:deep(.el-drawer__body) {
overflow: hidden;
padding: 0;
}
.drawer-content, .drawer-content2 {
padding: 20px;
padding-top: 0;
margin-top: 20px;
height: calc(100vh - 142px);
overflow-y: auto;
.drawer-content-item {
margin-bottom: 20px;
transition: all 0.3s;
.drawer-content-item-button {
text-align: right;
margin-top: 5px;
}
.expand-enter-active,
.expand-leave-active {
transition: all 0.3s ease-in-out;
max-height: 50px;
/* 根据实际内容调整最大高度 */
overflow: hidden;
}
.expand-enter-from,
.expand-leave-to {
max-height: 0;
opacity: 0;
}
.drawer-content-item-box {
border-radius: 6px;
background-color: #f9f9fb;
padding: 18px;
padding-top: 10px;
padding-bottom: 15px;
position: relative;
&.streaming {
background-color: rgba(var(--el-color-primary-rgb), 0.05);
border: 1px solid rgba(var(--el-color-primary-rgb), 0.1);
}
.streaming-cursor {
position: absolute;
right: 18px;
bottom: 15px;
width: 8px;
height: 16px;
background-color: var(--el-color-primary);
animation: blink 1s infinite;
}
}
.EaFdC {
// list-style: cjk-ideographic;
margin-bottom: 4px;
}
.drawer-content-title {
font-size: 16px;
line-height: 24px;
font-weight: 500;
line-height: 24px;
// list-style: cjk-ideographic;
margin: 0;
// margin-left: 35px;
height: auto;
min-height: 24px;
&::marker {
unicode-bidi: isolate;
font-variant-numeric: tabular-nums;
text-transform: none;
text-indent: 0px !important;
text-align: start !important;
text-align-last: start !important;
transform: translateY(-3px);
}
textarea {
width: 100%;
background-color: rgba($color: #000000, $alpha: 0);
border: 0;
font-style: normal;
resize: none;
min-height: 24px;
overflow: hidden;
position: relative;
top: 7px;
padding: 0;
}
}
.drawer-content-text {
font-size: 14px;
line-height: 20px;
width: 100%;
background-color: rgba($color: #000000, $alpha: 0);
border: 0;
font-style: normal;
resize: none;
height: auto;
min-height: 24px;
overflow: hidden;
padding: 0;
word-break: break-all;
}
}
}
.generating-indicator {
position: absolute;
top: 70px;
left: 30px;
color: var(--el-color-primary);
font-size: 28px;
font-weight: bold;
}
.loading-dots {
animation: loadingDots 1.5s infinite;
}
@keyframes loadingDots {
0% { opacity: 0.2; }
20% { opacity: 1; }
100% { opacity: 0.2; }
}
.article-preview {
padding: 10px;
height: 100%;
.article-preview-title {
font-size: 16px;
font-weight: 600;
margin-bottom: 15px;
color: var(--el-color-primary);
}
.article-preview-content {
font-size: 14px;
line-height: 1.6;
// max-height: calc(100vh - 200px);
overflow-y: auto;
padding: 15px;
background-color: #f9f9fb;
border-radius: 6px;
h1,
h2,
h3 {
margin-top: 16px;
margin-bottom: 8px;
font-weight: 600;
}
h1 {
font-size: 20px;
}
h2 {
font-size: 18px;
}
h3 {
font-size: 16px;
}
p {
margin-bottom: 10px;
}
}
}
.extract-style {
font-size: 14px;
background-color: var(--el-fill-color-blank);
border-radius: 6px;
padding: 15px;
// min-height: 100px;
// max-height: 200px;
overflow-y: auto;
height: 200px;
display: flex;
pre {
line-height: 18px;
white-space: pre-wrap;
}
}
.no-click {
pointer-events: none;
}
.article-preview-title {
font-size: 18px;
margin-bottom: 15px;
}
.dialog-preview {
max-height: calc(100vh - 200px);
overflow: auto;
.preview-title {
font-size: 24px;
color: var(--el-text-color-primary);
margin-bottom: 40px;
}
.preview-content {
color: var(--el-text-color-primary);
font-size: 16px;
line-height: 1;
// p{
// line-height: 26px;
// }
}
}
.drawer-footer{
display: flex;
justify-content: space-between;
}
}
@keyframes blink {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0;
}
}
</style>

View File

@ -1,128 +0,0 @@
<template>
<div>
<div class="hot-search">
<div class="hot-search-type">
<el-button :type="activeType === 'ai' ? 'primary' : 'default'" @click="handleFilter('ai')">AI
热榜</el-button>
<el-button :type="activeType === 'low' ? 'primary' : 'default'"
@click="handleFilter('low')">低粉高爆</el-button>
<el-button :type="activeType === 'create' ? 'primary' : 'default'"
@click="handleFilter('create')">创作榜单</el-button>
</div>
<div class="hot-search-filter">
<span>关键词</span>
<el-input v-model="query.keyword" placeholder="关键词搜索" style="width: 200px;" />
<span>阅读量</span>
<el-select v-model="query.readCount" placeholder="请选择阅读量" style="width: 200px;">
<el-option label="1000-10000" value="1000-10000"></el-option>
<el-option label="10000-100000" value="10000-100000"></el-option>
<el-option label="100000-1000000" value="100000-1000000"></el-option>
</el-select>
<span>发布时间</span>
<el-date-picker style="width: 300px;" v-model="date" type="daterange" range-separator=""
start-placeholder="开始日期" end-placeholder="结束日期" value-format="YYYY-MM-DD"
@change="handleDateChange" />
<el-button type="primary" @click="handleFilter">搜索</el-button>
</div>
</div>
<el-table :data="tableData" style="width: 100%;">
<el-table-column label="序号" type="index" width="80" />
<el-table-column prop="title" label="标题" />
<el-table-column prop="" label="领域" />
<el-table-column prop="readCount" label="阅读量" />
<el-table-column prop="publishTime" label="发布时间" />
<el-table-column prop="action" label="操作" width="150">
<template #default="scope">
<el-link type="primary" @click="handleEdit(scope.row)">AI 改写</el-link>
<el-link type="primary" @click="handleEdit(scope.row)">查看原文</el-link>
<el-link type="primary" @click="handleEdit(scope.row)">创作灵感</el-link>
</template>
</el-table-column>
</el-table>
<el-pagination background v-model:current-page="query.page" v-model:page-size="query.pageSize"
:page-sizes="[100, 200, 300, 400]" :size="query.pageSize" :disabled="disabled" :background="background"
layout="total, sizes, prev, pager, next, jumper" :total="400" @size-change="handleSizeChange"
@current-change="handleCurrentChange" />
</div>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue';
const activeType = ref('ai');
const handleFilter = (type) => {
activeType.value = type;
};
const query = reactive({
page: 1,
pageSize: 10,
keyword: '',
readCount: '',
startDate: '',
endDate: '',
});
const handleDateChange = (value) => {
query.startDate = value[0];
query.endDate = value[1];
};
const handleSizeChange = (size) => {
pageSize.value = size;
};
const handleCurrentChange = (page) => {
query.page = page;
};
onMounted(() => {
handleFilter(activeType.value);
});
</script>
<style scoped lang="scss">
.hot-search {
.hot-search-type {
margin-bottom: 20px;
}
.hot-search-filter {
line-height: 36px;
span {
margin-right: 10px;
font-size: 14px;
}
.el-input {
margin-right: 10px;
}
.el-select {
margin-right: 10px;
}
.el-button {
margin-left: 10px;
}
}
}
.el-table {
margin-top: 20px;
}
.el-pagination {
margin-top: 20px;
}
.el-link+ .el-link {
margin-left: 10px;
}
</style>

View File

@ -1,8 +0,0 @@
<template>
<div>
<h1>热榜</h1>
</div>
</template>
<script setup>
</script>

View File

@ -47,6 +47,7 @@
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { userLogin } from '@/api/login'
import md5 from 'js-md5'
const router = useRouter()
const loginFormRef = ref(null)
const loading = ref(false)
@ -62,7 +63,6 @@
],
password: [
{ required: true, message: '请输入密码', trigger: 'blur' },
{ min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
]
}
@ -73,20 +73,20 @@
await loginFormRef.value.validate()
loading.value = true
// TODO: API
// const res = await login(loginForm)
userLogin(loginForm).then(res => {
console.log(res)
localStorage.setItem('TOKEN', res.data.token)
router.push('/')
// MD5
const encryptedPassword = md5(loginForm.password)
const loginData = {
username: loginForm.username,
password: encryptedPassword
}
userLogin(loginData).then(res => {
localStorage.setItem('TOKEN', res.token)
router.push('/user')
loading.value = false
}).catch(err => {
loading.value = false
})
//
// setTimeout(() => {
// ElMessage.success('')
// router.push('/')
// loading.value = false
// }, 1000)
} catch (error) {
ElMessage.error('登录失败,请检查用户名和密码')

View File

@ -208,7 +208,7 @@ const handleCreated = (editor) => {
const newTitle = ref('')
const dialogPreview = ref(false)
const handlePreviewArticle = () => {
dialogPreview.value = true
}
@ -220,7 +220,9 @@ const handlePreviewArticle = () => {
onMounted(() => {
if(route.query.id){
newTitle.value = sessionStorage.getItem('title')
}
})
// Auto-resize directive

View File

@ -1,33 +1,44 @@
<template>
<div>
<div class="user-search">
<el-input style="width: 200px;margin-right: 10px;" v-model="search" placeholder="请输入文章标题" />
<el-input style="width: 200px;margin-right: 10px;" v-model="query.title" placeholder="请输入文章标题" />
<el-button type="primary">搜索</el-button>
<el-button style="float: right;" type="primary" @click="addNews">添加文章</el-button>
</div>
<div class="user-table">
<el-table :data="tableData" style="width: 100%">
<el-table-column prop="title" label="文章标题" />
<el-table-column prop="author" label="作者" />
<el-table-column prop="createTime" label="创建时间" />
<el-table-column prop="updateTime" label="更新时间" />
<el-table-column label="操作">
<el-table-column prop="content" label="内容">
<template #default="scope">
<div class="content-wrap" v-html="scope.row.content"></div>
</template>
</el-table-column>
<el-table-column prop="created_at" label="创建时间" />
<el-table-column label="操作" width="100" align="center">
<template #default="scope">
<el-link type="primary" @click="editNews(scope.row)">
<el-icon type="primary" @click="editNews(scope.row)">
<Edit />
</el-icon>
<el-icon type="danger" @click="handleDeleteNews(scope.row)">
</el-link>
<el-popconfirm title="确定删除吗?" @confirm="handleDeleteNews(scope.row)">
<template #reference>
<el-link type="danger">
<el-icon type="danger">
<Delete />
</el-icon>
</el-link>
</template>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
<el-pagination
background
layout="prev, pager, next"
:total="1000"
:page-size="20"
:current-page="1"
:total="total"
:page-size="query.page_size"
:current-page="query.page"
/>
</div>
</div>
@ -51,25 +62,33 @@ const addNews = () => {
router.push('/addNew')
}
const editNews = (row) => {
sessionStorage.setItem('works', row.content);
sessionStorage.setItem('title', row.title);
router.push(`/addNew?id=${row.id}`)
}
const handleDeleteNews = (row) => {
console.log(row)
deleteNews(row.id).then(res => {
console.log(res)
deleteNews({ids: `${row.id}`}).then(res => {
ElMessage.success('删除成功')
getNews()
}).catch(err => {
console.log(err)
})
}
const query = ref({
page: 1,
size: 20,
page_size: 20,
title: '',
author: '',
createTime: '',
start_time: '',
end_time: '',
})
const total = ref(0)
const getNews = () => {
news(query.value).then(res => {
console.log(res)
tableData.value = res.list
total.value = res.total
})
}
onMounted(() => {
@ -81,4 +100,15 @@ onMounted(() => {
.user-search {
margin-bottom: 10px;
}
.content-wrap {
max-height: 100px;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
.el-link+ .el-link {
margin-left: 10px;
}
</style>