Commit c58ce610 authored by 田翔's avatar 田翔

fix: 地址坐标形态优化

parent 746c879b
{
"name": "panda-xform",
"version": "4.6.1",
"description": "4.6.1 获取站点列表修复",
"version": "4.6.3",
"description": "4.6.3 地址坐标形态优化",
"keywords": [
"panda-xform"
],
......
......@@ -351,6 +351,7 @@ export function QueryAddFields(accountName) {
})
}
//根据坐标点获取地名
export function getLocation(location) {
return request({
url: `/pandagis/mapserver/Tool/PlaceAround?key=6e0b74fa6de65506b360e2e801f8582f&location=${location}`,
......@@ -358,6 +359,14 @@ export function getLocation(location) {
})
}
//模糊搜索地名
export function searchAdress({ keywords, region }) {
return request({
url: `/pandagis/mapserver/Tool/PlaceAroundV2?key=6e0b74fa6de65506b360e2e801f8582f&keywords=${keywords}&region=${region}`,
method: 'get'
})
}
//获取表字段
export function LoadTableFields(paramas) {
return request({
......
import React, { useMemo } from 'react'
import styles from './index.less'
import { isObject } from '../../../../utils'
const PrintXform = (props) => {
const { schemaForm, form } = props
const formTable = useMemo(() => {
const { column, properties } = schemaForm
let hiddenFields = Object.keys(form.getHiddenValues()).map(v => v?.split('.')?.[1])
let formValue = {}
Object.keys(form.formData).map(v => {
if (isObject(form.formData[v])) {
Object.keys(form.formData[v]).forEach(s => {
formValue[s] = form.formData[v][s]
})
}
})
let array = []
Object.keys(properties).map(v => {
let childObj = properties[v]?.properties || {}
let child = []
let num = 0
Object.keys(childObj).forEach(s => {
if (!hiddenFields.includes(s)) {
let width = childObj[s].width || ((100 / column).toFixed(2) + '%')
if (width !== '100%') {
num++
}
child.push({
title: childObj[s].title,
fieldName: s,
fieldValue: formValue[s],
width: width,
labelWidth: childObj[s].labelWidth || 120
})
}
})
if (num % column !== 0 && child[child.length - 1] !== '100%') {
child[child.length - 1].width = ((100 / column) * (column + 1 - num % column)).toFixed(2) + '%'
}
array.push({
title: properties[v].title,
fieldName: v,
fieldValue: null,
child,
})
})
return array
}, [schemaForm, form])
return (
<div className={styles.printXform}>
{
formTable.map(v => {
return (
<div className={styles.printGroup} key={v.fieldName}>
<div className={styles.groupName}>{v.title}</div>
<div className={styles.boxs}>
{
v.child.map(s => {
return (
<div key={s.fieldName} className={styles.box} style={{ width: s.width }}>
<div className={styles.itemLeft} style={{ width: s.labelWidth }}>{s.title}</div>
<div className={styles.itemRight}>{s.fieldValue}</div>
</div>
)
})
}
</div>
</div>
)
})
}
</div>
)
}
export default PrintXform
\ No newline at end of file
.printXform {
width: 100%;
.printGroup {
width: 100%;
&:nth-last-child(1) {
border-bottom: 1px solid #aaa;
}
.groupName {
width: 100%;
padding: 0 10px;
height: 33px;
line-height: 33px;
font-weight: bold;
border: 1px solid #aaa;
}
.boxs {
width: 100%;
display: flex;
flex-wrap: wrap;
.box {
display: flex;
height: 33px;
line-height: 33px;
border: 1px solid #aaa;
.itemLeft {
overflow: hidden;
padding: 0 10px;
width: 200px;
border-right: 1px solid #aaa;
}
.itemRight {
flex: 1;
padding: 0 10px;
}
}
}
}
}
\ No newline at end of file
......@@ -11,7 +11,6 @@ import widgets from '../widgets'
import { isObject } from '../../utils'
import { getWatch } from './watch'
import styles from '../../main.less'
// import PrintXform from './components/PrintXform'
const XRender = (props, ref) => {
......
import React, { useState, useEffect, useContext } from 'react'
import { Input, message } from 'antd'
import { AMap } from '@wisdom-map/amap'
import React, { useState, useEffect, useCallback } from 'react'
import { Input, message, Popover } from 'antd'
import { searchAdress } from '../../../../apis/process'
import { debounce } from '../../../../utils/index'
const SearchLocation = (props) => {
const { value, onChange, name, schema, addons } = props
const { disabled, placeholder, presetValue } = schema
const [extraData, setExtraData] = useState(null);
const [address, setAddress] = useState('');
const [pos, setPos] = useState('');
const renderSearch = async () => {
// 封装之后的AMap,如果需要使用高德地图上的方法,则需要按照如下方法去使用
AMap.prototype.key = 'e83f64300a2a55a33fa8e4ab9a46bca6';
let map = await AMap.prototype.loadLocaScript();
map?.plugin(['AMap.PlaceSearch', 'AMap.AutoComplete'], function (e) {
let auto = new map.AutoComplete({
input: 'searchInput'
});
auto.on('select', function (e) {
if (e?.poi?.location?.pos?.length) {
let _pos = e.poi.location.pos.join(',');
setPos(_pos);
setAddress(e.poi.name);
let _extraData = extraData ? { ...extraData } : {};
_extraData.pos = _pos;
setExtraData(_extraData);
onChange(e.poi.name);
} else {
setAddress('');
setPos('');
onChange('');
message.error('当前地址无坐标,请重新选取')
}
});
})
const areaName = window?.globalConfig?.mapsettings?.areasettings?.areaName || ''
const { value, onChange, schema, addons } = props
const { disabled, placeholder, presetValue } = schema
const [options, setOptions] = useState([])
const getAdress = async (value) => {
const { code, data } = await searchAdress({ keywords: `${areaName}${value}`, region: areaName })
if (code === '0') {
setOptions(data?.pois)
} else {
message.error('请求错误!')
}
}
const inputChange = (e) => {
if (addons) {
setAddress(e.target.value)
onChange(e.target.value)
}
const doSomeThing = useCallback(debounce(getAdress), [])
const onSearch = async (e) => {
doSomeThing(e.target.value)
onChange(e.target.value)
}
useEffect(() => {
if (addons) {
addons.setValue(addons.dataPath, presetValue)
addons.setValue(addons.dataPath, presetValue || '')
}
}, [presetValue])
useEffect(() => {
if (addons) {
renderSearch()
}
// if (value) setAddress(value)
}, [value])
const content = (
<div>
{
(options || []).map(v => <p key={v.name} onClick={() => onChange(v.name)}><a>{v.name}</a></p>)
}
</div>
)
return (
<Input
placeholder={placeholder}
disabled={disabled}
onChange={inputChange}
id={addons ? 'searchInput' : null}
value={value}
style={{ width: '100%' }}
/>
<div>
<Popover content={content} title="地名选择" trigger="hover" placement="topLeft">
<Input
disabled={disabled}
placeholder={placeholder}
value={value}
onChange={onSearch}
/>
</Popover>
</div>
)
}
......
......@@ -124,8 +124,10 @@ export const debounce = (fn) => {
clearTimeout(t)
}
t = setTimeout(function () {
fn.call(context, args)
}, 500)
if (typeof fn === 'function') {
fn.call(context, ...args)
}
}, 300)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment