├── .gitignore ├── README.md ├── composer.json ├── resources ├── assets │ ├── css │ │ └── index.css │ └── js │ │ └── index.js └── views │ └── index.blade.php ├── src ├── DistpickerServiceProvider.php ├── Form │ └── Distpicker.php ├── Http │ ├── Controllers │ │ └── DistpickerController.php │ └── routes.php ├── Models │ └── ChinaArea.php └── Setting.php ├── updates ├── ChinaAreaTableSeeder.php └── create_china_areas_table.php └── version.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | phpunit.phar 3 | /vendor 4 | composer.phar 5 | composer.lock 6 | *.project 7 | .idea/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dcat Admin Extension 2 | 3 | ### 演示地址 4 | [demo: http://dcat.weiwait.cn (admin:admin)](http://dcat.weiwait.cn/admin/demo-distpickers/create 'user: admin psw: admin') 5 | 6 | ### 通过 composer 安装扩展 7 | ```shell 8 | composer require weiwait/dcat-distpicker 9 | ``` 10 | ### 发布静态资源 11 | ```shell 12 | php artisan vendor:publish --tag=weiwait.dcat-distpicker 13 | ``` 14 | 15 | ### 更新 dcat-admin ide-helper 16 | ```shell 17 | php artisan admin:ide-helper 18 | ``` 19 | 20 | ```php 21 | $form->distpicker(['province', 'city', 'district'], 'label') 22 | ->detail('detail') // 使用地址详细 23 | ->coordinate(['longitude', 'latitude']) // 使用经度纬度坐标 24 | ->height(500) // 设置地图高度 默认300 25 | ->disableMap(); // 关闭地图 26 | ``` 27 | 28 | ![示例图片](https://github.com/weiwait/images/blob/main/dcat-distpicker.png?raw=true) 29 | 32 | 33 | ### Dcat-admin 扩展列表 34 | 1. [单图裁剪](https://github.com/weiwait/dcat-cropper) 35 | 2. [区划级联+坐标拾取](https://github.com/weiwait/dcat-distpicker) 36 | 3. [smtp快速便捷配置](https://github.com/weiwait/dcat-smtp) 37 | 4. [sms channel 快速便捷配置](https://github.com/weiwait/dcat-easy-sms) 38 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "weiwait/dcat-distpicker", 3 | "alias": "", 4 | "description": "省-市-区县级联 + 坐标拾取", 5 | "type": "library", 6 | "keywords": ["dcat-admin", "extension", "地区选择", "省市区", "坐标拾取"], 7 | "homepage": "https://github.com/weiwait/dcat-distpicker", 8 | "license": "MIT", 9 | "authors": [ 10 | { 11 | "name": "weiwait", 12 | "email": "mail@weiwait.cn" 13 | } 14 | ], 15 | "require": { 16 | "php": ">=7.1.0", 17 | "dcat/laravel-admin": "~2.0" 18 | }, 19 | "autoload": { 20 | "psr-4": { 21 | "Weiwait\\Distpicker\\": "src/" 22 | } 23 | }, 24 | "extra": { 25 | "dcat-admin": "Weiwait\\Distpicker\\DistpickerServiceProvider", 26 | "laravel": { 27 | "providers": [ 28 | "Weiwait\\Distpicker\\DistpickerServiceProvider" 29 | ] 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /resources/assets/css/index.css: -------------------------------------------------------------------------------- 1 | .extension-demo { 2 | font-size: 1.3rem; 3 | cursor: pointer; 4 | } -------------------------------------------------------------------------------- /resources/assets/js/index.js: -------------------------------------------------------------------------------- 1 | (function (w, $) { 2 | function ExtensionDemo(options) { 3 | this.options = $.extend({ 4 | $el: $('.demo'), 5 | }, options); 6 | 7 | this.init(this.options); 8 | } 9 | 10 | ExtensionDemo.prototype = { 11 | init: function (options) { 12 | options.$el.on('click', function () { 13 | Dcat.success($(this).text()); 14 | }); 15 | 16 | console.log('Done.'); 17 | }, 18 | }; 19 | 20 | $.fn.extensionDemo = function (options) { 21 | options = options || {}; 22 | options.$el = $(this); 23 | 24 | return new ExtensionDemo(options); 25 | }; 26 | })(window, jQuery); -------------------------------------------------------------------------------- /resources/views/index.blade.php: -------------------------------------------------------------------------------- 1 |
2 | @php(is_null($value) ? $value = array_fill_keys($column, '') : $value = array_combine($column, $value)) 3 | 4 | 5 |
6 | @include('admin::form.error') 7 | 8 |
9 | @if(isset($column[0])) 10 |
11 | {{--
--}} 12 | {{-- --}} 16 | {{-- --}} 24 | {{--
--}} 25 | 26 | {{-- --}} 27 | 28 | 38 | 39 |
40 | @endif 41 | @if(isset($column[1])) 42 |
43 | {{--
--}} 44 | {{-- --}} 48 | {{-- --}} 50 | {{--
--}} 51 | 52 | {{-- --}} 53 | 54 | 55 | @if($value[$column[1]]) 56 | 59 | @endif 60 | 61 | @if($value[$column[1]]) 62 | @foreach($cities as $city) 63 | @if($city->code == $value[$column[1]]) 64 | 65 | @elseif($city->pcode == $value[$column[0]]) 66 | 67 | @endif 68 | @endforeach 69 | @endif 70 | 71 |
72 | @endif 73 | @if(isset($column[2])) 74 |
75 | {{--
--}} 76 | {{-- --}} 80 | {{-- --}} 82 | {{--
--}} 83 | 84 | {{-- --}} 86 | 87 | 88 | @if($value[$column[2]]) 89 | 92 | @endif 93 | 94 | @if($value[$column[2]]) 95 | @foreach($districts as $district) 96 | @if($district->code == $value[$column[2]]) 97 | 99 | @elseif($district->pcode == $value[$column[1]]) 100 | 101 | @endif 102 | @endforeach 103 | @endif 104 | 105 |
106 | @endif 107 | 108 | @if($enableCoordinate) 109 |
110 |
111 |
112 | 经度 113 |
114 | 117 |
118 |
119 | 120 |
121 |
122 |
123 | 纬度 124 |
125 | 128 |
129 |
130 | @endif 131 |
132 | 133 | @if($enableDetail) 134 |
135 |
136 | 详细 137 |
138 | 141 |
142 | 145 | 147 |
148 |
149 | @endif 150 | 151 | @if(!$disableMap) 152 |
153 | @endif 154 | 155 | @include('admin::form.help-block') 156 |
157 |
158 | 159 | 173 | {{----}} 174 | 175 | 407 | -------------------------------------------------------------------------------- /src/DistpickerServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishable(); 31 | } 32 | 33 | public function settingForm() 34 | { 35 | return new Setting($this); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Form/Distpicker.php: -------------------------------------------------------------------------------- 1 | areaId = 'id' . md5(join('', $column)); 41 | 42 | $this->addVariables(compact( 'provinces', 'cities', 'districts')); 43 | 44 | parent::__construct($column, $arguments); 45 | } 46 | 47 | public function coordinate(array $lngLat): Distpicker 48 | { 49 | $this->enableCoordinate = true; 50 | 51 | $this->column[] = $lngLat[0]; 52 | $this->column[] = $lngLat[1]; 53 | 54 | $this->longitudeColumn = $lngLat[0]; 55 | $this->latitudeColumn = $lngLat[1]; 56 | 57 | return $this; 58 | } 59 | 60 | public function detail(string $detail): Distpicker 61 | { 62 | $this->enableDetail = true; 63 | 64 | $this->column[] = $detail; 65 | 66 | $this->detailColumn = $detail; 67 | 68 | return $this; 69 | } 70 | 71 | public function height(int $height): Distpicker 72 | { 73 | $this->height = $height; 74 | 75 | return $this; 76 | } 77 | 78 | public function disableMap(bool $disable = true): Distpicker 79 | { 80 | $this->disableMap = $disable; 81 | 82 | return $this; 83 | } 84 | 85 | public function defaultVariables(): array 86 | { 87 | return array_merge(parent::defaultVariables(), [ 88 | 'height' => $this->height, 89 | 'areaId' => $this->areaId, 90 | 'enableDetail' => $this->enableDetail, 91 | 'detailColumn' => $this->detailColumn, 92 | 'enableCoordinate' => $this->enableCoordinate, 93 | 'longitudeColumn' => $this->longitudeColumn, 94 | 'latitudeColumn' => $this->latitudeColumn, 95 | 'disableMap' => $this->disableMap, 96 | ]); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/Http/Controllers/DistpickerController.php: -------------------------------------------------------------------------------- 1 | title('Title') 15 | ->description('Description') 16 | ->body(Admin::view('weiwait.distpicker::index')); 17 | } 18 | } -------------------------------------------------------------------------------- /src/Http/routes.php: -------------------------------------------------------------------------------- 1 | where('level', 1)->get(); 14 | } 15 | 16 | public static function cities() 17 | { 18 | return self::query()->where('level', 2)->get(); 19 | } 20 | 21 | public static function districts() 22 | { 23 | return self::query()->where('level', 3)->get(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Setting.php: -------------------------------------------------------------------------------- 1 | text('key1')->required(); 12 | $this->text('key2')->required(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /updates/create_china_areas_table.php: -------------------------------------------------------------------------------- 1 | id('code'); 18 | $table->string('name')->comment('地区'); 19 | $table->unsignedTinyInteger('level')->index(); 20 | $table->unsignedBigInteger('pcode')->index()->comment('上级区划'); 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::dropIfExists('china_areas'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /version.php: -------------------------------------------------------------------------------- 1 | [ 5 | '省-市-区县级联 + 坐标拾取 学习版', 6 | 'create_china_areas_table.php', 7 | 'ChinaAreaTableSeeder.php', 8 | ], 9 | '1.0.5' => [ 10 | '修复字段单独使用时更新错误', 11 | ] 12 | ]; 13 | --------------------------------------------------------------------------------