60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
|
|
import dict from "./dict";
|
||
|
|
import toast from '../uview/libs/function/toast'
|
||
|
|
import addUnit from '../uview/libs/function/addUnit'
|
||
|
|
import $parent from '../uview/libs/function/$parent'
|
||
|
|
import guid from '../uview/libs/function/guid'
|
||
|
|
import deepClone from '../uview/libs/function/deepClone'
|
||
|
|
import debounce from '../uview/libs/function/debounce'
|
||
|
|
import throttle from '../uview/libs/function/throttle'
|
||
|
|
import trim from '../uview/libs/function/trim'
|
||
|
|
import {sys} from '../uview/libs/function/sys'
|
||
|
|
import test from '../uview/libs/function/test'
|
||
|
|
import config from '../uview/libs/config/config'
|
||
|
|
import zIndex from '../uview/libs/config/zIndex'
|
||
|
|
import $moment from 'dayjs'
|
||
|
|
|
||
|
|
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())
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
const u = {toast, $parent, addUnit, guid, config, zIndex, deepClone, throttle, debounce, trim, test, sys}
|
||
|
|
export default {
|
||
|
|
dict,
|
||
|
|
confirm,
|
||
|
|
calcAge,
|
||
|
|
u,
|
||
|
|
dateFormat: (time, format) => {
|
||
|
|
return $moment(time).format(format || 'YYYY-MM-DD').replace("Invalid Date", "")
|
||
|
|
}
|
||
|
|
}
|