77 lines
1.7 KiB
TypeScript
77 lines
1.7 KiB
TypeScript
import { t } from '@/utils/i18n'
|
|
/**
|
|
* 页面跳转
|
|
*/
|
|
export const onPageJump = (path: string) => {
|
|
uni.navigateTo({
|
|
url: path
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 页面返回
|
|
*/
|
|
export const onPageBack = () => {
|
|
uni.navigateBack()
|
|
}
|
|
|
|
/**
|
|
* 拨打电话
|
|
*/
|
|
export const makePhoneCall = (phoneNumber: string, title: string = '') => {
|
|
uni.showModal({
|
|
title: title,
|
|
content: phoneNumber,
|
|
confirmText: t('common.confirm'),
|
|
cancelText: t('common.cancel'),
|
|
success: (res: any) => {
|
|
if (res.confirm) {
|
|
uni.makePhoneCall({
|
|
phoneNumber: phoneNumber,
|
|
success: () => {
|
|
console.log('拨打电话成功')
|
|
},
|
|
fail: (error: any) => {
|
|
console.error('拨打电话失败:', error)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 复制到剪贴板
|
|
*/
|
|
export const copyToClipboard = (content: string, title: string = '') => {
|
|
uni.setClipboardData({
|
|
data: content,
|
|
success: () => {
|
|
uni.showToast({
|
|
title: title + t('user.copySuccess'),
|
|
icon: 'none'
|
|
})
|
|
},
|
|
fail: (error: any) => {
|
|
console.error('复制失败:', error)
|
|
}
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 计算最低价格
|
|
*/
|
|
export const calculateLowestPrice = (priceData: object): { key: string, value: number } => {
|
|
const validEntries = Object.entries(priceData)
|
|
.filter(([, value]) => typeof value === 'number' && value !== 0);
|
|
|
|
if (validEntries.length === 0) {
|
|
throw new Error('No valid non-zero price found in the data');
|
|
}
|
|
|
|
const [minKey, minValue] = validEntries.reduce((min, curr) =>
|
|
curr[1] < min[1] ? curr : min
|
|
);
|
|
|
|
return { key: minKey, value: minValue };
|
|
} |