mixin.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var prefix = 'jp_charging_' + process.car.NODE_ENV + '_';
  2. var app = {
  3. getPrefix:()=> prefix,
  4. get : key => uni.getStorageSync(prefix + key),
  5. set : (key, value) => uni.setStorageSync(prefix + key, value),
  6. remove: key => uni.removeStorageSync(prefix + key),
  7. getConfig : () => {
  8. var config = uni.getStorageSync(prefix + '_config_$')
  9. var configure={}
  10. if(config){
  11. for(var i in config){
  12. var con=config[i];
  13. configure[con.key]=con.value
  14. }
  15. }
  16. return configure;
  17. },
  18. setConfig : (value) => uni.setStorageSync(prefix + '_config_$', value),
  19. getPersonInfo : () => {
  20. return uni.getStorageSync(prefix + 'personInfo')
  21. },
  22. signOut:()=> uni.removeStorageSync(prefix + 'personInfo'),
  23. getOpenId : () => uni.getStorageSync(prefix + 'wx_openId'),
  24. setOpenId : (value) => uni.setStorageSync(prefix + 'wx_openId', value),
  25. setPersonInfo : (value) => uni.setStorageSync(prefix + 'personInfo', value),
  26. getToken : (options) => {
  27. //不同权限 ,不同token
  28. if(options&&options.jp_identity){
  29. return uni.getStorageSync(prefix+options.jp_identity+ '_token')
  30. }else{
  31. return uni.getStorageSync(prefix + 'token')
  32. }
  33. },
  34. setToken : (value) => {
  35. uni.setStorageSync(prefix + 'token', value)
  36. if(value){
  37. var tdate=new Date( +new Date() + 8 * 3600 * 1000 ).toJSON().substr(0,15).replace("T"," ")
  38. uni.setStorageSync(prefix + 'token_tdate', tdate)
  39. }
  40. }
  41. ,
  42. }
  43. module.exports = app