main.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // #ifdef H5
  2. // 解析地址栏参数
  3. function getQueryVariable(variable) {
  4. // 从?开始获取后面的所有数据
  5. var query = window.location.search.substring(1)
  6. // 从字符串&开始分隔成数组split
  7. var vars = query.split('&')
  8. // 遍历该数组
  9. for (var i = 0; i < vars.length; i++) {
  10. // 从等号部分分割成字符
  11. var pair = vars[i].split('=')
  12. // 如果第一个元素等于 传进来的参的话 就输出第二个元素
  13. if (pair[0] == variable) {
  14. return pair[1]
  15. }
  16. }
  17. return undefined
  18. }
  19. uni.removeStorageSync(`APPID${getQueryVariable('appid')}_token`)
  20. // #endif
  21. import Vue from 'vue'
  22. import App from './App'
  23. import store from 'store'
  24. import uView from 'uview-ui'
  25. Vue.use(uView)
  26. Vue.config.productionTip = false
  27. import { setStorage, getStorage, removeStorage } from '@/common/utils/storage.js'
  28. // #ifdef H5
  29. if (getQueryVariable('x-token')) {
  30. setStorage('token', getQueryVariable('x-token') || '')
  31. }
  32. if (getQueryVariable('openId')) {
  33. setStorage('openId', getQueryVariable('openId') || '')
  34. }
  35. if (getQueryVariable('username')) {
  36. setStorage('name', getQueryVariable('username') || '')
  37. }
  38. if (getQueryVariable('useravatar')) {
  39. setStorage('avatar', getQueryVariable('useravatar') || '')
  40. }
  41. if (getQueryVariable('userId')) {
  42. setStorage('userId', getQueryVariable('userId') || '')
  43. }
  44. if (getQueryVariable('mobile')) {
  45. setStorage('mobile', getQueryVariable('mobile') || '')
  46. }
  47. if (getQueryVariable('miniProgram')) {
  48. setStorage('miniProgram', getQueryVariable('miniProgram') || '')
  49. }
  50. if (getQueryVariable('appId')) {
  51. setStorage('appId', getQueryVariable('appId') || '')
  52. }
  53. if (getQueryVariable('miniOpenId')) {
  54. setStorage('miniOpenId', getQueryVariable('miniOpenId') || '')
  55. }
  56. if (getQueryVariable('sharerOpenId')) {
  57. setStorage('sharerOpenId', getQueryVariable('sharerOpenId') || '')
  58. }
  59. // #endif
  60. import { Base64 } from 'js-base64'
  61. Vue.prototype.$Base64 = Base64
  62. import {
  63. toast,
  64. successToast,
  65. showLoading,
  66. tipLoading,
  67. hideLoading,
  68. modal,
  69. tips,
  70. navPage,
  71. redPage,
  72. backPage,
  73. callPhone,
  74. copy,
  75. openLocation,
  76. getLocation,
  77. getAddress,
  78. getNowDate,
  79. getNowDatetime
  80. } from 'common/utils/common'
  81. import { navToPage } from 'common/utils/navPag'
  82. Vue.prototype.$navToPage = navToPage
  83. Vue.prototype.$H5Href = process.env.VUE_APP_HREF
  84. Vue.prototype.$toast = toast
  85. Vue.prototype.$successToast = successToast
  86. Vue.prototype.$showLoading = showLoading
  87. Vue.prototype.$tipLoading = tipLoading
  88. Vue.prototype.$hideLoading = hideLoading
  89. Vue.prototype.$modal = modal
  90. Vue.prototype.$tips = tips
  91. Vue.prototype.$navPage = navPage
  92. Vue.prototype.$redPage = redPage
  93. Vue.prototype.$backPage = backPage
  94. Vue.prototype.$callPhone = callPhone
  95. Vue.prototype.$copy = copy
  96. Vue.prototype.$openLocation = openLocation
  97. Vue.prototype.$getLocation = getLocation
  98. Vue.prototype.$getAddress = getAddress
  99. Vue.prototype.$getNowDate = getNowDate
  100. Vue.prototype.$getNowDatetime = getNowDatetime
  101. Vue.prototype.$setStorage = setStorage
  102. Vue.prototype.$getStorage = getStorage
  103. Vue.prototype.$removeStorage = removeStorage
  104. // 注入全局
  105. import pages from 'mixins'
  106. Vue.mixin(pages)
  107. App.mpType = 'app'
  108. import api from '@/common/http/'
  109. Vue.prototype.$api = api
  110. import * as filters from './filters/index.js' // global filters
  111. // register global utility filters
  112. Object.keys(filters).forEach(key => {
  113. Vue.filter(key, filters[key])
  114. })
  115. Vue.prototype.$onLaunched = new Promise((resolve, reject) => {
  116. Vue.prototype.$isResolve = resolve
  117. Vue.prototype.$isReject = reject
  118. })
  119. import custom from '@/components/custom.vue'
  120. import Loading from '@/components/Loading.vue'
  121. import zjPageLayout from '@/components/zj-container/zj-page-layout.vue'
  122. Vue.component('custom', custom)
  123. Vue.component('Loading', Loading)
  124. Vue.component('zjPageLayout', zjPageLayout)
  125. import floatButton from '@/components/floatButton.vue'
  126. Vue.component('floatButton', floatButton)
  127. import { getUserInfo, getConfigInfo, getTemplateInfo } from '@/common/utils/util.js'
  128. Vue.prototype.$getUserInfo = getUserInfo
  129. Vue.prototype.$getConfigInfo = getConfigInfo
  130. Vue.prototype.$getTemplateInfo = getTemplateInfo
  131. // #ifdef H5
  132. import { router, RouterMount } from 'router'
  133. Vue.use(router)
  134. import Mylink from 'uni-simple-router/dist/link.vue'
  135. // 组件式导航
  136. Vue.component('my-link', Mylink)
  137. // #endif
  138. // 渲染图片文件
  139. Vue.prototype.$imageUrl = process.env.VUE_APP_BASE_URL + process.env.VUE_APP_BASE_API + '/common/img/get?key='
  140. import { translaBeforeRegistration } from './global-text-processor' // 导入插件
  141. Vue.prototype.$setLanguage = function (type) {
  142. window.localStorage.setItem('Vue_Translation_Of_Text_Type', type)
  143. setTimeout(() => {
  144. location.reload(true)
  145. }, 200)
  146. }
  147. translaBeforeRegistration(function () {
  148. const app = new Vue({
  149. ...App,
  150. store
  151. })
  152. //v1.3.5起 H5端 你应该去除原有的app.$mount();使用路由自带的渲染方式
  153. // #ifdef H5
  154. RouterMount(app, router, '#app')
  155. // #endif
  156. // #ifndef H5
  157. app.$mount() //为了兼容小程序及app端必须这样写才有效果
  158. // #endif
  159. })