TerminalDialog.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <cwg-popup :title="t('Shop.Index.Transaction')" :visible="props.visible" :showFooters="false"
  3. @update:visible="$emit('update:visible', $event)">
  4. <view class="card-list">
  5. <view class="card" @click="handleWebClick">
  6. <view class="card-icon">
  7. <cwg-icon name="cwg-mt" :size="48" color="#fff" />
  8. </view>
  9. <view class="card-content">
  10. <text class="card-title">{{ webTitle }}</text>
  11. <text class="card-desc">{{ t('Downloadpage.item40') }}</text>
  12. </view>
  13. <view class="card-arrow">
  14. <cwg-icon name="cwg-arrow" :size="24" color="#141d22" />
  15. </view>
  16. </view>
  17. <view class="card" @click="handleDownloadClick">
  18. <view class="card-icon">
  19. <cwg-icon name="cwg-mt" :size="48" color="#fff" />
  20. </view>
  21. <view class="card-content">
  22. <text class="card-title">{{ downloadItem.name }}</text>
  23. <text class="card-desc">{{ downloadItem.description }}</text>
  24. </view>
  25. <view class="card-arrow">
  26. <cwg-icon name="cwg-arrow" :size="24" color="#141d22" />
  27. </view>
  28. </view>
  29. <view @click="handleClick" class="card">
  30. <view class="card-content">
  31. <text class="card-title" v-t="'vu.item13'"></text>
  32. </view>
  33. <view class="card-arrow">
  34. <cwg-icon name="cwg-arrow" :size="24" color="#141d22" />
  35. </view>
  36. </view>
  37. </view>
  38. </cwg-popup>
  39. </template>
  40. <script setup>
  41. import { ref, computed, onMounted } from 'vue'
  42. import { useI18n } from 'vue-i18n'
  43. import { TerminalMap } from '../composables/TerminalMap'
  44. import config from '@/config';
  45. const { t, locale } = useI18n()
  46. import useRouter from "@/hooks/useRouter";
  47. const router = useRouter();
  48. const props = defineProps({
  49. visible: { type: Boolean, default: false },
  50. mtType: { type: String, default: 'MT4', validator: val => ['MT4', 'MT5'].includes(val) }
  51. })
  52. const emit = defineEmits(['update:visible'])
  53. const handleClick = () => {
  54. router.push("/pages/common/download")
  55. }
  56. // ---------- 平台相关 ----------
  57. const platform = ref('')
  58. const baseUrl = ref('')
  59. const domain = ref('')
  60. // 获取当前运行平台
  61. const getPlatform = () => {
  62. // #ifdef APP-PLUS
  63. const sys = uni.getSystemInfoSync()
  64. return sys.platform === 'android' ? 'android' : 'ios'
  65. // #endif
  66. // #ifdef H5
  67. const ua = navigator.userAgent.toLowerCase()
  68. if (ua.includes('windows')) return 'windows'
  69. if (ua.includes('mac')) return 'mac'
  70. if (ua.includes('android')) return 'android'
  71. if (ua.includes('iphone') || ua.includes('ipad')) return 'ios'
  72. return 'windows'
  73. // #endif
  74. }
  75. // 初始化环境变量(域名、基础URL)
  76. const initEnv = () => {
  77. baseUrl.value = config.Host80
  78. domain.value = config.ho
  79. }
  80. // 替换 URL 中的占位符
  81. const resolveUrl = (urlTemplate) => {
  82. if (!urlTemplate) return ''
  83. let url = urlTemplate
  84. if (url.includes('{myLink}')) {
  85. url = url.replace(/{myLink}/g, baseUrl.value)
  86. }
  87. if (url.includes('{domain}')) {
  88. url = url.replace(/{domain}/g, domain.value)
  89. }
  90. return url
  91. }
  92. // 获取当前 MT 版本的数据
  93. const mtData = computed(() => TerminalMap[props.mtType] || {})
  94. // Web 端标题(根据版本显示不同标题)
  95. const webTitle = computed(() => {
  96. return props.mtType === 'MT4' ? t('Downloadpage.item38') : t('Downloadpage.item39')
  97. })
  98. // 根据当前 MT 版本和平台,获取对应的下载端信息
  99. const downloadItem = computed(() => {
  100. const data = mtData.value
  101. if (!data) return null
  102. let item = null
  103. if (platform.value === 'windows' || platform.value === 'mac') {
  104. const list = data.desktop?.[platform.value] || []
  105. item = list[0]
  106. } else if (platform.value === 'android' || platform.value === 'ios') {
  107. const list = data.mobile?.[platform.value] || []
  108. item = list[0]
  109. }
  110. if (!item) return null
  111. // 构造显示名称和描述(国际化)
  112. let name = ''
  113. let description = ''
  114. if (item.name) {
  115. name = item.name
  116. description = item.descriptionKey ? t(item.descriptionKey) : (item.description || '')
  117. } else if (item.nameKey) {
  118. name = t(item.nameKey)
  119. description = item.descriptionKey ? t(item.descriptionKey) : ''
  120. }
  121. // 图标路径处理
  122. let icon = item.icon || ''
  123. if (platform.value === 'android' && !icon) icon = 'android-os-3-72.png'
  124. if (platform.value === 'ios' && !icon) icon = 'apple-os-3-72.png'
  125. if (platform.value === 'windows' && !icon) icon = 'windows-os-1-48.png'
  126. if (platform.value === 'mac' && !icon) icon = 'apple-os-1-48.png'
  127. return {
  128. url: resolveUrl(item.url),
  129. filename: item.filename,
  130. name,
  131. description,
  132. icon
  133. }
  134. })
  135. // 获取 Web 端链接(根据当前 MT 版本和语言)
  136. const webUrl = computed(() => {
  137. const data = mtData.value
  138. if (!data || !data.web) return ''
  139. let url = data.web.url
  140. // 替换动态变量
  141. url = resolveUrl(url)
  142. // 替换语言占位符({lang})
  143. url = url.replace(/{lang}/g, locale.value)
  144. return url
  145. })
  146. // 处理 Web 端点击
  147. const handleWebClick = () => {
  148. if (!webUrl.value) {
  149. uni.showToast({ title: t('Downloadpage.invalidLink') || '链接无效', icon: 'none' })
  150. return
  151. }
  152. // #ifdef APP-PLUS
  153. plus.runtime.openURL(webUrl.value, (err) => {
  154. uni.showToast({ title: t('Downloadpage.openFailed') || '打开失败,请重试', icon: 'none' })
  155. })
  156. // #endif
  157. // #ifdef H5
  158. window.location.href = webUrl.value
  159. // #endif
  160. }
  161. // 处理下载端点击
  162. const handleDownloadClick = () => {
  163. if (!downloadItem.value || !downloadItem.value.url) {
  164. uni.showToast({ title: t('Downloadpage.unsupported') || '暂不支持当前平台下载', icon: 'none' })
  165. return
  166. }
  167. const url = downloadItem.value.url
  168. // #ifdef APP-PLUS
  169. plus.runtime.openURL(url, (err) => {
  170. uni.showToast({ title: t('Downloadpage.openFailed') || '打开失败,请重试', icon: 'none' })
  171. })
  172. // #endif
  173. // #ifdef H5
  174. if (url.match(/\.(exe|dmg|pkg|apk|zip)$/i)) {
  175. const a = document.createElement('a')
  176. a.href = url
  177. a.download = downloadItem.value.filename || ''
  178. document.body.appendChild(a)
  179. a.click()
  180. document.body.removeChild(a)
  181. } else {
  182. window.open(url, '_blank')
  183. }
  184. // #endif
  185. }
  186. // 初始化
  187. onMounted(() => {
  188. platform.value = getPlatform()
  189. initEnv()
  190. })
  191. </script>
  192. <style scoped lang="scss">
  193. @import "@/uni.scss";
  194. @media (min-width: 768px) {
  195. :deep(.cwg-dialog) {
  196. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  197. border-radius: px2rpx(8);
  198. width: px2rpx(600) !important;
  199. }
  200. }
  201. .card-list {
  202. display: flex;
  203. flex-direction: column;
  204. gap: px2rpx(12);
  205. }
  206. .card {
  207. display: flex;
  208. align-items: center;
  209. background-color: rgba(108, 133, 149, 0.08);
  210. border-radius: px2rpx(12);
  211. padding: px2rpx(14) px2rpx(12);
  212. border: 1px solid rgba(108, 133, 149, 0);
  213. transition: background-color 0.2s;
  214. &:hover {
  215. border: 1px solid rgba(108, 133, 149, 0.2);
  216. }
  217. }
  218. .card-icon {
  219. width: px2rpx(54);
  220. height: px2rpx(54);
  221. background-color: #141D22;
  222. border-radius: px2rpx(12);
  223. display: flex;
  224. align-items: center;
  225. justify-content: center;
  226. margin-right: px2rpx(12);
  227. flex-shrink: 0;
  228. .icon-image {
  229. width: px2rpx(32);
  230. height: px2rpx(32);
  231. }
  232. }
  233. .card-content {
  234. flex: 1;
  235. display: flex;
  236. flex-direction: column;
  237. }
  238. .card-title {
  239. font-size: px2rpx(14);
  240. font-weight: 600;
  241. line-height: 1.4;
  242. color: #fff;
  243. }
  244. .card-desc {
  245. font-size: px2rpx(14);
  246. color: #A0B0C0;
  247. margin-top: 8rpx;
  248. }
  249. .card-arrow {
  250. width: px2rpx(24);
  251. height: px2rpx(24);
  252. display: flex;
  253. align-items: center;
  254. justify-content: center;
  255. margin-left: 16rpx;
  256. flex-shrink: 0;
  257. color: #fff;
  258. }
  259. </style>