Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

service-register-config.component.ts 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import { Component, inject, ViewChild, OnInit, AfterViewInit } from '@angular/core';
  2. import { ConfigMetaService } from '../../services/config-meta.service';
  3. import { ConfigService, StickyHeaderComponent, StickyHeaderButton, TabulatorGridComponent } from 'base-core';
  4. import { CommonModule } from '@angular/common';
  5. import { Observable } from 'rxjs';
  6. @Component({
  7. imports: [CommonModule, StickyHeaderComponent, TabulatorGridComponent],
  8. selector: 'app-service-register-config',
  9. templateUrl: './service-register-config.component.html',
  10. styleUrl: './service-register-config.component.scss'
  11. })
  12. export class ServiceRegisterConfigComponent implements OnInit, AfterViewInit {
  13. private configMetaService = inject(ConfigMetaService);
  14. private config = inject(ConfigService);
  15. @ViewChild(TabulatorGridComponent) tabulatorGrid!: TabulatorGridComponent;
  16. ngOnInit(): void {
  17. console.log('ServiceRegisterConfigComponent 初始化');
  18. // 确保使用代理API路径
  19. this.config.apiBaseUrl = '/api';
  20. console.log('ConfigService:', {
  21. useMockData: this.config.useMockData,
  22. apiBaseUrl: this.config.apiBaseUrl
  23. });
  24. }
  25. ngAfterViewInit(): void {
  26. console.log('👀 ServiceRegisterConfigComponent: TabulatorGrid 视图初始化完成');
  27. }
  28. title = '注册服务配置';
  29. hintText = '点击"注册"按钮将同步所有配置元信息到数据库,并显示配置列表。';
  30. headerButtons: StickyHeaderButton[] = [
  31. { title: '注册', name: 'register', icon: 'add', color: 'primary' },
  32. { title: '刷新', name: 'refresh', icon: 'refresh', color: 'accent' }
  33. ];
  34. // 外部查询条件预留字段(用于将来扩展)
  35. externalFilters: any = {};
  36. // 表格列定义
  37. columns = [
  38. {
  39. title: 'ID',
  40. field: 'id',
  41. sorter: 'number',
  42. headerFilter: 'input',
  43. width: 220,
  44. headerMenu: [
  45. {
  46. label: "<i class='fa fa-filter'></i> 切换筛选",
  47. action: (column: any) => {
  48. const headerFilterEl = column.getElement().querySelector('.tabulator-header-filter');
  49. if (headerFilterEl) {
  50. const isHidden = headerFilterEl.style.display === 'none';
  51. headerFilterEl.style.display = isHidden ? '' : 'none';
  52. }
  53. }
  54. }
  55. ]
  56. },
  57. {
  58. title: '配置名称',
  59. field: 'configName',
  60. sorter: 'string',
  61. headerFilter: 'input',
  62. headerFilterFunc: 'like',
  63. width: 110
  64. },
  65. {
  66. title: '字段名',
  67. field: 'fieldName',
  68. sorter: 'string',
  69. headerFilter: 'input',
  70. headerFilterFunc: 'like',
  71. width: 130
  72. },
  73. {
  74. title: '字段类型',
  75. field: 'fieldType',
  76. sorter: 'string',
  77. headerFilter: 'input',
  78. width: 120,
  79. headerFilterParams: { values: ['string', 'number', 'boolean', 'array', 'object'] }
  80. },
  81. {
  82. title: '描述',
  83. field: 'fieldDesc',
  84. sorter: 'string',
  85. headerFilter: 'input',
  86. headerFilterFunc: 'like'
  87. }
  88. ];
  89. /**
  90. * 数据加载函数 - 适配 TabulatorGridComponent
  91. */
  92. dataLoader = (params: any): Observable<{ last_page: number; data: any[] }> => {
  93. console.group('🚨🚨🚨 ServiceRegisterConfigComponent 数据加载函数被调用 🚨🚨🚨');
  94. console.log('🔍 调用来源堆栈:', new Error().stack);
  95. console.log('🔍 原始参数结构:', {
  96. type: typeof params,
  97. isObject: params && typeof params === 'object',
  98. keys: params ? Object.keys(params) : [],
  99. hasSize: 'size' in params,
  100. hasPage: 'page' in params,
  101. hasFilter: 'filter' in params,
  102. hasSort: 'sort' in params
  103. });
  104. console.log('📦 原始参数详情:', params);
  105. // 深度检查筛选和排序参数
  106. if (params) {
  107. console.log('🔍 筛选参数检查:', {
  108. hasFilter: 'filter' in params,
  109. filterType: typeof params.filter,
  110. isArray: Array.isArray(params.filter),
  111. filterLength: Array.isArray(params.filter) ? params.filter.length : 'N/A',
  112. filterSample: Array.isArray(params.filter) && params.filter.length > 0 ? params.filter.slice(0, 2) : '空'
  113. });
  114. console.log('🔍 排序参数检查:', {
  115. hasSort: 'sort' in params,
  116. sortType: typeof params.sort,
  117. isArray: Array.isArray(params.sort),
  118. sortLength: Array.isArray(params.sort) ? params.sort.length : 'N/A',
  119. sortSample: Array.isArray(params.sort) && params.sort.length > 0 ? params.sort.slice(0, 2) : '空'
  120. });
  121. }
  122. console.log('🔗 ConfigMetaService URL:', this.configMetaService.getListUrl());
  123. // 确保参数有默认值
  124. const safeParams = {
  125. page: params?.page || 1,
  126. size: params?.size || 20,
  127. sort: params?.sort || [],
  128. filter: params?.filter || []
  129. };
  130. console.log('✅ 处理后参数:', safeParams);
  131. console.log('📤 发送给 listForTabulator 的参数:', JSON.stringify(safeParams, null, 2));
  132. console.groupEnd();
  133. return this.configMetaService.listForTabulator(safeParams);
  134. };
  135. /**
  136. * 注册配置元信息
  137. */
  138. onRegister(): void {
  139. console.log('注册按钮被点击');
  140. this.headerButtons[0].loading = true;
  141. this.configMetaService.initConfigMeta().subscribe({
  142. next: (result: any) => {
  143. this.headerButtons[0].loading = false;
  144. if (result.success) {
  145. console.log('注册完成:', result.data);
  146. // 注册成功后刷新表格数据
  147. this.refresh();
  148. console.log('注册成功,数据已重新加载');
  149. } else {
  150. console.error('注册失败:', result);
  151. }
  152. },
  153. error: (error) => {
  154. this.headerButtons[0].loading = false;
  155. console.error('注册请求失败:', error);
  156. }
  157. });
  158. }
  159. /**
  160. * 处理头部按钮点击事件
  161. */
  162. onHeaderButtonAction(name: string): void {
  163. console.log(`头部按钮点击: ${name}`);
  164. switch (name) {
  165. case 'register':
  166. this.onRegister();
  167. break;
  168. case 'refresh':
  169. this.refresh();
  170. break;
  171. default:
  172. console.warn(`未知按钮操作: ${name}`);
  173. }
  174. }
  175. /**
  176. * 刷新表格数据
  177. */
  178. refresh(): void {
  179. if (this.tabulatorGrid) {
  180. this.headerButtons[1].loading = true;
  181. this.tabulatorGrid.refresh();
  182. // 简单延迟后清除loading状态
  183. setTimeout(() => {
  184. this.headerButtons[1].loading = false;
  185. }, 500);
  186. }
  187. }
  188. /**
  189. * 重置筛选和排序
  190. */
  191. reset(): void {
  192. if (this.tabulatorGrid) {
  193. this.tabulatorGrid.reset();
  194. }
  195. }
  196. /**
  197. * 刷新表格 - 模板别名
  198. */
  199. refreshTable(): void {
  200. this.refresh();
  201. }
  202. /**
  203. * 重置表格 - 模板别名
  204. */
  205. resetTable(): void {
  206. this.reset();
  207. }
  208. /**
  209. * 导出数据为 CSV
  210. */
  211. exportData(): void {
  212. if (this.tabulatorGrid) {
  213. this.tabulatorGrid.exportToCSV('config-meta-data.csv');
  214. }
  215. }
  216. /**
  217. * 处理表格数据加载完成事件
  218. */
  219. onDataLoaded(response: any): void {
  220. console.log('✅ 表格数据加载完成:', {
  221. last_page: response?.last_page,
  222. data_count: response?.data?.length,
  223. data_sample: response?.data?.slice(0, 2)
  224. });
  225. }
  226. /**
  227. * 处理 AJAX 错误事件
  228. */
  229. onAjaxError(error: any): void {
  230. console.error('❌ 表格 AJAX 错误:', error);
  231. console.error('错误详情:', {
  232. message: error?.message,
  233. status: error?.status,
  234. url: error?.url
  235. });
  236. }
  237. }