Browse Source

去掉http

liuyuqi-dellpc 6 years ago
parent
commit
5f464fbe3e
4 changed files with 73 additions and 75 deletions
  1. 6 6
      wxapp-qrcode/app.js
  2. 6 8
      wxapp-qrcode/app.json
  3. 48 48
      wxapp-qrcode/pages/main/index.js
  4. 13 13
      wxapp-qrcode/pages/main/index.wxml

+ 6 - 6
wxapp-qrcode/app.js

@@ -6,11 +6,11 @@ App({
     logs.unshift(Date.now())
     wx.setStorageSync('logs', logs);
   },
-  getUserInfo:function(cb){
+  getUserInfo: function (cb) {
     var that = this
-    if(this.globalData.userInfo){
+    if (this.globalData.userInfo) {
       typeof cb == "function" && cb(this.globalData.userInfo)
-    }else{
+    } else {
       //调用登录接口
       wx.login({
         success: function () {
@@ -24,8 +24,8 @@ App({
       })
     }
   },
-  globalData:{
-    
-    userInfo:null
+  globalData: {
+
+    userInfo: null
   }
 })

+ 6 - 8
wxapp-qrcode/app.json

@@ -1,14 +1,12 @@
 {
-  "pages":[
-	"pages/main/index",
+  "pages": [
+    "pages/main/index",
     "pages/logs/logs"
-    
-    
   ],
-  "window":{
-    "backgroundTextStyle":"light",
+  "window": {
+    "backgroundTextStyle": "light",
     "navigationBarBackgroundColor": "#fff",
     "navigationBarTitleText": "WeChat",
-    "navigationBarTextStyle":"black"
+    "navigationBarTextStyle": "black"
   }
-}
+}

+ 48 - 48
wxapp-qrcode/pages/main/index.js

@@ -1,113 +1,113 @@
 // pages/main/index.js
 var QR = require("../../utils/qrcode.js");
 Page({
-  data:{
+  data: {
     /*
     官网说hidden只是简单的控制显示与隐藏,组件始终会被渲染,
     但是将canvas转化成图片走的居然是fail,hidden为false就是成功的
     所以这里手动控制显示隐藏canvas
     */
-    maskHidden:true,
-    imagePath:'',
-    placeholder:'baidu.com'
+    maskHidden: true,
+    imagePath: '',
+    placeholder: 'I love you !'
   },
-  onLoad:function(options){
+  onLoad: function (options) {
     // 页面初始化 options为页面跳转所带来的参数
     var size = this.setCanvasSize();//动态设置画布大小
-    var initUrl = "http://"+this.data.placeholder;
-    this.createQrCode(initUrl,"mycanvas",size.w,size.h);
+    var initUrl = this.data.placeholder;
+    this.createQrCode(initUrl, "mycanvas", size.w, size.h);
 
   },
-  onReady:function(){
-    
+  onReady: function () {
+
   },
-  onShow:function(){
-    
+  onShow: function () {
+
     // 页面显示
   },
-  onHide:function(){
+  onHide: function () {
     // 页面隐藏
   },
 
-  onUnload:function(){
+  onUnload: function () {
     // 页面关闭
 
   },
   //适配不同屏幕大小的canvas
-  setCanvasSize:function(){
-    var size={};
+  setCanvasSize: function () {
+    var size = {};
     try {
-        var res = wx.getSystemInfoSync();
-        var scale = 750/686;//不同屏幕下canvas的适配比例;设计稿是750宽
-        var width = res.windowWidth/scale;
-        var height = width;//canvas画布为正方形
-        size.w = width;
-        size.h = height;
-      } catch (e) {
-        // Do something when catch error
-        console.log("获取设备信息失败"+e);
-      } 
+      var res = wx.getSystemInfoSync();
+      var scale = 750 / 686;//不同屏幕下canvas的适配比例;设计稿是750宽
+      var width = res.windowWidth / scale;
+      var height = width;//canvas画布为正方形
+      size.w = width;
+      size.h = height;
+    } catch (e) {
+      // Do something when catch error
+      console.log("获取设备信息失败" + e);
+    }
     return size;
-  } ,
-  createQrCode:function(url,canvasId,cavW,cavH){
+  },
+  createQrCode: function (url, canvasId, cavW, cavH) {
     //调用插件中的draw方法,绘制二维码图片
-    QR.qrApi.draw(url,canvasId,cavW,cavH);
+    QR.qrApi.draw(url, canvasId, cavW, cavH);
     var that = this;
     //二维码生成之后调用canvasToTempImage();延迟3s,否则获取图片路径为空
-    var st = setTimeout(function(){
+    var st = setTimeout(function () {
       that.canvasToTempImage();
       clearTimeout(st);
-    },3000);
-    
+    }, 3000);
+
   },
   //获取临时缓存照片路径,存入data中
-  canvasToTempImage:function(){
+  canvasToTempImage: function () {
     var that = this;
     wx.canvasToTempFilePath({
       canvasId: 'mycanvas',
       success: function (res) {
-          var tempFilePath = res.tempFilePath;
-          console.log(tempFilePath);
-          that.setData({
-              imagePath:tempFilePath,
-          });
+        var tempFilePath = res.tempFilePath;
+        console.log(tempFilePath);
+        that.setData({
+          imagePath: tempFilePath,
+        });
       },
       fail: function (res) {
-          console.log(res);
+        console.log(res);
       }
     });
   },
   //点击图片进行预览,长按保存分享图片
-  previewImg:function(e){
+  previewImg: function (e) {
     var img = this.data.imagePath
     wx.previewImage({
       current: img, // 当前显示图片的http链接
       urls: [img] // 需要预览的图片http链接列表
     })
   },
-  formSubmit: function(e) {
+  formSubmit: function (e) {
     var that = this;
     var url = e.detail.value.url;
-    url = url==''?('http://'+that.data.placeholder):('http://'+url);
+    url = url == '' ? (that.data.placeholder) : (url);
     that.setData({
-      maskHidden:false,
+      maskHidden: false,
     });
     wx.showToast({
       title: '生成中...',
       icon: 'loading',
-      duration:2000
+      duration: 1000
     });
-    var st = setTimeout(function(){
+    var st = setTimeout(function () {
       wx.hideToast()
       var size = that.setCanvasSize();
       //绘制二维码
-      that.createQrCode(url,"mycanvas",size.w,size.h);
+      that.createQrCode(url, "mycanvas", size.w, size.h);
       that.setData({
-        maskHidden:true
+        maskHidden: true
       });
       clearTimeout(st);
-    },2000)
-    
+    }, 2000)
+
   }
 
 })

+ 13 - 13
wxapp-qrcode/pages/main/index.wxml

@@ -1,22 +1,22 @@
 <!--pages/main/index.wxml-->
 <view class="container-box">
-    <view class="img-box">
-        <canvas bindtap="previewImg" hidden="{{canvasHidden}}" style="width: 686rpx;height: 686rpx;background:#f1f1f1;" canvas-id="mycanvas"/>
-        <!--<image bindtap="previewImg" mode="scaleToFill" src="{{imagePath}}"></image>-->
+  <view class="img-box">
+    <canvas bindtap="previewImg" hidden="{{canvasHidden}}" style="width: 686rpx;height: 686rpx;background:#f1f1f1;" canvas-id="mycanvas" />
+    <!--<image bindtap="previewImg" mode="scaleToFill" src="{{imagePath}}"></image>-->
+  </view>
+  <form bindsubmit="formSubmit">
+    <view class="input-row">
+      <label>内容</label>
+      <input name='url' value='' type="text" maxlength="255" placeholder="{{placeholder}}" />
     </view>
-    <form bindsubmit="formSubmit">
-        <view class="input-row">
-            <label>网址</label>
-            <input name='url' value='' type="text" maxlength="255" placeholder="{{placeholder}}"/>
-        </view>
-        <!--<view class="input-row">
+    <!--<view class="input-row">
             <label>金额</label>
             <input name="money" type="number" maxlength="7"  placeholder="1000000"/>
         </view>-->
-        <button formType="submit" class="mybtn" type="primary">生成二维码</button>
-    </form>
+    <button formType="submit" class="mybtn" type="primary">生成二维码</button>
+  </form>
 </view>
 <view hidden="{{maskHidden}}" class="mask"></view>
 <view class="canvas-box">
-    
-</view>
+
+</view>