This commit is contained in:
liushiwei
2023-11-10 10:41:19 +08:00
parent 0016f7e5bc
commit fe6fd6cfdc
4 changed files with 231 additions and 103 deletions

View File

@@ -35,13 +35,13 @@
</el-form>
<div class="bottom flex-center">
<el-button @click="$emit('onClose')"> </el-button>
<el-button type="primary" @click="addToDraft" :loading="isCopying">确定</el-button>
<el-button type="primary" @click="toAddToDraft" :loading="isCopying">确定</el-button>
</div>
</div>
</template>
<script>
import {sendChromeAPIMessage, sendChromeWebReqMessage} from '@/api/chromeApi'
import {sendChromeAPIMessage, sendTemuAPIMessage, sendChromeWebReqMessage} from '@/api/chromeApi'
import AiLazyCascader from "@/components/AiLazyCascader.vue"
import { Message } from 'element-ui'
@@ -109,7 +109,8 @@ export default {
goods: {},
sku: {},
productDetail: {},
isCopying: false
isCopying: false,
goodsId: ''
}
},
created () {
@@ -118,102 +119,159 @@ export default {
}
},
methods: {
async addToDraft() {
this.$refs.form.validate((valid) => {
if (valid) {
this.isCopying = true
this.$http.post('/api/copyProduct/check',null, {params: {type: 0}}).then(res => {
if (res.code == 0) {
let source
if (this.form.type == '1') {
source = 'temu'
} else if (this.form.type == '2') {
source = 'aliexpress'
}
sendChromeWebReqMessage({
type: source,
url: this.form.url,
}).then((res) => {
if (this.form.type == '1') {
if (res.indexOf("window.rawData") == -1) {
this.isCopying = false
Message.error("请检查地址是否正确或者“TEMU”网站是否出现图形验证码")
return
}
let str = res.substring(res.indexOf("window.rawData"))
str = str.substring(0, str.indexOf("<\/script>"))
str = str.substring(str.indexOf("{"))
str = str.substring(0, str.lastIndexOf("}"))
str = str + "}"
let goodsObj = JSON.parse(str)
this.goods = goodsObj.store.goods
this.sku = goodsObj.store.sku
this.productDetail = goodsObj.store.productDetail
let specIds = []
this.sku.forEach(item => {
item.specs.forEach(item1 => {
let flag = false
specIds.forEach(item2 => {
if (item2.specValue == item1.specValue) {
flag = true
}
})
if (!flag) {
specIds.push({specKeyId: item1.specKeyId, specValue: item1.specValue})
}
})
})
Promise.all(specIds.map(item => this.getSpecId(item).then(res => {
this.sku.forEach(item1 => {
item1.specs.forEach(item2 => {
if (item2.specValue == item.specValue) {
item2.specValueId = res.result.specId
}
})
})
return 0
}))).then(() => {
this.$http.post('/api/copyProduct/translate',{type: 1, goods: this.goods, sku: this.sku, productDetail: this.productDetail}).then(res => {
if (res.code == 0) {
this.createDraft(res.data)
}
})
})
} else if (this.form.type == '2') {
/*if (res.indexOf("runParams") == -1) {
Message.error("请检查地址是否正确,或者“速卖通”网站是否出现滑动条")
return
}
let str = res.substring(res.indexOf("runParams"))
str = str.substring(0, str.indexOf("<\/script>"))
str = str.substring(str.indexOf("{"))
str = str.substring(0, str.lastIndexOf("}"))
str = str.substring(str.indexOf('data'))
str = str.substring(5)
let obj = JSON.parse(str)
sendChromeWebReqMessage({
type: source,
url: obj.productDescComponent.descriptionUrl,
}).then((res1) => {
res1 = res1.substring(0, res1.indexOf("<script>"))
let str = res1.replace(/<img[^>]+src="([^">]+)"[^>]+>/g, '$1\n').replace(/<.*?>/g, '[||]')
let arr = str.split('[||]')
for (let i = 0; i < arr.length; i++) {
console.log(arr[i])
}
})*/
}
})
} else {
this.isCopying = false
}
})
toAddToDraft() {
if (!this.form.url.startsWith("http")) {
this.goodsId = this.form.url
this.addToDraftNew()
} else {
let t = this.form.url
let urlParams = this.parseURL(t)
t = t.substring(0,t.indexOf(".html"))
if (t.lastIndexOf("-g-") > 0) {
t = t.substring(t.lastIndexOf("-g-"), t.length);
t = t.substring(3, t.length);
this.goodsId = t
this.addToDraftNew()
} else if(urlParams.params) {
let goodsId = urlParams.params.goods_id
if (!goodsId) {
this.addToDraft()
} else {
this.goodsId = goodsId
this.addToDraftNew()
}
} else {
this.addToDraft()
}
}
},
async addToDraftNew() {
this.$refs.form.validate((valid) => {
if (valid) {
this.isCopying = true
sendTemuAPIMessage({
url: 'api/oak/integration/render',
anti: true,
data: {
goods_id: this.goodsId
}}).then((res) => {
if (!res.goods) {
this.isCopying = false
Message.error("获取商品信息失败,采集失败")
return
}
this.goods = res.goods
this.sku = res.sku
this.productDetail = res.product_detail
let specIds = []
this.sku.forEach(item => {
item.specs.forEach(item1 => {
let flag = false
specIds.forEach(item2 => {
if (item2.spec_value == item1.spec_value) {
flag = true
}
})
if (!flag) {
specIds.push({spec_key_id: item1.spec_key_id, spec_value: item1.spec_value})
}
})
})
Promise.all(specIds.map(item => this.getSpecIdNew(item).then(res => {
this.sku.forEach(item1 => {
item1.specs.forEach(item2 => {
if (item2.spec_value == item.spec_value) {
item2.spec_value_id = res.result.specId
}
})
})
return 0
}))).then(() => {
this.$http.post('/api/copyProduct/translateNew',{type: 1, goods: this.goods, sku: this.sku, productDetail: this.productDetail}).then(res => {
if (res.code == 0) {
this.createDraft(res.data)
}
})
})
})
}
})
},
async addToDraft() {
this.$refs.form.validate((valid) => {
if (valid) {
this.isCopying = true
this.$http.post('/api/copyProduct/check',null, {params: {type: 0}}).then(res => {
if (res.code == 0) {
let source
if (this.form.type == '1') {
source = 'temu'
} else if (this.form.type == '2') {
source = 'aliexpress'
}
sendChromeWebReqMessage({
type: source,
url: this.form.url,
}).then((res) => {
if (this.form.type == '1') {
if (res.indexOf("window.rawData") == -1) {
this.isCopying = false
Message.error("请检查地址是否正确或者“TEMU”网站是否出现图形验证码")
return
}
let str = res.substring(res.indexOf("window.rawData"))
str = str.substring(0, str.indexOf("<\/script>"))
str = str.substring(str.indexOf("{"))
str = str.substring(0, str.lastIndexOf("}"))
str = str + "}"
let goodsObj = JSON.parse(str)
this.goods = goodsObj.store.goods
this.sku = goodsObj.store.sku
this.productDetail = goodsObj.store.productDetail
let specIds = []
this.sku.forEach(item => {
item.specs.forEach(item1 => {
let flag = false
specIds.forEach(item2 => {
if (item2.specValue == item1.specValue) {
flag = true
}
})
if (!flag) {
specIds.push({specKeyId: item1.specKeyId, specValue: item1.specValue})
}
})
})
Promise.all(specIds.map(item => this.getSpecId(item).then(res => {
this.sku.forEach(item1 => {
item1.specs.forEach(item2 => {
if (item2.specValue == item.specValue) {
item2.specValueId = res.result.specId
}
})
})
return 0
}))).then(() => {
this.$http.post('/api/copyProduct/translate',{type: 1, goods: this.goods, sku: this.sku, productDetail: this.productDetail}).then(res => {
if (res.code == 0) {
this.createDraft(res.data)
}
})
})
} else if (this.form.type == '2') {
console.log(1)
}
})
} else {
this.isCopying = false
}
})
}
})
},
createDraft(data) {
@@ -263,6 +321,22 @@ export default {
}
})
},
getSpecIdNew(data) {
return sendChromeAPIMessage({
url: 'bg-anniston-mms/sku/spec/byName/queryOrAdd',
needMallId: true,
mallId: this.form.targetMallId,
data: {
parentSpecId: data.spec_key_id,
specName: data.spec_value
}}).then((res) => {
if (res.errorCode == 1000000) {
return res
} else {
this.getSpecIdNew(data)
}
})
},
getSpecId(data) {
return sendChromeAPIMessage({
url: 'bg-anniston-mms/sku/spec/byName/queryOrAdd',
@@ -294,6 +368,33 @@ export default {
this.$emit('onSuccess')
}
})
},
parseURL(url) {
let a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':',''),
host: a.hostname,
port: a.port,
query: a.search,
params: (function(){
var ret = {},
seg = a.search.replace(/^\?/,'').split('&'),
len = seg.length, i = 0, s;
for (;i<len;i++) {
if (!seg[i]) { continue; }
s = seg[i].split('=');
ret[s[0]] = s[1];
}
return ret;
})(),
file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
hash: a.hash.replace('#',''),
path: a.pathname.replace(/^([^\/])/,'/$1'),
relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
segments: a.pathname.replace(/^\//,'').split('/')
};
}
}
}

View File

@@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "TEMU助手",
"description": "TEMU助手 - 自动化提高生产效率",
"version": "3.0.7",
"version": "3.0.8",
"background": {
"service_worker": "/background.js"
},

View File

@@ -45,7 +45,8 @@
@getList="getList">
<el-table-column slot="url" label="商品地址" align="left">
<template slot-scope="scope">
<div><a class="el-link el-link--primary" :href="scope.row.url" target="_blank">{{ scope.row.url }}</a></div>
<div v-if="scope.row.url.startsWith('http')"><a class="el-link el-link--primary" :href="scope.row.url" target="_blank">{{ scope.row.url }}</a></div>
<div v-else><a class="el-link el-link--primary" :href="'https://www.temu.com/goods.html?goods_id=' + scope.row.url" target="_blank">{{ scope.row.url }}</a></div>
</template>
</el-table-column>
</ai-table>

View File

@@ -26,7 +26,8 @@
<el-input :clearable="true" size="small" style="width: 80px" v-model="search.saleBegin" ></el-input>
~
<el-input :clearable="true" size="small" style="width: 80px" v-model="search.saleEnd" ></el-input>
<label style="width:100px">仅显示最新</label>
<ai-select :selectList="$dict.getDict('mall_yesno')" v-model="search.isNew"></ai-select>
</template>
<template #right>
<el-button type="primary" @click="search.current =1, getList()">查询</el-button>
@@ -38,7 +39,10 @@
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr; gap: 16px;">
<el-card v-for="item in tableData" :key="item.id" :body-style="{ padding: '0px', margin: '5px' }">
<el-image :src="item.imgUrl" class="image" :preview-src-list="[item.imgUrl]" />
<span class="nav-label labelBadge">
<span class="ii" v-if="item.isNew == 1"></span>
<el-image :src="item.imgUrl" class="image" :preview-src-list="[item.imgUrl]" />
</span>
<div style="padding: 14px;">
<div class="bottom clearfix">
<div style="margin-bottom: 5px;">
@@ -96,7 +100,8 @@ import AiProductDropDown from '@/components/AiProductDropDown.vue';
priceBegin: '',
priceEnd: '',
saleBegin: '',
saleEnd: ''
saleEnd: '',
isNew: ''
},
orderBys: [{
value: '0',
@@ -122,6 +127,7 @@ import AiProductDropDown from '@/components/AiProductDropDown.vue';
},
created () {
this.$dict.load('mall_yesno');
this.monitorId = this.params.id
this.getList()
},
@@ -215,4 +221,24 @@ import AiProductDropDown from '@/components/AiProductDropDown.vue';
.el-icon-arrow-down {
font-size: 12px;
}
/*徽标*/
.labelBadge {
position: relative;
}
.ii {
background: #f00;
border-radius: 50%;
width: 20px;
height: 20px;
top: -3px;
right: -5px;
position: absolute;
text-align: center;
color: #FFF;
z-index: 999;
font-size: 14px;
}
</style>