团队管理

This commit is contained in:
kuaifan 2021-06-29 11:41:18 +08:00
parent 11eb8000b3
commit a5e62b25f3
15 changed files with 704 additions and 37 deletions

View File

@ -132,6 +132,24 @@ class UsersController extends AbstractController
return Captcha::create();
}
/**
* @api {get} api/users/login/codejson 07. 验证码json
*
* @apiDescription 用于判断是否需要登录验证码
* @apiVersion 1.0.0
* @apiGroup users
* @apiName login__codejson
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function login__codejson()
{
$captcha = Captcha::create('default', true);
return Base::retSuccess('请求成功', $captcha);
}
/**
* @api {get} api/users/info 04. 获取我的信息
*
@ -279,24 +297,6 @@ class UsersController extends AbstractController
return Base::retSuccess('修改成功', $user);
}
/**
* @api {get} api/users/login/codejson 07. 验证码json
*
* @apiDescription 用于判断是否需要登录验证码
* @apiVersion 1.0.0
* @apiGroup users
* @apiName login__codejson
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function login__codejson()
{
$captcha = Captcha::create('default', true);
return Base::retSuccess('请求成功', $captcha);
}
/**
* @api {get} api/users/search 08. 搜索会员列表
*
@ -306,9 +306,9 @@ class UsersController extends AbstractController
* @apiName searchinfo
*
* @apiParam {Object} keys 搜索条件
* - keys.key // 昵称、邮箱、用户名
* - keys.project_id // 在指定项目ID
* - keys.no_project_id // 不在指定项目ID
* - keys.key 昵称、邮箱
* - keys.project_id 在指定项目ID
* - keys.no_project_id 不在指定项目ID
* @apiParam {Number} [take] 获取数量10-100
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
@ -376,4 +376,140 @@ class UsersController extends AbstractController
}
return Base::retSuccess('success', $retArray);
}
/**
* 会员列表(限管理员)
*
* @apiParam {Object} [keys] 搜索条件
* - keys.email 邮箱
* - keys.nickname 昵称
* - keys.profession 职位
* @apiParam {Number} [page] 当前页,默认:1
* @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:50
*/
public function lists()
{
User::auth('admin');
//
$builder = User::select(['*', 'nickname as nickname_original']);
//
$keys = Request::input('keys');
if (is_array($keys)) {
if ($keys['email']) {
$builder->where('email', 'like', '%' . $keys['email'] . '%');
}
if ($keys['nickname']) {
$builder->where('nickname', 'like', '%' . $keys['nickname'] . '%');
}
if ($keys['profession']) {
$builder->where('profession', 'like', '%' . $keys['profession'] . '%');
}
if ($keys['identity']) {
if (Base::leftExists($keys['identity'], "no")) {
$builder->where('identity', 'not like', '%,' . Base::leftDelete($keys['identity'], 'no') . ',%');
} else {
$builder->where('identity', 'like', '%,' . $keys['identity'] . ',%');
}
}
}
$list = $builder->orderByDesc('userid')->paginate(Base::getPaginate(50, 20));
//
return Base::retSuccess('success', $list);
}
/**
* 操作会员(限管理员)
*
* @apiParam {Number} userid 会员ID
* @apiParam {String} [type] 操作
* - setadmin 设为管理员
* - clearadmin 取消管理员
* - setdisable 设为禁用
* - cleardisable 取消禁用
* - delete 删除会员
* @apiParam {String} [password] 新的密码
* @apiParam {String} [nickname] 昵称
* @apiParam {String} [profession] 职位
*/
public function operation()
{
User::auth('admin');
//
$data = Request::all();
$userid = intval($data['userid']);
$type = $data['type'];
//
$userInfo = User::find($userid);
if (empty($userInfo)) {
return Base::retError('会员不存在或已被删除');
}
//
$upArray = [];
switch ($type) {
case 'setadmin':
$upArray['identity'] = array_diff($userInfo->identity, ['admin']);
$upArray['identity'][] = 'admin';
break;
case 'clearadmin':
$upArray['identity'] = array_diff($userInfo->identity, ['admin']);
break;
case 'setdisable':
$upArray['identity'] = array_diff($userInfo->identity, ['disable']);
$upArray['identity'][] = 'disable';
break;
case 'cleardisable':
$upArray['identity'] = array_diff($userInfo->identity, ['disable']);
break;
case 'delete':
$userInfo->delete();
break;
}
if (isset($upArray['identity'])) {
$upArray['identity'] = "," . implode(",", $upArray['identity']) . ",";
}
// 密码
if (Arr::exists($data, 'password')) {
$password = trim($data['password']);
if (strlen($password) < 6) {
return Base::retError('密码设置不能小于6位数');
} elseif (strlen($password) > 32) {
return Base::retError('密码最多只能设置32位数');
}
$upArray['encrypt'] = Base::generatePassword(6);
$upArray['password'] = Base::md52($password, $upArray['encrypt']);
$upArray['changepass'] = 1;
}
// 昵称
if (Arr::exists($data, 'nickname')) {
$nickname = trim($data['nickname']);
if (mb_strlen($nickname) < 2) {
return Base::retError('昵称不可以少于2个字');
} elseif (mb_strlen($nickname) > 20) {
return Base::retError('昵称最多只能设置20个字');
} else {
$upArray['nickname'] = $nickname;
}
}
// 职位/职称
if (Arr::exists($data, 'profession')) {
$profession = trim($data['profession']);
if (mb_strlen($profession) < 2) {
return Base::retError('职位/职称不可以少于2个字');
} elseif (mb_strlen($profession) > 20) {
return Base::retError('职位/职称最多只能设置20个字');
} else {
$upArray['profession'] = $profession;
}
}
if ($upArray) {
$userInfo->updateInstance($upArray);
$userInfo->save();
}
//
return Base::retSuccess('修改成功', $userInfo);
}
}

View File

@ -267,9 +267,10 @@ class User extends AbstractModel
/**
* 用户身份认证(获取用户信息)
* @param null $identity 判断身份
* @return self
*/
public static function auth()
public static function auth($identity = null)
{
$user = self::authInfo();
if (!$user) {
@ -280,6 +281,12 @@ class User extends AbstractModel
throw new ApiException('请登录后继续...', [], -1);
}
}
if (in_array('disable', $user->identity)) {
throw new ApiException('帐号已停用...', [], -1);
}
if ($identity) {
$user->identity($identity);
}
return $user;
}

View File

@ -18,7 +18,7 @@ class CreateUsersTable extends Migration
$table->string('identity')->nullable()->default('')->comment('身份');
$table->string('az', 10)->nullable()->default('')->comment('A-Z');
$table->string('email', 100)->nullable()->default('')->unique()->comment('邮箱');
$table->string('nickname')->nullable()->comment('昵称');
$table->string('nickname')->nullable()->default('')->comment('昵称');
$table->string('profession')->nullable()->default('')->comment('职位/职称');
$table->string('userimg')->nullable()->default('')->comment('头像');
$table->string('encrypt', 50)->nullable()->default('');

View File

@ -2,6 +2,7 @@
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
@ -14,12 +15,14 @@ class UsersTableSeeder extends Seeder
*/
public function run()
{
\DB::table('users')->delete();
if (User::count() > 0) {
return;
}
\DB::table('users')->insert(array (
0 =>
0 =>
array (
'userid' => 1,
'identity' => ',admin,',
@ -41,7 +44,7 @@ class UsersTableSeeder extends Seeder
'created_at' => '2021-06-02 11:01:14',
'updated_at' => '2021-06-25 18:50:28',
),
1 =>
1 =>
array (
'userid' => 2,
'identity' => '',
@ -64,7 +67,7 @@ class UsersTableSeeder extends Seeder
'updated_at' => '2021-06-25 18:51:06',
),
));
}
}
}

View File

@ -20,6 +20,7 @@ import Loading from './components/Loading.vue'
import AutoTip from './components/AutoTip.vue'
import TagInput from './components/TagInput.vue'
import TableAction from './components/TableAction.vue'
import QuickEdit from './components/QuickEdit.vue'
import UserAvatar from './components/UserAvatar.vue'
Vue.component('PageTitle', PageTitle);
@ -27,6 +28,7 @@ Vue.component('Loading', Loading);
Vue.component('AutoTip', AutoTip);
Vue.component('TagInput', TagInput)
Vue.component('TableAction', TableAction);
Vue.component('QuickEdit', QuickEdit);
Vue.component('UserAvatar', UserAvatar);
import {

View File

@ -0,0 +1,56 @@
<template>
<div class="quick-edit">
<div v-if="isEdit" class="quick-input">
<Input ref="input" v-model="content" :disabled="isLoad" @on-blur="onEnter" @on-enter="onEnter"/>
<div v-if="isLoad" class="quick-loading"><Loading/></div>
</div>
<template v-else>
<div class="quick-text"><slot></slot></div>
<Icon class="quick-icon" type="ios-create-outline" @click="onClick"/>
</template>
</div>
</template>
<script>
export default {
name: 'QuickEdit',
props: {
value: {},
},
data() {
return {
isLoad: false,
isEdit: false,
content: ''
}
},
mounted() {
},
methods: {
onClick() {
this.content = this.value;
this.isEdit = true;
this.$nextTick(() => {
this.$refs.input.focus();
})
},
onEnter() {
if (this.content == this.value) {
this.isEdit = false;
return;
}
this.isLoad = true;
this.$emit("input", this.content);
this.$emit("on-update", this.content, () => {
this.isEdit = false;
this.isLoad = false;
})
}
}
}
</script>

View File

@ -114,6 +114,22 @@
<TaskDetail :open-task="taskData"/>
</Modal>
<!--查看所有团队-->
<Drawer
v-model="allUserShow"
:width="900"
:title="$L('团队管理')">
<TeamManagement v-if="allUserShow"/>
</Drawer>
<!--查看所有项目-->
<Drawer
v-model="allProjectShow"
:width="900"
:title="$L('项目管理')">
</Drawer>
<!--查看归档项目-->
<Drawer
v-model="archivedProjectShow"
@ -129,9 +145,10 @@ import { mapState, mapGetters } from 'vuex'
import TaskDetail from "./manage/components/TaskDetail";
import ProjectArchived from "./manage/components/ProjectArchived";
import notificationKoro from "notification-koro1";
import TeamManagement from "./manage/components/TeamManagement";
export default {
components: {ProjectArchived, TaskDetail},
components: {TeamManagement, ProjectArchived, TaskDetail},
data() {
return {
loadIng: 0,
@ -150,6 +167,8 @@ export default {
openMenu: {},
visibleMenu: false,
allUserShow: false,
allProjectShow: false,
archivedProjectShow: false,
titleInterval: null,
@ -201,16 +220,18 @@ export default {
return [
{path: 'personal', name: '个人设置'},
{path: 'password', name: '密码设置'},
{path: 'clearCache', name: '清除缓存'},
{path: 'system', name: '系统设置', divided: true},
{path: 'priority', name: '任务等级'},
{path: 'project', name: '项目管理'},
{path: 'user', name: '会员管理', divided: true},
{path: 'allUser', name: '团队管理', divided: true},
{path: 'allProject', name: '项目管理'},
{path: 'archivedProject', name: '已归档的项目'}
]
} else {
return [
{path: 'personal', name: '个人设置'},
{path: 'password', name: '密码设置'},
{path: 'clearCache', name: '清除缓存'},
{path: 'archivedProject', name: '已归档的项目', divided: true}
]
}
@ -220,6 +241,11 @@ export default {
watch: {
'$route' (route) {
this.curPath = route.path;
this.chackPass();
},
userInfo() {
this.chackPass();
},
dialogMsgPush(data) {
@ -289,6 +315,12 @@ export default {
};
},
chackPass() {
if (this.userInfo.changepass === 1) {
this.goForward({path: '/manage/setting/password'});
}
},
toggleRoute(path) {
this.goForward({path: '/manage/' + path});
},
@ -299,13 +331,20 @@ export default {
settingRoute(path) {
switch (path) {
case 'project':
case 'allUser':
this.allUserShow = true;
return;
case 'user':
case 'allProject':
this.allProjectShow = true;
return;
case 'archivedProject':
this.archivedProjectShow = true;
return;
case 'clearCache':
this.$store.state.method.clearLocal();
this.$store.dispatch("saveUserInfo", this.userInfo);
$A.messageSuccess("清除成功");
return;
case 'signout':
$A.modalConfirm({
title: '退出登录',

View File

@ -0,0 +1,334 @@
<template>
<div class="team-management">
<div class="search-box">
<ul>
<li>
<div class="search-label">
{{$L("邮箱")}}
</div>
<div class="search-content">
<Input v-model="keys.email" clearable/>
</div>
</li>
<li>
<div class="search-label">
{{$L("昵称")}}
</div>
<div class="search-content">
<Input v-model="keys.nickname" clearable/>
</div>
</li>
<li>
<div class="search-label">
{{$L("职位/职称")}}
</div>
<div class="search-content">
<Input v-model="keys.position" clearable/>
</div>
</li>
<li>
<div class="search-label">
{{$L("身份")}}
</div>
<div class="search-content">
<Select v-model="keys.identity">
<Option value="">{{$L('全部')}}</Option>
<Option value="admin">{{$L('管理员')}}</Option>
<Option value="disable">{{$L('禁用')}}</Option>
</Select>
</div>
</li>
<li class="search-button">
<Button :loading="loadIng > 0" type="primary" icon="ios-search" @click="getLists">{{$L('搜索')}}</Button>
</li>
</ul>
</div>
<Table :columns="columns" :data="list" :no-data-text="$L(noText)"></Table>
<Page
class="page-box"
:total="total"
:current="page"
:disabled="loadIng > 0"
simple
@on-change="setPage"
@on-page-size-change="setPageSize"/>
</div>
</template>
<script>
export default {
name: "TeamManagement",
data() {
return {
loadIng: 0,
keys: {},
columns: [],
list: [],
page: 1,
pageSize: 20,
total: 0,
noText: ''
}
},
mounted() {
this.getLists();
},
methods: {
initLanguage() {
this.columns = [
{
title: this.$L('ID'),
key: 'userid',
minWidth: 60,
maxWidth: 100,
},
{
title: this.$L('邮箱'),
key: 'email',
minWidth: 100,
render: (h, {row}) => {
const arr = [h('AutoTip', row.email)];
const identity = row.identity;
if (identity.includes("admin")) {
arr.push(h('Tag', {
props: {
color: 'warning'
}
}, this.$L('管理员')))
}
if (identity.includes("disable")) {
arr.push(h('Tag', {
props: {
color: 'error'
}
}, this.$L('禁用')))
}
return h('div', {
class: 'team-email'
}, arr)
}
},
{
title: this.$L('昵称'),
key: 'nickname',
minWidth: 80,
render: (h, {row}) => {
return h('QuickEdit', {
props: {
value: row.nickname_original,
},
on: {
'on-update': (val, cb) => {
this.operationUser({
userid: row.userid,
nickname: val
}).then(cb);
}
}
}, [
h('AutoTip', row.nickname_original || '-')
]);
}
},
{
title: this.$L('职位/职称'),
key: 'profession',
minWidth: 80,
render: (h, {row}) => {
return h('QuickEdit', {
props: {
value: row.profession,
},
on: {
'on-update': (val, cb) => {
this.operationUser({
userid: row.userid,
profession: val
}).then(cb);
}
}
}, [
h('AutoTip', row.profession || '-')
]);
},
},
{
title: this.$L('最后在线'),
key: 'line_at',
width: 168,
},
{
title: this.$L('操作'),
align: 'center',
width: 100,
render: (h, params) => {
const identity = params.row.identity;
const dropdownItems = [];
if (identity.includes('admin')) {
dropdownItems.push(h('EDropdownItem', {
props: {
command: 'clearadmin',
},
}, [h('div', this.$L('取消管理员'))]));
} else {
dropdownItems.push(h('EDropdownItem', {
props: {
command: 'setadmin',
},
}, [h('div', this.$L('设为管理员'))]));
}
if (identity.includes('disable')) {
dropdownItems.push(h('EDropdownItem', {
props: {
command: 'cleardisable',
},
}, [h('div', this.$L('取消禁用'))]));
} else {
dropdownItems.push(h('EDropdownItem', {
props: {
command: 'setdisable',
},
}, [h('div', this.$L('设为禁用'))]));
}
dropdownItems.push(...[
h('EDropdownItem', {
props: {
command: 'password',
},
}, [h('div', this.$L('修改密码'))]),
h('EDropdownItem', {
props: {
command: 'delete',
},
}, [h('div', this.$L('删除'))]),
])
const dropdownMenu = h('EDropdown', {
props: {
size: 'small',
trigger: 'click',
},
on: {
command: (name) => {
this.dropUser(name, params.row)
}
}
}, [
h('Button', {
props: {
type: 'primary',
size: 'small'
},
style: {
fontSize: '12px',
},
}, this.$L('操作')),
h('EDropdownMenu', {slot: 'dropdown'}, [dropdownItems]),
])
return h('TableAction', {
props: {
column: params.column
}
}, [
dropdownMenu,
]);
}
}
]
},
getLists() {
this.loadIng++;
this.$store.dispatch("call", {
url: 'users/lists',
data: {
keys: this.keys,
page: Math.max(this.page, 1),
pagesize: Math.max($A.runNum(this.pageSize), 20),
},
}).then(({data}) => {
this.loadIng--;
this.page = data.current_page;
this.total = data.total;
this.list = data.data;
this.noText = '没有相关的数据';
}).catch(() => {
this.loadIng--;
this.noText = '数据加载失败';
})
},
setPage(page) {
this.page = page;
this.getLists();
},
setPageSize(pageSize) {
this.page = 1;
this.pageSize = pageSize;
this.getLists();
},
dropUser(name, row) {
switch (name) {
case 'password':
$A.modalInput({
title: "修改密码",
placeholder: "请输入新的密码",
onOk: (value) => {
if (value) {
this.operationUser({
userid: row.userid,
password: value
});
}
return true;
}
});
break;
case 'delete':
$A.modalConfirm({
content: '你确定要删除此帐号吗?',
onOk: () => {
this.operationUser({
userid: row.userid,
type: name,
});
}
});
break;
default:
this.operationUser({
userid: row.userid,
type: name
});
break;
}
},
operationUser(data) {
let that = this;
return new Promise(function (resolve) {
that.loadIng++;
that.$store.dispatch("call", {
url: 'users/operation',
data,
}).then(({msg}) => {
$A.messageSuccess(msg);
that.loadIng--;
that.getLists();
resolve()
}).catch(({msg}) => {
$A.modalError(msg);
that.loadIng--;
that.getLists();
resolve()
})
})
}
}
}
</script>

View File

@ -1,5 +1,6 @@
<template>
<div class="setting-item submit">
<Alert v-if="userInfo.changepass" type="warning" showIcon style="margin-bottom:32px">{{$L('请先修改登录密码')}}</Alert>
<Form ref="formDatum" :model="formDatum" :rules="ruleDatum" label-width="auto" @submit.native.prevent>
<FormItem :label="$L('旧密码')" prop="oldpass">
<Input v-model="formDatum.oldpass" type="password"></Input>
@ -19,6 +20,8 @@
</template>
<script>
import {mapState} from "vuex";
export default {
data() {
return {
@ -33,6 +36,9 @@ export default {
ruleDatum: { },
}
},
computed: {
...mapState(['userInfo']),
},
methods: {
initLanguage() {
this.ruleDatum = {

View File

@ -5,6 +5,7 @@
@import "scroller-y";
@import "spinner";
@import "t-editor";
@import "quick-edit";
@import "tag-input";
@import "user-avatar";
@import "user-input";

View File

@ -1,4 +1,4 @@
.common-auto-tip-content {
.common-auto-tip {
display: block;
overflow: hidden;
text-overflow: ellipsis;

View File

@ -0,0 +1,41 @@
.quick-edit {
display: flex;
align-items: center;
max-width: 100%;
.quick-input {
flex: 1;
position: relative;
.quick-loading {
position: absolute;
top: 0;
right: 8px;
bottom: 0;
display: flex;
align-items: center;
.common-loading {
margin: 0;
width: 14px;
height: 14px;
}
}
}
.quick-text {
overflow: hidden;
text-overflow: ellipsis;
align-items: center;
white-space: nowrap;
height: 20px;
line-height: 20px;
margin-right: 6px;
}
.quick-icon {
display: none;
font-size: 16px;
cursor: pointer;
}
&:hover {
.quick-icon {
display: inline-block;
}
}
}

View File

@ -268,6 +268,34 @@ body {
padding: 20px 0;
}
.search-box {
margin-bottom: 24px;
> ul {
display: flex;
align-items: flex-end;
> li {
flex: 1;
flex-shrink: 0;
margin-right: 12px;
list-style: none;
display: flex;
flex-direction: column;
&:last-child {
margin-right: 0;
}
.search-label {
font-weight: 600;
}
.search-content {
margin-top: 6px;
}
&.search-button {
flex: none;
}
}
}
}
.icon-loading {
animation: icon-loading-load 0.6s infinite linear;
}

View File

@ -6,3 +6,4 @@
@import "task-add-simple";
@import "task-detail";
@import "task-priority";
@import "team-management";

View File

@ -0,0 +1,13 @@
.team-management {
.team-email {
line-height: 1;
.ivu-tag {
height: 18px;
line-height: 18px;
padding: 0 4px;
margin: 0 -2px 0 0;
transform: scale(0.8);
transform-origin: left bottom;
}
}
}