新增曾用名

This commit is contained in:
pllx
2026-05-19 18:01:47 +08:00
parent 74e4803bc2
commit 3c7cefe447
7 changed files with 47 additions and 4 deletions
+1
View File
@@ -85,6 +85,7 @@ class UserController extends Controller
$activePosition = $targetUser->activePosition?->load('position.department')->position; $activePosition = $targetUser->activePosition?->load('position.department')->position;
$data = [ $data = [
'username' => $targetUser->username, 'username' => $targetUser->username,
'previous_name' => $targetUser->previous_name,
'sex' => match ((int) $targetUser->sex) { 'sex' => match ((int) $targetUser->sex) {
1 => '男', 2 => '女', default => '' 1 => '男', 2 => '女', default => ''
}, },
@@ -31,6 +31,7 @@ class UpdateProfileRequest extends FormRequest
public function rules(): array public function rules(): array
{ {
return [ return [
'previous_name' => ['nullable', 'string', 'max:50'],
'sex' => ['required', 'in:0,1,2'], 'sex' => ['required', 'in:0,1,2'],
'headface' => ['required', 'string', 'max:50'], // 比如存放 01.gif - 50.gif 'headface' => ['required', 'string', 'max:50'], // 比如存放 01.gif - 50.gif
'sign' => ['nullable', 'string', 'max:255'], 'sign' => ['nullable', 'string', 'max:255'],
+1
View File
@@ -45,6 +45,7 @@ class User extends Authenticatable
*/ */
protected $fillable = [ protected $fillable = [
'username', 'username',
'previous_name',
'password', 'password',
'email', 'email',
'sex', 'sex',
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('previous_name', 50)->nullable()->after('username')->comment('曾用名');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('previous_name');
});
}
};
@@ -345,6 +345,7 @@ export async function savePassword() {
*/ */
export async function saveSettings() { export async function saveSettings() {
const profileData = { const profileData = {
previous_name: element("set-previous-name").value || "",
sex: element("set-sex").value, sex: element("set-sex").value,
email: element("set-email").value, email: element("set-email").value,
email_code: element("set-email-code")?.value || "", email_code: element("set-email-code")?.value || "",
@@ -128,6 +128,12 @@
<div style="margin-bottom:16px; border:1px solid #e0e0e0; border-radius:6px; padding:12px;"> <div style="margin-bottom:16px; border:1px solid #e0e0e0; border-radius:6px; padding:12px;">
<div style="font-size:12px; font-weight:bold; color:#336699; margin-bottom:8px;">👤 个人资料</div> <div style="font-size:12px; font-weight:bold; color:#336699; margin-bottom:8px;">👤 个人资料</div>
<div style="display:flex; flex-direction:column; gap:6px;"> <div style="display:flex; flex-direction:column; gap:6px;">
<div style="display:flex; align-items:center; gap:8px;">
<label style="font-size:12px; width:50px; text-align:right;">曾用名:</label>
<input id="set-previous-name" type="text" value="{{ Auth::user()->previous_name ?? '' }}"
placeholder="设置曾用名(选填)"
style="flex:1; padding:5px; border:1px solid #ccc; border-radius:4px; font-size:12px;">
</div>
<div style="display:flex; align-items:center; gap:8px;"> <div style="display:flex; align-items:center; gap:8px;">
<label style="font-size:12px; width:50px; text-align:right;">性别:</label> <label style="font-size:12px; width:50px; text-align:right;">性别:</label>
<select id="set-sex" <select id="set-sex"
@@ -45,6 +45,11 @@
<div class="profile-info"> <div class="profile-info">
<h4> <h4>
<span x-text="userInfo.username"></span> <span x-text="userInfo.username"></span>
<template x-if="userInfo.previous_name">
<span style="font-size:11px; color:#999; font-weight:normal; margin-left:6px;">
(曾用名: <span x-text="userInfo.previous_name"></span>)
</span>
</template>
<span class="level-badge" x-text="'LV.' + userInfo.user_level"></span> <span class="level-badge" x-text="'LV.' + userInfo.user_level"></span>
<span class="sex-badge" <span class="sex-badge"
x-text="userInfo.sex === '男' ? '♂' : (userInfo.sex === '女' ? '♀' : '')" x-text="userInfo.sex === '男' ? '♂' : (userInfo.sex === '女' ? '♀' : '')"