出入码支持支付宝小程序
This commit is contained in:
		@@ -98,7 +98,7 @@ export default {
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
  methods: {
 | 
					  methods: {
 | 
				
			||||||
    drawCode(text = 'https://www.baidu.com/', foreground = 'red') {
 | 
					    drawCode(text = 'https://www.baidu.com/', foreground = 'red') {
 | 
				
			||||||
      const query = wx.createSelectorQuery()
 | 
					      const query = Taro.createSelectorQuery()
 | 
				
			||||||
      query.select('#myQrcode')
 | 
					      query.select('#myQrcode')
 | 
				
			||||||
        .fields({
 | 
					        .fields({
 | 
				
			||||||
          node: true,
 | 
					          node: true,
 | 
				
			||||||
@@ -108,7 +108,7 @@ export default {
 | 
				
			|||||||
          var canvas = res[0].node
 | 
					          var canvas = res[0].node
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          // 调用方法drawQrcode生成二维码
 | 
					          // 调用方法drawQrcode生成二维码
 | 
				
			||||||
          drawQrcode({
 | 
					          drawQrcode(Taro, {
 | 
				
			||||||
            canvas: canvas,
 | 
					            canvas: canvas,
 | 
				
			||||||
            canvasId: 'myQrcode',
 | 
					            canvasId: 'myQrcode',
 | 
				
			||||||
            width: 260,
 | 
					            width: 260,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@ function utf16to8(str) {
 | 
				
			|||||||
  return out
 | 
					  return out
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function drawQrcode(options, debug) {
 | 
					function drawQrcode(Taro, options, debug) {
 | 
				
			||||||
  options = options || {}
 | 
					  options = options || {}
 | 
				
			||||||
  options = extend(true, {
 | 
					  options = extend(true, {
 | 
				
			||||||
    canvasId: 'myQrcode',
 | 
					    canvasId: 'myQrcode',
 | 
				
			||||||
@@ -66,18 +66,18 @@ function drawQrcode(options, debug) {
 | 
				
			|||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return new Promise(function (resolve, reject) {
 | 
					    return new Promise(function (resolve, reject) {
 | 
				
			||||||
      return resolve(createCanvas());
 | 
					      return resolve(createCanvas(Taro));
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function createCanvas() {
 | 
					  function createCanvas(Taro) {
 | 
				
			||||||
    // create the qrcode itself
 | 
					    // create the qrcode itself
 | 
				
			||||||
    var qrcode = new QRCode(options.typeNumber, options.correctLevel)
 | 
					    var qrcode = new QRCode(options.typeNumber, options.correctLevel)
 | 
				
			||||||
    qrcode.addData(utf16to8(options.text))
 | 
					    qrcode.addData(utf16to8(options.text))
 | 
				
			||||||
    qrcode.make()
 | 
					    qrcode.make()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const dpr = wx ? wx.getSystemInfoSync().pixelRatio : 1 // 兼容支付宝小程序
 | 
					    const dpr = Taro.getSystemInfoSync().pixelRatio
 | 
				
			||||||
    var canvas = options.canvas
 | 
					    var canvas = options.canvas
 | 
				
			||||||
    const ctx = canvas.getContext('2d')
 | 
					    const ctx = canvas.getContext('2d')
 | 
				
			||||||
    canvas.width = options.width * dpr
 | 
					    canvas.width = options.width * dpr
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user