From 0a45d62278e2984737eb669065cd3e633cc2eccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=92?= Date: Sun, 31 Aug 2025 15:29:05 +0800 Subject: [PATCH] 1 --- src/permission.js | 2 +- src/plugins/index.js | 3 +++ src/router/index.js | 22 ++++++-------------- src/views/public/CommentGenerator.vue | 30 +++++++++++++++++++++------ 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/permission.js b/src/permission.js index b66190b..dedb360 100644 --- a/src/permission.js +++ b/src/permission.js @@ -9,7 +9,7 @@ import { isRelogin } from '@/utils/request' NProgress.configure({ showSpinner: false }) -const whiteList = ['/login', '/register'] +const whiteList = ['/login', '/register','/public/comment'] const isWhiteList = (path) => { return whiteList.some(pattern => isPathMatch(pattern, path)) diff --git a/src/plugins/index.js b/src/plugins/index.js index d000f2d..5860293 100644 --- a/src/plugins/index.js +++ b/src/plugins/index.js @@ -3,6 +3,7 @@ import auth from './auth' import cache from './cache' import modal from './modal' import download from './download' +import request from '@/utils/request' export default { install(Vue) { @@ -16,5 +17,7 @@ export default { Vue.prototype.$modal = modal // 下载文件 Vue.prototype.$download = download + // 全局请求实例(供 this.$axios 使用) + Vue.prototype.$axios = request } } diff --git a/src/router/index.js b/src/router/index.js index 40b621f..c0dd3bb 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -116,6 +116,12 @@ export const constantRoutes = [ } ] }, + // 公开评论独立页(不使用 Layout,无侧边栏) + { + path: '/public/comment', + component: () => import('@/views/public/CommentGenerator'), + hidden: true + }, { path: '/jdorder', 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', component: Layout, diff --git a/src/views/public/CommentGenerator.vue b/src/views/public/CommentGenerator.vue index 996140d..3b74b32 100644 --- a/src/views/public/CommentGenerator.vue +++ b/src/views/public/CommentGenerator.vue @@ -5,7 +5,7 @@ - + 刷新 @@ -13,10 +13,18 @@ 生成评论 - -
- 复制结果 +
+ +
{{ c.commentText }}
+
+ +
+
+ 复制文本 +
+
+
暂无数据
@@ -27,7 +35,7 @@ export default { name: 'CommentGeneratorPublic', data() { - return { form: { productType: '' }, loading: false, result: null, typeOptions: [] } + return { form: { productType: '' }, loading: false, result: null, typeOptions: [], comments: [] } }, computed: { pretty() { @@ -39,7 +47,11 @@ export default { async loadTypes() { try { 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) {} }, async generate() { @@ -50,6 +62,12 @@ export default { this.loading = false if (res && (res.code === 200 || res.msg === '操作成功')) { 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 { this.$message.error(res && res.msg ? res.msg : '生成失败') }