Browse Source

上传

hfll
前端-胡立永 3 months ago
parent
commit
84fc41733e
5 changed files with 295 additions and 95 deletions
  1. +6
    -6
      components/product/productItem.vue
  2. +4
    -3
      pages/index/center.vue
  3. +216
    -0
      pages_order/mine/promotion - 副本.vue
  4. +65
    -86
      pages_order/mine/promotion.vue
  5. +4
    -0
      store/store.js

+ 6
- 6
components/product/productItem.vue View File

@ -52,23 +52,23 @@
<view class="price">
<view class="money">
<text>{{ item.goldPrice }}</text>
<text>{{ item.silverPrice }}</text>
<text class="unit">/元每件</text>
</view>
<view class="price-imgs">
<image :src="configList.vip_money_one" mode="aspectFill"
class="price-img"></image>
<image :src="configList.vip_money_one" mode="aspectFill" class="price-img">
</image>
</view>
</view>
<view class="price">
<view class="money">
<text>{{ item.silverPrice }}</text>
<text>{{ item.goldPrice }}</text>
<text class="unit">/元每件</text>
</view>
<view class="price-imgs">
<image :src="configList.vip_money_two" mode="aspectFill" class="price-img">
</image>
<image :src="configList.vip_money_two" mode="aspectFill"
class="price-img"></image>
</view>
</view>


+ 4
- 3
pages/index/center.vue View File

@ -116,7 +116,7 @@
<view class="box">
<view class="boxs" @click="$utils.navigateTo('/pages_order/mine/recruit')">
<image src="@/static/image/center/5.png" mode="widthFix" />
<view class="title">广告招商</view>
<view class="title">合伙人招募</view>
</view>
<view class="boxs" @click="$utils.navigateTo('/pages_order/mine/memberCenter')">
<image src="@/static/image/center/6.png" mode="widthFix" />
@ -145,7 +145,8 @@
</view>
<!-- 广告 -->
<!-- <div v-if="showAdvertising" class="ad">
<div v-if="showAdvertising" class="ad"
@click="$utils.navigateTo('/pages_order/mine/recruit')">
<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="true" :interval="2000"
:duration="duration">
<swiper-item v-for="(item, index) in adList" :key="index">
@ -160,7 +161,7 @@
</view>
</swiper-item>
</swiper>
</div> -->
</div>
<customerServicePopup ref="customerServicePopup" />


+ 216
- 0
pages_order/mine/promotion - 副本.vue View File

@ -0,0 +1,216 @@
<template>
<view class="promotion">
<navbar title="二维码"
bgColor="#E3441A"
color="#fff"
leftClick @leftClick="$utils.navigateBack" />
<view class="promotion-card">
<image :src="userInfo.headImage" mode="aspectFill"
class="headImage"></image>
<image style="width: 100%;" :src="imagePath" mode="widthFix"></image>
<!-- <view class="invitation-code">加油站: {{ title }}</view> -->
<canvas id="myCanvas" type="2d" canvas-id="firstCanvas1"></canvas>
<view class="uni-color-btn"
@click="preservationImg(imagePath)">保存二维码</view>
</view>
</view>
</template>
<script>
import { mapState } from 'vuex'
export default {
name: 'Promotion',
computed: {
...mapState(['userInfo']),
},
data() {
return {
url: '',
title: '',
baseUrl: 'https://image.hhlm1688.com/',
canvas: {},
imagePath: '',
}
},
onShow() {
this.getQrCode()
this.$store.commit('getUserInfo')
},
methods: {
getQrCode() {
this.$api('getInviteCode', res => {
if (res.code == 200) {
this.url = res.result.url
this.title = res.result.name
this.draw()
}
})
},
draw() {
uni.showLoading({
title: "拼命绘画中..."
})
wx.createSelectorQuery()
.select('#myCanvas') // canvasid
.fields({
node: true,
size: true
})
.exec((res) => {
const canvas = res[0].node
//
const ctx = canvas.getContext('2d')
// Canvas
const width = res[0].width
const height = res[0].height
//
const dpr = wx.getWindowInfo().pixelRatio
//dpr
// dpr 2 4
// 3 6
let Ratio = dpr * 2
console.log("bug", dpr)
canvas.width = width * dpr
canvas.height = height * dpr
this.canvas = canvas
ctx.scale(dpr, dpr)
ctx.clearRect(0, 0, width, height)
ctx.fillStyle = '#fff'
ctx.fillRect(0, 0, canvas.width, canvas.height)
//
// const image = canvas.createImage()
// image.onload = () => {
// ctx.drawImage(image, 30, 18, 40, 40)
// }
// image.src = '/public/img/wechar_1.png'
// image.src = this.userInfo.headImage
ctx.fillStyle = 'black'
ctx.font = '22px PingFangSC-regular';
//
// let nickName = this.userInfo.nickName || ''
// ctx.fillText(nickName, canvas.width / Ratio - nickName.length * 11, 40);
// ctx.font = '18px PingFangSC-regular';
//
let s = this.title || ''
ctx.fillText(s, canvas.width / Ratio - s.length * 11, 50);
//
const coderImage = canvas.createImage()
coderImage.src = this.baseUrl + this.url
coderImage.onload = () => {
ctx.drawImage(coderImage,
canvas.width / Ratio - 240 / 2, 100, 240, 240)
}
//
setTimeout(() => {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: this.canvas.width,
height: this.canvas.height,
canvas,
success: (res) => {
var tempFilePath = res.tempFilePath;
this.imagePath = tempFilePath
uni.hideLoading()
}
});
}, 600);
})
},
back() {
uni.navigateBack(-1)
},
async preservationImg(img) {
await this.$authorize('scope.writePhotosAlbum')
this.imgApi(img);
},
imgApi(image) {
/* 获取图片的信息 */
uni.getImageInfo({
src: image,
success: function(image) {
/* 保存图片到手机相册 */
uni.saveImageToPhotosAlbum({
filePath: image.path,
success: function() {
uni.showModal({
title: '保存成功',
content: '图片已成功保存到相册',
showCancel: false
});
},
complete(res) {
console.log(res);
}
});
}
});
},
}
}
</script>
<style lang="scss" scoped>
.promotion {
width: 100%;
height: 100vh;
background-color: $uni-color;
.promotion-card {
width: 90%;
margin: 140rpx auto 0rpx auto;
box-shadow: 0rpx 0rpx 15rpx rgba(0, 0, 0, .2);
border-radius: 40rpx;
padding: 40rpx 30rpx;
box-sizing: border-box;
background-color: #fff;
position: relative;
padding-top: 100rpx;
.headImage{
position: absolute;
height: 180rpx;
width: 180rpx;
border-radius: 50%;
top: -80rpx;
left: 50%;
transform: translate(-50%);
border: 10rpx solid #fff;
box-shadow: 0 0 10rpx 10rpx #00000013;
}
}
}
#myCanvas {
position: fixed;
left: 100%;
/* visibility: hidden */
/* visibility: hidden; */
/* margin-top: 100rpx; */
margin: 68rpx auto;
width: 750rpx;
height: 750rpx;
/* line-height: 20px; */
background-color: rgba(255, 255, 255, 1);
text-align: center;
}
</style>

+ 65
- 86
pages_order/mine/promotion.vue View File

@ -2,23 +2,17 @@
<view class="promotion">
<navbar title="二维码"
bgColor="#E3441A"
bgColor="rgb(235, 51, 0)"
color="#fff"
leftClick @leftClick="$utils.navigateBack" />
<view class="promotion-card">
<image :src="userInfo.headImage" mode="aspectFill"
class="headImage"></image>
<image style="width: 100%;" :src="imagePath" mode="widthFix"></image>
<!-- <view class="invitation-code">加油站: {{ title }}</view> -->
<canvas id="myCanvas" type="2d" canvas-id="firstCanvas1"></canvas>
<view class="uni-color-btn"
@click="preservationImg(imagePath)">保存二维码</view>
</view>
<image
class="image"
:src="imagePath" mode="aspectFill"></image>
<canvas id="myCanvas" type="2d" canvas-id="firstCanvas1"></canvas>
</view>
</template>
@ -27,7 +21,7 @@
export default {
name: 'Promotion',
computed: {
...mapState(['userInfo']),
...mapState(['userInfo', 'promotionUrl']),
},
data() {
return {
@ -39,7 +33,11 @@
}
},
onShow() {
this.getQrCode()
if(this.promotionUrl){
this.imagePath = this.promotionUrl
}else{
this.getQrCode()
}
this.$store.commit('getUserInfo')
},
methods: {
@ -71,73 +69,73 @@
// Canvas
const width = res[0].width
const height = res[0].height
console.log(width, height);
//
const dpr = wx.getWindowInfo().pixelRatio
//dpr
// dpr 2 4
// 3 6
let Ratio = dpr * 2
console.log("bug", dpr)
canvas.width = width * dpr
canvas.height = height * dpr
this.canvas = canvas
ctx.scale(dpr, dpr)
ctx.clearRect(0, 0, width, height)
ctx.fillStyle = '#fff'
ctx.fillRect(0, 0, canvas.width, canvas.height)
//
// const image = canvas.createImage()
// image.onload = () => {
// ctx.drawImage(image, 30, 18, 40, 40)
// }
// image.src = '/public/img/wechar_1.png'
// image.src = this.userInfo.headImage
ctx.fillStyle = 'black'
ctx.font = '22px PingFangSC-regular';
//
// let nickName = this.userInfo.nickName || ''
// ctx.fillText(nickName, canvas.width / Ratio - nickName.length * 11, 40);
// ctx.font = '18px PingFangSC-regular';
// ctx.fillStyle = '#fff'
// ctx.fillRect(0, 0, canvas.width, canvas.height)
//
const bgImage = canvas.createImage()
bgImage.src = this.configList.qr_code
//
let s = this.title || ''
ctx.fillText(s, canvas.width / Ratio - s.length * 11, 50);
//
const coderImage = canvas.createImage()
coderImage.src = this.baseUrl + this.url
coderImage.onload = () => {
ctx.drawImage(coderImage,
canvas.width / Ratio - 240 / 2, 100, 240, 240)
bgImage.onload = () => {
canvas.width = bgImage.width
canvas.height = bgImage.height
ctx.drawImage(bgImage,
0, 0, bgImage.width, bgImage.height)
coderImage.onload = () => {
ctx.drawImage(coderImage,
canvas.width / 2 - 175, canvas.height / 2 - 100, 350, 350)
this.canvasToTempFilePath()
}
}
//
setTimeout(() => {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: this.canvas.width,
height: this.canvas.height,
canvas,
success: (res) => {
var tempFilePath = res.tempFilePath;
this.imagePath = tempFilePath
uni.hideLoading()
}
});
}, 600);
})
},
canvasToTempFilePath(){
//
setTimeout(() => {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: this.canvas.width,
height: this.canvas.height,
canvas : this.canvas,
success: (res) => {
var tempFilePath = res.tempFilePath;
this.imagePath = tempFilePath
this.$store.commit('setPromotionUrl', res.tempFilePath)
uni.hideLoading()
this.load = false
}
});
}, 200);
},
back() {
uni.navigateBack(-1)
},
@ -176,28 +174,10 @@
width: 100%;
height: 100vh;
background-color: $uni-color;
.promotion-card {
width: 90%;
margin: 140rpx auto 0rpx auto;
box-shadow: 0rpx 0rpx 15rpx rgba(0, 0, 0, .2);
border-radius: 40rpx;
padding: 40rpx 30rpx;
box-sizing: border-box;
background-color: #fff;
position: relative;
padding-top: 100rpx;
.headImage{
position: absolute;
height: 180rpx;
width: 180rpx;
border-radius: 50%;
top: -80rpx;
left: 50%;
transform: translate(-50%);
border: 10rpx solid #fff;
box-shadow: 0 0 10rpx 10rpx #00000013;
}
}
}
.image{
width: 100%;
height: calc(100vh - 200rpx);
}
#myCanvas {
@ -206,9 +186,8 @@
/* visibility: hidden */
/* visibility: hidden; */
/* margin-top: 100rpx; */
margin: 68rpx auto;
width: 750rpx;
height: 750rpx;
height: calc(100vh - 120rpx);
/* line-height: 20px; */
background-color: rgba(255, 255, 255, 1);
text-align: center;


+ 4
- 0
store/store.js View File

@ -13,6 +13,7 @@ const store = new Vuex.Store({
riceInfo: {}, //用户相关信息
category: [], //分类信息
payOrderProduct: [], //支付订单中的商品
promotionUrl : '',//分享二维码
},
getters: {},
mutations: {
@ -144,6 +145,9 @@ const store = new Vuex.Store({
setPayOrderProduct(state, data) {
state.payOrderProduct = data
},
setPromotionUrl(state, data){
state.promotionUrl = data
},
},
actions: {},
})


Loading…
Cancel
Save