mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2026-07-09 17:41:05 +08:00
Compare commits
4 Commits
c27f75b4d5
...
84442d5e62
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84442d5e62 | ||
|
|
cf6ab16aa8 | ||
|
|
d6f7a28623 | ||
|
|
9189ceb52f |
@ -3,57 +3,110 @@
|
||||
// 禁止 HTTP 访问脚本文件
|
||||
PHP_SAPI === 'cli' or die('Can only run in CLI mode.');
|
||||
|
||||
// 从腾讯地址接口获取数据
|
||||
$url = 'https://apis.map.qq.com/ws/district/v1/list?key=AVDBZ-VXMC6-VD2SU-M7DX2-TGSV7-WVF3U';
|
||||
$result = json_decode(file_get_contents($url), true)['result'];
|
||||
new class() {
|
||||
|
||||
// 生成数据字典(方便查询)
|
||||
$maps = [];
|
||||
foreach ($result as $items) foreach ($items as $item) {
|
||||
$id = preg_replace('#(0000$|00$)#', '', $item['id']);
|
||||
$item['list'] = [];
|
||||
$item['location'] = join(',', $item['location'] ?? []);
|
||||
unset($item['cidx'], $item['pinyin']);
|
||||
$maps[$id] = $item;
|
||||
}
|
||||
ksort($maps);
|
||||
private $tree = [];
|
||||
|
||||
// 根据名称生成数据树
|
||||
$items = [];
|
||||
foreach ($maps as $key => $map) {
|
||||
[$c1, $c2, $c3] = str_split("{$key}0000", 2);
|
||||
$pname = $maps[$c1]['fullname'] ?? '';
|
||||
$cname = $maps[$c1 . $c2]['fullname'] ?? $pname;
|
||||
if ($c2 . $c3 === '0000') {
|
||||
$items[$pname] = $map;
|
||||
} elseif ($c3 === '00') {
|
||||
$items[$pname]['list'][$cname] = $map;
|
||||
} else {
|
||||
if (empty($items[$pname]['list'][$cname])) {
|
||||
$items[$pname]['list'][$cname] = $items[$pname];
|
||||
public function __construct()
|
||||
{
|
||||
$this->debug($this->initBd())->write();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化百度地址行政数据
|
||||
* @return void
|
||||
*/
|
||||
protected function initBd(): array
|
||||
{
|
||||
$url = 'https://api.map.baidu.com/api_region_search/v1/?keyword=%E5%85%A8%E5%9B%BD&sub_admin=3&ak=S7I1ewwAVr8r2MI3rnSKeF3R6GTCZiOo&extensions_code=1';
|
||||
$provs = json_decode(file_get_contents($url), true)['districts'][0]['districts'];
|
||||
foreach ($provs as &$prov) {
|
||||
$prov['list'] = $prov['districts'];
|
||||
foreach ($prov['list'] as &$city) {
|
||||
$city['list'] = $city['districts'];
|
||||
foreach ($city['list'] as &$area) {
|
||||
unset($area['level'], $area['list'], $area['districts']);
|
||||
}
|
||||
unset($city['level'], $city['districts']);
|
||||
}
|
||||
unset($prov['level'], $prov['districts']);
|
||||
}
|
||||
$items[$pname]['list'][$cname]['list'][] = $map;
|
||||
ksort($provs);
|
||||
return $this->tree = $provs;
|
||||
}
|
||||
}
|
||||
|
||||
// 生成插件数据(去除索引值)
|
||||
$data = [];
|
||||
$items = array_values($items);
|
||||
foreach ($items as &$prov) {
|
||||
$lines = [];
|
||||
$prov['list'] = array_values($prov['list']);
|
||||
foreach ($prov['list'] as &$city) {
|
||||
$city['list'] = array_values($city['list']);
|
||||
$lines[] = $city['fullname'] . ',' . join(',', array_column($city['list'], 'fullname'));
|
||||
/**
|
||||
* 初始化腾讯地址行政
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function initQq(array $data = []): array
|
||||
{
|
||||
$url = 'https://apis.map.qq.com/ws/district/v1/list?key=AVDBZ-VXMC6-VD2SU-M7DX2-TGSV7-WVF3U';
|
||||
foreach (json_decode(file_get_contents($url), true)['result'] as $items) foreach ($items as $item) {
|
||||
$data[$item['id']] = ['code' => $item['id'], 'name' => $item['fullname'], 'list' => []];
|
||||
}
|
||||
ksort($data);
|
||||
foreach ($data as $item) {
|
||||
[$k1, $k2, $k3] = str_split($item['code'], 2);
|
||||
// 整合省份数据
|
||||
if ($k2 + $k3 == 0) {
|
||||
$this->tree[$k1] = $item;
|
||||
}
|
||||
// 整合城市
|
||||
if ($k2 > 0 && $k3 == 0) {
|
||||
$this->tree[$k1]['list'][$k1 . $k2] = $item;
|
||||
ksort($this->tree[$k1]['list']);
|
||||
}
|
||||
// 整合区域
|
||||
if ($k2 > 0 && $k3 > 0) {
|
||||
unset($item['list']);
|
||||
if (!isset($this->tree[$k1]['list'][$k1 . $k2])) {
|
||||
$this->tree[$k1]['list'][$k1 . $k2] = array_merge($this->tree[$k1], ['list' => []]);
|
||||
}
|
||||
$this->tree[$k1]['list'][$k1 . $k2]['list'][$k1 . $k2 . $k3] = $item;
|
||||
ksort($this->tree[$k1]['list'][$k1 . $k2]['list']);
|
||||
}
|
||||
}
|
||||
return $this->tree;
|
||||
}
|
||||
$data[] = $prov['fullname'] . '$' . join('|', $lines);
|
||||
}
|
||||
|
||||
// 数据写入文件
|
||||
$jsonFile = __DIR__ . '/data.json';
|
||||
$scriptFile = dirname(__DIR__) . '/pcasunzips.js';
|
||||
$jsonContent = json_encode($items, JSON_UNESCAPED_UNICODE);
|
||||
$scriptContent = str_replace('__STRING__', join('#', $data), <<<EOL
|
||||
/**
|
||||
* 打印输出日志
|
||||
* @param array $data
|
||||
* @return $this
|
||||
*/
|
||||
private function debug(array $data)
|
||||
{
|
||||
ob_clean();
|
||||
header('Content-type:application/json');
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入更新文件
|
||||
* @return bool
|
||||
*/
|
||||
private function write(): bool
|
||||
{
|
||||
$data = [];
|
||||
$items = array_values($this->tree);
|
||||
foreach ($items as &$prov) {
|
||||
$line = [];
|
||||
$prov['list'] = array_values($prov['list']);
|
||||
foreach ($prov['list'] as &$city) {
|
||||
$city['list'] = array_values($city['list']);
|
||||
$line[] = $city['name'] . ',' . join(',', array_column($city['list'], 'name'));
|
||||
}
|
||||
$data[] = $prov['name'] . '$' . join('|', $line);
|
||||
}
|
||||
|
||||
// 数据写入文件
|
||||
$jsonFile = __DIR__ . '/data.json';
|
||||
$scriptFile = dirname(__DIR__) . ' /pcasunzips.js';
|
||||
$jsonContent = json_encode($items, JSON_UNESCAPED_UNICODE);
|
||||
$scriptContent = str_replace('__STRING__', join('#', $data), <<<EOL
|
||||
/********************************************************
|
||||
*** 加载脚本文件 ***
|
||||
<script src="pcasunzip.js"></script>
|
||||
@ -140,11 +193,9 @@ PCAS.SetA = function (PCA) {
|
||||
}), $(PCA.SelA).trigger('change')
|
||||
};
|
||||
EOL
|
||||
);
|
||||
);
|
||||
|
||||
// 写入区域文件
|
||||
if (file_put_contents($scriptFile, $scriptContent) && file_put_contents($jsonFile, $jsonContent)) {
|
||||
echo 'success';
|
||||
} else {
|
||||
echo 'error';
|
||||
}
|
||||
// 写入区域文件
|
||||
return file_put_contents($scriptFile, $scriptContent) && file_put_contents($jsonFile, $jsonContent);
|
||||
}
|
||||
};
|
||||
File diff suppressed because one or more lines are too long
2
public/static/plugs/jquery/pcasunzips.js
vendored
2
public/static/plugs/jquery/pcasunzips.js
vendored
File diff suppressed because one or more lines are too long
15
readme.md
15
readme.md
@ -113,43 +113,44 @@ ThinkAdmin 为 MIT 协议开源项目,安装使用或二次开发不受约束
|
||||
* 修改`JsonRpc`接口异常处理机制,当服务端绑定`Exception`时,客户端将能收到`error`消息及异常数据。
|
||||
* 修改`location.hash`访问机制,禁止直接访问外部`URL`资源链接,防止外部`XSS`攻击读取本地缓存数据。
|
||||
* 增加后台主题样式配置,支持全局默认+用户个性配置,需要更新`ThinkLibrary`,`static`,`admin`组件及模块。
|
||||
* 后台行政区域数据更新,由原来的腾讯地图数据切换为百度地图最新数据,需要更新`static`,数据库版需另行更新。
|
||||
|
||||
## 项目版本
|
||||
|
||||
体验账号及密码都是admin
|
||||
体验账号及密码都是 admin
|
||||
|
||||
### ThinkAdmin v6 基于 ThinkPHP 6.0 开发(后台权限基于注解实现)
|
||||
|
||||
* 在线体验地址:https://v6.thinkadmin.top
|
||||
* 在线体验地址:https://v6.thinkadmin.top (运行中)
|
||||
* Gitee 代码地址:https://gitee.com/zoujingli/ThinkAdmin/tree/v6
|
||||
* Github 代码地址:https://github.com/zoujingli/ThinkAdmin/tree/v6
|
||||
|
||||
### ThinkAdmin v5 基于 ThinkPHP 5.1 开发(后台权限基于注解实现)
|
||||
|
||||
* 在线体验地址:https://v5.thinkadmin.top
|
||||
* 在线体验地址:https://v5.thinkadmin.top (已停用)
|
||||
* Gitee 代码地址:https://gitee.com/zoujingli/ThinkAdmin/tree/v5
|
||||
* Github 代码地址:https://github.com/zoujingli/ThinkAdmin/tree/v5
|
||||
|
||||
### ThinkAdmin v4 基于 ThinkPHP 5.1 开发(不建议继续使用)
|
||||
|
||||
* 在线体验地址:https://v4.thinkadmin.top
|
||||
* 在线体验地址:https://v4.thinkadmin.top (已停用)
|
||||
* Gitee 代码地址:https://gitee.com/zoujingli/ThinkAdmin/tree/v4
|
||||
* Github 代码地址:https://github.com/zoujingli/ThinkAdmin/tree/v4
|
||||
|
||||
### ThinkAdmin v3 基于 ThinkPHP 5.1 开发(不建议继续使用)
|
||||
|
||||
* 在线体验地址:https://v3.thinkadmin.top
|
||||
* 在线体验地址:https://v3.thinkadmin.top (已停用)
|
||||
* Gitee 代码地址:https://gitee.com/zoujingli/ThinkAdmin/tree/v3
|
||||
* Github 代码地址:https://github.com/zoujingli/ThinkAdmin/tree/v3
|
||||
|
||||
### ThinkAdmin v2 基于 ThinkPHP 5.0 开发(不建议继续使用)
|
||||
|
||||
* 在线体验地址:https://v2.thinkadmin.top
|
||||
* 在线体验地址:https://v2.thinkadmin.top (已停用)
|
||||
* Gitee 代码地址:https://gitee.com/zoujingli/ThinkAdmin/tree/v2
|
||||
* Github 代码地址:https://github.com/zoujingli/ThinkAdmin/tree/v2
|
||||
|
||||
### ThinkAdmin v1 基于 ThinkPHP 5.0 开发(不建议继续使用)
|
||||
|
||||
* 在线体验地址:https://v1.thinkadmin.top
|
||||
* 在线体验地址:https://v1.thinkadmin.top (已停用)
|
||||
* Gitee 代码地址:https://gitee.com/zoujingli/ThinkAdmin/tree/v1
|
||||
* Github 代码地址:https://github.com/zoujingli/ThinkAdmin/tree/v1
|
||||
Loading…
x
Reference in New Issue
Block a user