Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
jml0128
/
xrk-bi
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ac7ca248
authored
Jul 08, 2021
by
jml0128
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
1 parent
cedf1652
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
16 deletions
package.json
src/packages/bi/src/chart-type/common.js
package.json
View file @
ac7ca24
{
"name"
:
"xrk-bi"
,
"version"
:
"0.1.
3
"
,
"version"
:
"0.1.
4
"
,
"description"
:
"xrk-bi"
,
"author"
:
"xrk"
,
"main"
:
"dist/bundler.js"
,
...
...
src/packages/bi/src/chart-type/common.js
View file @
ac7ca24
...
...
@@ -205,9 +205,9 @@ export const keepLastIndex = (obj, focusOffset) => {
export
const
initDivInput
=
(
dom
,
options
=
{
useWrap
:
false
,
usePasteStyle
:
false
,
callback
:
()
=>
{}
}
options
=
{
useWrap
:
false
,
usePasteStyle
:
false
}
)
=>
{
const
{
useWrap
,
usePasteStyle
,
callback
}
=
options
;
const
{
useWrap
,
usePasteStyle
}
=
options
;
const
maxlength
=
dom
.
getAttribute
(
'maxlength'
);
let
baseIndex
=
0
;
let
focusIndex
=
0
;
...
...
@@ -216,10 +216,11 @@ export const initDivInput = (
let
deleteText
=
''
;
let
isComposition
=
false
;
dom
.
innerHTML
=
dom
.
innerText
;
const
setIndex
=
function
()
{
const
{
innerText
}
=
this
;
const
{
base
Offset
,
focusOffset
}
=
getSelection
();
[
baseIndex
,
focusIndex
]
=
[
base
Offset
,
focusOffset
].
sort
((
a
,
b
)
=>
a
-
b
);
const
{
anchor
Offset
,
focusOffset
}
=
getSelection
();
[
baseIndex
,
focusIndex
]
=
[
anchor
Offset
,
focusOffset
].
sort
((
a
,
b
)
=>
a
-
b
);
leftText
=
innerText
.
slice
(
0
,
baseIndex
);
rightText
=
innerText
.
slice
(
focusIndex
);
deleteText
=
innerText
.
slice
(
baseIndex
,
focusIndex
);
...
...
@@ -255,24 +256,26 @@ export const initDivInput = (
isComposition
=
false
;
dealText
.
call
(
this
,
event
.
data
);
});
dom
.
addEventListener
(
'
beforeinput
'
,
function
(
event
)
{
dom
.
addEventListener
(
'
keydown
'
,
function
(
event
)
{
if
(
isComposition
)
{
return
;
}
const
{
inputType
}
=
event
;
if
(
inputType
!=
'insertCompositionText
'
)
{
const
{
key
,
ctrlKey
}
=
event
;
if
(
key
!=
'Process
'
)
{
setIndex
.
call
(
this
);
}
if
(
this
.
innerText
.
length
-
(
focusIndex
-
baseIndex
)
>=
maxlength
&&
[
'insertText'
,
'insertCompositionText'
,
'insertParagraph'
].
includes
(
inputType
)
!
[
'Control'
,
'Backspace'
,
'Process'
,
'Enter'
].
includes
(
key
)
&&
!
(
ctrlKey
&&
[
'a'
,
'A'
].
includes
(
key
))
&&
// 全选
!
(
ctrlKey
&&
[
'x'
,
'X'
].
includes
(
key
))
&&
// 剪切
!
(
ctrlKey
&&
[
'c'
,
'C'
].
includes
(
key
))
&&
// 复制
!
(
ctrlKey
&&
[
'v'
,
'V'
].
includes
(
key
))
// 粘贴
)
{
// 超出长度并且是输入操作,则禁止输入
event
.
preventDefault
();
}
if
(
inputType
===
'insertParagraph
'
&&
!
useWrap
)
{
if
(
key
===
'Enter
'
&&
!
useWrap
)
{
// 禁止换行
event
.
preventDefault
();
}
...
...
@@ -298,10 +301,6 @@ export const initDivInput = (
document
.
execCommand
(
'paste'
,
false
,
text
);
}
});
dom
.
addEventListener
(
'blur'
,
function
()
{
callback
(
this
.
innerText
);
});
}
else
{
console
.
warn
(
'启用usePasteStyle,在粘贴时候无法限制字符长度'
);
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment