小程序二维码生成

javascript 复制代码
const submitForm = async (formEl: FormInstance | undefined) => {
    if (!formEl) return
    await formEl.validate((valid: any, fields: any) => {
        if (valid) {
            console.log(ruleForm)
            getToken({ act: 'miniprogram', op: 'getAccessToken', type: ruleForm.name }).then((res: any) => {
                const ACCESS_TOKEN = res.data.token
                // 根据选择循环生成多张
                selectData[0].children.forEach((element: { children: any; label: any; value: any }) => {
                    console.log(element.children[0].value)
                    const params = {
                        scene: element.children[0].value,
                        page: ruleForm.page,
                        width: 430,
                        env_version: 'develop',
                    }
                    const label = element.label
                    generateMiniProgramQR(params, ACCESS_TOKEN, label)
                })
            })
        } else {
            console.log('error submit!', fields)
        }
    })
}
javascript 复制代码
const generateMiniProgramQR = async (
    params: { scene: any; page?: any; width?: number; label?: any },
    ACCESS_TOKEN: any,
    label: any
) => {
    try {
        const url = `https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=${ACCESS_TOKEN}`
        const response = await axios.post(url, params, { responseType: 'arraybuffer' })
        const blob = new Blob([response.data], { type: 'image/jpeg' })
        const imageUrl = URL.createObjectURL(blob)
        const link = document.createElement('a')
        link.href = imageUrl
        link.download = `${label}.jpg`
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
        URL.revokeObjectURL(imageUrl)
    } catch (error) {
        // 错误处理
    }
}
相关推荐
dreams_dream11 小时前
微信小程序:页面事件-上拉触底
微信小程序·小程序
wafrdggh1 天前
2026电商快递批量查询怎么用?固乔助手模板设置评测
大数据·数据库·小程序
wafrdggh2 天前
2026 商城小程序平台哪个价格合理?把跨境附加成本这个坑算透
大数据·小程序
恩创软件开发4 天前
自助KTV系统管理员续单功能
经验分享·小程序
AI源码6 天前
在线考试小程序
小程序·notepad++
2501_916008896 天前
iPhone 设备信息查看,用 KeyMob 看型号、序列号、电池健康和 UDID
android·ios·小程序·https·uni-app·iphone·webview
云-缩影7 天前
做微信小程序,自建服务器还是用云托管:技术选型对比
服务器·微信小程序·小程序
超级新零售8 天前
服装订货会数字化:商品版本、订单状态与后续配发数据如何衔接?
大数据·小程序·企业微信
xiezhr8 天前
我用workBuddy开发了自己的第一个小程序并成功上线了
ai·小程序·ai agent·workbuddy
sinat_267611918 天前
用 AI 开发微信小程序(八):一个极简收纳工具的开发复盘
微信小程序·小程序