123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- 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('load')) {
- this.load();
- }
- }
-
- ,onReady: function () {
- if (this.hasOwnProperty('ready')) {
- this.ready();
- }
- }
-
- ,onShow: function () {
- if (this.hasOwnProperty('show')) {
- this.show();
- }
- }
-
- ,onHide: function () {
- if (this.hasOwnProperty('hide')) {
- this.hide();
- }
- }
-
- ,onUnload: function () {
- if (this.hasOwnProperty('unload')) {
- this.unload();
- }
- }
-
- ,onPullDownRefresh: function () {
- wx.showNavigationBarLoading();
- this.onLoad();
- }
-
- ,stopPullDown: function () {
- wx.hideNavigationBarLoading();
- wx.stopPullDownRefresh();
- }
-
- ,onShareAppMessage: function () {
- if (this.hasOwnProperty('share')) {
- this.share();
- }
- }
-
- ,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('launch')) {
- this.launch();
- }
- },
- onShow: function () {
- if (this.hasOwnProperty('show')) {
- this.show();
- }
- },
- onHide: function () {
- if (this.hasOwnProperty('hide')) {
- this.hide();
- }
- },
- dever: dever,
- page: page
- }
- module.exports = {
- app: app
- }
|