后台添加手机用户

This commit is contained in:
chenbo 2024-01-03 11:34:01 +08:00
parent 27b695a965
commit 2a468004e0
3 changed files with 86 additions and 2 deletions

View File

@ -19,3 +19,8 @@ export function userEdit(params: any) {
export function adjustMoney(params: any) {
return request.post({ url: '/user.user/adjustMoney', params })
}
//添加用户
export function addUser(params: any) {
return request.post({ url: '/user.user/add', params })
}

View File

@ -30,6 +30,7 @@
<el-form-item>
<el-button type="primary" @click="resetPage">查询</el-button>
<el-button @click="resetParams">重置</el-button>
<el-button @click="dialogFormVisible=true">创建</el-button>
</el-form-item>
</el-form>
</el-card>
@ -81,12 +82,34 @@
<pagination v-model="pager" @change="getLists" />
</div>
</el-card>
<el-dialog v-model="dialogFormVisible" title="添加用户" width="30%">
<el-form :model="form">
<el-form-item label="手机号">
<el-input v-model="form.mobile" autocomplete="off" />
<span>
<el-icon><Pointer /></el-icon>
初始密码:123456
</span>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogFormVisible = false">取消</el-button>
<el-button type="primary" @click="addUser">
确定
</el-button>
</span>
</template>
</el-dialog>
</div>
</template>
<script lang="ts" setup name="consumerLists">
import { usePaging } from '@/hooks/usePaging'
import { getRoutePath } from '@/router'
import { getUserList } from '@/api/consumer'
import { getUserList, addUser as addUserApi } from '@/api/consumer'
import { ElMessage } from 'element-plus'
import { ClientMap } from '@/enums/appEnums'
const queryParams = reactive({
keyword: '',
@ -102,6 +125,18 @@ const { pager, getLists, resetPage, resetParams } = usePaging({
onActivated(() => {
getLists()
})
const dialogFormVisible = ref(false)
const form = reactive({
"mobile": ""
})
const addUser = () => {
addUserApi(form)
ElMessage({
message: '用户添加成功',
type: 'success',
})
dialogFormVisible.value = false
getLists()
}
getLists()
</script>

View File

@ -18,6 +18,13 @@ use app\adminapi\lists\user\UserLists;
use app\adminapi\logic\user\UserLogic;
use app\adminapi\validate\user\AdjustUserMoney;
use app\adminapi\validate\user\UserValidate;
use app\api\validate\LoginAccountValidate;
use app\common\model\auth\Admin;
use app\common\model\auth\AdminRole;
use app\common\model\user\User;
use app\common\service\ConfigService;
use think\facade\Config;
use think\facade\Db;
/**
* 用户控制器
@ -38,6 +45,43 @@ class UserController extends BaseAdminController
return $this->dataLists(new UserLists());
}
public function add()
{
try {
$params = $this->request->param();
$userSn = User::createUserSn();
$passwordSalt = Config::get('project.unique_identification');
$password = create_password(123456, $passwordSalt);
$avatar = ConfigService::get('default_image', 'user_avatar');
Db::transaction(function () use($userSn,$password,$avatar,$params) {
$user = User::create([
'sn' => $userSn,
'avatar' => env('project.project_url').'/'.$avatar,
'nickname' => '用户' . $userSn,
'account' => $params['mobile'],
'mobile' => $params['mobile'],
'password' => $password,
'channel' => 6,
]);
$admin = Admin::create([
'user_id' => $user->id,
'name' => '用户' . $userSn,
'avatar' => env('project.project_url').'/'.$avatar,
'account' => $params['mobile'],
'password' => $password
]);
AdminRole::create([
'admin_id' => $admin->id,
'role_id' => 1
]);
});
return $this->success();
} catch (\Exception $e) {
return $this->fail($e->getMessage());
}
}
public function datas()
{
$datas = (new UserLogic())->datas(input(''));