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

67
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>
export default {
onLaunch: function() {
@ -25,15 +13,58 @@ export default {
</script>
<template>
<view>
<router-view />
<!-- 全局toast组件 -->
<u-toast ref="uToast" />
<!-- 全局modal组件 -->
<u-modal ref="uModal" />
<view id="app">
<!-- 全局uView配置 -->
<u-config :config="uConfig">
<router-view />
<!-- 全局toast组件 -->
<u-toast ref="uToast" />
<!-- 全局modal组件 -->
<u-modal ref="uModal" />
</u-config>
</view>
</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>
/* 每个页面公共css */
page {

View File

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

View File

@ -72,7 +72,7 @@
"easycom": {
"autoscan": true,
"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;
/* 引入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;
const showLoading = () => {
if (loadingCount === 0) {
uni.showLoading({
title: '加载中...',
mask: true
});
uni.$u.toast.loading('加载中...');
}
loadingCount++;
};
@ -28,7 +25,7 @@ const hideLoading = () => {
loadingCount--;
if (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({
plugins: [uni()],
optimizeDeps: {
include: ['uview-plus']
include: ['uview-ui']
}
})