File

src/app/layout/html-builder/component/ch/ch-head/ch-head.component.ts

Implements

OnInit

Metadata

encapsulation ViewEncapsulation.None
selector app-ch-head
styleUrls ./ch-head.component.less
templateUrl ./ch-head.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(pageEditorService: PageEditorService, nzContextMenuService: NzContextMenuService)
Parameters :
Name Type Optional
pageEditorService PageEditorService No
nzContextMenuService NzContextMenuService No

Inputs

item
Type : DropItem
itemIndex
Type : number
itemParent
Type : DropItem[]

Methods

Public click
click()
Returns : void
Public contextMenu
contextMenu(event: MouseEvent, menu: NzDropdownMenuComponent)
Parameters :
Name Type Optional
event MouseEvent No
menu NzDropdownMenuComponent No
Returns : void
Public copy
copy()
Returns : void
Public delete
delete()
Returns : void
Public ngOnInit
ngOnInit()
Returns : void

Properties

Public pageEditorService
Type : PageEditorService
Public schema
Type : SFSchema
Default value : { required: ['text'], properties: { head: { type: 'string', title: '标题类型', enum: [ { label: 'H1 (字体大小:20)', value: 'H1' }, { label: 'H2 (字体大小:15)', value: 'H2' }, { label: 'H3 (字体大小:12)', value: 'H3' }, { label: 'H4 (字体大小:10)', value: 'H4' }, { label: 'H5 (字体大小:10)', value: 'H5' }, { label: 'H6 (字体大小:10)', value: 'H6' }, ], default: 'H2', }, text: { type: 'string', title: '标题文本', ui: { widget: 'textarea', autosize: { minRows: 2 }, firstVisual: true, }, }, size: { type: 'number', title: '字体大小', minimum: 8, maximum: 40, }, headStyle: { type: 'string', title: '对齐方式', enum: [ { label: '左对齐', value: 'left-align' }, { label: '居中', value: 'center' }, { label: '右对齐', value: 'right-align' }, { label: '清除边距', value: 'clearmargin' }, ], default: 'left-align', }, href: { type: 'string', title: '标题链接url', }, icon: { type: 'string', title: '前置图标', enum: [ { label: '无', value: '' }, { label: '亮点', value: 'hicon-light' }, ], default: '', }, }, }
import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core';
import { SFSchema } from '@delon/form';
import { NzContextMenuService, NzDropdownMenuComponent } from 'ng-zorro-antd/dropdown';
import { DropItem, PageEditorService } from 'src/app/layout/html-builder/page-editor/page-editor.service';

@Component({
  selector: 'app-ch-head',
  templateUrl: './ch-head.component.html',
  styleUrls: ['./ch-head.component.less'],
  encapsulation: ViewEncapsulation.None
})
export class ChHeadComponent implements OnInit {

  public schema: SFSchema = {
    required: ['text'],
    properties: {
      head: {
        type: 'string',
        title: '标题类型',
        enum: [
          { label: 'H1 (字体大小:20)', value: 'H1' },
          { label: 'H2 (字体大小:15)', value: 'H2' },
          { label: 'H3 (字体大小:12)', value: 'H3' },
          { label: 'H4 (字体大小:10)', value: 'H4' },
          { label: 'H5 (字体大小:10)', value: 'H5' },
          { label: 'H6 (字体大小:10)', value: 'H6' },
        ],
        default: 'H2',
      },
      text: {
        type: 'string',
        title: '标题文本',
        ui: {
          widget: 'textarea',
          autosize: { minRows: 2 },
          firstVisual: true,
        },
      },
      size: {
        type: 'number',
        title: '字体大小',
        minimum: 8,
        maximum: 40,
      },
      headStyle: {
        type: 'string',
        title: '对齐方式',
        enum: [
          { label: '左对齐', value: 'left-align' },
          { label: '居中', value: 'center' },
          { label: '右对齐', value: 'right-align' },
          { label: '清除边距', value: 'clearmargin' },
        ],
        default: 'left-align',
      },
      href: {
        type: 'string',
        title: '标题链接url',
      },
      icon: {
        type: 'string',
        title: '前置图标',
        enum: [
          { label: '无', value: '' },
          { label: '亮点', value: 'hicon-light' },
        ],
        default: '',
      },
    },
  };

  @Input()
  public item: DropItem;

  @Input()
  public itemIndex: number;

  @Input()
  public itemParent: DropItem[];

  constructor(
    public pageEditorService: PageEditorService,
    private nzContextMenuService: NzContextMenuService,
  ) { }

  // 右键菜单
  public contextMenu(event: MouseEvent, menu: NzDropdownMenuComponent): void {
    event.stopPropagation();
    event.stopImmediatePropagation();
    this.nzContextMenuService.create(event, menu);
  }

  // 复制组件
  public copy() {
    this.pageEditorService.copyDropItem(this.itemIndex, this.itemParent);
  }

  // 删除组件
  public delete() {
    this.pageEditorService.removeDropItem(this.itemIndex, this.itemParent);
  }

  // 点击打开属性
  public click() {
    this.pageEditorService.updatePropForm(this.schema, this.item);
  }

  public ngOnInit() {
  }

}
<h1 *ngIf="item.data.head === 'H1'" class="ChHead mb2" (contextmenu)="contextMenu($event, menu)" (click)="click()"
  [ngClass]="item.data | props" [innerHTML]="(item.data.text || '标题(Heading)元素呈现不同的级别的标题,H1级别最高且唯一。') | safe">
</h1>
<h2 *ngIf="item.data.head === 'H2' || !item.data.head" class="ChHead mb2" (contextmenu)="contextMenu($event, menu)"
  (click)="click()" [ngClass]="item.data | props"
  [innerHTML]="(item.data.text || '标题(Heading)元素呈现不同的级别的标题,H1级别最高且唯一。') | safe">
</h2>
<h3 *ngIf="item.data.head === 'H3'" class="ChHead mb2" (contextmenu)="contextMenu($event, menu)" (click)="click()"
  [ngClass]="item.data | props" [innerHTML]="(item.data.text || '标题(Heading)元素呈现不同的级别的标题,H1级别最高且唯一。') | safe">
</h3>
<h4 *ngIf="item.data.head === 'H4'" class="ChHead mb2" (contextmenu)="contextMenu($event, menu)" (click)="click()"
  [ngClass]="item.data | props" [innerHTML]="(item.data.text || '标题(Heading)元素呈现不同的级别的标题,H1级别最高且唯一。') | safe">
</h4>
<h5 *ngIf="item.data.head === 'H5'" class="ChHead mb2" (contextmenu)="contextMenu($event, menu)" (click)="click()"
  [ngClass]="item.data | props" [innerHTML]="(item.data.text || '标题(Heading)元素呈现不同的级别的标题,H1级别最高且唯一。') | safe">
</h5>
<h6 *ngIf="item.data.head === 'H6'" class="ChHead mb2" (contextmenu)="contextMenu($event, menu)" (click)="click()"
  [ngClass]="item.data | props" [innerHTML]="(item.data.text || '标题(Heading)元素呈现不同的级别的标题,H1级别最高且唯一。') | safe">
</h6>
<nz-dropdown-menu #menu="nzDropdownMenu">
  <ul nz-menu class="grid-context-ment">
    <li nz-menu-item>标题 <i nz-icon nzType="question-circle" nzTheme="twotone"></i></li>
    <li nz-menu-divider></li>
    <li nz-menu-item (click)="copy()">复制标题</li>
    <li nz-menu-item (click)="delete()">删除标题</li>
  </ul>
</nz-dropdown-menu>

./ch-head.component.less

/*ChHead*/
h1.ChHead,
h2.ChHead,
h3.ChHead,
h4.ChHead {
  font-weight: 400;
  color: #444;
  margin-top: 0;
}

h1.ChHead {
  margin-top: 0.5rem;
}

/*前置图标*/
.ChHead.hicon-light {
  background: url(https://data.chinahighlights.com/css/images/tour/detail/itinerary-43x29.png) no-repeat 0 center;
  padding-left: 2.5rem;
  background-size: auto 60%;
}

@media (max-width: 768px) {
  h1.ChHead {
    font-size: 1.6rem;
    line-height: 2rem;
  }

  h2.ChHead {
    font-size: 1.4rem;
    line-height: 1.8rem;
  }

  h3.ChHead {
    font-size: 1.2rem;
    line-height: 1.6rem;
  }

  h4.ChHead {
    font-size: 1.1rem;
    line-height: 1.6rem;
  }

  h5.ChHead {
    font-size: 1rem;
    line-height: 1.6rem;
  }

  h6.ChHead {
    font-size: 1rem;
    line-height: 1.6rem;
  }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""