Skip to content

Commit

Permalink
添加引导页功能
Browse files Browse the repository at this point in the history
  • Loading branch information
huajian123 committed Dec 14, 2021
1 parent 9f6b3aa commit 7272a0a
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 12 deletions.
5 changes: 4 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
}
],
"styles": [
"node_modules/driver.js/dist/driver.min.css",
{
"input": "src/styles/default.less",
"bundleName": "default",
Expand All @@ -69,7 +70,9 @@
"stylePreprocessorOptions": {
"includePaths": ["src/styles/themes"]
},
"scripts": [],
"scripts": [
"node_modules/driver.js/dist/driver.min.js"
],
"allowedCommonJsDependencies": [
"qs",
"size-sensor",
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@antv/l7-source": "2.5.7",
"@antv/l7-utils": "2.5.7",
"@auth0/angular-jwt": "^5.0.2",
"driver.js": "^0.9.8",
"ng-zorro-antd": "^12.0.1",
"ngx-quicklink": "^0.2.7",
"rxjs": "~6.6.0",
Expand Down
1 change: 1 addition & 0 deletions src/app/config/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const TokenPre = 'Bearer ';
export const AuthKey = 'Authorization';
export const IsNightKey = 'IsNightKey';
export const ThemeOptionsKey = 'ThemeOptionsKey';
export const IsFirstLogin = 'IsFirstLogin';


export const SideCollapsedMaxWidth = 700;
Expand Down
83 changes: 83 additions & 0 deletions src/app/core/services/common/driver.service.ts
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();
}
}
132 changes: 132 additions & 0 deletions src/app/core/services/common/lazy.service.ts
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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<!--非混合模式侧边栏-->
<nz-sider
id="menuNav"
[class.left-nav-fixed]="isFixedLeftNav"
*ngIf="!isMixiMode&&((themesOptions$|async)!.mode==='side')&&!(isOverMode$|async)&&(themesOptions$|async)!.hasNavArea"
class="menu-sidebar"
Expand All @@ -31,7 +32,7 @@

<nz-layout [style]="{marginTop:isMixiMode&&themesOptions.hasTopArea?'48px':0}">
<!--sider模式的 header-->
<nz-header style="transition:width 0.2s"
<nz-header style="transition:width 0.2s"
*ngIf="!isMixiMode&&themesOptions.hasTopArea&&themesOptions.mode==='side'"
[ngClass]="{
'full-with':!themesOptions.hasNavArea,
Expand Down Expand Up @@ -89,7 +90,7 @@

<app-setting-drawer></app-setting-drawer>

<app-chat (changeShows)="showChats=false" *ngIf="showChats"></app-chat>
<app-chat (changeShows)="showChats=false" *ngIf="showChats"></app-chat>

<ng-template #trigger>
<ul nz-menu [nzTheme]="(isMixiMode&&!(isOverMode$|async))?'light':(themesOptions$|async)!.theme" nzMode="inline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class DefLayoutContentComponent implements OnInit {
mixiModeHasLeftNav = this.splitNavStoreService.getSplitLeftNavArrayStore();
private destory$ = new Subject<void>();

constructor(private themesService: ThemeService, private splitNavStoreService: SplitNavStoreService) {
constructor( private themesService: ThemeService, private splitNavStoreService: SplitNavStoreService) {
}

changeCollapsed(isCollapsed: boolean): void {
Expand All @@ -53,6 +53,7 @@ export class DefLayoutContentComponent implements OnInit {

ngOnInit(): void {
this.getThemeOptions();

}

ngOnDestroy(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout/default/default.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ng-template #headerTpl>
<app-tool-bar>
<ng-container left *ngIf="isOverMode||(themeOptions$|async)!.mode==='side';else topHeadTpl">
<i class="trigger" nz-icon [nzType]="(isCollapsed$|async) ? 'menu-unfold' : 'menu-fold'"
<i id="trigger" class="trigger" nz-icon [nzType]="(isCollapsed$|async) ? 'menu-unfold' : 'menu-fold'"
(click)="changeCollapsed()"></i>
</ng-container>
<ng-template #topHeadTpl>
Expand Down
20 changes: 17 additions & 3 deletions src/app/layout/default/default.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import {Component, OnInit, ChangeDetectionStrategy, OnDestroy, ViewChild} from '@angular/core';
import {Component, OnInit, ChangeDetectionStrategy, OnDestroy, ViewChild, AfterViewInit} from '@angular/core';
import {ThemeService} from "../../core/services/store/theme.service";
import {Subject} from "rxjs";
import {takeUntil} from "rxjs/operators";
import {NavDrawerComponent} from "./nav-drawer/nav-drawer.component";
import {RouterOutlet} from "@angular/router";
import {fadeRouteAnimation} from "../../animations/fade.animation";
import {DriverService} from "../../core/services/common/driver.service";
import {WindowService} from "../../core/services/common/window.service";
import {IsFirstLogin} from "../../config/constant";

@Component({
selector: 'app-default',
Expand All @@ -15,15 +18,26 @@ import {fadeRouteAnimation} from "../../animations/fade.animation";
fadeRouteAnimation
]
})
export class DefaultComponent implements OnInit, OnDestroy {
export class DefaultComponent implements OnInit, OnDestroy, AfterViewInit {
isCollapsed$ = this.themesService.getIsCollapsed();
themeOptions$ = this.themesService.getThemesMode();
isCollapsed = false;
isOverMode = false; // 窗口变窄时,导航栏是否变成抽屉模式
private destory$ = new Subject<void>();
@ViewChild('navDrawer') navDrawer!: NavDrawerComponent

constructor(private themesService: ThemeService) {
constructor(private themesService: ThemeService, private driverService: DriverService, private windowService: WindowService) {
}

ngAfterViewInit(): void {
setTimeout(() => {
if (this.windowService.getStorage(IsFirstLogin) === "false") {
return;
}
this.windowService.setStorage(IsFirstLogin, "false");
this.driverService.load();
}, 500)

}

changeCollapsed(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="drawer-handle" [class.open]="isCollapsed" (click)="changeCollapsed()">
<div class="drawer-handle" id="drawer-handle" [class.open]="isCollapsed" (click)="changeCollapsed()">
<ng-container *ngIf="!isCollapsed; then settingIcon else closeIcon"></ng-container>
<ng-template #settingIcon>
<i nz-icon nzType="setting" nzTheme="outline"></i>
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout/default/tab/tab.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<nz-card class="m-t-10" style="height: 35px" [nzBodyStyle]="{padding:0}" [nzBordered]="false">
<nz-card id="multi-tab" class="m-t-10" style="height: 35px" [nzBodyStyle]="{padding:0}" [nzBordered]="false">
<nz-tabset (nzClose)="clickCloseIcon($event)" [nzSelectedIndex]="currentIndex"
[nzTabBarStyle]="{'height':'35px'}"
[nzTabPosition]="'top'" [nzType]="'editable-card'" [nzHideAdd]="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ng-container *ngTemplateOutlet="headRight"></ng-container>
<ng-template #headRight>
<div class="bst-header-wrap">
<div class="bst-header-wrap" id="tools">
<span (click)="showSearchModal()" *appScreenLessHidden="'320'" class="bst-header-icon" nz-tooltip nzTooltipTitle="搜索"
nzTooltipPlacement="bottom">
<i nz-icon nzType="search" nzTheme="outline"></i>
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/components/chat/chat.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="chat-wrap" [class.show]="show">
<div id="chats" class="chat-wrap" [class.show]="show">
<nz-card [nzActions]="[inputTpl]" [nzTitle]="titleTemplate"
[nzBodyStyle]="{padding:0}" [nzExtra]="extraTemplate">
<div #scrollMe class="flex chart-content">
Expand Down

0 comments on commit 7272a0a

Please sign in to comment.