jiuyiUniapp/jiuyi2/pages/news/myQr.vue

82 lines
1.6 KiB
Vue
Raw Normal View History

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