first commit

This commit is contained in:
2026-02-26 09:32:03 +08:00
commit 36a8e4c51b
845 changed files with 116474 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
export default function useAreaCode() {
const defaultAreaCode = ref("+1")
function handlePageClick() {
}
return {
defaultAreaCode,
handlePageClick
}
}
+6
View File
@@ -0,0 +1,6 @@
export default function useEventEmit(eventName: string, callback: (result: any) => void) {
onLoad(() => uni.$on(eventName, callback))
onUnload(() => uni.$off(eventName))
}
+41
View File
@@ -0,0 +1,41 @@
import {appSmsSendPost} from "@/service";
// 获取短信验证码的自定义 Hook
export default function useGetMsgCode() {
const {t} = useI18n()
const isSend = ref(0)
async function getMsgCode({
type, phone, areaCode
}: {
type: string | number;
phone: string | number,
areaCode: string | number,
}) {
const res = await appSmsSendPost({
body: {
areaCode,
phone,
// 1 :用户端绑定手机号 2 :用户端邮箱注册 3 :用户端忘记密码 4 :用户端忘记支付密码 5 :用户端设置支付密码
type,
}
})
if (res) {
await uni.showToast({title: t('common.verification-code-sent-successfully'), icon: 'none'})
isSend.value = 60
const timer = setInterval(() => {
if (isSend.value === 0) {
clearInterval(timer)
} else {
isSend.value -= 1
}
}, 1000)
}
}
return {
isSend,
getMsgCode
}
}
+20
View File
@@ -0,0 +1,20 @@
// 监听网络状态变化的自定义 Hook
export default function useNetworkStatusChange(callback: () => void) {
const OnNetworkStatusChange = (res: any) => {
console.log('=>(useNetworkStatusChange)', res)
if (res.isConnected) {
callback && callback()
}
}
onLoad(() => {
uni.onNetworkStatusChange(OnNetworkStatusChange)
})
onUnload(() => {
uni.offNetworkStatusChange(OnNetworkStatusChange)
})
}
+42
View File
@@ -0,0 +1,42 @@
// 自定义分页 Hook
export default function usePage<T>(
queryFun: (pageNum: number, pageSize: number) => Promise<IResData<T>>,
callback?: (params?: any) => void,
) {
const paging = ref<ZPagingInstance<T> | null>(null)
const loading = ref(true)
const firstLoaded = ref(false)
const dataList = ref<T[]>([])
const totalRows = ref(0)
async function queryList(pageNum: number, pageSize: number) {
try {
const res = await queryFun(pageNum, pageSize)
console.log(res)
await paging.value?.complete(res?.rows)
totalRows.value = res?.total
firstLoaded.value = true
setTimeout(() => {
callback && callback({...res, pageNum, pageSize})
}, 100)
} catch (error) {
await paging.value?.complete(false)
setTimeout(() => {
callback && callback({pageNum, pageSize})
}, 100)
} finally {
setTimeout(() => {
loading.value = false
}, 100)
}
}
return {
paging,
firstLoaded,
loading,
dataList,
totalRows,
queryList,
}
}
+32
View File
@@ -0,0 +1,32 @@
import { ref, onMounted, onUnmounted } from 'vue'
import { throttle } from 'throttle-debounce'
export function useScrollThreshold(threshold = 250, delay = 150) {
const isThresholdReached = ref(false)
// 创建节流处理函数 (使用箭头函数保持this指向)
const throttledHandler = throttle(delay, (scrollTop: number) => {
const newState = scrollTop > threshold
// 仅当状态变化时更新
if (isThresholdReached.value !== newState) {
isThresholdReached.value = newState
console.log("阈值状态更新:", newState, "| 滚动位置:", scrollTop)
}
})
const handleScroll = (e: any) => {
// 传递滚动位置给节流函数
throttledHandler(e.scrollTop)
}
onMounted(() => {
uni.$on('page-scroll', handleScroll)
})
onUnmounted(() => {
uni.$off('page-scroll', handleScroll)
throttledHandler.cancel() // 清除节流函数残留任务
})
return isThresholdReached
}