功能更新

This commit is contained in:
2020-03-30 21:16:28 +08:00
parent b16e4ab920
commit f31f3b99fa
23 changed files with 464 additions and 230 deletions

View File

@@ -6,9 +6,10 @@
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model;
use think\facade\Config;
/**
* 设置模型
*/
@@ -18,88 +19,65 @@ class Attribute extends \think\Model {
'id' => 'integer',
);
// protected static function init() {
// self::afterInsert(function ($data) {
// if ($data['model_id']) {
// $name = db('Model')->where('id', $data['model_id'])->value('name');
// $db = new \com\Datatable();
// $attr = $data->toArray();
// $model_attr = array(
// 'model_id' => $data['model_id'],
// 'attr_id' => $data->id,
// 'group_id' => 0,
// 'is_add_table' => 1,
// 'is_show' => $data['is_show'],
// 'is_must' => $data['is_must'],
// 'sort' => 0,
// );
// $attr['after'] = db('Attribute')->where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name');
// return $db->columField(strtolower($name), $attr)->query();
// }
// });
// self::beforeUpdate(function ($data) {
// $attr = $data->toArray();
// $attr['action'] = 'CHANGE';
// $attr['oldname'] = db('Attribute')->where('id', $attr['id'])->value('name');
// if ($attr['id']) {
// $name = db('Model')->where('id', $attr['model_id'])->value('name');
// $db = new \com\Datatable();
// return $db->columField(strtolower($name), $attr)->query();
// } else {
// return false;
// }
// });
// }
protected static function onAfterInsert($model){
// if ($data['model_id']) {
// $name = db('Model')->where('id', $data['model_id'])->value('name');
// $db = new \com\Datatable();
// $attr = $data->toArray();
// $model_attr = array(
// 'model_id' => $data['model_id'],
// 'attr_id' => $data->id,
// 'group_id' => 0,
// 'is_add_table' => 1,
// 'is_show' => $data['is_show'],
// 'is_must' => $data['is_must'],
// 'sort' => 0,
// );
// $attr['after'] = db('Attribute')->where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name');
// return $db->columField(strtolower($name), $attr)->query();
// }
}
protected static function onAfterUpdate($model){
// $attr = $data->toArray();
// $attr['action'] = 'CHANGE';
// $attr['oldname'] = db('Attribute')->where('id', $attr['id'])->value('name');
// if ($attr['id']) {
// $name = db('Model')->where('id', $attr['model_id'])->value('name');
// $db = new \com\Datatable();
// return $db->columField(strtolower($name), $attr)->query();
// } else {
// return false;
// }
}
protected static function onAfterDelete($model){
$tablename = strtolower($tablename);
//删除模型表中字段
$db = new \com\Datatable();
if (!$db->CheckField($tablename, $info['name'])) {
return true;
}
$result = $db->delField($tablename, $info['name'])->query();
}
protected function getTypeTextAttr($value, $data) {
$type = config('config_type_list');
$type_text = explode(',', $type[$data['type']]);
return $type_text[0];
}
public function getFieldlist($map, $index = 'id') {
$list = array();
$row = db('Attribute')->field('*,remark as help,type,extra as "option",model_id')->where($map)->order('group_id asc, sort asc')->select();
foreach ($row as $key => $value) {
if (in_array($value['type'], array('checkbox', 'radio', 'select', 'bool'))) {
$value['option'] = parse_field_attr($value['extra']);
} elseif ($value['type'] == 'bind') {
$extra = parse_field_bind($value['extra'], '', $value['model_id']);
$option = array();
foreach ($extra as $k => $v) {
$option[$v['id']] = $v['title_show'];
}
$value['option'] = $option;
}
$list[$value['id']] = $value;
$config_type_list = Config::get('config.config_type_list');
$type = [];
foreach ($config_type_list as $key => $value) {
$type[$value['key']] = $value['label'];
}
return $list;
return isset($type[$data['type']]) ? $type[$data['type']] : '';
}
public function del($id, $model_id) {
$map['id'] = $id;
$info = $this->find($id);
$tablename = db('Model')->where(array('id' => $model_id))->value('name');
protected function getOptionAttr($value, $data){
if ($data == '') {
return [];
}
if (in_array($data['type'], ['checkbox', 'radio', 'select', 'bool'])) {
# code...
}elseif($data['type'] == 'bind'){
//先删除字段表内的数据
$result = $this->where($map)->delete();
if ($result) {
$tablename = strtolower($tablename);
//删除模型表中字段
$db = new \com\Datatable();
if (!$db->CheckField($tablename, $info['name'])) {
return true;
}
$result = $db->delField($tablename, $info['name'])->query();
if ($result) {
return true;
} else {
$this->error = "删除失败!";
return false;
}
} else {
$this->error = "删除失败!";
return false;
}
}
}

View File

@@ -23,4 +23,6 @@ class AuthGroup extends Model{
['name'=>'description', 'title'=>'分组描述', 'type'=>'textarea', 'help'=>'', 'option'=>''],
['name'=>'status', 'title'=>'状态', 'type'=>'select', 'help'=>'', 'option'=> [['key' => 0, 'label' => '禁用'],['key' => 1, 'label' => '启用']]],
];
public static function getAuthModels($uid){}
}

View File

@@ -83,10 +83,34 @@ class Config extends Model {
return $data;
}
public function getThemesList(){
public function getThemesList($request){
return [
'pc' => [],
'mobile' => []
'pc' => $this->getList('pc'),
'mobile' => $this->getList('mobile')
];
}
protected function getList($type){
$tempPath = app()->getRootPath() . 'public' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR;
$file = opendir($tempPath);
$list = [];
while (false !== ($filename = readdir($file))) {
if (!in_array($filename, array('.', '..'))) {
$files = $tempPath . $filename . '/info.php';
if (is_file($files)) {
$info = include($files);
if (isset($info['type']) && $info['type'] == $type) {
$info['id'] = $filename;
$preview = '/template/' . $filename . '/' . $info['preview'];
$info['preview'] = is_file($tempPath . $preview) ? $preview : '/static/common/images/default.png';
$list[] = $info;
}else{
continue;
}
}
}
}
return $list;
}
}

View File

@@ -16,7 +16,7 @@ class Rewrite extends \think\Model {
protected $autoWriteTimestamp = true;
public $keyList = array(
public static $keyList = array(
array('name' => 'id', 'title' => '标识', 'type' => 'hidden'),
array('name' => 'rule', 'title' => '规则名称', 'type' => 'text', 'option' => '', 'help' => '规则名称,方便记忆'),
array('name' => 'url', 'title' => '规则地址', 'type' => 'text', 'option' => '', 'help' => '规则地址'),

View File

@@ -14,18 +14,18 @@ namespace app\model;
*/
class SeoRule extends \think\Model {
public $keyList = array(
array('name' => 'id', 'title' => '标识', 'type' => 'hidden'),
array('name' => 'title', 'title' => '规则名称', 'type' => 'text', 'option' => '', 'help' => '规则名称,方便记忆'),
array('name' => 'app', 'title' => '模块名', 'type' => 'select', 'option' => array('*' => '-所有模块-', 'index' => '前台模块', 'user' => '用户中心'), 'help' => '不选表示所有模块'),
array('name' => 'controller', 'title' => '控制器', 'type' => 'text', 'option' => '', 'help' => '不填表示所有控制器'),
array('name' => 'action', 'title' => '方法', 'type' => 'text', 'option' => '', 'help' => '不填表示所有方法'),
array('name' => 'seo_title', 'title' => 'SEO标题', 'type' => 'text', 'option' => '', 'help' => '不填表示使用默认'),
array('name' => 'seo_keywords', 'title' => 'SEO关键字', 'type' => 'text', 'option' => '', 'help' => '不填表示使用默认'),
array('name' => 'seo_description', 'title' => 'SEO描述', 'type' => 'text', 'option' => '', 'help' => '不填表示使用默认'),
array('name' => 'status', 'title' => '状态', 'type' => 'select', 'option' => array('0' => '禁用', '1' => '启用'), 'help' => ''),
array('name' => 'sort', 'title' => '排序', 'type' => 'text', 'option' => '', 'help' => ''),
);
public static $keyList = [
['name' => 'id', 'title' => '标识', 'type' => 'hidden'],
['name' => 'title', 'title' => '规则名称', 'type' => 'text', 'option' => '', 'help' => '规则名称,方便记忆'],
['name' => 'app', 'title' => '模块名', 'type' => 'select', 'option' => [['key'=>'*', 'label' => '-所有模块-'], ['key'=>'index', 'label' => '前台模块'], ['key'=>'user', 'label' => '用户中心']], 'help' => '不选表示所有模块'],
['name' => 'controller', 'title' => '控制器', 'type' => 'text', 'option' => '', 'help' => '不填表示所有控制器'],
['name' => 'action', 'title' => '方法', 'type' => 'text', 'option' => '', 'help' => '不填表示所有方法'],
['name' => 'seo_title', 'title' => 'SEO标题', 'type' => 'text', 'option' => '', 'help' => '不填表示使用默认'],
['name' => 'seo_keywords', 'title' => 'SEO关键字', 'type' => 'text', 'option' => '', 'help' => '不填表示使用默认'],
['name' => 'seo_description', 'title' => 'SEO描述', 'type' => 'text', 'option' => '', 'help' => '不填表示使用默认'],
['name' => 'status', 'title' => '状态', 'type' => 'select', 'option' => [['key'=>'0', 'label' => '禁用'], ['key'=>'1', 'label' => '启用']], 'help' => ''],
['name' => 'sort', 'title' => '排序', 'type' => 'text', 'option' => '', 'help' => ''],
];
protected function setAppAttr($value) {
return $value ? $value : '*';