main.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import Vue from 'vue'
  2. import App from './App'
  3. import cookies from 'weapp-cookie'
  4. import router from './router/index.js'
  5. import store from './store/index.js'
  6. import permission from './utils/permission'
  7. import { isEmpty } from './utils/types'
  8. import { guid } from './utils/lib'
  9. import { STATIC_URL_FN, appVersion } from './config.js'
  10. Vue.config.productionTip = false
  11. Vue.use(router)
  12. Vue.prototype.$isEmpty = isEmpty
  13. Vue.prototype.$auth = permission
  14. Vue.prototype.$guid = guid
  15. /**
  16. * Toast
  17. */
  18. Vue.prototype.$toast = (msg, duration = 3000) => {
  19. // #ifdef APP-PLUS
  20. const richtext = '<font color="#FFFFFF" style="font-size:14px;">' + msg + '</font>'
  21. plus.nativeUI.toast(richtext, {
  22. background: 'rgba(0,0,0,1)',
  23. duration: duration > 3000 ? 'long' : 'short',
  24. type: 'richtext',
  25. verticalAlign: 'top'
  26. })
  27. // #endif
  28. // #ifndef APP-PLUS
  29. uni.showToast({
  30. position: 'top',
  31. title: msg,
  32. icon: 'none',
  33. duration: duration
  34. })
  35. // #endif
  36. }
  37. /**
  38. * 返回并刷新上一页内容
  39. */
  40. Vue.prototype.$refreshAndToPrev = (that, toPrev = true) => {
  41. const pages = getCurrentPages()
  42. if (pages.length >= 2) {
  43. const prevPage = pages[pages.length - 2]
  44. if (prevPage.$vm) {
  45. prevPage.$vm.refreshPage = true
  46. } else {
  47. prevPage.refreshPage = true
  48. }
  49. }
  50. if (toPrev) {
  51. that.$nextTick(function() {
  52. that.$Router.navigateBack()
  53. })
  54. }
  55. }
  56. /**
  57. * 拼接静态资源路径
  58. * @param {Object} val
  59. * @return {String}
  60. */
  61. Vue.prototype.$static = STATIC_URL_FN
  62. Vue.filter('static', Vue.prototype.$static)
  63. Vue.prototype.$clearStorage = () => {
  64. const username = uni.getStorageSync('username') || null
  65. const quickConfig = uni.getStorageSync('quickConfig') || [1, 2, 3, 4]
  66. const appid = uni.getStorageSync('appid') || null
  67. uni.clearStorageSync()
  68. if (username) {
  69. uni.setStorageSync('username', username)
  70. }
  71. if (appid) {
  72. uni.setStorageSync('appid', appid)
  73. }
  74. uni.setStorageSync('version', appVersion)
  75. uni.setStorageSync('quickConfig', quickConfig)
  76. }
  77. App.mpType = 'app'
  78. if (process.env.NODE_ENV !== 'development') {
  79. console.log = () => {}
  80. }
  81. const app = new Vue({
  82. ...App,
  83. store
  84. })
  85. app.$mount()
  86. export default app