list.component.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. import { AfterViewInit, Component, Input, OnInit } from '@angular/core';
  2. import { ActivatedRoute, Router } from '@angular/router';
  3. import { firstValueFrom } from 'rxjs';
  4. import { FilterItem, FilterType } from 'src/app/lib/pager/pager-filter.component';
  5. import { SysService } from '../sys/sys.service';
  6. @Component({
  7. selector: 'art-list',
  8. template: `
  9. <nz-page-header *ngIf="!embedMode" [nzGhost]="false">
  10. <nz-page-header-title i18n>{{data?.title || '作品列表'}}</nz-page-header-title>
  11. <nz-page-header-extra>
  12. <ng-container *ngIf="!hideUpload">
  13. <a *can="['create', 'own', 'art']" nz-button nzType="primary" routerLink="/art/play">
  14. <i class="fal fa-cloud-upload mr-1"></i>
  15. <ng-container i18n>上传作品</ng-container>
  16. </a>
  17. </ng-container>
  18. </nz-page-header-extra>
  19. <nz-page-header-content>
  20. </nz-page-header-content>
  21. </nz-page-header>
  22. <cg-pager
  23. [remoteUrl]="remoteUrl"
  24. remoteHeaderUrl="/napi/web/art/pager/headers"
  25. [defaultOrder]="'desc'"
  26. [defaultOrderBy]="'date'"
  27. [listTemplate]="listTemplate"
  28. [pageSizeOptions]="[30, 60, 90, 120, 150, 180, 480]"
  29. [topPagination]="true"
  30. [bottomPagination]="true"
  31. [showOrder]="true"
  32. [showSearch]="true"
  33. [debug]="false"
  34. [refresh]="refreshTrigger"
  35. [filterConfig]="filterConfig"
  36. [inputFilters]="inputFilters"
  37. [orderColumns]="['areaCount', 'status', 'publishTime', 'date','lastMod' ]"
  38. ></cg-pager>
  39. <ng-template #listTemplate let-list="list" >
  40. <div nz-row [nzGutter]="[20, 20]" class="pt-4 pb-4"
  41. cdkDropList
  42. id="list-1"
  43. cdkDropListConnectedTo="list-2"
  44. [cdkDropListDisabled]="!embedMode"
  45. [cdkDropListSortingDisabled]="true"
  46. [cdkDropListData]="list?.data"
  47. >
  48. <art-card *ngFor="let item of list?.data"
  49. nz-col [nzSm]="8" [nzMd]="6" [nzLg]="6" [nzXl]="4" [nzXXl]="3"
  50. [data]="item"
  51. [hideAuthor]="hideAuthor"
  52. (itemClick)="onItemClick($event)"
  53. (useClick)="filter('use', $event)"
  54. (tagClick)="filter('tags', [$event])"
  55. (authorClick)="filter('user', [$event])"
  56. cdkDrag
  57. >
  58. </art-card>
  59. </div>
  60. </ng-template>
  61. `,
  62. styles: [
  63. `
  64. :host {
  65. padding-bottom:100px;
  66. display:block;
  67. }
  68. .cdk-drag-preview {
  69. box-sizing: border-box;
  70. border-radius: 4px;
  71. box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
  72. 0 8px 10px 1px rgba(0, 0, 0, 0.14),
  73. 0 3px 14px 2px rgba(0, 0, 0, 0.12);
  74. }
  75. .cdk-drag-placeholder {
  76. opacity: 0;
  77. }
  78. .cdk-drag-animating {
  79. transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
  80. }
  81. nz-select {
  82. width: 150px;
  83. }
  84. `
  85. ]
  86. })
  87. export class ListComponent implements OnInit, AfterViewInit {
  88. @Input() remoteUrl = '/napi/web/art/pager/my';
  89. @Input() hideAuthor: boolean = false;
  90. @Input() hideUpload: boolean = false;
  91. @Input() embedMode: boolean = false;
  92. @Input() refreshTrigger: any;
  93. @Input()
  94. filterConfig: FilterItem[] = [
  95. {
  96. data: 'status',
  97. title: $localize`状态`,
  98. filterType: FilterType.radio,
  99. options: [
  100. { label: $localize`拒稿`, value: 500 },
  101. { label: $localize`草稿`, value: 1000 },
  102. { label: $localize`需要修改`, value: 2000 },
  103. { label: $localize`测试中`, value: 3000 },
  104. { label: $localize`测试通过`, value: 7000 },
  105. { label: $localize`已发布`, value: 9000 },
  106. { label: $localize`下线`, value: 8000 },
  107. ],
  108. span: 4,
  109. },
  110. {
  111. data: 'use',
  112. title: $localize`用途`,
  113. filterType: FilterType.radio,
  114. options: [
  115. { label: $localize`日常`, value: 'normal' },
  116. { label: $localize`每日`, value: 'daily' },
  117. { label: $localize`专辑`, value: 'album' },
  118. { label: $localize`收集`, value: 'collection' },
  119. ],
  120. span: 2,
  121. },
  122. {
  123. data: 'date',
  124. title: $localize`上传`,
  125. filterType: FilterType.dateRange,
  126. span: 2,
  127. },
  128. {
  129. data: 'publishTime',
  130. title: $localize`发布`,
  131. filterType: FilterType.dateRange,
  132. span: 2,
  133. },
  134. {
  135. data: 'tags',
  136. title: $localize`标签`,
  137. filterType: FilterType.select,
  138. mode: 'tags',
  139. span: 2,
  140. fullWidth: true,
  141. optionsUrl: '/napi/web/art/agg/tags',
  142. },
  143. {
  144. data: 'user',
  145. title: $localize`作者`,
  146. filterType: FilterType.select,
  147. mode: 'multiple',
  148. span: 2,
  149. fullWidth: true,
  150. optionsUrl: '/napi/web/user/select/options',
  151. },
  152. {
  153. data: 'hasSpecial',
  154. title: $localize`彩绘`,
  155. filterType: FilterType.select,
  156. options: [
  157. { label: $localize`是`, value: true },
  158. { label: $localize`否`, value: false },
  159. ],
  160. span: 1,
  161. },
  162. {
  163. data: 'mystery',
  164. title: $localize`神秘图`,
  165. filterType: FilterType.select,
  166. options: [
  167. { label: $localize`是`, value: true },
  168. { label: $localize`否`, value: false },
  169. ],
  170. span: 1,
  171. },
  172. {
  173. data: 'ai',
  174. title: $localize`AI`,
  175. filterType: FilterType.select,
  176. options: [
  177. { label: $localize`是`, value: true },
  178. { label: $localize`否`, value: false },
  179. ],
  180. span: 1,
  181. },
  182. {
  183. data: 'width',
  184. title: $localize`尺寸`,
  185. filterType: FilterType.select,
  186. options: [
  187. { label: '2000', value: 2000 },
  188. { label: '1500', value: 1500 },
  189. { label: '2400', value: 2400 },
  190. { label: '3000', value: 3000 },
  191. ],
  192. span: 1,
  193. },
  194. {
  195. data: 'lock',
  196. title: $localize`加锁`,
  197. filterType: FilterType.select,
  198. options: [
  199. { label: $localize`是`, value: true },
  200. { label: $localize`否`, value: false },
  201. ],
  202. span: 1,
  203. },
  204. ];
  205. inputFilters: any;
  206. constructor(
  207. private router: Router,
  208. private activatedRoute: ActivatedRoute,
  209. private sysService: SysService,
  210. ) {
  211. this.data = this.activatedRoute.snapshot.data;
  212. let { remoteUrl, hideAuthor, hideUpload } = this.activatedRoute.snapshot.data;
  213. this.remoteUrl = remoteUrl || this.remoteUrl;
  214. this.hideAuthor = hideAuthor;
  215. this.hideUpload = hideUpload;
  216. if (this.hideAuthor) {
  217. this.filterConfig = this.filterConfig.filter(c => c.data != 'user');
  218. }
  219. }
  220. filter(data, value) {
  221. console.log('filter', data, value);
  222. let filter = {};
  223. filter[data] = value;
  224. this.inputFilters = filter;
  225. }
  226. data: any;
  227. onItemClick(data: any) {
  228. //this.router.navigate([`/art/play/${data._id}`]);
  229. this.router.navigate(['/pages/detail', data._id]);
  230. }
  231. ngAfterViewInit() { }
  232. ngOnInit() {
  233. }
  234. }