1
This commit is contained in:
@@ -146,6 +146,22 @@ 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,
|
||||
|
||||
75
src/views/public/CommentGenerator.vue
Normal file
75
src/views/public/CommentGenerator.vue
Normal file
@@ -0,0 +1,75 @@
|
||||
<template>
|
||||
<div class="app-container" style="max-width: 920px; margin: 0 auto;">
|
||||
<el-card>
|
||||
<div slot="header">评论生成(公开)</div>
|
||||
<el-form :model="form" label-width="100px">
|
||||
<el-form-item label="型号/类型">
|
||||
<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-select>
|
||||
<el-button type="primary" size="mini" style="margin-left:8px;" @click="loadTypes">刷新</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="generate" :loading="loading">生成评论</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item label="结果">
|
||||
<el-input type="textarea" :rows="10" :value="pretty" readonly />
|
||||
<div style="margin-top:8px;">
|
||||
<el-button size="mini" type="success" @click="copy(pretty)" :disabled="!pretty">复制结果</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'CommentGeneratorPublic',
|
||||
data() {
|
||||
return { form: { productType: '' }, loading: false, result: null, typeOptions: [] }
|
||||
},
|
||||
computed: {
|
||||
pretty() {
|
||||
try { return this.result ? JSON.stringify(this.result, null, 2) : '' } catch(e) { return '' }
|
||||
}
|
||||
},
|
||||
mounted() { this.loadTypes() },
|
||||
methods: {
|
||||
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 || []
|
||||
} catch(e) {}
|
||||
},
|
||||
async generate() {
|
||||
if (!this.form.productType) { this.$message.error('请选择型号'); return }
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await this.$axios({ url: '/public/comment/generate', method: 'post', data: { productType: this.form.productType } })
|
||||
this.loading = false
|
||||
if (res && (res.code === 200 || res.msg === '操作成功')) {
|
||||
this.result = res.data
|
||||
} else {
|
||||
this.$message.error(res && res.msg ? res.msg : '生成失败')
|
||||
}
|
||||
} catch(e) { this.loading = false; this.$message.error('生成失败') }
|
||||
},
|
||||
copy(text) {
|
||||
if (!text) return
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(text).then(() => this.$message.success('已复制'))
|
||||
} else {
|
||||
const ta = document.createElement('textarea'); ta.value = text; document.body.appendChild(ta); ta.select();
|
||||
try { document.execCommand('copy'); this.$message.success('已复制') } catch(e) { this.$message.error('复制失败') }
|
||||
document.body.removeChild(ta)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user