import 'vant/es/toast/style/index' import 'vant/es/notify/style/index' import 'vant/es/dialog/style/index' import 'vant/es/image-preview/style/index' import { DatePicker, showToast, showSuccessToast, showFailToast } from 'vant' // 自定义svg 图标组件 import DocIcon from '@/components/docIcon/index' // 设置ant日期选择框为中文样式 import dayjs from 'dayjs' import 'dayjs/locale/zh-cn' dayjs.locale('cn') export function registe(app) { // 自定义组件 app.use(DocIcon) app.config.globalProperties.$idCardHide = idCardHide app.config.globalProperties.$phoneHide = phoneHide app.config.globalProperties.$addrJoin = addrJoin app.config.globalProperties.$message = { info: showToast, success: showSuccessToast, fail: showFailToast } // 日期选择框默认选中当前日期 DatePicker.props.modelValue.default = () => { const now = dayjs() return [now.year(), now.month() + 1, now.date()] } // 注册指令 setDirective(app) } // idCard 脱敏 function idCardHide(idCard) { if (!idCard || idCard.length < 18) { return idCard } return idCard.substring(0, 6) + '******' + idCard.substring(14) } // phone 脱敏 function phoneHide(phone) { if (!phone || phone.length < 11) { return phone } return phone.substring(0, 3) + '******' + phone.substring(9) } // 地址拼接显示 function addrJoin(str1 = '', str2 = '') { if (!str1 && !str2) return '-' return (str1 ?? '') + (str2 ?? '') } function setDirective(app) { // dom 取消挂载 将指定字段值设为 undefined app.directive('destory', { beforeUnmount(el, binding, vnode, prevVnod) { const field = binding.arg const value = binding.value const modifiers = binding.modifiers if (value instanceof Array) { const form = value[0] for (let i = 1; i < value.length; i++) { if (form[value[i]] != null) { form[value[i]] = modifiers.string ? '' : undefined } } return } const form = value if (form && field && form[field] != null) { form[field] = modifiers.string ? '' : undefined } // console.log(el, binding, vnode, prevVnod) } }) }