Commit bcd044e2 by 杨明

fixed

1 parent 5107f663
/*
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-05-19 13:46:20
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-05-30 14:30:14
* @FilePath: \scrm-micro-home\src\mixins\gpt.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { mapState, mapActions } from 'vuex'
import Drawing from '@/utils/drawing'
export default {
data() {
return {
cavansObj: {
1: {
titleStyle: {
x: 82,
y: 224,
fontSize: 52,
color: '#AD604C'
},
subTitleStyle: {
x: 66,
y: 362,
fontSize: 28,
color: '#AD604C'
}
},
2: {
titleStyle: {
x: 10,
y: 104,
fontSize: 54,
color: '#185D5E'
},
subTitleStyle: {
x: 10,
y: 176,
fontSize: 16,
color: '#185D5E'
}
}
}
}
},
methods: {
//主图、内容图、logo合并图片
async createCanvas() {
this.loading = true
const { backgroundImage, detailImage, merchantLog, marketingTitle, marketingSubtitle } = this.editForm
if (!backgroundImage) return
try {
const res = await Promise.all([this.getImgWH(backgroundImage), this.getImgWH(detailImage), this.getImgWH(merchantLog)])
const h = (res[0].dh / res[0].dw) * 375 + (res[1].dh / res[1].dw) * 375
this.logoInfo = { url: merchantLog, x: 375 - res[2].dw / 2 - 20, y: 20, width: res[2].dw / 2, height: res[2].dh / 2 }
const drawfun = new Drawing(document.getElementById('canvasId'), {
width: 375,
height: h
}),
imageList = [
{
url: backgroundImage,
x: 0,
y: 0,
width: 375,
height: (res[0].dh / res[0].dw) * 375
},
{
url: detailImage,
x: 0,
y: (res[0].dh / res[0].dw) * 375,
width: 375,
height: (res[1].dh / res[1].dw) * 375
},
{ ...this.logoInfo }
].filter(item => item.url)
let textList = [],
title = this.cavansObj[this.editForm.templateId]
if (title) {
marketingTitle.split(' ').forEach((item, index) => {
textList.push({
x: title.titleStyle.x,
y: title.titleStyle.y + index * 60,
fontSize: title.titleStyle.fontSize,
color: title.titleStyle.color,
text: item
})
})
new Array(marketingSubtitle).forEach((item, index) => {
textList.push({
x: title.subTitleStyle.x,
y: title.subTitleStyle.y + index * 60,
fontSize: title.subTitleStyle.fontSize,
color: title.subTitleStyle.color,
text: item
})
})
}
console.log(title, textList)
const canvasBase64 = await drawfun.begin({
imageList,
textList
})
await this.uploadImg(canvasBase64)
this.addOrUpdate()
} catch (e) {
console.log(e)
}
}
},
mounted() {}
}
......@@ -2,7 +2,7 @@
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-05-16 17:13:33
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-05-24 14:45:33
* @LastEditTime: 2023-05-26 16:19:48
* @FilePath: \scrm-micro-home\src\store\modules\marketing.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
......@@ -22,6 +22,7 @@ export default {
schemeList: {
list: []
},
mergeImg: {},
keywords: '',
GPTList: null,
merchantInfo: {}
......@@ -51,6 +52,10 @@ export default {
SET_KET_WORDs(state, data) {
state.keywords = data
},
// 设置合并图片
SET_MERGE_IMG(state, data) {
state.mergeImg = data
},
['SET_CALENDAR_DATA'](state, payload) {
state.calendarData = payload.calendarData
},
......@@ -83,6 +88,9 @@ export default {
setActivityProject({ commit }, data) {
commit('SET_ACTIVITY_PEOJECT', data)
},
setMergeImg({ commit }, data) {
commit('SET_MERGE_IMG', data)
},
setKeyWords({ commit, state }, data) {
if (state.keywords == data) return
commit('SET_KET_WORDs', data)
......
......@@ -2,40 +2,70 @@
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-05-17 16:07:55
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-05-18 09:58:54
* @LastEditTime: 2023-05-30 12:57:42
* @FilePath: \scrm-micro-home\src\utils\drawing.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
class Drawing {
constructor(canvasParams, list = [], fn) {
this.count = 0
this.fn = fn
this.list = list
this.canvasId = document.createElement('canvas')
constructor(el, canvasParams) {
this.canvasId = el
const { width, height } = canvasParams
this.canvasId.width = width
this.canvasId.height = height
this.ctx = this.canvasId.getContext('2d')
}
drawImages(fn) {
const { imgSrc, x, y, width, height } = this.list[this.count]
async drawImages(imageParams, callback) {
this.ctx.beginPath()
this.ctx.save()
let { height, width, url, x, y } = imageParams
let image = this.createImage()
image.src = imgSrc
this.count++
image.onload = () => {
this.ctx.drawImage(image, x, y, width, height)
console.log(this.count, this.list.length)
if (this.count === this.list.length) {
this.fn(this.canvasId.toDataURL('image/png'))
} else {
this.drawImages()
image.src = url
return new Promise(resolve => {
image.onload = () => {
setTimeout(() => {
this.ctx.drawImage(image, x, y, width, height)
// 再将图片填充到画布
let pattern = this.ctx.createPattern(image, 'no-repeat')
this.ctx.fillStyle = pattern
resolve(imageParams)
}, 3000)
}
}
})
}
drawText(textParams) {
const { fontSize, color, text, x, y } = textParams
console.log(x, y)
this.ctx.font = `${fontSize}px Calibri`
this.ctx.fillStyle = color
this.ctx.fillText(text, x, y + fontSize)
}
createImage() {
let image = new Image()
image.setAttribute('crossOrigin', 'Anonymous')
return image
}
async begin(data = {}) {
return new Promise(async (resolve, reject) => {
const drawFun = () => {
data.textList &&
data.textList.length &&
data.textList.map(e => {
this.drawText(e)
})
console.log(this.canvasId.toDataURL('image/png'))
resolve(this.canvasId.toDataURL('image/png'))
}
if (data.imageList && data.imageList.length) {
await this.drawImages(data.imageList[0])
if (data.imageList.length > 1)
for (let index = 1; index < data.imageList.length; index++) {
await this.drawImages(data.imageList[index])
if (index == data.imageList.length - 1) drawFun()
}
else drawFun()
} else drawFun()
})
}
}
export default Drawing
......@@ -2,7 +2,7 @@
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2023-05-16 10:20:01
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-05-22 15:10:15
* @LastEditTime: 2023-05-26 18:26:10
* @FilePath: \scrm-micro-home\src\views\home\components\Marketing\ChatGPT.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
......@@ -96,8 +96,8 @@ export default {
chatRef.scrollTop = height //滚动到最底部
})
},
activityInfo() {
this.chatItem = []
activityInfo(val) {
if (val.id) this.chatItem = []
}
},
methods: {
......
......@@ -2,7 +2,7 @@
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-05-16 10:23:52
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-05-25 16:24:02
* @LastEditTime: 2023-05-30 14:26:42
* @FilePath: \scrm-micro-home\src\views\home\components\Marketing\GPTAnalysis.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
......@@ -195,12 +195,12 @@ import selectGiftDialog from './selectGiftDialog'
import selectGoodsDialog from './selectGoodsDialog'
import selectEquityDialog from './selectEquityDialog'
import selectEmpDialog from './selectEmpDialog'
import Drawing from '@/utils/drawing'
import getUploadImgColor from '@/utils/color'
import { mapState, mapActions } from 'vuex'
import gpt from '@/mixins/gpt'
import draw from '@/mixins/draw'
export default {
mixins: [gpt],
mixins: [gpt, draw],
name: 'analysis',
data() {
return {
......@@ -406,8 +406,7 @@ export default {
goodsStock: [{ required: true, message: '请输入库存', trigger: 'input' }],
merchantname: [{ required: true, message: '请输入门店名称', trigger: 'input' }],
merchantAddress: [{ required: true, message: '请选择门店地址', trigger: 'input' }],
serviceHotline: [{ required: true, message: '请输入服务热线', trigger: 'input' }],
merchantLog: [{ required: true, message: '请选择门店Logo', trigger: 'change' }]
serviceHotline: [{ required: true, message: '请输入服务热线', trigger: 'input' }]
}
}
},
......@@ -415,22 +414,17 @@ export default {
computed: {
...mapState('marketing', ['activityInfo', 'GPTList', 'merchantInfo']),
mergeStr() {
const { backgroundImage, detailImage, merchantLog } = this.editForm
return [backgroundImage, detailImage, merchantLog]
const { backgroundImage, detailImage, merchantLog, mainColor, logoInfo, marketingTitle, marketingSubtitle, templateId } = this.editForm
return [backgroundImage, detailImage, merchantLog, mainColor, logoInfo, marketingTitle, marketingSubtitle, templateId]
}
},
watch: {
activityInfo(val) {
val && this.confirmMsg(val)
},
//监听主图、内容图、logo
mergeStr(val) {
if (val && val.every(item=>item)) {
this.getMergeImgs()
} else {
this.editForm.bigImage = null
}
console.log(this.editForm.bigImage)
console.log(val, 999999999999)
this.setMergeImg(val)
}
},
components: {
......@@ -440,7 +434,7 @@ export default {
selectEmpDialog
},
methods: {
...mapActions('marketing', ['setActivityInfo', 'setSchemeListData']),
...mapActions('marketing', ['setActivityInfo', 'setSchemeListData', 'setMergeImg']),
//获取优惠券模板
couponTemplate() {
this.$apis.giftBag.couponTemplate({ pageSize: 10000, pageNum: 1 }).then(res => {
......@@ -496,6 +490,9 @@ export default {
//获取图片宽度高度
getImgWH(src) {
return new Promise(resolve => {
if (!src) {
resolve({ dw: 0, dh: 0, src })
}
const img = new Image()
img.src = src
img.onload = () => {
......@@ -504,55 +501,14 @@ export default {
})
},
uploadImg(imgFile) {
const base64 = 'png' + '@' + imgFile.split(',')[1]
this.$apis.common.pictureUpload({ file: base64, fileType: 'image' }).then(res => {
this.editForm.bigImage = res
return new Promise((resolve, reject) => {
const base64 = 'png' + '@' + imgFile.split(',')[1]
this.$apis.common.pictureUpload({ file: base64, fileType: 'image' }).then(res => {
this.editForm.bigImage = res
resolve()
})
})
},
//主图、内容图、logo合并图片
async getMergeImgs() {
const { backgroundImage, detailImage, merchantLog } = this.editForm
try {
const res = await Promise.all([this.getImgWH(backgroundImage), this.getImgWH(detailImage), this.getImgWH(merchantLog)])
const h = (res[0].dh / res[0].dw) * 375 + (res[1].dh / res[1].dw) * 375
this.logoInfo = {
imgSrc: merchantLog,
x: 375 - res[2].dw/2 - 20,
y: 20,
width: res[2].dw / 2,
height: res[2].dh / 2
}
const draw = new Drawing(
{
width: 375,
height: h
},
[
{
imgSrc: backgroundImage,
x: 0,
y: 0,
width: 375,
height: (res[0].dh / res[0].dw) * 375
},
{
imgSrc: detailImage,
x: 0,
y: (res[0].dh / res[0].dw) * 375,
width: 375,
height: (res[1].dh / res[1].dw) * 375
},
{ ...this.logoInfo }
],
base64 => {
this.uploadImg(base64)
}
)
draw.drawImages()
} catch (e) {
console.log(e)
}
},
//选择门店优惠券
handleGiftAdd() {
this.selectedMealList = JSON.parse(JSON.stringify(this.couponObj))
......@@ -582,7 +538,7 @@ export default {
handleEmpConfirm(selectedData) {
this.editForm.followStaff = selectedData.staffId
this.handleEmpClose()
this.addOrUpdate()
this.createCanvas()
},
handleEquityConfirm(selectedData) {
this.selectedEquityList = selectedData
......@@ -672,7 +628,8 @@ export default {
},
getViewParams() {
const prams = this.getCouponInfoParams()
return { ...prams, selectedEquityList: this.selectedEquityList, couponList: this.editForm.superMarketingCouponRelRequestList, selectedGoodsList: this.selectedGoodsList, logoInfo: this.logoInfo,bigImage:this.editForm.bigImage }
console.log(prams)
return { ...prams, selectedEquityList: this.selectedEquityList, couponList: this.editForm.superMarketingCouponRelRequestList, selectedGoodsList: this.selectedGoodsList }
},
getCouponInfoParams() {
var param = this.$common.utils.deepClone(this.editForm)
......@@ -705,6 +662,9 @@ export default {
delete param.activityCouponBaseInfoDTOS
return param
},
handleCancel() {
this.$router.push('/home/index')
},
handleConfirm() {
if (this.selectedGoodsList.length + this.editForm.superMarketingCouponRelRequestList.length + this.selectedGoodsList.length == 0) {
this.$message.error('权益服务、平台优惠、门店优惠券至少选一项')
......@@ -712,7 +672,11 @@ export default {
}
this.$refs.editFormRef.$refs[this.editChildRef].validate(valid => {
if (valid) {
this.isSelectEmpVisible = true
if (this.importNum) {
this.isSelectEmpVisible = true
} else {
this.createCanvas()
}
}
})
},
......@@ -735,9 +699,12 @@ export default {
const { id } = this.activityInfo
this.$apis.activity.getCalendarDatail({ id }).then(res => {
this.setActivityInfo()
const { title, subTitle, startTime, endTime, couponItemList } = this.$common.utils.deepClone(res.data || {})
const { title, subTitle, startTime, endTime, couponItemList, backgroundImg, captionImg } = this.$common.utils.deepClone(res.data || {})
this.editForm.templateId = id
this.editForm.marketingTitle = title
this.editForm.marketingSubtitle = subTitle
this.editForm.backgroundImage = backgroundImg
this.editForm.detailImage = captionImg
this.editForm.activityTime = [startTime + ' 00:00:00', endTime + ' 00:00:00']
this.selectedGoodsList = couponItemList
this.selectedGoodsList.forEach(item => {
......
......@@ -2,7 +2,7 @@
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2023-05-15 15:08:32
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-05-25 16:24:16
* @LastEditTime: 2023-05-30 14:27:42
* @FilePath: \scrm-micro-home\src\views\home\components\Marketing\MarketingRight.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
......@@ -23,38 +23,29 @@ export default {
getComponent: ''
}
},
mounted() {
setTimeout(() => {
let children = this.$parent.$children
this.findComponent(children)
}, 300)
},
components: {
PhoneView
},
computed: {
...mapState('marketing', ['activityInfo']),
imgArr() {
const { backgroundImage, detailImage, merchantLog, mainColor, logoInfo,bigImage } = this.getComponent && this.getComponent.getViewParams()
return [backgroundImage, detailImage, merchantLog, mainColor, logoInfo,bigImage]
}
...mapState('marketing', ['activityInfo', 'mergeImg'])
},
watch: {
imgArr(val) {
const [backgroundImage = '', detailImage = '', merchantLog = '', mainColor, logoInfo,bigImage] = val
this.activityDetail = { ...this.activityDetail, ...{ backgroundImage, detailImage, merchantLog, mainColor, logoInfo,bigImage } }
console.log(this.activityDetail)
},
activityInfo(val) {
this.activityDetail = {}
console.log(this.activityDetail)
mergeImg: {
handler(val) {
const [backgroundImage = '', detailImage = '', merchantLog = '', mainColor, logoInfo, marketingTitle, marketingSubtitle,templateId] = val
this.activityDetail = { ...this.activityDetail, ...{ backgroundImage, detailImage, merchantLog, mainColor, logoInfo, marketingTitle, marketingSubtitle,templateId } }
},
deep: true
}
// activityInfo(val) {
// this.activityDetail = {}
// }
},
methods: {
findComponent(children) {
for (let i = 0; i < children.length; i++) {
if (children[i].$options.componentsName == 'analysis') {
this.getComponent = children[i]
this.activityDetail = children[i].getViewParams()
return
}
if (children[i].$children) {
......@@ -63,8 +54,8 @@ export default {
}
},
renewImg() {
this.activityDetail = this.getComponent.getViewParams()
console.log(this.activityDetail)
let children = this.$parent.$children
this.findComponent(children)
}
}
}
......
......@@ -2,23 +2,20 @@
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2023-05-15 15:08:32
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-05-25 16:22:34
* @LastEditTime: 2023-05-30 14:34:01
* @FilePath: \scrm-micro-home\src\views\home\components\Marketing\MarketingRight.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
<div class="review-body">
<canvas id="canvasId"></canvas>
<template v-if="isSuper">
<img src="@/assets/img/phone.png" class="review-phone" />
<div class="review-title_top">{{ detail.marketingTitle || detail.activityName }}</div>
<div class="review-content">
<div class="review-main">
<template v-if="detail.activityBigImg || detail.bigImage">
<div class="review-bg-img">
<img :src="detail.activityBigImg || detail.bigImage" />
</div>
</template>
<template v-else>
<template>
<div class="main-title" :style="{ top: item.y + 'px', left: item.x + 'px', 'font-size': item.fontSize + 'px', color: item.color }" v-for="(item, index) in textList" :key="index">{{ item.text }}</div>
<div class="review-bg-img">
<img :src="detail.backgroundImage" v-if="detail.backgroundImage" />
</div>
......@@ -98,11 +95,14 @@
</template>
<script>
import PhoneViewA from './PhoneViewA'
import draw from '@/mixins/draw'
export default {
mixins: [draw],
data() {
return {
detail: {},
logoInfo: {},
textList: [],
discount: {
2: '折扣券',
3: '代金券',
......@@ -128,7 +128,32 @@ export default {
activityInfo: {
handler(val) {
this.detail = val
if(!this.detail.logoInfo)return
const title = this.cavansObj[this.detail.templateId],
{ marketingTitle, marketingSubtitle } = this.detail,
textList = []
console.log(this.detail)
if (title) {
marketingTitle.split(' ').forEach((item, index) => {
textList.push({
x: (title.titleStyle.x)*.7,
y: (title.titleStyle.y + index * 60)*.7,
fontSize: title.titleStyle.fontSize*.7,
color: title.titleStyle.color,
text: item
})
})
new Array(marketingSubtitle).forEach((item, index) => {
textList.push({
x: title.subTitleStyle.x*.7,
y: (title.subTitleStyle.y + index * 60)*.7,
fontSize: title.subTitleStyle.fontSize*.7,
color: title.subTitleStyle.color,
text: item
})
})
}
this.textList = textList
if (!this.detail.logoInfo) return
const { x, y, height, width } = this.detail.logoInfo
this.logoInfo = {
x: (x * 262) / 375,
......@@ -149,6 +174,10 @@ export default {
width: 288px;
height: 645px;
position: relative;
#canvasId {
display: none;
transform: translate(-56px, -328px) scale(0.69);
}
.review-phone {
width: 100%;
}
......@@ -180,6 +209,10 @@ export default {
left: 13px;
.review-main {
position: relative;
overflow: hidden;
.main-title {
position: absolute;
}
.review-logo-img {
position: absolute;
width: 50px;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!