perf: 通讯录显示部门负责人

This commit is contained in:
kuaifan 2023-03-04 12:27:09 +08:00
parent 20e236d429
commit ba3eb7f27c
4 changed files with 78 additions and 11 deletions

View File

@ -460,7 +460,13 @@ class UsersController extends AbstractController
*/ */
public function search() public function search()
{ {
$builder = User::select(User::$basicField); $user = User::auth();
//
$columns = User::$basicField;
if ($user->isAdmin()) {
$columns[] = 'identity';
}
$builder = User::select($columns);
// //
$keys = Request::input('keys'); $keys = Request::input('keys');
$sorts = Request::input('sorts'); $sorts = Request::input('sorts');
@ -513,12 +519,25 @@ class UsersController extends AbstractController
$list = $builder->orderBy('userid')->take(Base::getPaginate(100, 10, 'take'))->get(); $list = $builder->orderBy('userid')->take(Base::getPaginate(100, 10, 'take'))->get();
} }
// //
if ($state === 1) { $list->transform(function (User $userInfo) use ($state) {
$list->transform(function (User $userInfo) { $tags = [];
$userInfo->online = $userInfo->getOnlineStatus(); $dep = $userInfo->getDepartmentName();
return $userInfo; $dep = array_filter(explode(",", $dep), function($item) {
return preg_match("/\(M\)$/", $item);
}); });
} if ($dep) {
$tags[] = preg_replace("/\(M\)$/", "", $dep[0]) . " " . Base::Lang("负责人");
}
if ($userInfo->isTemp()) {
$tags[] = Base::Lang("临时");
}
$userInfo->tags = $tags;
//
if ($state === 1) {
$userInfo->online = $userInfo->getOnlineStatus();
}
return $userInfo;
});
return Base::retSuccess('success', $list); return Base::retSuccess('success', $list);
} }
@ -1365,6 +1384,12 @@ class UsersController extends AbstractController
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个字');
} }
if (preg_match('/[\Q~!@#$%^&*()+-_=.:?<>,\E]/', $name)) {
return Base::retError('部门名称不能包含特殊符号');
}
if (str_contains($name, '(M)')) {
return Base::retError('部门名称不能包含:(M)');
}
// //
if ($id > 0) { if ($id > 0) {
$userDepartment = UserDepartment::find($id); $userDepartment = UserDepartment::find($id);

View File

@ -175,6 +175,15 @@ class User extends AbstractModel
return in_array('temp', $this->identity); return in_array('temp', $this->identity);
} }
/**
* 返回是否管理员
* @return bool
*/
public function isAdmin()
{
return in_array('admin', $this->identity);
}
/** /**
* 判断是否管理员 * 判断是否管理员
*/ */

View File

@ -103,7 +103,10 @@
<ul> <ul>
<li v-for="(user, index) in items.list" :key="index" @click="openContacts(user)"> <li v-for="(user, index) in items.list" :key="index" @click="openContacts(user)">
<div class="avatar"><UserAvatar :userid="user.userid" :size="30"/></div> <div class="avatar"><UserAvatar :userid="user.userid" :size="30"/></div>
<div class="nickname">{{user.nickname}}</div> <div class="nickname">
<em>{{user.nickname}}</em>
<div v-if="user.tags" class="tags">{{user.tags.join(', ')}}</div>
</div>
<div v-if="user.loading" class="loading"><Loading/></div> <div v-if="user.loading" class="loading"><Loading/></div>
</li> </li>
</ul> </ul>
@ -805,6 +808,18 @@ export default {
const {type, group_type} = data const {type, group_type} = data
return type === 'group' && group_type !== 'user' return type === 'group' && group_type !== 'user'
}, },
userTag({identity, department_name}) {
const array = []
const deps = department_name?.split(",").find(item => /\(M\)$/.test(item))
if (deps) {
array.push(deps.replace(/\(M\)$/, '') + ' ' + this.$L('负责人'))
}
if (identity?.includes('temp')) {
array.push(this.$L('临时'))
}
return array.join(', ')
}
} }
} }
</script> </script>

View File

@ -408,11 +408,29 @@
} }
.nickname { .nickname {
flex: 1; flex: 1;
padding: 0 12px; width: 0;
padding-left: 12px;
font-size: 14px; font-size: 14px;
white-space: nowrap; display: flex;
overflow: hidden; align-items: center;
text-overflow: ellipsis; justify-content: space-between;
flex-flow: row wrap;
align-content: flex-start;
> em {
padding-right: 12px;
font-style: normal;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.tags {
padding-right: 12px;
font-size: 12px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: $primary-desc-color;
}
} }
.loading { .loading {
margin-right: 12px; margin-right: 12px;