// pages/home/about/index.js const storage = require('../../../utils/storage') const util = require('../../../utils/util') const app = getApp() Page({ /** * 页面的初始数据 */ data: { height: app.globalData.fragmentHeight - 100, focus: true, rearchStringList: [], tabList: [ '交易', '行情', '订单' , '资讯'], tabIndex: 0, form: { name: '', pageSize: 10, pageNum: 1 }, taskList: [ ['极客小寨小程序开发_百度百科', '极客小寨微信小程序正式上线', '极客小寨微信小程序有哪些?关注极客小寨微信公众号获取微信小程序最全汇总?', '公众号出售-公众号价格-公众号买卖-A5公众号交易平台', '如何运营出一个有吸引力的微信公众号? - 微信公众平台号 - 知乎'] ] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var searchString = storage.get('mall-search') if(!util.isEmpty(searchString)){ this.setData({rearchStringList: searchString.split(',').slice(0, 24)}) } this.setData({height: app.globalData.fragmentHeight - 100}) }, clearHistory: function(){ var that = this wx.removeStorage({ key: 'mall-search', success (res) { that.setData({ rearchStringList: [] }) } }) }, onFocusChange: function(){ this.setData({ focus: true }) }, onBlurChange: function(){ if(util.isEmpty(this.data.form.name)){ return } this.setData({ focus: false }) }, onTabChange: function({detail}){ }, onSearchList: function({detail}){ this.data.form.name = detail.value if(util.isEmpty(this.data.form.name)){ util.showToast('请输入要搜索的关键字') return } var strList = this.data.rearchStringList if(!util.isEmpty(this.data.form.name) && strList.indexOf(this.data.form.name) < 0){ strList.splice(0, 0, this.data.form.name) } this.setData({ rearchStringList: strList.slice(0, 24), focus: false, ['form.name']: detail.value }) }, tagClick: function(e){ this.setData({ ['form.name']: this.data.rearchStringList[e.currentTarget.dataset.index] }) this.onSearchList({detail:{value: this.data.form.name}}) }, onUnload() { if(this.data.rearchStringList.length){ try { wx.setStorageSync('mall-search', this.data.rearchStringList.toString()) } catch (e) { } } } })