index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import Vue from 'vue'
  2. import valid from './valid'
  3. import message from './message'
  4. import common from './common'
  5. import cache from './cache'
  6. import router from './router'
  7. import service from '../service'
  8. import event from './event'
  9. import throttle from './throttle'
  10. import wxLog from './wxLog'
  11. const logger = {
  12. log(message) {
  13. if (process.env.NODE_ENV != 'production') {
  14. console.log(message)
  15. }
  16. }
  17. }
  18. export const init = () => {
  19. // #ifdef MP-WEIXIN
  20. Vue.mixin({
  21. methods: {
  22. setTabBarIndex(index) {
  23. if (this.$mp.page && typeof this.$mp.page.getTabBar === 'function' && this.$mp.page.getTabBar()) {
  24. this.$mp.page.getTabBar().setData({
  25. selected: index
  26. })
  27. }
  28. }
  29. }
  30. })
  31. // #endif
  32. }
  33. export const initUser = async () => {
  34. if (common.isLogin()) return
  35. uni.login({
  36. scopes: 'auth_base',
  37. success: async result => {
  38. if (result.code) {
  39. const res = await service.user.login(result.code)
  40. if (res && !res.needLogin) {
  41. service.user.info()
  42. event.emit(event.key.LOGIN)
  43. }
  44. res && event.emit(event.key.LANUCH_COUPON)
  45. }
  46. }
  47. })
  48. }
  49. export { logger, valid, message, common, cache, router, event, throttle, wxLog }