-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f6b3aa
commit 7272a0a
Showing
14 changed files
with
253 additions
and
12 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,83 @@ | ||
import {Inject, Injectable} from '@angular/core'; | ||
import Driver from 'driver.js'; | ||
import {DOCUMENT} from "@angular/common"; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class DriverService { | ||
|
||
constructor(@Inject(DOCUMENT) private doc: Document) { | ||
} | ||
|
||
/* | ||
* https://madewith.cn/766 | ||
* */ | ||
load(): void { | ||
const driver = new Driver({ | ||
animate: false, | ||
allowClose: true, | ||
doneBtnText: '完成', | ||
closeBtnText: '关闭', | ||
nextBtnText: '下一步', | ||
prevBtnText: '上一步', | ||
onHighlightStarted: () => { | ||
this.doc.body.style.cssText = 'overflow:hidden'; | ||
}, | ||
onReset: () => { | ||
this.doc.body.style.cssText = 'overflow:auto'; | ||
} | ||
}); | ||
driver.defineSteps([ | ||
{ | ||
element: '#menuNav', | ||
popover: { | ||
title: '菜单', | ||
description: '这里是菜单', | ||
position: 'right-center' | ||
} | ||
}, | ||
{ | ||
element: '#drawer-handle', | ||
popover: { | ||
title: '主题设置按钮', | ||
description: '点击展开设置主题', | ||
position: 'left' | ||
} | ||
}, | ||
{ | ||
element: '#tools', | ||
popover: { | ||
title: '工具栏', | ||
description: '搜索菜单,帮助文档,通知消息,退出登录,多语言', | ||
position: 'bottom' | ||
} | ||
}, | ||
{ | ||
element: '#chats', | ||
popover: { | ||
title: '联系管理员', | ||
description: '跟管理员联系联系', | ||
position: 'top' | ||
} | ||
}, | ||
{ | ||
element: '#trigger', | ||
popover: { | ||
title: '折叠菜单', | ||
description: '点击可以折叠菜单', | ||
position: 'bottom' | ||
} | ||
}, | ||
{ | ||
element: '#multi-tab', | ||
popover: { | ||
title: '多标签', | ||
description: '鼠标右键点击单个标签可以展开多个选项', | ||
position: 'bottom' | ||
} | ||
}, | ||
]); | ||
driver.start(); | ||
} | ||
} |
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,132 @@ | ||
import { DOCUMENT } from '@angular/common'; | ||
import { Inject, Injectable } from '@angular/core'; | ||
import { BehaviorSubject, Observable } from 'rxjs'; | ||
import { filter, share } from 'rxjs/operators'; | ||
|
||
import type { NzSafeAny } from 'ng-zorro-antd/core/types'; | ||
|
||
export interface LazyResult { | ||
path: string; | ||
status: 'ok' | 'error' | 'loading'; | ||
error?: NzSafeAny; | ||
} | ||
// this.lazy.load(["https://unpkg.com/driver.js/dist/driver.min.js", "https://unpkg.com/driver.js/dist/driver.min.css"]).then(() => { | ||
|
||
/** | ||
* 延迟加载资源(js 或 css)服务 | ||
*/ | ||
@Injectable({ providedIn: 'root' }) | ||
export class LazyService { | ||
private list: { [key: string]: boolean } = {}; | ||
private cached: { [key: string]: LazyResult } = {}; | ||
private _notify: BehaviorSubject<LazyResult[]> = new BehaviorSubject<LazyResult[]>([]); | ||
|
||
constructor(@Inject(DOCUMENT) private doc: NzSafeAny) {} | ||
|
||
get change(): Observable<LazyResult[]> { | ||
return this._notify.asObservable().pipe( | ||
share(), | ||
filter(ls => ls.length !== 0) | ||
); | ||
} | ||
|
||
clear(): void { | ||
this.list = {}; | ||
this.cached = {}; | ||
} | ||
|
||
load(paths: string | string[]): Promise<LazyResult[]> { | ||
if (!Array.isArray(paths)) { | ||
paths = [paths]; | ||
} | ||
|
||
const promises: Array<Promise<LazyResult>> = []; | ||
paths.forEach(path => { | ||
if (path.endsWith('.js')) { | ||
promises.push(this.loadScript(path)); | ||
} else { | ||
promises.push(this.loadStyle(path)); | ||
} | ||
}); | ||
|
||
return Promise.all(promises).then(res => { | ||
this._notify.next(res); | ||
return Promise.resolve(res); | ||
}); | ||
} | ||
|
||
loadScript(path: string, innerContent?: string): Promise<LazyResult> { | ||
return new Promise(resolve => { | ||
if (this.list[path] === true) { | ||
resolve({ ...this.cached[path], status: 'loading' }); | ||
return; | ||
} | ||
|
||
this.list[path] = true; | ||
const onSuccess = (item: LazyResult) => { | ||
this.cached[path] = item; | ||
resolve(item); | ||
this._notify.next([item]); | ||
}; | ||
|
||
const node = this.doc.createElement('script') as NzSafeAny; | ||
node.type = 'text/javascript'; | ||
node.src = path; | ||
node.charset = 'utf-8'; | ||
if (innerContent) { | ||
node.innerHTML = innerContent; | ||
} | ||
if (node.readyState) { | ||
// IE | ||
node.onreadystatechange = () => { | ||
if (node.readyState === 'loaded' || node.readyState === 'complete') { | ||
node.onreadystatechange = null; | ||
onSuccess({ | ||
path, | ||
status: 'ok' | ||
}); | ||
} | ||
}; | ||
} else { | ||
node.onload = () => | ||
onSuccess({ | ||
path, | ||
status: 'ok' | ||
}); | ||
} | ||
node.onerror = (error: NzSafeAny) => | ||
onSuccess({ | ||
path, | ||
status: 'error', | ||
error | ||
}); | ||
this.doc.getElementsByTagName('head')[0].appendChild(node); | ||
}); | ||
} | ||
|
||
loadStyle(path: string, rel: string = 'stylesheet', innerContent?: string): Promise<LazyResult> { | ||
return new Promise(resolve => { | ||
if (this.list[path] === true) { | ||
resolve(this.cached[path]); | ||
return; | ||
} | ||
|
||
this.list[path] = true; | ||
|
||
const node = this.doc.createElement('link') as HTMLLinkElement; | ||
node.rel = rel; | ||
node.type = 'text/css'; | ||
node.href = path; | ||
if (innerContent) { | ||
node.innerHTML = innerContent; | ||
} | ||
this.doc.getElementsByTagName('head')[0].appendChild(node); | ||
const item: LazyResult = { | ||
path, | ||
status: 'ok' | ||
}; | ||
this.cached[path] = item; | ||
resolve(item); | ||
}); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/app/layout/default/setting-drawer/setting-drawer.component.html
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
2 changes: 1 addition & 1 deletion
2
...components/layout-components/layout-head-right-menu/layout-head-right-menu.component.html
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