demo-int-table/front/src/stores/floorplan.ts

38 lines
1.3 KiB
TypeScript

import { defineStore } from 'pinia'
import { SERVER_URL } from '../constants'
import { chunks } from '../helpers'
export const useFloorplanStore = defineStore('floorplan', {
state: () => {
return {
title: undefined,
chunkSize: 5,
np_array: [] as number[][],
prepared_array: [] as number[][]
}
},
actions: {
async getData() {
try {
const res = await fetch(`${SERVER_URL}/api/floorplan`)
const data = await res.json()
this.title = data.title
this.np_array = data.np_field
this.prepared_array = [...chunks(data.np_field, this.chunkSize)].map(line => {
const line_data = [] as any[][]
line.map((item: any) => [...chunks(item, this.chunkSize)]).map((item) => {
item.map((one_line, k) => {
if (!line_data[k]) line_data[k] = []
line_data[k].push(...one_line)
})
})
return line_data.map(el => {
return el.filter(e => e > 0).length > 10 ? 1 : 0
})
});
} catch (error) {
// this.list = []
}
},
}
})