admin-resource.component.ts 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. import { CommonModule } from '@angular/common';
  2. import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, computed, inject, signal } from '@angular/core';
  3. import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
  4. import { FormsModule } from '@angular/forms';
  5. import { ActivatedRoute } from '@angular/router';
  6. import { ChevronLeft, ChevronRight, Eye, KeyRound, LoaderCircle, LucideAngularModule, Pencil, Plus, RefreshCw, Search, Trash2, X } from 'lucide-angular';
  7. import { AdminClassSchema, AdminFieldSchema, ResourcePage } from '../admin.models';
  8. import { CloudFunctionsService } from '../cloud-functions.service';
  9. interface SurveyChart {
  10. survey: Record<string, unknown>;
  11. responseCount: number;
  12. invalidAnswers: number;
  13. questions: { id: string; title: string; type: string; options: { text: string; value: string; count: number }[]; otherCount: number }[];
  14. }
  15. @Component({
  16. selector: 'app-admin-resource',
  17. standalone: true,
  18. imports: [CommonModule, FormsModule, LucideAngularModule],
  19. templateUrl: './admin-resource.component.html',
  20. styleUrl: './admin-resource.component.scss',
  21. changeDetection: ChangeDetectionStrategy.OnPush,
  22. })
  23. export class AdminResourceComponent implements OnInit {
  24. readonly className = signal('');
  25. readonly schema = signal<AdminClassSchema | null>(null);
  26. readonly page = signal<ResourcePage | null>(null);
  27. readonly loading = signal(true);
  28. readonly saving = signal(false);
  29. readonly resettingPassword = signal(false);
  30. readonly error = signal('');
  31. readonly search = signal('');
  32. readonly editorOpen = signal(false);
  33. readonly draftId = signal('');
  34. readonly draft = signal<Record<string, unknown>>({});
  35. readonly fieldErrors = signal<Record<string, string>>({});
  36. readonly fieldInputs = signal<Record<string, string>>({});
  37. readonly newPassword = signal('');
  38. readonly confirmPassword = signal('');
  39. readonly passwordMessage = signal('');
  40. readonly passwordError = signal('');
  41. readonly createUsername = signal('');
  42. readonly createPassword = signal('');
  43. readonly createConfirmPassword = signal('');
  44. readonly createDisplayName = signal('');
  45. readonly createMobile = signal('');
  46. readonly createInviteUsername = signal('');
  47. readonly createUserError = signal('');
  48. readonly userGroups = signal<Record<string, unknown>[]>([]);
  49. readonly selectedUserGroupId = signal(0);
  50. readonly userActionReason = signal('');
  51. readonly userActionError = signal('');
  52. readonly userActionMessage = signal('');
  53. readonly updatingUser = signal(false);
  54. readonly selectedContentStatus = signal(0);
  55. readonly targetContentNodeId = signal(0);
  56. readonly updatingContent = signal(false);
  57. readonly contentActionError = signal('');
  58. readonly contentActionMessage = signal('');
  59. readonly targetNodeParentId = signal(0);
  60. readonly updatingNode = signal(false);
  61. readonly nodeActionError = signal('');
  62. readonly nodeActionMessage = signal('');
  63. readonly targetSpecialParentId = signal(0);
  64. readonly updatingSpecial = signal(false);
  65. readonly specialActionError = signal('');
  66. readonly specialActionMessage = signal('');
  67. readonly selectedGuestbookStatus = signal(99);
  68. readonly guestbookReplyTitle = signal('');
  69. readonly guestbookReplyContent = signal('');
  70. readonly updatingGuestbook = signal(false);
  71. readonly guestbookActionError = signal('');
  72. readonly guestbookActionMessage = signal('');
  73. readonly guestCategoryType = signal(0);
  74. readonly targetGuestCategoryParentId = signal(0);
  75. readonly targetBarCategoryId = signal(0);
  76. readonly updatingBar = signal(false);
  77. readonly barActionError = signal('');
  78. readonly barActionMessage = signal('');
  79. readonly targetExamClassParentId = signal(0);
  80. readonly examClassType = signal(1);
  81. readonly examClassOrder = signal(0);
  82. readonly targetExamPointParentId = signal(0);
  83. readonly examPointOrder = signal(0);
  84. readonly targetKnowledgeClassId = signal(0);
  85. readonly targetKnowledgeParentId = signal(0);
  86. readonly knowledgeOrder = signal(0);
  87. readonly targetTeacherClassId = signal(0);
  88. readonly targetDictionaryCategoryId = signal(0);
  89. readonly dictionaryCategories = signal<Record<string, unknown>[]>([]);
  90. readonly updatingDictionary = signal(false);
  91. readonly targetGradeCategoryId = signal(0);
  92. readonly targetGradeParentId = signal(0);
  93. readonly filterGradeCategoryId = signal(0);
  94. readonly filterGradeParentId = signal(0);
  95. readonly gradeCategories = signal<Record<string, unknown>[]>([]);
  96. readonly updatingGrade = signal(false);
  97. readonly updatingCurrency = signal(false);
  98. readonly updatingHoliday = signal(false);
  99. readonly filterSearchNavigationType = signal(1);
  100. readonly filterSearchNavigationState = signal(-100);
  101. readonly filterSearchNavigationElite = signal(-100);
  102. readonly searchNavigationOrderStart = signal(1);
  103. readonly updatingSearchNavigation = signal(false);
  104. readonly filterAdZoneType = signal('');
  105. readonly filterAdStatus = signal(-100);
  106. readonly filterAdInfoZoneId = signal('');
  107. readonly targetAdZoneId = signal('');
  108. readonly adZones = signal<Record<string, unknown>[]>([]);
  109. readonly adPreview = signal<Record<string, unknown>[]>([]);
  110. readonly adPreviewLoading = signal(false);
  111. readonly adPreviewError = signal('');
  112. readonly updatingAdvertisement = signal(false);
  113. readonly filterFontShapeTypeId = signal(0);
  114. readonly targetFontShapeTypeId = signal(0);
  115. readonly fontShapeTypes = signal<Record<string, unknown>[]>([]);
  116. readonly fontShapePreview = signal('');
  117. readonly updatingFontShape = signal(false);
  118. readonly filterSurveyStatus = signal(-100);
  119. readonly filterSurveyId = signal(0);
  120. readonly surveys = signal<Record<string, unknown>[]>([]);
  121. readonly surveyOrderStart = signal(1);
  122. readonly surveyChart = signal<SurveyChart | null>(null);
  123. readonly surveyChartLoading = signal(false);
  124. readonly surveyChartError = signal('');
  125. readonly updatingSurvey = signal(false);
  126. readonly targetServiceSeatUsername = signal('');
  127. readonly updatingService = signal(false);
  128. readonly filterStoreStatus = signal(-100);
  129. readonly targetStoreStyleId = signal(0);
  130. readonly targetStoreUsername = signal('');
  131. readonly storeStyles = signal<Record<string, unknown>[]>([]);
  132. readonly updatingStore = signal(false);
  133. readonly selectedIds = signal<string[]>([]);
  134. readonly bulkError = signal('');
  135. readonly bulkMessage = signal('');
  136. readonly icons = { ChevronLeft, ChevronRight, Eye, KeyRound, LoaderCircle, Pencil, Plus, RefreshCw, Search, Trash2, X };
  137. readonly columns = computed(() => {
  138. const fields = this.schema()?.fields ?? [];
  139. const preferred = ['objectId', 'name', 'title', 'qtitle', 'sName', 'storeName', 'styleName', 'str1', 'categoryname', 'dicname', 'cateName', 'gradeName', 'cClassName', 'testPoint', 'kName', 'tname', 'username', 'userName', 'realName', 'sRemrk', 'askId', 'zoneId', 'typeId', 'shape', 'qtype', 'required', 'ztype', 'priority', 'zstatus', 'storeState', 'storeCommendState', 'storeStyleId', 'sDefault', 'sIndex', 'str4', 'sdate', 'edate', 'fileUrl', 'type', 'state', 'eliteLevel', 'orderId', 'mobile', 'sourceKey', 'status', 'createdAt', 'updatedAt'];
  140. const rank = (name: string): number => { const index = preferred.indexOf(name); return index < 0 ? preferred.length : index; };
  141. return fields.map((field, index) => ({ field, index })).sort((a, b) => rank(a.field.name) - rank(b.field.name) || a.index - b.index).map(({ field }) => field).slice(0, 7);
  142. });
  143. readonly pageCount = computed(() => Math.max(1, Math.ceil((this.page()?.total ?? 0) / (this.page()?.pageSize || 20))));
  144. readonly bulkEnabled = computed(() => ['_User', 'CommonModel', 'Node', 'Special', 'Guestbook', 'GuestBar', 'Datadiccategory', 'Datadic', 'GradeCate', 'Grade', 'Currency', 'SysHoliday', 'Search', 'AdZone', 'AdInfo', 'FontPicShape', 'FontPicShapeType', 'DesignAsk', 'DesignQuestion', 'DesignAnswer', 'ServiceSeat', 'Temp', 'StoreApplication', 'StoreStyle'].includes(this.className()));
  145. readonly allPageSelected = computed(() => {
  146. const ids = (this.page()?.results || []).map((row) => String(row['objectId'] || '')).filter(Boolean);
  147. return Boolean(ids.length) && ids.every((id) => this.selectedIds().includes(id));
  148. });
  149. private readonly functions = inject(CloudFunctionsService);
  150. private readonly route = inject(ActivatedRoute);
  151. private readonly destroyRef = inject(DestroyRef);
  152. ngOnInit(): void {
  153. this.route.paramMap.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((params) => {
  154. this.className.set(params.get('className') ?? '');
  155. this.search.set('');
  156. this.filterGradeCategoryId.set(0); this.filterGradeParentId.set(0);
  157. this.filterSearchNavigationType.set(1); this.filterSearchNavigationState.set(-100); this.filterSearchNavigationElite.set(-100); this.searchNavigationOrderStart.set(1);
  158. this.filterAdZoneType.set(''); this.filterAdStatus.set(-100); this.filterAdInfoZoneId.set(''); this.resetAdActions();
  159. this.filterFontShapeTypeId.set(0); this.resetFontShapeActions();
  160. this.filterSurveyStatus.set(-100); this.filterSurveyId.set(0); this.resetSurveyActions();
  161. this.resetServiceActions();
  162. this.filterStoreStatus.set(-100); this.resetStoreActions();
  163. void this.load(1, true);
  164. });
  165. }
  166. async load(pageNumber = this.page()?.page ?? 1, reloadSchema = false): Promise<void> {
  167. this.loading.set(true); this.error.set(''); this.selectedIds.set([]); this.bulkError.set(''); this.bulkMessage.set('');
  168. try {
  169. if (reloadSchema || !this.schema()) this.schema.set(await this.functions.admin<AdminClassSchema>('schema', { className: this.className() }));
  170. if (this.className() === 'Grade' && reloadSchema) { await this.loadGradeCategories(); if (!this.filterGradeCategoryId() && this.gradeCategories().length) this.filterGradeCategoryId.set(this.gradeCategoryIdOf(this.gradeCategories()[0])); }
  171. if (this.className() === 'AdInfo' && reloadSchema) await this.loadAdZones();
  172. if (this.className() === 'FontPicShape' && reloadSchema) await this.loadFontShapeTypes();
  173. if (['DesignQuestion', 'DesignAnswer'].includes(this.className()) && reloadSchema) { await this.loadSurveys(); if (!this.filterSurveyId() && this.surveys().length) this.filterSurveyId.set(this.surveyIdOf(this.surveys()[0])); }
  174. if (this.className() === 'StoreApplication' && reloadSchema) await this.loadStoreStyles();
  175. const pageOperation = this.className() === 'Grade' && this.filterGradeCategoryId() > 0 ? 'gradeOptions' : this.className() === 'Search' ? 'searchNavigations' : this.className() === 'AdZone' ? 'adZones' : this.className() === 'AdInfo' ? 'adInfos' : this.className() === 'FontPicShape' ? 'fontShapes' : this.className() === 'FontPicShapeType' ? 'fontShapeTypes' : this.className() === 'DesignAsk' ? 'surveys' : this.className() === 'DesignQuestion' ? 'surveyQuestions' : this.className() === 'DesignAnswer' ? 'surveyResults' : this.className() === 'ServiceSeat' ? 'serviceSeats' : this.className() === 'Temp' ? 'serviceCodes' : this.className() === 'StoreApplication' ? 'storeApplications' : this.className() === 'StoreStyle' ? 'storeStyles' : 'list';
  176. const pagePayload: Record<string, unknown> = { className: this.className(), page: pageNumber, pageSize: 20, search: this.search().trim() };
  177. if (pageOperation === 'gradeOptions') { pagePayload['categoryId'] = this.filterGradeCategoryId(); pagePayload['parentId'] = this.filterGradeParentId(); }
  178. if (pageOperation === 'searchNavigations') { pagePayload['type'] = this.filterSearchNavigationType(); pagePayload['state'] = this.filterSearchNavigationState(); pagePayload['elite'] = this.filterSearchNavigationElite(); }
  179. if (pageOperation === 'adZones') { pagePayload['type'] = this.filterAdZoneType(); pagePayload['status'] = this.filterAdStatus(); }
  180. if (pageOperation === 'adInfos') { pagePayload['zoneId'] = this.filterAdInfoZoneId(); pagePayload['status'] = this.filterAdStatus(); }
  181. if (pageOperation === 'fontShapes') pagePayload['typeId'] = this.filterFontShapeTypeId();
  182. if (pageOperation === 'surveys') pagePayload['status'] = this.filterSurveyStatus();
  183. if (pageOperation === 'surveyQuestions' || pageOperation === 'surveyResults') pagePayload['askId'] = this.filterSurveyId();
  184. if (pageOperation === 'storeApplications') pagePayload['status'] = this.filterStoreStatus();
  185. this.page.set(await this.functions.admin<ResourcePage>(pageOperation, pagePayload));
  186. if (this.className() === '_User' && reloadSchema) await this.loadUserGroups();
  187. if (this.className() === 'Datadic' && reloadSchema) await this.loadDictionaryCategories();
  188. } catch (error) { this.error.set(error instanceof Error ? error.message : '数据加载失败'); }
  189. finally { this.loading.set(false); }
  190. }
  191. openCreate(): void { this.draftId.set(''); this.draft.set({}); this.fieldErrors.set({}); this.fieldInputs.set({}); this.resetPasswordFields(); this.resetCreateUserFields(); this.resetUserActions(); this.resetContentActions(); this.resetNodeActions(); this.resetSpecialActions(); this.resetGuestbookActions(); this.resetGuestCategoryActions(); this.resetBarActions(); this.resetExamClassActions(); this.resetExamPointActions(); this.resetKnowledgeActions(); this.resetTeacherActions(); this.resetDictionaryActions(); this.resetGradeActions(); this.resetAdActions(); this.resetFontShapeActions(); this.resetSurveyActions(); this.resetServiceActions(); this.resetStoreActions(); this.editorOpen.set(true); }
  192. async openEdit(row: Record<string, unknown>): Promise<void> {
  193. const objectId = String(row['objectId'] ?? '');
  194. this.error.set('');
  195. try {
  196. const detail = await this.functions.admin<Record<string, unknown>>('get', { className: this.className(), objectId });
  197. this.draftId.set(objectId); this.draft.set(detail); this.fieldErrors.set({}); this.fieldInputs.set({}); this.resetPasswordFields(); this.resetCreateUserFields(); this.resetUserActions(detail); this.resetContentActions(detail); this.resetNodeActions(detail); this.resetSpecialActions(detail); this.resetGuestbookActions(detail); this.resetGuestCategoryActions(detail); this.resetBarActions(detail); this.resetExamClassActions(detail); this.resetExamPointActions(detail); this.resetKnowledgeActions(detail); this.resetTeacherActions(detail); this.resetDictionaryActions(detail); this.resetGradeActions(detail); this.resetAdActions(detail); this.resetFontShapeActions(detail); this.resetSurveyActions(); this.resetServiceActions(detail); this.resetStoreActions(detail); this.editorOpen.set(true);
  198. if (this.className() === '_User') await this.loadUserGroups();
  199. if (this.className() === 'AdInfo' && !this.adZones().length) await this.loadAdZones();
  200. if (this.className() === 'AdZone') await this.loadAdPreview();
  201. if (this.className() === 'FontPicShape' && !this.fontShapeTypes().length) await this.loadFontShapeTypes();
  202. } catch (error) { this.error.set(error instanceof Error ? error.message : '详情加载失败'); }
  203. }
  204. closeEditor(): void { this.editorOpen.set(false); this.draft.set({}); this.draftId.set(''); this.fieldErrors.set({}); this.fieldInputs.set({}); this.resetPasswordFields(); this.resetCreateUserFields(); this.resetUserActions(); this.resetContentActions(); this.resetNodeActions(); this.resetSpecialActions(); this.resetGuestbookActions(); this.resetGuestCategoryActions(); this.resetBarActions(); this.resetExamClassActions(); this.resetExamPointActions(); this.resetKnowledgeActions(); this.resetTeacherActions(); this.resetDictionaryActions(); this.resetGradeActions(); this.resetAdActions(); this.resetFontShapeActions(); this.resetSurveyActions(); this.resetServiceActions(); this.resetStoreActions(); }
  205. setField(field: AdminFieldSchema, raw: unknown): void {
  206. let value = raw;
  207. if (field.type === 'Number') value = raw === '' ? null : Number(raw);
  208. if (field.type === 'Pointer') value = raw ? { __type: 'Pointer', className: field.targetClass, objectId: String(raw) } : null;
  209. if ((field.type === 'Object' || field.type === 'Array') && typeof raw === 'string') {
  210. this.fieldInputs.update((current) => ({ ...current, [field.name]: raw }));
  211. try {
  212. value = raw.trim() ? JSON.parse(raw) : field.type === 'Array' ? [] : {};
  213. const valid = field.type === 'Array' ? Array.isArray(value) : Boolean(value) && typeof value === 'object' && !Array.isArray(value);
  214. if (!valid) throw new Error();
  215. this.fieldErrors.update((current) => { const next = { ...current }; delete next[field.name]; return next; });
  216. } catch {
  217. this.fieldErrors.update((current) => ({ ...current, [field.name]: field.type === 'Array' ? '请输入有效的 JSON 数组' : '请输入有效的 JSON 对象' }));
  218. return;
  219. }
  220. }
  221. this.draft.update((current) => ({ ...current, [field.name]: value }));
  222. }
  223. inputValue(field: AdminFieldSchema): string | number {
  224. const value = this.draft()[field.name];
  225. if (field.type === 'Pointer') return String((value as { objectId?: string } | null)?.objectId ?? '');
  226. if (field.type === 'Date') return String((value as { iso?: string } | string | null)?.hasOwnProperty?.('iso') ? (value as { iso: string }).iso.slice(0, 16) : String(value ?? '').slice(0, 16));
  227. if (field.type === 'Object' || field.type === 'Array') return this.fieldInputs()[field.name] ?? (value == null ? '' : JSON.stringify(value, null, 2));
  228. return typeof value === 'number' ? value : String(value ?? '');
  229. }
  230. async save(): Promise<void> {
  231. const invalidFields = Object.keys(this.fieldErrors());
  232. if (invalidFields.length) { this.error.set(`请先修正字段格式:${invalidFields.join('、')}`); return; }
  233. this.saving.set(true); this.error.set('');
  234. try {
  235. const operation = this.className() === 'Group' ? 'saveGroup'
  236. : this.className() === 'Node' ? 'saveNode'
  237. : this.className() === 'Special' ? 'saveSpecial'
  238. : this.className() === 'Model' ? 'saveModelMetadata'
  239. : this.className() === 'ModelField' ? 'saveModelFieldMetadata'
  240. : this.className() === 'Guestbook' ? 'saveGuestbook'
  241. : this.className() === 'Guestcate' ? 'saveGuestCategory'
  242. : this.className() === 'ExamClass' ? 'saveExamClass'
  243. : this.className() === 'ExamPoint' ? 'saveExamPoint'
  244. : this.className() === 'QuestionsKnowledge' ? 'saveKnowledge'
  245. : this.className() === 'ExTeacher' ? 'saveExamTeacher'
  246. : this.className() === 'Datadiccategory' ? 'saveDictionaryCategory'
  247. : this.className() === 'Datadic' ? 'saveDictionaryItem'
  248. : this.className() === 'GradeCate' ? 'saveGradeCategory'
  249. : this.className() === 'Grade' ? 'saveGradeOption'
  250. : this.className() === 'Currency' ? 'saveCurrency'
  251. : this.className() === 'SysHoliday' ? 'saveHoliday'
  252. : this.className() === 'Search' ? 'saveSearchNavigation'
  253. : this.className() === 'AdZone' ? 'saveAdZone'
  254. : this.className() === 'AdInfo' ? 'saveAdInfo'
  255. : this.className() === 'FontPicShape' ? 'saveFontShape'
  256. : this.className() === 'FontPicShapeType' ? 'saveFontShapeType'
  257. : this.className() === 'DesignAsk' ? 'saveSurvey'
  258. : this.className() === 'DesignQuestion' ? 'saveSurveyQuestion'
  259. : this.className() === 'ServiceSeat' ? 'saveServiceSeat'
  260. : this.className() === 'Temp' ? 'saveServiceCode'
  261. : this.className() === 'StoreApplication' ? 'saveStoreApplication'
  262. : this.className() === 'StoreStyle' ? 'saveStoreStyle' : 'save';
  263. const payload: Record<string, unknown> = { className: this.className(), objectId: this.draftId() || undefined, fields: this.draft() };
  264. if (this.className() === 'Node') payload['parentId'] = this.targetNodeParentId();
  265. if (this.className() === 'Special') payload['pid'] = this.targetSpecialParentId();
  266. if (this.className() === 'Guestcate') { payload['gtype'] = this.guestCategoryType(); payload['parentId'] = this.targetGuestCategoryParentId(); }
  267. if (this.className() === 'ExamClass') { payload['parentId'] = this.targetExamClassParentId(); payload['classType'] = this.examClassType(); payload['orderId'] = this.examClassOrder(); }
  268. if (this.className() === 'ExamPoint') { payload['parentId'] = this.targetExamPointParentId(); payload['orderId'] = this.examPointOrder(); }
  269. if (this.className() === 'QuestionsKnowledge') { payload['classId'] = this.targetKnowledgeClassId(); payload['parentId'] = this.targetKnowledgeParentId(); payload['orderId'] = this.knowledgeOrder(); }
  270. if (this.className() === 'ExTeacher') payload['classId'] = this.targetTeacherClassId();
  271. if (this.className() === 'Datadic') payload['categoryId'] = this.targetDictionaryCategoryId();
  272. if (this.className() === 'Grade') { payload['categoryId'] = this.targetGradeCategoryId(); payload['parentId'] = this.targetGradeParentId(); }
  273. if (this.className() === 'AdInfo') payload['zoneId'] = this.targetAdZoneId();
  274. if (this.className() === 'FontPicShape') payload['typeId'] = this.targetFontShapeTypeId();
  275. if (this.className() === 'ServiceSeat') payload['username'] = this.targetServiceSeatUsername();
  276. if (this.className() === 'StoreApplication') { payload['username'] = this.targetStoreUsername(); payload['styleId'] = this.targetStoreStyleId(); }
  277. await this.functions.admin(operation, payload);
  278. this.closeEditor(); await this.load();
  279. } catch (error) { this.error.set(error instanceof Error ? error.message : '保存失败'); }
  280. finally { this.saving.set(false); }
  281. }
  282. async submitEditor(): Promise<void> {
  283. if (this.className() === '_User' && !this.draftId()) await this.createUser();
  284. else await this.save();
  285. }
  286. async createUser(): Promise<void> {
  287. const username = this.createUsername().trim();
  288. const password = this.createPassword();
  289. this.createUserError.set('');
  290. if (this.className() !== '_User' || this.draftId()) { this.createUserError.set('只能从用户管理的新建入口开户'); return; }
  291. if (username.length < 3 || username.length > 64) { this.createUserError.set('账号长度应为 3 至 64 位'); return; }
  292. if (password.length < 8 || password.length > 72) { this.createUserError.set('密码长度应为 8 至 72 位'); return; }
  293. if (password !== this.createConfirmPassword()) { this.createUserError.set('两次输入的密码不一致'); return; }
  294. const payload: Record<string, unknown> = { username, password };
  295. const displayName = this.createDisplayName().trim();
  296. const mobile = this.createMobile().trim();
  297. const inviteUsername = this.createInviteUsername().trim();
  298. if (displayName) payload['displayName'] = displayName;
  299. if (mobile) payload['mobile'] = mobile;
  300. if (inviteUsername) payload['inviteUsername'] = inviteUsername;
  301. this.saving.set(true); this.error.set('');
  302. try {
  303. await this.functions.admin('createUser', payload);
  304. this.closeEditor(); await this.load();
  305. } catch (error) { this.createUserError.set(error instanceof Error ? error.message : '用户开户失败'); }
  306. finally { this.saving.set(false); }
  307. }
  308. async resetPassword(): Promise<void> {
  309. this.passwordError.set(''); this.passwordMessage.set('');
  310. if (this.className() !== '_User' || !this.draftId()) { this.passwordError.set('只能重置现有用户密码'); return; }
  311. if (this.newPassword().length < 8) { this.passwordError.set('新密码至少 8 位'); return; }
  312. if (this.newPassword() !== this.confirmPassword()) { this.passwordError.set('两次输入的密码不一致'); return; }
  313. this.resettingPassword.set(true);
  314. try {
  315. await this.functions.admin('resetPassword', { className: '_User', objectId: this.draftId(), newPassword: this.newPassword() });
  316. this.newPassword.set(''); this.confirmPassword.set(''); this.passwordMessage.set('密码已安全重置');
  317. } catch (error) { this.passwordError.set(error instanceof Error ? error.message : '密码重置失败'); }
  318. finally { this.resettingPassword.set(false); }
  319. }
  320. async setUserDisabled(disabled: boolean): Promise<void> {
  321. this.userActionError.set(''); this.userActionMessage.set('');
  322. if (this.className() !== '_User' || !this.draftId()) { this.userActionError.set('只能管理现有用户状态'); return; }
  323. if (disabled && !confirm('确认停用该账号并撤销其全部登录会话?')) return;
  324. this.updatingUser.set(true);
  325. try {
  326. const result = await this.functions.admin<{ results: Record<string, unknown>[]; revokedSessions: number }>('userBatch', {
  327. className: '_User', action: disabled ? 'lock' : 'unlock', objectIds: [this.draftId()], reason: this.userActionReason().trim(),
  328. });
  329. if (result.results?.[0]) this.draft.set(result.results[0]);
  330. this.userActionMessage.set(disabled ? `账号已停用,撤销 ${result.revokedSessions || 0} 个会话` : '账号已恢复使用');
  331. await this.load();
  332. } catch (error) { this.userActionError.set(error instanceof Error ? error.message : '账号状态更新失败'); }
  333. finally { this.updatingUser.set(false); }
  334. }
  335. async moveUserGroup(): Promise<void> {
  336. this.userActionError.set(''); this.userActionMessage.set('');
  337. const groupId = this.selectedUserGroupId();
  338. if (this.className() !== '_User' || !this.draftId() || !Number.isInteger(groupId) || groupId < 1) { this.userActionError.set('请选择有效用户组'); return; }
  339. this.updatingUser.set(true);
  340. try {
  341. const result = await this.functions.admin<{ results: Record<string, unknown>[] }>('userBatch', { className: '_User', action: 'move', objectIds: [this.draftId()], groupId });
  342. if (result.results?.[0]) this.draft.set(result.results[0]);
  343. this.userActionMessage.set(`已移动到用户组 ${groupId}`);
  344. await this.load();
  345. } catch (error) { this.userActionError.set(error instanceof Error ? error.message : '用户组更新失败'); }
  346. finally { this.updatingUser.set(false); }
  347. }
  348. async applyContentAction(action: 'status' | 'recycle' | 'recover' | 'move'): Promise<void> {
  349. this.contentActionError.set(''); this.contentActionMessage.set('');
  350. if (this.className() !== 'CommonModel' || !this.draftId()) { this.contentActionError.set('只能管理现有内容'); return; }
  351. if (action === 'recycle' && !confirm('确认将该内容移入回收站?')) return;
  352. const payload: Record<string, unknown> = { className: 'CommonModel', action, objectIds: [this.draftId()] };
  353. if (action === 'status') {
  354. const status = this.selectedContentStatus();
  355. if (![-3, -1, 0, 99].includes(status)) { this.contentActionError.set('请选择有效内容状态'); return; }
  356. payload['status'] = status;
  357. }
  358. if (action === 'move') {
  359. const nodeId = this.targetContentNodeId();
  360. if (!Number.isInteger(nodeId) || nodeId < 1) { this.contentActionError.set('请输入有效目标节点 ID'); return; }
  361. payload['nodeId'] = nodeId;
  362. }
  363. this.updatingContent.set(true);
  364. try {
  365. const result = await this.functions.admin<{ results: Record<string, unknown>[] }>('contentBatch', payload);
  366. if (result.results?.[0]) {
  367. this.draft.set(result.results[0]);
  368. this.selectedContentStatus.set(Number(result.results[0]['status']) || 0);
  369. this.targetContentNodeId.set(Number(result.results[0]['nodeId']) || 0);
  370. }
  371. const messages = { status: `内容状态已更新为${this.contentStatusLabel(this.selectedContentStatus())}`, recycle: '内容已移入回收站', recover: '内容已恢复为待审核', move: `内容已移动到节点 ${this.targetContentNodeId()}` };
  372. this.contentActionMessage.set(messages[action]);
  373. await this.load();
  374. } catch (error) { this.contentActionError.set(error instanceof Error ? error.message : '内容操作失败'); }
  375. finally { this.updatingContent.set(false); }
  376. }
  377. toggleSelection(objectId: string, selected: boolean): void {
  378. this.selectedIds.update((current) => selected ? [...new Set([...current, objectId])] : current.filter((id) => id !== objectId));
  379. }
  380. togglePageSelection(selected: boolean): void {
  381. const pageIds = (this.page()?.results || []).map((row) => String(row['objectId'] || '')).filter(Boolean);
  382. this.selectedIds.set(selected ? pageIds : []);
  383. }
  384. isSelected(objectId: unknown): boolean { return this.selectedIds().includes(String(objectId || '')); }
  385. async applyBulkUserAction(action: 'lock' | 'unlock' | 'move'): Promise<void> {
  386. const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  387. if (this.className() !== '_User' || !objectIds.length) { this.bulkError.set('请先选择用户'); return; }
  388. if (action === 'lock' && !confirm(`确认停用选中的 ${objectIds.length} 个账号并撤销全部会话?`)) return;
  389. const payload: Record<string, unknown> = { className: '_User', action, objectIds };
  390. if (action === 'move') {
  391. const groupId = this.selectedUserGroupId();
  392. if (!Number.isInteger(groupId) || groupId < 1) { this.bulkError.set('请选择有效用户组'); return; }
  393. payload['groupId'] = groupId;
  394. } else payload['reason'] = this.userActionReason().trim();
  395. this.updatingUser.set(true);
  396. try {
  397. const result = await this.functions.admin<{ updated: number; revokedSessions: number }>('userBatch', payload);
  398. const message = action === 'lock' ? `已停用 ${result.updated} 个账号并撤销 ${result.revokedSessions || 0} 个会话` : action === 'unlock' ? `已解锁 ${result.updated} 个账号` : `已移动 ${result.updated} 个用户`;
  399. await this.load(); this.bulkMessage.set(message);
  400. } catch (error) { this.bulkError.set(error instanceof Error ? error.message : '批量用户操作失败'); }
  401. finally { this.updatingUser.set(false); }
  402. }
  403. async applyBulkContentAction(action: 'status' | 'recycle' | 'recover' | 'move'): Promise<void> {
  404. const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  405. if (this.className() !== 'CommonModel' || !objectIds.length) { this.bulkError.set('请先选择内容'); return; }
  406. if (action === 'recycle' && !confirm(`确认将选中的 ${objectIds.length} 条内容移入回收站?`)) return;
  407. const payload: Record<string, unknown> = { className: 'CommonModel', action, objectIds };
  408. if (action === 'status') {
  409. const status = this.selectedContentStatus();
  410. if (![-3, -1, 0, 99].includes(status)) { this.bulkError.set('请选择有效内容状态'); return; }
  411. payload['status'] = status;
  412. }
  413. if (action === 'move') {
  414. const nodeId = this.targetContentNodeId();
  415. if (!Number.isInteger(nodeId) || nodeId < 1) { this.bulkError.set('请输入有效目标节点 ID'); return; }
  416. payload['nodeId'] = nodeId;
  417. }
  418. this.updatingContent.set(true);
  419. try {
  420. const result = await this.functions.admin<{ updated: number }>('contentBatch', payload);
  421. const message = `已处理 ${result.updated} 条内容`; await this.load(); this.bulkMessage.set(message);
  422. } catch (error) { this.bulkError.set(error instanceof Error ? error.message : '批量内容操作失败'); }
  423. finally { this.updatingContent.set(false); }
  424. }
  425. async applyNodeAction(action: 'recycle' | 'recover' | 'move'): Promise<void> {
  426. this.nodeActionError.set(''); this.nodeActionMessage.set('');
  427. if (this.className() !== 'Node' || !this.draftId()) { this.nodeActionError.set('只能管理现有栏目'); return; }
  428. if (action === 'recycle' && !confirm('确认将该栏目移入回收站?')) return;
  429. const payload: Record<string, unknown> = { className: 'Node', action, objectIds: [this.draftId()] };
  430. if (action === 'move') {
  431. const parentId = this.targetNodeParentId();
  432. if (!Number.isInteger(parentId) || parentId < 0) { this.nodeActionError.set('请输入有效父节点 ID,顶级栏目填 0'); return; }
  433. payload['parentId'] = parentId;
  434. }
  435. this.updatingNode.set(true);
  436. try {
  437. const result = await this.functions.admin<{ results: Record<string, unknown>[] }>('nodeBatch', payload);
  438. if (result.results?.[0]) { this.draft.set(result.results[0]); this.targetNodeParentId.set(Number(result.results[0]['parentId']) || 0); }
  439. this.nodeActionMessage.set(action === 'recycle' ? '栏目已移入回收站' : action === 'recover' ? '栏目已恢复' : `栏目已移动到父节点 ${this.targetNodeParentId()}`);
  440. await this.load();
  441. } catch (error) { this.nodeActionError.set(error instanceof Error ? error.message : '栏目操作失败'); }
  442. finally { this.updatingNode.set(false); }
  443. }
  444. async applyBulkNodeAction(action: 'recycle' | 'recover' | 'move'): Promise<void> {
  445. const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  446. if (this.className() !== 'Node' || !objectIds.length) { this.bulkError.set('请先选择栏目'); return; }
  447. if (action === 'recycle' && !confirm(`确认将选中的 ${objectIds.length} 个栏目移入回收站?`)) return;
  448. const payload: Record<string, unknown> = { className: 'Node', action, objectIds };
  449. if (action === 'move') {
  450. const parentId = this.targetNodeParentId();
  451. if (!Number.isInteger(parentId) || parentId < 0) { this.bulkError.set('请输入有效父节点 ID,顶级栏目填 0'); return; }
  452. payload['parentId'] = parentId;
  453. }
  454. this.updatingNode.set(true);
  455. try {
  456. const result = await this.functions.admin<{ updated: number }>('nodeBatch', payload);
  457. await this.load(); this.bulkMessage.set(`已处理 ${result.updated} 个栏目`);
  458. } catch (error) { this.bulkError.set(error instanceof Error ? error.message : '批量栏目操作失败'); }
  459. finally { this.updatingNode.set(false); }
  460. }
  461. async moveSpecial(): Promise<void> {
  462. this.specialActionError.set(''); this.specialActionMessage.set('');
  463. const pid = this.targetSpecialParentId();
  464. if (this.className() !== 'Special' || !this.draftId() || !Number.isInteger(pid) || pid < 0) { this.specialActionError.set('请输入有效父专题 ID,顶级专题填 0'); return; }
  465. this.updatingSpecial.set(true);
  466. try {
  467. const result = await this.functions.admin<{ results: Record<string, unknown>[] }>('specialBatch', { className: 'Special', action: 'move', objectIds: [this.draftId()], pid });
  468. if (result.results?.[0]) { this.draft.set(result.results[0]); this.targetSpecialParentId.set(Number(result.results[0]['pid']) || 0); }
  469. this.specialActionMessage.set(`专题已移动到父专题 ${pid}`); await this.load();
  470. } catch (error) { this.specialActionError.set(error instanceof Error ? error.message : '专题移动失败'); }
  471. finally { this.updatingSpecial.set(false); }
  472. }
  473. async applyBulkSpecialMove(): Promise<void> {
  474. const objectIds = this.selectedIds(); const pid = this.targetSpecialParentId(); this.bulkError.set(''); this.bulkMessage.set('');
  475. if (this.className() !== 'Special' || !objectIds.length) { this.bulkError.set('请先选择专题'); return; }
  476. if (!Number.isInteger(pid) || pid < 0) { this.bulkError.set('请输入有效父专题 ID,顶级专题填 0'); return; }
  477. this.updatingSpecial.set(true);
  478. try {
  479. const result = await this.functions.admin<{ updated: number }>('specialBatch', { className: 'Special', action: 'move', objectIds, pid });
  480. await this.load(); this.bulkMessage.set(`已移动 ${result.updated} 个专题`);
  481. } catch (error) { this.bulkError.set(error instanceof Error ? error.message : '批量专题移动失败'); }
  482. finally { this.updatingSpecial.set(false); }
  483. }
  484. async applyGuestbookAction(action: 'audit' | 'unaudit' | 'recycle' | 'recover'): Promise<void> {
  485. this.guestbookActionError.set(''); this.guestbookActionMessage.set('');
  486. if (this.className() !== 'Guestbook' || !this.draftId()) { this.guestbookActionError.set('只能管理现有留言'); return; }
  487. if (action === 'recycle' && !confirm('确认将该留言移入回收站?')) return;
  488. this.updatingGuestbook.set(true);
  489. try {
  490. const result = await this.functions.admin<{ results: Record<string, unknown>[] }>('guestbookBatch', { className: 'Guestbook', action, objectIds: [this.draftId()] });
  491. if (result.results?.[0]) { this.draft.set(result.results[0]); this.selectedGuestbookStatus.set(Number(result.results[0]['status']) || 0); }
  492. this.guestbookActionMessage.set(action === 'audit' ? '留言已审核' : action === 'unaudit' ? '留言已取消审核' : action === 'recycle' ? '留言已移入回收站' : '留言已恢复'); await this.load();
  493. } catch (error) { this.guestbookActionError.set(error instanceof Error ? error.message : '留言状态更新失败'); }
  494. finally { this.updatingGuestbook.set(false); }
  495. }
  496. async replyGuestbook(): Promise<void> {
  497. this.guestbookActionError.set(''); this.guestbookActionMessage.set('');
  498. const content = this.guestbookReplyContent();
  499. if (this.className() !== 'Guestbook' || !this.draftId() || !content.trim()) { this.guestbookActionError.set('请输入回复内容'); return; }
  500. this.updatingGuestbook.set(true);
  501. try {
  502. await this.functions.admin('guestbookReply', { className: 'Guestbook', parentObjectId: this.draftId(), title: this.guestbookReplyTitle().trim(), content });
  503. this.guestbookReplyTitle.set(''); this.guestbookReplyContent.set(''); this.guestbookActionMessage.set('管理员回复已发布');
  504. } catch (error) { this.guestbookActionError.set(error instanceof Error ? error.message : '管理员回复失败'); }
  505. finally { this.updatingGuestbook.set(false); }
  506. }
  507. async applyBulkGuestbookAction(action: 'audit' | 'unaudit' | 'recycle' | 'recover'): Promise<void> {
  508. const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  509. if (this.className() !== 'Guestbook' || !objectIds.length) { this.bulkError.set('请先选择留言'); return; }
  510. if (action === 'recycle' && !confirm(`确认将选中的 ${objectIds.length} 条留言移入回收站?`)) return;
  511. this.updatingGuestbook.set(true);
  512. try {
  513. const result = await this.functions.admin<{ updated: number }>('guestbookBatch', { className: 'Guestbook', action, objectIds });
  514. await this.load(); this.bulkMessage.set(`已处理 ${result.updated} 条留言`);
  515. } catch (error) { this.bulkError.set(error instanceof Error ? error.message : '批量留言操作失败'); }
  516. finally { this.updatingGuestbook.set(false); }
  517. }
  518. async applyBarAction(action: 'audit' | 'unaudit' | 'recycle' | 'recover' | 'move' | 'top-global' | 'top-section' | 'top-undo' | 'elite' | 'elite-undo' | 'bottom' | 'bottom-undo'): Promise<void> {
  519. this.barActionError.set(''); this.barActionMessage.set('');
  520. if (this.className() !== 'GuestBar' || !this.draftId()) { this.barActionError.set('只能管理现有帖子'); return; }
  521. if (action === 'recycle' && !confirm('确认将该帖子移入回收站?')) return;
  522. const payload: Record<string, unknown> = { className: 'GuestBar', action, objectIds: [this.draftId()] };
  523. if (action === 'move') {
  524. const cateId = this.targetBarCategoryId();
  525. if (!Number.isInteger(cateId) || cateId < 1) { this.barActionError.set('请输入有效目标贴吧分类 ID'); return; }
  526. payload['cateId'] = cateId;
  527. }
  528. this.updatingBar.set(true);
  529. try {
  530. const result = await this.functions.admin<{ results: Record<string, unknown>[] }>('barBatch', payload);
  531. if (result.results?.[0]) { this.draft.set(result.results[0]); this.targetBarCategoryId.set(Number(result.results[0]['cateId']) || 0); }
  532. this.barActionMessage.set('帖子状态已更新'); await this.load();
  533. } catch (error) { this.barActionError.set(error instanceof Error ? error.message : '帖子操作失败'); }
  534. finally { this.updatingBar.set(false); }
  535. }
  536. async applyBulkBarAction(action: 'audit' | 'unaudit' | 'recycle' | 'recover' | 'move' | 'top-global' | 'top-section' | 'top-undo' | 'elite' | 'elite-undo' | 'bottom' | 'bottom-undo'): Promise<void> {
  537. const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  538. if (this.className() !== 'GuestBar' || !objectIds.length) { this.bulkError.set('请先选择帖子'); return; }
  539. if (action === 'recycle' && !confirm(`确认将选中的 ${objectIds.length} 条帖子移入回收站?`)) return;
  540. const payload: Record<string, unknown> = { className: 'GuestBar', action, objectIds };
  541. if (action === 'move') {
  542. const cateId = this.targetBarCategoryId();
  543. if (!Number.isInteger(cateId) || cateId < 1) { this.bulkError.set('请输入有效目标贴吧分类 ID'); return; }
  544. payload['cateId'] = cateId;
  545. }
  546. this.updatingBar.set(true);
  547. try { const result = await this.functions.admin<{ updated: number }>('barBatch', payload); await this.load(); this.bulkMessage.set(`已处理 ${result.updated} 条帖子`); }
  548. catch (error) { this.bulkError.set(error instanceof Error ? error.message : '批量帖子操作失败'); }
  549. finally { this.updatingBar.set(false); }
  550. }
  551. async applyBulkDictionaryAction(action: 'enable' | 'disable' | 'delete'): Promise<void> {
  552. const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  553. if (!['Datadiccategory', 'Datadic'].includes(this.className()) || !objectIds.length) { this.bulkError.set('请先选择字典记录'); return; }
  554. if (action === 'delete' && !confirm(`确认删除选中的 ${objectIds.length} 条字典记录?`)) return;
  555. this.updatingDictionary.set(true);
  556. try {
  557. const result = await this.functions.admin<{ updated: number }>('dictionaryBatch', { className: this.className(), action, objectIds });
  558. await this.load(); this.bulkMessage.set(`已处理 ${result.updated} 条字典记录`);
  559. } catch (error) { this.bulkError.set(error instanceof Error ? error.message : '批量字典操作失败'); }
  560. finally { this.updatingDictionary.set(false); }
  561. }
  562. async applyBulkGradeDelete(): Promise<void> {
  563. const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  564. if (!['GradeCate', 'Grade'].includes(this.className()) || !objectIds.length) { this.bulkError.set('请先选择多级字典记录'); return; }
  565. if (!confirm(`确认删除选中的 ${objectIds.length} 条多级字典记录?`)) return;
  566. this.updatingGrade.set(true);
  567. try { const result = await this.functions.admin<{ updated: number }>('gradeBatch', { className: this.className(), action: 'delete', objectIds }); await this.load(); this.bulkMessage.set(`已删除 ${result.updated} 条多级字典记录`); }
  568. catch (error) { this.bulkError.set(error instanceof Error ? error.message : '批量删除多级字典失败'); }
  569. finally { this.updatingGrade.set(false); }
  570. }
  571. async applyBulkCurrencyDelete(): Promise<void> {
  572. const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  573. if (this.className() !== 'Currency' || !objectIds.length) { this.bulkError.set('请先选择货币记录'); return; }
  574. if (!confirm(`确认删除选中的 ${objectIds.length} 条货币记录?`)) return;
  575. this.updatingCurrency.set(true);
  576. try { const result = await this.functions.admin<{ updated: number }>('currencyBatch', { className: 'Currency', action: 'delete', objectIds }); await this.load(); this.bulkMessage.set(`已删除 ${result.updated} 条货币记录`); }
  577. catch (error) { this.bulkError.set(error instanceof Error ? error.message : '批量删除货币失败'); }
  578. finally { this.updatingCurrency.set(false); }
  579. }
  580. async applyBulkHolidayDelete(): Promise<void> {
  581. const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  582. if (this.className() !== 'SysHoliday' || !objectIds.length) { this.bulkError.set('请先选择节假日记录'); return; }
  583. if (!confirm(`确认删除选中的 ${objectIds.length} 条节假日记录?`)) return;
  584. this.updatingHoliday.set(true);
  585. try { const result = await this.functions.admin<{ updated: number }>('holidayBatch', { className: 'SysHoliday', action: 'delete', objectIds }); await this.load(); this.bulkMessage.set(`已删除 ${result.updated} 条节假日记录`); }
  586. catch (error) { this.bulkError.set(error instanceof Error ? error.message : '批量删除节假日失败'); }
  587. finally { this.updatingHoliday.set(false); }
  588. }
  589. async applyBulkSearchNavigationAction(action: 'enable' | 'disable' | 'elite' | 'unelite' | 'order' | 'delete'): Promise<void> {
  590. const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  591. if (this.className() !== 'Search' || !objectIds.length) { this.bulkError.set('请先选择快捷入口'); return; }
  592. if (action === 'delete' && !confirm(`确认删除选中的 ${objectIds.length} 条快捷入口?`)) return;
  593. const payload: Record<string, unknown> = { className: 'Search', action, objectIds };
  594. if (action === 'order') {
  595. const start = this.searchNavigationOrderStart();
  596. if (!Number.isInteger(start) || start < 1 || start + objectIds.length - 1 > 1000000) { this.bulkError.set('请输入有效的起始排序'); return; }
  597. payload['orders'] = objectIds.map((objectId, index) => ({ objectId, orderId: start + index }));
  598. }
  599. this.updatingSearchNavigation.set(true);
  600. try { const result = await this.functions.admin<{ updated: number }>('searchNavigationBatch', payload); await this.load(); this.bulkMessage.set(`已处理 ${result.updated} 条快捷入口`); }
  601. catch (error) { this.bulkError.set(error instanceof Error ? error.message : '批量处理快捷入口失败'); }
  602. finally { this.updatingSearchNavigation.set(false); }
  603. }
  604. async applyBulkAdvertisementAction(action: 'active' | 'pause' | 'audit' | 'unaudit' | 'delete'): Promise<void> {
  605. const className = this.className(); const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  606. if (!['AdZone', 'AdInfo'].includes(className) || !objectIds.length) { this.bulkError.set('请先选择广告位或广告内容'); return; }
  607. if (action === 'delete' && !confirm(`确认删除选中的 ${objectIds.length} 条${className === 'AdZone' ? '广告位' : '广告内容'}?`)) return;
  608. if (className === 'AdZone' && !['active', 'pause', 'delete'].includes(action)) { this.bulkError.set('广告位操作无效'); return; }
  609. if (className === 'AdInfo' && !['audit', 'unaudit', 'delete'].includes(action)) { this.bulkError.set('广告内容操作无效'); return; }
  610. this.updatingAdvertisement.set(true);
  611. try {
  612. const result = await this.functions.admin<{ updated: number }>(className === 'AdZone' ? 'adZoneBatch' : 'adInfoBatch', { className, action, objectIds });
  613. await this.load(); this.bulkMessage.set(`已处理 ${result.updated} 条${className === 'AdZone' ? '广告位' : '广告内容'}`);
  614. } catch (error) { this.bulkError.set(error instanceof Error ? error.message : '广告批量操作失败'); }
  615. finally { this.updatingAdvertisement.set(false); }
  616. }
  617. async loadAdPreview(): Promise<void> {
  618. this.adPreview.set([]); this.adPreviewError.set('');
  619. if (this.className() !== 'AdZone' || !this.draftId()) return;
  620. this.adPreviewLoading.set(true);
  621. try { const result = await this.functions.admin<{ results: Record<string, unknown>[] }>('adPreview', { zoneObjectId: this.draftId() }); this.adPreview.set(result.results || []); }
  622. catch (error) { this.adPreviewError.set(error instanceof Error ? error.message : '广告位预览加载失败'); }
  623. finally { this.adPreviewLoading.set(false); }
  624. }
  625. async applyBulkFontShapeDelete(): Promise<void> {
  626. const className = this.className(); const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  627. if (!['FontPicShape', 'FontPicShapeType'].includes(className) || !objectIds.length) { this.bulkError.set('请先选择图形素材或分类'); return; }
  628. if (!confirm(`确认删除选中的 ${objectIds.length} 条${className === 'FontPicShape' ? '图形素材' : '图形分类'}?`)) return;
  629. this.updatingFontShape.set(true);
  630. try { const result = await this.functions.admin<{ updated: number }>(className === 'FontPicShape' ? 'fontShapeBatch' : 'fontShapeTypeBatch', { className, action: 'delete', objectIds }); await this.load(); this.bulkMessage.set(`已删除 ${result.updated} 条${className === 'FontPicShape' ? '图形素材' : '图形分类'}`); }
  631. catch (error) { this.bulkError.set(error instanceof Error ? error.message : '图形删除失败'); }
  632. finally { this.updatingFontShape.set(false); }
  633. }
  634. async applyBulkSurveyAction(action: 'start' | 'stop' | 'sort' | 'delete'): Promise<void> {
  635. const className = this.className(); const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  636. const allowed = className === 'DesignAsk' ? ['start', 'stop', 'delete'] : className === 'DesignQuestion' ? ['sort', 'delete'] : className === 'DesignAnswer' ? ['delete'] : [];
  637. if (!allowed.includes(action) || !objectIds.length) { this.bulkError.set('请先选择可执行该操作的问卷记录'); return; }
  638. if (action === 'delete' && !confirm(`确认删除选中的 ${objectIds.length} 条问卷记录?`)) return;
  639. const payload: Record<string, unknown> = { className, action, objectIds };
  640. if (action === 'sort') {
  641. const start = this.surveyOrderStart();
  642. if (!Number.isInteger(start) || start < 1 || start + objectIds.length - 1 > 1000000) { this.bulkError.set('请输入有效的起始排序'); return; }
  643. payload['orders'] = objectIds.map((objectId, index) => ({ objectId, orderId: start + index }));
  644. }
  645. this.updatingSurvey.set(true);
  646. try { const result = await this.functions.admin<{ updated: number }>('surveyBatch', payload); await this.load(); this.bulkMessage.set(`已处理 ${result.updated} 条问卷记录`); }
  647. catch (error) { this.bulkError.set(error instanceof Error ? error.message : '问卷批量操作失败'); }
  648. finally { this.updatingSurvey.set(false); }
  649. }
  650. async loadSurveyChart(): Promise<void> {
  651. this.surveyChart.set(null); this.surveyChartError.set('');
  652. if (this.className() !== 'DesignAnswer' || !this.filterSurveyId()) return;
  653. this.surveyChartLoading.set(true);
  654. try { this.surveyChart.set(await this.functions.admin<SurveyChart>('surveyResultChart', { askId: this.filterSurveyId() })); }
  655. catch (error) { this.surveyChartError.set(error instanceof Error ? error.message : '问卷统计加载失败'); }
  656. finally { this.surveyChartLoading.set(false); }
  657. }
  658. async applyBulkServiceDelete(): Promise<void> {
  659. const className = this.className(); const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  660. if (!['ServiceSeat', 'Temp'].includes(className) || !objectIds.length) { this.bulkError.set('请先选择客服席位或欢迎语'); return; }
  661. if (!confirm(`确认删除选中的 ${objectIds.length} 条${className === 'ServiceSeat' ? '客服席位' : '欢迎语'}?`)) return;
  662. this.updatingService.set(true);
  663. try { const result = await this.functions.admin<{ updated: number }>('serviceBatch', { className, action: 'delete', objectIds }); await this.load(); this.bulkMessage.set(`已删除 ${result.updated} 条客服记录`); }
  664. catch (error) { this.bulkError.set(error instanceof Error ? error.message : '客服记录删除失败'); }
  665. finally { this.updatingService.set(false); }
  666. }
  667. async applyBulkStoreAction(action: 'audit' | 'unaudit' | 'elite' | 'unelite' | 'delete'): Promise<void> {
  668. const className = this.className(); const objectIds = this.selectedIds(); this.bulkError.set(''); this.bulkMessage.set('');
  669. const allowed = className === 'StoreApplication' ? ['audit', 'unaudit', 'elite', 'unelite'] : className === 'StoreStyle' ? ['delete'] : [];
  670. if (!allowed.includes(action) || !objectIds.length) { this.bulkError.set(action === 'delete' && className === 'StoreApplication' ? '店铺删除因商品主表缺失而阻塞' : '请先选择可执行该操作的店铺记录'); return; }
  671. if (action === 'delete' && !confirm(`确认删除选中的 ${objectIds.length} 条店铺样式?`)) return;
  672. this.updatingStore.set(true);
  673. try { const result = await this.functions.admin<{ updated: number }>('storeBatch', { className, action, objectIds }); await this.load(); this.bulkMessage.set(`已处理 ${result.updated} 条店铺记录`); }
  674. catch (error) { this.bulkError.set(error instanceof Error ? error.message : '店铺批量操作失败'); }
  675. finally { this.updatingStore.set(false); }
  676. }
  677. async remove(row: Record<string, unknown>): Promise<void> {
  678. const objectId = String(row['objectId'] ?? '');
  679. const verb = ['CommonModel', 'Node', 'Guestbook'].includes(this.className()) ? '移入回收站' : '删除';
  680. if (!objectId || !confirm(`确认${verb} ${this.className()} / ${objectId}?`)) return;
  681. try {
  682. if (this.className() === 'Search') await this.functions.admin('searchNavigationBatch', { className: 'Search', action: 'delete', objectIds: [objectId] });
  683. else if (this.className() === 'AdZone') await this.functions.admin('adZoneBatch', { className: 'AdZone', action: 'delete', objectIds: [objectId] });
  684. else if (this.className() === 'AdInfo') await this.functions.admin('adInfoBatch', { className: 'AdInfo', action: 'delete', objectIds: [objectId] });
  685. else if (this.className() === 'FontPicShape') await this.functions.admin('fontShapeBatch', { className: 'FontPicShape', action: 'delete', objectIds: [objectId] });
  686. else if (this.className() === 'FontPicShapeType') await this.functions.admin('fontShapeTypeBatch', { className: 'FontPicShapeType', action: 'delete', objectIds: [objectId] });
  687. else if (['DesignAsk', 'DesignQuestion', 'DesignAnswer'].includes(this.className())) await this.functions.admin('surveyBatch', { className: this.className(), action: 'delete', objectIds: [objectId] });
  688. else if (['ServiceSeat', 'Temp'].includes(this.className())) await this.functions.admin('serviceBatch', { className: this.className(), action: 'delete', objectIds: [objectId] });
  689. else if (['StoreApplication', 'StoreStyle'].includes(this.className())) await this.functions.admin('storeBatch', { className: this.className(), action: 'delete', objectIds: [objectId] });
  690. else await this.functions.admin('delete', { className: this.className(), objectId });
  691. await this.load();
  692. }
  693. catch (error) { this.error.set(error instanceof Error ? error.message : '删除失败'); }
  694. }
  695. display(value: unknown): string {
  696. if (value == null || value === '') return '—';
  697. if (typeof value === 'object') {
  698. const data = value as Record<string, unknown>;
  699. return String(data['name'] ?? data['title'] ?? data['username'] ?? data['objectId'] ?? JSON.stringify(value));
  700. }
  701. return String(value);
  702. }
  703. groupIdOf(group: Record<string, unknown>): number { return Number(group['groupId']) || 0; }
  704. groupLabel(group: Record<string, unknown>): string { return `${String(group['groupName'] || group['name'] || '未命名组')}(${this.groupIdOf(group)})`; }
  705. dictionaryCategoryIdOf(category: Record<string, unknown>): number { return Number(category['diccateid']) || 0; }
  706. gradeCategoryIdOf(category: Record<string, unknown>): number { return Number(category['cateId']) || 0; }
  707. adZoneIdOf(zone: Record<string, unknown>): string { return String(zone['id'] || ''); }
  708. adZoneLabel(zone: Record<string, unknown>): string { return `${String(zone['name'] || '未命名广告位')}(${this.adZoneIdOf(zone)})`; }
  709. fontShapeTypeIdOf(type: Record<string, unknown>): number { return Number(type['id']) || 0; }
  710. fontShapeTypeLabel(type: Record<string, unknown>): string { return `${String(type['name'] || '未命名分类')}(${this.fontShapeTypeIdOf(type)})`; }
  711. surveyIdOf(survey: Record<string, unknown>): number { return Number(survey['id']) || 0; }
  712. surveyLabel(survey: Record<string, unknown>): string { return `${String(survey['title'] || '未命名问卷')}(${this.surveyIdOf(survey)})`; }
  713. storeStyleIdOf(style: Record<string, unknown>): number { return Number(style['id']) || 0; }
  714. storeStyleLabel(style: Record<string, unknown>): string { return `${String(style['styleName'] || '未命名样式')}(${this.storeStyleIdOf(style)})`; }
  715. contentStatusValue(): number { return Number(this.draft()['status']) || 0; }
  716. contentStatusLabel(status: number): string { return ({ [-3]: '草稿', [-2]: '回收站', [-1]: '未通过', 0: '待审核', 99: '已审核' } as Record<number, string>)[status] || String(status); }
  717. nodeStatusValue(): number { return Number(this.draft()['zstatus'] ?? 99); }
  718. private async loadUserGroups(): Promise<void> {
  719. try {
  720. const groups = await this.functions.admin<ResourcePage>('list', { className: 'Group', page: 1, pageSize: 100, sort: 'orderId', order: 'asc' });
  721. this.userGroups.set(groups.results);
  722. } catch (error) { this.userGroups.set([]); this.userActionError.set(error instanceof Error ? error.message : '用户组加载失败'); }
  723. }
  724. private async loadDictionaryCategories(): Promise<void> {
  725. try {
  726. const result = await this.functions.admin<{ results: Record<string, unknown>[] }>('dictionaryCategories', { enabledOnly: false });
  727. this.dictionaryCategories.set(result.results || []);
  728. } catch (error) { this.dictionaryCategories.set([]); this.error.set(error instanceof Error ? error.message : '字典分类加载失败'); }
  729. }
  730. private async loadGradeCategories(): Promise<void> {
  731. try { const result = await this.functions.admin<{ results: Record<string, unknown>[] }>('gradeCategories', {}); this.gradeCategories.set(result.results || []); }
  732. catch (error) { this.gradeCategories.set([]); this.error.set(error instanceof Error ? error.message : '多级字典分类加载失败'); }
  733. }
  734. private async loadAdZones(): Promise<void> {
  735. try { const result = await this.functions.admin<ResourcePage>('adZones', { className: 'AdZone', page: 1, pageSize: 1000, search: '', type: '', status: -100 }); this.adZones.set(result.results || []); }
  736. catch (error) { this.adZones.set([]); this.error.set(error instanceof Error ? error.message : '广告位选项加载失败'); }
  737. }
  738. private async loadFontShapeTypes(): Promise<void> {
  739. try { const result = await this.functions.admin<ResourcePage>('fontShapeTypes', { className: 'FontPicShapeType', page: 1, pageSize: 1000, search: '' }); this.fontShapeTypes.set(result.results || []); }
  740. catch (error) { this.fontShapeTypes.set([]); this.error.set(error instanceof Error ? error.message : '图形分类选项加载失败'); }
  741. }
  742. private async loadSurveys(): Promise<void> {
  743. try { const result = await this.functions.admin<ResourcePage>('surveys', { className: 'DesignAsk', page: 1, pageSize: 100, search: '', status: -100 }); this.surveys.set(result.results || []); }
  744. catch (error) { this.surveys.set([]); this.error.set(error instanceof Error ? error.message : '问卷选项加载失败'); }
  745. }
  746. private async loadStoreStyles(): Promise<void> {
  747. try { const result = await this.functions.admin<ResourcePage>('storeStyles', { className: 'StoreStyle', page: 1, pageSize: 100, search: '' }); this.storeStyles.set(result.results || []); }
  748. catch (error) { this.storeStyles.set([]); this.error.set(error instanceof Error ? error.message : '店铺样式选项加载失败'); }
  749. }
  750. private resetPasswordFields(): void { this.newPassword.set(''); this.confirmPassword.set(''); this.passwordMessage.set(''); this.passwordError.set(''); }
  751. private resetCreateUserFields(): void { this.createUsername.set(''); this.createPassword.set(''); this.createConfirmPassword.set(''); this.createDisplayName.set(''); this.createMobile.set(''); this.createInviteUsername.set(''); this.createUserError.set(''); }
  752. private resetUserActions(detail: Record<string, unknown> = {}): void { this.userGroups.set([]); this.selectedUserGroupId.set(Number(detail['legacyGroupId'] ?? (detail['legacyUserData'] as Record<string, unknown> | undefined)?.['GroupID']) || 0); this.userActionReason.set(''); this.userActionError.set(''); this.userActionMessage.set(''); }
  753. private resetContentActions(detail: Record<string, unknown> = {}): void { this.selectedContentStatus.set(Number(detail['status']) || 0); this.targetContentNodeId.set(Number(detail['nodeId']) || 0); this.contentActionError.set(''); this.contentActionMessage.set(''); }
  754. private resetNodeActions(detail: Record<string, unknown> = {}): void { this.targetNodeParentId.set(Number(detail['parentId']) || 0); this.nodeActionError.set(''); this.nodeActionMessage.set(''); }
  755. private resetSpecialActions(detail: Record<string, unknown> = {}): void { this.targetSpecialParentId.set(Number(detail['pid']) || 0); this.specialActionError.set(''); this.specialActionMessage.set(''); }
  756. private resetGuestbookActions(detail: Record<string, unknown> = {}): void { this.selectedGuestbookStatus.set(Number(detail['status'] ?? 99)); this.guestbookReplyTitle.set(''); this.guestbookReplyContent.set(''); this.guestbookActionError.set(''); this.guestbookActionMessage.set(''); }
  757. private resetGuestCategoryActions(detail: Record<string, unknown> = {}): void { this.guestCategoryType.set(Number(detail['gtype']) || 0); this.targetGuestCategoryParentId.set(Number(detail['parentId']) || 0); }
  758. private resetBarActions(detail: Record<string, unknown> = {}): void { this.targetBarCategoryId.set(Number(detail['cateId']) || 0); this.barActionError.set(''); this.barActionMessage.set(''); }
  759. private resetExamClassActions(detail: Record<string, unknown> = {}): void { this.targetExamClassParentId.set(Number(detail['cClassid']) || 0); this.examClassType.set(Number(detail['cClassType']) || 1); this.examClassOrder.set(Number(detail['cOrderBy']) || 0); }
  760. private resetExamPointActions(detail: Record<string, unknown> = {}): void { this.targetExamPointParentId.set(Number(detail['tid']) || 0); this.examPointOrder.set(Number(detail['orderBy']) || 0); }
  761. private resetKnowledgeActions(detail: Record<string, unknown> = {}): void { this.targetKnowledgeClassId.set(Number(detail['kClassId']) || 0); this.targetKnowledgeParentId.set(Number(detail['pid']) || 0); this.knowledgeOrder.set(Number(detail['kOrderBy']) || 0); }
  762. private resetTeacherActions(detail: Record<string, unknown> = {}): void { this.targetTeacherClassId.set(Number(detail['tclsss']) || 0); }
  763. private resetDictionaryActions(detail: Record<string, unknown> = {}): void { this.targetDictionaryCategoryId.set(Number(detail['diccate']) || 0); }
  764. private resetGradeActions(detail: Record<string, unknown> = {}): void { this.targetGradeCategoryId.set(Number(detail['cate']) || this.filterGradeCategoryId()); this.targetGradeParentId.set(Number(detail['parentId']) || this.filterGradeParentId()); }
  765. private resetAdActions(detail: Record<string, unknown> = {}): void { this.targetAdZoneId.set(String(detail['zoneId'] || this.filterAdInfoZoneId() || '')); this.adPreview.set([]); this.adPreviewError.set(''); this.adPreviewLoading.set(false); }
  766. private resetFontShapeActions(detail: Record<string, unknown> = {}): void { this.targetFontShapeTypeId.set(Number(detail['typeId']) || this.filterFontShapeTypeId()); this.fontShapePreview.set(String(detail['shape'] || '')); }
  767. private resetSurveyActions(): void { this.surveyOrderStart.set(1); this.surveyChart.set(null); this.surveyChartError.set(''); this.surveyChartLoading.set(false); }
  768. private resetServiceActions(detail: Record<string, unknown> = {}): void { this.targetServiceSeatUsername.set(String(detail['sRemrk'] || '')); }
  769. private resetStoreActions(detail: Record<string, unknown> = {}): void { this.targetStoreUsername.set(String(detail['userName'] || '')); this.targetStoreStyleId.set(Number(detail['storeStyleId']) || 0); }
  770. }