|
@@ -1,218 +1,113 @@
|
|
|
+
|
|
|
+ * 公共方法
|
|
|
+ */
|
|
|
+var dever = {
|
|
|
|
|
|
-
|
|
|
-var dever =
|
|
|
-{
|
|
|
-
|
|
|
- init : function()
|
|
|
- {
|
|
|
- if (!this.config) {
|
|
|
- this.config = require('config.js').config;
|
|
|
- this.setting = {};
|
|
|
- this.log('init config', this.config);
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ * 初始化配置文件
|
|
|
+ */
|
|
|
+ init: function(){
|
|
|
+ if (!this.config) {
|
|
|
+ this.config = require('config.js').config;
|
|
|
+ this.setting = {};
|
|
|
+ this.log('init config', this.config);
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
-
|
|
|
- ,title : function(title)
|
|
|
- {
|
|
|
+
|
|
|
+ * 设置顶部导航栏标题
|
|
|
+ */
|
|
|
+ title: function(title){
|
|
|
wx.setNavigationBarTitle({
|
|
|
title: title
|
|
|
})
|
|
|
- }
|
|
|
+ },
|
|
|
|
|
|
-
|
|
|
- ,getData : function(event)
|
|
|
- {
|
|
|
- return event.currentTarget.dataset;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- ,save : function(key, value)
|
|
|
- {
|
|
|
+
|
|
|
+ * 保存数据到存储器
|
|
|
+ */
|
|
|
+ save: function(key, value){
|
|
|
wx.setStorageSync(key, value);
|
|
|
this.log('save ' + key, value);
|
|
|
- }
|
|
|
+ },
|
|
|
|
|
|
-
|
|
|
- ,getSave: function (key) {
|
|
|
+
|
|
|
+ * 读取保存数据到存储器
|
|
|
+ */
|
|
|
+ getSave: function (key) {
|
|
|
return wx.getStorageSync(key);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- ,saveLoginInfo: function(value){
|
|
|
- this.save('applet.bind', value);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- ,getLoginInfo: function(){
|
|
|
- return this.getSave('applet.bind');
|
|
|
- }
|
|
|
+ },
|
|
|
|
|
|
-
|
|
|
- ,getSignature: function(){
|
|
|
- if(this.getLoginInfo() == null){
|
|
|
- return '';
|
|
|
+
|
|
|
+ * 设置服务器传过来的公共值
|
|
|
+ */
|
|
|
+ setSetting: function(value){
|
|
|
+ this.setting = value;
|
|
|
+ if (value.title) {
|
|
|
+ this.title(value.title);
|
|
|
+ } else if(value.name) {
|
|
|
+ this.title(value.name);
|
|
|
}
|
|
|
- return this.getLoginInfo().signature ? this.getLoginInfo().signature : '';
|
|
|
- }
|
|
|
+ this.log('init server setting', this.setting);
|
|
|
+ },
|
|
|
|
|
|
-
|
|
|
- ,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);
|
|
|
- }
|
|
|
+
|
|
|
+ * 获取包
|
|
|
+ */
|
|
|
+ package: function(name){
|
|
|
+ return require('package/' + name + '.js');
|
|
|
+ },
|
|
|
|
|
|
-
|
|
|
- ,setList: function (self, value) {
|
|
|
- this.set(self, 'list', value);
|
|
|
- }
|
|
|
+
|
|
|
+ * 保存登录信息
|
|
|
+ * vid Number 微信id
|
|
|
+ * uid Number 用户id
|
|
|
+ * signature String 用于登录后的uid验证,每次都要传入
|
|
|
+ */
|
|
|
+ saveLoginInfo: function (obj) {
|
|
|
+ this.save('applet.bind', obj);
|
|
|
+ },
|
|
|
|
|
|
-
|
|
|
- ,sets: function (self, data) {
|
|
|
- this.log('data', data);
|
|
|
- self.setData(data);
|
|
|
- }
|
|
|
+
|
|
|
+ * 获取登录信息
|
|
|
+ */
|
|
|
+ getLoginInfo: function () {
|
|
|
+ return this.getSave('applet.bind');
|
|
|
+ },
|
|
|
|
|
|
-
|
|
|
- , appendList: function (self, value) {
|
|
|
- var list = self.data.list;
|
|
|
- for(var i=0; i<value.length; i++){
|
|
|
- list.push(value[i]);
|
|
|
+
|
|
|
+ * 获取签名串儿
|
|
|
+ */
|
|
|
+ getSign: function () {
|
|
|
+ let loginInfo = this.getLoginInfo();
|
|
|
+ if (loginInfo == null) {
|
|
|
+ return '';
|
|
|
}
|
|
|
- this.setList(self, list);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- , setView: function (self, value) {
|
|
|
- this.set(self, 'view', value);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- ,package : function(name)
|
|
|
- {
|
|
|
- return require('package/' + name + '.js');
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- , html: function (bindName, data, target)
|
|
|
- {
|
|
|
- var wxParse = this.package('wxParse/wxParse');
|
|
|
- wxParse.wxParse(bindName, 'html', data, target, 0);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- ,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: 'none',
|
|
|
- duration: 3000
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- ,location : function(url)
|
|
|
- {
|
|
|
- this.log('location', url);
|
|
|
- wx.navigateTo({
|
|
|
- url: '../../template/' + url,
|
|
|
- })
|
|
|
- }
|
|
|
+ return loginInfo.signature ? loginInfo.signature : '';
|
|
|
+ },
|
|
|
|
|
|
|
|
|
- * 重定向页面
|
|
|
+ * 获取用户id
|
|
|
*/
|
|
|
- ,redirect: function(url){
|
|
|
- this.log('redirect', url);
|
|
|
- wx.redirectTo({
|
|
|
- url: '../../template/' + url,
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- ,goBack: function(delta){
|
|
|
- if(typeof delta != 'number') delta = 1;
|
|
|
- wx.navigateBack({
|
|
|
- delta: delta
|
|
|
- })
|
|
|
- }
|
|
|
+ getUid: function(){
|
|
|
+ let loginInfo = this.getLoginInfo();
|
|
|
+ if (loginInfo == null) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ return loginInfo.uid ? loginInfo.uid : '';
|
|
|
+ },
|
|
|
|
|
|
-
|
|
|
- ,log : function(title, msg)
|
|
|
- {
|
|
|
+
|
|
|
+ * 打印日志
|
|
|
+ */
|
|
|
+ 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);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- ,showLoading: function(){
|
|
|
- wx.showLoading({
|
|
|
- title: '加载中',
|
|
|
- mask: true
|
|
|
- })
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- ,hideLoading: function(){
|
|
|
- wx.hideLoading();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- ,isLogin: function(fun){
|
|
|
- wx.checkSession({
|
|
|
- success: function(res){
|
|
|
- fun(true);
|
|
|
- },
|
|
|
- fail: function(res){
|
|
|
- fun(false);
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
}
|
|
|
+
|
|
|
dever.init();
|
|
|
-module.exports = {
|
|
|
- load: dever
|
|
|
-}
|
|
|
+
|
|
|
+module.exports = dever;
|