1、修复几处bug;

2、完善内容管理中的细节功能
This commit is contained in:
2020-04-03 17:14:49 +08:00
parent 743d429bb8
commit 2f4386f196
12 changed files with 72 additions and 52 deletions

View File

@@ -150,9 +150,8 @@ class User extends Base {
* @author colin <colin@tensent.cn>
*/
private function getUserinfo($uid = null, $pass = null, $errormsg = null) {
$uid = $uid ? $uid : input('id');
//如果无UID则修改当前用户
$uid = $uid ? $uid : session('user_auth.uid');
$uid = $uid ? $uid : $this->request->param('uid', session('userInfo.uid'));
$map['uid'] = $uid;
if ($pass != null) {
unset($map);

View File

@@ -14,6 +14,16 @@ use \app\controller\Base as BaseC;
class Base extends BaseC {
protected function initialize() {
$url = str_replace(".", "/", strtolower($this->request->controller())) . '/' . $this->request->action();
if (!is_login() and !in_array($url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
$this->redirect('/admin/index/login');
}
if (!in_array($url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
}
}
protected function fetch($template = '') {
$config = Cache::get('system_config_data');
$this->tpl_config['view_depr'] = '_';
@@ -29,6 +39,15 @@ class Base extends BaseC {
if ($template == '') {
$template = str_replace(".", "@", strtolower($this->request->controller())) . "/" . $this->request->action();
}
$template_path = str_replace("public", "", $this->tpl_config['view_dir_name']);
$this->tpl_config['tpl_replace_string'] = [
'__static__' => '/static',
'__img__' => $template_path . 'static/images',
'__css__' => $template_path . 'static/css',
'__js__' => $template_path . 'static/js',
'__plugins__' => '/static/plugins',
'__public__' => $template_path . 'static',
];
View::config($this->tpl_config);
View::assign($this->data);

View File

@@ -16,14 +16,16 @@ use think\Validate;
class Category extends Validate{
protected $rule = [
'title' => 'require',
'model_id' => 'require'
];
protected $message = [
'title.require' => '栏目名称必须',
'model_id.require' => '绑定模型必须',
];
protected $scene = [
'adminadd' => ['title'],
'adminedit' => ['title'],
'adminadd' => ['title', 'model_id'],
'adminedit' => ['title', 'model_id'],
];
}

View File

@@ -22,26 +22,32 @@ class Attribute extends \think\Model {
'id' => 'integer',
);
/**
* @title 新增后事件
*/
protected static function onAfterInsert($data){
$data = $data->toArray();
if ($data['model_id']) {
$db = new \com\Datatable();
$name = Models::where('id', $data['model_id'])->value('name');
$data['after'] = self::where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name');
$data['after'] = self::where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('sort asc, id desc')->value('name');
return $db->columField(strtolower($name), $data)->query();
}
}
/**
* @title 更新后事件
*/
protected static function onAfterUpdate($data){
$data = $data->toArray();
if ($data['model_id']) {
if (isset($data['model_id']) && isset($data['name'])) {
$tablename = Models::where('id', $data['model_id'])->value('name');
//删除模型表中字段
$db = new \com\Datatable();
if ($db->CheckField($tablename, $data['name'])) {
$data['action'] = 'CHANGE';
}
$data['after'] = self::where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('sort asc, id asc')->value('name');
$result = $db->columField(strtolower($tablename), $data)->query();
return $result;
}else{
@@ -49,6 +55,9 @@ class Attribute extends \think\Model {
}
}
/**
* @title 删除后事件
*/
protected static function onAfterDelete($data){
$data = $data->toArray();
if ($data['model_id']) {
@@ -94,9 +103,14 @@ class Attribute extends \think\Model {
}elseif($data['type'] == 'bool'){
$list = [['key'=>0,'label'=>'禁用'],['key'=>1,'label'=>'启用']];
}elseif($data['type'] == 'bind'){
$map = [];
$db = new \com\Datatable();
if (strrpos($data['extra'], ":")) {
$extra = explode(":", $data['extra']);
$row = Db::name($extra[0])->select()->toArray();
if ($db->CheckField($extra[0], 'model_id')) {
$map[] = ['model_id', '=', $data['model_id']];
}
$row = Db::name($extra[0])->where($map)->select()->toArray();
if ($extra[1] == 'tree') {
$row = (new Tree())->toFormatTree($row);
foreach ($row as $val) {
@@ -108,7 +122,10 @@ class Attribute extends \think\Model {
}
}
}else{
$row = Db::name($data['extra'])->select()->toArray();
if ($db->CheckField($data['extra'], 'model_id')) {
$map[] = ['model_id', '=', $data['model_id']];
}
$row = Db::name($data['extra'])->select($map)->toArray();
foreach ($row as $val) {
$list[] = ['key'=>$val['id'], 'label'=>$val['title']];
}

View File

@@ -21,6 +21,10 @@ class Category extends \think\Model{
'icon' => 'integer',
);
protected static function onAfterUpdate($model){
$data = $model->toArray();
}
public static function getCategoryTree($map = []){
$list = self::where($map)->select();
@@ -31,22 +35,6 @@ class Category extends \think\Model{
return $list;
}
public function change() {
$data = input('post.');
if ($data['id']) {
$result = $this->save($data, array('id' => $data['id']));
} else {
unset($data['id']);
$result = $this->save($data);
}
if (false !== $result) {
return true;
} else {
$this->error = "失败!";
return false;
}
}
public function info($id, $field = true) {
return $this->db()->where(array('id' => $id))->field($field)->find();
}

View File

@@ -69,19 +69,28 @@ class Model extends \think\Model{
}
protected static function onAfterUpdate($data){
$data = $data->toArray();
if (isset($data['attribute_sort']) && $data['attribute_sort']) {
$attribute_sort = json_decode($data['attribute_sort'], true);
$attr = [];
if (!empty($attribute_sort)) {
foreach ($attribute_sort as $key => $value) {
$attr[$key] = Attribute::where('id', 'IN', $value)->column('*', 'id');
foreach ($value as $k => $v) {
$attr[] = ['id' => $v, 'group_id' => $key, 'sort' => $k];
$attr[$key][$v]['group'] = $key;
$attr[$key][$v]['sort'] = $k;
}
}
}
$save = [];
foreach($attr as $value){
if(!empty($value)){
$save = array_merge($save, $value);
}
}
if (!empty($attr)) {
(new Attribute())->saveAll($attr);
(new Attribute())->saveAll($save);
}
}
return true;

View File

@@ -126,7 +126,7 @@ class Datatable {
} elseif ($field_attr['action'] == 'CHANGE') {
$field_attr['oldname'] = (isset($attr['oldname']) && $attr['oldname']) ? $attr['oldname'] : $attr['name'];
$this->sql = "ALTER TABLE `{$field_attr['table']}` CHANGE `{$field_attr['oldname']}` `{$field_attr['name']}` {$field_attr['type']}{$field_attr['length']} {$field_attr['is_null']} {$field_attr['default']} COMMENT '{$field_attr['comment']}'";
$this->sql = "ALTER TABLE `{$field_attr['table']}` CHANGE `{$field_attr['oldname']}` `{$field_attr['name']}` {$field_attr['type']}{$field_attr['length']} {$field_attr['is_null']} {$field_attr['default']} COMMENT '{$field_attr['comment']}' {$field_attr['after']}";
}
return $this;
}

View File

@@ -1,2 +0,0 @@
*
!.gitignore

View File

@@ -1,2 +0,0 @@
*
!.gitignore

View File

@@ -14,9 +14,9 @@ use app\model\Model;
$model = Model::where('status', '>', 0)->field(['id', 'name'])->select()->toArray();
foreach ($model as $value) {
Route::rule('/admin/' . $value['name'] . '/:function', 'admin.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]);
Route::rule('/front/' . $value['name'] . '/:function', 'front.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]);
Route::rule('/user/' . $value['name'] . '/:function', 'user.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]);
Route::rule('/admin/' . $value['name'] . '/:function', 'Admin.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]);
Route::rule('/front/' . $value['name'] . '/:function', 'Front.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]);
Route::rule('/user/' . $value['name'] . '/:function', 'User.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]);
}
Route::rule('/', 'Front.Index/index');
@@ -37,12 +37,12 @@ Route::group('admin', function () {
});
Route::group('user', function () {
Route::rule('/', 'user.Index/index');
Route::rule('login', 'user.Index/login');
Route::rule('logout', 'user.Index/logout');
Route::rule('register', 'user.Index/register');
Route::rule('/', 'User.Index/index');
Route::rule('login', 'User.Index/login');
Route::rule('logout', 'User.Index/logout');
Route::rule('register', 'User.Index/register');
Route::rule('upload/:function', 'Upload/:function');
Route::rule(':controller/:function', 'user.:controller/:function');
Route::rule(':controller/:function', 'User.:controller/:function');
});
Route::group('api', function () {

View File

@@ -164,16 +164,6 @@
<script type="text/javascript" src="__static__/plugins/webuploader/webuploader.min.js"></script>
<script type="text/javascript" src="__static__/plugins/webuploader/webuploader.custom.js"></script>
<script type="text/javascript">
{present name="info['id']"}
Sent.setValue("allow_publish", {$info.allow_publish|default=1});
Sent.setValue("check", {$info.check|default=0});
Sent.setValue("model[]", {$info.model|json_encode} || [1]);
Sent.setValue("model_sub[]", {$info.model_sub|json_encode} || [1]);
Sent.setValue("type[]", {$info.type|json_encode} || [2]);
Sent.setValue("display", {$info.display|default=1});
Sent.setValue("reply", {$info.reply|default=0});
Sent.setValue("reply_model[]", {$info.reply_model|json_encode} || [1]);
{/present}
$(function(){
$("input[name=reply]").change(function(){
var $reply = $(".form-group.reply");

View File

@@ -21,13 +21,13 @@
</a>
<ul class="dropdown-menu dropdown-menu-right">
<li>
<a href="{:url('/admin/User/edit')}">
<a href="{:url('/admin/user/edit')}">
<i class="fa fa-user"></i>
修改资料
</a>
</li>
<li>
<a href="{:url('/admin/User/editpwd')}">
<a href="{:url('/admin/user/editpwd')}">
<i class="fa fa-cog"></i>
修改密码
</a>