1
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<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-option v-for="it in typeOptions" :key="it.name" :label="it.name" :value="it.name" />
|
||||
</el-select>
|
||||
<el-button type="primary" size="mini" style="margin-left:8px;" @click="loadTypes">刷新</el-button>
|
||||
</el-form-item>
|
||||
@@ -13,10 +13,18 @@
|
||||
<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 v-if="comments.length">
|
||||
<el-card v-for="(c, idx) in comments" :key="idx" class="comment-block" shadow="never" style="margin-bottom:12px;">
|
||||
<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 v-else>暂无数据</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
@@ -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 : '生成失败')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user