Files
dvcp_v2_wxcp_app/src/common/util.js

48 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-11-15 10:29:05 +08:00
import dict from "./dict";
2021-11-17 17:34:44 +08:00
import $moment from './monent';
2021-11-15 10:29:05 +08:00
const confirm = (content, title, config) => {
let ops = {content}
if (typeof title == 'object') {
ops = {...ops, ...title}
} else ops = {...ops, title: title || "提示"}
return new Promise((resolve, reject) => {
uni.showModal({
...ops, ...config, success: res => {
if (res?.confirm) {
resolve()
} else if (res?.cancel) {
reject()
}
}
})
})
}
/**
* 获取年龄
* @param code
*/
const calcAge = (code) => {
let birthday
if (typeof code == 'string' && code.length == 18) {
birthday = $moment(code.substring(6, 14), 'YYYYMMDD')
} else if (typeof code == 'object') {
birthday = code
}
return Math.ceil($moment().year() - $moment(birthday).year())
}
export default {
dict,
confirm,
calcAge,
dateFormat: (time, format) => {
return $moment(time).format(format || 'YYYY-MM-DD').replace("Invalid Date", "")
2021-11-17 17:34:44 +08:00
},
formatName: (name) => {
return Array.from(name)?.slice(-2)?.toString() || "";
2021-11-15 10:29:05 +08:00
}
}