AuthRule.php 986 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace app\admin\model;
  3. use think\Cache;
  4. use think\Model;
  5. class AuthRule extends Model
  6. {
  7. // 开启自动写入时间戳字段
  8. protected $autoWriteTimestamp = 'int';
  9. // 定义时间戳字段名
  10. protected $createTime = 'createtime';
  11. protected $updateTime = 'updatetime';
  12. protected static function init()
  13. {
  14. self::beforeWrite(function ($row) {
  15. if (isset($_POST['row']) && is_array($_POST['row']) && isset($_POST['row']['condition'])) {
  16. $originRow = $_POST['row'];
  17. $row['condition'] = $originRow['condition'] ?? '';
  18. }
  19. });
  20. self::afterWrite(function ($row) {
  21. Cache::rm('__menu__');
  22. });
  23. }
  24. public function getTitleAttr($value, $data)
  25. {
  26. return __($value);
  27. }
  28. public function getMenutypeList()
  29. {
  30. return ['addtabs' => __('Addtabs'), 'dialog' => __('Dialog'), 'ajax' => __('Ajax'), 'blank' => __('Blank')];
  31. }
  32. }