95 lines
2.4 KiB
TypeScript
95 lines
2.4 KiB
TypeScript
import App from './App.vue';
|
|
import { createSSRApp } from 'vue';
|
|
// @ts-ignore
|
|
import { setupPinia } from './sheep/store';
|
|
import './main.scss';
|
|
import 'virtual:uno.css';
|
|
// @ts-ignore
|
|
import wfc from './wfc/client/wfc';
|
|
// @ts-ignore
|
|
import Config from './config';
|
|
// @ts-ignore
|
|
import store from './store';
|
|
// @ts-ignore
|
|
import { getItem } from '@/sheep/util/storageHelper';
|
|
import { createI18n } from 'vue-i18n';
|
|
// @ts-ignore
|
|
import zhCNLang from './assets/lang/zh-CN.json';
|
|
// @ts-ignore
|
|
import zhTWLang from './assets/lang/zh-TW.json';
|
|
// @ts-ignore
|
|
import enLang from './assets/lang/en.json';
|
|
import mitt from 'mitt';
|
|
|
|
export function createApp() {
|
|
const app = createSSRApp(App);
|
|
|
|
setupPinia(app);
|
|
|
|
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);
|
|
|
|
// 如果不存在会话页面,则入栈,如果已经存在会话页面,则返回到该页面
|
|
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);
|
|
},
|
|
});
|
|
}
|
|
};
|
|
|
|
const eventBus = mitt();
|
|
// @ts-ignore
|
|
eventBus.$on = eventBus.on;
|
|
// @ts-ignore
|
|
eventBus.$off = eventBus.off;
|
|
// @ts-ignore
|
|
eventBus.$emit = eventBus.emit;
|
|
app.config.globalProperties.$eventBus = eventBus;
|
|
// @ts-ignore
|
|
app.config.globalProperties.$set = (obj, key, value) => (obj[key] = value);
|
|
|
|
// #ifdef APP-PLUS
|
|
wfc.init();
|
|
store.init();
|
|
// #endif
|
|
|
|
return {
|
|
app,
|
|
};
|
|
}
|