|
@@ -0,0 +1,260 @@
|
|
|
+
|
|
|
+var dever =
|
|
|
+{
|
|
|
+
|
|
|
+ init : function()
|
|
|
+ {
|
|
|
+ if (!this.config) {
|
|
|
+ this.config = require('config.js').config;
|
|
|
+ this.setting = {};
|
|
|
+ this.log('init config', this.config);
|
|
|
+
|
|
|
+ wx.getSystemInfo({
|
|
|
+ success: e => {
|
|
|
+ this.config.bar = {};
|
|
|
+ this.config.bar.status = e.statusBarHeight;
|
|
|
+ this.config.bar.custom = e.platform == 'android' ? e.statusBarHeight + 50 : e.statusBarHeight + 45;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,title : function(title)
|
|
|
+ {
|
|
|
+ wx.setNavigationBarTitle({
|
|
|
+ title: title
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,package : function(name)
|
|
|
+ {
|
|
|
+ return require('package/' + name + '.js');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,html : function()
|
|
|
+ {
|
|
|
+ var wxParse = this.package('wxParse');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,alert : function(msg, title)
|
|
|
+ {
|
|
|
+ wx.showToast({
|
|
|
+ title: msg,
|
|
|
+ icon: 'success',
|
|
|
+ duration: 3000
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,location : function(url)
|
|
|
+ {
|
|
|
+ this.log('location', url);
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '../../template/' + url,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,goBack: function(delta)
|
|
|
+ {
|
|
|
+ if(typeof delta == 'undefined') delta = 1;
|
|
|
+ wx.navigateBack({
|
|
|
+ delta: delta
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,log : function(title, msg)
|
|
|
+ {
|
|
|
+ if (this.config.debug) {
|
|
|
+ console.log('dever debug -- ' + title, msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,carts: function(self, save, path)
|
|
|
+ {
|
|
|
+ this.package('carts').load(self, save, path);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+var page =
|
|
|
+{
|
|
|
+ dever : dever.init()
|
|
|
+ ,data: {}
|
|
|
+
|
|
|
+
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ ,onLoad: function (options) {
|
|
|
+ this.setConfig();
|
|
|
+ this.stopPullDown();
|
|
|
+ if (this.hasOwnProperty('oLoad')) {
|
|
|
+ this.oLoad(options);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ ,onReady: function () {
|
|
|
+ if (this.hasOwnProperty('oReady')) {
|
|
|
+ this.oReady();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ ,onShow: function () {
|
|
|
+ if (this.hasOwnProperty('oShow')) {
|
|
|
+ this.oShow();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ ,onHide: function () {
|
|
|
+ if (this.hasOwnProperty('oHide')) {
|
|
|
+ this.oHide();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ ,onUnload: function () {
|
|
|
+ if (this.hasOwnProperty('oUnload')) {
|
|
|
+ this.oUnload();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ ,onPullDownRefresh: function () {
|
|
|
+ wx.showNavigationBarLoading();
|
|
|
+ this.onLoad();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 停止下拉刷新
|
|
|
+ */
|
|
|
+ ,stopPullDown: function () {
|
|
|
+ wx.hideNavigationBarLoading();
|
|
|
+ wx.stopPullDownRefresh();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ ,onShareAppMessage: function () {
|
|
|
+ if (this.hasOwnProperty('oShare')) {
|
|
|
+ this.oShare();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,set : function(key, value)
|
|
|
+ {
|
|
|
+ var data = {};
|
|
|
+ data[key] = value;
|
|
|
+ this.sets(data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,setList: function (value)
|
|
|
+ {
|
|
|
+ this.set('list', value);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,setView: function (value)
|
|
|
+ {
|
|
|
+ this.set('view', value);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,sets: function (data)
|
|
|
+ {
|
|
|
+ this.dever.log('data', data);
|
|
|
+ this.setData(data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,setConfig: function ()
|
|
|
+ {
|
|
|
+ this.set('config', this.dever.config);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ,request : function(url, param, callback, method)
|
|
|
+ {
|
|
|
+ if (!method) {
|
|
|
+ method = 'get';
|
|
|
+ }
|
|
|
+ return this.dever.package('network').request(this, url, param, callback, method);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+var app =
|
|
|
+{
|
|
|
+ onLaunch: function () {
|
|
|
+ if (this.hasOwnProperty('oLaunch')) {
|
|
|
+ this.oLaunch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onShow: function () {
|
|
|
+ if (this.hasOwnProperty('oShow')) {
|
|
|
+ this.oShow();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onHide: function () {
|
|
|
+ if (this.hasOwnProperty('oHide')) {
|
|
|
+ this.oHide();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ dever: dever,
|
|
|
+ page: page
|
|
|
+}
|
|
|
+
|
|
|
+module.exports = {
|
|
|
+ app: app
|
|
|
+}
|