point.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <!-- 引入 ECharts 文件 -->
  6. <script type="text/javascript" src="static/jquery-3.3.1.min.js"></script>
  7. <script src="static/echarts.min.js"></script>
  8. <script src="static/plug-in.min.js"></script>
  9. <link rel="stylesheet" href="static/index.css" media="all"/>
  10. </head>
  11. <body>
  12. <div class="positon">
  13. <span>
  14. 底图:<select id="mapName">
  15. </select>
  16. </span>
  17. <span></span><span>水平位置: </span><input id="x"></input><span>,垂直位置: </span><input id="y"></input>
  18. <span id="y"><a class="ahref">保存位置</a></span>
  19. </div>
  20. <div class="point">
  21. </div>
  22. <div id="echart" class="echart"></div>
  23. <div class="data">
  24. <div>
  25. <span id="monthNum">暂无</span>
  26. </div>
  27. <div>
  28. <span id="waitNum">暂无</span>
  29. <span id="rate">暂无</span>
  30. </div>
  31. <div>
  32. <div id="weekJob" class="item title">
  33. <span>设备名称</span>
  34. <span>保养任务</span>
  35. <span>报修时间</span>
  36. </div>
  37. <!-- <div class="item">
  38. <span>设备名称</span>
  39. <span>正常</span>
  40. <span>2021/03/21</span>
  41. </div>-->
  42. </div>
  43. </div>
  44. </body>
  45. <script>
  46. const ACCESS_TOKEN = 'Access-Token'
  47. const VUE_STORE_BASE = 'pro__'
  48. let mapList=[]
  49. var id = window.location.search.split("id=")[1]
  50. id = filterUrlData(id);
  51. var xx = window.location.search.split("zjm=")[1];
  52. xx = filterUrlData(xx) || 0;
  53. var yy = window.location.search.split("jbdh=")[1] || 0;
  54. yy = filterUrlData(yy);
  55. var mapName = window.location.search.split("mapName=")[1];
  56. mapName =decodeURI(filterUrlData(mapName)) ;
  57. function getMapList(){
  58. $.ajax({
  59. type: "GET",
  60. url: "/api/upms/files?type=56",
  61. headers: getHeader(),
  62. success: function (res) {
  63. var data = res.data
  64. mapList = data
  65. console.log(2);
  66. for(var i=0;i<data.length;i++){
  67. var option = '<option value="'+data[i].targetId+'">'+data[i].targetId+'</option>'
  68. $('#mapName').append(option)
  69. }
  70. if(!mapName){
  71. mapName=mapList[0].targetId
  72. }
  73. img.src = mapList.find(item => item.targetId == mapName).url
  74. $('#mapName').val(mapName);
  75. }
  76. })
  77. }
  78. getMapList()
  79. // 初始化设备位置
  80. $(function(){
  81. $('#x').val(xx);
  82. $('#y').val(yy);
  83. console.log($('#mapName').val);
  84. $('.point').attr("style", 'left: ' + xx + 'px;top: ' + yy + 'px');
  85. $('#echart').click(function(e) {
  86. xx = e.pageX || 0;
  87. yy = e.pageY || 0;
  88. console.log(xx+' '+yy);
  89. $('#x').val(xx);
  90. $('#y').val(yy);
  91. $('.point').css('left',xx).css('top',yy);
  92. })
  93. $('#x').on('input',function(e){
  94. xx = e.delegateTarget.value
  95. $('.point').attr("style", 'left: ' + xx + 'px;top: ' + yy + 'px')
  96. });
  97. $('#y').on('input',function(e){
  98. yy = e.delegateTarget.value
  99. $('.point').attr("style", 'left: ' + xx + 'px;top: ' + yy + 'px')
  100. });
  101. $('#mapName').on('change',function(e){
  102. mapName = e.delegateTarget.value
  103. img.src = mapList.find(item => item.targetId == mapName).url
  104. });
  105. $('.ahref').click(function(e) {
  106. if(id == null){
  107. alert('请设置设备')
  108. return
  109. }
  110. if(xx==null || yy==null || xx == 0 || yy==0){
  111. alert('请点击位置,该位置将作为设备的显示位置')
  112. return
  113. }
  114. var data = {id: id, zjm:xx, jbdh: yy}
  115. $.ajax({
  116. type: "PUT",
  117. url: "/api/sb/infos/" + id,
  118. headers: getHeader(),
  119. data: JSON.stringify(data),
  120. success: function(response) {
  121. const data = response.data;
  122. alert("保存成功。")
  123. },
  124. error: function(xhr, textStatus, errorThrown) {
  125. error(xhr, textStatus, errorThrown);
  126. }
  127. });
  128. })
  129. })
  130. /**
  131. * filterUrlData 过滤url数据
  132. * @param Boolean {name}
  133. * @param Boolean {value}
  134. * @param Boolean {data}
  135. * Created by preference on 2020/08/01
  136. */
  137. function filterUrlData (data) {
  138. if (data) {
  139. var dataArr = data.split('');
  140. var tempArr = [];
  141. for(var i = 0; i <= dataArr.length; i++){
  142. if (dataArr[i] != '&') {
  143. tempArr.push(dataArr[i]);
  144. } else {
  145. break;
  146. }
  147. }
  148. return tempArr.join('');
  149. }
  150. };
  151. // 基于准备好的dom,初始化echarts实例
  152. var myChart = echarts.init(document.getElementById('echart'))
  153. var img = new Image()
  154. var canvas = document.createElement('canvas')
  155. var ctx = canvas.getContext('2d')
  156. canvas.width = myChart.getWidth() * window.devicePixelRatio
  157. canvas.height = myChart.getHeight() * window.devicePixelRatio
  158. var fullImage = new Image()
  159. img.onload = function () {
  160. ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
  161. fullImage.src = canvas.toDataURL()
  162. setTimeout(function () {
  163. myChart.resize()
  164. }, 100)
  165. }
  166. var option = {
  167. // 背景
  168. backgroundColor: {
  169. repeat: 'no-repeat',
  170. image: fullImage
  171. },
  172. // 地图
  173. geo: {
  174. map: 'world',
  175. silent: true,
  176. top: 0,
  177. left: 0,
  178. right: 0,
  179. bottom: 0,
  180. itemStyle: {
  181. normal: {
  182. opacity: 0.8,
  183. borderWidth: 0,
  184. color: '#a53d13'
  185. }
  186. }
  187. },
  188. title: {
  189. text: '',
  190. },
  191. // 开启工具栏
  192. tooltip: {
  193. "trigger": "item",
  194. "confine": true
  195. },
  196. series: [{
  197. name: '正常',
  198. type: 'effectScatter',
  199. coordinateSystem: 'geo',
  200. data: [
  201. ],
  202. showEffectOn: 'render',
  203. rippleEffect: {
  204. brushType: 'stroke'
  205. },
  206. hoverAnimation: true,
  207. label: {
  208. normal: {
  209. formatter: '{@value}',
  210. position: 'left',
  211. show: false
  212. }
  213. },
  214. itemStyle: {
  215. normal: {
  216. color: '#17bf9e',
  217. shadowBlur: 200,
  218. shadowColor: '#17bf9e'
  219. }
  220. },
  221. zlevel: 1
  222. }, {
  223. name: '异常点',
  224. type: 'scatter',
  225. coordinateSystem: 'geo',
  226. symbol: 'pin', // 气泡
  227. symbolSize: 50,
  228. label: {
  229. normal: {
  230. show: true,
  231. formatter: '{@value}',
  232. textStyle: {
  233. color: '#fff',
  234. fontSize: 11
  235. }
  236. }
  237. },
  238. itemStyle: {
  239. normal: {
  240. color: 'red'
  241. }
  242. },
  243. zlevel: 6,
  244. data: [
  245. ]
  246. }, {
  247. name: '异常图片和名称',
  248. type: 'effectScatter',
  249. coordinateSystem: 'geo',
  250. data: [
  251. ],
  252. showEffectOn: 'render',
  253. rippleEffect: {
  254. brushType: 'stroke'
  255. },
  256. hoverAnimation: true,
  257. label: {
  258. normal: {
  259. formatter: '{@value}',
  260. position: 'left',
  261. show: false
  262. }
  263. },
  264. itemStyle: {
  265. normal: {
  266. color: 'yellow',
  267. shadowBlur: 200,
  268. shadowColor: 'yellow'
  269. }
  270. },
  271. zlevel: 1
  272. }]
  273. }
  274. // 使用刚指定的配置项和数据显示图表
  275. myChart.setOption(option);
  276. function getHeader(){
  277. return {
  278. Authorization: getToken(),
  279. "Cache-Control": "no-cache",
  280. accept: "application/json; charset=utf-8",
  281. 'Content-Type': 'application/json;charset=UTF-8'
  282. // "Access-Control-Allow-Headers":"Origin, X-Requested-With, Content-Type, Accept"
  283. }
  284. }
  285. function getToken(){
  286. const storeTokenJson = JSON.parse(localStorage.getItem(VUE_STORE_BASE+ACCESS_TOKEN))
  287. return 'Bearer ' + storeTokenJson.value
  288. }
  289. </script>
  290. <style>
  291. .positon{
  292. position: absolute;
  293. top: 20px;
  294. left: 30%;
  295. z-index: 1000;
  296. }
  297. .point{
  298. position: absolute;
  299. padding: 5px;
  300. background: blue;
  301. border-radius: 5px;
  302. z-index: 1000;
  303. }
  304. #mapName{
  305. width: 120px;
  306. }
  307. .ahref{
  308. background: blue;
  309. padding: 8px;
  310. cursor: pointer;
  311. }
  312. </style>
  313. </html>