zzzz
2024-04-17 c34c87ff6bf310e461ae27c1988d39baef208da8
1
{"ast":null,"code":"import \"vant/es/icon/style\";\nimport _Icon from \"vant/es/icon\";\nimport \"vant/es/uploader/style\";\nimport _Uploader from \"vant/es/uploader\";\nimport \"core-js/modules/es.array.push.js\";\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\nimport QRCode from \"qrcode\";\nimport * as imageConversion from \"image-conversion\";\nimport Axios from \"@/API/recharge.js\";\nimport axios from \"axios\";\nimport assetsHead from \"@/components/assets-head\";\n//import Config from \"@/config\";\nimport { BASE_URL } from \"@/config\";\nimport { signatureGenerate } from \"@/utils/signatureUtil\";\nimport { mapGetters } from \"vuex\";\nexport default {\n  name: \"rechargePage\",\n  components: {\n    [_Uploader.name]: _Uploader,\n    [_Icon.name]: _Icon,\n    assetsHead\n  },\n  computed: {\n    ...mapGetters({\n      userInfo: \"user/userInfo\"\n    })\n  },\n  state: {\n    status: 0,\n    // 状态\n    gasObj: {},\n    //\n    userInfo: {\n      usercode: \"\",\n      //\n      token: \"\",\n      // 登录token\n      username: \"\",\n      perpetual_contracts_status: 0,\n      account: \"\" // 钱包地址\n    }\n  },\n  getters: {\n    mingStatus: state => state.status,\n    isToken: state => state.token,\n    userInfo: state => state.userInfo\n  },\n  data() {\n    return {\n      BASE_URL,\n      tip: \"\",\n      fileList: [],\n      address: \"\",\n      uploadImgUrl: \"\",\n      nowUrl: \"\",\n      session_token: \"\",\n      amount: \"\",\n      //充币数量\n      from: \"\",\n      //客户转出地址\n      submitImg: \"\",\n      coin: \"\",\n      //币种\n      blockchainIndex: 0,\n      blockchain_name: \"\",\n      chainList: [],\n      QRCodeMsg: \"\",\n      imgshow: false,\n      img: \"\",\n      enterAddress: \"\"\n    };\n  },\n  mounted() {\n    //获取域名\n    this.nowUrl = \"https://\" + window.location.hostname;\n    this.coin = this.$route.query.symbol;\n    this.getData();\n    this.getToken();\n    // https://www.wbfjsfhjdbsh.site/wap/api/cms!get.action?language=en&content_code=002&token=fe3c35583f8a4f12a86b0c13faa75ee6\n    Axios.getRechargeTips({\n      language: this.$i18n.locale,\n      token: this.$store.state.user.userInfo.token,\n      content_code: \"002\"\n    }).then(res => {\n      //console.log('充值提示',res)\n      this.tip = res.data.content;\n    }).catch(err => {\n      if (err.code === \"ECONNABORTED\") {\n        this.$toast(this.$t(\"网络超时!\"));\n      } else if (err !== undefined) {\n        this.$toast(this.$t(err));\n      }\n    });\n  },\n  methods: {\n    getData() {\n      Axios.getBlock({\n        coin: this.coin\n      }).then(res => {\n        console.log(res);\n        this.address = res.address;\n        // this.blockchain_name = res.data[0].blockchain_name;\n        this.getQRCode();\n      });\n    },\n    changeBlockchain(index) {\n      this.blockchainIndex = index;\n      this.address = this.chainList[this.blockchainIndex].address;\n      this.blockchain_name = this.chainList[this.blockchainIndex].blockchain_name;\n      this.getQRCode();\n    },\n    getToken() {\n      Axios.getRechargeToken().then(res => {\n        this.session_token = res.data.session_token;\n      });\n    },\n    onClickLeft() {\n      this.$router.go(-1);\n    },\n    onCopy(e) {\n      this.$toast(this.$t(\"复制成功\"));\n    },\n    onError(e) {\n      this.$toast(this.$t(\"复制失败\"));\n    },\n    //上传前\n    beforeRead(file) {\n      let types = [\"image/jpeg\", \"image/jpg\", \"image/gif\", \"image/bmp\", \"image/png\"];\n      const isImage = types.includes(file.type);\n      if (!isImage) {\n        this.$toast(this.$t(\"上传图片只能是JPG、JPEG、gif、bmp、PNG格式!\"));\n        return false;\n      }\n      return true;\n    },\n    //上传完成\n    async afterRead(file) {\n      const {\n        timestamp,\n        signature\n      } = signatureGenerate();\n      const blob = await imageConversion.compressAccurately(file.file, 500);\n      const formData = new FormData();\n      formData.append(\"file\", blob);\n      const BASE_URL = this.BASE_URL;\n      await axios.post(`${BASE_URL}public/uploadimg!execute.action`, formData, {\n        headers: {\n          \"Content-Type\": \"multipart/form-data\",\n          tissuePaper: timestamp,\n          sign: signature\n        }\n      }).then(res => {\n        if (res.data.code == 0) {\n          this.submitImg = res.data.data;\n          // this.uploadImgUrl = this.nowUrl+'/wap/public/showimg!showImg.action?imagePath=' + res.data.data;\n          this.uploadImgUrl = `${BASE_URL}public/showimg!showImg.action?imagePath=${res.data.data}`;\n          this.$toast(this.$t(\"上传成功\"));\n          console.log(this.uploadImgUrl);\n        } else {\n          this.$toast(this.$t(\"上传失败\"));\n        }\n      });\n    },\n    //生成二维码\n    getQRCode() {\n      let opts = {\n        errorCorrectionLevel: \"H\",\n        //容错级别\n        type: \"image/png\",\n        //生成的二维码类型\n        quality: 0.3,\n        //二维码质量\n        margin: 4,\n        //二维码留白边距\n        width: 200,\n        //宽\n        height: 200,\n        //高\n        text: \"http://www.xxx.com\",\n        //二维码内容\n        color: {\n          dark: \"#333333\",\n          //前景色\n          light: \"#fff\" //背景色\n        }\n      };\n      this.QRCodeMsg = this.address; //生成的二维码为URL地址js\n      let msg = document.getElementById(\"QRcodeCanvas\"); // 将获取到的数据(val)画到msg(canvas)上\n      QRCode.toCanvas(msg, this.QRCodeMsg, opts, function (error) {\n        console.log(error);\n      });\n      // 将canvas转成图片格式,可以长按保存\n      this.img = msg.toDataURL(\"image/png\");\n      this.imgshow = true;\n    },\n    download(selector) {\n      // 通过 API 获取目标 canvas 元素\n      const canvas = document.querySelector(selector);\n      // 创建一个 a 标签,并设置 href 和 download 属性\n      const el = document.createElement(\"a\");\n      // 设置 href 为图片经过 base64 编码后的字符串,默认为 png 格式\n      el.href = canvas.toDataURL();\n      el.download = \"123\";\n\n      // 创建一个点击事件并对 a 标签进行触发\n      const event = new MouseEvent(\"click\");\n      el.dispatchEvent(event);\n    },\n    nextBtn() {\n      if (!this.amount) {\n        this.$toast(this.$t(\"请输入数量\"));\n        return;\n      }\n      let numReg = /^[0-9]+([.]{1}[0-9]+){0,1}$/;\n      if (!numReg.test(this.amount)) {\n        this.$toast(this.$t(\"请输入数字\"));\n        return;\n      }\n      if (this.amount) {\n        Axios.rechargeApply({\n          session_token: this.session_token,\n          amount: this.amount,\n          from: this.enterAddress,\n          blockchain_name: this.coin,\n          img: this.submitImg,\n          coin: this.coin,\n          channel_address: this.address,\n          tx: \"\"\n        }).then(res => {\n          if (res.code == 0) {\n            this.$router.push({\n              path: \"/recharge/rechargeSubmit\"\n            });\n          } else {\n            this.getToken();\n            this.$toast(this.$t(res.msg));\n          }\n        }).catch(error => {\n          if (error.code === \"ECONNABORTED\") {\n            this.$toast(this.$t(\"网络超时!\"));\n          } else if (error.msg !== undefined) {\n            this.$toast(this.$t(error.msg));\n          }\n          this.getToken();\n        });\n      } else {\n        this.$toast(this.$t(\"请输入充币数量\"));\n      }\n    }\n  }\n};","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}