This commit is contained in:
左哥 2025-06-16 23:53:04 +08:00
parent 60f4bc5913
commit 8603acf35e
7 changed files with 147 additions and 81 deletions

View File

@ -3,3 +3,5 @@ NODE_ENV = 'development'
VITE_APP_BASE_API = 'https://ddbs.1024tool.vip/' VITE_APP_BASE_API = 'https://ddbs.1024tool.vip/'
VITE_SERVE = "https://ddbs.1024tool.vip/" VITE_SERVE = "https://ddbs.1024tool.vip/"
# VITE_SERVE = "http://192.168.210.29:18100/" # VITE_SERVE = "http://192.168.210.29:18100/"
VITE_OSS_ACCESS_KEY_ID = "LTAI5tCpvXC17uuPwWvb5oRo"
VITE_OSS_ACCESS_KEY_SECRET = "44EqDghVI0UVF0rVaea7gwOsPkXZ1z"

View File

@ -3,3 +3,5 @@ NODE_ENV = 'production'
VITE_APP_BASE_API = 'https://tools.1024tool.vip/' VITE_APP_BASE_API = 'https://tools.1024tool.vip/'
VITE_SERVE = "https://tools.1024tool.vip/" VITE_SERVE = "https://tools.1024tool.vip/"
VITE_OSS_ACCESS_KEY_ID = "LTAI5tCpvXC17uuPwWvb5oRo"
VITE_OSS_ACCESS_KEY_SECRET = "44EqDghVI0UVF0rVaea7gwOsPkXZ1z"

View File

@ -20,6 +20,7 @@
"@element-plus/icons-vue": "2.1.0", "@element-plus/icons-vue": "2.1.0",
"@wangeditor/editor": "^5.1.23", "@wangeditor/editor": "^5.1.23",
"@wangeditor/editor-for-vue": "next", "@wangeditor/editor-for-vue": "next",
"ali-oss": "^6.23.0",
"axios": "^1.4.0", "axios": "^1.4.0",
"default-passive-events": "^2.0.0", "default-passive-events": "^2.0.0",
"echarts": "^5.6.0", "echarts": "^5.6.0",

19
src/api/upload.js Normal file
View File

@ -0,0 +1,19 @@
import request from '@/utils/request'
export const getCode = () =>{
return request({
url: 'admin/policy_token',
method: 'post',
})
}
export const uploadFile = (data) =>{
request({
url: 'https://image-fudan.oss-cn-beijing.aliyuncs.com',
method: 'get',
data
})
}

View File

@ -99,7 +99,6 @@ const whiteList = ['/login']
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, from, next) => {
// Nprogress.start() // Nprogress.start()
const token = GET_TOKEN() const token = GET_TOKEN()
console.log(token)
if (token) { if (token) {
if (to.path === '/login') { if (to.path === '/login') {
next('/index') next('/index')

View File

@ -28,7 +28,7 @@
</div> </div>
</div> </div>
<input type="file" @change="handleUpload" />
<el-dialog v-model="dialogPreview" title="文章预览" width="1000px"> <el-dialog v-model="dialogPreview" title="文章预览" width="1000px">
@ -49,13 +49,15 @@
<script setup> <script setup>
import '@wangeditor/editor/dist/css/style.css' // css import '@wangeditor/editor/dist/css/style.css' // css
import { Loading } from '@element-plus/icons-vue' import { Loading } from '@element-plus/icons-vue'
import { onBeforeUnmount, onUnmounted , ref, reactive, shallowRef, onMounted, computed, getCurrentInstance, nextTick } from 'vue' import { onBeforeUnmount, onUnmounted, ref, reactive, shallowRef, onMounted, computed, getCurrentInstance, nextTick } from 'vue'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue' import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import { addNews, editNews } from '@/api/news' import { addNews, editNews } from '@/api/news'
import { getCode } from '@/api/upload'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { DomEditor } from '@wangeditor/editor' import { DomEditor } from '@wangeditor/editor'
import OSS from 'ali-oss'
const ossurl = 'https://image-fudan.oss-cn-beijing.aliyuncs.com' const ossurl = 'https://image-fudan.oss-cn-beijing.aliyuncs.com'
@ -77,10 +79,7 @@ const valueText = ref('')
const characterCount = ref(0) const characterCount = ref(0)
const toolbarConfig = { const toolbarConfig = {
excludeKeys: [
'group-image',
'group-video',
]
} }
@ -92,46 +91,87 @@ const editorConfig = {
editorConfig.MENU_CONF['uploadImage'] = { editorConfig.MENU_CONF['uploadImage'] = {
// //
server: import.meta.env.VITE_API_BASE_URL + '/api/upload', // 使APIURL // server: '', // 使APIURL
// 10M // fieldName: 'your-custom-name',
maxFileSize: 5 * 1024 * 1024, // 5M // // 10M
// // maxFileSize: 5 * 1024 * 1024, // 5M
allowedFileTypes: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'], // //
// // allowedFileTypes: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
meta: { // //
token: localStorage.getItem('token') || '' // meta: {
}, // token: localStorage.getItem('token') || ''
// http // },
headers: { // // http
Authorization: 'Bearer ' + (localStorage.getItem('token') || '') // headers: {
}, // Authorization: 'Bearer ' + (localStorage.getItem('token') || '')
// // },
onBeforeUpload(file) { // //
console.log('准备上传图片', file) // onBeforeUpload(file) {
return file // file // console.log('', file)
}, // return file // file
// // },
onSuccess(file, res) { // //
console.log('图片上传成功', file, res) // onSuccess(file, res) {
}, // console.log('', file, res)
// // },
onError(file, err, res) { // //
console.log('图片上传失败', file, err, res) // onError(file, err, res) {
// // console.log('', file, err, res)
ElNotification.error('图片上传失败,请重试') // //
}, // ElNotification.error('')
// },
// //
customInsert(res, insertFn) { // customInsert(res, insertFn) {
// res // console.log('', res, insertFn)
if (res.code === 200 && res.data) { // // res
// URL // if (res.code === 200 && res.data) {
const url = res.data.url || res.data // // URL
// // const url = res.data.url || res.data
insertFn(url) // //
} else { // insertFn(url)
ElNotification.error('图片插入失败') // } else {
// ElNotification.error('')
// }
// }
//
async customUpload(file, insertFn) {
try {
const formData = new FormData()
formData.append('file', file)
const code = await getCode()
const client = new OSS({
region: "oss-cn-beijing",
authorizationV4: true,
accessKeyId: import.meta.env.VITE_OSS_ACCESS_KEY_ID,
accessKeySecret: import.meta.env.VITE_OSS_ACCESS_KEY_SECRET,
stsToken: code.token,
bucket: "image-fudan",
});
// Generate unique filename with original extension
const fileExt = file.name.split('.').pop()
const fileName = `${Date.now()}-${Math.random().toString(36).substring(2)}.${fileExt}`
const options = {
meta: { temp: "demo" },
mime: file.type,
headers: { "Content-Type": file.type },
};
const result = await client.put(fileName, file, options);
console.log('Upload result:', result);
// Construct the full URL and call insertFn
const url = `${ossurl}/${fileName}`;
insertFn(url, file.name, url);
} catch (error) {
console.error('Upload failed:', error);
ElNotification.error('图片上传失败,请重试');
} }
} },
}
const handleUpload = (e) => {
console.log(e.target.files[0])
} }
editorConfig.MENU_CONF['uploadVideo'] = { editorConfig.MENU_CONF['uploadVideo'] = {
@ -153,7 +193,7 @@ editorConfig.MENU_CONF['uploadVideo'] = {
const handleSaveArticle = () => { const handleSaveArticle = () => {
if(route.query.id){ if (route.query.id) {
editNews({ editNews({
title: newTitle.value, title: newTitle.value,
content: valueHtml.value content: valueHtml.value
@ -197,10 +237,10 @@ const handleCreated = (editor) => {
characterCount.value = valueText.value.length characterCount.value = valueText.value.length
}) })
// const toolbar = DomEditor.getToolbar(editor) // const toolbar = DomEditor.getToolbar(editor)
// const curToolbarConfig = toolbar.getConfig() // const curToolbarConfig = toolbar.getConfig()
// console.log(curToolbarConfig.toolbarKeys) // // console.log(curToolbarConfig.toolbarKeys) //
} }
@ -222,7 +262,7 @@ const handlePreviewArticle = () => {
onMounted(() => { onMounted(() => {
if(route.query.id){ if (route.query.id) {
newTitle.value = sessionStorage.getItem('title') newTitle.value = sessionStorage.getItem('title')
} }
}) })
@ -258,16 +298,20 @@ app.appContext.app.directive('auto-resize', vAutoResize)
.container { .container {
width: 100%; width: 100%;
height: 100%; height: 100%;
.toolbar-box{
.toolbar-box {
height: 80px; height: 80px;
} }
:deep(.el-radio__label) { :deep(.el-radio__label) {
white-space: normal; white-space: normal;
} }
.editor-box-content{
.editor-box-content {
padding: 0 16px; padding: 0 16px;
height: calc(100% - 130px); height: calc(100% - 130px);
} }
.title-input { .title-input {
width: 100%; width: 100%;
height: 50px; height: 50px;
@ -290,8 +334,7 @@ app.appContext.app.directive('auto-resize', vAutoResize)
.editor { .editor {}
}
.editor-btn-box { .editor-btn-box {
width: 100%; width: 100%;
@ -564,7 +607,8 @@ app.appContext.app.directive('auto-resize', vAutoResize)
padding: 0; padding: 0;
} }
.drawer-content, .drawer-content2 { .drawer-content,
.drawer-content2 {
padding: 20px; padding: 20px;
padding-top: 0; padding-top: 0;
margin-top: 20px; margin-top: 20px;
@ -691,14 +735,23 @@ app.appContext.app.directive('auto-resize', vAutoResize)
} }
@keyframes loadingDots { @keyframes loadingDots {
0% { opacity: 0.2; } 0% {
20% { opacity: 1; } opacity: 0.2;
100% { opacity: 0.2; } }
20% {
opacity: 1;
}
100% {
opacity: 0.2;
}
} }
.article-preview { .article-preview {
padding: 10px; padding: 10px;
height: 100%; height: 100%;
.article-preview-title { .article-preview-title {
font-size: 16px; font-size: 16px;
font-weight: 600; font-weight: 600;
@ -746,11 +799,12 @@ app.appContext.app.directive('auto-resize', vAutoResize)
background-color: var(--el-fill-color-blank); background-color: var(--el-fill-color-blank);
border-radius: 6px; border-radius: 6px;
padding: 15px; padding: 15px;
// min-height: 100px; // min-height: 100px;
// max-height: 200px; // max-height: 200px;
overflow-y: auto; overflow-y: auto;
height: 200px; height: 200px;
display: flex; display: flex;
pre { pre {
line-height: 18px; line-height: 18px;
white-space: pre-wrap; white-space: pre-wrap;
@ -785,7 +839,8 @@ app.appContext.app.directive('auto-resize', vAutoResize)
// } // }
} }
} }
.drawer-footer{
.drawer-footer {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
} }

View File

@ -1,12 +0,0 @@
export default uploadFile = (data) =>{
request({
url: 'https://image-fudan.oss-cn-beijing.aliyuncs.com',
method: 'get',
data
})
}