widget.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. <template>
  2. <div style="position: absolute; top: 60px; left: 30px;">
  3. <el-row style="width: 340px">
  4. <el-select v-model="selectT" style="float: left;width:100px;" placeholder="请选择" size="small">
  5. <el-option label="地名" value="1" />
  6. <el-option label="坐标" value="2" />
  7. <el-option label="管径" value="3" />
  8. <el-option label="管材" value="4" />
  9. <el-option label="设施编号" value="5" />
  10. <el-option label="阀门类型" value="6" />
  11. <el-option label="阀门规格" value="7" />
  12. </el-select>
  13. <el-autocomplete
  14. v-model="inputT"
  15. class="helpInput"
  16. style="width: 190px; float: left; padding-left: 5px;"
  17. clearable
  18. size="small"
  19. popper-class="my-autocomplete"
  20. :fetch-suggestions="querySearch"
  21. :placeholder="selectTt"
  22. @clear="textClear"
  23. >
  24. <template slot-scope="{ item }">
  25. <span class="name">{{ item.value }}</span>
  26. </template>
  27. </el-autocomplete>
  28. <el-button style="float: left; height: 32px; border-radius: 0px 4px 4px 0px;" type="primary" icon="el-icon-search" size="small" plain @click="queryFeature" />
  29. </el-row>
  30. <div id="zoomH" style="position: absolute; top: 0px; left: 350px; width: 70px;">
  31. <div class="widgetGroupButtoms" title="前一视图" style="float: left;" @click="viewHistroy(true)">
  32. <img src="./images/left.png">
  33. </div>
  34. <div class="widgetGroupButtoms" title="后一视图" style="float: left;" @click="viewHistroy(false)">
  35. <img src="./images/right.png">
  36. </div>
  37. </div>
  38. <el-collapse-transition>
  39. <div v-show="showResult" id="resultDiv" ref="showResult" style="width:410px;margin-top:10px;">
  40. <div style="overflow:auto;max-height:380px;margin-bottom:10px;">
  41. <ul id="resultUl" ref="scroll" v-infinite-scroll="load" infinite-scroll-disabled="disabled">
  42. <li v-for="(i, index) in queryResult" :key="index" @click="liClick(i)">
  43. <div>
  44. <span class="title">{{ queryTitle }}<span v-html="i.text" /></span>
  45. </div>
  46. <div style="margin-top: 13px;">
  47. <span class="other">编号:<span class="text">{{ i.id }}</span></span>
  48. <span class="other" style="margin-left: 8px;">设备类型:<span class="text">{{ i.layer }}</span></span>
  49. </div>
  50. <div class="icon"><i class="el-icon-arrow-right" /></div>
  51. </li>
  52. </ul>
  53. <div ref="queryLoading" class="load"><i class="el-icon-loading" />加载中...</div>
  54. <div ref="queryNoMore" class="load">没有更多了...</div>
  55. </div>
  56. <div ref="statue" class="allResult" />
  57. </div>
  58. </el-collapse-transition>
  59. </div>
  60. </template>
  61. <script>
  62. import { queryConfig } from './queryConfig'
  63. import { esriConfig, appconfig } from 'staticPub/config'
  64. import { loadModules } from 'esri-loader'
  65. export default {
  66. name: 'SimpleQueryTool',
  67. components: {},
  68. props: {
  69. mapView: { type: Object, default: () => [] }
  70. },
  71. data() {
  72. return {
  73. inputT: '',
  74. selectT: '1',
  75. selectTt: '请输入地名',
  76. queryResult: [],
  77. allFea: [],
  78. testi: 0,
  79. disabled: false,
  80. showResult: false,
  81. queryTitle: ''
  82. }
  83. },
  84. watch: {
  85. selectT: function(e, old) {
  86. this.selectTt = [
  87. '请输入地名', '请输入X,Y', '请输入管径大小', '请输入管材类型',
  88. '请输入设施编号', '请输入阀门类型', '请输入阀门半径大小'
  89. ][e - 1]
  90. if (e != old) {
  91. this.queryResult = []
  92. this.showResult = false
  93. }
  94. },
  95. mapView: function(e) {
  96. var center = e.center
  97. this.extentGourp = []
  98. this.extentGourp.push({
  99. center: center,
  100. zoom: e.zoom
  101. })
  102. this.extentIndex = 0
  103. this.isExtentChange = true
  104. this.isExtentTime = undefined
  105. var sleepZoom = [[center.x, center.y], e.zoom, undefined]
  106. loadModules(['esri/Graphic'], { url: esriConfig.baseUrl }).then(([Graphic]) => {
  107. this.showGeo = new Graphic({
  108. geometry: { type: 'point', x: 0, y: 0, spatialReference: this.mapView.spatialReference },
  109. symbol: {
  110. path: 'M527.676 51c146.71 0 265.919 117.742 268.288 263.887l0.036 4.437C789.928 444.319 695.261 606.878 512 807 329.564 606.484 234.897 443.926 228 319.324 228 171.133 348.133 51 496.324 51h31.352z m-15.31 53h-0.732C390.886 104 293 201.886 293 322.634 298.319 424.162 371.319 556.617 512 720c141.318-163.062 214.318-295.518 219-397.366l-0.03-3.615C729.04 199.938 631.908 104 512.367 104z M512 171c86.709 0 157 70.291 157 157s-70.291 157-157 157-157-70.291-157-157 70.291-157 157-157z m0.5 55C455.89 226 410 271.89 410 328.5S455.89 431 512.5 431 615 385.11 615 328.5 569.11 226 512.5 226z',
  111. color: '2D74E7', outline: { color: '2D74E7', width: '1px' },
  112. size: '30px', yoffset: '15px', xoffset: '0px', type: 'simple-marker'
  113. }
  114. })
  115. this.mapView.graphics.add(this.showGeo)
  116. })
  117. this.mapView.watch('center', (ec) => {
  118. if (this.isExtentChange && ec.x != sleepZoom[0][0] && ec.y != sleepZoom[0][1]) {
  119. if (sleepZoom[2]) clearTimeout(sleepZoom[2])
  120. sleepZoom[2] = setTimeout(() => {
  121. sleepZoom[0] = [ec.x, ec.y]
  122. if (this.extentIndex != this.extentGourp.length - 1) {
  123. this.extentGourp.splice(
  124. this.extentIndex + 1,
  125. this.extentGourp.length - this.extentIndex
  126. )
  127. }
  128. this.extentGourp.push({
  129. center: ec,
  130. zoom: this.mapView.zoom
  131. })
  132. this.extentIndex = this.extentGourp.length - 1
  133. }, 200)
  134. }
  135. })
  136. }
  137. },
  138. mounted() {
  139. this.queryConfig = queryConfig
  140. this.queryAllText = {}
  141. this.queryText(16, 'MATERIAL', this.queryAllText)
  142. this.queryText(9, 'VALVETYPE', this.queryAllText)
  143. this.loadLayerInfo()
  144. window.str = this.$refs.scroll
  145. this.disabled = true
  146. },
  147. methods: {
  148. loadLayerInfo() {
  149. $.ajax({ // 结果
  150. url: `${appconfig.gisResource.business_map.config[0].url}?f=pjson&token=${this.$store.state.user.arcgistoken}`,
  151. type: 'GET',
  152. success: (data) => {
  153. data = JSON.parse(data)
  154. data = data.layers
  155. var layers = []
  156. for (let i = 0, ii = data.length; i < ii; i++) {
  157. if (!data[i].subLayerIds) layers.push(data[i].id)
  158. }
  159. sencondFun(layers)
  160. },
  161. error: (error) => {
  162. this.$message.error('查询错误,请联系管理员')
  163. console.log(error)
  164. }
  165. })
  166. var sencondFun = (layers) => {
  167. $.ajax({ // 结果
  168. url: appconfig.gisResource.layer_name.config[0].url,
  169. type: 'POST',
  170. data: {
  171. token: this.$store.state.user.arcgistoken,
  172. usertoken: appconfig.usertoken,
  173. layerids: JSON.stringify(layers),
  174. f: 'pjson'
  175. },
  176. success: (data) => {
  177. data = JSON.parse(data)
  178. if (data.code == 10000) {
  179. data = data.result.rows
  180. var rows = {}
  181. var rows2 = {}
  182. for (let i = 0, ii = data.length; i < ii; i++) {
  183. var dd = data[i]
  184. rows[data[i].layerdbname] = { id: dd.layerid, name: data[i].layername }
  185. rows2[dd.layerid] = data[i].layerdbname
  186. }
  187. this.layerIndex = rows
  188. this.layerIdIndex = rows2
  189. }
  190. },
  191. error: (error) => {
  192. this.$message.error('查询错误,请联系管理员')
  193. console.log(error)
  194. }
  195. })
  196. }
  197. },
  198. querySearch(queryString, cb) {
  199. switch (parseInt(this.selectT)) {
  200. default:
  201. cb([])
  202. break
  203. case 4:
  204. cb(this.queryAllText['MATERIAL'].filter((e) => e.value.indexOf(queryString) > -1))
  205. break
  206. case 6:
  207. cb(this.queryAllText['VALVETYPE'].filter((e) => e.value.indexOf(queryString) > -1))
  208. break
  209. }
  210. },
  211. queryText(id, name, texts) {
  212. $.ajax({
  213. url: appconfig.gisResource.fieldUniqueValue.config[0].url,
  214. type: 'POST',
  215. data: {
  216. token: this.$store.state.user.arcgistoken,
  217. usertoken: appconfig.usertoken,
  218. layerid: id,
  219. field_name: name,
  220. f: 'pjson'
  221. },
  222. success: (data) => {
  223. data = JSON.parse(data)
  224. console.log(id, name, texts, appconfig.gisResource.fieldUniqueValue.config[0].url)
  225. if (data.result && data.result.rows) {
  226. texts[name] = data.result.rows.map((e) => { return { value: e } })
  227. }
  228. },
  229. error: (error) => {
  230. this.$message.error('查询错误,请联系管理员')
  231. console.log(error)
  232. }
  233. })
  234. },
  235. queryFeature() {
  236. var Istr = this.inputT.replace(/^\s*|\s*$/g, '').toUpperCase()
  237. if (Istr == '') return this.$message('请输入查询内容')
  238. if (parseInt(this.selectT) == 2) {
  239. Istr = Istr.replace(',', ',')
  240. if (Istr.indexOf(',') < 0) return this.$message.error('请以 X坐标,Y坐标 格式输入 如: 104.4,30.8 ')
  241. Istr = Istr.split(',')
  242. try {
  243. var x = parseFloat(Istr[0])
  244. var y = parseFloat(Istr[1])
  245. } catch {
  246. return this.$message.error('坐标格式错误 请输入正确坐标格式 如: 104.4,30.8 ')
  247. }
  248. this.mapView.center = { x: x, y: y, spatialReference: this.mapView.spatialReference }
  249. if (this.mapView.zoom > 6) this.mapView.zoom = 6
  250. this.$message.success('跳转至 X:' + x + 'Y:' + y)
  251. } else {
  252. this.disabled = false
  253. this.queryResult = []
  254. this.showResult = true
  255. var config = this.queryConfig[['', '地名', '', '管径', '管材', '设施编号', '阀门类型', '阀门规格'][this.selectT]]
  256. const seed = new Date().getTime()
  257. this.timeTable = seed
  258. const ii = config.layers.length
  259. var statue = this.$refs.statue
  260. var dshow = 0; var dquery = 0
  261. this.allFea = []
  262. this.setFea = 0
  263. var firstLoad = false
  264. var ilength = ii
  265. this.$refs.queryNoMore.style.display = 'none'
  266. this.showGeo.geometry = { type: 'point', x: 0, y: 0, spatialReference: this.mapView.spatialReference }
  267. var fields = config.fields
  268. this.queryTitle = config.text
  269. for (let i = 0; i < ii; i++) {
  270. var dc = config.layers[i]
  271. const layerId = this.layerIndex[dc].id
  272. $.ajax({
  273. url: appconfig.gisResource.business_map.config[0].url + '/' + layerId + '/query',
  274. type: 'POST',
  275. data: {
  276. token: this.$store.state.user.arcgistoken,
  277. where: 'UPPER("' + fields + '")' +
  278. (config.isLike
  279. ? " like '%" + Istr.replace(/_/g, '$_').replace(/\?/g, '$?').replace(/%/g, '$%') + "%' ESCAPE '$'"
  280. : (" = '" + Istr + "'")),
  281. returnIdsOnly: true,
  282. f: 'pjson'
  283. },
  284. success: (data) => {
  285. ilength -= 1
  286. if (seed != this.timeTable) return
  287. data = JSON.parse(data)
  288. var str = ''
  289. if (!data.error) {
  290. data = data.objectIds
  291. if (data) {
  292. dquery += data.length
  293. var newRows = []
  294. for (var j = 0, jj = data.length; j < jj; j++) {
  295. newRows.push({ l: layerId, id: data[j] })
  296. }
  297. this.allFea = this.allFea.concat(newRows)
  298. }
  299. str += '找到相关结果:' + dquery + '个'
  300. if (!firstLoad && this.allFea.length > 0) {
  301. this.loadFun()
  302. firstLoad = true
  303. }
  304. }
  305. statue.innerHTML = str
  306. if (ilength == 0) {
  307. if (dquery == 0) {
  308. this.disabled = true
  309. this.showResult = false
  310. this.$message('未查询出结果')
  311. this.timeTable = undefined
  312. }
  313. }
  314. },
  315. error: (error) => {
  316. this.$message.error('查询错误,请联系管理员')
  317. console.log(error)
  318. }
  319. })
  320. }
  321. let setFea = 0
  322. var layerDir = this.layerIdIndex
  323. var layerNameDir = this.layerIndex
  324. var queryLoading = this.$refs.queryLoading
  325. this.loadFun = () => {
  326. this.disabled = true
  327. var il = this.allFea
  328. var quertIds = {}
  329. var ii = Math.min(setFea + 4, il.length)
  330. if (ii == 0) queryLoading.style.display = 'none'
  331. for (;setFea < ii; setFea++) {
  332. var di = il[setFea]
  333. if (quertIds.hasOwnProperty(di.l)) {
  334. quertIds[di.l].push(di.id)
  335. } else {
  336. quertIds[di.l] = [di.id]
  337. }
  338. }
  339. let inlength = 0
  340. for (const iname in quertIds) {
  341. inlength += 1
  342. $.ajax({
  343. url: appconfig.gisResource.business_map.config[0].url + '/' + iname + '/query',
  344. type: 'POST',
  345. data: {
  346. token: this.$store.state.user.arcgistoken,
  347. outFields: 'OBJECTID,SID,' + fields,
  348. objectIds: quertIds[iname].join(','),
  349. f: 'pjson'
  350. },
  351. success: (data) => {
  352. if (seed != this.timeTable) return
  353. data = JSON.parse(data).features
  354. var addRows = []
  355. for (var i = 0, ii = data.length; i < ii; i++) {
  356. var att = data[i].attributes
  357. var text = (att[fields] || '').toString()
  358. text = text.replace(
  359. new RegExp(Istr, 'g'),
  360. '<span class="highLight">' + Istr + '</span>'
  361. )
  362. addRows.push({ layer: layerNameDir[layerDir[iname]].name, id: att.SID || '', text: text, geomentry: data[i].geometry })
  363. }
  364. this.queryResult.push(...addRows)
  365. inlength -= 1
  366. if (inlength == 0) {
  367. queryLoading.style.display = 'none'
  368. // console.log(this.queryResult.length + ',' + this.allFea.length)
  369. this.disabled = false
  370. if (this.$refs.scroll.offsetHeight < 380) {
  371. if (ilength != 0) {
  372. firstLoad = false
  373. } else {
  374. this.$nextTick(this.load)
  375. }
  376. }
  377. }
  378. },
  379. error: (error) => {
  380. this.$message.error('查询错误,请联系管理员')
  381. }
  382. })
  383. }
  384. }
  385. }
  386. },
  387. load() {
  388. if (this.loadFun) {
  389. if (this.queryResult.length >= this.allFea.length) {
  390. this.disabled = true
  391. this.$refs.queryNoMore.style.display = ''
  392. } else {
  393. this.$refs.queryNoMore.style.display = 'none'
  394. this.$refs.queryLoading.style.display = ''
  395. this.disabled = true
  396. window.requestAnimationFrame(this.loadFun)
  397. }
  398. }
  399. },
  400. liClick(row) {
  401. var geo = row.geomentry
  402. var x, y
  403. if (geo.paths) {
  404. geo = geo.paths[0]
  405. x = (geo[0][0] + geo[1][0]) / 2
  406. y = (geo[0][1] + geo[1][1]) / 2
  407. } else if (geo.rings) {
  408. } else {
  409. x = geo.x, y = geo.y
  410. }
  411. this.showGeo.geometry = { type: 'point', x: x, y: y, spatialReference: this.mapView.spatialReference }
  412. this.mapView.goTo(
  413. {
  414. center: this.showGeo.geometry,
  415. zoom: 6
  416. }
  417. )
  418. },
  419. textClear() {
  420. this.queryResult = []
  421. this.showResult = false
  422. this.timeTable = undefined
  423. this.allFea = []
  424. this.showGeo.geometry = { type: 'point', x: 0, y: 0, spatialReference: this.mapView.spatialReference }
  425. },
  426. viewHistroy(isLast) {
  427. if (isLast) {
  428. if (this.extentIndex == 0) return
  429. this.extentIndex -= 1
  430. } else {
  431. if (this.extentIndex == this.extentGourp.length - 1) return
  432. this.extentIndex += 1
  433. }
  434. this.mapView.goTo(
  435. { center: this.extentGourp[this.extentIndex].center, zoom: this.extentGourp[this.extentIndex].zoom },
  436. { duration: 1000 }
  437. )
  438. this.isExtentChange = false
  439. if (this.isExtentTime) clearTimeout(this.isExtentTime)
  440. this.isExtentTime = setTimeout(() => { this.isExtentChange = true }, 1200)
  441. }
  442. }
  443. }
  444. </script>
  445. <style lang="scss" scoped>
  446. #resultDiv {
  447. padding: 15px 10px 10px 10px;
  448. background: rgb(246,246,246);
  449. border-radius: 5px;
  450. box-shadow: 0px 4px 18px #938cb3;
  451. }
  452. #resultDiv .load {
  453. background: #fff;
  454. color: rgb(153,153,153);
  455. font-size: 14px;
  456. padding: 4px;
  457. text-align: center;
  458. }
  459. #resultDiv .allResult {
  460. text-align: right;
  461. color: #555;
  462. font-size: 13px;
  463. }
  464. #resultUl {
  465. list-style-type: none;
  466. margin: 0px;
  467. padding: 0;
  468. padding-right: 5px;
  469. }
  470. #resultUl li {
  471. cursor: pointer;
  472. margin-bottom: 6px;
  473. background: #fff;
  474. position: relative;
  475. padding: 13px 10px;
  476. }
  477. #resultUl li .icon {
  478. position: absolute;
  479. right: 12px;
  480. top: 50%;
  481. font-size: 20px;
  482. transform: translateY(-50%);
  483. }
  484. #resultUl li div .title {
  485. font-size: 23px;
  486. letter-spacing: 1px;
  487. }
  488. #resultUl li div .other {
  489. color: rgb(153,153,153);
  490. font-size: 13px;
  491. }
  492. #resultUl li div .other .text {
  493. color: rgb(85,85,85);
  494. }
  495. #resultUl li:hover {
  496. background: #2d74e7;
  497. color: #fff;
  498. }
  499. #resultUl li div .title >>> .highLight {
  500. color: #2d74e7;
  501. }
  502. #resultUl li:hover div .title >>> .highLight {
  503. color: #fff;
  504. }
  505. #resultUl li:hover div .other {
  506. color: #fff;
  507. }
  508. #resultUl li:hover div .other .text {
  509. color: #fff;
  510. }
  511. </style>