mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-17 19:23:26 +00:00
perf: 支持选择已有群为创建部门群
This commit is contained in:
parent
c1381d5f67
commit
1db5d3a3e0
@ -1375,4 +1375,33 @@ class DialogController extends AbstractController
|
|||||||
$dialog->pushMsg("groupDelete");
|
$dialog->pushMsg("groupDelete");
|
||||||
return Base::retSuccess('解散成功');
|
return Base::retSuccess('解散成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {get} api/dialog/group/searchuser 32. 搜索个人群(仅限管理员)
|
||||||
|
*
|
||||||
|
* @apiDescription 需要token身份,用于创建部门搜索个人群组
|
||||||
|
* @apiVersion 1.0.0
|
||||||
|
* @apiGroup dialog
|
||||||
|
* @apiName group__searchuser
|
||||||
|
*
|
||||||
|
* @apiParam {String} key 关键词
|
||||||
|
*
|
||||||
|
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||||
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
|
* @apiSuccess {Object} data 返回数据
|
||||||
|
*/
|
||||||
|
public function group__searchuser()
|
||||||
|
{
|
||||||
|
User::auth('admin');
|
||||||
|
//
|
||||||
|
$key = trim(Request::input('key'));
|
||||||
|
//
|
||||||
|
$builder = WebSocketDialog::whereType('group')->whereGroupType('user');
|
||||||
|
if ($key) {
|
||||||
|
$builder->where('name', 'like', "%{$key}%");
|
||||||
|
}
|
||||||
|
return Base::retSuccess('success', [
|
||||||
|
'list' => $builder->take(20)->get()
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1191,6 +1191,10 @@ class UsersController extends AbstractController
|
|||||||
* @apiParam {String} name 部门名称
|
* @apiParam {String} name 部门名称
|
||||||
* @apiParam {Number} [parent_id] 上级部门ID
|
* @apiParam {Number} [parent_id] 上级部门ID
|
||||||
* @apiParam {Number} owner_userid 部门负责人ID
|
* @apiParam {Number} owner_userid 部门负责人ID
|
||||||
|
* @apiParam {String} [dialog_group] 部门群(仅创建部门时有效)
|
||||||
|
* - new: 创建(默认)
|
||||||
|
* - use: 使用现有群
|
||||||
|
* @apiParam {Number} [dialog_useid] 使用现有群ID(dialog_group=use时有效)
|
||||||
*
|
*
|
||||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
@ -1204,6 +1208,8 @@ class UsersController extends AbstractController
|
|||||||
$name = trim(Request::input('name'));
|
$name = trim(Request::input('name'));
|
||||||
$parent_id = intval(Request::input('parent_id'));
|
$parent_id = intval(Request::input('parent_id'));
|
||||||
$owner_userid = intval(Request::input('owner_userid'));
|
$owner_userid = intval(Request::input('owner_userid'));
|
||||||
|
$dialog_group = trim(Request::input('dialog_group'));
|
||||||
|
$dialog_useid = $dialog_group === 'use' ? intval(Request::input('dialog_useid')) : 0;
|
||||||
//
|
//
|
||||||
if (mb_strlen($name) < 2 || mb_strlen($name) > 20) {
|
if (mb_strlen($name) < 2 || mb_strlen($name) > 20) {
|
||||||
return Base::retError('部门名称长度限制2-20个字');
|
return Base::retError('部门名称长度限制2-20个字');
|
||||||
@ -1244,7 +1250,7 @@ class UsersController extends AbstractController
|
|||||||
'name' => $name,
|
'name' => $name,
|
||||||
'parent_id' => $parent_id,
|
'parent_id' => $parent_id,
|
||||||
'owner_userid' => $owner_userid,
|
'owner_userid' => $owner_userid,
|
||||||
]);
|
], $dialog_useid);
|
||||||
//
|
//
|
||||||
return Base::retSuccess($parent_id > 0 ? '保存成功' : '新建成功');
|
return Base::retSuccess($parent_id > 0 ? '保存成功' : '新建成功');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,9 +31,10 @@ class UserDepartment extends AbstractModel
|
|||||||
/**
|
/**
|
||||||
* 保存部门
|
* 保存部门
|
||||||
* @param $data
|
* @param $data
|
||||||
|
* @param $dialogUseid
|
||||||
*/
|
*/
|
||||||
public function saveDepartment($data = []) {
|
public function saveDepartment($data = [], $dialogUseid = 0) {
|
||||||
AbstractModel::transaction(function () use ($data) {
|
AbstractModel::transaction(function () use ($dialogUseid, $data) {
|
||||||
$oldUser = null;
|
$oldUser = null;
|
||||||
$newUser = null;
|
$newUser = null;
|
||||||
if ($data['owner_userid'] !== $this->owner_userid) {
|
if ($data['owner_userid'] !== $this->owner_userid) {
|
||||||
@ -43,13 +44,44 @@ class UserDepartment extends AbstractModel
|
|||||||
$this->updateInstance($data);
|
$this->updateInstance($data);
|
||||||
//
|
//
|
||||||
if ($this->dialog_id > 0) {
|
if ($this->dialog_id > 0) {
|
||||||
|
// 已有群
|
||||||
$dialog = WebSocketDialog::find($this->dialog_id);
|
$dialog = WebSocketDialog::find($this->dialog_id);
|
||||||
if ($dialog) {
|
if ($dialog) {
|
||||||
$dialog->name = $this->name;
|
$dialog->name = $this->name;
|
||||||
$dialog->owner_id = $this->owner_userid;
|
$dialog->owner_id = $this->owner_userid;
|
||||||
$dialog->save();
|
if ($dialog->save()) {
|
||||||
|
$dialog->joinGroup($this->owner_userid, 0, true);
|
||||||
|
$dialog->pushMsg("groupUpdate", [
|
||||||
|
'id' => $dialog->id,
|
||||||
|
'name' => $dialog->name,
|
||||||
|
'owner_id' => $dialog->owner_id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} elseif ($dialogUseid > 0) {
|
||||||
|
// 使用现有群
|
||||||
|
$dialog = WebSocketDialog::whereType('group')->whereGroupType('user')->find($dialogUseid);
|
||||||
|
if (empty($dialog)) {
|
||||||
|
throw new ApiException("选择现有聊天群不存在");
|
||||||
|
}
|
||||||
|
$dialog->name = $this->name;
|
||||||
|
$dialog->owner_id = $this->owner_userid;
|
||||||
|
$dialog->group_type = 'department';
|
||||||
|
if ($dialog->save()) {
|
||||||
|
$dialog->joinGroup($this->owner_userid, 0, true);
|
||||||
|
$dialog->pushMsg("groupUpdate", [
|
||||||
|
'id' => $dialog->id,
|
||||||
|
'name' => $dialog->name,
|
||||||
|
'owner_id' => $dialog->owner_id,
|
||||||
|
'group_type' => $dialog->group_type,
|
||||||
|
]);
|
||||||
|
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'notice', [
|
||||||
|
'notice' => User::nickname() . " 将此群改为部门群"
|
||||||
|
], User::userid(), true, true);
|
||||||
|
}
|
||||||
|
$this->dialog_id = $dialog->id;
|
||||||
} else {
|
} else {
|
||||||
|
// 创建群
|
||||||
$dialog = WebSocketDialog::createGroup($this->name, [$this->owner_userid], 'department', $this->owner_userid);
|
$dialog = WebSocketDialog::createGroup($this->name, [$this->owner_userid], 'department', $this->owner_userid);
|
||||||
if (empty($dialog)) {
|
if (empty($dialog)) {
|
||||||
throw new ApiException("创建群组失败");
|
throw new ApiException("创建群组失败");
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
:userid="source.userid"
|
:userid="source.userid"
|
||||||
:tooltipDisabled="source.userid == userId"
|
:tooltipDisabled="source.userid == userId"
|
||||||
:show-icon-menu="dialogData.type == 'group'"
|
:show-icon-menu="dialogData.type == 'group'"
|
||||||
|
:open-delay="100"
|
||||||
:size="30"/>
|
:size="30"/>
|
||||||
</div>
|
</div>
|
||||||
<DialogView
|
<DialogView
|
||||||
|
|||||||
@ -160,6 +160,31 @@
|
|||||||
<FormItem prop="owner_userid" :label="$L('部门负责人')">
|
<FormItem prop="owner_userid" :label="$L('部门负责人')">
|
||||||
<UserInput v-model="departmentData.owner_userid" :multiple-max="1" max-hidden-select :placeholder="$L('请选择部门负责人')"/>
|
<UserInput v-model="departmentData.owner_userid" :multiple-max="1" max-hidden-select :placeholder="$L('请选择部门负责人')"/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
<template v-if="departmentData.id == 0">
|
||||||
|
<Divider orientation="left">{{$L('群组设置')}}</Divider>
|
||||||
|
<FormItem prop="dialog_group" :label="$L('部门群聊')">
|
||||||
|
<RadioGroup v-model="departmentData.dialog_group">
|
||||||
|
<Radio label="new">{{$L('创建部门群')}}</Radio>
|
||||||
|
<Radio label="use">{{$L('使用现有群')}}</Radio>
|
||||||
|
</RadioGroup>
|
||||||
|
</FormItem>
|
||||||
|
<FormItem v-if="departmentData.dialog_group === 'use'" prop="dialog_useid" :label="$L('选择群组')">
|
||||||
|
<Select
|
||||||
|
v-model="departmentData.dialog_useid"
|
||||||
|
filterable
|
||||||
|
:remote-method="dialogRemote"
|
||||||
|
:placeholder="$L('输入关键词搜索群')"
|
||||||
|
:loading="dialogLoad">
|
||||||
|
<Option v-for="(option, index) in dialogList" :value="option.id" :label="option.name" :key="index">
|
||||||
|
<div class="team-department-add-dialog-group">
|
||||||
|
<div class="dialog-name">{{option.name}}</div>
|
||||||
|
<UserAvatar :userid="option.owner_id" :size="20"/>
|
||||||
|
</div>
|
||||||
|
</Option>
|
||||||
|
</Select>
|
||||||
|
<div class="form-tip">{{$L('仅支持选择个人群转为部门群')}}</div>
|
||||||
|
</FormItem>
|
||||||
|
</template>
|
||||||
</Form>
|
</Form>
|
||||||
<div slot="footer" class="adaption">
|
<div slot="footer" class="adaption">
|
||||||
<Button type="default" @click="departmentShow=false">{{$L('取消')}}</Button>
|
<Button type="default" @click="departmentShow=false">{{$L('取消')}}</Button>
|
||||||
@ -262,9 +287,14 @@ export default {
|
|||||||
id: 0,
|
id: 0,
|
||||||
name: '',
|
name: '',
|
||||||
parent_id: 0,
|
parent_id: 0,
|
||||||
owner_userid: []
|
owner_userid: [],
|
||||||
|
dialog_group: 'new',
|
||||||
|
dialog_useid: 0
|
||||||
},
|
},
|
||||||
departmentList: [],
|
departmentList: [],
|
||||||
|
|
||||||
|
dialogLoad: false,
|
||||||
|
dialogList: [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
@ -766,7 +796,8 @@ export default {
|
|||||||
id: 0,
|
id: 0,
|
||||||
name: '',
|
name: '',
|
||||||
parent_id: 0,
|
parent_id: 0,
|
||||||
owner_userid: []
|
owner_userid: [],
|
||||||
|
dialog_group: 'new'
|
||||||
}, data || {})
|
}, data || {})
|
||||||
this.departmentShow = true
|
this.departmentShow = true
|
||||||
},
|
},
|
||||||
@ -837,7 +868,25 @@ export default {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
dialogRemote(key) {
|
||||||
|
if (key !== '') {
|
||||||
|
this.dialogLoad = true;
|
||||||
|
this.$store.dispatch("call", {
|
||||||
|
url: 'dialog/group/searchuser',
|
||||||
|
data: {
|
||||||
|
key,
|
||||||
|
},
|
||||||
|
}).then(({data}) => {
|
||||||
|
this.dialogList = data.list;
|
||||||
|
}).finally(_ => {
|
||||||
|
this.dialogLoad = false;
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.dialogList = [];
|
||||||
}
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -131,6 +131,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.team-department-add-dialog-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
.dialog-name {
|
||||||
|
flex: 1;
|
||||||
|
width: 0;
|
||||||
|
padding-right: 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.team-table-department-warp {
|
.team-table-department-warp {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user