generated from ccsens_fe/uni-vue3-template
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
import { CODE_DICT } from '@/config/code'
|
|
|
|
/**
|
|
* 打开页面 timeout 1s执行
|
|
* @param {string} pageName 页面的名称 同文件名 文件夹名
|
|
* @param {boolean} isRedirect 是否是重定向 替换模式
|
|
* @param {string} query 查询参数 不带? 如 name=wally&age=17
|
|
*/
|
|
export function openPage(pageName: string, isRedirect = false, query?: string) {
|
|
const path = query ? `/pages/${pageName}/${pageName}?${query}` : `/pages/${pageName}/${pageName}`
|
|
if (isRedirect) {
|
|
setTimeout(() => {
|
|
uni.redirectTo({ url: path })
|
|
}, 1000)
|
|
} else {
|
|
setTimeout(() => {
|
|
uni.navigateTo({ url: path })
|
|
}, 1000)
|
|
}
|
|
}
|
|
|
|
// show modal 显示弹窗
|
|
export function alertError(error: any) {
|
|
let msg = error
|
|
if (typeof error === 'object') {
|
|
msg = JSON.stringify(error)
|
|
}
|
|
uni.showModal({ title: '提示', content: msg, showCancel: false })
|
|
}
|
|
|
|
// 时间数字统一成两位
|
|
export function toDouble(num: number): string {
|
|
return num.toString().padStart(2, '0')
|
|
}
|
|
|
|
// 计算bmi
|
|
export function computeBMI(height: string, weight: string): string {
|
|
if (!height || !weight || height === '0') return ''
|
|
const h = Number(height)
|
|
const w = Number(weight)
|
|
return (w / ((h * h) / 100 / 100)).toFixed(2)
|
|
}
|
|
|
|
// 计算code form 前置条件的显示
|
|
export function computeShow(code: string, codeForm: any) {
|
|
const { showType } = CODE_DICT[code]
|
|
if (!showType) return true
|
|
if (showType.type === 'value' && codeForm[showType.code] === showType.value) {
|
|
return true
|
|
}
|
|
if (showType.type === 'valueInclude' && codeForm[showType.code].includes(showType.value)) {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|