-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,185 additions
and
902 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import {Button} from 'react-bootstrap'; | ||
import {Page, PageHeader, FormItem, Form, FormAction, Options, ImageUpload} from 'components'; | ||
|
||
const loader = Promise.all([ | ||
import('jquery-populate'), | ||
import('jquery-form'), | ||
import('jquery-validation-mx') | ||
]); | ||
|
||
class AdminForm extends React.Component { | ||
componentDidMount() { | ||
loader.then(() => { | ||
$('.js-admin-form') | ||
.populate(wei.user) | ||
.ajaxForm({ | ||
url: $.url('admin/admins/' + (wei.user.id ? 'update' : 'create')), | ||
dataType: 'json', | ||
beforeSubmit: (arr, $form) => $form.valid(), | ||
success: (ret) => { | ||
$.msg(ret, () => { | ||
if (ret.code === 1) { | ||
window.location = $.url('admin/admins'); | ||
} | ||
}); | ||
} | ||
}) | ||
.validate(); | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Page> | ||
<PageHeader> | ||
<Button href={$.url('admin/admins')}>返回列表</Button> | ||
</PageHeader> | ||
<Form horizontal className="js-admin-form" method="post"> | ||
<FormItem label="用户名" name="username" required={!wei.user.id} | ||
control={wei.user.id && <p className="form-control-static">{wei.user.username}</p>} /> | ||
|
||
<FormItem label="用户组" name="groupId" required> | ||
<Options data={wei.groups} labelKey="name" valueKey="id"/> | ||
</FormItem> | ||
|
||
<FormItem label="头像" name="headImg" control={<ImageUpload name="headImg"/>} | ||
help="支持.jpg .jpeg .bmp .gif .png格式照片"/> | ||
|
||
<FormItem label="昵称" name="nickName"/> | ||
|
||
<FormItem label="密码" name="password" type="password" required={!wei.user.id} | ||
help={wei.user.id && '不修改密码请留空'}/> | ||
|
||
<FormItem label="重复密码" name="passwordAgain" type="password" required={!wei.user.id}/> | ||
|
||
<input type="hidden" id="id" name="id"/> | ||
|
||
<FormAction url={$.url('admin/admins')}/> | ||
</Form> | ||
</Page> | ||
) | ||
} | ||
} | ||
|
||
export default AdminForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import {Button} from 'react-bootstrap'; | ||
import {Page, PageHeader, DataTable, SearchForm, SearchItem} from 'components'; | ||
import rp from 'require-promise'; | ||
import 'jquery-update-event'; | ||
|
||
const loader = Promise.all([ | ||
rp('template'), | ||
import('query-url'), | ||
import('datatables-net-mx') | ||
]); | ||
|
||
class AdminIndex extends React.Component { | ||
componentDidMount() { | ||
loader.then(() => { | ||
// FIXME | ||
template.helper('$', $); | ||
|
||
var $table = $('.js-admin-table').dataTable({ | ||
searchEl: '.js-admin-form', | ||
searchEvent: 'update', | ||
ajax: { | ||
url: $.queryUrl2('admin/admins.json') | ||
}, | ||
order: [], | ||
columns: [ | ||
{ | ||
title: '用户名', | ||
data: 'username' | ||
}, | ||
{ | ||
title: '昵称', | ||
data: 'nickName' | ||
}, | ||
{ | ||
title: '邮箱', | ||
data: 'email' | ||
}, | ||
{ | ||
title: '分组', | ||
data: 'group.name' | ||
}, | ||
{ | ||
title: '创建时间', | ||
data: 'createTime' | ||
}, | ||
{ | ||
title: `<span class="js-tips-hover table-header-tips" data-content="禁用后,用户将无法登录" | ||
data-container="body" data-placement="bottom" data-trigger="hover"> | ||
启用 <i class="fa fa-question-circle light-grey bigger-130"></i> | ||
</span>`, | ||
data: 'enable', | ||
render: function (data, type, full) { | ||
return template.render('checkbox-col-tpl', { | ||
id: full.id, | ||
name: 'enable', | ||
value: data | ||
}); | ||
} | ||
}, | ||
{ | ||
title: '操作', | ||
data: 'id', | ||
createdCell: (td, val) => { | ||
ReactDOM.render(<span> | ||
<a href={$.url('admin/admins/%s/edit', val)}>编辑</a> | ||
{' '} | ||
{wei.isInstalledCan && <a href={$.url('admin/users/%s/roles/assign', val)}>分配角色</a>} | ||
</span>, td); | ||
} | ||
} | ||
] | ||
}); | ||
|
||
$('.js-tips-hover').popover(); | ||
|
||
// 切换状态 | ||
$table.on('click', '.js-toggle-status', function () { | ||
const $this = $(this); | ||
var data = {}; | ||
data['id'] = $this.data('id'); | ||
data[$this.attr('name')] = +!$this.data('value'); | ||
$.post($.url('admin/admins/enable'), data, function (result) { | ||
$.msg(result); | ||
$table.reload(); | ||
}, 'json'); | ||
}); | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Page> | ||
<PageHeader> | ||
<Button bsStyle="success" href={$.url('admin/admins/new')}>添加管理员</Button> | ||
</PageHeader> | ||
<SearchForm className="js-admin-form"> | ||
<SearchItem label="用户名" name="username" /> | ||
|
||
<SearchItem label="昵称" name="nickName" /> | ||
|
||
<SearchItem label="邮箱" name="email" /> | ||
</SearchForm> | ||
<DataTable className="js-admin-table" /> | ||
</Page> | ||
) | ||
} | ||
} | ||
|
||
export default AdminIndex; |
Oops, something went wrong.