123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997 |
- angular.module('app')
- .directive('devManage', ['$filter', '$http', '$stateParams', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'QRCodeOptions', '$rootScope', '$localStorage', function ($filter, $http, $stateParams, $timeout, uiGridConstants, i18nService, toaster, QRCodeOptions, $rootScope, $localStorage) {
- return {
- restrict: 'AEC',
- templateUrl: 'js/directives/tpl/devManage.html',
- // 独立作用域,并暴露配置属性
- scope: {},
- link: function ($scope, el, attrs) {
- i18nService.setCurrentLang("zh-cn");//汉化
- moment.locale('zh-cn');
- var dealerId = "";
- var searchKey = "";
- function initDevList() {
- //可能是由路由跳转,则获取url参数
- if ($stateParams.dealerId) {
- $scope.dealerId = dealerId = $stateParams.dealerId;
- }
- if ($stateParams.searchKey) {
- searchKey = $stateParams.searchKey;
- }
- // 更新查询条件到界面
- condition.searchKey = searchKey;
- setColumnDefs();
- initDataGrid();
- }
- $scope.$on('initDevList', function (evt, data) {
- //先获取广播参数
- if (data && data.dealerId) {
- $scope.dealerId = dealerId = data.dealerId;
- }
- if (data && data.searchKey) {
- searchKey = data.searchKey || "";
- }
- initDevList();
- });
- $scope.gridOptions = {
- data: 'myData',
- showGridFooter: true, //是否显示grid footer
- // rowHeight: 80,
- //-------- 分页属性 ----------------
- paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
- paginationCurrentPage: 1, //当前页码
- paginationPageSize: 10, //每页显示个数
- totalItems: 0,// 总数量
- useExternalPagination: true,//是否使用分页按钮
- //过滤
- // enableFiltering: true,
- columnDefs: [],
- //---------------api---------------------
- onRegisterApi: function (gridApi) {
- $scope.gridApi = gridApi;
- gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
- if ($scope.setPagingData) {
- $scope.getPagedDataAsync(newPage, pageSize);
- }
- });
- }
- };
- //查询条件
- var condition = $scope.condition = {
- searchKey: searchKey,
- startLogicalCode: '',
- endLogicalCode: '',
- };
- //枚举常量
- $scope.enum = {};
- //事件
- $scope.event = {
- search: function () {
- dealerId = "";//清空跳转带入的条件
- $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
- }
- };
- //截止日期选择
- $scope.dateOptions = {
- formatYear: 'yy',
- startingDay: 1,
- class: 'datepicker'
- };
- $scope.expireDate = null;
- $scope.format = 'yyyy-MM-dd';
- $scope.minDate = new Date();
- var maxDate = new Date();
- $scope.maxDate = maxDate.setFullYear(maxDate.getFullYear() + 10);
- $scope.opened = true;
- $scope.open = function ($event) {
- $event.preventDefault();
- $event.stopPropagation();
- $scope.opened = true;
- };
- function setColumnDefs() {
- var cols = $scope.gridOptions.columnDefs = [
- {field: 'logicalCode', displayName: '逻辑编号'},
- {field: 'devType', displayName: '设备类型'},
- {
- field: 'imei',
- displayName: '电子标签',
- minWidth: 160,
- cellTemplate: '<div class="temp-row" title="{{row.entity.imei}}" ng-bind="row.entity.imei"></div>'
- },
- {
- field: 'createdTime',
- displayName: '注册时间',
- width: 160,
- cellTemplate: '<div class="temp-row" ng-bind="row.entity.createdTime| date:\'yyyy-MM-dd HH:mm:ss\'"></div>'
- },
- {
- field: 'dealerName',
- displayName: '商户',
- minWidth: 160,
- cellTemplate: '<div class="temp-row" title="{{row.entity.dealerName}}" ng-bind="row.entity.dealerName"></div>'
- },
- {
- field: 'address',
- displayName: '设备地址',
- minWidth: 160,
- cellTemplate: '<div class="temp-row" title="{{row.entity.address}}" ng-bind="row.entity.address"></div>'
- },
- {
- field: 'serverAddress',
- displayName: '服务器',
- },
- {
- field: 'online', displayName: '设备状态',
- cellTemplate: '<div class="temp-row" ng-class="{\'text-dark\':row.entity.online==\'离线\',\'text-success\':row.entity.online==\'在线\'}" >{{row.entity.online}}</div>'
- },
- {
- field: 'lastOffTime', displayName: '最近离线时间',
- cellTemplate: '<div class="temp-row" ng-bind="row.entity.lastOffTime?(row.entity.lastOffTime| date:\'yyyy-MM-dd HH:mm:ss\'):\'无\'"></div>',
- width: 160
- },
- {
- field: 'signal', displayName: '信号',
- cellTemplate: '<div class="temp-row iconfont text-success" ng-click="grid.appScope.refreshSignal(row.entity)" style="cursor: pointer" ng-class="{' +
- '\'icon-refresh text-dark\':row.entity.signal==0,' +
- '\'icon-xinhao1\':row.entity.signal>0&&row.entity.signal<=6,' +
- '\'icon-xinhao2\':row.entity.signal>7&&row.entity.signal<=12,' +
- '\'icon-xinhao3\':row.entity.signal>13&&row.entity.signal<=18,' +
- '\'icon-xinhao4\':row.entity.signal>19&&row.entity.signal<=24,' +
- '\'icon-xinhao5\':row.entity.signal>24' +
- '}" ></div>'
- },
- {
- field: 'detail', displayName: '详细信息',
- cellTemplate: '<div class="temp-row" ng-click="grid.appScope.showInfoDetail(\'详细信息\',row.entity)" >{{row.entity.detail}}</div>'
- }
- ];
- var feature_map = $scope.feature_map = $localStorage.feature_map
- if (feature_map && feature_map.disableDevice) {
- cols.push(
- {
- field: 'disableDevice', displayName: '禁用状态',
- cellTemplate: '<div class="temp-row" >{{row.entity.disableDevice?\'已禁用\':\'已启用\'}}</div>'
- }
- )
- }
- cols.push({
- field: 'oper', displayName: '操作',
- enableFiltering: false,
- enableSorting: false,
- enableHiding: false,//禁止在列选择器中隐藏
- enableColumnMenu: false,// 是否显示列头部菜单按钮
- width: 450,
- cellTemplate: '<div class="grid-button">' +
- '<button class="btn btn-sm btn-rounded btn-info" ng-click="grid.appScope.sendCommand(row.entity)"><i class="fa fa-file-code-o"></i> 指令</button>' +
- '<button class="btn btn-sm btn-rounded btn-info" ng-click="grid.appScope.onOpenPort(row.entity)"><i class="fa fa-file-code-o"></i> 端口信息</button>' +
- '<button class="btn btn-sm btn-rounded btn-danger" ng-if="row.entity.code==100500" ng-click="grid.appScope.openDeviceFunctionParam(row.entity)"><i class="fa fa-gear"></i> 参数</button>' +
- '<button class="btn btn-sm btn-rounded btn-danger" ng-if="row.entity.code==100210" ng-click="grid.appScope.showRealtimeData(row.entity)"><i class="fa fa-eye"></i> 数据监控</button>' +
- ((feature_map && feature_map.disableDevice) ? ('<button class="btn btn-sm btn-rounded " ng-class="{\'btn-info\':row.entity.disableDevice,\'btn-danger\':!row.entity.disableDevice}" ng-click="grid.appScope.disableDeviceToggle(row.entity)"><i class="fa fa-wrench"></i> {{row.entity.disableDevice?\'启用\':\'禁用\'}}</button>') : ('')) +
- '<button class="btn btn-sm btn-rounded btn-success" ng-click="grid.appScope.getQRCode(row.entity)"><i class="fa fa-qrcode"></i> 二维码</button>' +
- '</div>'
- })
- var fields = $scope.gridOptions.columnDefs;
- for (var index in fields) {
- var item = fields[index];
- if (item && item['minWidth'] == null) {
- item['minWidth'] = 100;
- }
- }
- }
- $scope.refreshSignal = function (entity) {
- $http.get('/device/sendSignal', {
- params: {logicalCode: entity.logicalCode}
- }).then(function (data) {
- data = data.data
- if (data.result == 1) {
- var signal = data.para;
- entity.signal = signal;
- if (entity.signal == 0) {
- toaster.pop("info", "设备离线!");
- }
- }
- }).catch(function (data) {
- toaster.pop("error", "提示", "操作失败!");
- });
- };
- $scope.setPagingData = function (data, curPage, pageSize) {
- var firstRow = (curPage - 1) * pageSize;
- var pagedData = data.data.dataList;
- $scope.myData = pagedData;
- $scope.gridOptions.totalItems = data.data.total;
- };
- $scope.getPagedDataAsync = function (curPage, pageSize) {
- if ($scope.gridOptionsLoading) {
- return;
- }
- var params = {
- pageSize: pageSize,
- pageIndex: curPage
- };
- if (condition.searchKey != "") {
- params.searchKey = condition.searchKey
- }
- if (condition.startLogicalCode != "") {
- params.startLogicalCode = condition.startLogicalCode
- }
- if (condition.endLogicalCode != "") {
- params.endLogicalCode = condition.endLogicalCode
- }
- if (dealerId) {
- params.dealerId = dealerId;
- }
- $scope.gridOptionsLoading = true;
- $http.get('/manager/getDevDetailList', {
- params: params
- }).then(function (data) {
- data = data.data
- $scope.gridOptionsLoading = false;
- $scope.setPagingData(data, curPage, pageSize);
- setTimeout(function () {
- $(window).trigger("resize");
- }, 50);
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取数据列表失败");
- });
- };
- function initDataGrid() {
- //首次加载表格
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }
- if (attrs.autoInit !== "false") {
- initDevList();
- }
- //展示详情
- $scope.showInfoDetail = function (title, content) {
- var data = $.extend(true, {}, JSON.parse(content.detail))
- $scope.infoDetail = {
- title: title,
- content: data
- };
- $(".devManageMain #detailInfoPanel").modal();
- };
- $scope.closeDetailInfoPanel = function () {
- $(".devManageMain #detailInfoPanel").modal("hide");
- };
- var dialogData = $scope.dialogData = {};
- //发送指令
- $scope.sendCommand = function (entity) {
- $scope.commandInfoPanel.$setPristine();
- $scope.commandInfoPanel.$setUntouched();
- $http.get('/manager/getCommandByDevice', {
- params: {logicalCode: entity.logicalCode}
- }).then(function (data) {
- data = data.data
- if (data.result == 1) {
- dialogData.commandList = data.payload.dataList
- $scope.currentCmdIndex = -1
- $scope.currentCmd = null;
- }
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取常用命令列表失败");
- });
- $(".devManageMain #commandInfoPanel").modal();
- };
- $scope.selectCommand = function (index, item) {
- $scope.currentCmdIndex = index
- $scope.currentCmd = item;
- };
- //确认发送指令
- $scope.sendCommandConfirm = function () {
- if ($scope.commandInfoPanel.$invalid) {
- return;
- }
- var currentCmd = $scope.currentCmd
- if(!$scope.currentCmd.id){
- toaster.pop("info", "提示", "请选择指令!");
- return
- }
- var params = []
- for(var index in currentCmd.params) {
- var item = currentCmd.params[index]
- params.push({
- id: item.id,
- default: item.default,
- })
- }
- $http({
- method: 'POST',
- url: '/manager/sendCommand',
- data: {id: currentCmd.id, devNo: currentCmd.IMEI, params: params}
- }).then(function (response) {
- var data = response.data;
- if (data.result == 1) {
- toaster.pop("success", "提示", "操作成功!");
- $scope.currentResult = JSON.parse(data.data);
- }
- }, function (response) {
- toaster.pop("error", "提示", "操作失败!");
- });
- };
- $scope.closeCommandPanel = function () {
- $(".devManageMain #commandInfoPanel").modal("hide");
- delete dialogData.command;
- };
- // 查看端口信息
- $scope.portList = [];
- $scope.onOpenPort = function (entity) {
- $(".devManageMain #portInfoPanel").modal();
- $http.get('/device/getDevicePort', {
- params: {logicalCode: entity.logicalCode}
- }).then(function (response) {
- let data = response.data;
- let payload = data.payload;
- $scope.portList = payload.portList || [];
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取端口信息失败!");
- });
- };
- $scope.closePortInfoPanel = function () {
- $(".devManageMain #portInfoPanel").modal("hide");
- };
- $scope.qiangStatusMap = {
- yes: '是',
- no: '否',
- unknow: '未知'
- }
- $scope.getPayTypeEnum = function (item, type) {
- // 单位后台确定
- var payTypeEnum = {
- 'mobile': '扫码付费' + (item.coins || 0),
- 'mobile_vcard': '虚拟卡抵扣',
- 'monthlyPackage': '包月卡抵扣',
- 'coin': '投币' + (item.coins || 0),
- 'card': '刷卡' + (item.coins || 0),
- 'serverBilling': '后台计费',
- 'powerBilling': '功率计费',
- 'postpaid': '后付费',
- null: "未知"
- }
- return payTypeEnum[type]
- }
- $scope.getPortStatusDom = function (status) {
- var statusMap = {
- // 这三个状态根据配置来确定是否可用
- idle: {
- name: '空闲',
- style: 'text-success'
- },
- busy: {
- name: '繁忙',
- style: 'text-warning'
- },
- finished: {
- name: '完成',
- style: 'text-success'
- },
- connected: {
- name: '连接',
- style: 'text-warning'
- },
- // 以下两个状态 完全不能用
- fault: {
- name: '故障',
- style: 'text-danger'
- },
- ban: {
- name: '禁用',
- style: 'font-4'
- },
- estop: {
- name: '急停状态',
- style: 'text-danger'
- },
- ready: {
- name: '就绪',
- style: 'text-warning'
- },
- // 0:'空闲',
- // 1:'繁忙',
- // 2:'故障',
- // 3:'禁用',
- // 4:'暂停',
- // 5:'已连接',
- // 6:'充电完成',
- // 7:'维护中',
- // 8:'预约中',
- 0: {
- name: '空闲',
- style: 'text-success'
- },
- 1: {
- name: '繁忙',
- style: 'text-warning'
- },
- 2: {
- name: '故障',
- style: 'text-danger'
- },
- 3: {
- name: '禁用',
- style: 'text-danger'
- },
- 4: {
- name: '暂停',
- style: 'text-warning'
- },
- 5: {
- name: '已连接',
- style: 'text-success'
- },
- 6: {
- name: '充电完成',
- style: 'text-success'
- },
- 7: {
- name: '维护中',
- style: 'text-danger'
- },
- 8: {
- name: '预约中',
- style: 'text-danger'
- },
- 10: {
- name: '占位状态',
- style: 'text-warning'
- },
- 11: {
- name: '急停状态',
- style: 'text-danger'
- },
- 12: {
- name: '就绪',
- style: 'text-success'
- },
- 13: {
- name: '继电器粘连',
- style: 'text-danger'
- },
- }
- var item = statusMap[status]
- // 普通充电桩
- if (item) {
- return "<span class='" + item.style + "'>" + item.name + "</span>"
- } else {
- return "<span class='font-4'>未知</span>"
- }
- }
- // 切换禁用状态
- $scope.disableDeviceToggle = function (entity) {
- $http.get('/manager/disableDevice', {
- params: {logicalCode: entity.logicalCode, disable: !entity.disableDevice}
- }).then(function (data) {
- data = data.data
- if (data.result == 1) {
- entity.disableDevice = !entity.disableDevice
- toaster.pop("success", "操作成功!");
- }
- }).catch(function (data) {
- toaster.pop("error", "提示", "操作失败!");
- });
- };
- function getSelectRows() {
- var rows = $scope.gridApi.selection.getSelectedRows();
- if (rows.length === 0) {
- toaster.pop("info", "提示", "请选择数据!");
- return false;
- }
- var ids = [];
- for (var i = 0; i < rows.length; i++) {
- ids.push(rows[i].logicalCode);
- }
- $scope.selectedIds = ids;
- return ids
- }
- // 禁用启用选中设备
- $scope.disableDeviceSelected = function (target) {
- var ids = getSelectRows()
- if (ids) {
- $http.post('/manager/disableSelectedDevice', {
- logicalCode: ids, disable: target
- }).then(function (data) {
- toaster.pop("success", "操作成功!");
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }).catch(function (data) {
- toaster.pop("error", "提示", "操作失败!");
- });
- }
- };
- // 禁用启用全部设备
- $scope.disableAllDevice = function (target) {
- $http.post('/manager/disableAllDevice', {
- disable: target, dealerId: $scope.dealerId
- }).then(function (data) {
- toaster.pop("success", "操作成功!");
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }).catch(function (data) {
- toaster.pop("error", "提示", "操作失败!");
- });
- };
- $scope.getQRCode = function (entity) {
- $(".devManageMain #devQRCodePanel").modal();
- var currentDomain = location.protocol + "//" + location.host;
- var dataURL = QRCodeOptions.getQRCodeImageData({
- text: currentDomain + "/userLogin?l=" + entity.logicalCode,
- label: entity.logicalCode,
- // logoDom: $("#qrcodeOptPreviewLogo")[0]
- });
- $(".devManageMain #previewImg").attr({
- "width": 200,
- "height": 240,
- "src": dataURL
- });
- };
- $scope.closeQRCode = function () {
- $(".devManageMain #devQRCodePanel").modal('hide');
- };
- /*********设备参数配置*************/
- //弹窗内部折叠状态
- $scope.devParamDialogStatus = {
- open1: true,
- open2: true,
- open3: true,
- };
- var logicalCode;
- $scope.openDeviceFunctionParam = function (entity) {
- //重置表单状态
- $scope.devParamForm.$setPristine();
- $scope.devParamForm.$setUntouched();
- logicalCode = entity.logicalCode;
- //目前只有沥森 100500 需要这么设置
- $(".devManageMain #devParamPanel").modal();
- $scope.devParamDialogData = {}
- //非沥森 待实现 todo
- if (entity.code != 100500) {
- var url = "/device/getDeviceFunction";
- $http({
- method: 'POST',
- url: url,
- data: {id: entity.id}
- }).then(function (response) {
- var data = response.data
- if (data.result == 1) {
- $scope.devParamDialogData = data.payload;
- }
- }, function (response) {
- toaster.pop("error", "提示", "获取失败!");
- });
- }
- };
- $scope.getDevParam = function (key) {
- var url = "/device/getDeviceFunctionByKey";
- $http({
- method: 'POST',
- url: url,
- data: {key: key, logicalCode: logicalCode}
- }).then(function (response) {
- var data = response.data
- if (data.result == 1) {
- $scope.devParamDialogData[key] = data.payload[key];
- $(".devManageMain #devParamPanel").modal();
- }
- }, function (response) {
- toaster.pop("error", "提示", "获取失败!");
- });
- }
- $scope.setDevParam = function (key) {
- var url = "/device/setDeviceFunctionByKey";
- if ($scope.devParamDialogData[key] == null || $scope.devParamDialogData[key] == '') {
- toaster.pop("warning", "请填写正确的数据。");
- return
- }
- var data = {
- logicalCode: logicalCode, config: {}
- };
- data.config[key] = $scope.devParamDialogData[key]
- $http({
- method: 'POST',
- url: url,
- data: data
- }).then(function (response) {
- toaster.pop("success", "提示", "设置成功!");
- }, function (response) {
- toaster.pop("error", "提示", "保存失败!");
- });
- }
- $scope.closeDevParam = function () {
- $('.devManageMain #devParamPanel').modal('hide');
- }
- /********************设备端口充电状态变化曲线*****************************/
- $scope.realtimeConfig = {
- startTimeOpen: false,
- endTimeOpen: false,
- timeChange: function () {
- this.startTimeOpen = false
- this.endTimeOpen = false
- }
- }
- $scope.realtimeEnity = null;
- $scope.realtimeCondition = {
- // 默认今天,后台需要 智能采样 优化性能
- startTime: moment().format("YYYY-MM-DD"),
- endTime: moment().format("YYYY-MM-DD"),
- port: 1,// 默认为1
- logicalCode: null,
- }
- $scope.portList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] // 暂时写死10路
- $scope.realtimeConditionChange = function (port) {
- $scope.realtimeCondition.port = port
- }
- var showRealtimeChart = echarts.init(document.getElementById('realtimeDataChart'));
- $scope.showRealtimeData = function (entity) {
- $scope.realtimeCondition.logicalCode = entity.logicalCode
- $(".devManageMain #realtimeDialog").modal();
- $scope.loadRealtimeData();
- }
- $scope.loadRealtimeData = function () {
- $http.get('/manager/getDeviceRealtimeData', {
- params: $scope.realtimeCondition
- }).then(function (data) {
- data = data.data
- var payload = data.payload;
- var dataList = payload.dataList
- var option = getRealtimeDataOption(dataList, {
- 'voltage': {
- name: "电压"
- },
- 'electricity': {
- name: "电流"
- },
- 'temperature': {
- name: "温度"
- },
- })
- showRealtimeChart.setOption(option)
- showRealtimeChart.resize();
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取数据列表失败");
- });
- }
- function getRealtimeDataOption(list, dataConfig) {
- var xData = [];
- var seriesMap = {};
- var markAreaData = []
- var prevStatus = ''
- var leng = list.length
- for (var index in list) {
- var item = list[index];
- xData.push(item.dateStr);
- var status = item.status
- // 如果发现状态值变化 或是 循环已经结束,则结束上一轮的markArea
- if (prevStatus !== status || index === leng - 1) {
- prevStatus = status
- // 如果发现有上一轮的 markArea 则设置其结束坐标
- if (markAreaItem) {
- markAreaItem[1].xAxis = item.dateStr
- }
- var markAreaItem = [{
- xAxis: item.dateStr,
- itemStyle: {}
- }, {
- xAxis: null
- }]
- // 繁忙标记为绿色
- if (status === 'busy') {
- markAreaItem[0].itemStyle.color = 'rgba(7,193,96,.8)'
- }
- // 故障标记为红色
- else if (status === 'fault') {
- markAreaItem[0].itemStyle.color = 'rgba(255,82,76,.8)'
- } else {
- //空闲或其他状态暂时标记为白色
- markAreaItem[0].itemStyle.color = '#fff'
- }
- markAreaData.push(markAreaItem)
- }
- for (var key in dataConfig) {
- var value = item[key];
- if (!seriesMap[key]) {
- seriesMap[key] = [];
- }
- seriesMap[key].push(value);
- }
- }
- var option = {
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- lineStyle: {
- color: '#108EE9',
- width: .3,
- }
- }
- },
- legend: {
- bottom: 0,
- data: []
- },
- grid: {
- x: 20,
- x2: 20,
- y: 20,
- y2: 45,
- },
- xAxis: [
- {
- type: 'category',
- axisLabel: {
- textStyle: {
- color: "#aaa",
- fontSize: "12px"
- }
- },
- axisTick: {
- show: false,
- },
- axisLine: {
- show: false,
- },
- data: xData
- }
- ],
- yAxis: [
- {
- type: 'value',
- axisLabel: {
- textStyle: {
- color: "#aaa",
- fontSize: "12px"
- }
- },
- axisTick: {
- show: false,
- },
- axisLine: {
- show: false,
- },
- splitLine: {
- show: false,
- },
- },
- ],
- series: []
- };
- var legend = []
- var index = 0;
- for (var key in seriesMap) {
- var dataList = seriesMap[key];
- var serie = {
- name: dataConfig[key].name,
- smooth: true,
- symbolSize: 0,
- type: 'line',
- data: dataList
- }
- // 只有电压一个坐标设置 markArea ,否则重复了
- if (key === 'voltage') {
- serie.markArea = {data: markAreaData}
- }
- option.series.push(serie);
- legend.push(dataConfig[key].name)
- index++;
- }
- option.legend.data = legend
- return option;
- }
- /********************查看设备上投放的广告*****************************/
- $scope.adGridOptions = {
- data: 'adGridData',
- showGridFooter: true, //是否显示grid footer
- //-------- 分页属性 ----------------
- paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
- paginationCurrentPage: 1, //当前页码
- paginationPageSize: 100, //每页显示个数
- totalItems: 0,// 总数量
- useExternalPagination: true,//是否使用分页按钮
- //过滤
- enableFiltering: true,
- columnDefs: [],
- // 菜单
- enableGridMenu: true,
- //---------------api---------------------
- onRegisterApi: function (gridApi) {
- $scope.adGridApi = gridApi;
- gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
- if ($scope.setAdGridPagingData) {
- $scope.getAdGridPagedData(newPage, pageSize);
- }
- });
- }
- };
- function setAdGridColumnDefs() {
- $scope.adGridOptions.columnDefs = [
- {
- field: 'adId',
- displayName: '编号', cellClass: "text-center"
- },
- {field: 'name', displayName: '名称'},
- {field: 'word', displayName: '广告词'},
- {field: 'startTime', enableFiltering: false, displayName: '开始时间'},
- {field: 'endTime', enableFiltering: false, displayName: '结束时间'},
- {
- field: 'img',
- displayName: '图片',
- enableFiltering: false,
- enableSorting: false,
- cellTemplate: '<img ng-src="{{row.entity.img}}" class="img-circle center-block" style="max-height: 100%"/>'
- },
- {
- field: 'status',
- displayName: '状态',
- enableSorting: false,
- cellTemplate: '<span ng-if="row.entity.status==true" class="text-success ui-grid-cell-contents">在线</span><span ng-if="row.entity.status==false" class="ui-grid-cell-contents">下线</span>' +
- ''
- },
- ];
- var fields = $scope.adGridOptions.columnDefs;
- for (var index in fields) {
- var item = fields[index];
- if (item && item['minWidth'] == null) {
- item['minWidth'] = 100;
- }
- }
- }
- setAdGridColumnDefs();
- $scope.getAdGridPagedData = function (curPage, pageSize) {
- var adByLogicalCode = $scope.adByLogicalCode;
- if (!adByLogicalCode) {
- toaster.pop("error", "提示", "设备逻辑码错误");
- return
- }
- var params = {
- pageSize: pageSize,
- pageIndex: curPage,
- logicalCode: adByLogicalCode
- };
- $http.get('/ad/getDeviceAllocatedAds', {
- params: params
- }).then(function (data) {
- data = data.data
- if (data.result == 1) {
- $scope.setAdGridPagingData(data, curPage, pageSize);
- setTimeout(function () {
- $(window).trigger("resize");
- }, 100);
- } else {
- toaster.pop("error", "提示", data.description);
- }
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取数据列表失败");
- });
- };
- $scope.setAdGridPagingData = function (data, curPage, pageSize) {
- var pagedData = data.data.dataList;
- $scope.adGridData = pagedData;
- $scope.adGridOptions.totalItems = data.data.total;
- };
- function initAdDataGrid() {
- $scope.getAdGridPagedData($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }
- $scope.openAdDataGrid = function (entity) {
- $scope.adByLogicalCode = entity.logicalCode;
- $(".devManageMain #adDataGrid").modal();
- initAdDataGrid()
- }
- $scope.closeAdDataGrid = function () {
- $(".devManageMain #adDataGrid").modal('hide')
- }
- /**end***/
- }
- };
- }]);
|