feat(admin): 添加用户管理相关文件

添加用户管理视图、API和状态管理文件
This commit is contained in:
张翔
2026-03-28 14:37:29 +08:00
commit 08ea5fbe98
1643 changed files with 255646 additions and 0 deletions
@@ -0,0 +1,96 @@
import { Page, Locator } from '@playwright/test'
export class FormHelper {
private page: Page
constructor(page: Page) {
this.page = page
}
async fillInput(selector: string, value: string, options?: { clear?: boolean; delay?: number }) {
const input = this.page.locator(selector)
if (options?.clear) {
await input.clear()
}
await input.fill(value, { delay: options?.delay })
}
async selectOption(selector: string, value: string) {
const select = this.page.locator(selector)
await select.selectOption(value)
}
async checkCheckbox(selector: string) {
const checkbox = this.page.locator(selector)
await checkbox.check()
}
async uncheckCheckbox(selector: string) {
const checkbox = this.page.locator(selector)
await checkbox.uncheck()
}
async selectRadio(selector: string, value: string) {
const radio = this.page.locator(`${selector}[value="${value}"]`)
await radio.check()
}
async uploadFile(selector: string, filePath: string) {
const input = this.page.locator(selector)
await input.setInputFiles(filePath)
}
async submitForm(selector: string) {
const form = this.page.locator(selector)
await form.evaluate((form: HTMLFormElement) => form.submit())
}
async resetForm(selector: string) {
const form = this.page.locator(selector)
await form.evaluate((form: HTMLFormElement) => form.reset())
}
async getFieldValue(selector: string): Promise<string> {
const field = this.page.locator(selector)
return await field.inputValue()
}
async isFieldValid(selector: string): Promise<boolean> {
const field = this.page.locator(selector)
const isValid = await field.evaluate((el: HTMLInputElement) => el.checkValidity())
return isValid
}
async getValidationMessage(selector: string): Promise<string> {
const field = this.page.locator(selector)
return await field.evaluate((el: HTMLInputElement) => el.validationMessage)
}
async waitForFormToBeReady(selector: string, timeout: number = 5000) {
await this.page.waitForSelector(selector, { state: 'visible', timeout })
await this.page.waitForLoadState('networkidle', { timeout })
}
async fillForm(fields: Array<{ selector: string; value: string; type?: 'input' | 'select' | 'checkbox' }>) {
for (const field of fields) {
switch (field.type) {
case 'select':
await this.selectOption(field.selector, field.value)
break
case 'checkbox':
if (field.value === 'true' || field.value === 'checked') {
await this.checkCheckbox(field.selector)
} else {
await this.uncheckCheckbox(field.selector)
}
break
default:
await this.fillInput(field.selector, field.value)
}
}
}
}
export default FormHelper