context.js 621 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. *
  3. * @type {{foo(*)}}
  4. */
  5. 'use strict';
  6. module.exports = {
  7. isMobile() {
  8. const deviceAgent = this.get('user-agent').toLowerCase();
  9. const agentID = deviceAgent.match(/(iphone|ipod|ipad|android)/);
  10. if (agentID) {
  11. // 手机访问
  12. return true;
  13. }
  14. // 电脑访问
  15. return false;
  16. },
  17. success(msg, data, total) {
  18. this.body = {
  19. success: true,
  20. msg,
  21. result: data,
  22. total,
  23. };
  24. },
  25. failure(msg, data) {
  26. this.body = {
  27. success: false,
  28. msg,
  29. result: data,
  30. };
  31. },
  32. async infoPage(msg) {
  33. await this.render('500', { msg });
  34. },
  35. };