123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- /**
- * 公共方法
- */
- var dever = {
- /**
- * 初始化配置文件
- */
- init: function(){
- if (!this.config) {
- this.config = require('config.js').config;
- this.setting = {};
- this.log('init config', this.config);
- }
- },
- /**
- * 设置顶部导航栏标题
- */
- title: function(title){
- wx.setNavigationBarTitle({
- title: title
- })
- },
- /**
- * 保存数据到存储器
- */
- save: function(key, value){
- wx.setStorageSync(key, value);
- this.log('save ' + key, value);
- },
- /**
- * 读取保存数据到存储器
- */
- getSave: function (key) {
- return wx.getStorageSync(key);
- },
- /**
- * 设置服务器传过来的公共值
- */
- setSetting: function(value){
- this.setting = value;
- if (value.title) {
- this.title(value.title);
- } else if(value.name) {
- this.title(value.name);
- }
- this.log('init server setting', this.setting);
- },
- /**
- * 获取包
- */
- package: function(name){
- return require('package/' + name + '.js');
- },
- /**
- * 保存登录信息
- * vid Number 微信id
- * uid Number 用户id
- * signature String 用于登录后的uid验证,每次都要传入
- */
- saveLoginInfo: function (obj) {
- this.save('applet.bind', obj);
- },
- /**
- * 获取登录信息
- */
- getLoginInfo: function () {
- return this.getSave('applet.bind');
- },
- /**
- * 获取签名串儿
- */
- getSign: function () {
- let loginInfo = this.getLoginInfo();
- if (loginInfo == null) {
- return '';
- }
- return loginInfo.signature ? loginInfo.signature : '';
- },
- /**
- * 获取用户id
- */
- getUid: function(){
- let loginInfo = this.getLoginInfo();
- if (loginInfo == null) {
- return '';
- }
- return loginInfo.uid ? loginInfo.uid : '';
- },
- /**
- * 打印日志
- */
- log : function(title, msg){
- if (this.config.debug) {
- console.log('dever debug -- ' + title, msg);
- }
- }
-
- }
- dever.init();
- module.exports = dever;
|