扩展链接高佣版

qrcode.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // pages/qrcode/qrcode.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. word: '',
  9. from: '',
  10. canvasWidth: '',
  11. canvasHeight: '',
  12. isCode: false
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. this.setData({
  19. word: wx.getStorageSync('introduce'),
  20. from: options.from,
  21. openId: wx.getStorageSync('userInfo').openId
  22. })
  23. !this.data.word&&this.getword(0);
  24. var qrWH = [];
  25. this.data.from&&(
  26. qrWH = wx.getStorageSync("qrWH").split("~~"),
  27. this.setData({
  28. canvasWidth: qrWH[0],
  29. canvasHeight: qrWH[1],
  30. b64: wx.getStorageSync("qrcode"),
  31. isCode: wx.getStorageSync("isCode")
  32. })
  33. )
  34. },
  35. toWord(e) {
  36. // 保存关键词
  37. wx.setStorageSync('keyword',this.data.keyword)
  38. wx.setStorageSync("qrcode",this.data.b64)
  39. wx.setStorageSync("isCode",this.data.isCode)
  40. wx.setStorageSync("qrWH",this.data.canvasWidth+"~~"+this.data.canvasHeight)
  41. wx.redirectTo({
  42. url: '/pages/word/word?type='+e.currentTarget.dataset.type+'&word='+this.data.word+'&from=2'
  43. })
  44. },
  45. // 没有本地词,从列表中获取----默认引导词
  46. getword(type) {
  47. app.func.req('/api/article/getGuideWords', 'get', {
  48. 'type': type
  49. }, (res) => {
  50. wx.hideLoading()
  51. if(res && res.errno == 0){
  52. if(type==0) {
  53. this.setData({
  54. word: res.rst.data[0].keyword
  55. })
  56. wx.setStorageSync('word',res.rst.data[0].keyword)
  57. }else {
  58. //成功
  59. this.setData({
  60. author: res.rst.data[0].keyword
  61. })
  62. wx.setStorageSync('author',res.rst.data[0].keyword)
  63. }
  64. }else {
  65. wx.showToast({
  66. title: res.err,
  67. icon: 'none',
  68. duration: 2000
  69. })
  70. }
  71. },()=>{
  72. wx.hideLoading()
  73. })
  74. },
  75. fetch() {
  76. wx.chooseImage({
  77. success: res => {
  78. wx.showLoading({
  79. title: '上传中',
  80. icon: 'none'
  81. })
  82. wx.getFileSystemManager().readFile({
  83. filePath: res.tempFilePaths[0], //选择图片返回的相对路径
  84. encoding: 'base64', //编码格式
  85. success: res => { //成功的回调
  86. this.getUrl('data:image/png;base64,' + res.data)
  87. },
  88. fail(error) {
  89. console.log(error)
  90. }
  91. })
  92. }
  93. })
  94. },
  95. checkCode(url) {
  96. app.func.req('/api/qrCodeReader', 'post', {
  97. 'qrcode': url
  98. }, (res) => {
  99. wx.hideLoading()
  100. if(res && res.errno == 0){
  101. //成功
  102. this.setData({
  103. isCode: true
  104. })
  105. console.log(res)
  106. }else {
  107. this.setData({
  108. isCode: false
  109. })
  110. wx.showToast({
  111. title: res.err,
  112. icon: 'none',
  113. duration: 2000
  114. })
  115. }
  116. },()=>{
  117. wx.hideLoading()
  118. })
  119. },
  120. getUrl(url) {
  121. app.func.req('/api/goods/imageUrl', 'post', {
  122. 'qrcode': url
  123. }, (res) => {
  124. wx.hideLoading()
  125. if(res && res.errno == 0){
  126. if(!res.rst) {
  127. wx.showToast({
  128. title: '图片上传失败',
  129. icon: 'none'
  130. })
  131. return;
  132. }
  133. //成功
  134. this.setData({
  135. b64: res.rst
  136. })
  137. this.checkCode(url)
  138. }else {
  139. wx.showToast({
  140. title: res.err,
  141. icon: 'none',
  142. duration: 2000
  143. })
  144. }
  145. },()=>{
  146. wx.hideLoading()
  147. })
  148. },
  149. toStatus() {
  150. if(!this.data.b64&&!this.data.isCode) {
  151. wx.showToast({
  152. title: this.data.b64?'图片上传中':'二维码识别失败',
  153. icon: none
  154. })
  155. return;
  156. }
  157. wx.setStorageSync('introduce',this.data.word)
  158. wx.redirectTo({
  159. url: '/pages/status/status?url='+this.data.b64
  160. })
  161. },
  162. onShareAppMessage() {
  163. }
  164. })