main.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import Vue from 'vue'
  2. import App from './App'
  3. import store from "./store";
  4. import VueI18n from 'vue-i18n'
  5. import {getItem} from "./pages/util/storageHelper";
  6. import picker from "./common/picker";
  7. import wfc from "./wfc/client/wfc";
  8. import wfcUIKit from "./wfc/uikit/wfcUIKit";
  9. import Config from "./config";
  10. import forward from "./common/forward";
  11. Vue.config.productionTip = false
  12. App.mpType = 'app'
  13. Vue.use(VueI18n)
  14. Vue.use(picker)
  15. Vue.use(forward)
  16. const i18n = new VueI18n({
  17. // 使用localStorage存储语言状态是为了保证页面刷新之后还是保持原来选择的语言状态
  18. locale: getItem('lang') ? getItem('lang') : 'zh-CN', // 定义默认语言为中文
  19. messages: {
  20. 'zh-CN': require('@/assets/lang/zh-CN.json'),
  21. 'zh-TW': require('@/assets/lang/zh-TW.json'),
  22. 'en': require('@/assets/lang/en.json')
  23. }
  24. })
  25. Vue.prototype.$navigateToPage = (url, options) => {
  26. uni.navigateTo({
  27. url: url,
  28. success: (res) => {
  29. res.eventChannel.emit('options', options);
  30. },
  31. fail: (e) => {
  32. console.log('navigate to WebViewPage error', e)
  33. }
  34. });
  35. }
  36. // 如果不存在会话页面,则入栈,如果已经存在会话页面,则返回到该页面
  37. Vue.prototype.$go2ConversationPage = () => {
  38. let pages = getCurrentPages();
  39. let cvRoute = 'pages/conversation/ConversationPage'
  40. let delta = 0;
  41. let found = false;
  42. for (let i = pages.length - 1; i >= 0; i--) {
  43. if (pages[i].route === cvRoute) {
  44. found = true;
  45. break;
  46. } else {
  47. delta++;
  48. }
  49. }
  50. if (found) {
  51. uni.navigateBack({
  52. delta: delta,
  53. fail: err => {
  54. console.log('nav back to conversationView err', err);
  55. }
  56. });
  57. } else {
  58. uni.navigateTo({
  59. url: '/pages/conversation/ConversationPage',
  60. success: () => {
  61. console.log('nav to conversationPage success');
  62. },
  63. fail: (err) => {
  64. console.log('nav to conversationPage err', err);
  65. }
  66. })
  67. }
  68. }
  69. Vue.prototype.$scrollToBottom = () => {
  70. setTimeout(() => {
  71. uni.pageScrollTo({
  72. scrollTop: 999999,
  73. duration: 10
  74. });
  75. app.$forceUpdate()
  76. }, 100);
  77. }
  78. Vue.prototype._i18n = i18n;
  79. const app = new Vue({
  80. i18n,
  81. ...App
  82. })
  83. app.store = store;
  84. wfc.init();
  85. if (wfcUIKit.isUIKitEnable()) {
  86. Config.ICE_SERVERS.forEach(iceServer => {
  87. wfcUIKit.addICEServer(iceServer.uri, iceServer.userName, iceServer.password);
  88. })
  89. }
  90. store.init();
  91. app.$mount()