index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <div :class="prefixCls" class="ai-base-station-page">
  3. <div class="filter-bar filter-bar--stacked">
  4. <div class="filter-row filter-row--carrier">
  5. <div class="filter-item filter-item--carrier">
  6. <span class="filter-item__label">MNC:</span>
  7. <RadioGroup v-model:value="formState.mnc">
  8. <Radio v-for="item in carrierOptions" :key="item.value" :value="item.value">{{ item.label }}</Radio>
  9. </RadioGroup>
  10. </div>
  11. </div>
  12. <div class="filter-row">
  13. <div class="filter-item">
  14. <span class="filter-item__label">LAC:</span>
  15. <Input
  16. v-model:value="formState.lac"
  17. class="filter-item__input"
  18. :maxlength="15"
  19. placeholder="请输入搜索内容"
  20. @input="handleCodeInput('lac', $event)"
  21. />
  22. </div>
  23. <div class="filter-item">
  24. <span class="filter-item__label">CID:</span>
  25. <Input
  26. v-model:value="formState.ci"
  27. class="filter-item__input"
  28. :maxlength="15"
  29. placeholder="请输入搜索内容"
  30. @input="handleCodeInput('ci', $event)"
  31. />
  32. </div>
  33. <div class="filter-item">
  34. <span class="filter-item__label">DEC/HEX:</span>
  35. <Select v-model:value="formState.radixMode" class="filter-item__select" :options="radixOptions" />
  36. </div>
  37. <div class="filter-actions">
  38. <Button type="primary" :loading="queryLoading" @click="handleSearch">搜索</Button>
  39. <Button @click="handleReset">重置</Button>
  40. </div>
  41. <div class="side-actions">
  42. <Button @click="handleFetchTemplate">获取转换基站模版</Button>
  43. <Button @click="handleConvertFile">批量转换基站</Button>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="content-panel">
  48. <div class="table-card">
  49. <div class="panel-header">
  50. <div>
  51. <div class="panel-title">基站结果地图</div>
  52. <div class="panel-desc">
  53. {{ resultSummary }}
  54. </div>
  55. </div>
  56. </div>
  57. <div class="table-panel">
  58. <div class="map-panel__body">
  59. <BaseStationQueryMap :points="mapPoints" />
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script lang="ts" setup name="ViewsAiBaseStationIndex">
  67. import { computed, ref } from 'vue';
  68. import { Button, Input, Radio, Select } from 'ant-design-vue';
  69. import { useDesign } from '@jeesite/core/hooks/web/useDesign';
  70. import { useMessage } from '@jeesite/core/hooks/web/useMessage';
  71. import { useTableSkill } from '@jeesite/core/hooks/web/useTableSkill';
  72. import {
  73. convertBaseStationData,
  74. fetchBaseStationTemplatePath,
  75. searchBaseStation,
  76. type BaseStationSearchLocation,
  77. type BaseStationSearchResponse,
  78. type BaseStationTemplateResponse,
  79. } from '@jeesite/trans/api/baseStationQueryApi';
  80. import BaseStationQueryMap, { type BaseStationMapPoint } from './components/BaseStationQueryMap.vue';
  81. type RadixMode = 'dec' | 'hex';
  82. const { prefixCls } = useDesign('ai-base-station');
  83. const { createConfirm, createMessage } = useMessage();
  84. const { queryLoading, runWithQueryLoading } = useTableSkill();
  85. const RadioGroup = Radio.Group;
  86. const carrierOptions: Array<{ label: string; value: string }> = [
  87. { label: '移动', value: '0' },
  88. { label: '联通', value: '1' },
  89. { label: '电信', value: '11' },
  90. ];
  91. const radixOptions: Array<{ label: string; value: RadixMode }> = [
  92. { label: '10进制', value: 'dec' },
  93. { label: '16进制', value: 'hex' },
  94. ];
  95. const formState = ref({
  96. mnc: '0',
  97. lac: '',
  98. ci: '',
  99. radixMode: 'dec' as RadixMode,
  100. });
  101. const mapPoints = ref<BaseStationMapPoint[]>([]);
  102. const normalizeText = (value: unknown) => String(value ?? '').trim();
  103. const getCarrierLabel = (value: string) => carrierOptions.find((item) => item.value === value)?.label || '未知运营商';
  104. const ipcRenderer = window.electron?.ipcRenderer;
  105. const resultSummary = computed(() => {
  106. if (!mapPoints.value.length) return '当前无可展示的基站坐标数据。';
  107. return `当前展示 ${mapPoints.value.length} 个查询命中基站点。`;
  108. });
  109. const sanitizeCodeText = (value: string) => value.replace(/[^0-9a-fA-F]/g, '');
  110. const handleCodeInput = (field: 'lac' | 'ci', event: Event) => {
  111. const input = event?.target as HTMLInputElement | null;
  112. const sanitized = sanitizeCodeText(input?.value || '');
  113. formState.value[field] = sanitized;
  114. };
  115. const normalizeCodeValue = (value: string, label: string) => {
  116. const text = normalizeText(value);
  117. if (!text) {
  118. throw new Error(`请输入${label}`);
  119. }
  120. if (formState.value.radixMode === 'hex') {
  121. if (!/^[0-9a-fA-F]+$/.test(text)) {
  122. throw new Error(`${label}仅支持 16 进制字符`);
  123. }
  124. return String(parseInt(text, 16));
  125. }
  126. if (!/^\d+$/.test(text)) {
  127. throw new Error(`${label}仅支持数字`);
  128. }
  129. return text;
  130. };
  131. const getFirstDefinedText = (...values: unknown[]) => {
  132. for (const value of values) {
  133. const text = normalizeText(value);
  134. if (text) return text;
  135. }
  136. return '';
  137. };
  138. const extractSearchLocation = (result: BaseStationSearchResponse): BaseStationSearchLocation | null => {
  139. if (!result) return null;
  140. if (Array.isArray(result)) {
  141. if (!result.length) return null;
  142. if (Array.isArray(result[0])) {
  143. const row = result[0] as Array<string | number | null>;
  144. return {
  145. lat: row?.[0],
  146. lng: row?.[1],
  147. address: row?.[2] as string | null,
  148. };
  149. }
  150. const firstItem = result[0];
  151. if (firstItem && typeof firstItem === 'object') {
  152. return firstItem as BaseStationSearchLocation;
  153. }
  154. return {
  155. lat: result?.[0] as string | number | null,
  156. lng: result?.[1] as string | number | null,
  157. address: result?.[2] as string | null,
  158. };
  159. }
  160. if (typeof result === 'object') {
  161. if ('rows' in result && Array.isArray(result.rows) && result.rows.length) return result.rows[0];
  162. if ('list' in result && Array.isArray(result.list) && result.list.length) return result.list[0];
  163. if ('records' in result && Array.isArray(result.records) && result.records.length) return result.records[0];
  164. if ('data' in result && result.data) return extractSearchLocation(result.data as BaseStationSearchResponse);
  165. if ('result' in result && result.result) return extractSearchLocation(result.result as BaseStationSearchResponse);
  166. return result as BaseStationSearchLocation;
  167. }
  168. return null;
  169. };
  170. const buildSingleSearchPoint = (result: BaseStationSearchResponse) => {
  171. const location = extractSearchLocation(result);
  172. if (!location) return null;
  173. const latitudeText = getFirstDefinedText(location.latitude, location.lat, location.y);
  174. const longitudeText = getFirstDefinedText(location.longitude, location.lng, location.lon, location.x);
  175. const range = getFirstDefinedText(location.range, location.radius);
  176. const address = getFirstDefinedText(location.address, location.addr, location.stationAddr, location.stationName);
  177. const lng = Number(longitudeText);
  178. const lat = Number(latitudeText);
  179. if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
  180. return null;
  181. }
  182. return {
  183. id: ['search', formState.value.mnc, formState.value.lac, formState.value.ci].join('||'),
  184. lng,
  185. lat,
  186. title: address || '查询结果',
  187. address,
  188. regionId: getFirstDefinedText(location.lac, formState.value.lac) || '-',
  189. cellId: getFirstDefinedText(location.ci, location.cid, formState.value.ci) || '-',
  190. longitudeText,
  191. latitudeText,
  192. range: range || '-',
  193. operatorName: getFirstDefinedText(location.operatorName, location.yys) || getCarrierLabel(formState.value.mnc),
  194. } satisfies BaseStationMapPoint;
  195. };
  196. const resolveTemplatePath = (payload: BaseStationTemplateResponse | null | undefined): string => {
  197. if (!payload) return '';
  198. if (typeof payload === 'string') return normalizeText(payload);
  199. const candidates = [
  200. payload.data,
  201. payload.path,
  202. payload.filePath,
  203. payload.file,
  204. payload.message,
  205. payload.msg,
  206. (payload.data as Recordable | null | undefined)?.path,
  207. (payload.data as Recordable | null | undefined)?.filePath,
  208. (payload.data as Recordable | null | undefined)?.file,
  209. ];
  210. for (const candidate of candidates) {
  211. const text = normalizeText(candidate);
  212. if (text) return text;
  213. }
  214. return '';
  215. };
  216. const openDirectoryByPath = async (targetPath: string) => {
  217. if (!ipcRenderer?.invoke) {
  218. createMessage.warning(`当前不在 Electron 环境,路径为:${targetPath}`);
  219. return;
  220. }
  221. const opened = await ipcRenderer.invoke('controller/os/openDirectory', { id: targetPath });
  222. if (!opened) {
  223. throw new Error('打开文件夹失败');
  224. }
  225. };
  226. const handleFetchTemplate = async () => {
  227. await runWithQueryLoading(async () => {
  228. const response = await fetchBaseStationTemplatePath();
  229. const code = typeof response === 'object' && response ? Number(response.code ?? 200) : 200;
  230. if (code !== 200) {
  231. throw new Error(
  232. (typeof response === 'object' && response && (response.message || response.msg)) || '获取导入模版失败',
  233. );
  234. }
  235. const templatePath = resolveTemplatePath(response);
  236. if (!templatePath) {
  237. throw new Error('未获取到转换基站模版路径');
  238. }
  239. createConfirm({
  240. title: '已获取转换基站模版',
  241. content: `模版路径为:<br/>${templatePath}<br/><br/>点击确定后将打开所在文件夹。`,
  242. iconType: 'success',
  243. okText: '打开文件夹',
  244. cancelText: '关闭',
  245. async onOk() {
  246. await openDirectoryByPath(templatePath);
  247. return Promise.resolve();
  248. },
  249. });
  250. }).catch((error: any) => {
  251. createMessage.error(error?.message || '获取转换基站模版失败');
  252. });
  253. };
  254. const handleSearch = async () => {
  255. let lac = '';
  256. let ci = '';
  257. try {
  258. lac = normalizeCodeValue(formState.value.lac, 'LAC');
  259. ci = normalizeCodeValue(formState.value.ci, 'CID');
  260. } catch (error: any) {
  261. createMessage.warning(error?.message || '请输入正确的查询条件');
  262. return;
  263. }
  264. await runWithQueryLoading(async () => {
  265. const result = await searchBaseStation({
  266. mnc: formState.value.mnc,
  267. lac,
  268. ci,
  269. });
  270. const point = buildSingleSearchPoint(result);
  271. mapPoints.value = point ? [point] : [];
  272. if (!point) {
  273. createMessage.warning('未查询到可用的基站坐标');
  274. }
  275. });
  276. };
  277. const handleReset = () => {
  278. formState.value = {
  279. mnc: '0',
  280. lac: '',
  281. ci: '',
  282. radixMode: 'dec',
  283. };
  284. mapPoints.value = [];
  285. };
  286. const doConvertFile = async (fileToken: string) => {
  287. await runWithQueryLoading(async () => {
  288. const convertResult = await convertBaseStationData(fileToken);
  289. const convertedPath = convertResult;
  290. if (!convertedPath) {
  291. createMessage.warning('转换完成,但未获取到有效路径');
  292. return;
  293. }
  294. createConfirm({
  295. title: '转换完成',
  296. content: `基站转换完成,路径为:<br/>${convertedPath}<br/><br/>点击确定后将打开所在文件夹。`,
  297. okText: '打开文件夹',
  298. cancelText: '关闭',
  299. iconType: 'success',
  300. async onOk() {
  301. if (!ipcRenderer?.invoke) return Promise.resolve();
  302. await ipcRenderer.invoke('controller/os/openDirectory', { id: convertedPath });
  303. return Promise.resolve();
  304. },
  305. });
  306. });
  307. };
  308. const handleConvertFile = async () => {
  309. if (!ipcRenderer?.invoke) {
  310. createMessage.warning('当前不在 Electron 环境');
  311. return;
  312. }
  313. const filePath: string = await ipcRenderer.invoke('controller/os/selectXlsFile');
  314. if (!filePath) return;
  315. await doConvertFile(filePath);
  316. };
  317. </script>
  318. <style lang="less">
  319. @import '../styles/trans-analysis-table-ui.less';
  320. @prefix-cls: ~'jeesite-ai-base-station';
  321. .@{prefix-cls}.ai-base-station-page {
  322. .analysis-single-panel-frame();
  323. .filter-bar {
  324. flex-direction: column;
  325. align-items: stretch;
  326. gap: 10px;
  327. padding: 6px 8px 8px;
  328. }
  329. .filter-row {
  330. display: flex;
  331. align-items: center;
  332. gap: 8px;
  333. flex-wrap: wrap;
  334. }
  335. .filter-row--carrier {
  336. min-height: 24px;
  337. }
  338. .filter-item {
  339. display: flex;
  340. align-items: center;
  341. gap: 4px;
  342. min-width: 0;
  343. }
  344. .filter-item--carrier {
  345. gap: 8px;
  346. }
  347. .filter-item__label {
  348. color: #6b7280;
  349. font-size: 12px;
  350. line-height: 20px;
  351. white-space: nowrap;
  352. }
  353. .filter-item__input {
  354. width: 180px;
  355. }
  356. .filter-item__select {
  357. width: 160px;
  358. }
  359. .filter-actions,
  360. .side-actions {
  361. display: flex;
  362. align-items: center;
  363. gap: 6px;
  364. }
  365. .side-actions {
  366. margin-left: auto;
  367. }
  368. .table-card {
  369. padding: 8px;
  370. }
  371. .table-panel {
  372. padding-top: 0;
  373. }
  374. .map-panel__body {
  375. display: flex;
  376. flex: 1 1 auto;
  377. min-height: 0;
  378. overflow: hidden;
  379. }
  380. :deep(.ant-radio-wrapper) {
  381. color: #475569;
  382. font-size: 14px;
  383. }
  384. :deep(.ant-input),
  385. :deep(.ant-select-selector),
  386. :deep(.ant-btn) {
  387. border-radius: 8px;
  388. }
  389. @media screen and (max-width: 1280px) {
  390. .side-actions {
  391. margin-left: 0;
  392. }
  393. }
  394. @media screen and (max-width: 992px) {
  395. .filter-row {
  396. gap: 12px;
  397. }
  398. .filter-item,
  399. .filter-item__input,
  400. .filter-item__select,
  401. .filter-actions,
  402. .side-actions {
  403. width: 100%;
  404. }
  405. .filter-actions,
  406. .side-actions {
  407. margin-left: 0;
  408. justify-content: flex-start;
  409. }
  410. }
  411. }
  412. </style>