添加登录逻辑

This commit is contained in:
bobobobo
2025-12-24 02:01:34 +08:00
parent 8271e4e0bb
commit 6f418fae8a
35 changed files with 928 additions and 94 deletions

56
utils/use-ui.js Normal file
View File

@@ -0,0 +1,56 @@
// 加载状态,提示语
import { ref } from 'vue'
// 全局 loading 状态(可用于页面绑定 v-if
const isLoading = ref(false)
/**
* 显示 loading
* @param {string} title - 提示文字H5 支持App 小程序部分支持)
*/
const showLoading = (title = '加载中...') => {
isLoading.value = true
// uni.showLoading 在 H5 和 App 中行为略有不同,但基本可用
uni.showLoading({
title,
mask: true // 防止穿透点击
})
}
/**
* 隐藏 loading
*/
const hideLoading = () => {
isLoading.value = false
uni.hideLoading()
}
/**
* 统一 Toast 提示
* @param {string} message - 提示内容
* @param {string} type - 'success' | 'error' | 'warning' | 'none'
* @param {number} duration - 持续时间(毫秒)
*/
const showToast = (message, type = 'none', duration = 2000) => {
let icon = 'none'
if (type === 'success') icon = 'success'
if (type === 'error') icon = 'error'
if (type === 'warning') icon = 'none'
uni.showToast({
title: message,
icon,
duration,
mask: true
})
}
// 导出响应式状态和方法
export const useUI = () => {
return {
isLoading: isLoading, // 可用于模板中 v-if="isLoading"
showLoading,
hideLoading,
showToast
}
}