Przeglądaj źródła

Add 照片上传功能

Jinhui Zhu 5 lat temu
rodzic
commit
36a04fd477

+ 13 - 9
app.js

@@ -25,7 +25,16 @@ App({
       console.log("res.isConnected", res.isConnected)
       console.log("res.networkType", res.networkType)
     })*/
-    
+
+    wx.getSystemInfo({
+      success: e => {
+        this.globalData.StatusBar = e.statusBarHeight;
+        let custom = wx.getMenuButtonBoundingClientRect();
+        this.globalData.Custom = custom;
+        this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
+      }
+    })
+
     // 获取用户信息
     this.login();
   },
@@ -72,7 +81,7 @@ App({
     info : null,
     res : null,
     background: "/images/theme/10001.jpg",
-    networkType : "wifi",
+    networkType : "wifi"
   },
   toast : function(str)  {
     wx.showToast({
@@ -93,13 +102,8 @@ App({
     return obj.stack;
   },
   log : function() {
-    /*
-    if(appConfig.host.indexOf("http://localhost/") == -1) {
-      return;
-    }*/
-    //console.log.apply(console, arguments)
-    var stack = this.getStackTrace() || ""
-    var matchResult = stack.split("at");
+    var stack = this.getStackTrace() || "";
+    var matchResult = stack.split("at ");
     
     var line = matchResult[5] || ""
     for (var i in arguments) {

+ 7 - 3
app.json

@@ -5,15 +5,19 @@
     "pages/keys/keys",
     "pages/reset/reset",
     "pages/components/about/about",
+    "pages/components/album/album",
     "pages/components/background/background",
     "pages/privatekey/privatekey"
   ],
   "window": {
     "backgroundTextStyle": "light",
-    "navigationBarBackgroundColor": "#fff",
     "navigationBarTitleText": "密码本",
-    "navigationBarTextStyle": "black",
-    "enablePullDownRefresh": true
+    "navigationBarBackgroundColor": "#39b54a",
+    "navigationStyle": "custom",
+    "navigationBarTextStyle": "white"
+  },
+  "usingComponents": {
+    "cu-custom": "/colorui/components/cu-custom"
   },
   "sitemapLocation": "sitemap.json"
 }

+ 5 - 2
app.wxss

@@ -3,13 +3,15 @@
 @import "colorui/icon.wxss";
 @import "pages/components/background/background.wxss";
 
+.nav-content{color:#fff;}
+.cuIcon-back{color: #fff;}
 .container {
   height: 100%;
   display: flex;
   flex-direction: column;
   align-items: center;
   justify-content: space-between;
-  padding: 20rpx 0;
+  padding: 20rpx 0rpx;
   box-sizing: border-box;
 }
 .hidden {
@@ -150,4 +152,5 @@
  }
  button[plain]{ border:0 }
  .tab-bottom{padding:43rpx;}
- .text-center{text-align: center;}
+ .text-center{text-align: center;}
+ .cu-form-group>text.bigTriangle{font-size:66rpx;}

+ 7 - 0
common.js

@@ -11,6 +11,7 @@ const decrypt = require("js/decrypt")
 const verifyKeys = require("js/verifyKeys")
 const remove = require("js/remove")
 const saveClientPublicKey = require('js/saveClientPublicKey')
+const album = require("js/album")
 
 var common = {
   login: function(_this) {
@@ -46,6 +47,12 @@ var common = {
   saveClientPublicKey: function(_this, publicKey, privateKey){
     saveClientPublicKey(_this, publicKey, privateKey);
   },
+  album: function (_this, lastId, page, pageSize) {
+    album.lists(_this, lastId, page, pageSize);
+  },
+  albumRemove: function (_this, uid, id, type) {
+    album.remove(_this, uid, id, type);
+  }
 }
 
 module.exports = common

+ 4 - 1
config.js

@@ -18,7 +18,10 @@ var config = {
     "download" : `${host}/api/admin/password/download.json`,
     "sync" : `${host}/api/admin/password/sync.json`,
     "savePublicKeyClient": `${host}/api/admin/password/savePublicKeyClient.json`,
-    "batchUpdate": `${host}/api/admin/password/batchUpdate.json`
+    "batchUpdate": `${host}/api/admin/password/batchUpdate.json`,
+    "album": `${host}/api/virtual/album.json`,
+    "albumUpload": `${host}/api/virtual/upload.json`,
+    'albumRemove': `${host}/api/virtual/remove.json`,
   },
   "storeKeys": {
     "sslKeys": "sslKeys",

BIN
images/tabbar/basics.png


BIN
images/tabbar/basics_cur.png


+ 66 - 0
js/album.js

@@ -0,0 +1,66 @@
+const app = getApp();
+const appConfig = require("../config");
+const utils = require("../utils/util");
+var album = function (_this, lastId, page, pageSize) {
+
+  var header = {
+    'content-type': 'application/x-www-form-urlencoded',
+    'cookie': wx.getStorageSync(appConfig.storeKeys.sessionId)
+  };
+  wx.request({
+    url: utils.getUrl("album", {lastId:lastId, page:page, pageSize: pageSize}),
+    header: header,
+    dataType: 'json',
+    success: function (res) {
+      wx.hideLoading();
+      if (res.data.code > 0) {
+        wx.showToast({
+          title: res.data.msg || "获取公私钥失败",
+          duration: appConfig.duration
+        });
+        return;
+      }
+      app.albumSync(res.data);
+    },
+    fail: function () {
+      app.albumSync(appConfig.networkError);
+      wx.hideLoading();
+    }
+  })
+}
+
+var remove = function(_this, uid, id, type) {
+  var request = {};
+  request.uid = uid;
+  request.id = id;
+  request.type = type;
+  request.timestamp = new Date().getTime();
+  request = utils.ksort(request);
+  var str = utils.httpBuild(request);
+  var sign = utils.hexSha1(str);
+  request.sign = sign;
+  delete request.uid;
+  
+
+  var header = {
+    'content-type': 'application/x-www-form-urlencoded',
+    'cookie': wx.getStorageSync(appConfig.storeKeys.sessionId)
+  };
+  wx.request({
+    url: utils.getUrl("albumRemove", request),
+    header: header,
+    method: "GET",
+    dataType: "json",
+    success: function (req) {
+      app.removeAlbumSync(req.data)
+    },
+    fail: function (req) {
+      app.removeAlbumSync(appConfig.networkError)
+    }
+  })
+}
+
+module.exports = {
+  lists: album,
+  remove: remove
+};

+ 0 - 2
js/cache.js

@@ -180,7 +180,6 @@ var download = function(page, pageSize) {
   }
   //再检查本地是否有新增的数据
   var newItem = wx.getStorageSync(appConfig.storeKeys.newItem) || [];
-  app.log(newItem);
   if (newItem.length > 0) {
     wx.request({
       url: utils.getUrl('batchUpdate'),
@@ -191,7 +190,6 @@ var download = function(page, pageSize) {
       dataType: 'json',
       method: 'post',
       success: function(res) {
-        app.log(res);
         if (res.data) {
           if (res.data.data) {
             for (var i in res.data.data) {

+ 0 - 1
js/genKeys.js

@@ -16,7 +16,6 @@ var genKeys = function(that){
     dataType : 'json',
     success : function(res){
       wx.hideLoading();
-        app.log(res)
         if(res.data.code > 0) {
           wx.showToast({
             title: res.data.msg || "获取公私钥失败",

+ 0 - 1
js/info.js

@@ -29,7 +29,6 @@ var info = function (id) {
     method : "GET",
     dataType : "json",
     success : function(req){
-      app.log(req)
       app.infoSuccessSync(req.data)
     },
     fail: function (req) {

+ 0 - 1
js/login.js

@@ -80,7 +80,6 @@ var login = function (that) {
   //如果有openId 和 sessionId 就直接登录,不走获取微信信息
   wx.getSetting({
     success(res) {
-      app.log("wx.getSetting", res);
       if (res.authSetting['scope.userInfo']) {
         if (!app.globalData.res) {
           app.warning("用户信息获取失败");

+ 0 - 2
js/saveKeys.js

@@ -21,7 +21,6 @@ var saveKeys = function (that, forceUpdate) {
     method : 'POST',
     dataType: 'json',
     success: function (res) {
-      app.log(res)
       if (res.data.code == 5) {
         wx.showModal({
           title: '提示',
@@ -30,7 +29,6 @@ var saveKeys = function (that, forceUpdate) {
           confirmText: "更新",
           success: function (item) {
             if (item.confirm) {
-              app.log("更新", res.data.forceUpdate);
               saveKeys(that, res.data.forceUpdate);
             } else {
             }

+ 0 - 1
js/savePwd.js

@@ -59,7 +59,6 @@ var savePwd = function(that, data){
     method : "POST",
     dataType : "json",
     success : function(res) {
-      app.log(res)
       app.storeSuccess(res.data);
     },
     fail : function(res) {

Plik diff jest za duży
+ 0 - 0
js/sha1.js


+ 253 - 0
pages/components/album/album.js

@@ -0,0 +1,253 @@
+// pages/components/album/album.js
+const app = getApp();
+const common = require('../../../common');
+const utils = require("../../../utils/util");
+const appConfig = require("../../../config");
+const wxUploadFile = utils.promisify(wx.uploadFile);
+
+Component({
+  /**
+   * 组件的属性列表
+   */
+  properties: {
+    albumList: Object
+  },
+
+  /**
+   * 组件的初始数据
+   */
+  data: {
+    imgList: [],
+    albumList: {
+      "pages": {
+        "totalPage": 0,
+        "currentPage": 0,
+      },
+      "lists": []
+    },
+    bgColor: [
+      "grey",
+      "blue",
+      "red",
+      "cyan"
+    ],
+    pics: [],
+    isLoad: false,
+    lastId: 0,
+  },
+  ready: function () {
+    var _this = this;
+    this.loadAlbum(_this, this.data.lastId, 1, appConfig.pageSize);
+  },
+  /**
+   * 组件的方法列表
+   */
+  methods: {
+    setDefaultAlbum() {
+      this.setData({
+        albumList: {
+          "pages": {
+            "totalPage": 0,
+            "currentPage": 0,
+          },
+          "lists": []
+        },
+        lastId: 0,
+      });
+    },
+    onPullDownRefresh() {
+      wx.showNavigationBarLoading();
+      this.setDefaultAlbum();
+      this.loadAlbum(this, 0, 1, appConfig.pageSize);
+      wx.stopPullDownRefresh();
+    },
+    onReachBottom() {
+      if (!this.data.albumList.pages) {
+        return;
+      }
+      if (this.data.albumList.pages.currentPage < this.data.albumList.pages.totalPage) {
+        this.setData({
+          hiddenLoading: false,
+        });
+        //加载下一页
+        this.loadAlbum(this, this.data.lastId, parseInt(this.data.albumList.pages.currentPage) + 1, appConfig.pageSize);
+      }
+    },
+    loadAlbum(_this, lastId, page, pageSize) {
+      this.data.lastId = lastId;
+      this.setData({
+        "isLoad": false
+      });
+      app.albumSync = res => {
+        this.setData({
+          hiddenLoading: true,
+        });
+        var showRes = this.data.albumList;
+        if (parseInt(res.pages.currentPage) == 1) {
+          this.data.pics = [];
+          showRes = res;
+          for (var i in res.lists) {
+            this.data.pics.push(res.lists[i].source);
+          }
+        }else{
+          showRes['pages'] = res.pages;
+          for (var i in res.lists) {
+            this.data.lastId = res.lists[i].id;
+            this.data.pics.push(res.lists[i].source);
+            showRes.lists.push(res.lists[i]);
+          }
+        }
+
+        _this.setData({
+          albumList: showRes
+        });
+
+        if (res.pages.currentPage == res.pages.totalPage || res.pages.totalPage == 0) {
+          this.setData({
+            "isLoad": true
+          });
+          this.setData({
+            hiddenLoading: false,
+          });
+        }
+      }
+      common.album(this, this.data.lastId, page, pageSize)
+    },
+    showPic(e) {
+      var pics = [e.target.dataset.source, e.target.dataset.src];
+      var index = e.target.dataset.index;
+
+      wx.previewImage({
+        urls: this.data.pics,
+        current: pics[0] // 当前显示图片的http链接      
+      })
+    },
+    remove(e){
+      var _this = this;
+      var uid = e.target.dataset.uid;
+      var id = e.target.dataset.id;
+      var type = e.target.dataset.type;
+      app.removeAlbumSync = res =>{
+        if(typeof res != 'object') {
+          app.toast("删除失败");
+          return;
+        }
+        if(res.code > 0){
+          app.toast(res.msg || "删除失败");
+          return;
+        }
+
+        app.toast("删除成功");
+        setTimeout(function(){
+          _this.setDefaultAlbum();
+          _this.loadAlbum(_this, 0, 1, appConfig.pageSize);
+        }, 1500);
+      }
+      wx.showModal({
+        title: '温馨提示',
+        content: '是否要永久删除此照片',
+        success: function(item){
+          if (item.confirm) {
+            common.albumRemove(this, uid, id, type);
+          }
+        }
+      })
+    },
+    ChooseImage() {
+      wx.chooseImage({
+        count: 8, //默认9
+        sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
+        sourceType: ['album'], //从相册选择
+        success: (res) => {
+          if (this.data.imgList.length != 0) {
+            this.setData({
+              imgList: this.data.imgList.concat(res.tempFilePaths)
+            })
+          } else {
+            this.setData({
+              imgList: res.tempFilePaths
+            })
+          }
+        }
+      });
+    },
+    ViewImage(e) {
+      wx.previewImage({
+        urls: this.data.imgList,
+        current: e.currentTarget.dataset.url
+      });
+    },
+    DelImg(e) {
+      wx.showModal({
+        title: '召唤师',
+        content: '确定要删除这段回忆吗?',
+        cancelText: '再看看',
+        confirmText: '再见',
+        success: res => {
+          if (res.confirm) {
+            this.data.imgList.splice(e.currentTarget.dataset.index, 1);
+            this.setData({
+              imgList: this.data.imgList
+            })
+          }
+        }
+      })
+    },
+    submitForm: function() {
+      var _this = this;
+      if (this.data.imgList.length == 0) {
+        app.warning("请选择您要上传的文件~");
+        return;
+      }
+      wx.showLoading({
+        title: '上传中',
+      });
+      var header = {
+        'content-type': 'multipart/form-data',
+        'cookie': wx.getStorageSync(appConfig.storeKeys.sessionId)
+      };
+      var url = utils.getUrl("albumUpload");
+      var success = 0;
+      var fail = 0;
+      const arr = this.data.imgList.map(path => {
+        return wxUploadFile({
+          url: url,
+          header: header,
+          filePath: path,
+          name: 'file[]'
+        });
+      });
+      Promise.all(arr).then(res => {
+        return res.map(item => JSON.parse(item.data).data.files[0]);
+      }).catch(err => {
+        app.warning("上传文件失败~");
+        wx.hideLoading();
+      }).then(res => {
+          return res;
+        }).then(res => {
+          var success = 0;
+          var fail = 0;
+          for(var i in res) {
+            if(res[i].code == 0){
+              success++;
+            }else{
+              fail++;
+            }
+          }
+          wx.hideLoading();
+          if(fail > 0) {
+            app.toast("失败" + fail + "个");
+          }else{
+            app.toast("上传成功");
+            _this.setData({
+              imgList:[],
+            });
+          }
+          setTimeout(function () {
+            _this.setDefaultAlbum();
+            _this.loadAlbum(_this, 0, 1, appConfig.pageSize);
+          }, 2000);
+      });
+    }
+  }
+})

+ 5 - 0
pages/components/album/album.json

@@ -0,0 +1,5 @@
+{
+  "component": true,
+  "usingComponents": {},
+  "enablePullDownRefresh": true
+}

+ 51 - 0
pages/components/album/album.wxml

@@ -0,0 +1,51 @@
+<!--pages/components/wallpaper/wallpaper.wxml-->
+<scroll-view scroll-y class="scrollPage padding-tabbar">
+
+  <view style="opacity:{{0.85}}">
+    <form>
+      <view class="bg-white margin-top">
+        <view class="cu-bar bg-white">
+          <view class="action">
+            图片上传
+          </view>
+          <view class="action">
+            {{imgList.length}}/8
+          </view>
+        </view>
+      </view>
+      <view class="cu-form-group bg-white">
+        <view class="grid col-4 grid-square flex-sub">
+          <view class="bg-img" wx:for="{{imgList}}" wx:key="{{index}}" bindtap="ViewImage" data-url="{{imgList[index]}}">
+            <image src='{{imgList[index]}}' mode='aspectFill'></image>
+            <view class="cu-tag bg-red" catchtap="DelImg" data-index="{{index}}">
+              <text class="cuIcon-close"></text>
+            </view>
+          </view>
+          <view class="solids" bindtap="ChooseImage" wx:if="{{imgList.length<8}}">
+            <text class="cuIcon-cameraadd"></text>
+          </view>
+        </view>
+      </view>
+      <view class="margin-top padding">
+        <button class="cu-btn block bg-blue margin-tb-sm lg" catchtap="submitForm">上传</button>
+      </view>
+    </form>
+
+
+    <view class="cu-timeline">
+      <view class="cu-time">照片列表</view>
+      <view class="cu-item cur text-{{bgColor[(index%bgColor.length)]}}" wx:for="{{albumList.lists}}" wx:key>
+        <view class="content bg-{{bgColor[(index%bgColor.length)]}} shadow-blur">
+          <text>{{item.create_time}}</text>
+          <image data-source="{{item.source}}" data-src='{{item.thumb}}' data-index="{{index}}" src='{{item.thumb}}' mode='aspectFill' ontap="showPic"></image>
+          <text class="album-remove cuIcon-delete lg text-gray" data-id="{{item.id}}" data-uid="{{item.uid}}" data-type="{{item.type == 'folder' ? 'folder' : 'file' }}" catchtap="remove"></text>
+        </view>
+      </view>
+
+      <view class="cu-item cur">
+        <view class="cu-load bg-white {{!isLoad?'loading':'over'}} {{hiddenLoading?'hidden':'show'}}"></view>
+      </view>
+
+    </view>
+  </view>
+</scroll-view>

+ 10 - 0
pages/components/album/album.wxss

@@ -0,0 +1,10 @@
+/* pages/components/wallpaper/wallpaper.wxss */
+@import "/colorui/main.wxss";
+@import "/colorui/icon.wxss";
+.cu-form-group .title {
+  min-width: calc(4em + 30rpx);
+}
+.padding-tabbar{
+  padding-bottom: 80rpx;
+}
+.album-remove{background: #fff;padding: 2px;border-radius:50%;float:right;position:absolute;top:5px; right:5px;width:40rpx;height:40rpx;opacity:0.85;text-align: center;}

+ 47 - 17
pages/index/index.js

@@ -8,6 +8,7 @@ const cache = require('../../js/cache');
 
 Page({
   data: {
+    title : "密码本",
     motto: '请点击上边图标以授权此应用',
     userInfo: {},
     hiddenStatus: false,
@@ -56,12 +57,32 @@ Page({
       type: 'image',
         url: '/images/theme/10007.jpg'
     }],
+    imgList:[],
+    albumList:{
+      "pages" : {
+        "totalPage" : 0,
+        "currentPage" : 0,
+      },
+      "lists" : []
+    }
   },
   NavChange(e) {
+    var _this = this;
+
     this.setData({
       PageCur: e.currentTarget.dataset.cur,
       switchToLocalText: utils.getSwitchToLocalStatus() ? "切换到线上使用" : "切换到本地使用"
-    })
+    });
+    if (e.currentTarget.dataset.cur == 'album') {
+      this.setData({
+        'title' : '我的相册'
+      });
+      this.album = this.selectComponent("#album");
+    }else{
+      this.setData({
+        'title' : '密码本'
+      });
+    }
   },
   showModal(e) {
     this.setData({
@@ -133,12 +154,35 @@ Page({
       ListTouchDirection: null
     })
   },
-  onPullDownRefresh:function(){
+  onPullDownRefresh: function () {
+    if (this.data.PageCur == 'album') {
+      app.log('album onPullDownRefresh');
+      this.album.onPullDownRefresh();
+      return;
+    }
+    if (this.data.PageCur != 'passwd-note') {
+      return;
+    }
+    this.setData({
+      isLoad: false,
+      hiddenLoading: false,
+    });
     wx.showNavigationBarLoading();
     common.lists(this, 1, appConfig.pageSize);
     wx.stopPullDownRefresh();
   },
-  onReachBottom: function(){
+  onReachBottom: function () {
+    if (this.data.PageCur == 'album') {
+      app.log('album onReachBottom');
+      this.album.onReachBottom();
+      return;
+    }
+    if (this.data.PageCur != 'passwd-note') {
+      this.setData({
+        "onReachBottom": true,
+      });
+      return;
+    }
     if(!this.data.pages) {
         return;
     }
@@ -161,12 +205,10 @@ Page({
   //事件处理函数
   bindViewTap: function() {
     if (!utils.hasLogined()) {
-      app.log("bindViewTap reLogin");
       this.reLogin();
     }
   },
   clickItem: function (e) {
-    app.log("utils.hasLogined", utils.hasLogined());
     var _this = this;
     var method = e.target.dataset.id;
     switch (method) {
@@ -234,7 +276,6 @@ Page({
         });
         break;
       case 'save-to-local':
-        app.log('save-to-local');
         cache.download(1, 10000);
       break;
     }
@@ -263,7 +304,6 @@ Page({
   editPwd: function(e) {
     var _this = this;
     app.infoSuccessSync = res => {
-      app.log(res)
       if (!res || (res.code && res.code > 0)) {
         app.toast(res.msg || "获取失败");
         return;
@@ -314,9 +354,7 @@ Page({
   removePwd: function(e) {
     var id = e.target.dataset.id;
     var name = e.target.dataset.name;
-    app.log(id, name)
     app.removeSuccessSync = res => {
-      app.log("app.removeSuccessSync");
       if (!res || (res.code && res.code > 0)) {
         app.warning(res.msg || "删除失败");
         return;
@@ -382,7 +420,6 @@ Page({
     }
 
     app.sslKeyDecryptSync = res => {
-      app.log(res);
       if (!res ||  (res.code && res.code > 0)) {
         app.warning(res.msg || "解密失败");
         return;
@@ -457,7 +494,6 @@ Page({
         title: '温馨提示',
         content: '请输入您的私钥以解密您的密码',
         success: function(item) {
-          app.log(item);
           if (item.confirm) {
             wx.navigateTo({
               url: '/pages/privatekey/privatekey',
@@ -539,13 +575,10 @@ Page({
     }
     //保存数据到本地回调
     app.storeToLocal = res => {
-      app.log(res);
     }
 
     app.serInfoReady = res => {
       var _this = this;
-      app.log("app.serInfoReady(serverInfo)", res);
-      app.log("app.serInfoReady(serverInfo).code", res.code);
       if (!res || res.code > 0 || !res.data || !res.data.sslKeys) {
         if (res.code == 10005) {
           //删除本地登录信息,重新登录
@@ -556,7 +589,6 @@ Page({
           content: res.msg || "登录失败,请重试 ~",
           showCancel: false,
           success: function(item) {
-            app.log(item);
             _this.reLogin();
           }
         })
@@ -588,10 +620,8 @@ Page({
       // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
       // 所以此处加入 callback 以防止这种情况
       app.userInfoReadyCallback = res => {
-        app.log("app.userInfoReadyCallback");
         app.globalData.res = res
         common.login(this)
-        app.log(1, res.userInfo)
         this.setData({
           motto: "正在登录,请稍后...",
           userInfo: res.userInfo,

+ 4 - 2
pages/index/index.json

@@ -1,6 +1,8 @@
 {
   "usingComponents": {
     "about": "/pages/components/about/about",
-    "background": "/pages/components/background/background"
-  }
+    "background": "/pages/components/background/background",
+    "album" : "/pages/components/album/album"
+  },
+  "enablePullDownRefresh": true
 }

+ 10 - 0
pages/index/index.wxml

@@ -1,5 +1,9 @@
+<cu-custom>
+    <view class="nav-content" slot="content">{{title}}</view>
+</cu-custom>
 <background background="{{background}}"></background>
 <about wx:if="{{PageCur=='about'}}" switchToLocalText="{{switchToLocalText}}"></about>
+<album wx:if="{{PageCur == 'album'}}" imgList="{{imgList}}" id="album"></album>
 <home wx:if="{{PageCur=='passwd-note'}}">
   <view class="container">
     <view class="userinfo">
@@ -75,6 +79,12 @@
     </view>
     <view class="{{PageCur=='passwd-note'?'text-green':'text-gray'}}">我的密码</view>
   </view>
+  <view class="action" bindtap="NavChange" data-cur="album">
+    <view class='cuIcon-cu-image'>
+      <image src="/images/tabbar/basics{{PageCur=='album'?'_cur':''}}.png"></image>
+    </view>
+    <view class="{{PageCur=='album'?'text-green':'text-gray'}}">相册</view>
+  </view>
   <view class="action" bindtap="NavChange" data-cur="about">
     <view class='cuIcon-cu-image'>
       <image src="/images/tabbar/about{{PageCur=='about'?'_cur':''}}.png"></image>

+ 1 - 1
pages/index/index.wxss

@@ -16,7 +16,7 @@
 .userinfo-avatar-unauth{
   width: 158rpx;
   height: 158rpx;
-  margin: 20rpx;
+  padding: 20rpx;
 }
 
 .userinfo-nickname {

+ 1 - 1
pages/keys/keys.js

@@ -8,6 +8,7 @@ Page({
    * 页面的初始数据
    */
   data: {
+    title:"创建公私钥",
     publicKey : "",
     privateKey : "",
     background: "",
@@ -54,7 +55,6 @@ Page({
       }
     }
     app.sslKeySaveSync = res => {
-      app.log('sslKeySaveSync', res);
       //保存公私钥到本地
       wx.setStorageSync(appConfig.storeKeys.sslKeys, { 'publicKey': this.data.publicKey, 'privateKey': this.data.privateKey });
       //更新serverInfo中用户的公私钥

+ 4 - 0
pages/keys/keys.wxml

@@ -1,3 +1,7 @@
+<cu-custom bgColor="#39b54a" isBack="true">
+    <view class="nav_content" slot="backText">返回</view>
+    <view class="nav_content" slot="content">{{title}}</view>
+</cu-custom>
 <background background="{{background}}"></background>
 <view class="font-18" style="opacity:{{0.85}}">
 <view class="cu-bar bg-white solid-bottom margin-top">

+ 6 - 5
pages/password/password.js

@@ -26,7 +26,6 @@ Page({
   inputAction: function(e) {
     var name = e.target.dataset.id;
     var data = {};
-    app.log(name);
     if (name == 'passwordLength') {
       if(e.detail.value < 6) {
         data[name] = 6;
@@ -42,7 +41,6 @@ Page({
   },
   randPassword: function() {
     var passwd = rand.randCombin("alpha,smallLetter,bigLetter,specialChars", this.data.passwordLength, true);
-    app.log('password', passwd);
     this.setData({
       password: passwd
     });
@@ -77,7 +75,6 @@ Page({
     submitData.note = this.data.note;
     submitData.pubKey = this.data.pubKey;
     submitData.isEdit = this.data.isEdit;
-    app.log("submitData", submitData);
     common.savePwd(this, submitData);
   },
   /**
@@ -90,9 +87,11 @@ Page({
     wx.setNavigationBarTitle({
       title: '创建我的密码'
     });
+    this.setData({
+      "title" : '创建我的密码'
+    });
     var serverInfo = wx.getStorageSync("serverInfo");
     app.sslKeyDecryptSync = res => {
-      app.log(res)
       this.setData(app.globalData.info, utils.getPrivateKey());
       if (!res || (res.code && res.code > 0)) {
         app.warning(res.msg || "解密失败,请确认您的私钥是否正确~");
@@ -149,10 +148,12 @@ Page({
       wx.setNavigationBarTitle({
         title: '编辑我的密码',
       });
+      this.setData({
+        "title": '编辑我的密码'
+      });
       this.setData({
         isEdit : true
       });
-      app.log("app.globalData.info", typeof app.globalData.info);
     }
     this.setData({
       'pubKey': serverInfo.sslKeys.publicKey

+ 6 - 2
pages/password/password.wxml

@@ -1,4 +1,8 @@
 <!--pages/password/password.wxml-->
+<cu-custom isBack="true">
+    <view class="nav-content" slot="backText">返回</view>
+    <view class="nav-content" slot="content">{{title}}</view>
+</cu-custom>
 <background background="{{background}}"></background>
 <view style="opacity:{{0.85}}">
   <form>
@@ -12,9 +16,9 @@
     </view>
     <view class='cu-form-group'>
       <view class='title'>密码长度</view>
-      <text class='cuIcon-pulldown text-orange' bindtap="minusLength"></text>
+      <text class='cuIcon-triangledownfill bigTriangle text-orange' bindtap="minusLength"></text>
       <input class='text-center' type='text' placeholder="密码长度" bindinput="inputAction" id="passwordLength" data-id="passwordLength" value="{{passwordLength}}" disabled='disabled'></input>
-      <text class='cuIcon-pullup text-orange' bindtap="addLength"></text>
+      <text class='cuIcon-triangleupfill bigTriangle text-orange' bindtap="addLength"></text>
     </view>
     <view class="cu-form-group">
       <view class="title">密码</view>

+ 1 - 4
pages/privatekey/privatekey.js

@@ -9,13 +9,13 @@ Page({
    * 页面的初始数据
    */
   data: {
+    title:"验证私钥",
     publicKey : "",
     privateKey : "",
     background : "",
   },
   inputAction: function (e) {
     var name = e.target.dataset.id;
-    app.log(name, e.detail.value);
     var data = {};
     data[name] = e.detail.value;
     this.setData(data);
@@ -40,7 +40,6 @@ Page({
         res.msg = "校验失败,您的公私钥不匹配,请查证后再试!";
       }
     }catch(e) {
-      app.log(e);
       res.code = 400;
       res.msg = e;
     }
@@ -60,7 +59,6 @@ Page({
       title: '验证私钥'
     });
     app.verifyKeysSuccessSync = res => {
-      app.log(res)
       if(!res || (res.code && res.code > 0)) {
         app.warning(res.msg || "验证失败,请检查您的私钥~");
         return;
@@ -73,7 +71,6 @@ Page({
       //更新serverInfo中用户的公私钥
       var serverInfo = wx.getStorageSync(appConfig.storeKeys.serverInfo);
       serverInfo.sslKeys = { 'publicKey': this.data.publicKey, 'privateKey': this.data.privateKey };
-      app.log("更新 serverInfo", serverInfo);
       wx.setStorageSync(appConfig.storeKeys.serverInfo, serverInfo);
       wx.showModal({
         title: '温馨提示',

+ 4 - 0
pages/privatekey/privatekey.wxml

@@ -1,4 +1,8 @@
 <background background="{{background}}"></background>
+<cu-custom bgColor="#39b54a" isBack="true">
+    <view class="nav_content" slot="backText">返回</view>
+    <view class="nav_content" slot="content">{{title}}</view>
+</cu-custom>
 <view class="font-18" style="opacity:{{0.85}}">
 <view class="cu-bar bg-white solid-bottom margin-top">
   <view class="action">

+ 1 - 3
pages/reset/reset.js

@@ -8,6 +8,7 @@ Page({
    * 页面的初始数据
    */
   data: {
+    title:"重置私钥",
     publicKey: "",
     privateKey: "",
     opt: "",
@@ -15,7 +16,6 @@ Page({
   },
   textareaAInput : function(e){
     var name = e.target.dataset.id;
-    app.log(name, e.detail.value);
     var data = {};
     data[name] = e.detail.value;
     this.setData(data);
@@ -75,7 +75,6 @@ Page({
         app.warning(res.msg || "更新失败");
         return;
       }
-      app.log('sslKeySaveSync', res);
       this.data.publicKey = res.data.publicKey;
       this.data.privateKey = res.data.privateKey;
       this.setData({
@@ -88,7 +87,6 @@ Page({
       //更新serverInfo中用户的公私钥
       var serverInfo = wx.getStorageSync(appConfig.storeKeys.serverInfo);
       serverInfo.sslKeys = { 'publicKey': this.data.publicKey, 'privateKey': this.data.privateKey };
-      app.log("更新 serverInfo", serverInfo);
       wx.setStorageSync(appConfig.storeKeys.serverInfo, serverInfo);
       app.globalData.isReloadLists = true;
       

+ 4 - 0
pages/reset/reset.wxml

@@ -1,3 +1,7 @@
+<cu-custom isBack="true">
+    <view class="nav-content" slot="backText">返回</view>
+    <view class="nav-content" slot="content">{{title}}</view>
+</cu-custom>
 <background background="{{background}}"></background>
 <view class="font-18 white" style="opacity:{{0.85}}">
 <view class="cu-bar bg-white solid-bottom margin-top">

+ 1 - 1
project.config.json

@@ -21,7 +21,7 @@
 		}
 	},
 	"compileType": "miniprogram",
-	"libVersion": "2.7.0",
+	"libVersion": "2.7.7",
 	"appid": "wx3caf868dab62f709",
 	"projectname": "passwd",
 	"cloudfunctionTemplateRoot": "",

+ 35 - 5
utils/util.js

@@ -1,6 +1,7 @@
 const app =  getApp();
 const appConfig = require("../config")
 const Encrypt = require("../js/jsencrypt")
+const sha1 = require("../js/sha1");
 
 function http_build_query(formdata, numeric_prefix, arg_separator) {
   var value, key, tmp = [],
@@ -63,7 +64,13 @@ function urldecode(str) {
     return '';
   }
 }
-
+var ksort = function(arr) {
+  const ordered = {};
+  Object.keys(arr).sort().forEach(function (key) {
+    ordered[key] = arr[key];
+  });
+  return ordered;
+}
 const formatTime = date => {
   const year = date.getFullYear()
   const month = date.getMonth() + 1
@@ -106,9 +113,16 @@ var sslDecrypt = function (str, privateKey) {
   privateKey = privateKey.replace("-----END RSA PRIVATE KEY-----", "-----END PRIVATE KEY-----");
   return this.decrypt(str, privateKey);
 }
+var hexSha1 = function(str){
+  return sha1.sha1(str);
+}
+var sslSign = function (text, privateKey) {
+  var crypt = new Encrypt.JSEncrypt({ default_key_size: 1024 });
+  crypt.setPrivateKey(privateKey);
+  return crypt.sign(text, hexSha1, '');
+}
 //验证公私钥
 var verifySslKey = function(publicKey, privateKey){
-  app.log(publicKey, privateKey);
   var verifyStr = "It's ok";
   var encrypt = this.encrypt(verifyStr, publicKey);
   var decrypt = this.decrypt(encrypt, privateKey);
@@ -153,6 +167,8 @@ var getUrl = function(api, params) {
   {
     params = {};
   }
+  params.fromApp = "weixin";
+  params.appId = wx.getAccountInfoSync().miniProgram.appId;
   if (!appConfig.api[api]) {
     return "";
   }
@@ -173,8 +189,7 @@ var getSwitchToLocalStatus = function() {
 
 var syncServerInfo = function() { //同步更新serverInfo和sslKey
   var sslKeys = wx.getStorageSync(appConfig.storeKeys.sslKeys)
-  var serverInfo = wx.getStorageSync(appConfig.storeKeys.serverInfo)
-  app.log("syncServerInfo", sslKeys, serverInfo);
+  var serverInfo = wx.getStorageSync(appConfig.storeKeys.serverInfo);
   if (!serverInfo) return false;
   if (sslKeys && sslKeys['publicKey'] && sslKeys['privateKey'] &&
     serverInfo && serverInfo['sslKeys'] && (sslKeys['publicKey'] == serverInfo['sslKeys']['publicKey'])
@@ -277,19 +292,32 @@ var setBackground =  function(url) {
 }
 var getBackground = function() {
   var background = wx.getStorageSync(appConfig.storeKeys.background);
-  app.log(background);
   if (!background) return app.globalData.background;
   return background;
 }
+var promisify =  api => {
+  return (options, ...params) => {
+    return new Promise((resolve, reject) => {
+      const extras = {
+        success: resolve,
+        fail: reject
+      }
+      api({ ...options, ...extras }, ...params)
+    })
+  }
+}
 module.exports = {
   formatTime: formatTime,
+  hexSha1: hexSha1,
   sslEncrypt: encrypt,
   sslDecrypt: decrypt,
+  sslSign: sslSign,
   encrypt: encrypt,
   decrypt: decrypt,
   genSslKey: genSslKey,
   verifySslKey: verifySslKey,
   getUrl: getUrl,
+  httpBuild: http_build_query,
   getSwitchToLocalStatus: getSwitchToLocalStatus,
   showCreateTime: showCreateTime,
   syncServerInfo: syncServerInfo,
@@ -302,4 +330,6 @@ module.exports = {
   getOpenId: getOpenId,
   setBackground: setBackground,
   getBackground: getBackground,
+  promisify: promisify,
+  ksort: ksort,
 }

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików