Commit 9fb57efc292f77a1e1519c5bb4f55a9ea2a7990c

Authored by xp.Huang
2 parents afa6a157 6d1debd2

Merge branch 'ww' into 'main'

perf: device location show all devcie marker point && add alarm effect

See merge request huang/yun-teng-iot-front!343
... ... @@ -86,6 +86,18 @@
86 86 import { defaultSchemas } from './cpns/TimePeriodForm/config';
87 87 import { QueryWay, SchemaFiled, AggregateDataEnum } from './cpns/TimePeriodForm/config';
88 88 import { dateUtil } from '/@/utils/dateUtil';
  89 +
  90 + interface DeviceInfo {
  91 + alarmStatus: 0 | 1;
  92 + deviceState: string;
  93 + tbDeviceId: string;
  94 + name: string;
  95 + organizationDTO: { name: string };
  96 + deviceProfile: { default: boolean; enabled: boolean; name: string; transportType: string };
  97 + deviceInfo: { longitude: string; latitude: string; address: string };
  98 + }
  99 + type MarkerList = DeviceInfo & { marker: any };
  100 +
89 101 export default defineComponent({
90 102 name: 'BaiduMap',
91 103 components: {
... ... @@ -118,6 +130,8 @@
118 130 const { toPromise } = useScript({ src: BAI_DU_MAP_URL });
119 131 const [registerDetailDrawer, { openDrawer }] = useDrawer();
120 132 const [registerModal, { openModal }] = useModal();
  133 + const BMapInstance = ref<Nullable<any>>(null);
  134 +
121 135 const loading = ref(false);
122 136
123 137 const [registerTable] = useTable({
... ... @@ -131,7 +145,41 @@
131 145 showIndexColumn: false,
132 146 useSearchForm: true,
133 147 pagination: {
134   - showSizeChanger: false,
  148 + showQuickJumper: false,
  149 + showSizeChanger: true,
  150 + },
  151 + afterFetch: async (data: DeviceInfo[]) => {
  152 + const BMap = (window as any).BMap;
  153 + unref(BMapInstance).clearOverlays();
  154 + const markerList: MarkerList[] = [];
  155 + data.forEach((item) => {
  156 + const {
  157 + deviceState,
  158 + deviceInfo: { longitude, latitude },
  159 + } = item;
  160 + const point = new BMap.Point(longitude, latitude);
  161 + const rivet = deviceState === 'INACTIVE' ? djx : deviceState === 'ONLINE' ? zx : lx;
  162 + const myIcon = new BMap.Icon(rivet, new BMap.Size(20, 30));
  163 + const marker = new BMap.Marker(point, { icon: myIcon });
  164 + markerList.push({ ...item, marker });
  165 + });
  166 +
  167 + markerList.forEach((record) => {
  168 + unref(BMapInstance).addOverlay(record.marker);
  169 + const isAlarmStatus = !!record.alarmStatus;
  170 + if (isAlarmStatus) {
  171 + const alarmStatusClassName = 'device-status__alarm';
  172 + const className = record.marker.Ec.getAttribute('class');
  173 + record.marker.Ec.setAttribute('class', `${className} ${alarmStatusClassName}`);
  174 + }
  175 +
  176 + //标注监听事件
  177 + record.marker.addEventListener('click', function () {
  178 + createDeviceInfoWindow(record);
  179 + });
  180 + });
  181 +
  182 + return data;
135 183 },
136 184 });
137 185
... ... @@ -141,43 +189,32 @@
141 189 const wrapEl = unref(wrapRef);
142 190 const BMap = (window as any).BMap;
143 191 if (!wrapEl) return;
144   - const map = new BMap.Map(wrapEl);
  192 + BMapInstance.value = new BMap.Map(wrapEl);
145 193 function myFun(result) {
146 194 let mk = new BMap.Marker(result.center);
147   - map.addOverlay(mk);
148   - map.panTo(result.center);
149   - map.centerAndZoom(result.center, 15);
150   - map.enableScrollWheelZoom(true);
  195 + unref(BMapInstance).addOverlay(mk);
  196 + unref(BMapInstance).panTo(result.center);
  197 + unref(BMapInstance).centerAndZoom(result.center, 15);
  198 + unref(BMapInstance).enableScrollWheelZoom(true);
151 199 }
152 200 let myCity = new BMap.LocalCity();
153 201 myCity.get(myFun);
154 202 }
155   - // 点击表格某一行触发
156   - const deviceRowClick = async (record) => {
  203 +
  204 + const createDeviceInfoWindow = async (record: DeviceInfo) => {
  205 + const BMap = (window as any).BMap;
157 206 entityId = record.tbDeviceId;
158 207 globalRecord = record;
159   - const BMap = (window as any).BMap;
160   - const wrapEl = unref(wrapRef);
161   - const map = new BMap.Map(wrapEl);
162   - // if (record.deviceInfo.address) {
163   - // keys = await getDeviceDataKeys(entityId);
164 208 try {
165 209 deviceAttrs.value = (await getDeviceDataKeys(entityId)) || [];
166 210 } catch (error) {}
167 211
168   - const { name, organizationDTO, deviceState, deviceProfile } = record;
169   - const { longitude, latitude, address } = record.deviceInfo;
170   - //这里如果没有地理位置 最好设置一个默认位置 不然地图会全蓝
171   - const point = new BMap.Point(
172   - longitude == '' ? 104.04666605565338 : longitude,
173   - latitude == '' ? 30.543516387560476 : latitude
174   - );
175   - let options = {
  212 + const options = {
176 213 width: 330, // 信息窗口宽度
177 214 height: 0, // 信息窗口高度
178 215 };
179   - map.centerAndZoom(point, 15);
180   - map.enableScrollWheelZoom(true);
  216 + const { name, organizationDTO, deviceState, deviceProfile } = record;
  217 + const { address, longitude, latitude } = record.deviceInfo;
181 218 // 创建信息窗口对象
182 219 const res = await getDeviceActiveTime(entityId);
183 220
... ... @@ -185,61 +222,48 @@
185 222 lastUpdateTs = moment(lastUpdateTs).format('YYYY-MM-DD HH:mm:ss');
186 223 let infoWindow = new BMap.InfoWindow(
187 224 `
188   - <div style="display:flex;justify-content:space-between; margin:20px 0px;">
189   - <div style="font-size:16px;font-weight:bold">${name}</div>
190   - ${
191   - deviceState === 'INACTIVE'
192   - ? `<div style="display:flex;align-items:center;"><img style="width:15px;height:15px" src="${djh}" class="mr-1">待激活</div>`
193   - : deviceState === 'ONLINE'
194   - ? `<div style="display:flex;align-items:center; ">
195   - <img style="width:15px;height:15px" src="${online}" class="mr-1">在线</div>`
196   - : `<div style="display:flex;align-items:center;"><img style="width:15px;height:15px" src="${lx1}" class="mr-1">离线</div>`
197   - }
198   - </div>
199   - <div>所属组织:${organizationDTO.name}</div>
200   - <div style="margin-top:6px;">接入协议:${deviceProfile.transportType}</div>
201   - <div style="margin-top:6px;">设备位置:${
202   - address == '' ? '该设备暂无地理位置' : address
203   - }</div>
204   - <div style="margin-top:6px;">${
  225 + <div style="display:flex;justify-content:space-between; margin:20px 0px;">
  226 + <div style="font-size:16px;font-weight:bold">${name}</div>
  227 + ${
  228 + deviceState === 'INACTIVE'
  229 + ? `<div style="display:flex;align-items:center;"><img style="width:15px;height:15px" src="${djh}" class="mr-1">待激活</div>`
  230 + : deviceState === 'ONLINE'
  231 + ? `<div style="display:flex;align-items:center; ">
  232 + <img style="width:15px;height:15px" src="${online}" class="mr-1">在线</div>`
  233 + : `<div style="display:flex;align-items:center;"><img style="width:15px;height:15px" src="${lx1}" class="mr-1">离线</div>`
  234 + }
  235 + </div>
  236 + <div>所属组织:${organizationDTO.name}</div>
  237 + <div style="margin-top:6px;">接入协议:${deviceProfile.transportType}</div>
  238 + <div style="margin-top:6px;">
  239 + 设备位置:${address == '' ? '该设备暂无地理位置' : address}
  240 + </div>
  241 + <div style="margin-top:6px;">
  242 + ${
205 243 deviceState === 'ONLINE' ? '在线' : deviceState === 'INACTIVE' ? '创建' : '离线'
206   - }时间:${lastUpdateTs}</div>
207   - <div style="display:flex;justify-content:end; margin-top:10px">
208   - <button onclick="openDeviceInfoDrawer()" style="margin-right:10px;color:#fff;background-color:#409eff;padding:4px; border-radius:4px;">设备信息</button>
209   - <button onclick="openHistoryModal()" style="color:#fff;background-color:#409eff;padding:4px; border-radius:4px;">历史数据</button>
  244 + }时间:${lastUpdateTs}
210 245 </div>
211   - `,
  246 + <div style="display:flex;justify-content:end; margin-top:10px">
  247 + <button onclick="openDeviceInfoDrawer()" style="margin-right:10px;color:#fff;background-color:#409eff;padding:4px; border-radius:4px;">设备信息</button>
  248 + <button onclick="openHistoryModal()" style="color:#fff;background-color:#409eff;padding:4px; border-radius:4px;">历史数据</button>
  249 + </div>
  250 + `,
212 251 options
213 252 );
214 253
215   - map.openInfoWindow(infoWindow, map.getCenter());
216   - let preMarker = null;
  254 + const point = new BMap.Point(
  255 + longitude || 104.04666605565338,
  256 + latitude || 30.543516387560476
  257 + );
217 258
218   - const rivet = deviceState === 'INACTIVE' ? djx : deviceState === 'ONLINE' ? zx : lx;
219   - let myIcon = new BMap.Icon(rivet, new BMap.Size(20, 30));
220   - let marker = new BMap.Marker(point, { icon: myIcon });
221   - if (marker) {
222   - map.removeOverlay(preMarker);
223   - }
224   - map.addOverlay(marker);
225   - //标注监听事件
226   - marker.addEventListener('click', function (e) {
227   - const point = e.point;
228   - map.openInfoWindow(infoWindow, point);
229   - });
230   - //标注监听事件
231   - // } else {
232   - // const point = new BMap.Point(106.63028229687498, 36.06735821600903);
233   - // let options = {
234   - // width: 100, // 信息窗口宽度
235   - // height: 100, // 信息窗口高度
236   - // title: '提示', // 信息窗口标题
237   - // };
238   - // map.centerAndZoom(point, 5);
239   - // map.enableScrollWheelZoom(true);
240   - // let infoWindow = new BMap.InfoWindow('该设备暂无地理位置', options); // 创建信息窗口对象
241   - // map.openInfoWindow(infoWindow, map.getCenter());
242   - // }
  259 + if (!longitude || !latitude)
  260 + infoWindow = new BMap.InfoWindow('该设备暂无地理位置', options); // 创建信息窗口对象
  261 + unref(BMapInstance).centerAndZoom(point, 15);
  262 + unref(BMapInstance).openInfoWindow(infoWindow, unref(BMapInstance).getCenter());
  263 + };
  264 + // 点击表格某一行触发
  265 + const deviceRowClick = async (record) => {
  266 + createDeviceInfoWindow(record);
243 267 };
244 268
245 269 // 设备信息
... ... @@ -428,3 +452,26 @@
428 452 background-color: #fff;
429 453 }
430 454 </style>
  455 +<style>
  456 + .device-status__alarm {
  457 + transform-origin: 10px 15px;
  458 + animation: 0.5s linear 0s infinite alternate Scale;
  459 + }
  460 +
  461 + @keyframes Scale {
  462 + 0% {
  463 + /* transform: translateY(0px); */
  464 + transform: scale(1);
  465 + }
  466 +
  467 + 50% {
  468 + /* transform: translateY(5px); */
  469 + transform: scale(1.5);
  470 + }
  471 +
  472 + 100% {
  473 + /* transform: translateY(10px); */
  474 + transform: scale(2);
  475 + }
  476 + }
  477 +</style>
... ...