Jelajahi Sumber

新增搜索,修复部分bug

Jinhui Zhu 4 tahun lalu
induk
melakukan
a33c0bb37a
9 mengubah file dengan 124 tambahan dan 75 penghapusan
  1. 2 1
      app.wxss
  2. 2 2
      common.js
  3. 15 1
      js/cache.js
  4. 4 3
      js/lists.js
  5. 3 0
      pages/components/album/album.js
  6. 2 2
      pages/components/album/album.wxml
  7. 15 5
      pages/index/index.js
  8. 18 8
      pages/index/index.wxml
  9. 63 53
      project.config.json

+ 2 - 1
app.wxss

@@ -153,4 +153,5 @@
  button[plain]{ border:0 }
  .tab-bottom{padding:43rpx;}
  .text-center{text-align: center;}
- .cu-form-group>text.bigTriangle{font-size:66rpx;}
+ .cu-form-group>text.bigTriangle{font-size:66rpx;}
+ .cu-avatar.lg{overflow: hidden;}

+ 2 - 2
common.js

@@ -17,8 +17,8 @@ var common = {
   login: function(_this) {
     login(_this)
   },
-  lists: function(_this, page, pageSize) {
-    lists.pwd(_this, page, pageSize)
+  lists: function(_this, page, pageSize, keyword) {
+    lists.pwd(_this, page, pageSize, keyword)
   },
   genKeys: function(_this) {
     genKeys(_this);

+ 15 - 1
js/cache.js

@@ -308,7 +308,7 @@ var download = function(page, pageSize) {
     }
   });
 }
-var getFromLocal = function(page, pageSize) {
+var getFromLocal = function(page, pageSize, keyword) {
   var pages = {
     total: 0,
     currentPage: 1,
@@ -323,6 +323,20 @@ var getFromLocal = function(page, pageSize) {
   data.sort(function(x, y) {
     return parseInt(y['id']) - parseInt(x['id']);
   });
+  //如果传了搜索关键字,就过滤一下数据再输出
+  if(keyword != "") {
+    var tmpArr = new Array();
+    for(var i in data) {
+      var val = data[i];
+      if(val['name'].indexOf(keyword) != -1 ||
+        val['account'].indexOf(keyword) != -1||
+        val['note'].indexOf(keyword) != -1
+      ) {
+        tmpArr.push(data[i])
+      }
+    }
+    data = tmpArr;
+  }
   pages.total = parseInt(data.length);
   pages.totalPage = Math.ceil(pages.total / pages.pageSize);
   pages.currentPage = Math.min(parseInt(page), pages.totalPage);

+ 4 - 3
js/lists.js

@@ -3,9 +3,9 @@ const appConfig = require("../config");
 const utils = require("../utils/util");
 const cache = require("cache");
 
-var lists = function(_this, page, pageSize) {
+var lists = function(_this, page, pageSize, keyword) {
   if (utils.getSwitchToLocalStatus()) {
-    var res = cache.getFromLocal(page, pageSize);
+    var res = cache.getFromLocal(page, pageSize, keyword);
     app.listSync(res);
     return;
   }
@@ -16,7 +16,8 @@ var lists = function(_this, page, pageSize) {
   wx.request({
     url: utils.getUrl("lists", {
       page: page,
-      pageSize: pageSize
+      pageSize: pageSize,
+      keyword: keyword
     }),
     header: header,
     dataType: "json",

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

@@ -6,6 +6,9 @@ const appConfig = require("../../../config");
 const wxUploadFile = utils.promisify(wx.uploadFile);
 
 Component({
+  options: {
+    addGlobalClass: true,
+  },
   /**
    * 组件的属性列表
    */

+ 2 - 2
pages/components/album/album.wxml

@@ -15,7 +15,7 @@
       </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]}}">
+          <view class="bg-img" wx:for="{{imgList}}" wx:key="index" bindtap="ViewImage" data-url="{{imgList[index]}}">
             <image src='{{imgList[index]}}' mode='aspectFit'></image>
             <view class="cu-tag bg-red" catchtap="DelImg" data-index="{{index}}">
               <text class="cuIcon-close"></text>
@@ -34,7 +34,7 @@
 
     <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="cu-item cur text-{{bgColor[(index%bgColor.length)]}}" wx:for="{{albumList.lists}}" wx:key="id">
         <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>

+ 15 - 5
pages/index/index.js

@@ -28,6 +28,7 @@ Page({
     isLoad: false,
     cardCur: 0,
     DotStyle: "square-dot",
+    keyword:"",
     swiperList: [{
       id: 0,
       type: 'image',
@@ -167,7 +168,7 @@ Page({
       hiddenLoading: false,
     });
     wx.showNavigationBarLoading();
-    common.lists(this, 1, appConfig.pageSize);
+    common.lists(this, 1, appConfig.pageSize, this.data.keyword);
     wx.stopPullDownRefresh();
   },
   onReachBottom: function () {
@@ -189,7 +190,7 @@ Page({
         hiddenLoading: false,
       });
       //加载下一页
-      common.lists(this, parseInt(this.data.pages.currentPage) + 1, appConfig.pageSize);
+      common.lists(this, parseInt(this.data.pages.currentPage) + 1, appConfig.pageSize, this.data.keyword);
     }
   },
   setToBackground: function(e){
@@ -284,7 +285,7 @@ Page({
       this.setData({
         hiddenLoading: false,
       });
-      common.lists(this, 1, appConfig.pageSize);
+      common.lists(this, 1, appConfig.pageSize, this.data.keyword);
       app.globalData.isReloadLists = false;
     }
     if (app.globalData.isReloadIcon) {
@@ -299,6 +300,15 @@ Page({
   reLogin: function() {
     app.login();
   },
+  inputAction: function(e){
+    var name = e.target.dataset.id;
+    var data = {};
+    data[name] = e.detail.value;
+    this.setData(data);
+  },
+  search: function(e) {
+    common.lists(this, 1, appConfig.pageSize, this.data.keyword)
+  },
   editPwd: function(e) {
     var _this = this;
     app.infoSuccessSync = res => {
@@ -510,7 +520,7 @@ Page({
       this.setData({
         hiddenLoading: false,
       });
-      common.lists(this, 1, appConfig.pageSize)
+      common.lists(this, 1, appConfig.pageSize, this.data.keyword)
     }
   },
   onLoad: function() {
@@ -568,7 +578,7 @@ Page({
 
       app.toast("同步成功");
       if (utils.getSwitchToLocalStatus) {
-        common.lists(this, 1, appConfig.pageSize);
+        common.lists(this, 1, appConfig.pageSize, this.data.keyword);
       }
     }
     //保存数据到本地回调

+ 18 - 8
pages/index/index.wxml

@@ -15,9 +15,10 @@
         <text class="userinfo-nickname white">{{userInfo.nickName}}</text>
       </block>
     </view>
+
     <scroll-view scroll-y="{{modalName==null}}" class="page {{modalName!=null?'show':''}}" wx:if="{{showLists}}" style="opacity:{{0.85}}">
       <view class="cu-list grid col-{{iconCls}}">
-        <view class="cu-item" wx:for="{{iconList}}" wx:key="{{item.method}}" bindtap='clickItem' data-id="{{item.method}}">
+        <view class="cu-item" wx:for="{{iconList}}" wx:key="method" bindtap='clickItem' data-id="{{item.method}}">
           <view class="cuIcon-{{item.icon}} text-{{item.color}}" data-id="{{item.method}}">
             <view class="cu-tag badge" wx:if="{{item.badge!=0}}">
               <block wx:if="{{item.badge!=1}}">{{item.badge>99?"99+":item.badge}}</block>
@@ -27,15 +28,24 @@
         </view>
       </view>
       <view class="cu-bar bg-white solid-bottom margin-top">
-        <view class="action">
-          已保存密码
+        <view class="cu-list box">
+          <view class="cu-bar search bg-white">
+            <view class="search-form round">
+              <text class="cuIcon-search"></text>
+              <input type="text" id="search-kwd" placeholder="请输入关键字"  bindinput="inputAction" data-id="keyword" confirm-type="search"></input>
+            </view>
+            <view class="action">
+              <button class="cu-btn bg-green shadow-blur round" bindtap="search">搜索</button>
+            </view>
+          </view>
         </view>
-      </view>
+      </view> 
       <view class="cu-list menu-avatar">
-        <view class="cu-item {{modalName=='move-box-'+ index?'move-cur':''}}" wx:for="{{lists}}" wx:key bindtouchstart="ListTouchStart" bindtouchmove="ListTouchMove" bindtouchend="ListTouchEnd" data-target="move-box-{{index}}">
-          <view class="cu-avatar lg round small-font {{colors[(index+1%colors.length)]}}" data-id="{{item.id}}" bindtap='editPwd'>{{item.name}}</view>
+        <view class="cu-item {{modalName=='move-box-'+ index?'move-cur':''}}" wx:for="{{lists}}" wx:key="id" bindtouchstart="ListTouchStart" bindtouchmove="ListTouchMove" bindtouchend="ListTouchEnd" data-target="move-box-{{index}}">
+          <view class="cu-avatar lg round small-font {{colors[(index+1)%colors.length]}}" data-id="{{item.id}}" bindtap='editPwd'>{{item.name}}</view>
           <view class="content">
-            <view class="text-grey">账户 - {{item.account}}</view>
+            <view class="text-grey text-cut">{{item.name}}</view>
+            <view class="text-grey">{{item.account}}</view>
             <view class="text-gray text-sm text-cut">
               <text class="cuIcon-infofill text-red" bindtap='copyPwd' data-val="{{item.password}}">查看密码</text> - {{item.password}}</view>
           </view>
@@ -63,7 +73,7 @@
       </view>
     </view>
     <swiper class="screen-swiper {{DotStyle?'square-dot':'round-dot'}}" indicator-dots="true" circular="true" autoplay="true" interval="5000" duration="500">
-      <swiper-item wx:for="{{swiperList}}" wx:key data-src="{{item.url}}" bindtap='setToBackground'>
+      <swiper-item wx:for="{{swiperList}}" wx:key="id" data-src="{{item.url}}" bindtap='setToBackground'>
         <image src="{{item.url}}" mode="aspectFill" wx:if="{{item.type=='image'}}"></image>
         <video src="{{item.url}}" autoplay loop muted show-play-btn="{{false}}" controls="{{false}}" objectFit="cover" wx:if="{{item.type=='video'}}"></video>
       </swiper-item>

+ 63 - 53
project.config.json

@@ -1,55 +1,65 @@
 {
-	"description": "项目配置文件",
-	"packOptions": {
-		"ignore": []
-	},
-	"setting": {
-		"urlCheck": false,
-		"es6": true,
-		"postcss": true,
-		"minified": true,
-		"newFeature": true,
-		"coverView": true,
-		"autoAudits": false,
-		"checkInvalidKey": true,
-		"checkSiteMap": true,
-		"uploadWithSourceMap": true,
-		"babelSetting": {
-			"ignore": [],
-			"disablePlugins": [],
-			"outputPath": ""
-		}
-	},
-	"compileType": "miniprogram",
-	"libVersion": "2.7.7",
-	"appid": "wx3caf868dab62f709",
-	"projectname": "passwd",
-	"cloudfunctionTemplateRoot": "",
-	"debugOptions": {
-		"hidedInDevtools": []
-	},
-	"scripts": {},
-	"simulatorType": "wechat",
-	"simulatorPluginLibVersion": {},
-	"condition": {
-		"search": {
-			"current": -1,
-			"list": []
-		},
-		"conversation": {
-			"current": -1,
-			"list": []
-		},
-		"plugin": {
-			"current": -1,
-			"list": []
-		},
-		"game": {
-			"list": []
-		},
-		"miniprogram": {
-			"current": -1,
-			"list": []
-		}
-	}
+  "description": "项目配置文件",
+  "packOptions": {
+    "ignore": []
+  },
+  "setting": {
+    "urlCheck": false,
+    "es6": true,
+    "enhance": false,
+    "postcss": true,
+    "preloadBackgroundData": false,
+    "minified": true,
+    "newFeature": true,
+    "coverView": true,
+    "nodeModules": false,
+    "autoAudits": false,
+    "showShadowRootInWxmlPanel": true,
+    "scopeDataCheck": false,
+    "uglifyFileName": false,
+    "checkInvalidKey": true,
+    "checkSiteMap": true,
+    "uploadWithSourceMap": true,
+    "compileHotReLoad": false,
+    "useMultiFrameRuntime": false,
+    "useApiHook": true,
+    "babelSetting": {
+      "ignore": [],
+      "disablePlugins": [],
+      "outputPath": ""
+    },
+    "useIsolateContext": true,
+    "useCompilerModule": true,
+    "userConfirmedUseCompilerModuleSwitch": false,
+    "packNpmManually": false,
+    "packNpmRelationList": []
+  },
+  "compileType": "miniprogram",
+  "libVersion": "2.7.7",
+  "appid": "wx3caf868dab62f709",
+  "projectname": "passwd",
+  "cloudfunctionTemplateRoot": "",
+  "debugOptions": {
+    "hidedInDevtools": []
+  },
+  "scripts": {},
+  "simulatorType": "wechat",
+  "simulatorPluginLibVersion": {},
+  "condition": {
+    "search": {
+      "list": []
+    },
+    "conversation": {
+      "list": []
+    },
+    "plugin": {
+      "list": []
+    },
+    "game": {
+      "list": []
+    },
+    "miniprogram": {
+      "list": []
+    }
+  }
 }