add new front
This commit is contained in:
parent
768bea9967
commit
6cdc2d7f9a
84
app/main.py
84
app/main.py
|
@ -11,11 +11,29 @@ from fastapi import FastAPI, Request
|
|||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.constants import *
|
||||
|
||||
app = FastAPI()
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
origins = [
|
||||
"http://localhost",
|
||||
"http://localhost:3000",
|
||||
"http://localhost:3001",
|
||||
# "http://192.168.100.242"
|
||||
]
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
locale.setlocale(locale.LC_TIME, "ru_RU")
|
||||
except Exception as e:
|
||||
|
@ -42,6 +60,7 @@ statuses = {
|
|||
"7": "Отклонена",
|
||||
}
|
||||
|
||||
|
||||
# Создаем кастомный фильтр для форматирования дат
|
||||
def format_status(value):
|
||||
value = str(value)
|
||||
|
@ -139,35 +158,9 @@ async def tg_intgr_get(request: Request):
|
|||
return {"status": "error"}
|
||||
|
||||
|
||||
@app.post("/deal_tab")
|
||||
async def deal_tab(
|
||||
request: Request,
|
||||
DOMAIN: str | None = None,
|
||||
PROTOCOL: str | None = None,
|
||||
LANG: str | None = None,
|
||||
APP_SID: str | None = None,
|
||||
):
|
||||
@app.post("/deal_tab/{deal_id}")
|
||||
async def deal_tab(request: Request, deal_id):
|
||||
try:
|
||||
body = await request.body()
|
||||
b_str = body.decode()
|
||||
result = parse_qs(b_str)
|
||||
q = [DOMAIN, PROTOCOL, LANG, APP_SID]
|
||||
|
||||
def extract_id(params):
|
||||
json_strings = params.get("PLACEMENT_OPTIONS", [])
|
||||
for json_str in json_strings:
|
||||
try:
|
||||
data = json.loads(json_str)
|
||||
if "ID" in data:
|
||||
return data["ID"]
|
||||
except json.JSONDecodeError:
|
||||
print(f"Ошибка: Некорректная JSON-строка - {json_str}")
|
||||
|
||||
deal_id = extract_id(result)
|
||||
if not deal_id:
|
||||
raise('not deal id')
|
||||
deal_id = 49
|
||||
|
||||
select = [
|
||||
"ID",
|
||||
"TITLE",
|
||||
|
@ -182,8 +175,8 @@ async def deal_tab(
|
|||
task_data_json = task_data.json()
|
||||
result = task_data_json["result"]["tasks"]
|
||||
|
||||
while len(task_data_json["result"]["tasks"]) == 50 and len(result) < 50*4:
|
||||
limit = (len(result)//50) * 50
|
||||
while len(task_data_json["result"]["tasks"]) == 50 and len(result) < 50 * 4:
|
||||
limit = (len(result) // 50) * 50
|
||||
task_data = requests.get(get_task_hook + f"&start={limit}")
|
||||
task_data_json = task_data.json()
|
||||
result += task_data_json["result"]["tasks"]
|
||||
|
@ -191,21 +184,18 @@ async def deal_tab(
|
|||
# logger.info(task_data_json["result"]["tasks"])
|
||||
parts = WEBHOOK.split("/")
|
||||
domain = f"https://{parts[2]}"
|
||||
return templates.TemplateResponse(
|
||||
request=request,
|
||||
name="deal_tab.html",
|
||||
context={"tasks": result, "domain": domain},
|
||||
)
|
||||
|
||||
return {"status": "success", "result": task_data_json}
|
||||
return {"status": "success", "result": result, "format": {"domain": domain, "statuses": statuses}}
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
return {"status": "error"}
|
||||
|
||||
|
||||
# app.mount("/widget", StaticFiles(directory="front/dist", html=True), name="static")
|
||||
|
||||
NUXT_DIST = Path("front/dist")
|
||||
|
||||
|
||||
@app.post("/widget")
|
||||
async def handle_widget_post(request: Request):
|
||||
# Обработка данных POST-запроса
|
||||
|
@ -215,11 +205,25 @@ async def handle_widget_post(request: Request):
|
|||
body = await request.body()
|
||||
b_str = body.decode()
|
||||
result = parse_qs(b_str)
|
||||
|
||||
|
||||
def extract_id(params):
|
||||
json_strings = params.get("PLACEMENT_OPTIONS", [])
|
||||
for json_str in json_strings:
|
||||
try:
|
||||
data = json.loads(json_str)
|
||||
if "ID" in data:
|
||||
return data["ID"]
|
||||
except json.JSONDecodeError:
|
||||
print(f"Ошибка: Некорректная JSON-строка - {json_str}")
|
||||
|
||||
deal_id = extract_id(result)
|
||||
if not deal_id:
|
||||
raise ("not deal id")
|
||||
deal_id = 49
|
||||
logger.info(result)
|
||||
|
||||
html_file = NUXT_DIST / "index.html"
|
||||
|
||||
html_file = NUXT_DIST / f"deal/index.html?deal_id={deal_id}"
|
||||
if html_file.exists():
|
||||
html_content = html_file.read_text()
|
||||
return HTMLResponse(content=html_content, status_code=200)
|
||||
return {"error": "Nuxt.js page not found"}, 404
|
||||
return {"error": "Nuxt.js page not found"}, 404
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
<template>
|
||||
<div>
|
||||
<NuxtRouteAnnouncer />
|
||||
<NuxtWelcome />
|
||||
</div>
|
||||
<NuxtPage/>
|
||||
</template>
|
||||
|
|
|
@ -2,9 +2,17 @@
|
|||
export default defineNuxtConfig({
|
||||
compatibilityDate: '2024-04-03',
|
||||
devtools: { enabled: true },
|
||||
|
||||
app: {
|
||||
baseURL: '/widget/', // Базовый путь
|
||||
// buildAssetsDir: '/widget/_nuxt/', // Путь для статических файлов
|
||||
},
|
||||
|
||||
})
|
||||
runtimeConfig: {
|
||||
public: {
|
||||
apiBase: process.env.NODE_ENV == 'development' ? 'http://localhost:8000' : ''
|
||||
}
|
||||
},
|
||||
|
||||
modules: ['@nuxt/ui'],
|
||||
})
|
File diff suppressed because it is too large
Load Diff
|
@ -10,6 +10,7 @@
|
|||
"postinstall": "nuxt prepare"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nuxt/ui": "^2.19.2",
|
||||
"nuxt": "^3.14.1592",
|
||||
"vue": "latest",
|
||||
"vue-router": "latest"
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
<script setup lang="ts">
|
||||
const route = useRoute()
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
const data = ref()
|
||||
const formatter = ref()
|
||||
|
||||
export interface Data {
|
||||
status: string;
|
||||
result: Result[];
|
||||
format: {
|
||||
domain: string;
|
||||
statuses: { [key: string]: string };
|
||||
}
|
||||
}
|
||||
|
||||
export interface Result {
|
||||
id: string;
|
||||
title: string;
|
||||
responsibleId: string;
|
||||
createdDate: Date;
|
||||
deadline: Date;
|
||||
status: string;
|
||||
groupId: string;
|
||||
group: any[] | GroupClass;
|
||||
responsible: string;
|
||||
subStatus: string;
|
||||
}
|
||||
|
||||
export interface GroupClass {
|
||||
id: string;
|
||||
name: string;
|
||||
opened: boolean;
|
||||
membersCount: number;
|
||||
image: string;
|
||||
additionalData: any[];
|
||||
}
|
||||
|
||||
const loadData = async (deal_id: number) => {
|
||||
const res = await $fetch<Data>(`${config.public.apiBase}/deal_tab/${deal_id}`, { method: 'POST' })
|
||||
if (res.status == 'success') {
|
||||
data.value = res.result
|
||||
formatter.value = res.format
|
||||
}
|
||||
}
|
||||
|
||||
const columns = [{
|
||||
key: 'id',
|
||||
label: 'ID'
|
||||
}, {
|
||||
key: 'title',
|
||||
label: 'Название'
|
||||
}, {
|
||||
key: 'status',
|
||||
label: 'Статус'
|
||||
}, {
|
||||
key: 'responsible',
|
||||
label: 'Исполнитель'
|
||||
}, {
|
||||
key: 'createdDate',
|
||||
label: 'Создана'
|
||||
}, {
|
||||
key: 'deadline',
|
||||
label: 'Крайний срок',
|
||||
}]
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
const deal_id = route.query.deal_id
|
||||
if (!deal_id) return
|
||||
|
||||
loadData(parseInt(deal_id as string))
|
||||
})
|
||||
</script>
|
||||
<template>
|
||||
<UTable :rows="data" :columns="columns">
|
||||
<template #responsible-data="{ row }">
|
||||
{{ row.responsible.name }}
|
||||
</template>
|
||||
<template #deadline-data="{ row }">
|
||||
{{ new Date(Date.parse(row.deadline)).toLocaleDateString('ru-RU', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
}) }}
|
||||
</template>
|
||||
<template #createdDate-data="{ row }">
|
||||
{{ new Date(Date.parse(row.createdDate)).toLocaleDateString('ru-RU', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
}) }}
|
||||
</template>
|
||||
<template #status-data="{ row }">
|
||||
{{ formatter.statuses[row.status] }}
|
||||
</template>
|
||||
<template #title-data="{ row }">
|
||||
<a :href="`${formatter.domain}/workgroups/group/${row.groupId}/tasks/task/view/${row.id}/`" target="_blank" class="text-primary-600 underline hover:no-underline">
|
||||
{{ row.title }}
|
||||
</a>
|
||||
</template>
|
||||
</UTable>
|
||||
</template>
|
Loading…
Reference in New Issue