oak-general-business/src/components/wechatQrCode/share/index.ts

58 lines
1.9 KiB
TypeScript
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.

export default OakComponent({
entity: 'wechatQrCode',
projection: {
id: 1,
entity: 1,
entityId: 1,
type: 1, //类型
ticket: 1,
url: 1,
buffer: 1,
expired: 1,
expiresAt: 1,
applicationId: 1,
},
isList: false,
formData: ({ data: wechatQrCode }) => {
let qrCodeUrl = wechatQrCode?.url;
const buffer = wechatQrCode?.buffer;
if (buffer) {
const newBuffer = new ArrayBuffer(buffer.length * 2);
const newBufferToUint16 = new Uint16Array(newBuffer);
for (let i = 0; i < buffer.length; i++) {
newBufferToUint16[i] = buffer.charCodeAt(i);
}
if (process.env.OAK_PLATFORM === 'wechatMp') {
const base64Str = wx.arrayBufferToBase64(newBufferToUint16 as unknown as ArrayBuffer);
qrCodeUrl = 'data:image/png;base64,' + base64Str;
} else {
let binary = '';
const bytes = new Uint8Array(newBufferToUint16);
const len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
const base64Str = window.btoa(binary);
qrCodeUrl = 'data:image/png;base64,' + base64Str;
}
if (process.env.NODE_ENV === 'development') {
console.warn('使用微信api生成二维码不支持二维码颜色更换[color、bgColor]')
}
}
return {
entity: wechatQrCode?.entity,
url: qrCodeUrl,
expired: wechatQrCode?.expired,
expiresAt: wechatQrCode?.expiresAt,
};
},
properties: {
disableDownload: false,
size: 280,
disabled: false,
color: '#000000',
bgColor: '#ffffff',
}
});