//公共方法,写的匆忙。暂时先扔这里吧。 var dever = { //初始化 init : function() { if (!this.config) { this.config = require('config.js').config; this.setting = {}; this.log('init config', this.config); } } //设置title ,title : function(title) { wx.setNavigationBarTitle({ title: title }) } //获取模板里传过来的data ,getData : function(event) { return event.currentTarget.dataset; } //保存数据到存储器 ,save : function(key, value) { wx.setStorageSync(key, value); this.log('save ' + key, value); } //读取保存数据到存储器 ,getSave: function (key) { wx.getStorageSync(key) } //设置服务器传过来的公共值 ,setSetting : function(value) { this.setting = value; this.log('init server setting', this.setting); if (value.title) { this.title(value.title); } else if(value.name) { this.title(value.name); } } //设置模板变量 ,set : function(self, key, value) { var data = {}; data[key] = value; this.sets(self, data); } //设置模板变量 ,setList: function (self, value) { this.set(self, 'list', value); } //设置模板变量 , setView: function (self, value) { this.set(self, 'view', value); } //设置模板变量 ,sets: function (self, data) { this.log('data', data); self.setData(data); } //获取包 ,package : function(name) { return require('package/' + name + '.js'); } //html解析 ,html : function() { var wxParse = this.package('wxParse'); } //获取请求 ,request : function(url, param, callback, method) { if (!method) { method = 'get'; } return this.package('network').request(this, url, param, callback, method); } //提示框 ,alert : function(msg, title) { wx.showToast({ title: msg, icon: 'success', duration: 3000 }); } //跳转 ,location : function(url) { this.log('location', url); wx.navigateTo({ url: '../../template/' + url, }) } //log ,log : function(title, msg) { if (this.config.debug) { console.log('dever debug -- ' + title, msg); } } //开始下拉刷新 ,startPullDown : function(self) { wx.showNavigationBarLoading(); self.onLoad(); } //停止下拉刷新 ,stopPullDown: function () { wx.hideNavigationBarLoading(); wx.stopPullDownRefresh(); } //加载购物车 ,carts: function(self, save, path) { this.package('carts').load(self, save, path); } } dever.init(); module.exports = { load: dever }