Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
najiu-frontend
najiu-admin-template
Commits
bbfb06f0
Commit
bbfb06f0
authored
Oct 13, 2020
by
nebv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: optimize preview and ContextMenu functions
parent
a7c09703
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
15 deletions
+13
-15
index.ts
src/components/ContextMenu/index.ts
+6
-9
functional.ts
src/components/Preview/src/functional.ts
+7
-6
No files found.
src/components/ContextMenu/index.ts
View file @
bbfb06f0
import
contextMenuVue
from
'
./src/index
'
;
import
{
isClient
}
from
'
/@/utils/is
'
;
import
{
Options
,
Props
}
from
'
./src/types
'
;
import
{
create
App
}
from
'
vue
'
;
import
{
create
VNode
,
render
}
from
'
vue
'
;
const
menuManager
:
{
doms
:
Element
[];
resolve
:
Fn
;
...
...
@@ -19,7 +19,7 @@ export const createContextMenu = function (options: Options) {
if
(
!
isClient
)
return
;
return
new
Promise
((
resolve
)
=>
{
const
wrapDom
=
document
.
createElement
(
'
div
'
);
const
container
=
document
.
createElement
(
'
div
'
);
const
propsData
:
Partial
<
Props
>
=
{};
if
(
options
.
styles
!==
undefined
)
propsData
.
styles
=
options
.
styles
;
if
(
options
.
items
!==
undefined
)
propsData
.
items
=
options
.
items
;
...
...
@@ -27,12 +27,12 @@ export const createContextMenu = function (options: Options) {
propsData
.
customEvent
=
event
;
propsData
.
axis
=
{
x
:
event
.
clientX
,
y
:
event
.
clientY
};
}
createApp
(
contextMenuVue
,
propsData
).
mount
(
wrapDom
);
const
vm
=
createVNode
(
contextMenuVue
,
propsData
);
render
(
vm
,
container
);
const
bodyClick
=
function
()
{
menuManager
.
resolve
(
''
);
};
const
contextMenuDom
=
wrapDom
.
children
[
0
];
menuManager
.
doms
.
push
(
contextMenuDom
);
menuManager
.
doms
.
push
(
container
);
const
remove
=
function
()
{
menuManager
.
doms
.
forEach
((
dom
:
Element
)
=>
{
try
{
...
...
@@ -41,16 +41,13 @@ export const createContextMenu = function (options: Options) {
});
document
.
body
.
removeEventListener
(
'
click
'
,
bodyClick
);
document
.
body
.
removeEventListener
(
'
scroll
'
,
bodyClick
);
try
{
(
wrapDom
as
any
)
=
null
;
}
catch
(
error
)
{}
};
menuManager
.
resolve
=
function
(...
arg
:
any
)
{
resolve
(
arg
[
0
]);
remove
();
};
remove
();
document
.
body
.
appendChild
(
cont
extMenuDom
);
document
.
body
.
appendChild
(
cont
ainer
);
document
.
body
.
addEventListener
(
'
click
'
,
bodyClick
);
document
.
body
.
addEventListener
(
'
scroll
'
,
bodyClick
);
});
...
...
src/components/Preview/src/functional.ts
View file @
bbfb06f0
...
...
@@ -3,19 +3,20 @@ import { isClient } from '/@/utils/is';
import
type
{
Options
,
Props
}
from
'
./types
'
;
import
{
create
App
}
from
'
vue
'
;
import
{
create
VNode
,
render
}
from
'
vue
'
;
let
instance
:
any
=
null
;
export
function
createImgPreview
(
options
:
Options
)
{
if
(
!
isClient
)
return
;
const
{
imageList
,
show
=
true
,
index
=
0
}
=
options
;
const
propsData
:
Partial
<
Props
>
=
{};
const
wrapDom
=
document
.
createElement
(
'
div
'
);
const
container
=
document
.
createElement
(
'
div
'
);
propsData
.
imageList
=
imageList
;
propsData
.
show
=
show
;
propsData
.
index
=
index
;
const
imgDom
=
createApp
(
ImgPreview
,
propsData
);
i
mgDom
.
mount
(
wrapDom
);
const
imgPreviewDom
=
wrapDom
.
children
[
0
]
;
document
.
body
.
appendChild
(
imgPreviewDom
);
i
nstance
=
createVNode
(
ImgPreview
,
propsData
);
render
(
instance
,
container
)
;
document
.
body
.
appendChild
(
container
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment