<?php
namespace app\model;
use tpScriptVueCurd\base\model\BaseModel;
use tpScriptVueCurd\base\model\VueCurlModel;
use tpScriptVueCurd\field\DateField;
use tpScriptVueCurd\field\RadioField;
use tpScriptVueCurd\field\StringField;
use tpScriptVueCurd\field\TextField;
use tpScriptVueCurd\FieldCollection;
use tpScriptVueCurd\option\generate_table\GenerateTableOption;
use tpScriptVueCurd\option\ModelInfoAuth;
class User extends BaseModel
{
/**
* 表字段配置
* @return FieldCollection
*/
public function fields(): FieldCollection
{
return new FieldCollection([
StringField::init('name','姓名')->listShow(true)->required(true),
RadioField::init('sex', '性别')->items(['男', '女'])->listShow(true)->required(true),
DateField::init('date','出生日期')->listShow(true),
TextField::init('address', '住址'),
]);
}
/**
* 是否自动创建数据库表,当debug为false时,将不会执行
* @param GenerateTableOption $table
* @return bool
*/
public function generateTable(GenerateTableOption $table): bool
{
//当字段改变时,是否更改数据库表相关字段
$table->setModifyColumn(true);
return true;
}
/**
* 表的操作权限
* @param ModelInfoAuth $authCheck
*/
protected function authCheck(ModelInfoAuth $authCheck):void{
$authCheck->add=function (FieldCollection $field,self $info,?BaseModel $baseInfo){
return true;
};
$authCheck->edit=function (FieldCollection $field,self $info,?BaseModel $baseInfo){
return true;
};
$authCheck->show=function (FieldCollection $field,self $info,?BaseModel $baseInfo){
return true;
};
$authCheck->del=function (FieldCollection $field,self $info,?BaseModel $baseInfo){
return true;
};
}
/**
* 生成保存数据前(字段doSaveBeforeChecked前,doSaveBefore后)
*/
protected function doSaveDataBefore(FieldCollection $fields,array &$postData,bool $isExcelDo,int $id,?BaseModel $parentInfo,BaseModel $beforeInfo): void
{
parent::doSaveDataBefore($fields, $postData, $isExcelDo, $id,$parentInfo, $beforeInfo);
}
/**
* 生成保存数据后,还未保存(字段doSaveBeforeChecked前,doSaveBefore后)
*/
protected function doSaveDataAfter(array &$saveData,int $id,?BaseModel $parentInfo,BaseModel $beforeInfo): void
{
parent::doSaveDataAfter($saveData, $id,$parentInfo, $beforeInfo); // TODO: Change the autogenerated stub
}
/**
* 数据成功添加后
*/
protected function onAddAfter(BaseModel $info,array $postData,?BaseModel $parentInfo): void
{
parent::onAddAfter($info, $postData,$parentInfo);
}
/**
* 数据成功修改后
*/
protected function onEditAfter(BaseModel $info,array $postData,?BaseModel $parentInfo,BaseModel $beforeInfo): void
{
parent::onEditAfter($info, $postData,$parentInfo, $beforeInfo);
}
/**
* 数据删除前
* @param \think\model\Collection $delList
*/
protected function onDelBefore(\think\model\Collection $delList): void
{
}
/**
* 数据删除后
* @param \think\model\Collection $delList
*/
protected function onDelAfter(\think\model\Collection $delList): void
{
}
}