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\UmengAlias;
|
||||
use App\Models\User;
|
||||
use App\Models\UserBot;
|
||||
use App\Models\UserCheckinMac;
|
||||
use App\Models\UserCheckinRecord;
|
||||
use App\Models\UserDelete;
|
||||
@ -336,6 +337,7 @@ class UsersController extends AbstractController
|
||||
public function editdata()
|
||||
{
|
||||
$user = User::auth();
|
||||
//
|
||||
$data = Request::all();
|
||||
$user->checkSystem(1);
|
||||
$upLdap = [];
|
||||
@ -1660,4 +1662,112 @@ class UsersController extends AbstractController
|
||||
'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 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
|
||||
|
||||
@ -119,7 +119,7 @@ class WebSocketDialog extends AbstractModel
|
||||
$basic = User::userid2basic($dialog_user->userid);
|
||||
if ($basic) {
|
||||
$this->name = $basic->nickname;
|
||||
$this->bot = $basic->bot;
|
||||
$this->bot = $basic->getBotOwner();
|
||||
$this->quick_msgs = UserBot::quickMsgs($basic->email);
|
||||
} else {
|
||||
$this->name = 'non-existent';
|
||||
|
||||
@ -77,24 +77,29 @@
|
||||
<EDropdownItem command="searchMsg">
|
||||
<div>{{$L('搜索消息')}}</div>
|
||||
</EDropdownItem>
|
||||
<EDropdownItem v-if="dialogData.type === 'user'" command="openCreate">
|
||||
<div>{{$L('创建群组')}}</div>
|
||||
</EDropdownItem>
|
||||
<template v-if="dialogData.type === 'user'">
|
||||
<EDropdownItem v-if="dialogData.bot == userId" command="modifyNormal">
|
||||
<div>{{$L('修改资料')}}</div>
|
||||
</EDropdownItem>
|
||||
<EDropdownItem command="openCreate">
|
||||
<div>{{$L('创建群组')}}</div>
|
||||
</EDropdownItem>
|
||||
</template>
|
||||
<template v-else>
|
||||
<EDropdownItem command="groupInfo">
|
||||
<div>{{$L('群组设置')}}</div>
|
||||
</EDropdownItem>
|
||||
<template v-if="dialogData.owner_id != userId">
|
||||
<EDropdownItem v-if="dialogData.group_type === 'all' && userIsAdmin" command="avatarAdmin">
|
||||
<div>{{$L('修改头像')}}</div>
|
||||
<EDropdownItem v-if="dialogData.group_type === 'all' && userIsAdmin" command="modifyAdmin">
|
||||
<div>{{$L('修改资料')}}</div>
|
||||
</EDropdownItem>
|
||||
<EDropdownItem command="exit">
|
||||
<div style="color:#f00">{{$L('退出群组')}}</div>
|
||||
</EDropdownItem>
|
||||
</template>
|
||||
<template v-else-if="dialogData.group_type === 'user'">
|
||||
<EDropdownItem command="avatar">
|
||||
<div>{{$L('修改头像')}}</div>
|
||||
<EDropdownItem command="modifyNormal">
|
||||
<div>{{$L('修改资料')}}</div>
|
||||
</EDropdownItem>
|
||||
<EDropdownItem command="transfer">
|
||||
<div>{{$L('转让群主')}}</div>
|
||||
@ -343,19 +348,30 @@
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
<!--修改头像-->
|
||||
<!--修改资料-->
|
||||
<Modal
|
||||
v-model="avatarModifyShow"
|
||||
:title="$L('修改头像')"
|
||||
v-model="modifyShow"
|
||||
:title="$L('修改资料')"
|
||||
:mask-closable="false">
|
||||
<Form :model="avatarModifyData" label-width="auto" @submit.native.prevent>
|
||||
<FormItem prop="avatar" :label="$L('群头像')">
|
||||
<ImgUpload v-model="avatarModifyData.avatar" :num="1" :width="512" :height="512" :whcut="1"/>
|
||||
<Form :model="modifyData" label-width="auto" @submit.native.prevent>
|
||||
<FormItem prop="avatar" :label="$L('头像')">
|
||||
<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>
|
||||
</Form>
|
||||
<div slot="footer" class="adaption">
|
||||
<Button type="default" @click="avatarModifyShow=false">{{$L('取消')}}</Button>
|
||||
<Button type="primary" :loading="avatarModifyLoad > 0" @click="onAvatarModify">{{$L('保存')}}</Button>
|
||||
<Button type="default" @click="modifyShow=false">{{$L('取消')}}</Button>
|
||||
<Button type="primary" :loading="modifyLoad > 0" @click="onModify">{{$L('保存')}}</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
@ -559,9 +575,9 @@ export default {
|
||||
createGroupData: {},
|
||||
createGroupLoad: 0,
|
||||
|
||||
avatarModifyShow: false,
|
||||
avatarModifyData: {},
|
||||
avatarModifyLoad: 0,
|
||||
modifyShow: false,
|
||||
modifyData: {},
|
||||
modifyLoad: 0,
|
||||
|
||||
forwardShow: false,
|
||||
forwardLoad: false,
|
||||
@ -1774,14 +1790,43 @@ export default {
|
||||
this.createGroupShow = true
|
||||
break;
|
||||
|
||||
case "avatar":
|
||||
this.avatarModifyData = {dialog_id: this.dialogData.id, avatar: this.dialogData.avatar}
|
||||
this.avatarModifyShow = true
|
||||
case "modifyNormal":
|
||||
this.modifyData = {
|
||||
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;
|
||||
|
||||
case "avatarAdmin":
|
||||
this.avatarModifyData = {dialog_id: this.dialogData.id, avatar: this.dialogData.avatar, admin: 1}
|
||||
this.avatarModifyShow = true
|
||||
case "modifyAdmin":
|
||||
this.modifyData = {
|
||||
dialog_id: this.dialogData.id,
|
||||
avatar: this.dialogData.avatar,
|
||||
admin: 1
|
||||
}
|
||||
this.modifyShow = true
|
||||
break;
|
||||
|
||||
case "groupInfo":
|
||||
@ -1899,21 +1944,55 @@ export default {
|
||||
});
|
||||
},
|
||||
|
||||
onAvatarModify() {
|
||||
this.avatarModifyLoad++;
|
||||
this.$store.dispatch("call", {
|
||||
url: 'dialog/group/edit',
|
||||
data: this.avatarModifyData
|
||||
}).then(({data, msg}) => {
|
||||
$A.messageSuccess(msg);
|
||||
this.avatarModifyShow = false;
|
||||
this.avatarModifyData = {};
|
||||
this.$store.dispatch("saveDialog", data);
|
||||
}).catch(({msg}) => {
|
||||
$A.modalError(msg);
|
||||
}).finally(_ => {
|
||||
this.avatarModifyLoad--;
|
||||
});
|
||||
onModify() {
|
||||
if (this.modifyData.userid) {
|
||||
// 个人头像(机器人)
|
||||
this.modifyLoad++;
|
||||
this.$store.dispatch("call", {
|
||||
url: 'users/bot/edit',
|
||||
data: {
|
||||
id: this.modifyData.userid,
|
||||
avatar: this.modifyData.avatar,
|
||||
name: this.modifyData.name,
|
||||
clear_day: this.modifyData.clear_day,
|
||||
webhook_url: this.modifyData.webhook_url,
|
||||
},
|
||||
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) {
|
||||
|
||||
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/operation',
|
||||
'users/delete/account',
|
||||
'users/bot/*',
|
||||
'dialog/msg/*',
|
||||
], true)) {
|
||||
params.encrypt = true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user