jiuyiUniapp/jiuyi2/pages/news/myQr.vue

84 lines
1.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup>
// 我的二维码
import uQRCode from '@/common/js/uqrcode.js'
import {
ref,
reactive,
computed,
} from 'vue'
import {
useStore,
} from 'vuex'
import {
onLoad,
} from '@dcloudio/uni-app'
// vuex
const store = useStore()
// 用户信息
const userinfo = computed(() => {
let result = store.state.userinfo
return result
})
// 二维码大小
const qrcodeSize = ref(300)
// 二维码路径
const qrUrl = ref('')
onLoad(() => {
init()
})
// 初始化
function init() {
uni.showLoading({
title: '二维码生成中',
mask: true
})
//
const content = {
key: 'user',
userId: userinfo.value.userId,
userNickname: userinfo.value.userNickname,
}
uQRCode.make({
canvasId: 'qrcode',
text: JSON.stringify(content),
size: qrcodeSize.value,
margin: 10,
success: res => {
qrUrl.value = res
console.log('qrcodeSrc ', qrUrl.value);
},
complete: () => {
uni.hideLoading()
}
})
}
</script>
<template>
<view class="app">
<!-- -->
<view class="container ver mtb30 mlr30 tac">
<!-- 二维码插件 width height设置宽高 -->
<canvas canvas-id="qrcode" :style="{width: `${qrcodeSize}px`, height: `${qrcodeSize}px`}" />
<view class="user mtb30 df aic">
<view class="avatar">
<image class="wh80 cir" :src="userinfo.userPortrait" mode="aspectFill" />
</view>
<view class="nickname f1 ml20 c333 f32">{{userinfo.userNickname}}</view>
</view>
<view class="hint mtb30 tac c999">扫一扫添加我为好友</view>
</view>
</view>
</template>
<style lang="scss">
//
</style>