This commit is contained in:
2025-08-31 15:29:05 +08:00
parent acb59b64bd
commit 0a45d62278
4 changed files with 34 additions and 23 deletions

View File

@@ -9,7 +9,7 @@ import { isRelogin } from '@/utils/request'
NProgress.configure({ showSpinner: false }) NProgress.configure({ showSpinner: false })
const whiteList = ['/login', '/register'] const whiteList = ['/login', '/register','/public/comment']
const isWhiteList = (path) => { const isWhiteList = (path) => {
return whiteList.some(pattern => isPathMatch(pattern, path)) return whiteList.some(pattern => isPathMatch(pattern, path))

View File

@@ -3,6 +3,7 @@ import auth from './auth'
import cache from './cache' import cache from './cache'
import modal from './modal' import modal from './modal'
import download from './download' import download from './download'
import request from '@/utils/request'
export default { export default {
install(Vue) { install(Vue) {
@@ -16,5 +17,7 @@ export default {
Vue.prototype.$modal = modal Vue.prototype.$modal = modal
// 下载文件 // 下载文件
Vue.prototype.$download = download Vue.prototype.$download = download
// 全局请求实例(供 this.$axios 使用)
Vue.prototype.$axios = request
} }
} }

View File

@@ -116,6 +116,12 @@ export const constantRoutes = [
} }
] ]
}, },
// 公开评论独立页(不使用 Layout无侧边栏
{
path: '/public/comment',
component: () => import('@/views/public/CommentGenerator'),
hidden: true
},
{ {
path: '/jdorder', path: '/jdorder',
component: Layout, component: Layout,
@@ -146,22 +152,6 @@ export const constantRoutes = [
} }
] ]
}, },
// 公共页面(免登录)可直接通过服务端 Anonymous 注解放行接口,这里仍挂在主框架下展示
{
path: '/public',
component: Layout,
redirect: 'noredirect',
name: 'Public',
meta: { title: '公共工具', icon: 'link' },
children: [
{
path: 'comment',
component: () => import('@/views/public/CommentGenerator'),
name: 'CommentGeneratorPublic',
meta: { title: '评论生成(公开)', icon: 'message' }
}
]
},
{ {
path: '/sloworder', path: '/sloworder',
component: Layout, component: Layout,

View File

@@ -5,7 +5,7 @@
<el-form :model="form" label-width="100px"> <el-form :model="form" label-width="100px">
<el-form-item label="型号/类型"> <el-form-item label="型号/类型">
<el-select v-model="form.productType" filterable placeholder="请选择"> <el-select v-model="form.productType" filterable placeholder="请选择">
<el-option v-for="it in typeOptions" :key="it.value" :label="`${it.name}${it.value}`" :value="it.value" /> <el-option v-for="it in typeOptions" :key="it.name" :label="it.name" :value="it.name" />
</el-select> </el-select>
<el-button type="primary" size="mini" style="margin-left:8px;" @click="loadTypes">刷新</el-button> <el-button type="primary" size="mini" style="margin-left:8px;" @click="loadTypes">刷新</el-button>
</el-form-item> </el-form-item>
@@ -13,10 +13,18 @@
<el-button type="primary" @click="generate" :loading="loading">生成评论</el-button> <el-button type="primary" @click="generate" :loading="loading">生成评论</el-button>
</el-form-item> </el-form-item>
<el-form-item label="结果"> <el-form-item label="结果">
<el-input type="textarea" :rows="10" :value="pretty" readonly /> <div v-if="comments.length">
<div style="margin-top:8px;"> <el-card v-for="(c, idx) in comments" :key="idx" class="comment-block" shadow="never" style="margin-bottom:12px;">
<el-button size="mini" type="success" @click="copy(pretty)" :disabled="!pretty">复制结果</el-button> <div class="comment-text">{{ c.commentText }}</div>
<div class="image-list" v-if="Array.isArray(c.images) && c.images.length">
<el-image v-for="(img, ix) in c.images" :key="ix" :src="img" :preview-src-list="c.images" fit="cover" style="width:120px;height:120px;margin:6px 6px 0 0;" />
</div>
<div style="margin-top:8px;">
<el-button size="mini" type="success" @click="copy(c.commentText)">复制文本</el-button>
</div>
</el-card>
</div> </div>
<div v-else>暂无数据</div>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-card> </el-card>
@@ -27,7 +35,7 @@
export default { export default {
name: 'CommentGeneratorPublic', name: 'CommentGeneratorPublic',
data() { data() {
return { form: { productType: '' }, loading: false, result: null, typeOptions: [] } return { form: { productType: '' }, loading: false, result: null, typeOptions: [], comments: [] }
}, },
computed: { computed: {
pretty() { pretty() {
@@ -39,7 +47,11 @@ export default {
async loadTypes() { async loadTypes() {
try { try {
const res = await this.$axios({ url: '/public/comment/types', method: 'get' }) const res = await this.$axios({ url: '/public/comment/types', method: 'get' })
if (res && (res.code === 200 || res.msg === '操作成功')) this.typeOptions = res.data || [] if (res && (res.code === 200 || res.msg === '操作成功')) {
// 后端返回 [{name,value}] 或纯数组,这里统一转成 [{name}]
const arr = Array.isArray(res.data) ? res.data : []
this.typeOptions = arr.map(it => ({ name: it.name || it }))
}
} catch(e) {} } catch(e) {}
}, },
async generate() { async generate() {
@@ -50,6 +62,12 @@ export default {
this.loading = false this.loading = false
if (res && (res.code === 200 || res.msg === '操作成功')) { if (res && (res.code === 200 || res.msg === '操作成功')) {
this.result = res.data this.result = res.data
// 结果渲染
const list = (res.data && res.data.list && Array.isArray(res.data.list)) ? res.data.list : []
this.comments = list.map(it => ({
commentText: (it && it.commentText) ? it.commentText : '',
images: Array.isArray(it && it.images) ? it.images : []
}))
} else { } else {
this.$message.error(res && res.msg ? res.msg : '生成失败') this.$message.error(res && res.msg ? res.msg : '生成失败')
} }