From 6b5c575b7afdb5ee36987e38ce4cb7c88625bc96 Mon Sep 17 00:00:00 2001 From: Odboy Date: Thu, 5 Feb 2026 19:58:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(utils):=20=E6=B7=BB=E5=8A=A0=E5=A4=9A?= =?UTF-8?q?=E7=A7=8D=E6=95=B0=E6=8D=AE=E6=A0=BC=E5=BC=8F=E5=8C=96=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E5=99=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增身份证号掩码过滤器MaskIdCard,用于隐藏敏感信息 - 新增银行卡号掩码过滤器MaskBankCard,保护支付信息安全 - 新增百分比格式化过滤器FormatPercent,支持自定义小数位 - 新增文件名截取过滤器TruncateFileName,防止超长文件名显示异常 - 新增文本截取过滤器TruncateText,控制文本长度显示 - 新增首字母大写过滤器Capitalize,统一文本格式 - 新增大小写转换过滤器ToUpperCase和ToLowerCase,灵活格式控制 - 新增相对时间格式化过滤器FormatRelativeTime,显示友好时间提示 - 新增星期几格式化过滤器FormatWeekday,便捷日期展示 - 新增布尔值转换过滤器FormatBoolean,支持自定义文本显示 - 新增开关状态过滤器FormatSwitch和启用状态过滤器FormatEnabled - 新增时长格式化过滤器FormatDuration,将秒数转换为可读格式 - 新增数组转字符串过滤器ArrayToString,自定义分隔符连接 - 新增JSON对象格式化过滤器JsonToString,支持缩进美化显示 - 新增数字转中文过滤器NumberToChinese,实现数字的中文表达 - 新增URL链接格式化过滤器FormatUrl,自动补全协议前缀 - 新增货币格式化过滤器FormatCurrency,支持多币种金额显示 --- cutejava-front/src/main.js | 14 ++++--- .../directives.js} | 42 +++++++++---------- .../views/components/dev/CuteScreenShot.vue | 2 +- 3 files changed, 31 insertions(+), 27 deletions(-) rename cutejava-front/src/{plugins/PreventReClickDirective.js => utils/directives.js} (96%) diff --git a/cutejava-front/src/main.js b/cutejava-front/src/main.js index ddcd32ee..6bb8d0a7 100644 --- a/cutejava-front/src/main.js +++ b/cutejava-front/src/main.js @@ -9,9 +9,6 @@ import Element from 'element-ui' // 数据字典 import dict from './components/Dict' -// 防止二次提交 -import { preventReClick } from '@/plugins/PreventReClickDirective' - // 一键复制插件 import VueClipboard from 'vue-clipboard2' @@ -35,10 +32,11 @@ import './router/index' // 过滤器 import * as filters from './utils/filters' +// 指令 +import * as directives from './utils/directives' Vue.use(checkPer) Vue.use(permission) -Vue.directive(preventReClick) Vue.use(dict) Vue.use(VueClipboard) Vue.use(Element, { @@ -48,11 +46,17 @@ Vue.use(Element, { Vue.component('split-pane', SplitPane) // 注册全局过滤器 -// 使用方法:{{ value | filter-key }} +// 使用方法:{{ value | 过滤器方法名 }} Object.keys(filters).forEach(key => { Vue.filter(key, filters[key]) }) +// 注册全局指令 +// 使用方法: +Object.keys(directives).forEach(key => { + Vue.directive(directives[key]) +}) + Vue.config.productionTip = false Vue.config.errorHandler = function(err, vm, info) { diff --git a/cutejava-front/src/plugins/PreventReClickDirective.js b/cutejava-front/src/utils/directives.js similarity index 96% rename from cutejava-front/src/plugins/PreventReClickDirective.js rename to cutejava-front/src/utils/directives.js index bc5d305c..a55d6a89 100644 --- a/cutejava-front/src/plugins/PreventReClickDirective.js +++ b/cutejava-front/src/utils/directives.js @@ -1,21 +1,21 @@ -import Vue from 'vue' - -/** - * 防止重复提交指令,需要在main.js中全局注册 Vue.directive('preventReClick', preventReClick) - * 使用默认的 3000 毫秒防重复点击时间 - * 例子: 提交 - * 自定义防重复点击时间为 5000 毫秒 - * 例子: 提交 - */ -export const preventReClick = Vue.directive('preventReClick', { - inserted(el, binding) { - el.addEventListener('click', () => { - if (!el.disabled) { - el.disabled = true - setTimeout(() => { - el.disabled = false - }, binding.value || 3000) - } - }) - } -}) +import Vue from 'vue' + +/** + * 防止重复提交指令,需要在main.js中全局注册 Vue.directive('preventReClick', preventReClick) + * 使用默认的 3000 毫秒防重复点击时间 + * 例子: 提交 + * 自定义防重复点击时间为 5000 毫秒 + * 例子: 提交 + */ +export const preventReClick = Vue.directive('preventReClick', { + inserted(el, binding) { + el.addEventListener('click', () => { + if (!el.disabled) { + el.disabled = true + setTimeout(() => { + el.disabled = false + }, binding.value || 3000) + } + }) + } +}) diff --git a/cutejava-front/src/views/components/dev/CuteScreenShot.vue b/cutejava-front/src/views/components/dev/CuteScreenShot.vue index 27507fb6..f7a57ff3 100644 --- a/cutejava-front/src/views/components/dev/CuteScreenShot.vue +++ b/cutejava-front/src/views/components/dev/CuteScreenShot.vue @@ -17,7 +17,7 @@ 截屏 -
+