fix: 切换uview-plus为uview-ui 2.0官方版本,调整全局配置

This commit is contained in:
claw_bot 2026-03-12 12:00:49 +00:00
parent 0b09c9eed8
commit 6f10244a01
6 changed files with 59 additions and 30 deletions

57
App.vue
View File

@ -1,15 +1,3 @@
<script setup>
// u-toast
import { useToast } from 'uview-plus'
const toast = useToast()
//
uni.$u = {
toast,
showModal: useToast().showModal
}
</script>
<script> <script>
export default { export default {
onLaunch: function() { onLaunch: function() {
@ -25,15 +13,58 @@ export default {
</script> </script>
<template> <template>
<view> <view id="app">
<!-- 全局uView配置 -->
<u-config :config="uConfig">
<router-view /> <router-view />
<!-- 全局toast组件 --> <!-- 全局toast组件 -->
<u-toast ref="uToast" /> <u-toast ref="uToast" />
<!-- 全局modal组件 --> <!-- 全局modal组件 -->
<u-modal ref="uModal" /> <u-modal ref="uModal" />
</u-config>
</view> </view>
</template> </template>
<script setup>
// uView
const uConfig = {
//
primaryColor: '#064e3b',
successColor: '#10B981',
warningColor: '#f59e0b',
errorColor: '#ef4444'
}
//
uni.$u.toast = (title, options = {}) => {
uni.$refs.uToast.show({
title,
...options
})
}
uni.$u.toast.success = (title) => {
uni.$refs.uToast.show({
title,
type: 'success'
})
}
uni.$u.toast.error = (title) => {
uni.$refs.uToast.show({
title,
type: 'error'
})
}
uni.$u.toast.loading = (title) => {
uni.$refs.uToast.show({
title,
type: 'loading'
})
}
uni.$u.showModal = (options) => {
uni.$refs.uModal.show(options)
}
</script>
<style> <style>
/* 每个页面公共css */ /* 每个页面公共css */
page { page {

View File

@ -14,7 +14,7 @@ app.$mount()
// #ifdef VUE3 // #ifdef VUE3
import { createSSRApp } from 'vue' import { createSSRApp } from 'vue'
import api from './utils/api' import api from './utils/api'
import uviewPlus from 'uview-plus' import uView from 'uview-ui'
console.log('🚀 应用启动导入api模块') console.log('🚀 应用启动导入api模块')
@ -25,9 +25,9 @@ export function createApp() {
app.config.globalProperties.$api = api app.config.globalProperties.$api = api
console.log('✅ api已全局注册为 $api') console.log('✅ api已全局注册为 $api')
// 注册uView Plus // 注册uView UI 2.0
app.use(uviewPlus) app.use(uView)
console.log('✅ uView Plus 已全局注册') console.log('✅ uView UI 2.0 已全局注册')
return { return {
app app

View File

@ -72,7 +72,7 @@
"easycom": { "easycom": {
"autoscan": true, "autoscan": true,
"custom": { "custom": {
"^u-(.*)": "uview-plus/components/u-$1/u-$1.vue" "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"
} }
} }
} }

View File

@ -76,4 +76,5 @@ $uni-color-paragraph: #3F536E; // 文章段落颜色
$uni-font-size-paragraph:15px; $uni-font-size-paragraph:15px;
/* 引入uView样式 */ /* 引入uView样式 */
@import "uview-plus/index.scss"; @import "uview-ui/theme.scss";
@import "uview-ui/index.scss";

View File

@ -17,10 +17,7 @@ let loginLock = null;
let loadingCount = 0; let loadingCount = 0;
const showLoading = () => { const showLoading = () => {
if (loadingCount === 0) { if (loadingCount === 0) {
uni.showLoading({ uni.$u.toast.loading('加载中...');
title: '加载中...',
mask: true
});
} }
loadingCount++; loadingCount++;
}; };
@ -28,7 +25,7 @@ const hideLoading = () => {
loadingCount--; loadingCount--;
if (loadingCount <= 0) { if (loadingCount <= 0) {
loadingCount = 0; loadingCount = 0;
uni.hideLoading(); uni.$u.toast.hide();
} }
}; };

View File

@ -4,6 +4,6 @@ import uni from '@dcloudio/vite-plugin-uni'
export default defineConfig({ export default defineConfig({
plugins: [uni()], plugins: [uni()],
optimizeDeps: { optimizeDeps: {
include: ['uview-plus'] include: ['uview-ui']
} }
}) })