1
This commit is contained in:
281
src/views/system/jdorder/index.vue
Normal file
281
src/views/system/jdorder/index.vue
Normal file
@@ -0,0 +1,281 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<el-card class="box-card">
|
||||
<div slot="header" class="clearfix">
|
||||
<span>一键转链</span>
|
||||
</div>
|
||||
|
||||
<el-form :model="form" label-width="120px">
|
||||
<el-form-item label="输入内容">
|
||||
<el-input
|
||||
v-model="form.inputContent"
|
||||
type="textarea"
|
||||
:rows="6"
|
||||
placeholder="请输入需要转链的内容,如商品链接、商品名称等"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleGenerate" :loading="loading">
|
||||
生成转链内容
|
||||
</el-button>
|
||||
<el-button @click="handleClear">清空</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<div v-if="result" style="margin-top: 20px;">
|
||||
<h4>转链结果:</h4>
|
||||
|
||||
<!-- 商品列表 -->
|
||||
<div v-if="parsedResult && Array.isArray(parsedResult) && parsedResult.length > 0" style="margin-bottom: 20px;">
|
||||
<h5>商品列表 ({{ parsedResult.length }}个商品):</h5>
|
||||
|
||||
<el-tabs v-model="activeProductTab" type="card">
|
||||
<el-tab-pane
|
||||
v-for="(product, productIndex) in parsedResult"
|
||||
:key="productIndex"
|
||||
:label="`商品${productIndex + 1}`"
|
||||
:name="productIndex"
|
||||
>
|
||||
<!-- 商品基本信息 -->
|
||||
<el-descriptions :column="2" border style="margin-bottom: 20px;">
|
||||
<el-descriptions-item label="商品名称">{{ product.skuName || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="店铺">{{ product.shopName || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="佣金">¥{{ product.commission || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="佣金比例">{{ product.commissionShare || '-' }}%</el-descriptions-item>
|
||||
<el-descriptions-item label="SPUID">{{ product.spuid || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="商品链接">
|
||||
<a :href="product.url || '#'" target="_blank" style="color: #409EFF;">{{ product.url || '-' }}</a>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<!-- 文案版本 -->
|
||||
<div v-if="product.wenan && Array.isArray(product.wenan) && product.wenan.length > 0" style="margin-bottom: 20px;">
|
||||
<h6>文案版本 ({{ product.wenan.length }}个):</h6>
|
||||
<el-tabs v-model="activeWenanTab[productIndex]" type="border-card">
|
||||
<el-tab-pane
|
||||
v-for="(wenan, wenanIndex) in product.wenan"
|
||||
:key="wenanIndex"
|
||||
:label="wenan.type || `版本${wenanIndex + 1}`"
|
||||
:name="wenanIndex"
|
||||
>
|
||||
<el-input
|
||||
:value="wenan.content || ''"
|
||||
type="textarea"
|
||||
:rows="8"
|
||||
readonly
|
||||
style="width: 100%"
|
||||
/>
|
||||
<div style="margin-top: 10px;">
|
||||
<el-button type="success" @click="handleCopyText(wenan.content || '')">复制此版本</el-button>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
|
||||
<!-- 商品图片 -->
|
||||
<div v-if="product.images && Array.isArray(product.images) && product.images.length > 0" style="margin-bottom: 20px;">
|
||||
<h6>商品图片 ({{ product.images.length }}张):</h6>
|
||||
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
|
||||
<div
|
||||
v-for="(image, imageIndex) in product.images"
|
||||
:key="imageIndex"
|
||||
style="text-align: center;"
|
||||
>
|
||||
<img
|
||||
:src="image"
|
||||
:alt="`商品${productIndex + 1}图片${imageIndex + 1}`"
|
||||
style="width: 120px; height: 120px; object-fit: cover; border: 1px solid #ddd; border-radius: 4px;"
|
||||
@click="handlePreviewImage(image)"
|
||||
/>
|
||||
<div style="margin-top: 5px; font-size: 12px; color: #666;">
|
||||
<el-button type="text" size="mini" @click="handleCopyImageUrl(image)">复制链接</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
|
||||
<!-- 原始数据 -->
|
||||
<div style="margin-top: 20px;">
|
||||
<h5>原始数据:</h5>
|
||||
<el-input
|
||||
:value="result"
|
||||
type="textarea"
|
||||
:rows="6"
|
||||
readonly
|
||||
style="width: 100%"
|
||||
/>
|
||||
<div style="margin-top: 10px;">
|
||||
<el-button type="success" @click="handleCopy">复制原始数据</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { generatePromotionContent } from "@/api/system/jdorder";
|
||||
|
||||
export default {
|
||||
name: "Jdorder",
|
||||
data() {
|
||||
return {
|
||||
form: {
|
||||
inputContent: ""
|
||||
},
|
||||
loading: false,
|
||||
result: "",
|
||||
parsedResult: {},
|
||||
// 当前选中的商品
|
||||
activeProductTab: 0,
|
||||
// 每个商品的文案标签页状态
|
||||
activeWenanTab: {}
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
handleGenerate() {
|
||||
if (!this.form.inputContent.trim()) {
|
||||
this.$modal.msgError("请输入需要转链的内容");
|
||||
return;
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
generatePromotionContent({
|
||||
promotionContent: this.form.inputContent.trim()
|
||||
}).then(response => {
|
||||
this.loading = false;
|
||||
if (response.code === 200) {
|
||||
this.result = response.msg || response.data || "转链成功";
|
||||
try {
|
||||
if (typeof this.result === 'string') {
|
||||
this.parsedResult = JSON.parse(this.result);
|
||||
} else {
|
||||
this.parsedResult = this.result;
|
||||
}
|
||||
// 初始化每个商品的文案标签页状态
|
||||
if (Array.isArray(this.parsedResult)) {
|
||||
this.parsedResult.forEach((_, index) => {
|
||||
this.$set(this.activeWenanTab, index, 0);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('数据解析失败,使用原始数据');
|
||||
this.parsedResult = {};
|
||||
}
|
||||
this.$modal.msgSuccess("转链内容生成成功");
|
||||
} else {
|
||||
this.$modal.msgError(response.msg || "转链失败");
|
||||
}
|
||||
}).catch(error => {
|
||||
this.loading = false;
|
||||
console.error('转链失败:', error);
|
||||
this.$modal.msgError("转链失败,请稍后重试");
|
||||
});
|
||||
},
|
||||
|
||||
handleClear() {
|
||||
this.form.inputContent = "";
|
||||
this.result = "";
|
||||
this.parsedResult = {};
|
||||
this.activeProductTab = 0;
|
||||
this.activeWenanTab = {};
|
||||
},
|
||||
|
||||
handleCopy() {
|
||||
if (this.result) {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(this.result).then(() => {
|
||||
this.$modal.msgSuccess("复制成功");
|
||||
}).catch(() => {
|
||||
this.fallbackCopy();
|
||||
});
|
||||
} else {
|
||||
this.fallbackCopy();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
fallbackCopy() {
|
||||
const textArea = document.createElement("textarea");
|
||||
textArea.value = this.result;
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
this.$modal.msgSuccess("复制成功");
|
||||
} catch (err) {
|
||||
this.$modal.msgError("复制失败");
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
},
|
||||
|
||||
handleCopyText(text) {
|
||||
if (text) {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
this.$modal.msgSuccess("复制成功");
|
||||
}).catch(() => {
|
||||
this.fallbackCopyText(text);
|
||||
});
|
||||
} else {
|
||||
this.fallbackCopyText(text);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
fallbackCopyText(text) {
|
||||
const textArea = document.createElement("textarea");
|
||||
textArea.value = text;
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
this.$modal.msgSuccess("复制成功");
|
||||
} catch (err) {
|
||||
this.$modal.msgError("复制失败");
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
},
|
||||
|
||||
handleCopyImageUrl(imageUrl) {
|
||||
if (imageUrl) {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(imageUrl).then(() => {
|
||||
this.$modal.msgSuccess("图片链接复制成功");
|
||||
}).catch(() => {
|
||||
this.fallbackCopyText(imageUrl);
|
||||
});
|
||||
} else {
|
||||
this.fallbackCopyText(imageUrl);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
handlePreviewImage(imageUrl) {
|
||||
window.open(imageUrl, '_blank');
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.box-card {
|
||||
margin: 20px;
|
||||
}
|
||||
|
||||
.clearfix:before,
|
||||
.clearfix:after {
|
||||
display: table;
|
||||
content: "";
|
||||
}
|
||||
.clearfix:after {
|
||||
clear: both;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user