SpatialAnalysis.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <div class="menu-content">
  3. <div class="gradient-text common-dialog-title2">空间分析</div>
  4. <div class="analyze-data-container">
  5. <div class="item" @click="handleShowDetail">
  6. <div class="item-label">行政镇(个)</div>
  7. <div class="item-value">{{ validateNum(analysisData.townCount) }}</div>
  8. </div>
  9. <div class="item" @click="handleShowDetail">
  10. <div class="item-label">行政村(个)</div>
  11. <div class="item-value">{{ validateNum(analysisData.villageCount) }}</div>
  12. </div>
  13. <div class="item" @click="handleShowDetail">
  14. <div class="item-label">面积(km²)</div>
  15. <div class="item-value">{{ validateNum(analysisData.areaSize) }}</div>
  16. </div>
  17. <div class="item" @click="handleShowDetail">
  18. <div class="item-label">常住人口(万)</div>
  19. <div class="item-value">{{ validateNum(analysisData.populationSize) }}</div>
  20. </div>
  21. <div class="item" @click="handleShowDetail">
  22. <div class="item-label">GDP(万元)</div>
  23. <div class="item-value">{{ validateNum(analysisData.GDP) }}</div>
  24. </div>
  25. <div class="flex" style="margin: 15px 0 10px; width: 100%">
  26. <el-input v-model="keyword" class="custom-input2" placeholder="请输入" size="large" style="flex: 1" />
  27. </div>
  28. <div class="flex" style="flex-wrap: wrap">
  29. <div v-for="(item, index) in filteredList" :key="index" class="item2">{{ item.name + '(' + item.list.length + ')' }}</div>
  30. </div>
  31. </div>
  32. <Dialog v-if="showDetail" v-model="showDetail" title="空间分析" height="760px" hide-footer>
  33. <div class="common-btn-primary export-btn" @click="exportData">导出</div>
  34. <div class="common-table">
  35. <div class="table-header">
  36. <div class="td">序号</div>
  37. <div class="td">行政镇</div>
  38. <div class="td">行政村</div>
  39. <div class="td">常住人口(万)</div>
  40. <div class="td">面积(km2)</div>
  41. <div class="td">GDP(亿元)</div>
  42. </div>
  43. <div v-for="(item, index) in analysisData.townData" :key="index" class="tr">
  44. <div class="td">{{ index + 1 }}</div>
  45. <div class="td">{{ item.townName }}</div>
  46. <div class="td">{{ item.villageName ? item.villageName : '-' }}</div>
  47. <div class="td">{{ item.populationSize }}</div>
  48. <div class="td">{{ item.areaSize }}</div>
  49. <div class="td">{{ item.GDP }}</div>
  50. </div>
  51. </div>
  52. </Dialog>
  53. </div>
  54. </template>
  55. <script lang="ts" setup name="AnalyzeDataDialog">
  56. import { validateNum } from '@/utils/ruoyi';
  57. import { getSpatialAnalysis } from '@/api/globalMap';
  58. import { deepClone } from '@/utils';
  59. import * as XLSX from 'xlsx';
  60. const props = defineProps({
  61. updateLocation: []
  62. });
  63. const emits = defineEmits(['handleMenu']);
  64. const keyword = ref('');
  65. let analysisData = ref({
  66. townCount: '',
  67. townData: [],
  68. villageCount: '',
  69. areaSize: '',
  70. populationSize: '',
  71. GDP: '',
  72. list: []
  73. });
  74. const filteredList = computed(() => {
  75. const data = deepClone(analysisData.value.list);
  76. return data.filter((item) => {
  77. if (!!keyword.value) {
  78. // 模糊搜索逻辑,这里简单使用 includes 进行包含关系判断
  79. let flag = item.name.toLowerCase().includes(keyword.value.toLowerCase());
  80. if (flag) {
  81. return true;
  82. } else {
  83. let res = filteredSubItems(item);
  84. if (res && res.length > 0) {
  85. item.list = res;
  86. return true;
  87. } else {
  88. return false;
  89. }
  90. }
  91. } else {
  92. return true;
  93. }
  94. });
  95. });
  96. const filteredSubItems = (parentItem) => {
  97. return parentItem.list.filter((subItem) => {
  98. return subItem.name.toLowerCase().includes(keyword.value.toLowerCase());
  99. });
  100. };
  101. const location = ref([]);
  102. watch(
  103. () => props.updateLocation,
  104. () => {
  105. location.value = props.updateLocation;
  106. },
  107. {
  108. immediate: true,
  109. deep: true
  110. }
  111. );
  112. watch(
  113. () => location,
  114. () => {
  115. getSpatialAnalysis(location.value).then((res) => {
  116. if (res.data && res.data.list) {
  117. const list = [];
  118. res.data.list.forEach((item) => {
  119. if (item.num > 0) {
  120. list.push(item);
  121. }
  122. });
  123. res.data.list = list;
  124. }
  125. if (res.data && res.data.townData) {
  126. const data = [];
  127. res.data.townData.forEach((item) => {
  128. data.push(item);
  129. item.children.forEach((item2) => {
  130. const obj = deepClone(item2);
  131. obj.townName = item.townName;
  132. data.push(obj);
  133. });
  134. delete item.children;
  135. });
  136. res.data.townData = data;
  137. }
  138. analysisData.value = res.data;
  139. });
  140. },
  141. {
  142. immediate: true,
  143. deep: true
  144. }
  145. );
  146. let showDetail = ref(false);
  147. const handleShowDetail = () => {
  148. showDetail.value = true;
  149. };
  150. // 导出
  151. const exportData = () => {
  152. let jsonData = [];
  153. const headerMap = {
  154. townName: '行政镇',
  155. villageName: '行政村',
  156. populationSize: '常住人口(万)',
  157. areaSize: '面积(km2)',
  158. GDP: 'GDP(亿元)'
  159. };
  160. const orderedKeys = Object.keys(headerMap);
  161. analysisData.value.townData.forEach((item) => {
  162. const newItem = {};
  163. Object.keys(item).forEach((key) => {
  164. if (headerMap[key]) {
  165. newItem[headerMap[key]] = item[key];
  166. }
  167. });
  168. jsonData.push(newItem);
  169. });
  170. const worksheet = XLSX.utils.json_to_sheet(jsonData, {
  171. header: orderedKeys.map((key) => headerMap[key]) // 按 headerMap 顺序传递中文表头
  172. });
  173. // 创建工作簿并添加工作表
  174. const workbook = XLSX.utils.book_new();
  175. XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
  176. // 导出文件
  177. XLSX.writeFile(workbook, '空间分析数据.xlsx');
  178. };
  179. </script>
  180. <style lang="scss" scoped>
  181. .menu-content {
  182. width: 574px;
  183. height: 581px;
  184. background: url('@/assets/images/map/rightMenu/content.png') no-repeat;
  185. background-size: 100% 100%;
  186. padding: 60px 10px 10px 15px;
  187. font-size: 14px;
  188. position: relative;
  189. color: #ffffff;
  190. }
  191. .analyze-data-container {
  192. width: 100%;
  193. font-size: 16px;
  194. padding: 10px 0;
  195. display: flex;
  196. flex-wrap: wrap;
  197. .item {
  198. width: 130px;
  199. height: 60px;
  200. background: url('@/assets/images/map/rightMenu/ironTower/boxBg.png') no-repeat;
  201. background-size: 100% 100%;
  202. color: #fff;
  203. display: flex;
  204. flex-direction: column;
  205. justify-content: center;
  206. align-items: center;
  207. font-size: 14px;
  208. margin-right: 9px;
  209. cursor: pointer;
  210. &:nth-child(4) {
  211. margin-right: 0;
  212. }
  213. &:nth-child(5) {
  214. margin-top: 10px;
  215. }
  216. .item-label {
  217. margin-bottom: 5px;
  218. }
  219. }
  220. }
  221. .item2 {
  222. background-color: #0b184b;
  223. font-size: 14px;
  224. padding: 5px 10px;
  225. margin-right: 10px;
  226. color: #ffffff;
  227. border: 2px solid #247dff;
  228. border-radius: 4px;
  229. margin-top: 5px;
  230. }
  231. .export-btn {
  232. position: absolute;
  233. right: 20px;
  234. top: 55px;
  235. }
  236. </style>