小程序码上增加店铺logo
This commit is contained in:
parent
6bfda106da
commit
3318afed0d
@ -15,6 +15,30 @@ Object.defineProperties(Date.prototype, {
|
|||||||
writable: true
|
writable: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
interface CanvasRenderingContext2D {
|
||||||
|
roundRect(x: number, y: number, w: number, h: number, r: number):CanvasRenderingContext2D
|
||||||
|
}
|
||||||
|
Object.defineProperties(CanvasRenderingContext2D.prototype, {
|
||||||
|
roundRect: {
|
||||||
|
value: function(x: number, y: number, w: number, h: number, r: number) {
|
||||||
|
const minSize = Math.min(w, h)
|
||||||
|
if (r > minSize / 2) r = minSize / 2
|
||||||
|
// 开始绘制
|
||||||
|
this.beginPath()
|
||||||
|
this.moveTo(x + r, y)
|
||||||
|
this.arcTo(x + w, y, x + w, y + h, r)
|
||||||
|
this.arcTo(x + w, y + h, x, y + h, r)
|
||||||
|
this.arcTo(x, y + h, x, y, r)
|
||||||
|
this.arcTo(x, y, x + w, y, r)
|
||||||
|
this.strokeStyle = '#FFF'
|
||||||
|
this.stroke()
|
||||||
|
this.closePath()
|
||||||
|
return this
|
||||||
|
},
|
||||||
|
writable: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
interface Array<T> {
|
interface Array<T> {
|
||||||
/**
|
/**
|
||||||
* 如果数组中没有要放入的对象,则将对象放入数组
|
* 如果数组中没有要放入的对象,则将对象放入数组
|
||||||
|
@ -18,3 +18,8 @@ export default {
|
|||||||
vue.prototype.$local = local
|
vue.prototype.$local = local
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 最后编辑的店铺
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
export const LAST_SHOP = 'last_edit_shop'
|
||||||
|
@ -67,12 +67,12 @@
|
|||||||
v-if="!noShop"
|
v-if="!noShop"
|
||||||
style="width: 40px; height: 40px"
|
style="width: 40px; height: 40px"
|
||||||
:src="vdata.type === 1 ? 'img/icons/wqr.png' : 'img/icons/preview.png'"
|
:src="vdata.type === 1 ? 'img/icons/wqr.png' : 'img/icons/preview.png'"
|
||||||
@click="showPreview(vdata, game._id)"
|
@click="showPreview(vdata, game._id, vdata.image)"
|
||||||
>
|
>
|
||||||
</el-image>
|
</el-image>
|
||||||
<span
|
<span
|
||||||
v-if="vdata.type === 1 && !noShop"
|
v-if="vdata.type === 1 && !noShop"
|
||||||
@click="showPreview(vdata, game._id)"
|
@click="showPreview(vdata, game._id, vdata.image)"
|
||||||
>
|
>
|
||||||
查看小程序码
|
查看小程序码
|
||||||
</span>
|
</span>
|
||||||
@ -105,12 +105,10 @@
|
|||||||
<el-image
|
<el-image
|
||||||
style="width: 100%;"
|
style="width: 100%;"
|
||||||
:src="qrUrl"
|
:src="qrUrl"
|
||||||
:preview-src-list="[qrUrl]"
|
v-show="false"
|
||||||
>
|
>
|
||||||
<div slot="placeholder" class="image-slot">
|
|
||||||
加载中<span class="dot">...</span>
|
|
||||||
</div>
|
|
||||||
</el-image>
|
</el-image>
|
||||||
|
<canvas id="qr_canvas" width="430" height="430"></canvas>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12">
|
<el-col :span="12">
|
||||||
<el-form
|
<el-form
|
||||||
@ -132,6 +130,13 @@
|
|||||||
>
|
>
|
||||||
生成
|
生成
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
type="success"
|
||||||
|
@click="exportCanvasAsPNG"
|
||||||
|
:loading="refreshing"
|
||||||
|
>
|
||||||
|
下载
|
||||||
|
</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<label class="history_list">历史记录</label>
|
<label class="history_list">历史记录</label>
|
||||||
@ -163,6 +168,7 @@ import Sticky from '@/components/Sticky/index.vue'
|
|||||||
import ElImageViewer from 'element-ui/packages/image/src/image-viewer.vue'
|
import ElImageViewer from 'element-ui/packages/image/src/image-viewer.vue'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
getShop,
|
||||||
getShopGameInfo,
|
getShopGameInfo,
|
||||||
getShopGameQr,
|
getShopGameQr,
|
||||||
getShops,
|
getShops,
|
||||||
@ -171,6 +177,7 @@ import {
|
|||||||
import { UserModule } from '@/store/modules/user'
|
import { UserModule } from '@/store/modules/user'
|
||||||
import { EVENT_GAME_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus'
|
import { EVENT_GAME_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus'
|
||||||
import { delay } from '@/utils'
|
import { delay } from '@/utils'
|
||||||
|
import { LAST_SHOP } from '@/utils/storage'
|
||||||
|
|
||||||
declare module 'vue/types/vue' {
|
declare module 'vue/types/vue' {
|
||||||
interface Vue {
|
interface Vue {
|
||||||
@ -199,6 +206,7 @@ export default class extends Vue {
|
|||||||
private gameid = ''
|
private gameid = ''
|
||||||
private versionid = ''
|
private versionid = ''
|
||||||
private qrUrl = ''
|
private qrUrl = ''
|
||||||
|
private shopLogo = ''
|
||||||
private showViewer = false
|
private showViewer = false
|
||||||
private dialogVisible = false
|
private dialogVisible = false
|
||||||
private qrParam = ''
|
private qrParam = ''
|
||||||
@ -229,9 +237,15 @@ export default class extends Vue {
|
|||||||
EventBus.$on(EVENT_SHOP_UPDATE, () => {
|
EventBus.$on(EVENT_SHOP_UPDATE, () => {
|
||||||
this.getRemoteDeptList()
|
this.getRemoteDeptList()
|
||||||
})
|
})
|
||||||
|
if (this.$local.get(LAST_SHOP)) {
|
||||||
|
this.shop = this.$local.get(LAST_SHOP).id
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.shop = UserModule.department
|
this.shop = UserModule.department
|
||||||
}
|
}
|
||||||
|
if (this.shop) {
|
||||||
|
// this.getShopInfo(this.shop)
|
||||||
|
}
|
||||||
EventBus.$on(EVENT_GAME_UPDATE, () => {
|
EventBus.$on(EVENT_GAME_UPDATE, () => {
|
||||||
this.getList()
|
this.getList()
|
||||||
})
|
})
|
||||||
@ -248,6 +262,8 @@ export default class extends Vue {
|
|||||||
private onShopChange() {
|
private onShopChange() {
|
||||||
if (this.shop) {
|
if (this.shop) {
|
||||||
this.getShopGameSetting(this.shop)
|
this.getShopGameSetting(this.shop)
|
||||||
|
this.$local.set(LAST_SHOP, { id: this.shop })
|
||||||
|
// this.getShopInfo(this.shop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,9 +385,10 @@ export default class extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private showPreview(data: IGameVersion, gameId: string) {
|
private showPreview(data: IGameVersion, gameId: string, logo: string) {
|
||||||
this.preGameId = gameId
|
this.preGameId = gameId
|
||||||
this.preVersionId = data._id!
|
this.preVersionId = data._id!
|
||||||
|
this.shopLogo = logo
|
||||||
if (data.type === 1 && data.qr) {
|
if (data.type === 1 && data.qr) {
|
||||||
this.qrUrl = data.qr!
|
this.qrUrl = data.qr!
|
||||||
// this.showViewer = true
|
// this.showViewer = true
|
||||||
@ -382,6 +399,9 @@ export default class extends Vue {
|
|||||||
if (historyData) {
|
if (historyData) {
|
||||||
this.historys = historyData
|
this.historys = historyData
|
||||||
}
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
this.doDraw()
|
||||||
|
}, 500)
|
||||||
} else if (data.url) {
|
} else if (data.url) {
|
||||||
window.open(data.url, '_blank')
|
window.open(data.url, '_blank')
|
||||||
}
|
}
|
||||||
@ -420,6 +440,7 @@ export default class extends Vue {
|
|||||||
const img = await this.getGameQr(this.shop, this.preGameId, this.preVersionId, params)
|
const img = await this.getGameQr(this.shop, this.preGameId, this.preVersionId, params)
|
||||||
await delay(1)
|
await delay(1)
|
||||||
this.qrUrl = img
|
this.qrUrl = img
|
||||||
|
this.doDraw()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.$message({
|
this.$message({
|
||||||
message: '生成二维码出错',
|
message: '生成二维码出错',
|
||||||
@ -441,6 +462,77 @@ export default class extends Vue {
|
|||||||
this.$local.set(key, this.historys)
|
this.$local.set(key, this.historys)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getShopInfo(shop: string) {
|
||||||
|
try {
|
||||||
|
const { data } = await getShop(shop, {})
|
||||||
|
this.shopLogo = data.logo
|
||||||
|
} catch (err) {
|
||||||
|
console.log('err get shop info', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private doDraw() {
|
||||||
|
// 获取canvas
|
||||||
|
const canvas = document.getElementById('qr_canvas')
|
||||||
|
if (!canvas) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
// 可以理解为一个画笔,可画路径、矩形、文字、图像
|
||||||
|
const context = canvas.getContext('2d')
|
||||||
|
context.clearRect(0, 0, 430, 430)
|
||||||
|
const img = new Image()
|
||||||
|
img.src = this.qrUrl
|
||||||
|
img.setAttribute('crossOrigin', 'Anonymous')
|
||||||
|
// 加载图片
|
||||||
|
img.onload = () => {
|
||||||
|
if (img.complete) {
|
||||||
|
// 绘制图片
|
||||||
|
context.drawImage(img, 0, 0, img.width, img.height)
|
||||||
|
this.drawLogo(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private drawLogo(context: any) {
|
||||||
|
const img = new Image()
|
||||||
|
img.src = this.shopLogo
|
||||||
|
img.setAttribute('crossOrigin', 'Anonymous')
|
||||||
|
img.onload = function() {
|
||||||
|
if (img.complete) {
|
||||||
|
// 创建临时的canvas, 缩放图片
|
||||||
|
const canvasTemp = document.createElement('canvas')
|
||||||
|
const contextTemp = canvasTemp.getContext('2d')
|
||||||
|
canvasTemp.width = 430
|
||||||
|
canvasTemp.height = 430
|
||||||
|
contextTemp.drawImage(img, 0, 0, img.width, img.height, 120, 120, 190, 190)
|
||||||
|
const pattern = context.createPattern(canvasTemp, 'no-repeat')
|
||||||
|
|
||||||
|
context.roundRect(120, 120, 190, 190, 95)
|
||||||
|
context.fillStyle = pattern
|
||||||
|
context.fill()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private exportCanvasAsPNG() {
|
||||||
|
const fileName = `${this.shop}.png`
|
||||||
|
const canvasElement = document.getElementById('qr_canvas')
|
||||||
|
|
||||||
|
const MIME_TYPE = 'image/png'
|
||||||
|
|
||||||
|
const imgURL = canvasElement.toDataURL(MIME_TYPE)
|
||||||
|
|
||||||
|
const dlLink = document.createElement('a')
|
||||||
|
dlLink.download = fileName
|
||||||
|
dlLink.href = imgURL
|
||||||
|
dlLink.dataset.downloadurl = [MIME_TYPE, dlLink.download, dlLink.href].join(':')
|
||||||
|
|
||||||
|
document.body.appendChild(dlLink)
|
||||||
|
dlLink.click()
|
||||||
|
document.body.removeChild(dlLink)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
@ -151,6 +151,7 @@ import { getAllCategory, getAllTags } from '@/api/question'
|
|||||||
import { UserModule } from '@/store/modules/user'
|
import { UserModule } from '@/store/modules/user'
|
||||||
import { EVENT_ACTIVITY_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus'
|
import { EVENT_ACTIVITY_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus'
|
||||||
import { deleteMail, getMails, IMailData } from '@/api/mail'
|
import { deleteMail, getMails, IMailData } from '@/api/mail'
|
||||||
|
import { LAST_SHOP } from '@/utils/storage'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
name: 'MailList',
|
name: 'MailList',
|
||||||
@ -210,6 +211,10 @@ export default class extends Vue {
|
|||||||
EventBus.$on(EVENT_SHOP_UPDATE, () => {
|
EventBus.$on(EVENT_SHOP_UPDATE, () => {
|
||||||
this.getRemoteDeptList()
|
this.getRemoteDeptList()
|
||||||
})
|
})
|
||||||
|
if (this.$local.get(LAST_SHOP)) {
|
||||||
|
this.filterForm.sender = this.$local.get(LAST_SHOP).id
|
||||||
|
this.listQuery.sender = this.$local.get(LAST_SHOP).id
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.filterForm.sender = UserModule.department
|
this.filterForm.sender = UserModule.department
|
||||||
this.listQuery.sender = UserModule.department
|
this.listQuery.sender = UserModule.department
|
||||||
|
Loading…
x
Reference in New Issue
Block a user