-
Notifications
You must be signed in to change notification settings - Fork 290
fix(drawer): modify h/render to createApp #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,66 @@ | ||
import { createApp } from 'vue' | ||
import { DrawerProps } from './drawer-types' | ||
|
||
import DDrawer from './drawer' | ||
|
||
interface drawerInstance { | ||
hide(): void | ||
hideDirectly(): void | ||
destroy(): void | ||
} | ||
|
||
function createDrawerApp(props: DrawerProps, drawer: drawerInstance, el: HTMLElement) { | ||
if (drawer) { | ||
return drawer | ||
} | ||
const res = createApp( | ||
<DDrawer {...props}>{{ header: props.header, content: props.content }}</DDrawer> | ||
) | ||
res.mount(el) | ||
return res | ||
} | ||
|
||
export default class DrawerService { | ||
static create(props: DrawerProps, drawer: drawerInstance): drawerInstance { | ||
if (!drawer) { | ||
drawer = new Drawer(props) | ||
} | ||
return drawer | ||
} | ||
} | ||
|
||
class Drawer { | ||
private drawer: any = null | ||
private div: HTMLElement = null | ||
private props: DrawerProps = null | ||
|
||
constructor(props: DrawerProps) { | ||
this.props = props | ||
} | ||
|
||
public show(): void { | ||
this.div = document.createElement('div') | ||
this.drawer = createDrawerApp(this.props, this.drawer, this.div) | ||
this.drawer._instance.props.visible = true | ||
} | ||
|
||
public hide = async (): Promise<void> => { | ||
const beforeHidden = this.props.beforeHidden | ||
let result = (typeof beforeHidden === 'function' ? beforeHidden() : beforeHidden) ?? false | ||
if (result instanceof Promise) { | ||
result = await result | ||
} | ||
if (!result) this.hideDirectly() | ||
} | ||
|
||
public hideDirectly = (): void => { | ||
this.drawer._instance.props.visible = false | ||
this.div.remove() | ||
} | ||
|
||
public destroy = (): void => { | ||
this.drawer.unmount() | ||
this.drawer = null | ||
this.div.remove() | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,37 +1,43 @@ | ||
import type { ExtractPropTypes, PropType } from 'vue' | ||
|
||
export const drawerProps = { | ||
width: { | ||
width: { // 宽度 | ||
type: String, | ||
default: '300px', | ||
}, | ||
visible: { | ||
visible: { // 是否可见 | ||
type: Boolean, | ||
default: false, | ||
}, | ||
zIndex: { | ||
zIndex: { // 层级 | ||
type: Number, | ||
default: 1000, | ||
}, | ||
isCover: { | ||
isCover: { // 是否有遮罩层 | ||
type: Boolean, | ||
default: true, | ||
}, | ||
escKeyCloseable: { | ||
escKeyCloseable: { // 是否可通过esc关闭 | ||
type: Boolean, | ||
default: true, | ||
}, | ||
position: { | ||
position: { // 位置 只有左和右 | ||
type: String as PropType<'left' | 'right'>, | ||
default: 'left', | ||
}, | ||
backdropCloseable: { | ||
backdropCloseable: { // 点击遮罩层是否可关闭 | ||
type: Boolean, | ||
default: true, | ||
}, | ||
beforeHidden: { | ||
beforeHidden: { // 关闭前的回调 | ||
type: [Promise, Function] as PropType<Promise<boolean> | (() => boolean | Promise<boolean>)>, | ||
}, | ||
content: { // 默认内容插槽 | ||
type: [Object, Function], | ||
}, | ||
header: { // 头部内容插槽 | ||
type: [Object, Function], | ||
}, | ||
} as const | ||
|
||
export type DrawerProps = ExtractPropTypes<typeof drawerProps> |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.