App.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <el-config-provider :locale="locale">
  3. <!-- 一级路由 -->
  4. <router-view />
  5. </el-config-provider>
  6. </template>
  7. <!--<script lang="ts">
  8. export default {
  9. name: 'App',
  10. }
  11. </script>-->
  12. <script lang="ts" setup>
  13. import { computed } from 'vue'
  14. import { useRouter } from 'vue-router'
  15. import { ElMessageBox, ElNotification } from 'element-plus'
  16. import { useLogin } from '@/business/login'
  17. import { i18n, useSettingStore } from "@/stores"
  18. import eventBus from '@/services/bus'
  19. import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
  20. import en from 'element-plus/dist/locale/en.mjs'
  21. import th from 'element-plus/dist/locale/th.mjs'
  22. import zhTW from 'element-plus/dist/locale/zh-tw.mjs'
  23. import vi from 'element-plus/dist/locale/vi.mjs'
  24. const { userLogout } = useLogin()
  25. const settingStore = useSettingStore()
  26. const router = useRouter()
  27. // 国际化语言
  28. const locale = computed(() => {
  29. switch (i18n.global.locale) {
  30. case 'zh-CN':
  31. return zhCn
  32. case 'zh-TW':
  33. return zhTW
  34. case 'th':
  35. return th
  36. case 'vi':
  37. return vi
  38. default:
  39. return en
  40. }
  41. })
  42. // 接收用户登出通知
  43. eventBus.$on('LogoutNotify', (msg) => {
  44. userLogout(() => {
  45. if (msg) {
  46. ElMessageBox.alert(msg as string, i18n.global.t('user.login.tips4'))
  47. }
  48. router.replace({ name: 'login' })
  49. })
  50. })
  51. // 接收风控通知
  52. eventBus.$on('RiskToWebNtf', (msg, type) => {
  53. const res = msg as { title: string, content: string }
  54. if (type === 1) {
  55. ElNotification({
  56. title: res.title,
  57. message: res.content,
  58. type: 'warning'
  59. })
  60. } else {
  61. ElMessageBox.alert(res.content, res.title)
  62. }
  63. })
  64. // 接收委托单成交通知
  65. eventBus.$on('OrderDealedNtf', (res) => {
  66. if (settingStore.getSettingValue('showOrderSuccessNotify')) {
  67. const data = res as Proto.OrderDealedNtf
  68. ElNotification({
  69. title: '订单成交通知',
  70. message: `订单 ${data.OrderID} 已成交,价格 ${data.TradePrice}`
  71. })
  72. }
  73. })
  74. </script>