-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(directive): added draggable sidebar functionality
- Loading branch information
Showing
16 changed files
with
252 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import http from '@/API'; | ||
import type { Tree } from '@/API/interface'; | ||
|
||
export const getTreeSource = (async: Boolean): Promise<Tree[]> => { | ||
const syncUrl = '/api/v1/perms/users/self/nodes/all-with-assets/tree/'; | ||
const asyncUrl = '/api/v1/perms/users/self/nodes/children-with-assets/tree/'; | ||
|
||
const url = async ? asyncUrl : syncUrl; | ||
|
||
return http.get(url, { observe: 'response' }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { DirectiveBinding } from 'vue'; | ||
|
||
export const draggable = { | ||
beforeMount(el: HTMLElement, binding: DirectiveBinding) { | ||
let startX = 0; | ||
let startWidth = 0; | ||
|
||
const mouseMoveHandler = (event: MouseEvent) => { | ||
const newWidth = startWidth + (event.clientX - startX); | ||
|
||
// 确保宽度在合理范围内 | ||
if (newWidth >= 100 && newWidth <= 600) { | ||
el.style.width = `${newWidth}px`; | ||
|
||
// 更新传递的 ref 变量 | ||
binding.value = newWidth; | ||
} | ||
}; | ||
|
||
const mouseUpHandler = () => { | ||
document.removeEventListener('mousemove', mouseMoveHandler); | ||
document.removeEventListener('mouseup', mouseUpHandler); | ||
}; | ||
|
||
const mouseDownHandler = (event: MouseEvent) => { | ||
const rect = el.getBoundingClientRect(); | ||
// 只有在右侧边缘10px范围内拖动才触发 | ||
if (event.clientX >= rect.right - 10 && event.clientX <= rect.right) { | ||
startX = event.clientX; | ||
startWidth = el.offsetWidth; | ||
document.addEventListener('mousemove', mouseMoveHandler); | ||
document.addEventListener('mouseup', mouseUpHandler); | ||
} | ||
}; | ||
|
||
el.addEventListener('mousedown', mouseDownHandler); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { h } from 'vue'; | ||
import SvgIcon from '@/components/SvgIcon/index.vue'; | ||
|
||
export enum AssetIconType { | ||
// 数据库类 | ||
mysql = 'mysql', | ||
mariadb = 'mariadb', | ||
|
||
// 主机 | ||
windows = 'windows', | ||
linux = 'linux', | ||
macos = 'macos', | ||
aix = 'aix', | ||
bsd = 'bsd', | ||
gatway = 'gatway', | ||
remoteapphost = 'remoteapphost' | ||
} | ||
|
||
export const AssetIconMap = { | ||
[AssetIconType.mysql]: h(SvgIcon, { name: 'mysql' }), | ||
[AssetIconType.mariadb]: h(SvgIcon, { name: 'mariadb' }) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.