diff --git a/app/Models/Option.php b/app/Models/Option.php new file mode 100755 index 00000000..3cc7d429 --- /dev/null +++ b/app/Models/Option.php @@ -0,0 +1,51 @@ +where("k", $k)->first()?->v; + + return $v; + } + + public static function _list($sThisName) + { + $oSelf = self::where("this_name", $sThisName)->get(); + + return self::_filterList($oSelf); + } + +// public static function _limit($sThisName, $iSkip, $iTake) +// { +// $oSelf = self::where("this_name", $sThisName)->skip($iSkip)->take($iTake)->get(); +// +// return self::__filterList($oSelf); +// } + + public static function _filter($oOption) + { + $arr = []; + $arr[$oOption->this_name."#".$oOption->k] = $oOption->v; + + return $arr; + } + + public static function _filterList($oOption) + { + $arr = []; + foreach ($oOption as $oOptionRow) { + $arr[] = self::_filter($oOptionRow); + } + + return $arr; + } + +} diff --git a/app/Services/TG/Hook/Mod/Blade.php b/app/Services/TG/Hook/Mod/Blade.php index bd310b09..1496d4c4 100644 --- a/app/Services/TG/Hook/Mod/Blade.php +++ b/app/Services/TG/Hook/Mod/Blade.php @@ -1,207 +1,30 @@ $length) { - return mb_substr($string, 0, $length) . '...'; // 添加省略号 - } - return $string; - } - - private function _filter($oBladeRow) - { - $oBladeRow->content = $this->subStr($oBladeRow->content); - unset($oBladeRow->id); - - return $oBladeRow; - } - - private function filter($oBlade, $sMod = "row") + private $oDDT; + + public function __construct($aUpdate) { - if ($sMod == "row") { - - $oBlade = $this->_filter($oBlade); - - } else if ($sMod == "list") { - foreach ($oBlade as &$oBladeRow) { - $oBladeRow = $this->_filter($oBladeRow); - } - - } - return $oBlade; + $this->oDDT = new DDT(new ModelBlade()); + $this->oDDT->_setPrimaryKey("code"); // 可选,默认id + $this->oDDT->_setStrField(["content"]); // 可选,指定长文本字段 + $this->oDDT->_setThisName("blade"); // 必须,me用,正常就是类名,只不过后期没准改名,所以就这里写死 + } - public function List() + public function __call($sName, $aArg) { - $oBlade = ModelBlade::all(); - $oBlade = $this->filter($oBlade, "list"); - return $this->toJson($oBlade); - } - - public function Find($aParam) - { - $sField = $aParam["aOption"][1] ?? "id"; - $sValue = $aParam["aArg"][1] ?? false; + return $this->oDDT->$sName($aArg[0]); - if ($sValue == "?") { - return "/blade#find__{field?} {value}"; - } - - $oBlade = ModelBlade::where($sField, $sValue)->first(); - - return $this->toJson($oBlade); - } - - public function Content($aParam) - { - $sField = $aParam["aOption"][1] ?? "code"; - $sValue = $aParam["aArg"][1] ?? false; - - if ($sValue == "?") { - return "/blade#content__{field?} {value}"; - } - - $oBlade = ModelBlade::where($sField, $sValue)->first(); - - return $oBlade->content; - } - - public function Like($aParam) - { - $sField = $aParam["aOption"][1] ?? false; - $sValue = $aParam["aArg"][1] ?? false; - - if ($sValue == "?") { - return "/blade#like__{field} {value}"; - } - - if (!$sField) { - return "需要field"; - } - - if (!$sValue) { - return "需要value"; - } - - $oBlade = ModelBlade::where($sField, "like", "%".$sValue."%")->get(); - - $oBlade = $this->filter($oBlade); - - return $this->toJson($oBlade); - } - - public function Add($aParam) - { - $sCode = $aParam["aArg"][1] ?? false; - - if ($sCode == "?") { - return "/blade#add "; - } - - if (!$sCode) { - return "需要code"; - } - - $bExists = ModelBlade::where("code", $sCode)->exists(); - if ($bExists) { - return "code以存在"; - } - - $oBlade = new ModelBlade(); - $oBlade->code = $sCode; - $oBlade->save(); - - $aParam["aOption"][1] = "code"; - $aParam["aArg"][1] = $sCode; - return $this->Find($aParam); - } - - public function Del($aParam) - { - $sCode = $aParam["aArg"][1] ?? false; - $sWhereField = $aParam["aOption"][1] ?? false; - - if ($sCode == "?") { - return "/blade#del__ "; - } - - if (!$sCode) { - return "需要code"; - } - - $oBlade = ModelBlade::where("code", $sCode); - - if (!$oBlade->exists()) { - return "没有这个code"; - } - - $r = $oBlade->delete(); - - return $r; - } - - public function Set($aParam) - { - $sSetValue = $aParam["aArg"] ?? false; - $sSetValue = implode(" ", $sSetValue); - - if ($sSetValue == "?") { - $tmp = "/blade#set______ "; - $tmp .= "\n /blade#set____ "; - return $tmp; - } - - // 有第三参数说明是findSet模式 - if (isset($aParam["aOption"][3])) { - $sWhereField = $aParam["aOption"][1] ?? false; - $sWhereValue = $aParam["aOption"][2] ?? false; - $sSetField = $aParam["aOption"][3] ?? false; - $sMod = "findSet"; - } else { - $sWhereField = "code"; - $sWhereValue = $aParam["aOption"][1] ?? false; - $sSetField = $aParam["aOption"][2] ?? false; - $sMod = "set"; - } - - if (!$sWhereField) { - return "需要whereField"; - } - - if (!$sWhereValue) { - return "需要whereValue"; - } - - if (!$sSetField) { - return "需要setValue"; - } - - $oBlade = ModelBlade::where($sWhereField, $sWhereValue)->get(); - - if ($oBlade->isEmpty()) { - return "没找到这个blade"; - } - - $i = 0; - foreach ($oBlade as $oBladeRow) { - $oBladeRow->$sSetField = $sSetValue; - $oBladeRow->save(); - $i++; - } - - if ($i == 1) { - $aParam["aOption"][1] = "code"; - $aParam["aArg"][1] = $oBladeRow->code; - return $this->find($aParam); - } - - return "影响".$i."条数据"; } } diff --git a/app/Services/TG/Hook/Mod/BladeOld.php b/app/Services/TG/Hook/Mod/BladeOld.php new file mode 100644 index 00000000..bd310b09 --- /dev/null +++ b/app/Services/TG/Hook/Mod/BladeOld.php @@ -0,0 +1,207 @@ + $length) { + return mb_substr($string, 0, $length) . '...'; // 添加省略号 + } + return $string; + } + + private function _filter($oBladeRow) + { + $oBladeRow->content = $this->subStr($oBladeRow->content); + unset($oBladeRow->id); + + return $oBladeRow; + } + + private function filter($oBlade, $sMod = "row") + { + + if ($sMod == "row") { + + $oBlade = $this->_filter($oBlade); + + } else if ($sMod == "list") { + foreach ($oBlade as &$oBladeRow) { + $oBladeRow = $this->_filter($oBladeRow); + } + + } + return $oBlade; + } + + public function List() + { + $oBlade = ModelBlade::all(); + $oBlade = $this->filter($oBlade, "list"); + + return $this->toJson($oBlade); + } + + public function Find($aParam) + { + $sField = $aParam["aOption"][1] ?? "id"; + $sValue = $aParam["aArg"][1] ?? false; + + if ($sValue == "?") { + return "/blade#find__{field?} {value}"; + } + + $oBlade = ModelBlade::where($sField, $sValue)->first(); + + return $this->toJson($oBlade); + } + + public function Content($aParam) + { + $sField = $aParam["aOption"][1] ?? "code"; + $sValue = $aParam["aArg"][1] ?? false; + + if ($sValue == "?") { + return "/blade#content__{field?} {value}"; + } + + $oBlade = ModelBlade::where($sField, $sValue)->first(); + + return $oBlade->content; + } + + public function Like($aParam) + { + $sField = $aParam["aOption"][1] ?? false; + $sValue = $aParam["aArg"][1] ?? false; + + if ($sValue == "?") { + return "/blade#like__{field} {value}"; + } + + if (!$sField) { + return "需要field"; + } + + if (!$sValue) { + return "需要value"; + } + + $oBlade = ModelBlade::where($sField, "like", "%".$sValue."%")->get(); + + $oBlade = $this->filter($oBlade); + + return $this->toJson($oBlade); + } + + public function Add($aParam) + { + $sCode = $aParam["aArg"][1] ?? false; + + if ($sCode == "?") { + return "/blade#add "; + } + + if (!$sCode) { + return "需要code"; + } + + $bExists = ModelBlade::where("code", $sCode)->exists(); + if ($bExists) { + return "code以存在"; + } + + $oBlade = new ModelBlade(); + $oBlade->code = $sCode; + $oBlade->save(); + + $aParam["aOption"][1] = "code"; + $aParam["aArg"][1] = $sCode; + return $this->Find($aParam); + } + + public function Del($aParam) + { + $sCode = $aParam["aArg"][1] ?? false; + $sWhereField = $aParam["aOption"][1] ?? false; + + if ($sCode == "?") { + return "/blade#del__ "; + } + + if (!$sCode) { + return "需要code"; + } + + $oBlade = ModelBlade::where("code", $sCode); + + if (!$oBlade->exists()) { + return "没有这个code"; + } + + $r = $oBlade->delete(); + + return $r; + } + + public function Set($aParam) + { + $sSetValue = $aParam["aArg"] ?? false; + $sSetValue = implode(" ", $sSetValue); + + if ($sSetValue == "?") { + $tmp = "/blade#set______ "; + $tmp .= "\n /blade#set____ "; + return $tmp; + } + + // 有第三参数说明是findSet模式 + if (isset($aParam["aOption"][3])) { + $sWhereField = $aParam["aOption"][1] ?? false; + $sWhereValue = $aParam["aOption"][2] ?? false; + $sSetField = $aParam["aOption"][3] ?? false; + $sMod = "findSet"; + } else { + $sWhereField = "code"; + $sWhereValue = $aParam["aOption"][1] ?? false; + $sSetField = $aParam["aOption"][2] ?? false; + $sMod = "set"; + } + + if (!$sWhereField) { + return "需要whereField"; + } + + if (!$sWhereValue) { + return "需要whereValue"; + } + + if (!$sSetField) { + return "需要setValue"; + } + + $oBlade = ModelBlade::where($sWhereField, $sWhereValue)->get(); + + if ($oBlade->isEmpty()) { + return "没找到这个blade"; + } + + $i = 0; + foreach ($oBlade as $oBladeRow) { + $oBladeRow->$sSetField = $sSetValue; + $oBladeRow->save(); + $i++; + } + + if ($i == 1) { + $aParam["aOption"][1] = "code"; + $aParam["aArg"][1] = $oBladeRow->code; + return $this->find($aParam); + } + + return "影响".$i."条数据"; + } + +} diff --git a/app/Services/TG/Hook/Mod/DDT.php b/app/Services/TG/Hook/Mod/DDT.php index 6dcccd97..e86bb10b 100644 --- a/app/Services/TG/Hook/Mod/DDT.php +++ b/app/Services/TG/Hook/Mod/DDT.php @@ -6,6 +6,7 @@ namespace App\Services\TG\Hook\Mod; //use App\Services\TomTool\Http; //use App\Models\BladeJctj as ModelBladeJctj; use App\Models\Me as ModelMe; +use App\Models\Option as ModelOption; class DDT extends Base { @@ -13,15 +14,16 @@ class DDT extends Base { public $sPrimaryKey = "id"; public $iStrMaxLen = 50; public $aStrField = []; - public $sMe; + public $sThisName; - public function __construct($oModelSelf) + public function __construct($oModelSelf = false) { $this->_setModel($oModelSelf); } + //// 定义系列 public function _setStrMaxLen($iStrMaxLen) { $this->iStrMaxLen = $iStrMaxLen; @@ -32,11 +34,130 @@ class DDT extends Base { $this->aStrField = $aStrField; } - public function _setMe($sMe) + public function _setThisName($sThisName) { - $this->sMe = $sMe; + $this->sThisName = $sThisName; } + + public function _setModel($oModelSelf) + { + $this->oModelSelf = $oModelSelf; + } + + public function _setPrimaryKey($key) + { + $this->sPrimaryKey = $key; + } + //// 定义系列 end + + //// option 系列 + public function option($aParam) + { + + $aOption = ModelOption::_list($this->sThisName); + + return $this->toJson($aOption); + } + + public function optionAdd($aParam) + { + $k = $aParam["aArg"][1] ?? false; + $v = $aParam["aArg"][2] ?? false; + + if ($k == "?") { + return "#optionAdd {k} {v}"; + } + + if (!$k) { + return "需要k"; + } + + if (!$v) { + return "需要v"; + } + + $oOption = new ModelOption(); + $oOption->this_name = $this->sThisName; + $oOption->k = $k; + $oOption->v = $v; + $oOption->save(); + + return $this->toJson(ModelOption::_filter($oOption)); + } + + public function optionSet($aParam) + { + $k = $aParam["aOption"][1] ?? false; + $v = $aParam["aArg"][1] ?? false; + + if ($v == "?") { + return "#optionSet__{k} {v}"; + } + + if (!$k) { + return "需要k"; + } + + if (!$v) { + return "需要v"; + } + + $oOption = ModelOption::where("this_name", $this->sThisName)->where("k", $k)->first(); + + if (!$oOption) { + return "没找到这个"; + } + + $oOption->v = $v; + $oOption->save(); + + return $this->toJson(ModelOption::_filter($oOption)); + } + + public function optionDel($aParam) + { + $k = $aParam["aArg"][1] ?? false; + $is_done = $aParam["is_done"] ?? false; + + if ($k == "?") { + return "#optionDel {k}"; + } + + if (!$k) { + return "需要k"; + } + + $oOption = ModelOption::where("this_name", $this->sThisName)->where("k", $k)->first(); + + if (!$oOption) { + return "没找到这个"; + } + + if ($is_done === false) { + + $sMsg = "匹配以下,确认用optionDelDone()。"; + $sOption = $this->toJson($oOption); + + return $sMsg."\n\n".$sOption; + + } else if ($is_done === true) { + + $r = $oOption->delete(); + + return $r; + } + } + + public function optionDelDone($aParam) + { + $aParam["is_done"] = true; + + return $this->optionDel($aParam); + } + //// option 系列 end + + //// 辅助系列 private function filterList($oSelfList) { foreach ($oSelfList as &$oSelfListRow) { @@ -67,10 +188,16 @@ class DDT extends Base { return $str; } + //// 辅助系列 end + //// me系列 public function me() { - $oMe = ModelMe::where("class", $this->sMe)->get(); + $oMe = ModelMe::where("class", $this->sThisName)->get(); + + if ($oMe->isEmpty()) { + return "空"; + } return $this->meToStr_list($oMe); } @@ -89,7 +216,7 @@ class DDT extends Base { } $oMe = new ModelMe(); - $oMe->class = $this->sMe; + $oMe->class = $this->sThisName; $oMe->rag = $sRag; $oMe->save(); @@ -184,6 +311,7 @@ class DDT extends Base { return "删除".$i."条数据"; } } + //// me系列 end private function filterRow($oSelfRow) { @@ -205,16 +333,6 @@ class DDT extends Base { return $input; } - - public function _setModel($oModelSelf) - { - $this->oModelSelf = $oModelSelf; - } - - public function _setPrimaryKey($key) - { - $this->sPrimaryKey = $key; - } public function list() { @@ -434,7 +552,9 @@ class DDT extends Base { // tomd($sTable, 1); // $columns = \DB::select("SHOW FULL COLUMNS FROM blade"); $columns = \DB::select("SHOW CREATE TABLE `{$sTable}`"); - tomd($columns[0]->{"Create Table"}, 1); + + return $this->toJson($columns[0]->{"Create Table"}); +// tomd($columns[0]->{"Create Table"}, 1); } } diff --git a/app/Services/TG/Hook/Mod/Db.php b/app/Services/TG/Hook/Mod/Db.php new file mode 100644 index 00000000..47c5b6d2 --- /dev/null +++ b/app/Services/TG/Hook/Mod/Db.php @@ -0,0 +1,44 @@ +{"Create Table"}; + } + +} diff --git a/app/Services/TG/Hook/Mod/Jctj.php b/app/Services/TG/Hook/Mod/Jctj.php index 5beb1394..6357848d 100644 --- a/app/Services/TG/Hook/Mod/Jctj.php +++ b/app/Services/TG/Hook/Mod/Jctj.php @@ -16,7 +16,7 @@ class Jctj extends Base { $this->oDDT = new DDT(new ModelBladeJctj()); $this->oDDT->_setPrimaryKey("id"); // 可选,默认id $this->oDDT->_setStrField(["content"]); // 可选,指定长文本字段 - $this->oDDT->_setMe("jctj"); // 必须,me用,正常就是类名,只不过后期没准改名,所以就这里写死 + $this->oDDT->_setThisName("jctj"); // 必须,me用,正常就是类名,只不过后期没准改名,所以就这里写死 } diff --git a/app/Services/TG/Hook/Mod/JctjOption.php b/app/Services/TG/Hook/Mod/JctjOption.php index 61b83005..24d0d5ff 100644 --- a/app/Services/TG/Hook/Mod/JctjOption.php +++ b/app/Services/TG/Hook/Mod/JctjOption.php @@ -16,6 +16,7 @@ class JctjOption extends Base { $this->aUpdate = $aUpdate; $this->oDDT = new DDT(new ModelBladeJctjOption()); $this->oDDT->_setPrimaryKey("k"); + $this->oDDT->_setThisName("jctj_option"); // $this->oDDT->_setStrField(["content"]); } diff --git a/app/Services/TG/Hook/Mod/Upload.php b/app/Services/TG/Hook/Mod/Upload.php new file mode 100644 index 00000000..fc27023c --- /dev/null +++ b/app/Services/TG/Hook/Mod/Upload.php @@ -0,0 +1,231 @@ +oDDT = new DDT(); + $this->oDDT->_setPrimaryKey("id"); // 可选,默认id +// $this->oDDT->_setStrField(["content"]); // 可选,指定长文本字段 + $this->oDDT->_setThisName("upload"); // 必须,me用,正常就是类名,只不过后期没准改名,所以就这里写死 + + } + + public function __call($sName, $aArg) + { + + return $this->oDDT->$sName($aArg[0]); + + } + + public function limit($aParam) + { + $iSkip = $aParam["aArg"][1] ?? 0; + $iTake = $aParam["aArg"][2] ?? 0; + $sLike = $aParam["like"] ?? ''; + $isDel = $aParam["is_del"] ?? false; + + if ($iSkip == "?") { + return "#limit {skip} {take}"; + } + + if (!$iTake) { + $iTake = ModelOption::_hit("upload", "limit"); + } + +// if (!$iSkip) { +// return "需要skip"; +// } + + if (!$iTake) { + return "需要take"; + } + + $t = $this->getFileList($iSkip, $iTake, $sLike, $isDel); + + return $t; + + } + + public function page($aParam) + { + $iPage = $aParam["aArg"][1] ?? 1; + $sLike = $aParam["like"] ?? ''; + + if ($iPage == "?") { + return "#page {page:defaut=1}"; + } + + $iLimit = ModelOption::_hit("upload", "limit") ?? 0; + + if (!$iLimit) { + return "需要option里的limit值"; + } + + $iPageTrue = $iPage - 1; + + $iSkip = $iPageTrue * $iLimit; + + $aParam["aArg"][1] = $iSkip; + $aParam["aArg"][2] = $iLimit; + + return $this->limit($aParam); + } + + public function like($aParam) + { + $iPage = $aParam["aOption"][1] ?? 1; + $sLike = $aParam["aArg"][1] ?? false; +// $is_del = $aParam + + if ($sLike == "?") { + return "#like {like}"; + } + + if (!$sLike) { + return "需要like"; + } + + $aParam["like"] = $sLike; + $aParam["aArg"][1] = $iPage; + $aParam["aOption"] = []; + + return $this->page($aParam); + } + + public function list($aParam) + { + return $this->page($aParam); + } + + public function del($aParam) + { + $sName = $aParam["aArg"][1] ?? false; + + if ($sName == "?") { + return "#del {name}"; + } + + if (!$sName) { + return "需要name"; + } + + $filePath = 'upload/'.$sName; // 替换为你要删除的文件路径 + + if (file_exists($filePath)) { + if (unlink($filePath)) { + return "文件已成功删除。"; + } else { + return "删除文件时出错。"; + } + } else { + return "文件不存在。"; + } + } + + public function show($aParam) + { + $sName = $aParam["aArg"][1] ?? false; + + if ($sName == "?") { + return "#show {name}"; + } + + if (!$sName) { + return "需要name"; + } + + $str = ""; + $str .= $sName."\n\n"; + $str .= ""; + + return $str; + } + + public function likeDel($aParam) + { + $aParam["is_del"] = true; + + return $this->like($aParam); + } + + private function getFileList($skip = 0, $take = 10, $searchTerm = '', $is_del = false) // 添加 is_del 参数 + { + $directory = 'upload'; + + if (is_dir($directory)) { + $str = ""; + $str .= ""; + $str .= ""; // 添加表头 + + $files = scandir($directory); + $count = 0; // 计数器 + $id = 1; // ID 从1开始 + $countDel = 0; + + foreach ($files as $file) { + // 排除当前目录(.)和上级目录(..) + if ($file !== '.' && $file !== '..') { + // 如果提供了搜索关键字,检查文件名是否包含该关键字 + if ($searchTerm && stripos($file, $searchTerm) === false) { + continue; // 不包含关键字则跳过 + } + + // 如果 is_del 为 true,删除匹配的文件 + if ($is_del) { + $filePath = $directory . '/' . $file; + if (file_exists($filePath)) { + unlink($filePath); // 删除文件 + $countDel++; + } + continue; // 删除后跳过当前循环 + } + + // 跳过指定数量的文件 + if ($count < $skip) { + $count++; + continue; // 跳过当前循环 + } + + // 检查是否超过取的限制 + if ($count >= $skip + $take) { + break; // 超过限制则退出循环 + } + + $str .= ""; + $str .= ""; // 输出 ID + $str .= ""; + $str .= ""; + $str .= ""; + + $count++; // 增加计数 + $id++; // 增加 ID + } + } + + $str .= "
NO文件名预览
".$id."".$file."
"; + + if ($is_del === true) { + return $countDel; + } else { + return $str; + } + + } else { + return "目录不存在。"; + } + } + + + + +} diff --git a/public/upload/clash.xcf b/public/upload/clash.xcf deleted file mode 100644 index 8e0ee897..00000000 Binary files a/public/upload/clash.xcf and /dev/null differ diff --git a/public/upload/qweqwe.xcf b/public/upload/qweqwe.xcf deleted file mode 100644 index 4b2811f3..00000000 Binary files a/public/upload/qweqwe.xcf and /dev/null differ diff --git a/public/upload/xcvxcv.xcf b/public/upload/xcvxcv.xcf deleted file mode 100644 index b75c826c..00000000 Binary files a/public/upload/xcvxcv.xcf and /dev/null differ diff --git a/public/upload/无标题.xcf b/public/upload/无标题.xcf deleted file mode 100644 index 70fe18e7..00000000 Binary files a/public/upload/无标题.xcf and /dev/null differ diff --git a/resources/views/cmd.blade.php b/resources/views/cmd.blade.php index 1405b0fd..140e5d77 100644 --- a/resources/views/cmd.blade.php +++ b/resources/views/cmd.blade.php @@ -19,7 +19,7 @@ pre { } .cmd_text { - width:380px; + width:500px; // font-size:16px; //background-color:#222; // border:1px solid cyan; @@ -185,24 +185,20 @@ a{ - +
- +
- - - + + + +
- - - +
@@ -250,7 +246,8 @@ a{