This commit is contained in:
van
2026-11-14 16:21:32 +08:00
parent f3dae81257
commit 7d4f06f3c1
2 changed files with 161 additions and 2 deletions
+18
View File
@@ -118,6 +118,24 @@ export function getTbProductTypeMap() {
})
}
// 保存型号与商品ID映射
export function saveProductTypeMap(data) {
return request({
url: '/jarvis/comment/redis/map',
method: 'put',
data: data
})
}
// 删除型号与商品ID映射
export function delProductTypeMap(source, key) {
return request({
url: '/jarvis/comment/redis/map',
method: 'delete',
params: { source, key }
})
}
// 获取评论(由后端转发到外部服务,避免前端跨域)
export function fetchComments(productId) {
return request({
+143 -2
View File
@@ -330,8 +330,63 @@
</el-table>
</div>
</el-tab-pane>
<!-- 商品ID维护:原微信评价群「添加型号 / 删除型号」 -->
<el-tab-pane label="商品ID" name="productMap">
<div class="comment-container">
<el-alert
title="京东维护「型号名称 → 京东商品ID」。淘宝映射维护「京东商品ID → 淘宝商品ID」,生成评论时按这个关系取淘宝评论。"
type="info"
:closable="false"
show-icon
style="margin-bottom: 16px;"
/>
<el-form :inline="true" size="small">
<el-form-item label="平台">
<el-radio-group v-model="mapSource" size="small">
<el-radio-button label="jd">京东型号</el-radio-button>
<el-radio-button label="tb">淘宝映射</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item>
<el-input v-model="mapKeyword" placeholder="型号或商品ID" clearable style="width: 220px;" />
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-plus" size="small" @click="openMapDialog()">新增</el-button>
<el-button icon="el-icon-refresh" size="small" @click="reloadProductTypeMap">刷新</el-button>
</el-form-item>
</el-form>
<el-table :data="mapTableRows" border>
<el-table-column :label="mapKeyLabel" prop="key" min-width="220" />
<el-table-column :label="mapValueLabel" prop="value" min-width="220" />
<el-table-column label="操作" align="center" width="180" fixed="right">
<template slot-scope="scope">
<el-button size="mini" type="primary" @click="openMapDialog(scope.row)">编辑</el-button>
<el-button size="mini" type="danger" @click="handleMapDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
</el-tab-pane>
</el-tabs>
<!-- 商品ID编辑 -->
<el-dialog :title="mapDialogTitle" :visible.sync="mapDialogVisible" width="480px" append-to-body>
<el-form ref="mapForm" :model="mapForm" :rules="mapRules" label-width="110px" size="small">
<el-form-item :label="mapKeyLabel" prop="key">
<el-input v-model="mapForm.key" :placeholder="'请输入' + mapKeyLabel" />
</el-form-item>
<el-form-item :label="mapValueLabel" prop="value">
<el-input v-model="mapForm.value" :placeholder="'请输入' + mapValueLabel" />
</el-form-item>
</el-form>
<div slot="footer">
<el-button size="small" @click="mapDialogVisible = false">取消</el-button>
<el-button type="primary" size="small" :loading="mapSaving" @click="submitMapForm">保存</el-button>
</div>
</el-dialog>
<!-- 图片查看对话框 -->
<el-dialog title="评论图片" :visible.sync="imageDialogVisible" width="80%">
<div class="image-gallery">
@@ -352,7 +407,7 @@
import {
listJdComment, getJdComment, updateJdComment, delJdComment, resetJdCommentByProductId,
listTbComment, getTbComment, updateTbComment, delTbComment, resetTbCommentByProductId,
getCommentStatistics, getJdProductTypeMap, getTbProductTypeMap, fetchComments
getCommentStatistics, getJdProductTypeMap, getTbProductTypeMap, saveProductTypeMap, delProductTypeMap, fetchComments
} from '@/api/jarvis/comment'
import { mapGetters } from 'vuex'
import MobileSearchForm from '@/components/MobileSearchForm'
@@ -407,7 +462,18 @@ export default {
// 获取评论 loading
jdFetchLoading: false,
tbFetchLoading: false,
statFetchLoading: false
statFetchLoading: false,
// 商品ID映射
mapSource: 'jd',
mapKeyword: '',
mapDialogVisible: false,
mapDialogTitle: '新增商品ID',
mapSaving: false,
mapForm: {
key: '',
value: '',
oldKey: ''
}
}
},
computed: {
@@ -432,6 +498,30 @@ export default {
{ key: 'fetchComments', label: '获取评论', type: 'warning', icon: 'el-icon-upload2', handler: () => this.handleTbFetchComments(), disabled: this.tbFetchLoading },
{ key: 'export', label: '导出', type: 'success', icon: 'el-icon-download', handler: () => this.handleTbExport(), disabled: false }
]
},
mapKeyLabel() {
return this.mapSource === 'tb' ? '京东商品ID' : '型号名称'
},
mapValueLabel() {
return this.mapSource === 'tb' ? '淘宝商品ID' : '京东商品ID'
},
mapRules() {
return {
key: [{ required: true, message: '请输入' + this.mapKeyLabel, trigger: 'blur' }],
value: [{ required: true, message: '请输入' + this.mapValueLabel, trigger: 'blur' }]
}
},
mapTableRows() {
const sourceMap = this.mapSource === 'tb' ? this.tbProductTypeMap : this.jdProductTypeMap
const keyword = (this.mapKeyword || '').trim()
return Object.keys(sourceMap || {}).sort().filter(key => {
if (!keyword) return true
const value = sourceMap[key] == null ? '' : String(sourceMap[key])
return key.indexOf(keyword) !== -1 || value.indexOf(keyword) !== -1
}).map(key => ({
key: key,
value: sourceMap[key]
}))
}
},
created() {
@@ -607,6 +697,54 @@ export default {
this.tbProductTypeMap = response.data || {}
})
},
reloadProductTypeMap() {
if (this.mapSource === 'tb') {
this.getTbProductTypeMap()
} else {
this.getJdProductTypeMap()
}
},
openMapDialog(row) {
this.mapDialogTitle = row ? '编辑商品ID' : '新增商品ID'
this.mapForm = {
key: row ? row.key : '',
value: row ? row.value : '',
oldKey: row ? row.key : ''
}
this.mapDialogVisible = true
this.$nextTick(() => {
if (this.$refs.mapForm) {
this.$refs.mapForm.clearValidate()
}
})
},
submitMapForm() {
this.$refs.mapForm.validate(valid => {
if (!valid) return
this.mapSaving = true
saveProductTypeMap({
source: this.mapSource,
key: (this.mapForm.key || '').trim(),
value: (this.mapForm.value || '').trim(),
oldKey: this.mapForm.oldKey || ''
}).then(() => {
this.$modal.msgSuccess('保存成功')
this.mapDialogVisible = false
this.reloadProductTypeMap()
}).finally(() => {
this.mapSaving = false
})
})
},
handleMapDelete(row) {
const label = this.mapKeyLabel + '「' + row.key + '」'
this.$modal.confirm('是否确认删除' + label + '?').then(() => {
return delProductTypeMap(this.mapSource, row.key)
}).then(() => {
this.reloadProductTypeMap()
this.$modal.msgSuccess('删除成功')
}).catch(() => {})
},
// 标签页切换
handleTabClick(tab) {
if (tab.name === 'jd') {
@@ -621,6 +759,9 @@ export default {
if (this.statisticsList.length === 0) {
this.getStatistics()
}
} else if (tab.name === 'productMap') {
this.getJdProductTypeMap()
this.getTbProductTypeMap()
}
},
// 查看图片