mixin.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * 全局注入器
  3. */
  4. let page = {
  5. data() {
  6. return {
  7. }
  8. },
  9. computed: {
  10. //ios底部安全区域
  11. safeAreaBottom() {
  12. let info = uni.getSystemInfoSync()
  13. let safe = 20
  14. if (
  15. info && ['devtools', 'ios'].includes(info.platform) &&
  16. info.statusBarHeight > safe
  17. ) {
  18. return info.statusBarHeight - safe + 'px'
  19. }
  20. return 0
  21. },
  22. discount(){
  23. return data=>{
  24. if (data==-1 || data==0 || data==1 || data == null) {
  25. return '无折扣'
  26. }
  27. return data * 10 + "折"
  28. }
  29. }
  30. },
  31. methods: {
  32. },
  33. onLoad(options) {
  34. let currentPage = this.$util.getCurrentRoute()
  35. //全局登录拦截
  36. let WHiTE_LIST = ['pages/login/login',
  37. 'pages/login/forget',
  38. 'pages/login/register',
  39. 'pages/login/account-login',
  40. 'pages/webView/webView',
  41. 'pages/login/submit-success',
  42. 'pages/test/test',
  43. 'pages/chooseLable/chooseLable',
  44. 'pages/shop-info/shop-info',
  45. ]
  46. if (!WHiTE_LIST.includes(currentPage)) {
  47. if (!this.$cache.get('phone')) {
  48. uni.reLaunch({
  49. url: "/pages/login/account-login"
  50. })
  51. return
  52. }
  53. }
  54. //判断商场id是否为空
  55. WHiTE_LIST.push('pages/index/index')
  56. if (!WHiTE_LIST.includes(currentPage)) {
  57. if (!this.vuex_shopId) {
  58. uni.reLaunch({
  59. url:"/pages/index/index"
  60. })
  61. return
  62. }
  63. }
  64. }
  65. }
  66. export default page