|
@@ -335,6 +335,251 @@
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
|
|
+ // 检测是否为安卓设备
|
|
|
|
|
+ isAndroidDevice() {
|
|
|
|
|
+ // 在H5环境中检测
|
|
|
|
|
+ // #ifdef H5
|
|
|
|
|
+ const ua = navigator.userAgent.toLowerCase();
|
|
|
|
|
+ return ua.indexOf('android') > -1;
|
|
|
|
|
+ // #endif
|
|
|
|
|
+
|
|
|
|
|
+ // 在App环境中检测
|
|
|
|
|
+ // #ifdef APP-PLUS
|
|
|
|
|
+ return plus.os.name === 'Android';
|
|
|
|
|
+ // #endif
|
|
|
|
|
+
|
|
|
|
|
+ // 其他环境默认返回false
|
|
|
|
|
+ return false;
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 安卓设备自动下载并安装APK
|
|
|
|
|
+ downloadAndInstallAndroid(androidUrl) {
|
|
|
|
|
+ const that = this;
|
|
|
|
|
+
|
|
|
|
|
+ // 显示下载提示
|
|
|
|
|
+ uni.showLoading({
|
|
|
|
|
+ title: '正在下载应用...',
|
|
|
|
|
+ mask: true
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 在App环境中使用plus.downloader
|
|
|
|
|
+ // #ifdef APP-PLUS
|
|
|
|
|
+ const appDownloadTask = plus.downloader.createDownload(androidUrl, {
|
|
|
|
|
+ filename: '_downloads/CTE.apk'
|
|
|
|
|
+ }, function(download, status) {
|
|
|
|
|
+ uni.hideLoading();
|
|
|
|
|
+
|
|
|
|
|
+ if (status === 200) {
|
|
|
|
|
+ // 下载成功,尝试安装
|
|
|
|
|
+ that.installAndroidApp(download.filename);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '下载失败,请重试',
|
|
|
|
|
+ icon: 'none',
|
|
|
|
|
+ duration: 2000
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 监听下载进度
|
|
|
|
|
+ appDownloadTask.addEventListener('statechanged', function(download, status) {
|
|
|
|
|
+ if (status === 200) {
|
|
|
|
|
+ const progress = Math.round((download.downloadedSize / download.totalSize) * 100);
|
|
|
|
|
+ uni.showLoading({
|
|
|
|
|
+ title: `下载中 ${progress}%`,
|
|
|
|
|
+ mask: true
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ appDownloadTask.start();
|
|
|
|
|
+ // #endif
|
|
|
|
|
+
|
|
|
|
|
+ // 在H5环境中使用uni.downloadFile
|
|
|
|
|
+ // #ifdef H5
|
|
|
|
|
+ const h5DownloadTask = uni.downloadFile({
|
|
|
|
|
+ url: androidUrl,
|
|
|
|
|
+ success: function(res) {
|
|
|
|
|
+ uni.hideLoading();
|
|
|
|
|
+
|
|
|
|
|
+ if (res.statusCode === 200) {
|
|
|
|
|
+ // 下载成功,尝试安装
|
|
|
|
|
+ that.installAndroidApp(res.tempFilePath);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '下载失败,请重试',
|
|
|
|
|
+ icon: 'none',
|
|
|
|
|
+ duration: 2000
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: function(err) {
|
|
|
|
|
+ uni.hideLoading();
|
|
|
|
|
+ console.log('下载失败:', err);
|
|
|
|
|
+
|
|
|
|
|
+ // 下载失败时,提供手动下载选项
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title: '下载失败',
|
|
|
|
|
+ content: '自动下载失败,是否手动下载?',
|
|
|
|
|
+ success: function(res) {
|
|
|
|
|
+ if (res.confirm) {
|
|
|
|
|
+ // 使用浏览器打开下载链接
|
|
|
|
|
+ window.open(androidUrl, '_blank');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 监听下载进度
|
|
|
|
|
+ h5DownloadTask.onProgressUpdate(function(res) {
|
|
|
|
|
+ const progress = Math.round(res.progress);
|
|
|
|
|
+ uni.showLoading({
|
|
|
|
|
+ title: `下载中 ${progress}%`,
|
|
|
|
|
+ mask: true
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ // #endif
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 安装安卓应用
|
|
|
|
|
+ installAndroidApp(filePath) {
|
|
|
|
|
+ const that = this;
|
|
|
|
|
+
|
|
|
|
|
+ // 在App环境中,直接尝试安装APK
|
|
|
|
|
+ // #ifdef APP-PLUS
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title: '下载完成',
|
|
|
|
|
+ content: '应用已下载完成,是否立即安装?',
|
|
|
|
|
+ success: function(res) {
|
|
|
|
|
+ if (res.confirm) {
|
|
|
|
|
+ // 使用plus.runtime.install安装APK
|
|
|
|
|
+ plus.runtime.install(filePath, {
|
|
|
|
|
+ force: false
|
|
|
|
|
+ }, function() {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '安装成功',
|
|
|
|
|
+ icon: 'success',
|
|
|
|
|
+ duration: 2000
|
|
|
|
|
+ });
|
|
|
|
|
+ }, function(e) {
|
|
|
|
|
+ console.log('安装失败:', e);
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title: '安装失败',
|
|
|
|
|
+ content: '自动安装失败,请手动安装。是否打开文件管理器?',
|
|
|
|
|
+ success: function(res) {
|
|
|
|
|
+ if (res.confirm) {
|
|
|
|
|
+ // 打开文件管理器
|
|
|
|
|
+ plus.runtime.openFile(filePath);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ // #endif
|
|
|
|
|
+
|
|
|
|
|
+ // 在H5环境中,提示用户手动安装
|
|
|
|
|
+ // #ifdef H5
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title: '下载完成',
|
|
|
|
|
+ content: '应用已下载完成,请点击下载的文件进行安装',
|
|
|
|
|
+ showCancel: false,
|
|
|
|
|
+ success: function(res) {
|
|
|
|
|
+ if (res.confirm) {
|
|
|
|
|
+ // 尝试打开下载链接,让用户手动下载
|
|
|
|
|
+ window.open(filePath, '_blank');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ // #endif
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 下载iOS应用
|
|
|
|
|
+ downloadIOSApp(iosUrl) {
|
|
|
|
|
+ // 检测是否为iOS设备
|
|
|
|
|
+ const isIOS = this.isIOSDevice();
|
|
|
|
|
+
|
|
|
|
|
+ if (!isIOS) {
|
|
|
|
|
+ // 非iOS设备直接打开浏览器链接
|
|
|
|
|
+ window.open('https://apps.apple.com/cn/app/cte/id6468907188', '_blank');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 在App环境中使用plus.runtime.openURL
|
|
|
|
|
+ // #ifdef APP-PLUS
|
|
|
|
|
+ plus.runtime.openURL(
|
|
|
|
|
+ 'itms-apps://itunes.apple.com/cn/app/cte/id6468907188',
|
|
|
|
|
+ (res) => {
|
|
|
|
|
+ console.log('打开 App Store 成功')
|
|
|
|
|
+ },
|
|
|
|
|
+ (err) => {
|
|
|
|
|
+ console.log('打开 App Store 失败,尝试浏览器打开')
|
|
|
|
|
+ // 如果 itms-apps:// 失败,回退到浏览器打开
|
|
|
|
|
+ plus.runtime.openURL('https://apps.apple.com/cn/app/cte/id6468907188')
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ // #endif
|
|
|
|
|
+
|
|
|
|
|
+ // 在H5环境中,针对iOS设备优化
|
|
|
|
|
+ // #ifdef H5
|
|
|
|
|
+ // 先尝试直接打开App Store链接
|
|
|
|
|
+ const appStoreUrl = 'https://apps.apple.com/cn/app/cte/id6468907188';
|
|
|
|
|
+
|
|
|
|
|
+ // 尝试多种方式打开App Store
|
|
|
|
|
+ this.tryOpenAppStore(appStoreUrl);
|
|
|
|
|
+ // #endif
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 检测是否为iOS设备
|
|
|
|
|
+ isIOSDevice() {
|
|
|
|
|
+ // #ifdef H5
|
|
|
|
|
+ const ua = navigator.userAgent.toLowerCase();
|
|
|
|
|
+ return /iphone|ipad|ipod/.test(ua);
|
|
|
|
|
+ // #endif
|
|
|
|
|
+
|
|
|
|
|
+ // #ifdef APP-PLUS
|
|
|
|
|
+ return plus.os.name === 'iOS';
|
|
|
|
|
+ // #endif
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 尝试打开App Store的多种方式
|
|
|
|
|
+ tryOpenAppStore(appStoreUrl) {
|
|
|
|
|
+ // 方法1: 直接使用window.open
|
|
|
|
|
+ const newWindow = window.open(appStoreUrl, '_blank');
|
|
|
|
|
+
|
|
|
|
|
+ // 如果新窗口被阻止,尝试其他方法
|
|
|
|
|
+ if (!newWindow || newWindow.closed || typeof newWindow.closed == 'undefined') {
|
|
|
|
|
+ // 方法2: 尝试使用itms-apps协议
|
|
|
|
|
+ this.tryItmsProtocol();
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 尝试使用itms-apps协议
|
|
|
|
|
+ tryItmsProtocol() {
|
|
|
|
|
+ const itmsUrl = 'itms-apps://itunes.apple.com/cn/app/cte/id6468907188';
|
|
|
|
|
+
|
|
|
|
|
+ // 创建一个隐藏的iframe来尝试打开itms-apps协议
|
|
|
|
|
+ const iframe = document.createElement('iframe');
|
|
|
|
|
+ iframe.style.display = 'none';
|
|
|
|
|
+ iframe.style.width = '1px';
|
|
|
|
|
+ iframe.style.height = '1px';
|
|
|
|
|
+ iframe.src = itmsUrl;
|
|
|
|
|
+ document.body.appendChild(iframe);
|
|
|
|
|
+
|
|
|
|
|
+ // 设置超时,如果App Store没有打开,则回退到浏览器
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ if (document.body.contains(iframe)) {
|
|
|
|
|
+ document.body.removeChild(iframe);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 最后回退到浏览器打开
|
|
|
|
|
+ window.location.href = 'https://apps.apple.com/cn/app/cte/id6468907188';
|
|
|
|
|
+ }, 1500);
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
//促销
|
|
//促销
|
|
|
cuxiaoList() {
|
|
cuxiaoList() {
|
|
|
this.youyh = false;
|
|
this.youyh = false;
|
|
@@ -993,14 +1238,20 @@
|
|
|
showCancel: true,
|
|
showCancel: true,
|
|
|
cancelText: this.$t('jiesuan.xzios'),
|
|
cancelText: this.$t('jiesuan.xzios'),
|
|
|
confirmText: this.$t('jiesuan.xiazandriod'),
|
|
confirmText: this.$t('jiesuan.xiazandriod'),
|
|
|
- success: function(res) {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ success: (res) => {
|
|
|
if (res.confirm) {
|
|
if (res.confirm) {
|
|
|
- // 请将'YOUR_ANDROID_DOWNLOAD_LINK'替换为您的安卓App下载地址
|
|
|
|
|
- window.open(r.data.data.androidUrl, '_blank');
|
|
|
|
|
|
|
+ // 点击下载Android版本
|
|
|
|
|
+ const isAndroid = this.isAndroidDevice();
|
|
|
|
|
+ if (isAndroid) {
|
|
|
|
|
+ // 安卓设备自动下载并安装
|
|
|
|
|
+ this.downloadAndInstallAndroid(r.data.data.androidUrl);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 非安卓设备直接打开下载链接
|
|
|
|
|
+ window.open(r.data.data.androidUrl, '_blank');
|
|
|
|
|
+ }
|
|
|
} else if (res.cancel) {
|
|
} else if (res.cancel) {
|
|
|
- // 请将'YOUR_IOS_DOWNLOAD_LINK'替换为您的iOS App下载地址
|
|
|
|
|
- window.open(r.data.data.iosUrl, '_blank');
|
|
|
|
|
|
|
+ // 点击下载iOS版本
|
|
|
|
|
+ this.downloadIOSApp(r.data.data.iosUrl);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|