优化地图标记,首次标记时展示小区边界

This commit is contained in:
cloud 2021-01-02 06:24:12 +08:00
parent 55ee58c372
commit 59fcc51a17
6 changed files with 696 additions and 21 deletions

View File

@ -1320,3 +1320,17 @@ li.village-list-item > p {
z-index: 9; z-index: 9;
display: none; display: none;
} }
@media (min-width: 992px) {
.modal-lgx {
max-width: 80%;
}
.modal-fill-in .modal-dialog.modal-lg > * {
width: 80%;
}
.h-500 {
height: 600px !important
}
}

View File

@ -29,6 +29,7 @@ var APPMAP;
this.selectCity = ''; this.selectCity = '';
this.selectDist = ''; this.selectDist = '';
this.address = ''; this.address = '';
this.placeName = '';
this.lngDom = {}; this.lngDom = {};
this.latDom = {}; this.latDom = {};
this.mapLng = CL.c.maplng || this.mapLng; this.mapLng = CL.c.maplng || this.mapLng;
@ -101,13 +102,13 @@ var APPMAP;
base.prototype.level = function () { base.prototype.level = function () {
var level = 12; var level = 12;
if (!this.isEmpty(this.selectProv)) if (!this.isEmpty(this.selectProv))
level = 10; level = 11;
if (!this.isEmpty(this.selectCity)) if (!this.isEmpty(this.selectCity))
level = 12; level = 13;
if (!this.isEmpty(this.selectDist)) if (!this.isEmpty(this.selectDist))
level = 14;
if (!this.isEmpty(this.selectDist) && !this.isEmpty(this.address))
level = 15; level = 15;
if (!this.isEmpty(this.selectDist) && !this.isEmpty(this.address))
level = 18;
return level; return level;
}; };
base.prototype.watch = function (JsonObj, key, closure) { base.prototype.watch = function (JsonObj, key, closure) {
@ -156,6 +157,7 @@ var APPMAP;
}; };
initialMap.prototype.initMap = function (domId, level) { initialMap.prototype.initMap = function (domId, level) {
var map = new BMapGL.Map(domId, { enableMapClick: false }); var map = new BMapGL.Map(domId, { enableMapClick: false });
console.log(this.level());
map.centerAndZoom(this.mapPoints, level || this.level()); map.centerAndZoom(this.mapPoints, level || this.level());
map.enableScrollWheelZoom(true); map.enableScrollWheelZoom(true);
map.setDisplayOptions({ map.setDisplayOptions({
@ -182,6 +184,30 @@ var APPMAP;
} }
}, this.selectProv); }, this.selectProv);
}; };
initialMap.prototype.placeNameMap = function (map, callbackQuery, callbackPolygon) {
var _this = this;
var local = new BMapGL.LocalSearch(this.selectCity, {
renderOptions: {
map: map
},
pageCapacity: 1,
});
local.search(this.placeName, { forceLocal: true });
local.setMarkersSetCallback(function (e) {
var city = e.pop();
map.removeOverlay(city.marker);
setTimeout(function () {
if (city.isAccurate === true) {
map.panTo(city.point);
map.setZoom(18);
callbackQuery(city.uid, callbackPolygon);
}
else {
_this.citySyncMap(map);
}
}, 50);
});
};
initialMap.prototype.ajaxlnglatList = function (map, formJson, clickEvent, closure) { initialMap.prototype.ajaxlnglatList = function (map, formJson, clickEvent, closure) {
var _this = this; var _this = this;
if (clickEvent === void 0) { clickEvent = false; } if (clickEvent === void 0) { clickEvent = false; }
@ -295,7 +321,9 @@ var APPMAP;
}); });
} }
else { else {
_this.placeName = $('select[name="v_name"]').find("option:selected").val();
var html = '范围:' + _this.selectProv + '<small style="padding-left:15px;">' + _this.allCity + '</small>'; var html = '范围:' + _this.selectProv + '<small style="padding-left:15px;">' + _this.allCity + '</small>';
html += '<span class="tag tag-sm tag-outline tag-danger font-size-16 m-l-5">' + _this.placeName + '</span>';
$('h4.modal-title').html(html); $('h4.modal-title').html(html);
$('#appmaps').modal('show'); $('#appmaps').modal('show');
} }
@ -311,6 +339,9 @@ var APPMAP;
city: _this.selectCity, city: _this.selectCity,
district: _this.selectDist district: _this.selectDist
}); });
if (_this.placeName && _this.isEmpty(_this.inputLng) && _this.isEmpty(_this.inputLat)) {
_this.placeNameMap(_this.modalMap, _this.queryHouseOutline, _this.showPolygon(_this.modalMap));
}
_this.modalMap.addEventListener("click", function (e) { _this.modalMap.addEventListener("click", function (e) {
_this.modalMap.removeOverlay(_this.cacheMarker); _this.modalMap.removeOverlay(_this.cacheMarker);
_this.modalLng = e.latlng.lng; _this.modalLng = e.latlng.lng;
@ -346,6 +377,107 @@ var APPMAP;
if (!this.isEmpty(this.inputLng) && !this.isEmpty(this.inputLat)) if (!this.isEmpty(this.inputLng) && !this.isEmpty(this.inputLat))
this.addMapOverlay(this.modalMap, this.inputLng, this.inputLat, true); this.addMapOverlay(this.modalMap, this.inputLng, this.inputLat, true);
}; };
modalMap.prototype.queryHouseOutline = function (uid, callback) {
var baseURL = 'https://map.baidu.com/?reqflag=pcmap&coord_type=3&from=webmap&qt=ext&ext_ver=new&l=18';
var url = baseURL + "&uid=" + uid;
callback && (window['queryHouseOutlineCallback'] = callback);
$.ajax({
type: "get",
async: false,
url: url,
dataType: "jsonp",
jsonpCallback: "queryHouseOutlineCallback",
success: function (datas) {
}
});
};
modalMap.prototype.parseGeo = function (mocator) {
if (typeof mocator != 'string')
return {};
var t = mocator.split("|");
var n = parseInt(t[0]);
var i = t[1];
var r = t[2];
var o = r.split(";");
if (n === 4) {
var a = [];
for (var s = 0; s < o.length - 1; s++) {
"1" === o[s].split("-")[0] && a.push(o[s].split("-")[1]);
}
o = a;
o.push("");
}
var u = [];
switch (n) {
case 1:
u.push(o[0]);
break;
case 2:
case 3:
case 4:
for (var s = 0; s < o.length - 1; s++) {
var l = o[s];
if (l.length > 100) {
l = l.replace(/(-?[1-9]\d*\.\d*|-?0\.\d*[1-9]\d*|-?0?\.0+|0|-?[1-9]\d*),(-?[1-9]\d*\.\d*|-?0\.\d*[1-9]\d*|-?0?\.0+|0|-?[1-9]\d*)(,)/g, "$1,$2;");
u.push(l);
}
else {
var c = [];
for (var d = l.split(","), f = 0; f < d.length; f += 2) {
var p = d[f], h = d[f + 1];
c.push(p + "," + h);
}
u.push(c.join(";"));
}
}
break;
default:
break;
}
if (u.length <= 1)
u = u.toString();
return {
type: n,
bound: i,
points: u
};
};
modalMap.prototype.coordinateToPoints = function (map, coordinate) {
var points = [];
if (coordinate) {
var arr = coordinate.split(";");
if (arr) {
for (var i = 0; i < arr.length; i++) {
var coord = arr[i].split(",");
if (coord && coord.length == 2) {
var point = map.mercatorToLnglat(coord[0], coord[1]);
points.push(new BMapGL.Point(point[0], point[1]));
}
}
}
}
return points;
};
modalMap.prototype.showPolygon = function (map) {
var _this = this;
return function (datas) {
var geo = datas.content.geo;
if (geo) {
var geoObj = _this.parseGeo(geo);
var points = _this.coordinateToPoints(map, geoObj.points);
var ply = new BMapGL.Polygon(points, {
strokeColor: "#ff4c52",
strokeWeight: 2,
strokeOpacity: 1,
strokeStyle: 'dashed',
fillColor: "transparent",
fillOpacity: 0
});
map.addOverlay(ply);
map.setViewport(ply.getPath());
}
};
};
return modalMap; return modalMap;
}(showMap)); }(showMap));
var selectMap = (function (_super) { var selectMap = (function (_super) {
@ -656,17 +788,15 @@ var APPMAP;
vtype: vtype, vtype: vtype,
allinfo: 'all' allinfo: 'all'
}, true); }, true);
this.citySyncMap(this.selectMap); this.citySyncMap(this.selectMap, this.level());
}; };
return selectMap; return selectMap;
}(initialMap)); }(initialMap));
function bmaps() { function bmaps() {
if ($('#modalmap').length) { if ($('#modalmap').length) {
console.log('模态框类型');
new modalMap(); new modalMap();
} }
else if ($('#showmap').length) { else if ($('#showmap').length) {
console.log('纯展示类型');
new showMap(); new showMap();
} }
else if ($('#selectMap').length) { else if ($('#selectMap').length) {

View File

@ -79,7 +79,7 @@ $met_title = $data['met_title'];
<script type="text/javascript" <script type="text/javascript"
src="https://api.map.baidu.com/api?type=webgl&v=1.0&ak={$data.mapkey}"></script> src="https://api.map.baidu.com/api?type=webgl&v=1.0&ak={$data.mapkey}"></script>
<div class="modal fade" id="appmaps" aria-hidden="true" data-keyboard="false" role="dialog" tabindex="-1"> <div class="modal fade" id="appmaps" aria-hidden="true" data-keyboard="false" role="dialog" tabindex="-1">
<div class="modal-dialog modal-center modal-lg"> <div class="modal-dialog modal-center modal-lgx">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close blue-600" data-dismiss="modal" aria-label="Close"> <button type="button" class="close blue-600" data-dismiss="modal" aria-label="Close">
@ -87,8 +87,8 @@ $met_title = $data['met_title'];
</button> </button>
<h4 class="modal-title"></h4> <h4 class="modal-title"></h4>
</div> </div>
<div class="modal-body"> <div class="modal-body p-t-0 p-b-10">
<div id="modalmap" class="h-400" data-mapid="{$data.data.id}"></div> <div id="modalmap" class="h-500 h-600" data-mapid="{$data.data.id}"></div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button> <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>

View File

@ -22,6 +22,8 @@ namespace APPMAP {
protected selectCity: string = '' protected selectCity: string = ''
protected selectDist: string = '' protected selectDist: string = ''
protected address: string = '' protected address: string = ''
// 场所
protected placeName: string = ''
// dom // dom
private lngDom: any = {} private lngDom: any = {}
@ -130,13 +132,13 @@ namespace APPMAP {
level() { level() {
let level = 12 let level = 12
// 省份 20km // 省份 20km
if (!this.isEmpty(this.selectProv)) level = 10 if (!this.isEmpty(this.selectProv)) level = 11
// 市区 5km // 市区 5km
if (!this.isEmpty(this.selectCity)) level = 12 if (!this.isEmpty(this.selectCity)) level = 13
// 县市区 500M // 县市区 500M
if (!this.isEmpty(this.selectDist)) level = 14 if (!this.isEmpty(this.selectDist)) level = 15
// 详细地址 200M // 详细地址 200M
if (!this.isEmpty(this.selectDist) && !this.isEmpty(this.address)) level = 15 if (!this.isEmpty(this.selectDist) && !this.isEmpty(this.address)) level = 18
return level; return level;
} }
@ -200,6 +202,7 @@ namespace APPMAP {
initMap(domId: string, level?: any) { initMap(domId: string, level?: any) {
const map = new BMapGL.Map(domId, {enableMapClick: false}); const map = new BMapGL.Map(domId, {enableMapClick: false});
// 初始化地图,设置中心点坐标和地图级别 // 初始化地图,设置中心点坐标和地图级别
console.log(this.level())
map.centerAndZoom(this.mapPoints, level || this.level()); map.centerAndZoom(this.mapPoints, level || this.level());
// 开启鼠标滚轮缩放 // 开启鼠标滚轮缩放
map.enableScrollWheelZoom(true); map.enableScrollWheelZoom(true);
@ -238,6 +241,57 @@ namespace APPMAP {
}, this.selectProv); }, this.selectProv);
} }
// 根据小区名称调整地图
placeNameMap(map, callbackQuery, callbackPolygon) {
// this.mapPoints this.selectCity
const local = new BMapGL.LocalSearch(this.selectCity, {
renderOptions: {
map: map
// panel:"r-result" 查询得到的信息列表
},
pageCapacity: 1,
});
// local.disableAutoViewport()
// forceLocal限定在区域内
local.search(this.placeName, {forceLocal: true});
// 自动标注后回调
local.setMarkersSetCallback((e) => {
// 获取数组第一个值
let city = e.pop()
// address: "山东省泰安市岱岳区杏林路"
// city: "泰安市"
// detailUrl: "https://api.map.baidu.com/place/detail?uid=7df64328bc0d8e4788f15d0a&output=html&source=jsapi"
// isAccurate: true
// marker: az {latLng: cZ, hashCode: "mz_2h", _type: "overlay", _visible: true, _visibleInternal: true, …}
// phoneNumber: undefined
// point: cZ {lng: 117.07973971764177, lat: 36.18540716406726}
// postcode: undefined
// province: "山东省"
// tags: (2) ["地产小区", "小区/楼盘"]
// title: "东瑞·长城一品"
// type: 0
// uid: "7df64328bc0d8e4788f15d0a"
// url: "https://map.baidu.com?s=inf%26uid%3D7df64328bc0d8e4788f15d0a%26c%3D325&i=0&sr=1"
// 目前只调整位置,然后删除标记,目前因为需求只是获取地图显示位置,不需要他进行标注
map.removeOverlay(city.marker)
// isAccurate 为true 精确定位 false 模糊定位
setTimeout(() => {
if (city.isAccurate === true) {
// 精准查询则按小区名
map.panTo(city.point)
map.setZoom(18)
// 对小区画线
callbackQuery(city.uid, callbackPolygon)
} else {
// 模糊查询则按地址查询
this.citySyncMap(map)
}
}, 50)
});
}
// 获取经纬度列表 // 获取经纬度列表
ajaxlnglatList(map: any, formJson: object, clickEvent: boolean = false, closure?: any) { ajaxlnglatList(map: any, formJson: object, clickEvent: boolean = false, closure?: any) {
$.getJSON(M.url.own_name + "c=ajax&a=doallmap", formJson, (listJson: any) => { $.getJSON(M.url.own_name + "c=ajax&a=doallmap", formJson, (listJson: any) => {
@ -275,6 +329,7 @@ namespace APPMAP {
// 当您需要从一幅较大的图片中截取某部分作为标注图标时,您 // 当您需要从一幅较大的图片中截取某部分作为标注图标时,您
// 需要指定大图的偏移位置此做法与css sprites技术类似。 // 需要指定大图的偏移位置此做法与css sprites技术类似。
// 设置图片偏移 // 设置图片偏移
// imageOffset: new BMapGL.Size(0, 0)
imageOffset: new BMapGL.Size(0, 300) imageOffset: new BMapGL.Size(0, 300)
} }
); );
@ -404,7 +459,10 @@ namespace APPMAP {
alertify.error("请选择城市。"); alertify.error("请选择城市。");
}) })
} else { } else {
const html = '范围:' + this.selectProv + '<small style="padding-left:15px;">' + this.allCity + '</small>'; // 获取小区名称
this.placeName = $('select[name="v_name"]').find("option:selected").val()
let html = '范围:' + this.selectProv + '<small style="padding-left:15px;">' + this.allCity + '</small>';
html += '<span class="tag tag-sm tag-outline tag-danger font-size-16 m-l-5">' + this.placeName + '</span>';
$('h4.modal-title').html(html) $('h4.modal-title').html(html)
// 打开模态框 // 打开模态框
$('#appmaps').modal('show') $('#appmaps').modal('show')
@ -430,6 +488,11 @@ namespace APPMAP {
district: this.selectDist district: this.selectDist
}) })
// 根据小区名称 且经纬度为空 调整地图核心
if (this.placeName && this.isEmpty(this.inputLng) && this.isEmpty(this.inputLat)) {
this.placeNameMap(this.modalMap, this.queryHouseOutline, this.showPolygon(this.modalMap))
}
//点击百度地图时触发 //点击百度地图时触发
this.modalMap.addEventListener("click", (e: any) => { this.modalMap.addEventListener("click", (e: any) => {
//清除单个标注 //清除单个标注
@ -480,6 +543,7 @@ namespace APPMAP {
}); });
} }
// 初始化
modalInitMap() { modalInitMap() {
// 初始化地图 // 初始化地图
this.modalMap = this.initMap("modalmap") this.modalMap = this.initMap("modalmap")
@ -488,6 +552,127 @@ namespace APPMAP {
} }
// 本接口采集于百度地图,并非官方文档提供,稳定性有待考究
// 获取指定小区的边界经纬度
queryHouseOutline(uid: number, callback: any) {
let baseURL = 'https://map.baidu.com/?reqflag=pcmap&coord_type=3&from=webmap&qt=ext&ext_ver=new&l=18';
let url = baseURL + "&uid=" + uid;
callback && (window['queryHouseOutlineCallback'] = callback);
$.ajax({
type: "get",
async: false,
url: url,
dataType: "jsonp",
jsonpCallback: "queryHouseOutlineCallback",
success: function (datas) {
}
});
}
// 墨卡托坐标解析
parseGeo(mocator: string) {
if (typeof mocator != 'string') return {}
const t = mocator.split("|");
let n = parseInt(t[0]);
let i = t[1];
let r = t[2];
let o: any = r.split(";");
if (n === 4) {
let a = []
for (let s = 0; s < o.length - 1; s++) {
// @ts-ignore
"1" === o[s].split("-")[0] && a.push(o[s].split("-")[1]);
}
o = a;
o.push("");
}
let u = [];
switch (n) {
case 1:
// @ts-ignore
u.push(o[0]);
break;
case 2:
case 3:
case 4:
for (let s = 0; s < o.length - 1; s++) {
let l = o[s];
if (l.length > 100) {
l = l.replace(/(-?[1-9]\d*\.\d*|-?0\.\d*[1-9]\d*|-?0?\.0+|0|-?[1-9]\d*),(-?[1-9]\d*\.\d*|-?0\.\d*[1-9]\d*|-?0?\.0+|0|-?[1-9]\d*)(,)/g,
"$1,$2;");
// @ts-ignore
u.push(l);
} else {
let c = []
for (let d = l.split(","), f = 0; f < d.length; f += 2) {
let p = d[f], h = d[f + 1];
// @ts-ignore
c.push(p + "," + h);
}
// @ts-ignore
u.push(c.join(";"))
}
}
break;
default:
break;
}
// @ts-ignore
if (u.length <= 1) u = u.toString();
return {
type: n,
bound: i,
points: u
}
}
// 墨卡托坐标转百度坐标
coordinateToPoints(map, coordinate) {
let points = [];
if (coordinate) {
const arr = coordinate.split(";");
if (arr) {
for (let i = 0; i < arr.length; i++) {
const coord = arr[i].split(",");
if (coord && coord.length == 2) {
// coord 墨卡托平面坐标转换为经纬度球体坐标
const point = map.mercatorToLnglat(coord[0], coord[1]);
// @ts-ignore
points.push(new BMapGL.Point(point[0], point[1]));
}
}
}
}
return points;
}
// 显示多边形
showPolygon(map) {
return (datas) => {
let geo = datas.content.geo
if (geo) {
// 存在geo 则标记边界
// map.clearOverlays();
const geoObj = this.parseGeo(geo);
//边界点
const points = this.coordinateToPoints(map, geoObj.points);
//建立多边形覆盖物
const ply = new BMapGL.Polygon(points, {
// 蓝色:#3e8ef7、浅蓝色#0bb2d4、绿色#17b3a3
// 橘色:#eb6709、红色#ff4c52、紫色#9463f7
strokeColor: "#ff4c52",
strokeWeight: 2,
strokeOpacity: 1,
strokeStyle: 'dashed', // solid默认、dashed
fillColor: "transparent",
fillOpacity: 0
});
map.addOverlay(ply); //添加覆盖物
map.setViewport(ply.getPath()); //调整视野
}
}
}
} }
// 通过地图选择 // 通过地图选择
@ -901,11 +1086,12 @@ namespace APPMAP {
// 根据条件筛选小区 // 根据条件筛选小区
filter() { filter() {
// 获取指定的值 // 获取指定的值
let vtype:any let vtype: any
if($('select[name="vtype"]').length){ if ($('select[name="vtype"]').length) {
vtype = $('select[name="vtype"]').val() vtype = $('select[name="vtype"]').val()
vtype = vtype ? vtype.join(',') : '' vtype = vtype ? vtype.join(',') : ''
} }
// 需要将缓存全部删除掉 // 需要将缓存全部删除掉
$('#selectMapId .mapreset').trigger('click') $('#selectMapId .mapreset').trigger('click')
//清除标注 //清除标注
@ -919,9 +1105,8 @@ namespace APPMAP {
vtype: vtype, vtype: vtype,
allinfo: 'all' allinfo: 'all'
}, true) }, true)
// 调整地图核心位置 // 调整地图核心位置
this.citySyncMap(this.selectMap) this.citySyncMap(this.selectMap, this.level())
} }
} }
@ -930,10 +1115,8 @@ namespace APPMAP {
export function bmaps() { export function bmaps() {
// 模态框 // 模态框
if ($('#modalmap').length) { if ($('#modalmap').length) {
console.log('模态框类型')
new modalMap() new modalMap()
} else if ($('#showmap').length) { } else if ($('#showmap').length) {
console.log('纯展示类型')
// 展示形式 // 展示形式
new showMap() new showMap()
} else if ($('#selectMap').length) { } else if ($('#selectMap').length) {
@ -943,6 +1126,7 @@ namespace APPMAP {
new selectMap() new selectMap()
// 测试时自动启动模态框 // 测试时自动启动模态框
// $('button[data-target="#selectMapId"]').click() // $('button[data-target="#selectMapId"]').click()
} }
} }
} }

View File

@ -1,4 +1,5 @@
declare let $: any declare let $: any
declare let window: any
declare let jQuery: any declare let jQuery: any
declare let APPFUN: { declare let APPFUN: {
isEmpty: (a: any) => {} isEmpty: (a: any) => {}

View File

@ -0,0 +1,346 @@
/*!
* M['weburl'] 网站网址
* M['lang'] 网站语言
* M['tem'] 模板目录路径
* M['user_name'] 页面登录用户名
* met_prevarrow,
met_nextarrow slick插件翻页按钮自定义html
* M['device_type'] 客户端判断dPC端t平板端m手机端
* M['n'] 当前模块名称
* M['c'] 当前类
* M['a'] 当前方法
* M['langtxt'] 当前语言文字
* M['langset'] 当前后台语言
* M['anyid'] 当前模块id
* M['met_editor'] 当前系统编辑器名称
* M['met_keywords'] 页面关键词
* M['url']['admin'] 后台文件夹路径
* M['url']['static']
* M['url']['static_vendor']
* M['url']['static2']
* M['url']['static2_vendor']
* M['url']['static2_plugin']
* M['url']['uiv2'] 模板框架v2路径
* M['url']['uiv2_css']
* M['url']['uiv2_js']
* M['url']['app'] 应用文件夹路径
* M['url']['pub'] 后台模块公用文件夹路径
* M['url']['epl'] 后台模块公用示例文件夹路径
* M['url']['ui'] 应用前后台公用UI文件app/system/include/piblic/ui/里面
* M['url']['own_form'] 当前页面程序地址
* M['url']['own_name'] 当前模块地址
* M['url']['own'] 当前模块后台路径
* M['url']['own_tem'] 当前页面模板路径
* M['url']['api'] app站点地址
* M['url']['editor'] 当前编辑器应用文件夹路径
*/
$(function () {
var myDate = new Date().getTime()
$.include(M.url.own_tem + 'js/appcheck.min.js?'+myDate);
$.ajax({
type : "GET",
url : M.url.own_name + 'c=ajax&a=doajaxcl&lang=' + M['langset'],
dataType: "jsonp",
async : false
}).done(function (data) {
CL = data;
});
var appfun = function () {
var $self = this;
//有序表处理
$.getJSON(M.url.own_name + 'c=ajax&a=dosequence&lang=' + M['langset'], {}, function (json) {});
//select2
if ($('[data-plugin="select2"]').length) $self.select2(true);
//排期广告位选择
if ($('.add_ap_list').length) $.include(M.url.own_tem + 'js/applan.js?' + myDate);
//表格重绘后回调
$('#tableslist').on('draw.dt', function (e, settings) {
if ($('[data-plugin="alertify"]').length) $self.select2(false);
})
// 表格数据加载状态
$('#tableslist').on('processing.dt', function (e, settings, processing) {
if(processing) {
$self.tableProcessing(this)
}
})
$('#tables-list').on('processing.dt', function (e, settings, processing) {
if(processing) {
$self.tableProcessing(this)
}
})
//单个时间初始化
if ($('[data-plugin="alonetime"]').length) $self.alonetime();
//时间区段选择
if ($('[data-plugin="datetosearch"]').length) $self.datepicker();
//导出功能
$(document).on('click', '.backups', function (event) {
var my = $(this);
event.preventDefault();
my.parents('form').metSubmit(0);
var obj = my.parents("form").serialize(),
href = my.data('url'),
veaps = $('select[name="veaps"]').val(),
vtype = $('select[name="vtype"]').val();
// 单独给get传递增加veaps的值
if (!$self.isEmpty(veaps)) obj += '&jsadd_veaps=' + veaps.join(',');
if (!$self.isEmpty(vtype)) obj += '&jsadd_vtype=' + vtype.join(',');
window.location.href = href + '&' + obj;
})
//表格底部自定义按钮
$(document).on('click', '[table-zdybtn]', function (event) {
var my = $(this),
$form = my.parents('form'),
typestr = my.data('submit_type');
event.preventDefault();
$self.ownsubmit($form, typestr);
if (my.data('plugin') != 'alertify') {
$form.submit();
return true;
}
})
//排序功能
if ($('a.orderby-link').length) $self.orders();
//状态更改
// http://bsify.admui.com/alertify/ 中文说明
$(document).on('click', '.btn-cursor-pointer', function () {
var self = $(this);
$.include(M['url']['static2_vendor'] + 'alertify/alertify.js', function () {
alertify
.okBtn("确定")
.cancelBtn("取消")
.confirm('确定更改状态吗?', function () {
$.getJSON(self.data('href'), function (json) {
window.location.reload();
})
})
})
});
};
appfun.prototype = {
isEmpty : function (val) {
switch (typeof val) {
case 'undefined':
return true;
case 'string':
if (val.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length == 0)
return true;
break;
case 'boolean':
if (!val)
return true;
break;
case 'number':
if (0 === val || isNaN(val))
return true;
break;
case 'object':
if (null === val || val.length === 0)
return true;
for (var i in val) {
return false;
}
return true;
}
return false;
},
select2 : function (drawdt) {
// drawdt true 执行默认操作 false 不执行
var $self = this,
select = [];
//选择器
M['plugin']['select2'] = [
M['url']['static2_vendor'] + 'select2/select2.min.css',
M['url']['static2_vendor'] + 'select2/select2.full.min.js',
M['url']['static2_vendor'] + 'select2/i18n/zh-CN.js',
];
$.include(M['plugin']['select2'], function () {
$('[data-plugin="select2"]').each(function (indexs, item) {
var _self = $(this),
defaults = _self.data('default'),
select2url = _self.data('select2-url') + '&' + myDate;
select[indexs] = _self.select2({
placeholder: '输入搜索内容', //提示语
ajax : {
url : select2url,
dataType: 'jsonp',
delay : 500,
data : function (params) {
return {
querys : params.term, //search term
tname : _self.data('tname'), //指定简短表
fiend : _self.data('fiend'), //指定字段值
allnone : _self.data('allnone'), //是否只显示应用的值
source : _self.data('source'), //查看来源标记
condition: _self.data('condition') //查询限制条件
};
},
results : function (data, page) {
return {results: data.results};
}
}
});
//默认值处理
if (!$self.isEmpty(defaults) && drawdt == true) {
$.getJSON(
select2url,
{
tname : _self.data('tname'), //指定简短表
fiend : _self.data('fiend'), //指定字段值
allnone : _self.data('allnone'), //是否只显示应用的值
source : _self.data('source'), //查看来源标记
condition: _self.data('condition'), //查询限制条件
default : defaults, //默认值
division : _self.data('division') //默认值分隔符
},
function (obj) {
$.each(obj.results, function (index, ele) {
$.each(ele.children, function (indexop, eleop) {
var option = new Option(eleop.text, eleop.id, true, true);
select[indexs].append(option).trigger('change');
})
});
}
)
}
});
});
},
datepicker: function () {
var $self = this;
M['plugin']['datetimepicker'] = [
M['url']['epl'] + 'time/jquery.datetimepicker.css',
M['url']['epl'] + 'time/jquery.datetimepicker.js'
];
$.include(M['plugin']['datetimepicker'], function () {
var starttime = $('#date_timepicker_start'),
endtime = $('#date_timepicker_end');
starttime.datetimepicker({
lang : M.synchronous == 'cn' ? 'ch' : 'en',
timepicker : starttime.attr("data-day-type") == 2 ? true : false,
format : starttime.attr("data-day-type") == 2 ? 'Y-m-d H:i:s' : 'Y-m-d',
// value:starttime.val()?starttime.val():'',
// onShow:function( ct ){
// this.setOptions({
// maxDate:endtime.val()?endtime.val():false
// })
// },
onSelectDate: function (ct, $i) {
$self.tableaajx(starttime);
}
});
endtime.datetimepicker({
lang : M.synchronous == 'cn' ? 'ch' : 'en',
timepicker : endtime.attr("data-day-type") == 2 ? true : false,
format : endtime.attr("data-day-type") == 2 ? 'Y-m-d H:i:s' : 'Y-m-d',
// value:endtime.val()?endtime.val():'',
// onShow:function( ct ){
// this.setOptions({
// minDate:starttime.val()?starttime.val():false
// })
// },
onSelectDate: function (ct, $i) {
$self.tableaajx(endtime);
}
});
})
},
alonetime : function () {
var $self = this;
M['plugin']['datetimepicker'] = [
M['url']['epl'] + 'time/jquery.datetimepicker.css',
M['url']['epl'] + 'time/jquery.datetimepicker.js'
];
$.include(M['plugin']['datetimepicker'], function () {
var alonetime = $('[data-plugin="alonetime"]');
alonetime.datetimepicker({
lang : M.synchronous == 'cn' ? 'ch' : 'en',
timepicker : alonetime.attr("data-day-type") == 2 ? true : false,
format : alonetime.attr("data-day-type") == 2 ? 'Y-m-d H:i:s' : 'Y-m-d',
onSelectDate: function (ct, $i) {
$self.tableaajx(alonetime);
}
});
});
},
tableaajx : function (timedom) {
if (typeof datatable != 'undefined') {
var $this_datatable = timedom.parents('.dataTable'),
datatable_index = $this_datatable.index('.dataTable');
if (datatable_index < 0) datatable_index = 0;
datatable[datatable_index].ajax.reload();
}
},
orders : function () {
var $self = this;
$(document).on('click', 'a.orderby-link', function (event) {
var $this = $(this),
arrow = $this.find(".orderby-arrow");
if (arrow.length) {
if ($this.find(".desc").length) {
$self.orderby($this, 'asc');
} else {
//还原
$self.orderby($this, '');
}
} else {
$self.orderby($this, 'desc');
}
});
},
orderby(dom, type) {
var $self = this;
//清楚所有排序
$("a.orderby-link").find(".orderby-arrow").remove();
$("a.orderby-link").next().val('');
//操作当前排序
if (type) dom.append('<span class="orderby-arrow ' + type + '"></span>');
dom.next().val(type);
$self.tableaajx(dom);
},
ownsubmit : function ($form, typestr) {
// 插入submit_type字段
if ($form.find('[name="submit_type"]').length) $form.append('<input type="hidden" name="submit_type" value=""/>');
$form.find('[name="submit_type"]').val(typestr);
// 插入表格的all_id字段
if ($form.find('.dataTable').length) {
var $table = $form.find('.dataTable'),
$checkbox = $table.find('tbody input[type="checkbox"][name="id"]:checked'),
all_id = '';
$checkbox.each(function (index, el) {
all_id += all_id ? ',' + $(this).val() : $(this).val();
})
if (!$form.find('[name="all_id"]').length) $form.append('<input type="hidden" name="all_id"/>');
$form.find('[name="all_id"]').val(all_id);
}
},
tableProcessing:function (_this_){
// 表格数据加载状态
var tbody = $(_this_).find('tbody')
var colspan = tbody.data('colspan')
var html= `<tr>
<td colspan="${colspan}">
<div class="h-50 vertical-align text-xs-center"><div class="loader vertical-align-middle loader-default"></div></div>
</td>
</tr>`
tbody.html(html)
}
};
APPFUN = new appfun();
//地图
if ($('#showmap').length || $('#modalmap').length || $('#selectMap').length) {
$.include(M.url.own_tem + 'js/bmaps.js?' + myDate, function () {
APPMAP.bmaps();
});
}
//缓存
$.ajaxSetup({cache: false});
});