From 3a83e5b4fbcc9a4eb566873ce0bd7b9e27f7b530 Mon Sep 17 00:00:00 2001
From: h_mo <596417202@qq.com>
Date: Sun, 18 Sep 2022 21:55:19 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BD=93=E5=89=8Dplatform(=E5=B9=B3?=
=?UTF-8?q?=E5=8F=B0)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/enums/platformEnum.ts | 109 ++++++++++++++++++++++++++++++++++++++
src/pages/index/index.vue | 6 +++
2 files changed, 115 insertions(+)
create mode 100644 src/enums/platformEnum.ts
diff --git a/src/enums/platformEnum.ts b/src/enums/platformEnum.ts
new file mode 100644
index 0000000..5e6e865
--- /dev/null
+++ b/src/enums/platformEnum.ts
@@ -0,0 +1,109 @@
+/**
+ * 平台
+ */
+export enum PLATFORMS {
+ DEFAULT = 'DEFAULT' /* 默认 */,
+ VUE3 = 'VUE3' /* HBuilderX 3.2.0+ */,
+ APP_PLUS = 'APP-PLUS' /* App */,
+ APP_PLUS_NVUE = 'APP-PLUS-NVUE' /* App nvue 页面 */,
+ APP_NVUE = 'APP-NVUE' /* App nvue 页面 */,
+ H5 = 'H5' /* H5 */,
+ MP_WEIXIN = 'MP-WEIXIN' /* 微信小程序 */,
+ MP_ALIPAY = 'MP-ALIPAY' /* 支付宝小程序 */,
+ MP_BAIDU = 'MP_BAIDU' /* 百度小程序 */,
+ MP_TOUTIAO = 'MP-TOUTIAO' /* 字节跳动小程序 */,
+ MP_LARK = 'MP-LARK' /* 飞书小程序 */,
+ MP_QQ = 'MP-QQ' /* QQ小程序 */,
+ MP_KUAISHOU = 'MP-KUAISHOU' /* 快手小程序 */,
+ MP_JD = 'MP-JD' /* 京东小程序 */,
+ MP_360 = 'MP-360' /* 360小程序 */,
+ MP = 'MP' /* 微信小程序/支付宝小程序/百度小程序/字节跳动小程序/飞书小程序/QQ小程序/360小程序 */,
+ QUICKAPP_WEBVIEW = 'QUICKAPP-WEBVIEW' /* 快应用通用(包含联盟、华为) */,
+ QUICKAPP_WEBVIEW_UNION = 'QUICKAPP-WEBVIEW-UNION' /* 快应用联盟 */,
+ QUICKAPP_WEBVIEW_HUAWEI = 'QUICKAPP-WEBVIEW-HUAWEI' /* 快应用华为 */,
+}
+
+/**
+ * 平台环境
+ * @constructor
+ */
+function PLATFORM_ENV() {
+ let platform = PLATFORMS.DEFAULT;
+
+ /* #ifdef VUE3 */
+ platform = PLATFORMS.VUE3;
+ /* #endif */
+
+ /* #ifdef APP-PLUS */
+ platform = PLATFORMS.APP_PLUS;
+ /* #endif */
+
+ /* #ifdef APP-PLUS-NVUE */
+ platform = PLATFORMS.APP_PLUS_NVUE;
+ /* #endif */
+
+ /* #ifdef APP-NVUE */
+ platform = PLATFORMS.APP_NVUE;
+ /* #endif */
+
+ /* #ifdef H5 */
+ platform = PLATFORMS.H5;
+ /* #endif */
+
+ /* #ifdef MP */
+ platform = PLATFORMS.MP;
+ /* #endif */
+
+ /* #ifdef MP-WEIXIN */
+ platform = PLATFORMS.MP_WEIXIN;
+ /* #endif */
+
+ /* #ifdef MP-ALIPAY */
+ platform = PLATFORMS.MP_ALIPAY;
+ /* #endif */
+
+ /* #ifdef MP_BAIDU */
+ platform = PLATFORMS.MP_BAIDU;
+ /* #endif */
+
+ /* #ifdef MP-TOUTIAO */
+ platform = PLATFORMS.MP_TOUTIAO;
+ /* #endif */
+
+ /* #ifdef MP-LARK */
+ platform = PLATFORMS.MP_LARK;
+ /* #endif */
+
+ /* #ifdef MP-QQ */
+ platform = PLATFORMS.MP_QQ;
+ /* #endif */
+
+ /* #ifdef MP-KUAISHOU */
+ platform = PLATFORMS.MP_KUAISHOU;
+ /* #endif */
+
+ /* #ifdef MP-JD */
+ platform = PLATFORMS.MP_JD;
+ /* #endif */
+
+ /* #ifdef MP-360 */
+ platform = PLATFORMS.MP_360;
+ /* #endif */
+
+ /* #ifdef QUICKAPP-WEBVIEW */
+ platform = PLATFORMS.QUICKAPP_WEBVIEW;
+ /* #endif */
+
+ /* #ifdef QUICKAPP-WEBVIEW-UNION */
+ platform = PLATFORMS.QUICKAPP_WEBVIEW_UNION;
+ /* #endif */
+
+ /* #ifdef QUICKAPP-WEBVIEW-HUAWEI */
+ platform = PLATFORMS.QUICKAPP_WEBVIEW_HUAWEI;
+ /* #endif */
+
+ return platform;
+}
+
+/* 当前平台 */
+export const CURRENT_PLATFORM = PLATFORM_ENV();
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index cb71d86..2086154 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -3,8 +3,11 @@
import AppProvider from '@/components/AppProvider/inedx.vue';
import { ref } from 'vue';
import { useRouter } from '@/hooks/router';
+ import { CURRENT_PLATFORM } from '@/enums/platformEnum';
const title = ref('uni-app vue3 ts --Vite');
+ const platform = CURRENT_PLATFORM;
+
const router = useRouter();
const handleGetStarted = () => {
router.pushTab('/pages/demo/index?d=str');
@@ -17,6 +20,9 @@
{{ title }}
+
+ 当前平台: {{ platform }}
+
Get Started →