|
@@ -13,6 +13,7 @@ import { ref, computed } from 'vue'
|
|
import { userStore } from '@/store/user'
|
|
import { userStore } from '@/store/user'
|
|
import { onLoad } from '@dcloudio/uni-app'
|
|
import { onLoad } from '@dcloudio/uni-app'
|
|
import { getUserAvatar } from '@/utils/avatar'
|
|
import { getUserAvatar } from '@/utils/avatar'
|
|
|
|
+import { getJobAdvertisedShareQrcode } from '@/api/user'
|
|
|
|
|
|
const useUserStore = userStore()
|
|
const useUserStore = userStore()
|
|
const baseInfo = computed(() => useUserStore?.baseInfo)
|
|
const baseInfo = computed(() => useUserStore?.baseInfo)
|
|
@@ -65,8 +66,50 @@ const drawAvatar = (ctx, imagePath, x, y, radius) => {
|
|
ctx.restore() // 恢复之前保存的绘图上下文
|
|
ctx.restore() // 恢复之前保存的绘图上下文
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+const getToLocal = (base64data) => {
|
|
|
|
+ const fsm = wx.getFileSystemManager()
|
|
|
|
+ const FILE_BASE_NAME = 'tmp_base64src'; //自定义文件名
|
|
|
|
+ const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || []
|
|
|
|
+ if (!format) {
|
|
|
|
+ return (new Error('ERROR_BASE64SRC_PARSE'))
|
|
|
|
+ }
|
|
|
|
+ const filePath = `${wx.env.USER_DATA_PATH}/${FILE_BASE_NAME}.${format}`
|
|
|
|
+ const buffer = wx.base64ToArrayBuffer(bodyData);
|
|
|
|
+ fsm.writeFile({
|
|
|
|
+ filePath,
|
|
|
|
+ data: buffer,
|
|
|
|
+ encoding: 'binary',
|
|
|
|
+ success(r) {
|
|
|
|
+ console.log(filePath,'filePath')
|
|
|
|
+ qrCode.value = filePath
|
|
|
|
+ },
|
|
|
|
+ fail() {
|
|
|
|
+ return (new Error('ERROR_BASE64SRC_WRITE'))
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 生成分享二维码
|
|
|
|
+const qrCode = ref()
|
|
|
|
+const handleShareCode = async () => {
|
|
|
|
+ const userId = useUserStore?.accountInfo?.userId || ''
|
|
|
|
+ const query = {
|
|
|
|
+ scene: 'shareId=' + userId,
|
|
|
|
+ path: 'pages/login/index',
|
|
|
|
+ width: 200,
|
|
|
|
+ autoColor: false,
|
|
|
|
+ checkPath: true,
|
|
|
|
+ hyaline: true
|
|
|
|
+ }
|
|
|
|
+ const res = await getJobAdvertisedShareQrcode(query)
|
|
|
|
+ const data = res?.data ? 'data:image/png;base64,' + res.data : ''
|
|
|
|
+ getToLocal(data)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
const createPoster = async () => {
|
|
const createPoster = async () => {
|
|
uni.showLoading({ title: '生成中...', mask: true })
|
|
uni.showLoading({ title: '生成中...', mask: true })
|
|
|
|
+ await handleShareCode() // 生产分享二维码
|
|
var context = uni.createCanvasContext('posterCanvas')
|
|
var context = uni.createCanvasContext('posterCanvas')
|
|
|
|
|
|
//清空画布
|
|
//清空画布
|
|
@@ -82,8 +125,8 @@ const createPoster = async () => {
|
|
drawAvatar(context, path, 124, 22, 40.5) // canvas、图片路径、x、y、半径
|
|
drawAvatar(context, path, 124, 22, 40.5) // canvas、图片路径、x、y、半径
|
|
|
|
|
|
//分享二维码
|
|
//分享二维码
|
|
- const { path: qrCode } = await getImageTempRatio('https://minio.citupro.com/dev/menduner/miniProgram.jpg')
|
|
|
|
- context.drawImage(qrCode, 105.5, 312.5, 120, 120)
|
|
|
|
|
|
+ // const { path: qrCode } = await getImageTempRatio('https://minio.citupro.com/dev/menduner/miniProgram.jpg')
|
|
|
|
+ context.drawImage(qrCode.value, 105.5, 312.5, 120, 120)
|
|
|
|
|
|
context.draw(false, () =>{
|
|
context.draw(false, () =>{
|
|
wx.canvasToTempFilePath({
|
|
wx.canvasToTempFilePath({
|