Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
biaogebusy committed Dec 13, 2024
2 parents 5bd2b63 + a036cce commit 34786b2
Show file tree
Hide file tree
Showing 66 changed files with 2,319 additions and 2,945 deletions.
7 changes: 3 additions & 4 deletions src/app/core/branding/footer/inverse/inverse.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
}

.item-header {
height: 48px;
line-height: 16px;
font-size: 14px;
font-weight: bold;
height: 40px;
font-size: 16px;
display: flex;
align-items: center;
margin-top: 14px;
}

.left {
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/branding/header/menu/menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<app-switch-theme class="has-icon" />
}
@if (header.params.userInfo) {
<app-user-menu [content]="header.userMenu" />
<app-user-menu />
}
<app-lang-switch />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,18 @@
}
@if (user$ | async; as user) {
@if (!user.picture) {
<button aria-label="user name" mat-mini-fab color="primary" [matMenuTriggerFor]="menu">
<button aria-label="user name" mat-mini-fab color="primary" (click)="openDialog()">
<h3 class="name">
{{ utilities.getIndexTitle(user.display_name || 'N') }}
</h3>
</button>
} @else {
<img
class="user-picture"
[matMenuTriggerFor]="menu"
(click)="openDialog()"
[src]="user.picture"
alt="{{ user.display_name }}"
/>
}
<ng-template #picture>
<img
class="user-picture"
[matMenuTriggerFor]="menu"
[src]="user.picture"
alt="{{ user.display_name }}"
/>
</ng-template>
<mat-menu #menu="matMenu" class="user-dropdown">
<a mat-menu-item [routerLink]="userService.userPage">
<mat-icon>account_circle</mat-icon>{{ user.display_name }}
</a>
@for (item of content; track item) {
<button aria-label="user link" mat-menu-item *reqRolesIf="item">
<app-icon [content]="item.icon" />
<app-link [content]="item" />
</button>
}
<button aria-label="logout" mat-menu-item (click)="logout()">
<mat-icon>exit_to_app</mat-icon>退出
</button>
</mat-menu>
}
</div>
68 changes: 23 additions & 45 deletions src/app/core/branding/header/menu/user-menu/user-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ import {
inject,
DestroyRef,
} from '@angular/core';
import { UtilitiesService } from '@core/service/utilities.service';
import { ScreenState } from '@core/state/screen/ScreenState';
import { DialogComponent } from '@uiux/widgets/dialog/dialog.component';
import { DialogService } from '@core/service/dialog.service';
import { Observable } from 'rxjs';
import { USER } from '@core/token/token-providers';
import type { IUser } from '@core/interface/IUser';
import { UserService } from '@core/service/user.service';
import { environment } from 'src/environments/environment';
import { LoginComponent } from '@modules/user/login/login.component';
import { Router } from '@angular/router';
import { LocalStorageService } from 'ngx-webstorage';
import { MatDialog } from '@angular/material/dialog';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { UtilitiesService } from '@core/service/utilities.service';

@Component({
selector: 'app-user-menu',
Expand All @@ -34,33 +32,29 @@ export class UserMenuComponent implements OnInit {
dialogRef: any;
currentUser: IUser | false;

utilities = inject(UtilitiesService);
screen = inject(ScreenState);
dialog = inject(MatDialog);
dialogService = inject(DialogService);
cd = inject(ChangeDetectorRef);
userService = inject(UserService);
router = inject(Router);
storage = inject(LocalStorageService);
utilities = inject(UtilitiesService);
private destroyRef = inject(DestroyRef);
constructor(@Inject(USER) public user$: Observable<IUser>) {
this.user$.pipe(takeUntilDestroyed()).subscribe(user => {
this.currentUser = user;
});
this.userService.userSub$
.pipe(takeUntilDestroyed())
.subscribe((currentUser: any) => {
// login
if (currentUser) {
this.currentUser = currentUser;
this.cd.detectChanges();
}
// logout
if (!currentUser) {
this.currentUser = false;
this.cd.detectChanges();
}
});
this.userService.userSub$.pipe(takeUntilDestroyed()).subscribe((currentUser: any) => {
// login
if (currentUser) {
this.currentUser = currentUser;
this.cd.detectChanges();
}
// logout
if (!currentUser) {
this.currentUser = false;
this.cd.detectChanges();
}
});
}

ngOnInit(): void {
Expand All @@ -78,11 +72,6 @@ export class UserMenuComponent implements OnInit {
}
}

logout(): void {
const logoutToken = this.storage.retrieve(this.userService.logoutToken);
this.userService.logout(logoutToken);
}

onLogin(): void {
const { pathname } = window.location;
const queryParams = {
Expand All @@ -92,31 +81,20 @@ export class UserMenuComponent implements OnInit {
this.dialog.open(LoginComponent);
}

openDialog(dialog: any): void {
openDialog(): void {
this.dialogRef = this.dialog.open(DialogComponent, {
width: dialog.width || '600px',
width: '380px',
panelClass: ['close-outside', 'close-icon-white'],
data: {
title: '账户设置',
disableCloseButton: true,
inputData: {
content: dialog.content,
actions: dialog.actions,
content: {
type: 'user-setting',
fullWidth: true,
},
},
},
});
this.dialogRef
.afterClosed()
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => console.log('dialog after'));
this.dialogService.dialogState$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(state => {
if (!state) {
this.dialogRef.close();
}
});
this.dialogService.handlerIframe(this.dialog);
}

trackByFn(index: number, item: any): number {
return index;
}
}
12 changes: 4 additions & 8 deletions src/app/core/directive/contentedit.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ export class ContenteditDirective implements AfterViewInit, OnInit {

@HostListener('blur', ['$event']) onBlur(event: any): void {
const { currentTarget } = event;
if (
this.componentItem &&
currentTarget &&
currentTarget.contentEditable === 'true'
) {
if (this.componentItem && currentTarget && currentTarget.contentEditable === 'true') {
currentTarget.contentEditable = 'false';
const path = this.generatePath(currentTarget);
this.builder.updatePageContentByPath(path, currentTarget.innerHTML);
Expand Down Expand Up @@ -102,7 +98,7 @@ export class ContenteditDirective implements AfterViewInit, OnInit {
mode: 'push',
hasBackdrop: false,
style: {
width: '260px',
'width': '260px',
'max-width': 'calc(100vw - 50px)',
},
elements: [meta],
Expand All @@ -123,7 +119,7 @@ export class ContenteditDirective implements AfterViewInit, OnInit {
mode: 'text',
path,
ele,
fields: getInlineText(ele),
fields: [getInlineText(ele)],
data: {
innerHTML: ele.innerHTML,
tag: ele.tagName,
Expand All @@ -133,7 +129,7 @@ export class ContenteditDirective implements AfterViewInit, OnInit {
mode: 'push',
hasBackdrop: false,
style: {
width: '300px',
'width': '300px',
'max-width': 'calc(100vw - 140px)',
},
elements: [meta],
Expand Down
24 changes: 0 additions & 24 deletions src/app/core/interface/branding/IBranding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export interface IHeader {
banner?: any;
mainMenu: IMainMenu[];
search: IHeaderSearch;
userMenu: IUserMenu[];
actions: ILink[];
}

Expand Down Expand Up @@ -109,29 +108,6 @@ interface FooterParams {
shape?: boolean;
}

export interface IUserMenu {
label: string;
icon: {
name: string;
};
dialog?: Dialog;
href?: string;
}

interface Dialog {
content: any;
actions: Action[];
}

interface Action {
label: string;
color: string;
params: {
type: string;
snackMes: string;
};
}

export interface IHeaderSearch {
enable: boolean;
placeholder: string;
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/service/builder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ export class BuilderService extends ApiService {
);
}

getDefaultPage(): Observable<IPage> {
getDefaultPage(url: string): Observable<IPage> {
const { apiUrl, production } = environment;
const pathname = window.location.pathname;
const { lang } = this.getUrlPath(pathname);
if (!production) {
return this.http.get<IPage>(`${apiUrl}/assets/app${lang}/builder/default-page.json`);
return this.http.get<IPage>(`${apiUrl}/assets/app${lang}${url}.json`);
} else {
this.builder.loading$.next(true);
return this.contentService.loadPageContent(`${lang}/builder/default-page`).pipe(
return this.contentService.loadPageContent(`${lang}${url}`).pipe(
tap(res => {
this.builder.loading$.next(false);
if (isArray(res) || !res) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/service/component.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class ComponentService {
['manage-media', 'upload-media', 'taxonomy'].forEach(type =>
this.setModule(type, () => import('@modules/manage/manage.module').then(m => m.ManageModule))
);
['login'].forEach(type =>
['login', 'user-setting'].forEach(type =>
this.setModule(type, () => import('@modules/user/user.module').then(m => m.UserModule))
);
}
Expand Down
Loading

0 comments on commit 34786b2

Please sign in to comment.