const submitForm = async (formEl: FormInstance | undefined) => {if (!formEl) returnawait 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.tokenselectData[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.labelgenerateMiniProgramQR(params, ACCESS_TOKEN, label)})})} else {console.log('error submit!', fields)}})
}
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 = imageUrllink.download = `${label}.jpg`document.body.appendChild(link)link.click()document.body.removeChild(link)URL.revokeObjectURL(imageUrl)} catch (error) {}
}
