提交 7a5248f4 作者: 方治民

feat: 新增全局 Message 工具方法、横竖屏实例等

上级 821b7b8f
...@@ -18,6 +18,7 @@ export function configAutoImportPlugin(): Plugin { ...@@ -18,6 +18,7 @@ export function configAutoImportPlugin(): Plugin {
'@/config/app': ['$app'], '@/config/app': ['$app'],
'@/api/services': ['defs'], '@/api/services': ['defs'],
'@/api/services/mods': ['API'], '@/api/services/mods': ['API'],
'@/commom/message': ['Message'],
}, },
], ],
}) })
......
<script setup lang="ts"> <script setup lang="ts">
import { Message } from '@/common/message'
onLaunch(() => { onLaunch(() => {
console.log('App Launch') console.log('App Launch')
}) })
...@@ -12,17 +14,11 @@ ...@@ -12,17 +14,11 @@
}) })
onError((err) => { onError((err) => {
uni.showToast({ Message.toast('App Error: ' + err)
title: 'App Error: ' + err,
icon: 'none',
})
}) })
onUnhandledRejection((err) => { onUnhandledRejection((err) => {
uni.showToast({ Message.toast('App UnhandledRejection: ' + err)
title: 'App UnhandledRejection: ' + err,
icon: 'none',
})
}) })
</script> </script>
......
// 本文件由FirstUI授权予长沙壹润信息科技发展有限公司(手机号: 156 16 26 019 5,身份证尾号:503 75T)专用,请尊重知识产权,勿私下传播,违者追究法律责任。 // 本文件由FirstUI授权予长沙壹润信息科技发展有限公司(手机号: 156 16 26 019 5,身份证尾号:503 75T)专用,请尊重知识产权,勿私下传播,违者追究法律责任。
const fui = { const fui = {
toast: function (text: string) { toast: function (text: string) {
text && if (text) {
// #ifndef APP-PLUS
uni.showToast({ uni.showToast({
title: text, title: text,
icon: 'none', icon: 'none',
duration: 2000, duration: 2000,
}) })
// #endif
// #ifdef APP-PLUS
plus.nativeUI.toast(text, {
duration: 'short',
})
// #endif
}
}, },
modal: function ( modal: function (
title: string, title: string,
......
export const Message = {
/**
* 消息轻提示
* @param text 消息内容
*/
toast: function (text: string) {
if (text) {
// #ifndef APP-PLUS
uni.showToast({
title: text,
icon: 'none',
duration: 2000,
})
// #endif
// #ifdef APP-PLUS
plus.nativeUI.toast(text, {
duration: 'short',
})
// #endif
}
},
}
...@@ -120,11 +120,11 @@ ...@@ -120,11 +120,11 @@
left: 0; left: 0;
right: 0; right: 0;
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
left: constant(safe-area-inset-left); /* left: constant(safe-area-inset-left);
left: env(safe-area-inset-left); left: env(safe-area-inset-left);
right: constant(safe-area-inset-right); right: constant(safe-area-inset-right);
right: env(safe-area-inset-right) right: env(safe-area-inset-right) */
/* #endif */ /* #endif */
} }
.fui-footer__link { .fui-footer__link {
...@@ -212,4 +212,4 @@ ...@@ -212,4 +212,4 @@
} }
/* #endif */ /* #endif */
</style> </style>
\ No newline at end of file
<script setup lang="ts"> <script setup lang="ts">
import { Message } from '@/common/message'
import dayjs from 'dayjs' import dayjs from 'dayjs'
const year = ref(dayjs().year()) const year = ref(dayjs().year())
...@@ -6,14 +7,27 @@ ...@@ -6,14 +7,27 @@
// TODO: 测试接口 // TODO: 测试接口
API.example.hello.request().then((body) => { API.example.hello.request().then((body) => {
console.log(body)
title.value = body title.value = body
Message.toast(body)
console.log(body)
}) })
const change = () => {
const orientation = plus.navigator.getOrientation()
Message.toast('Orientation: ' + orientation)
if (orientation === 0) {
plus.screen.lockOrientation('landscape-primary')
} else if (orientation === 90) {
plus.screen.lockOrientation('portrait-primary')
}
}
</script> </script>
<template> <template>
<view class="content"> <view class="content">
<fui-avatar src="/static/logo.png" radius="14" /> <fui-avatar src="/static/logo.png" radius="14" @click="change" />
<view class="info"> <view class="info">
<text class="title">{{ title }}</text> <text class="title">{{ title }}</text>
<text class="title">{{ $t('app.hello') }}</text> <text class="title">{{ $t('app.hello') }}</text>
......
...@@ -18,6 +18,7 @@ declare global { ...@@ -18,6 +18,7 @@ declare global {
const isReadonly: typeof import('vue')['isReadonly'] const isReadonly: typeof import('vue')['isReadonly']
const isRef: typeof import('vue')['isRef'] const isRef: typeof import('vue')['isRef']
const markRaw: typeof import('vue')['markRaw'] const markRaw: typeof import('vue')['markRaw']
const Message: typeof import('@/commom/message')['Message']
const nextTick: typeof import('vue')['nextTick'] const nextTick: typeof import('vue')['nextTick']
const onActivated: typeof import('vue')['onActivated'] const onActivated: typeof import('vue')['onActivated']
const onAddToFavorites: typeof import('@dcloudio/uni-app')['onAddToFavorites'] const onAddToFavorites: typeof import('@dcloudio/uni-app')['onAddToFavorites']
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论