123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- // pages/qrcode/qrcode.js
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- word: '',
- from: '',
- canvasWidth: '',
- canvasHeight: '',
- isCode: false
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- word: wx.getStorageSync('introduce'),
- from: options.from,
- openId: wx.getStorageSync('userInfo').openId
- })
- !this.data.word&&this.getword(0);
- var qrWH = [];
- this.data.from&&(
- qrWH = wx.getStorageSync("qrWH").split("~~"),
- this.setData({
- canvasWidth: qrWH[0],
- canvasHeight: qrWH[1],
- b64: wx.getStorageSync("qrcode"),
- isCode: wx.getStorageSync("isCode")
- })
- )
- },
- toWord(e) {
- // 保存关键词
- wx.setStorageSync('keyword',this.data.keyword)
- wx.setStorageSync("qrcode",this.data.b64)
- wx.setStorageSync("isCode",this.data.isCode)
- wx.setStorageSync("qrWH",this.data.canvasWidth+"~~"+this.data.canvasHeight)
- wx.redirectTo({
- url: '/pages/word/word?type='+e.currentTarget.dataset.type+'&word='+this.data.word+'&from=2'
- })
- },
- // 没有本地词,从列表中获取----默认引导词
- getword(type) {
- app.func.req('/api/article/getGuideWords', 'get', {
- 'type': type
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- if(type==0) {
- this.setData({
- word: res.rst.data[0].keyword
- })
- wx.setStorageSync('word',res.rst.data[0].keyword)
- }else {
- //成功
- this.setData({
- author: res.rst.data[0].keyword
- })
- wx.setStorageSync('author',res.rst.data[0].keyword)
- }
- }else {
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
- },
- fetch() {
- wx.chooseImage({
- success: res => {
- wx.showLoading({
- title: '上传中',
- icon: 'none'
- })
- wx.getFileSystemManager().readFile({
- filePath: res.tempFilePaths[0], //选择图片返回的相对路径
- encoding: 'base64', //编码格式
- success: res => { //成功的回调
- this.getUrl('data:image/png;base64,' + res.data)
- },
- fail(error) {
- console.log(error)
- }
- })
- }
- })
- },
-
- checkCode(url) {
- app.func.req('/api/qrCodeReader', 'post', {
- 'qrcode': url
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- //成功
- this.setData({
- isCode: true
- })
- console.log(res)
- }else {
- this.setData({
- isCode: false
- })
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
- },
- getUrl(url) {
- app.func.req('/api/goods/imageUrl', 'post', {
- 'qrcode': url
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- if(!res.rst) {
- wx.showToast({
- title: '图片上传失败',
- icon: 'none'
- })
- return;
- }
- //成功
- this.setData({
- b64: res.rst
- })
- this.checkCode(url)
- }else {
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
- },
- toStatus() {
- if(!this.data.b64&&!this.data.isCode) {
- wx.showToast({
- title: this.data.b64?'图片上传中':'二维码识别失败',
- icon: none
- })
- return;
- }
- wx.setStorageSync('introduce',this.data.word)
- wx.redirectTo({
- url: '/pages/status/status?url='+this.data.b64
- })
- },
- onShareAppMessage() {
-
- }
- })
|