main.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import { webLogin, getUserInfo, getConfigInfo, getTemplateInfo } from '@/common/utils/util.js'
  2. // #ifdef H5
  3. // 解析地址栏参数
  4. function getQueryVariable(variable) {
  5. // 从?开始获取后面的所有数据
  6. var query = window.location.search.substring(1)
  7. // 从字符串&开始分隔成数组split
  8. var vars = query.split('&')
  9. // 遍历该数组
  10. for (var i = 0; i < vars.length; i++) {
  11. // 从等号部分分割成字符
  12. var pair = vars[i].split('=')
  13. // 如果第一个元素等于 传进来的参的话 就输出第二个元素
  14. if (pair[0] == variable) {
  15. return pair[1]
  16. }
  17. }
  18. return undefined
  19. }
  20. if (!getQueryVariable('code')) {
  21. uni.removeStorageSync(`APPID${getQueryVariable('appid')}_token`)
  22. webLogin(true)
  23. }
  24. // #endif
  25. import Vue from 'vue'
  26. import App from './App'
  27. import store from 'store'
  28. import uView from 'uview-ui'
  29. Vue.use(uView)
  30. Vue.config.productionTip = false
  31. import { setStorage, getStorage, removeStorage } from '@/common/utils/storage.js'
  32. // #ifdef H5
  33. if (getQueryVariable('x-token')) {
  34. setStorage('token', getQueryVariable('x-token') || '')
  35. }
  36. if (getQueryVariable('openId')) {
  37. setStorage('openId', getQueryVariable('openId') || '')
  38. }
  39. if (getQueryVariable('username')) {
  40. setStorage('name', getQueryVariable('username') || '')
  41. }
  42. if (getQueryVariable('userId')) {
  43. setStorage('userId', getQueryVariable('userId') || '')
  44. }
  45. if (getQueryVariable('mobile')) {
  46. setStorage('mobile', getQueryVariable('mobile') || '')
  47. }
  48. if (getQueryVariable('miniProgram')) {
  49. setStorage('miniProgram', getQueryVariable('miniProgram') || '')
  50. }
  51. if (getQueryVariable('appId')) {
  52. setStorage('appId', getQueryVariable('appId') || '')
  53. }
  54. if (getQueryVariable('miniOpenId')) {
  55. setStorage('miniOpenId', getQueryVariable('miniOpenId') || '')
  56. }
  57. if (getQueryVariable('sharerOpenId')) {
  58. setStorage('sharerOpenId', getQueryVariable('sharerOpenId') || '')
  59. }
  60. // #endif
  61. import { Base64 } from 'js-base64'
  62. Vue.prototype.$Base64 = Base64
  63. import {
  64. toast,
  65. successToast,
  66. showLoading,
  67. tipLoading,
  68. hideLoading,
  69. modal,
  70. tips,
  71. navPage,
  72. redPage,
  73. backPage,
  74. callPhone,
  75. copy,
  76. openLocation,
  77. getLocation,
  78. getAddress,
  79. getNowDate,
  80. getNowDatetime
  81. } from 'common/utils/common'
  82. import { navToPage } from 'common/utils/navPag'
  83. Vue.prototype.$navToPage = navToPage
  84. Vue.prototype.$H5Href = process.env.VUE_APP_HREF
  85. Vue.prototype.$toast = toast
  86. Vue.prototype.$successToast = successToast
  87. Vue.prototype.$showLoading = showLoading
  88. Vue.prototype.$tipLoading = tipLoading
  89. Vue.prototype.$hideLoading = hideLoading
  90. Vue.prototype.$modal = modal
  91. Vue.prototype.$tips = tips
  92. Vue.prototype.$navPage = navPage
  93. Vue.prototype.$redPage = redPage
  94. Vue.prototype.$backPage = backPage
  95. Vue.prototype.$callPhone = callPhone
  96. Vue.prototype.$copy = copy
  97. Vue.prototype.$openLocation = openLocation
  98. Vue.prototype.$getLocation = getLocation
  99. Vue.prototype.$getAddress = getAddress
  100. Vue.prototype.$getNowDate = getNowDate
  101. Vue.prototype.$getNowDatetime = getNowDatetime
  102. Vue.prototype.$setStorage = setStorage
  103. Vue.prototype.$getStorage = getStorage
  104. Vue.prototype.$removeStorage = removeStorage
  105. // 注入全局
  106. import pages from 'mixins'
  107. Vue.mixin(pages)
  108. App.mpType = 'app'
  109. import api from '@/common/http/'
  110. Vue.prototype.$api = api
  111. import * as filters from './filters/index.js' // global filters
  112. // register global utility filters
  113. Object.keys(filters).forEach(key => {
  114. Vue.filter(key, filters[key])
  115. })
  116. Vue.prototype.$onLaunched = new Promise((resolve, reject) => {
  117. Vue.prototype.$isResolve = resolve
  118. Vue.prototype.$isReject = reject
  119. })
  120. import custom from '@/components/custom.vue'
  121. import Loading from '@/components/Loading.vue'
  122. import zjPageLayout from '@/components/zj-container/zj-page-layout.vue'
  123. Vue.component('custom', custom)
  124. Vue.component('Loading', Loading)
  125. Vue.component('zjPageLayout', zjPageLayout)
  126. import floatButton from '@/components/floatButton.vue'
  127. Vue.component('floatButton', floatButton)
  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. })