main.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import Vue from 'vue'
  4. import FastClick from 'fastclick'
  5. import VueRouter from 'vue-router'
  6. import VueResource from 'vue-resource'
  7. import App from './App.vue'
  8. import Vuex from 'vuex'
  9. import {ConfirmPlugin} from 'vux'
  10. import VueVideoPlayer from 'vue-video-player'
  11. import {ToastPlugin} from 'vux'
  12. import routes from './router/routes'
  13. import WechatShare from './wechat/WechatShare'
  14. import {base64} from 'vux'
  15. import CommonUtil from './components/util/commonUtil.js'
  16. import Actions from './lib/Actions'
  17. Vue.use(VueRouter);
  18. Vue.use(VueResource);
  19. Vue.use(Vuex);
  20. Vue.use(VueVideoPlayer);
  21. Vue.use(ToastPlugin);
  22. Vue.use(ConfirmPlugin);
  23. const store = new Vuex.Store({
  24. state: {
  25. isLoading: false,
  26. isLogIn: false,
  27. user: {
  28. name: '',
  29. image: ''
  30. },
  31. changeState: {
  32. action: null,
  33. action_id: -1
  34. },
  35. user_bonus: [],
  36. address:{
  37. aid:'',
  38. name:'',
  39. mobile:'',
  40. address:''
  41. },
  42. wechatShareMsg:{
  43. title:'熊猫美妆测试版',
  44. desc:'熊猫美妆即将上线',
  45. link:window.location.host,
  46. imgUrl:'http://manager.lrlz.com/data/upload/shop/store/goods/6/6_05065318508868273_360.jpg'
  47. }
  48. },
  49. mutations: {
  50. updateLoadingStatus (state, payload) {
  51. state.isLoading = payload.isLoading
  52. },
  53. updateLogIn(state){
  54. state.isLogIn = true
  55. },
  56. updateUser(state, payload){
  57. state.user['name'] = payload.name;
  58. state.user['image'] = payload.image;
  59. },
  60. updateOrderState(state, payload){
  61. state.changeState.action = payload.action;
  62. state.changeState.action_id = payload.action_id;
  63. },
  64. updateUser_bonus(state, payload) {
  65. state.user_bonus = payload.array;
  66. },
  67. update_address(state, payload){
  68. state.address.name = payload.name;
  69. state.address.mobile = payload.mobile;
  70. state.address.address = payload.address;
  71. state.address.aid = payload.aid;
  72. },
  73. updateWxShareMsg(state,payload){
  74. state.wechatShareMsg.title = payload.title;
  75. state.wechatShareMsg.desc = payload.desc;
  76. state.wechatShareMsg.link = payload.link;
  77. state.wechatShareMsg.imgUrl = payload.imgUrl;
  78. }
  79. }
  80. });
  81. const scrollBehavior = (to, from, savedPosition) => {
  82. if (savedPosition) {
  83. setTimeout(() => {
  84. document.body.scrollTop = savedPosition.y
  85. }, 100);
  86. return savedPosition
  87. }
  88. return {
  89. x: 0,
  90. y: 0
  91. };
  92. };
  93. const router = new VueRouter({
  94. routes,
  95. scrollBehavior,
  96. mode: 'hash'
  97. });
  98. router.beforeEach(function (to, from, next) {
  99. if (to.path.indexOf("schema") !== -1) {
  100. let schema = base64.decode(to.query.schema);
  101. let urlObj = CommonUtil.parseURL(schema);
  102. let path = urlObj.path;
  103. switch (path) {
  104. case "//p.lrlz.com/web/web":
  105. let title = decodeURI(urlObj.params.title);
  106. let url = base64.encode(decodeURIComponent(urlObj.params.url));
  107. next(Actions.getWebViewPath(title, url));
  108. break
  109. }
  110. } else {
  111. next();
  112. }
  113. });
  114. let Wechat_share = new WechatShare(store.state.wechatShareMsg);
  115. FastClick.attach(document.body);
  116. Vue.config.productionTip = false;
  117. Vue.directive('document_title', {
  118. inserted: function (el, binding) {
  119. document.title = el.innerText;
  120. el.remove();
  121. }
  122. });
  123. /* eslint-disable no-new */
  124. new Vue({
  125. store,
  126. router,
  127. render: h => h(App)
  128. }).$mount('#app-box');