Merge remote-tracking branch 'origin/qcast-pub' into dev
# Conflicts: # src/components/floor-plan/modal/setting01/FirstOption.jsx
This commit is contained in:
commit
022cbf1e2d
@ -11,5 +11,5 @@ export async function POST(req) {
|
|||||||
const buffer = Buffer.from(arrayBuffer)
|
const buffer = Buffer.from(arrayBuffer)
|
||||||
await writeImage(fileName, buffer)
|
await writeImage(fileName, buffer)
|
||||||
|
|
||||||
return NextResponse.json({ fileNm: `${fileName}` })
|
return NextResponse.json({ fileNm: `${fileName}.png` })
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,20 +33,17 @@ export default function ImgLoad() {
|
|||||||
const { floorPlanState, setFloorPlanState } = useContext(FloorPlanContext)
|
const { floorPlanState, setFloorPlanState } = useContext(FloorPlanContext)
|
||||||
|
|
||||||
const handleModal = () => {
|
const handleModal = () => {
|
||||||
console.log('floorPlanState', floorPlanState)
|
|
||||||
console.log('currentCanvasPlan', currentCanvasPlan)
|
|
||||||
console.log('refImage', refImage)
|
|
||||||
setFloorPlanState({ ...floorPlanState, refFileModalOpen: false, toggleRotate: false })
|
setFloorPlanState({ ...floorPlanState, refFileModalOpen: false, toggleRotate: false })
|
||||||
setCurrentCanvasPlan({
|
setCurrentCanvasPlan({
|
||||||
...currentCanvasPlan,
|
...currentCanvasPlan,
|
||||||
bgImageName: currentCanvasPlan?.bgImageName ?? null,
|
bgImageName: refImage?.name ?? null,
|
||||||
mapPositionAddress,
|
mapPositionAddress,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// console.log('🚀 ~ ImgLoad ~ floorPlanState.refFileModalOpen:', floorPlanState.refFileModalOpen)
|
console.log('🚀 ~ ImgLoad ~ floorPlanState.refFileModalOpen:', floorPlanState.refFileModalOpen)
|
||||||
// console.log('🚀 ~ ImgLoad ~ currentCanvasPlan:', currentCanvasPlan)
|
console.log('🚀 ~ ImgLoad ~ currentCanvasPlan:', currentCanvasPlan)
|
||||||
}, [floorPlanState.refFileModalOpen])
|
}, [floorPlanState.refFileModalOpen])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -65,11 +62,9 @@ export default function ImgLoad() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!currentCanvasPlan) return
|
if (!currentCanvasPlan) return
|
||||||
console.log('currentCanvasPlan', currentCanvasPlan)
|
|
||||||
const refFileMethod = currentCanvasPlan?.mapPositionAddress === null || currentCanvasPlan?.mapPositionAddress?.trim() === '' ? '1' : '2'
|
const refFileMethod = currentCanvasPlan?.mapPositionAddress === null || currentCanvasPlan?.mapPositionAddress?.trim() === '' ? '1' : '2'
|
||||||
setRefFileMethod(refFileMethod)
|
setRefFileMethod(refFileMethod)
|
||||||
setMapPositionAddress(currentCanvasPlan?.mapPositionAddress ?? '')
|
setMapPositionAddress(currentCanvasPlan?.mapPositionAddress ?? '')
|
||||||
console.log(currentCanvasPlan)
|
|
||||||
}, [currentCanvasPlan])
|
}, [currentCanvasPlan])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -111,14 +106,13 @@ export default function ImgLoad() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="img-name-wrap">
|
<div className="img-name-wrap">
|
||||||
{/* <input type="text" className="input-origin al-l" defaultValue={'IMG_Name.PNG'} readOnly />
|
<input
|
||||||
<button className="img-check"></button> */}
|
type="text"
|
||||||
{!currentCanvasPlan?.bgImageName ? (
|
className="input-origin al-l"
|
||||||
<input type="text" className="input-origin al-l" value={refImage ? 'ref' + refImage.name : ''} readOnly />
|
value={refImage ? (refImage?.name ?? '') : (currentCanvasPlan?.bgImageName ?? '')}
|
||||||
) : (
|
readOnly
|
||||||
<input type="text" className="input-origin al-l" value={'bg' + currentCanvasPlan?.bgImageName} readOnly />
|
/>
|
||||||
)}
|
{refImage && <button className="img-check" onClick={handleFileDelete}></button>}
|
||||||
{(refImage || currentCanvasPlan?.bgImageName) && <button className="img-check" onClick={handleFileDelete}></button>}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -34,7 +34,7 @@ export const Orientation = forwardRef(({ tabNum }, ref) => {
|
|||||||
onClick={() => setCompasDeg(15 * (12 + index))}
|
onClick={() => setCompasDeg(15 * (12 + index))}
|
||||||
>
|
>
|
||||||
{index === 0 && <i>180°</i>}
|
{index === 0 && <i>180°</i>}
|
||||||
{index === 6 && <i>270°</i>}
|
{index === 6 && <i>-90°</i>}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{Array.from({ length: 180 / 15 }).map((dot, index) => (
|
{Array.from({ length: 180 / 15 }).map((dot, index) => (
|
||||||
@ -56,7 +56,7 @@ export const Orientation = forwardRef(({ tabNum }, ref) => {
|
|||||||
<div className="center-wrap">
|
<div className="center-wrap">
|
||||||
<div className="d-check-box pop">
|
<div className="d-check-box pop">
|
||||||
<input type="checkbox" id="ch99" checked={!hasAnglePassivity} onChange={() => setHasAnglePassivity(!hasAnglePassivity)} />
|
<input type="checkbox" id="ch99" checked={!hasAnglePassivity} onChange={() => setHasAnglePassivity(!hasAnglePassivity)} />
|
||||||
<label htmlFor="ch99">{getMessage('modal.module.basic.setting.orientation.setting.angle.passivity')}(0〜360)</label>
|
<label htmlFor="ch99">{getMessage('modal.module.basic.setting.orientation.setting.angle.passivity')}(-180 〜 180)</label>
|
||||||
</div>
|
</div>
|
||||||
<div className="outline-form">
|
<div className="outline-form">
|
||||||
<div className="input-grid mr10" style={{ width: '160px' }}>
|
<div className="input-grid mr10" style={{ width: '160px' }}>
|
||||||
|
|||||||
@ -41,7 +41,14 @@ export default function FirstOption() {
|
|||||||
setSurfaceShapePattern(polygon, item.column)
|
setSurfaceShapePattern(polygon, item.column)
|
||||||
})
|
})
|
||||||
//디스플레이 설정 표시(단 건 선택)
|
//디스플레이 설정 표시(단 건 선택)
|
||||||
} else {
|
} else if (item.column === 'imageDisplay') {
|
||||||
|
item.selected = !item.selected
|
||||||
|
canvas
|
||||||
|
.getObjects()
|
||||||
|
.filter((obj) => obj.name === 'backGroundImage')
|
||||||
|
.forEach((image) => (image.visible = item.selected))
|
||||||
|
canvas.renderAll()
|
||||||
|
}else {
|
||||||
const options = settingModalFirstOptions?.option1.map((opt) => {
|
const options = settingModalFirstOptions?.option1.map((opt) => {
|
||||||
if (opt.id === item.id) {
|
if (opt.id === item.id) {
|
||||||
opt.selected = !opt.selected
|
opt.selected = !opt.selected
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { useRecoilState, useRecoilValue } from 'recoil'
|
import { useRecoilState, useRecoilValue } from 'recoil'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
|
||||||
import fs from 'fs/promises'
|
|
||||||
|
|
||||||
import { useSwal } from '@/hooks/useSwal'
|
import { useSwal } from '@/hooks/useSwal'
|
||||||
import { useAxios } from '../useAxios'
|
import { useAxios } from '../useAxios'
|
||||||
@ -14,13 +12,13 @@ export function useRefFiles() {
|
|||||||
const [refImage, setRefImage] = useState(null)
|
const [refImage, setRefImage] = useState(null)
|
||||||
const [refFileMethod, setRefFileMethod] = useState('1')
|
const [refFileMethod, setRefFileMethod] = useState('1')
|
||||||
const [mapPositionAddress, setMapPositionAddress] = useState('')
|
const [mapPositionAddress, setMapPositionAddress] = useState('')
|
||||||
const [currentCanvasPlan, setCurrentCanvasPlan] = useRecoilState(currentCanvasPlanState)
|
|
||||||
const queryRef = useRef(null)
|
|
||||||
const canvas = useRecoilValue(canvasState)
|
|
||||||
const [currentBgImage, setCurrentBgImage] = useState(null)
|
const [currentBgImage, setCurrentBgImage] = useState(null)
|
||||||
|
const queryRef = useRef(null)
|
||||||
|
const [currentCanvasPlan, setCurrentCanvasPlan] = useRecoilState(currentCanvasPlanState)
|
||||||
|
const canvas = useRecoilValue(canvasState)
|
||||||
|
const { handleBackImageLoadToCanvas } = useCanvas()
|
||||||
const { swalFire } = useSwal()
|
const { swalFire } = useSwal()
|
||||||
const { get, promisePut, promiseGet, promisePost } = useAxios()
|
const { get, post, promisePost } = useAxios()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (refFileMethod === '1') {
|
if (refFileMethod === '1') {
|
||||||
@ -30,6 +28,20 @@ export function useRefFiles() {
|
|||||||
setRefImage(null)
|
setRefImage(null)
|
||||||
}
|
}
|
||||||
}, [refFileMethod])
|
}, [refFileMethod])
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 현재 플랜이 변경되면 플랜 상태 저장
|
||||||
|
*/
|
||||||
|
useEffect(() => {
|
||||||
|
// console.log('🚀 ~ useRefFiles ~ currentCanvasPlan:', currentCanvasPlan)
|
||||||
|
// const handleCurrentPlan = async () => {
|
||||||
|
// await promisePut({ url: '/api/canvas-management/canvas-statuses', data: currentCanvasPlan }).then((res) => {
|
||||||
|
// console.log('🚀 ~ awaitpromisePut ~ res:', res)
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// handleCurrentPlan()
|
||||||
|
}, [currentCanvasPlan])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 파일 불러오기 버튼 컨트롤
|
* 파일 불러오기 버튼 컨트롤
|
||||||
* @param {*} file
|
* @param {*} file
|
||||||
@ -37,11 +49,26 @@ export function useRefFiles() {
|
|||||||
const handleRefFile = (file) => {
|
const handleRefFile = (file) => {
|
||||||
console.log('handleRefFile', file)
|
console.log('handleRefFile', file)
|
||||||
console.log('refImage', refImage)
|
console.log('refImage', refImage)
|
||||||
|
|
||||||
|
if (refImage) {
|
||||||
|
swalFire({
|
||||||
|
text: '파일을 변경하시겠습니까?',
|
||||||
|
type: 'confirm',
|
||||||
|
confirmFn: () => {
|
||||||
|
refFileSetting(file)
|
||||||
|
// setRefImage(file)
|
||||||
|
// file.name.split('.').pop() === 'dwg' ? handleUploadConvertRefFile(file) : handleUploadImageRefFile(file)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
refFileSetting(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const refFileSetting = (file) => {
|
||||||
if (file && ['image/png', 'image/jpg', 'image/jpeg', 'image/bmp', 'image/gif'].includes(file.type)) {
|
if (file && ['image/png', 'image/jpg', 'image/jpeg', 'image/bmp', 'image/gif'].includes(file.type)) {
|
||||||
// setRefImage(file)
|
// setRefImage(file)
|
||||||
file.name.split('.').pop() === 'dwg' ? handleUploadConvertRefFile(file) : handleUploadImageRefFile(file)
|
file.name.split('.').pop() === 'dwg' ? handleUploadConvertRefFile(file) : handleUploadImageRefFile(file)
|
||||||
|
|
||||||
return
|
|
||||||
} else {
|
} else {
|
||||||
swalFire({
|
swalFire({
|
||||||
text: '이미지가 아닙니다.',
|
text: '이미지가 아닙니다.',
|
||||||
@ -49,30 +76,7 @@ export function useRefFiles() {
|
|||||||
icon: 'error',
|
icon: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (refImage) {
|
|
||||||
swalFire({
|
|
||||||
text: '파일을 변경하시겠습니까?',
|
|
||||||
type: 'confirm',
|
|
||||||
confirmFn: () => {
|
|
||||||
setRefImage(file)
|
|
||||||
const backGroundImage = canvas.getObjects().filter((obj) => obj.name === 'backGroundImage')
|
|
||||||
if (backGroundImage.length > 0) {
|
|
||||||
canvas.remove(backGroundImage)
|
|
||||||
}
|
}
|
||||||
canvas.renderAll()
|
|
||||||
file.name.split('.').pop() === 'dwg' ? handleUploadConvertRefFile(file) : handleUploadImageRefFile(file)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 파일 확장자가 dwg일 경우 변환하여 이미지로 저장
|
|
||||||
* 파일 확장자가 이미지일 경우 이미지 저장
|
|
||||||
*/
|
|
||||||
|
|
||||||
// handleUploadRefFile(file)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 파일 삭제
|
* 파일 삭제
|
||||||
*/
|
*/
|
||||||
@ -133,30 +137,25 @@ export function useRefFiles() {
|
|||||||
}
|
}
|
||||||
console.log('🚀 ~ useEffect ~ currentBgImage:', currentBgImage)
|
console.log('🚀 ~ useEffect ~ currentBgImage:', currentBgImage)
|
||||||
handleBackImageLoadToCanvas(`plan-images/${currentCanvasPlan.id}.png`)
|
handleBackImageLoadToCanvas(`plan-images/${currentCanvasPlan.id}.png`)
|
||||||
setCurrentCanvasPlan((prev) => ({ ...prev, bgImageName: currentCanvasPlan.id, mapPositionAddress: queryRef.current.value }))
|
setCurrentCanvasPlan((prev) => ({ ...prev, bgImageName: refImage?.name ?? null, mapPositionAddress: queryRef.current.value }))
|
||||||
}, [currentBgImage])
|
}, [currentBgImage])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 이미지 파일 업로드
|
* 이미지 파일 업로드
|
||||||
* @param {*} file
|
* @param {*} file
|
||||||
*/
|
*/
|
||||||
const { handleBackImageLoadToCanvas } = useCanvas()
|
|
||||||
const handleUploadImageRefFile = async (file) => {
|
const handleUploadImageRefFile = async (file) => {
|
||||||
// console.log('🚀 ~ handleUploadImageRefFile ~ file:', file)
|
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('file', file)
|
formData.append('file', file)
|
||||||
formData.append('fileName', currentCanvasPlan.id)
|
formData.append('fileName', currentCanvasPlan.id)
|
||||||
|
|
||||||
const response = await fetch('http://localhost:3000/api/image-upload', {
|
const res = await post({ url: 'http://localhost:3000/api/image-upload', data: formData })
|
||||||
method: 'POST',
|
console.log('🚀 ~ handleUploadImageRefFile ~ res:', res)
|
||||||
body: formData,
|
const image = await readImage(res.fileNm)
|
||||||
})
|
console.log('🚀 ~ handleUploadImageRefFile ~ file:', image)
|
||||||
|
|
||||||
handleBackImageLoadToCanvas(`plan-images/${currentCanvasPlan.id}.png`)
|
setCurrentBgImage(image)
|
||||||
const result = await response.json()
|
|
||||||
setRefImage(file)
|
setRefImage(file)
|
||||||
// console.log('🚀 ~ handleUploadImageRefFile ~ res:', result)
|
|
||||||
// writeImageBuffer(file)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -186,19 +185,6 @@ export function useRefFiles() {
|
|||||||
setRefFileMethod(e.target.value)
|
setRefFileMethod(e.target.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 현재 플랜이 변경되면 플랜 상태 저장
|
|
||||||
*/
|
|
||||||
useEffect(() => {
|
|
||||||
// console.log('🚀 ~ useRefFiles ~ currentCanvasPlan:', currentCanvasPlan)
|
|
||||||
// const handleCurrentPlan = async () => {
|
|
||||||
// await promisePut({ url: '/api/canvas-management/canvas-statuses', data: currentCanvasPlan }).then((res) => {
|
|
||||||
// console.log('🚀 ~ awaitpromisePut ~ res:', res)
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// handleCurrentPlan()
|
|
||||||
}, [currentCanvasPlan])
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
refImage,
|
refImage,
|
||||||
queryRef,
|
queryRef,
|
||||||
|
|||||||
@ -507,8 +507,6 @@ export function useCanvas(id) {
|
|||||||
* cad 파일 사용시 이미지 로딩 함수
|
* cad 파일 사용시 이미지 로딩 함수
|
||||||
*/
|
*/
|
||||||
const handleBackImageLoadToCanvas = (url) => {
|
const handleBackImageLoadToCanvas = (url) => {
|
||||||
console.log('image load url: ', url)
|
|
||||||
|
|
||||||
canvas
|
canvas
|
||||||
.getObjects()
|
.getObjects()
|
||||||
.filter((obj) => obj.name === 'backGroundImage')
|
.filter((obj) => obj.name === 'backGroundImage')
|
||||||
@ -516,7 +514,7 @@ export function useCanvas(id) {
|
|||||||
canvas.remove(img)
|
canvas.remove(img)
|
||||||
canvas?.renderAll()
|
canvas?.renderAll()
|
||||||
})
|
})
|
||||||
fabric.Image.fromURL(url, function (img) {
|
fabric.Image.fromURL(`${url}?${new Date().getTime()}`, function (img) {
|
||||||
console.log(img)
|
console.log(img)
|
||||||
img.set({
|
img.set({
|
||||||
left: 0,
|
left: 0,
|
||||||
@ -536,7 +534,6 @@ export function useCanvas(id) {
|
|||||||
canvas?.add(img)
|
canvas?.add(img)
|
||||||
canvas?.sendToBack(img)
|
canvas?.sendToBack(img)
|
||||||
canvas?.renderAll()
|
canvas?.renderAll()
|
||||||
console.log(canvas.getObjects().filter((obj) => obj.name === 'backGroundImage'))
|
|
||||||
setBackImg(img)
|
setBackImg(img)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -200,6 +200,7 @@ export function usePlan() {
|
|||||||
userId: userId,
|
userId: userId,
|
||||||
imageName: 'image_name', // api 필수항목이여서 임시로 넣음, 이후 삭제 필요
|
imageName: 'image_name', // api 필수항목이여서 임시로 넣음, 이후 삭제 필요
|
||||||
objectNo: objectNo,
|
objectNo: objectNo,
|
||||||
|
bgImageName: currentCanvasPlan?.bgImageName ?? null,
|
||||||
mapPositionAddress: currentCanvasPlan?.mapPositionAddress ?? null,
|
mapPositionAddress: currentCanvasPlan?.mapPositionAddress ?? null,
|
||||||
canvasStatus: canvasToDbFormat(canvasStatus),
|
canvasStatus: canvasToDbFormat(canvasStatus),
|
||||||
}
|
}
|
||||||
@ -220,8 +221,8 @@ export function usePlan() {
|
|||||||
const putCanvasStatus = async (canvasStatus) => {
|
const putCanvasStatus = async (canvasStatus) => {
|
||||||
const planData = {
|
const planData = {
|
||||||
id: currentCanvasPlan.id,
|
id: currentCanvasPlan.id,
|
||||||
bgImageName: currentCanvasPlan?.id ?? null,
|
bgImageName: currentCanvasPlan?.bgImageName ?? null,
|
||||||
mapPositionAddress: currentCanvasPlan.mapPositionAddress,
|
mapPositionAddress: currentCanvasPlan?.mapPositionAddress ?? null,
|
||||||
canvasStatus: canvasToDbFormat(canvasStatus),
|
canvasStatus: canvasToDbFormat(canvasStatus),
|
||||||
}
|
}
|
||||||
await promisePut({ url: '/api/canvas-management/canvas-statuses', data: planData })
|
await promisePut({ url: '/api/canvas-management/canvas-statuses', data: planData })
|
||||||
|
|||||||
@ -62,16 +62,13 @@ const writeImageBase64 = async (title, data) => {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
const writeImage = async (fileName, file) => {
|
const writeImage = async (fileName, file) => {
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
try {
|
try {
|
||||||
fs.readdir(FILE_PATH)
|
await fs.readdir(FILE_PATH)
|
||||||
} catch {
|
} catch {
|
||||||
fs.mkdir(FILE_PATH)
|
await fs.mkdir(FILE_PATH)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFile(`${FILE_PATH}/${fileName}.png`, file)
|
return fs.writeFile(`${FILE_PATH}/${fileName}.png`, file)
|
||||||
resolve(true)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const readImage = async (fileName) => {
|
const readImage = async (fileName) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user