From 566c35444def62d13f0c76c3a8e642cd234b2b45 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期五, 19 九月 2025 14:16:52 +0800
Subject: [PATCH] ss
---
admin/src/directives/v-trim.js | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/admin/src/directives/v-trim.js b/admin/src/directives/v-trim.js
new file mode 100644
index 0000000..4b35d06
--- /dev/null
+++ b/admin/src/directives/v-trim.js
@@ -0,0 +1,31 @@
+export default {
+ inserted: function (el) {
+ let input = el
+ let classes = input.getAttribute('class') || ''
+ if (classes != null) {
+ classes = classes.split(' ')
+ }
+ // 杈撳叆妗嗭細<el-input/>
+ if (classes.indexOf('el-input') > -1) {
+ input = input.querySelector('input')
+ }
+ // 澶氳杈撳叆妗嗭細<el-input type="textarea"/>
+ if (classes.indexOf('el-textarea') > -1) {
+ input = input.querySelector('textarea')
+ }
+ // 澶卞幓鐒︾偣鏃跺幓鎺変袱渚х┖鏍�
+ input.addEventListener('blur', (e) => {
+ e.target.value = e.target.value.trim()
+ input.dispatchEvent(new Event('input'))
+ })
+ // 鍥炶溅鏃跺幓鎺変袱渚х┖鏍硷紙浠呰緭鍏ユ锛�
+ if (classes.indexOf('el-input') > -1) {
+ input.addEventListener('keydown', (e) => {
+ if (e.key === 'Enter') {
+ e.target.value = e.target.value.trim()
+ input.dispatchEvent(new Event('input'))
+ }
+ })
+ }
+ }
+}
--
Gitblit v1.9.3