mirror of https://gitee.com/karson/fastadmin.git
模型定义拼音自动完成字段
parent
119b0273d4
commit
a5eb7ef3b7
|
|
@ -13,9 +13,16 @@ class AuthRule extends Model
|
||||||
// 定义时间戳字段名
|
// 定义时间戳字段名
|
||||||
protected $createTime = 'createtime';
|
protected $createTime = 'createtime';
|
||||||
protected $updateTime = 'updatetime';
|
protected $updateTime = 'updatetime';
|
||||||
|
// 数据自动完成字段
|
||||||
|
protected $insert = ['py', 'pinyin'];
|
||||||
|
protected $update = ['py', 'pinyin'];
|
||||||
|
// 拼音对象
|
||||||
|
protected static $pinyin = null;
|
||||||
|
|
||||||
protected static function init()
|
protected static function init()
|
||||||
{
|
{
|
||||||
|
self::$pinyin = new \Overtrue\Pinyin\Pinyin('Overtrue\Pinyin\MemoryFileDictLoader');
|
||||||
|
|
||||||
self::beforeWrite(function ($row) {
|
self::beforeWrite(function ($row) {
|
||||||
if (isset($_POST['row']) && is_array($_POST['row']) && isset($_POST['row']['condition'])) {
|
if (isset($_POST['row']) && is_array($_POST['row']) && isset($_POST['row']['condition'])) {
|
||||||
$originRow = $_POST['row'];
|
$originRow = $_POST['row'];
|
||||||
|
|
@ -37,4 +44,17 @@ class AuthRule extends Model
|
||||||
return ['addtabs' => __('Addtabs'), 'dialog' => __('Dialog'), 'ajax' => __('Ajax'), 'blank' => __('Blank')];
|
return ['addtabs' => __('Addtabs'), 'dialog' => __('Dialog'), 'ajax' => __('Ajax'), 'blank' => __('Blank')];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setPyAttr($value, $data) {
|
||||||
|
if (isset($data['title']) && $data['title']) {
|
||||||
|
return self::$pinyin->abbr($data['title']);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPinyinAttr($value, $data) {
|
||||||
|
if (isset($data['title']) && $data['title']) {
|
||||||
|
return self::$pinyin->permalink($data['title'], '');
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue