-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
127 lines (116 loc) · 3.36 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import {createSSRApp} from 'vue'
import App from './App'
import {createPinia} from 'pinia'
import store from "./store";
import {createI18n} from 'vue-i18n'
import picker from "./common/picker";
import wfc from "./wfc/client/wfc";
import forward from "./common/forward";
// import pttClient from "./wfc/ptt/pttClient";
// import avengineKit from "./wfc/av/engine/avenginekit";
import {getItem} from "./pages/util/storageHelper";
import zhCNLang from './assets/lang/zh-CN.json'
import zhTWLang from './assets/lang/zh-TW.json'
import enLang from './assets/lang/en.json'
import mitt from "mitt";
const app = createSSRApp(App)
const pinia = createPinia()
app.use(pinia)
app.use(picker)
app.use(forward)
const i18n = createI18n({
// 使用localStorage存储语言状态是为了保证页面刷新之后还是保持原来选择的语言状态
locale: getItem('lang') ? getItem('lang') : 'zh-CN', // 定义默认语言为中文
allowComposition: true,
messages: {
'zh-CN': zhCNLang,
'zh-TW': zhTWLang,
'en': enLang
}
})
app.use(i18n)
/**
*
* @param url
* @param options 普通页面到 nvue 页面 或 nvue 页面到普通页面时,不生效
*/
app.config.globalProperties.$navigateToPage = (url, options) => {
uni.navigateTo({
url: url,
success: (res) => {
if (options) {
res.eventChannel.emit('options', options);
}
},
fail: (e) => {
console.log('navigate to WebViewPage error', e)
}
});
}
// 如果不存在会话页面,则入栈,如果已经存在会话页面,则返回到该页面
app.config.globalProperties.$go2ConversationPage = () => {
let pages = getCurrentPages();
let cvRoute = 'pages/conversation/ConversationPage'
let delta = 0;
let found = false;
for (let i = pages.length - 1; i >= 0; i--) {
if (pages[i].route === cvRoute) {
found = true;
break;
} else {
delta++;
}
}
if (found) {
uni.navigateBack({
delta: delta,
fail: err => {
console.log('nav back to conversationView err', err);
}
});
} else {
uni.navigateTo({
url: '/pages/conversation/ConversationPage',
success: () => {
console.log('nav to conversationPage success');
},
fail: (err) => {
console.log('nav to conversationPage err', err);
}
})
}
}
app.config.globalProperties.$scrollToBottom = () => {
setTimeout(() => {
uni.pageScrollTo({
scrollTop: 999999,
duration: 10
});
app.$forceUpdate()
}, 100);
}
app.config.globalProperties.$notify = (options) => {
uni.showToast({
title: options.text,
icon: 'none',
});
}
const eventBus = mitt()
eventBus.$on = eventBus.on
eventBus.$off = eventBus.off
eventBus.$emit = eventBus.emit
app.config.globalProperties.$eventBus = eventBus
app.config.globalProperties.$set = (obj, key, value) => obj[key] = value
wfc.init();
// web 端音视频初始化
// 如果不进行初始化,则无法弹出音视频通话界面,不能进行音视频通话。
// avengineKit.setup();
// if (pttClient.isPttClientEnable()) {
// pttClient.init();
// }
store.init();
export function createApp() {
return {
app
}
}