|
@@ -33,6 +33,13 @@ export class AdminResourceComponent implements OnInit {
|
|
|
readonly confirmPassword = signal('');
|
|
readonly confirmPassword = signal('');
|
|
|
readonly passwordMessage = signal('');
|
|
readonly passwordMessage = signal('');
|
|
|
readonly passwordError = signal('');
|
|
readonly passwordError = signal('');
|
|
|
|
|
+ readonly createUsername = signal('');
|
|
|
|
|
+ readonly createPassword = signal('');
|
|
|
|
|
+ readonly createConfirmPassword = signal('');
|
|
|
|
|
+ readonly createDisplayName = signal('');
|
|
|
|
|
+ readonly createMobile = signal('');
|
|
|
|
|
+ readonly createInviteUsername = signal('');
|
|
|
|
|
+ readonly createUserError = signal('');
|
|
|
readonly icons = { ChevronLeft, ChevronRight, Eye, KeyRound, LoaderCircle, Pencil, Plus, RefreshCw, Search, Trash2, X };
|
|
readonly icons = { ChevronLeft, ChevronRight, Eye, KeyRound, LoaderCircle, Pencil, Plus, RefreshCw, Search, Trash2, X };
|
|
|
readonly columns = computed(() => {
|
|
readonly columns = computed(() => {
|
|
|
const fields = this.schema()?.fields ?? [];
|
|
const fields = this.schema()?.fields ?? [];
|
|
@@ -62,16 +69,16 @@ export class AdminResourceComponent implements OnInit {
|
|
|
finally { this.loading.set(false); }
|
|
finally { this.loading.set(false); }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- openCreate(): void { this.draftId.set(''); this.draft.set({}); this.fieldErrors.set({}); this.fieldInputs.set({}); this.resetPasswordFields(); this.editorOpen.set(true); }
|
|
|
|
|
|
|
+ openCreate(): void { this.draftId.set(''); this.draft.set({}); this.fieldErrors.set({}); this.fieldInputs.set({}); this.resetPasswordFields(); this.resetCreateUserFields(); this.editorOpen.set(true); }
|
|
|
async openEdit(row: Record<string, unknown>): Promise<void> {
|
|
async openEdit(row: Record<string, unknown>): Promise<void> {
|
|
|
const objectId = String(row['objectId'] ?? '');
|
|
const objectId = String(row['objectId'] ?? '');
|
|
|
this.error.set('');
|
|
this.error.set('');
|
|
|
try {
|
|
try {
|
|
|
const detail = await this.functions.admin<Record<string, unknown>>('get', { className: this.className(), objectId });
|
|
const detail = await this.functions.admin<Record<string, unknown>>('get', { className: this.className(), objectId });
|
|
|
- this.draftId.set(objectId); this.draft.set(detail); this.fieldErrors.set({}); this.fieldInputs.set({}); this.resetPasswordFields(); this.editorOpen.set(true);
|
|
|
|
|
|
|
+ this.draftId.set(objectId); this.draft.set(detail); this.fieldErrors.set({}); this.fieldInputs.set({}); this.resetPasswordFields(); this.resetCreateUserFields(); this.editorOpen.set(true);
|
|
|
} catch (error) { this.error.set(error instanceof Error ? error.message : '详情加载失败'); }
|
|
} catch (error) { this.error.set(error instanceof Error ? error.message : '详情加载失败'); }
|
|
|
}
|
|
}
|
|
|
- closeEditor(): void { this.editorOpen.set(false); this.draft.set({}); this.draftId.set(''); this.fieldErrors.set({}); this.fieldInputs.set({}); this.resetPasswordFields(); }
|
|
|
|
|
|
|
+ closeEditor(): void { this.editorOpen.set(false); this.draft.set({}); this.draftId.set(''); this.fieldErrors.set({}); this.fieldInputs.set({}); this.resetPasswordFields(); this.resetCreateUserFields(); }
|
|
|
setField(field: AdminFieldSchema, raw: unknown): void {
|
|
setField(field: AdminFieldSchema, raw: unknown): void {
|
|
|
let value = raw;
|
|
let value = raw;
|
|
|
if (field.type === 'Number') value = raw === '' ? null : Number(raw);
|
|
if (field.type === 'Number') value = raw === '' ? null : Number(raw);
|
|
@@ -107,6 +114,32 @@ export class AdminResourceComponent implements OnInit {
|
|
|
} catch (error) { this.error.set(error instanceof Error ? error.message : '保存失败'); }
|
|
} catch (error) { this.error.set(error instanceof Error ? error.message : '保存失败'); }
|
|
|
finally { this.saving.set(false); }
|
|
finally { this.saving.set(false); }
|
|
|
}
|
|
}
|
|
|
|
|
+ async submitEditor(): Promise<void> {
|
|
|
|
|
+ if (this.className() === '_User' && !this.draftId()) await this.createUser();
|
|
|
|
|
+ else await this.save();
|
|
|
|
|
+ }
|
|
|
|
|
+ async createUser(): Promise<void> {
|
|
|
|
|
+ const username = this.createUsername().trim();
|
|
|
|
|
+ const password = this.createPassword();
|
|
|
|
|
+ this.createUserError.set('');
|
|
|
|
|
+ if (this.className() !== '_User' || this.draftId()) { this.createUserError.set('只能从用户管理的新建入口开户'); return; }
|
|
|
|
|
+ if (username.length < 3 || username.length > 64) { this.createUserError.set('账号长度应为 3 至 64 位'); return; }
|
|
|
|
|
+ if (password.length < 8 || password.length > 72) { this.createUserError.set('密码长度应为 8 至 72 位'); return; }
|
|
|
|
|
+ if (password !== this.createConfirmPassword()) { this.createUserError.set('两次输入的密码不一致'); return; }
|
|
|
|
|
+ const payload: Record<string, unknown> = { username, password };
|
|
|
|
|
+ const displayName = this.createDisplayName().trim();
|
|
|
|
|
+ const mobile = this.createMobile().trim();
|
|
|
|
|
+ const inviteUsername = this.createInviteUsername().trim();
|
|
|
|
|
+ if (displayName) payload['displayName'] = displayName;
|
|
|
|
|
+ if (mobile) payload['mobile'] = mobile;
|
|
|
|
|
+ if (inviteUsername) payload['inviteUsername'] = inviteUsername;
|
|
|
|
|
+ this.saving.set(true); this.error.set('');
|
|
|
|
|
+ try {
|
|
|
|
|
+ await this.functions.admin('createUser', payload);
|
|
|
|
|
+ this.closeEditor(); await this.load();
|
|
|
|
|
+ } catch (error) { this.createUserError.set(error instanceof Error ? error.message : '用户开户失败'); }
|
|
|
|
|
+ finally { this.saving.set(false); }
|
|
|
|
|
+ }
|
|
|
async resetPassword(): Promise<void> {
|
|
async resetPassword(): Promise<void> {
|
|
|
this.passwordError.set(''); this.passwordMessage.set('');
|
|
this.passwordError.set(''); this.passwordMessage.set('');
|
|
|
if (this.className() !== '_User' || !this.draftId()) { this.passwordError.set('只能重置现有用户密码'); return; }
|
|
if (this.className() !== '_User' || !this.draftId()) { this.passwordError.set('只能重置现有用户密码'); return; }
|
|
@@ -134,4 +167,5 @@ export class AdminResourceComponent implements OnInit {
|
|
|
return String(value);
|
|
return String(value);
|
|
|
}
|
|
}
|
|
|
private resetPasswordFields(): void { this.newPassword.set(''); this.confirmPassword.set(''); this.passwordMessage.set(''); this.passwordError.set(''); }
|
|
private resetPasswordFields(): void { this.newPassword.set(''); this.confirmPassword.set(''); this.passwordMessage.set(''); this.passwordError.set(''); }
|
|
|
|
|
+ private resetCreateUserFields(): void { this.createUsername.set(''); this.createPassword.set(''); this.createConfirmPassword.set(''); this.createDisplayName.set(''); this.createMobile.set(''); this.createInviteUsername.set(''); this.createUserError.set(''); }
|
|
|
}
|
|
}
|