core.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * 公共方法
  3. */
  4. var dever = {
  5. /**
  6. * 初始化配置文件
  7. */
  8. init: function(){
  9. if (!this.config) {
  10. this.config = require('config.js').config;
  11. this.setting = {};
  12. this.log('init config', this.config);
  13. }
  14. },
  15. /**
  16. * 设置顶部导航栏标题
  17. */
  18. title: function(title){
  19. wx.setNavigationBarTitle({
  20. title: title
  21. })
  22. },
  23. /**
  24. * 保存数据到存储器
  25. */
  26. save: function(key, value){
  27. wx.setStorageSync(key, value);
  28. this.log('save ' + key, value);
  29. },
  30. /**
  31. * 读取保存数据到存储器
  32. */
  33. getSave: function (key) {
  34. return wx.getStorageSync(key);
  35. },
  36. /**
  37. * 设置服务器传过来的公共值
  38. */
  39. setSetting: function(value){
  40. this.setting = value;
  41. if (value.title) {
  42. this.title(value.title);
  43. } else if(value.name) {
  44. this.title(value.name);
  45. }
  46. this.log('init server setting', this.setting);
  47. },
  48. /**
  49. * 获取包
  50. */
  51. package: function(name){
  52. return require('package/' + name + '.js');
  53. },
  54. /**
  55. * 保存登录信息
  56. * vid Number 微信id
  57. * uid Number 用户id
  58. * signature String 用于登录后的uid验证,每次都要传入
  59. */
  60. saveLoginInfo: function (obj) {
  61. this.save('applet.bind', obj);
  62. },
  63. /**
  64. * 获取登录信息
  65. */
  66. getLoginInfo: function () {
  67. return this.getSave('applet.bind');
  68. },
  69. /**
  70. * 获取签名串儿
  71. */
  72. getSign: function () {
  73. let loginInfo = this.getLoginInfo();
  74. if (loginInfo == null) {
  75. return '';
  76. }
  77. return loginInfo.signature ? loginInfo.signature : '';
  78. },
  79. /**
  80. * 获取用户id
  81. */
  82. getUid: function(){
  83. let loginInfo = this.getLoginInfo();
  84. if (loginInfo == null) {
  85. return '';
  86. }
  87. return loginInfo.uid ? loginInfo.uid : '';
  88. },
  89. /**
  90. * 打印日志
  91. */
  92. log : function(title, msg){
  93. if (this.config.debug) {
  94. console.log('dever debug -- ' + title, msg);
  95. }
  96. }
  97. }
  98. dever.init();
  99. module.exports = dever;