mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-11 18:42:54 +00:00
perf: 通过页面修改机器人资料
This commit is contained in:
parent
d828ed83a5
commit
2fcb7fb59b
@ -8,6 +8,7 @@ use App\Models\Meeting;
|
|||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\UmengAlias;
|
use App\Models\UmengAlias;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\UserBot;
|
||||||
use App\Models\UserCheckinMac;
|
use App\Models\UserCheckinMac;
|
||||||
use App\Models\UserCheckinRecord;
|
use App\Models\UserCheckinRecord;
|
||||||
use App\Models\UserDelete;
|
use App\Models\UserDelete;
|
||||||
@ -336,6 +337,7 @@ class UsersController extends AbstractController
|
|||||||
public function editdata()
|
public function editdata()
|
||||||
{
|
{
|
||||||
$user = User::auth();
|
$user = User::auth();
|
||||||
|
//
|
||||||
$data = Request::all();
|
$data = Request::all();
|
||||||
$user->checkSystem(1);
|
$user->checkSystem(1);
|
||||||
$upLdap = [];
|
$upLdap = [];
|
||||||
@ -1660,4 +1662,112 @@ class UsersController extends AbstractController
|
|||||||
'key' => $data['public_key'],
|
'key' => $data['public_key'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {get} api/users/bot/info 29. 机器人信息
|
||||||
|
*
|
||||||
|
* @apiDescription 需要token身份,获取我的机器人信息
|
||||||
|
* @apiVersion 1.0.0
|
||||||
|
* @apiGroup users
|
||||||
|
* @apiName bot__info
|
||||||
|
*
|
||||||
|
* @apiParam {Number} id 机器人ID
|
||||||
|
*
|
||||||
|
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||||
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
|
* @apiSuccess {Object} data 返回数据
|
||||||
|
*/
|
||||||
|
public function bot__info()
|
||||||
|
{
|
||||||
|
$user = User::auth();
|
||||||
|
//
|
||||||
|
$botId = intval(Request::input('id'));
|
||||||
|
$botUser = User::whereUserid($botId)->whereBot(1)->first();
|
||||||
|
if (empty($botUser)) {
|
||||||
|
return Base::retError('机器人不存在');
|
||||||
|
}
|
||||||
|
$userBot = UserBot::whereBotId($botUser->userid)->whereUserid($user->userid)->first();
|
||||||
|
if (empty($userBot)) {
|
||||||
|
return Base::retError('不是你的机器人');
|
||||||
|
}
|
||||||
|
return Base::retSuccess('success', [
|
||||||
|
'id' => $botUser->userid,
|
||||||
|
'name' => $botUser->nickname,
|
||||||
|
'avatar' => $botUser->userimg,
|
||||||
|
'clear_day' => $userBot->clear_day,
|
||||||
|
'webhook_url' => $userBot->webhook_url,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {post} api/users/bot/edit 30. 编辑机器人
|
||||||
|
*
|
||||||
|
* @apiDescription 需要token身份,编辑我的机器人信息
|
||||||
|
* @apiVersion 1.0.0
|
||||||
|
* @apiGroup users
|
||||||
|
* @apiName bot__edit
|
||||||
|
*
|
||||||
|
* @apiParam {Number} id 机器人ID
|
||||||
|
* @apiParam {String} [name] 机器人名称
|
||||||
|
* @apiParam {String} [avatar] 机器人头像
|
||||||
|
* @apiParam {Number} [clear_day] 清理天数
|
||||||
|
* @apiParam {String} [webhook_url] Webhook地址
|
||||||
|
*
|
||||||
|
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||||
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
|
* @apiSuccess {Object} data 返回数据
|
||||||
|
*/
|
||||||
|
public function bot__edit()
|
||||||
|
{
|
||||||
|
$user = User::auth();
|
||||||
|
//
|
||||||
|
$botId = intval(Request::input('id'));
|
||||||
|
$botUser = User::whereUserid($botId)->whereBot(1)->first();
|
||||||
|
if (empty($botUser)) {
|
||||||
|
return Base::retError('机器人不存在');
|
||||||
|
}
|
||||||
|
$userBot = UserBot::whereBotId($botUser->userid)->whereUserid($user->userid)->first();
|
||||||
|
if (empty($userBot)) {
|
||||||
|
return Base::retError('不是你的机器人');
|
||||||
|
}
|
||||||
|
//
|
||||||
|
$data = Request::input();
|
||||||
|
$upUser = [];
|
||||||
|
$upBot = [];
|
||||||
|
//
|
||||||
|
if (isset($data['name'])) {
|
||||||
|
$upUser['nickname'] = trim($data['name']);
|
||||||
|
}
|
||||||
|
if (isset($data['avatar'])) {
|
||||||
|
$avatar = $data['avatar'];
|
||||||
|
$avatar = $avatar ? Base::unFillUrl(is_array($avatar) ? $avatar[0]['path'] : $avatar) : '';
|
||||||
|
if (str_contains($avatar, 'avatar/')) {
|
||||||
|
$avatar = '';
|
||||||
|
}
|
||||||
|
$upUser['userimg'] = $avatar;
|
||||||
|
}
|
||||||
|
if (isset($data['clear_day'])) {
|
||||||
|
$upBot['clear_day'] = min(max(intval($data['clear_day']), 1), 999);
|
||||||
|
}
|
||||||
|
if (isset($data['webhook_url'])) {
|
||||||
|
$upBot['webhook_url'] = trim($data['webhook_url']);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
if ($upUser) {
|
||||||
|
$botUser->updateInstance($upUser);
|
||||||
|
$botUser->save();
|
||||||
|
}
|
||||||
|
if ($upBot) {
|
||||||
|
$userBot->updateInstance($upBot);
|
||||||
|
$userBot->save();
|
||||||
|
}
|
||||||
|
//
|
||||||
|
return Base::retSuccess('修改成功', [
|
||||||
|
'id' => $botUser->userid,
|
||||||
|
'name' => $botUser->nickname,
|
||||||
|
'avatar' => $botUser->userimg,
|
||||||
|
'clear_day' => $userBot->clear_day,
|
||||||
|
'webhook_url' => $userBot->webhook_url,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -149,6 +149,21 @@ class User extends AbstractModel
|
|||||||
return implode(', ', $array);
|
return implode(', ', $array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取机器人所有者
|
||||||
|
* @return int|mixed
|
||||||
|
*/
|
||||||
|
public function getBotOwner()
|
||||||
|
{
|
||||||
|
if (!$this->bot) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
$key = "BotOwner::" . $this->userid;
|
||||||
|
return Cache::remember($key, now()->addMonth(), function() {
|
||||||
|
return intval(UserBot::whereBotId($this->userid)->value('userid'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否在线
|
* 是否在线
|
||||||
* @return bool
|
* @return bool
|
||||||
|
|||||||
@ -119,7 +119,7 @@ class WebSocketDialog extends AbstractModel
|
|||||||
$basic = User::userid2basic($dialog_user->userid);
|
$basic = User::userid2basic($dialog_user->userid);
|
||||||
if ($basic) {
|
if ($basic) {
|
||||||
$this->name = $basic->nickname;
|
$this->name = $basic->nickname;
|
||||||
$this->bot = $basic->bot;
|
$this->bot = $basic->getBotOwner();
|
||||||
$this->quick_msgs = UserBot::quickMsgs($basic->email);
|
$this->quick_msgs = UserBot::quickMsgs($basic->email);
|
||||||
} else {
|
} else {
|
||||||
$this->name = 'non-existent';
|
$this->name = 'non-existent';
|
||||||
|
|||||||
@ -77,24 +77,29 @@
|
|||||||
<EDropdownItem command="searchMsg">
|
<EDropdownItem command="searchMsg">
|
||||||
<div>{{$L('搜索消息')}}</div>
|
<div>{{$L('搜索消息')}}</div>
|
||||||
</EDropdownItem>
|
</EDropdownItem>
|
||||||
<EDropdownItem v-if="dialogData.type === 'user'" command="openCreate">
|
<template v-if="dialogData.type === 'user'">
|
||||||
<div>{{$L('创建群组')}}</div>
|
<EDropdownItem v-if="dialogData.bot == userId" command="modifyNormal">
|
||||||
</EDropdownItem>
|
<div>{{$L('修改资料')}}</div>
|
||||||
|
</EDropdownItem>
|
||||||
|
<EDropdownItem command="openCreate">
|
||||||
|
<div>{{$L('创建群组')}}</div>
|
||||||
|
</EDropdownItem>
|
||||||
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<EDropdownItem command="groupInfo">
|
<EDropdownItem command="groupInfo">
|
||||||
<div>{{$L('群组设置')}}</div>
|
<div>{{$L('群组设置')}}</div>
|
||||||
</EDropdownItem>
|
</EDropdownItem>
|
||||||
<template v-if="dialogData.owner_id != userId">
|
<template v-if="dialogData.owner_id != userId">
|
||||||
<EDropdownItem v-if="dialogData.group_type === 'all' && userIsAdmin" command="avatarAdmin">
|
<EDropdownItem v-if="dialogData.group_type === 'all' && userIsAdmin" command="modifyAdmin">
|
||||||
<div>{{$L('修改头像')}}</div>
|
<div>{{$L('修改资料')}}</div>
|
||||||
</EDropdownItem>
|
</EDropdownItem>
|
||||||
<EDropdownItem command="exit">
|
<EDropdownItem command="exit">
|
||||||
<div style="color:#f00">{{$L('退出群组')}}</div>
|
<div style="color:#f00">{{$L('退出群组')}}</div>
|
||||||
</EDropdownItem>
|
</EDropdownItem>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="dialogData.group_type === 'user'">
|
<template v-else-if="dialogData.group_type === 'user'">
|
||||||
<EDropdownItem command="avatar">
|
<EDropdownItem command="modifyNormal">
|
||||||
<div>{{$L('修改头像')}}</div>
|
<div>{{$L('修改资料')}}</div>
|
||||||
</EDropdownItem>
|
</EDropdownItem>
|
||||||
<EDropdownItem command="transfer">
|
<EDropdownItem command="transfer">
|
||||||
<div>{{$L('转让群主')}}</div>
|
<div>{{$L('转让群主')}}</div>
|
||||||
@ -343,19 +348,30 @@
|
|||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<!--修改头像-->
|
<!--修改资料-->
|
||||||
<Modal
|
<Modal
|
||||||
v-model="avatarModifyShow"
|
v-model="modifyShow"
|
||||||
:title="$L('修改头像')"
|
:title="$L('修改资料')"
|
||||||
:mask-closable="false">
|
:mask-closable="false">
|
||||||
<Form :model="avatarModifyData" label-width="auto" @submit.native.prevent>
|
<Form :model="modifyData" label-width="auto" @submit.native.prevent>
|
||||||
<FormItem prop="avatar" :label="$L('群头像')">
|
<FormItem prop="avatar" :label="$L('头像')">
|
||||||
<ImgUpload v-model="avatarModifyData.avatar" :num="1" :width="512" :height="512" :whcut="1"/>
|
<ImgUpload v-model="modifyData.avatar" :num="1" :width="512" :height="512" :whcut="1"/>
|
||||||
|
</FormItem>
|
||||||
|
<FormItem v-if="typeof modifyData.name !== 'undefined'" prop="name" :label="$L('名称')">
|
||||||
|
<Input v-model="modifyData.name" :maxlength="20" />
|
||||||
|
</FormItem>
|
||||||
|
<FormItem v-if="typeof modifyData.clear_day !== 'undefined'" prop="clear_day" :label="$L('消息保留')">
|
||||||
|
<Input v-model="modifyData.clear_day" :maxlength="3" type="number">
|
||||||
|
<div slot="append">{{$L('天')}}</div>
|
||||||
|
</Input>
|
||||||
|
</FormItem>
|
||||||
|
<FormItem v-if="typeof modifyData.webhook_url !== 'undefined'" prop="webhook_url" label="Webhook">
|
||||||
|
<Input v-model="modifyData.webhook_url" :maxlength="255" />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</Form>
|
</Form>
|
||||||
<div slot="footer" class="adaption">
|
<div slot="footer" class="adaption">
|
||||||
<Button type="default" @click="avatarModifyShow=false">{{$L('取消')}}</Button>
|
<Button type="default" @click="modifyShow=false">{{$L('取消')}}</Button>
|
||||||
<Button type="primary" :loading="avatarModifyLoad > 0" @click="onAvatarModify">{{$L('保存')}}</Button>
|
<Button type="primary" :loading="modifyLoad > 0" @click="onModify">{{$L('保存')}}</Button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
@ -559,9 +575,9 @@ export default {
|
|||||||
createGroupData: {},
|
createGroupData: {},
|
||||||
createGroupLoad: 0,
|
createGroupLoad: 0,
|
||||||
|
|
||||||
avatarModifyShow: false,
|
modifyShow: false,
|
||||||
avatarModifyData: {},
|
modifyData: {},
|
||||||
avatarModifyLoad: 0,
|
modifyLoad: 0,
|
||||||
|
|
||||||
forwardShow: false,
|
forwardShow: false,
|
||||||
forwardLoad: false,
|
forwardLoad: false,
|
||||||
@ -1774,14 +1790,43 @@ export default {
|
|||||||
this.createGroupShow = true
|
this.createGroupShow = true
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "avatar":
|
case "modifyNormal":
|
||||||
this.avatarModifyData = {dialog_id: this.dialogData.id, avatar: this.dialogData.avatar}
|
this.modifyData = {
|
||||||
this.avatarModifyShow = true
|
dialog_id: this.dialogData.id,
|
||||||
|
avatar: this.dialogData.avatar,
|
||||||
|
name: this.dialogData.name
|
||||||
|
}
|
||||||
|
if (this.dialogData.type === 'user') {
|
||||||
|
// 机器人
|
||||||
|
this.modifyData = Object.assign(this.modifyData, {
|
||||||
|
userid: this.dialogData.dialog_user.userid,
|
||||||
|
avatar: this.cacheUserBasic.find(item => item.userid === this.dialogData.dialog_user.userid)?.userimg,
|
||||||
|
clear_day: 0,
|
||||||
|
webhook_url: '',
|
||||||
|
})
|
||||||
|
this.modifyLoad++;
|
||||||
|
this.$store.dispatch("call", {
|
||||||
|
url: 'users/bot/info',
|
||||||
|
data: {
|
||||||
|
id: this.dialogData.dialog_user.userid
|
||||||
|
},
|
||||||
|
}).then(({data}) => {
|
||||||
|
this.modifyData.clear_day = data.clear_day
|
||||||
|
this.modifyData.webhook_url = data.webhook_url
|
||||||
|
}).finally(() => {
|
||||||
|
this.modifyLoad--;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.modifyShow = true
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "avatarAdmin":
|
case "modifyAdmin":
|
||||||
this.avatarModifyData = {dialog_id: this.dialogData.id, avatar: this.dialogData.avatar, admin: 1}
|
this.modifyData = {
|
||||||
this.avatarModifyShow = true
|
dialog_id: this.dialogData.id,
|
||||||
|
avatar: this.dialogData.avatar,
|
||||||
|
admin: 1
|
||||||
|
}
|
||||||
|
this.modifyShow = true
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "groupInfo":
|
case "groupInfo":
|
||||||
@ -1899,21 +1944,55 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onAvatarModify() {
|
onModify() {
|
||||||
this.avatarModifyLoad++;
|
if (this.modifyData.userid) {
|
||||||
this.$store.dispatch("call", {
|
// 个人头像(机器人)
|
||||||
url: 'dialog/group/edit',
|
this.modifyLoad++;
|
||||||
data: this.avatarModifyData
|
this.$store.dispatch("call", {
|
||||||
}).then(({data, msg}) => {
|
url: 'users/bot/edit',
|
||||||
$A.messageSuccess(msg);
|
data: {
|
||||||
this.avatarModifyShow = false;
|
id: this.modifyData.userid,
|
||||||
this.avatarModifyData = {};
|
avatar: this.modifyData.avatar,
|
||||||
this.$store.dispatch("saveDialog", data);
|
name: this.modifyData.name,
|
||||||
}).catch(({msg}) => {
|
clear_day: this.modifyData.clear_day,
|
||||||
$A.modalError(msg);
|
webhook_url: this.modifyData.webhook_url,
|
||||||
}).finally(_ => {
|
},
|
||||||
this.avatarModifyLoad--;
|
method: 'post'
|
||||||
});
|
}).then(({data, msg}) => {
|
||||||
|
$A.messageSuccess(msg);
|
||||||
|
this.$store.dispatch("saveUserBasic", {
|
||||||
|
userid: this.modifyData.userid,
|
||||||
|
nickname: data.name,
|
||||||
|
userimg: data.avatar,
|
||||||
|
});
|
||||||
|
this.$store.dispatch("saveDialog", {
|
||||||
|
id: this.modifyData.dialog_id,
|
||||||
|
name: data.name
|
||||||
|
});
|
||||||
|
this.modifyShow = false;
|
||||||
|
this.modifyData = {};
|
||||||
|
}).catch(({msg}) => {
|
||||||
|
$A.modalError(msg);
|
||||||
|
}).finally(_ => {
|
||||||
|
this.modifyLoad--;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 群组头像
|
||||||
|
this.modifyLoad++;
|
||||||
|
this.$store.dispatch("call", {
|
||||||
|
url: 'dialog/group/edit',
|
||||||
|
data: this.modifyData
|
||||||
|
}).then(({data, msg}) => {
|
||||||
|
$A.messageSuccess(msg);
|
||||||
|
this.$store.dispatch("saveDialog", data);
|
||||||
|
this.modifyShow = false;
|
||||||
|
this.modifyData = {};
|
||||||
|
}).catch(({msg}) => {
|
||||||
|
$A.modalError(msg);
|
||||||
|
}).finally(_ => {
|
||||||
|
this.modifyLoad--;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onForward(type) {
|
onForward(type) {
|
||||||
|
|||||||
1
resources/assets/js/store/actions.js
vendored
1
resources/assets/js/store/actions.js
vendored
@ -131,6 +131,7 @@ export default {
|
|||||||
'users/editpass',
|
'users/editpass',
|
||||||
'users/operation',
|
'users/operation',
|
||||||
'users/delete/account',
|
'users/delete/account',
|
||||||
|
'users/bot/*',
|
||||||
'dialog/msg/*',
|
'dialog/msg/*',
|
||||||
], true)) {
|
], true)) {
|
||||||
params.encrypt = true
|
params.encrypt = true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user