Merge pull request #41 from daofeng-coder/base

feat: add the global constant "__UNI_PLATFORM__"
This commit is contained in:
菲鸽 2024-03-28 19:05:26 +08:00 committed by GitHub
commit d72c220a18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 2 deletions

14
global.d.ts vendored Normal file
View File

@ -0,0 +1,14 @@
declare const __UNI_PLATFORM__:
| 'h5'
| 'app'
| 'mp-alipay'
| 'mp-baidu'
| 'mp-jd'
| 'mp-kuaishou'
| 'mp-lark'
| 'mp-qq'
| 'mp-toutiao'
| 'mp-weixin'
| 'quickapp-webview'
| 'quickapp-webview-huawei'
| 'quickapp-webview-union'

View File

@ -17,6 +17,7 @@
</view> </view>
<view class="text-center text-4xl main-title-color mt-4">unibest</view> <view class="text-center text-4xl main-title-color mt-4">unibest</view>
<view class="text-center text-2xl mt-2 mb-8">最好用的 uniapp 开发模板</view> <view class="text-center text-2xl mt-2 mb-8">最好用的 uniapp 开发模板</view>
<view class="text-justify max-w-100 m-auto text-4 indent mb-2">{{ description }}</view> <view class="text-justify max-w-100 m-auto text-4 indent mb-2">{{ description }}</view>
<view class="mt-8 text-center"> <view class="mt-8 text-center">
<text class="text-green-400">在线文档</text> <text class="text-green-400">在线文档</text>
@ -40,12 +41,21 @@
</a> </a>
<!-- #endif --> <!-- #endif -->
</view> </view>
<view class="text-center py-4" v-if="isH5">当前平台是 - h5</view>
<view class="text-center py-4" v-else-if="isApp">当前平台是 - app</view>
<view class="text-center py-4" v-else>当前平台是 - {{ platform }}</view>
</view> </view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
// //
const { safeAreaInsets } = uni.getSystemInfoSync() const { safeAreaInsets } = uni.getSystemInfoSync()
const platform = __UNI_PLATFORM__
const isH5 = __UNI_PLATFORM__ === 'h5'
const isApp = __UNI_PLATFORM__ === 'app'
const isMP = __UNI_PLATFORM__.startsWith('mp-')
const isQuickApp = __UNI_PLATFORM__.startsWith('quickapp-')
const author = ref('菲鸽') const author = ref('菲鸽')
const description = ref( const description = ref(

View File

@ -17,7 +17,8 @@
"@dcloudio/types", "@dcloudio/types",
"@types/wechat-miniprogram", "@types/wechat-miniprogram",
"@uni-helper/uni-app-types", "@uni-helper/uni-app-types",
"wot-design-uni/global.d.ts" "wot-design-uni/global.d.ts",
"./global.d.ts"
] ]
}, },
"vueCompilerOptions": { "vueCompilerOptions": {

View File

@ -108,7 +108,9 @@ export default ({ command, mode }) => {
// TODO: 缓存每次压缩过的图片,已经压缩过的不再压缩 // TODO: 缓存每次压缩过的图片,已经压缩过的不再压缩
imagemin(mode === 'production'), imagemin(mode === 'production'),
], ],
define: {
__UNI_PLATFORM__: JSON.stringify(process.env.UNI_PLATFORM),
},
css: { css: {
postcss: { postcss: {
plugins: [ plugins: [