Commit 4c871552 authored by 田翔's avatar 田翔

fix: 支持坐标与地名互相同步,附件bug

parent 48c08342
{
"name": "panda-xform",
"version": "4.6.4",
"description": "4.6.4 将站点id转化为字符串",
"version": "4.6.5",
"description": "4.6.5 支持坐标与地名互相同步,附件bug'修复",
"keywords": [
"panda-xform"
],
......
......@@ -746,6 +746,12 @@ const textWidgets = [
description: '所有形态默认显示',
widget: 'HiddenCondition'
},
coordSync: {
title: '坐标同步',
type: 'string',
widget: 'CoordSync',
description: '坐标信息将会同步到下方字段中'
},
required: {
title: '必填',
type: 'boolean',
......@@ -2028,6 +2034,7 @@ const fileWidgets = [
type: 'string',
widget: 'FileUpload',
width: '100%',
preview: true,
},
setting: {
widget: {
......
......@@ -61,7 +61,7 @@ const FileUpload = (props) => {
const { value, schema, onChange } = props
const { disabled, fileType, presetValue, placeholder, preview, download } = schema
const [showList, setShowList] = useState('')
const [showList, setShowList] = useState([])
const [visible, setVisible] = useState(false)
const [showFile, setShowFile] = useState({ fileType: '', filePath: '' })
......@@ -110,13 +110,13 @@ const FileUpload = (props) => {
message.error('上传失败!')
}
if (Array.isArray(fileList)) {
let list = fileList.map(v => v.sourcePath || v.value)
onChange(list.join(','))
setShowList(JSON.stringify(fileList))
setShowList(fileList)
} else {
onChange('')
setShowList()
}
if (file.status === 'done') {
onChange(fileList.map(v => v.sourcePath).join(','))
}
},
onPreview: (file) => {
if (!preview) return message.info('该附件禁止预览')
......@@ -142,16 +142,10 @@ const FileUpload = (props) => {
return <FileOutlined />
}
useEffect(() => {
if (presetValue && !presetValue.includes('拍照相册')) {
onChange(presetValue)
}
}, [presetValue])
useEffect(() => {
if (value) {
let fileList = []
let list = value ? value.split(',') : []
const valueToList = (presetValue) => {
let fileList = []
if (presetValue) {
let list = presetValue ? presetValue.split(',') : []
list.forEach((item, index) => {
if (item) { // @Tips: 直接过滤掉名字中有异常字符的文件
let uid = index + '_' + Math.random()
......@@ -171,16 +165,23 @@ const FileUpload = (props) => {
fileList.push(_obj);
}
})
setShowList(JSON.stringify(fileList))
}
}, [value])
return fileList
}
useEffect(() => {
if (presetValue && !presetValue.includes('拍照相册')) {
addons?.setValueByPath(addons.dataPath, presetValue || '')
setShowList(valueToList(presetValue))
}
}, [presetValue])
return (
<div className={styles.uploadBox}>
<Upload
disabled={disabled}
accept={accepts[fileType]}
fileList={showList ? JSON.parse(showList) : []}
fileList={showList}
className="upload-list-inline"
iconRender={iconRender}
{...option}
......
import React, { useState } from 'react'
import { Select, message } from 'antd'
import { ReloadTableFields } from '../../../../../apis/process'
const CoordSync = (props) => {
const { value, onChange, schema, addons } = props
const { tableNameParent } = addons.formData
const [options, setOptions] = useState([])
const onFocus = async () => {
if (!tableNameParent) {
return message.info('请选择表名!')
}
const { code, data, msg } = await ReloadTableFields({ tableName: tableNameParent })
if (code === 0) {
let result = data.root.map(v => { return { label: v.name, value: v.name } })
setOptions(result)
} else {
message.error(msg)
}
}
const selectChange = (value) => {
onChange(value)
}
return (
<Select
style={{ width: '100%' }}
options={options}
value={value}
onFocus={onFocus}
onChange={selectChange}
>
</Select>
)
}
export default CoordSync
\ No newline at end of file
......@@ -10,6 +10,7 @@ import FieldList from './FieldList'
import FieldName from './FieldName'
import CalculateRule from './CalculateRule'
import AddressSync from './AddressSync'
import CoordSync from './CoordSync'
import SimpleList from './SimpleList'
import SqlFilter from './SqlFilter'
......@@ -26,6 +27,7 @@ const groupSource = {
FieldName,
CalculateRule,
AddressSync,
CoordSync,
SimpleList,
SqlFilter,
}
......
import React, { useState, useEffect, useCallback } from 'react'
import { Input, message, Popover } from 'antd'
import { searchAdress } from '../../../../apis/process'
import { debounce } from '../../../../utils/index'
import { debounce, lngmkt, isObject } from '../../../../utils/index'
const SearchLocation = (props) => {
const areaName = window?.globalConfig?.mapsettings?.areasettings?.areaName || ''
const { value, onChange, schema, addons } = props
const { disabled, placeholder, presetValue } = schema
const { disabled, placeholder, presetValue, coordSync } = schema
const [options, setOptions] = useState([])
const getAdress = async (value) => {
......@@ -26,6 +26,34 @@ const SearchLocation = (props) => {
onChange(e.target.value)
}
const selectChange = (item) => {
if (item.location) {
let array = item.location.split(',')
let coord = lngmkt({ lng: array[0], lat: array[1] })
if (coordSync) {
let paths = Object.keys(addons.formData)
let targetPath = null
if (Array.isArray(paths)) {
paths.forEach(v => {
let values = addons.getValue(v)
if (isObject(values)) {
for (let key in values) {
if (key === coordSync) {
targetPath = `${v}.${key}`
}
}
}
})
}
// console.log(targetPath, coord)
if (targetPath) {
addons.setValue(targetPath, `${coord.x},${coord.y}`)
}
}
}
onChange(item.name)
}
useEffect(() => {
if (addons) {
addons.setValue(addons.dataPath, presetValue || '')
......@@ -35,7 +63,7 @@ const SearchLocation = (props) => {
const content = (
<div>
{
(options || []).map(v => <p key={v.name} onClick={() => onChange(v.name)}><a>{v.name}</a></p>)
(options || []).map((v, i) => <p key={i} onClick={() => selectChange(v)}><a>{v.name}</a></p>)
}
</div>
)
......
......@@ -85,6 +85,12 @@ export function parseSQL2JSON(str) {
};
}
/**
* @description 墨卡托转经纬度
* @param {*} x
* @param {*} y
* @returns
*/
export const mercatorToLngLat = (x, y) => {
const EARTH_RAD = 6378137
const radToAngle = (rad) => {
......@@ -95,6 +101,21 @@ export const mercatorToLngLat = (x, y) => {
return [lng, lat]
}
/**
* @description 经纬度转墨卡托
* @param {*} x
* @param {*} y
* @returns
*/
export const lngmkt = (poi) => {
var mercator = {};
var earthRad = 6378137.0;
mercator.x = ((poi.lng * Math.PI) / 180) * earthRad;
var a = (poi.lat * Math.PI) / 180;
mercator.y = (earthRad / 2) * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
return mercator; //[12727039.383734727, 3579066.6894065146
};
//判断是否为JSON字符串
export const isJson = (json) => {
if (typeof json === 'string') {
......
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