log.js 739 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const logLength=100;//缓存存储上限
  2. const name = 'log';//缓存名字
  3. export function addLog (data,content='') {
  4. let log = uni.getStorageSync(name)||[];
  5. log.unshift({
  6. title:data,
  7. content:content
  8. });
  9. uni.setStorageSync(name,log);
  10. initLog(log);
  11. }
  12. export function delLog () {
  13. return uni.setStorageSync(name,'');
  14. }
  15. export function getLog () {
  16. return uni.getStorageSync(name);
  17. }
  18. export function initLog (log) {
  19. if(log.length>logLength){
  20. const newarr = log.slice(log.length-logLength);
  21. uni.setStorageSync(name,newarr);
  22. }
  23. }
  24. export function showLog (log) {
  25. let str = '';
  26. uni.getStorageSync(name).forEach((e) => {
  27. str+=e.title+':'+JSON.stringify(e.content)
  28. })
  29. uni.showModal({
  30. title:"日志",
  31. content:str
  32. })
  33. }