代码拉取完成,页面将自动刷新
<?php
/**
* 积木云渲染器
*
* @package XbCode
* @author 楚羽幽 <958416459@qq.com>
* @version 1.0
* @license Apache License 2.0
* @link http://www.xbcode.net
* @document http://doc.xbcode.net
*/
namespace plugin\xbDevExample\app\admin;
use plugin\xbCode\XbController;
use support\Cache;
/**
* 控制器基类
* @copyright 贵州小白基地网络科技有限公司
* @author 楚羽幽 cy958416459@qq.com
*/
class BaseController extends XbController
{
/**
* 获取普通列表数据
* @copyright 贵州积木云网络科技有限公司
* @author 楚羽幽 958416459@qq.com
*/
protected function getList()
{
$key = request()->path();
$key = ltrim($key, '/');
$key = rtrim($key,'/');
$key = str_replace('/', '_', $key);
$key = str_replace('.', '_', $key);
$key = str_replace('\\', '_', $key);
$data = Cache::get($key);
if (empty($data)) {
$data = $this->generate();
Cache::set($key, $data, 60 * 60 * 24);
}
return $data;
}
/**
* 获取树形列表数据
* @copyright 贵州积木云网络科技有限公司
* @author 楚羽幽 958416459@qq.com
*/
protected function getTreeList()
{
$data = $this->getList();
// 每10条数据作为一组,children作为子级
$groupedData = [];
foreach ($data as $item) {
$groupIndex = floor(($item['id'] - 1) / 10);
if (!isset($groupedData[$groupIndex])) {
$groupedData[$groupIndex] = array_merge($item, [
'id'=> $groupIndex + 1,
'children' => []
]);
}
$groupedData[$groupIndex]['children'][] = $item;
}
// 重置索引
$data = array_values($groupedData);
return $data;
}
/**
* 生成模拟数据
* @return array<array>
* @copyright 贵州积木云网络科技有限公司
* @author 楚羽幽 958416459@qq.com
*/
private function generate()
{
$faker = \Poppy\Faker\Factory::create('zh_CN');
$sexText = ['男生', '女生', '保密'];
for ($i = 0; $i < 50; $i++) {
$data[$i]['id'] = $i + 1;
$data[$i]['name'] = $faker->name;
$sex = $faker->numberBetween(0, 2);
$data[$i]['sex'] = $sex;
$data[$i]['sex_text'] = $sexText[$sex];
$age = $faker->numberBetween(16, 50);
$data[$i]['age'] = $age;
$data[$i]['age_text'] = $age. '岁';
$data[$i]['idnumber'] = $faker->idNumber;
$data[$i]['address'] = "{$faker->state} {$faker->address}";
$data[$i]['phone'] = $faker->phoneNumber;
$data[$i]['email'] = $faker->email;
$data[$i]['balance'] = $faker->randomFloat(2,0, 1000000);
$data[$i]['create_at'] = $faker->dateTimeBetween('-30 years', 'now')->format('Y-m-d H:i:s') ?? '';
}
return $data;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。