From f9ee903d60a38c25da4666bc9bb92c2f31b8e6ed Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Wed, 18 Sep 2024 18:39:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0GraphiQL=E5=BD=A2=E5=BC=8F?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E8=AF=B7=E6=B1=82+iscs=E8=8D=89?= =?UTF-8?q?=E7=A8=BF=E5=9B=BE=E7=9A=84=E5=88=9B=E5=BB=BA=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/ApiCommon.ts | 42 +++++ src/api/DraftApi.ts | 138 +++++++++++++++ src/boot/@pixi/graphics-extras.ts | 7 + src/boot/axios.ts | 124 +++++++++++++ src/configs/UrlManage.ts | 55 ++++++ src/layouts/MainLayout.vue | 2 +- src/pages/IscsDraftManage.vue | 280 ++++++++++++++++++++++++++++++ src/router/routes.ts | 31 +++- 8 files changed, 676 insertions(+), 3 deletions(-) create mode 100644 src/api/ApiCommon.ts create mode 100644 src/api/DraftApi.ts create mode 100644 src/boot/@pixi/graphics-extras.ts create mode 100644 src/boot/axios.ts create mode 100644 src/configs/UrlManage.ts create mode 100644 src/pages/IscsDraftManage.vue diff --git a/src/api/ApiCommon.ts b/src/api/ApiCommon.ts new file mode 100644 index 0000000..a68a66a --- /dev/null +++ b/src/api/ApiCommon.ts @@ -0,0 +1,42 @@ +export class PageQueryDto { + current: number; + size: number; + orders?: OrderItemDto[]; + constructor(current: number, size: number, orders?: OrderItemDto[]) { + this.current = current; + this.size = size; + this.orders = orders; + } +} + +export class OrderItemDto { + column: string; + asc: boolean; + constructor(column: string, asc: boolean) { + this.column = column; + this.asc = asc; + } + + static asc(column: string): OrderItemDto { + return new OrderItemDto(column, true); + } + static desc(column: string): OrderItemDto { + return new OrderItemDto(column, false); + } +} + +export interface PageDto { + data: T[]; + /** + * 记录总数 + */ + total: number; + /** + * 第几页 + */ + current: number; + /** + * 每页数量 + */ + size: number; +} diff --git a/src/api/DraftApi.ts b/src/api/DraftApi.ts new file mode 100644 index 0000000..015826a --- /dev/null +++ b/src/api/DraftApi.ts @@ -0,0 +1,138 @@ +import { api } from 'src/boot/axios'; +import { PageDto } from './ApiCommon'; + +const DraftUriBase = ''; + +export enum DraftDataType { + UNKNOWN, + EM = 'EM', + IBP = 'IBP', + PSL = 'PSL', + ISCS = 'ISCS', +} + +export interface DraftItem { + id: number; + name: string; + dataType: DraftDataType; + data: []; + userId: number; + isShared: boolean; + createdAt: string; + updatedAt: string; +} + +interface PagingQueryParams { + paging: { + page: number; + itemsPerPage: number; + }; + query: { + userId: number; + dataType: DraftDataType; + name?: string; + isShared?: boolean; + }; +} +export async function draftPageQuery( + params: PagingQueryParams +): Promise> { + const query = ` + query userDraftDataPaging($paging: PageQueryDto, $query: UserDraftDataFilterDto) { + userDraftDataPaging(paging: $paging, query: $query) { + total + data { + id name dataType createdAt updatedAt isShared + } + } + } +`; + const response = await api.post(``, { + query, + variables: params, + }); + return response.data.data.userDraftDataPaging; +} + +/** + * 创建草稿 + * @param params + * @returns + */ +export function createDraft(name: string) { + const mutation = ` + mutation createDraftData($input: CreateDraftDataDto) { + createDraftData(input: $input) { + name + } + } +`; + const variables = { + input: { + name, + dataType: DraftDataType.ISCS, + data: [], + userId: 1, + }, + }; + return api.post(``, { + query: mutation, + variables, + }); +} + +/** + * 删除草稿 + * @param id 草稿id + */ +export function deleteDraft(id: number) { + const mutation = ` + mutation deleteDraftData($id: Int) { + deleteDraftData(id: $id) + } +`; + const variables = { + id, + }; + return api.post(``, { + query: mutation, + variables, + }); +} + +/** + * 获取草稿数据 + * @param params + * @returns + */ +export async function getDraft(id: number): Promise { + const response = await api.get(`${DraftUriBase}/${id}`); + return response.data; +} + +/** + * 保存草稿数据 + * @param data + * @returns + */ +export function saveDraft( + id: number, + data: { + proto: string; + } +) { + return api.put(`${DraftUriBase}/${id}`, data); +} + +/** + * 另存草稿数据 + * @param data + * @returns + */ +export async function saveAsDraft( + id: number, + data: { name: string; proto: string } +): Promise { + const response = await api.post(`${DraftUriBase}/${id}/saveAs`, data); + return response.data; +} diff --git a/src/boot/@pixi/graphics-extras.ts b/src/boot/@pixi/graphics-extras.ts new file mode 100644 index 0000000..4a70eb8 --- /dev/null +++ b/src/boot/@pixi/graphics-extras.ts @@ -0,0 +1,7 @@ +import { boot } from 'quasar/wrappers'; +import * as GraphicsExtras from '@pixi/graphics-extras'; +// "async" is optional; +// more info on params: https://v2.quasar.dev/quasar-cli/boot-files +export default boot(async (/* { app, router, ... } */) => { + GraphicsExtras; +}); diff --git a/src/boot/axios.ts b/src/boot/axios.ts new file mode 100644 index 0000000..30dc28d --- /dev/null +++ b/src/boot/axios.ts @@ -0,0 +1,124 @@ +import axios, { AxiosInstance } from 'axios'; +import { AxiosError } from 'axios'; +import { Dialog } from 'quasar'; +import { boot } from 'quasar/wrappers'; +//import { getJwtToken } from 'src/configs/TokenManage'; +import { getHttpBase } from 'src/configs/UrlManage'; + +declare module '@vue/runtime-core' { + interface ComponentCustomProperties { + $axios: AxiosInstance; + } +} + +interface ErrorData { + status: number; + title: string; + detail: string; + code: number; +} + +export class ApiError { + origin: AxiosError; + /** + * 业务错误代码 + */ + code: number; + /** + * 错误信息 + */ + title: string; + /** + * 相关问题描述 + */ + detail?: string; + constructor(origin: AxiosError) { + this.origin = origin; + const response = origin.response; + if (response) { + const err = response.data as ErrorData; + this.code = err.code; + this.title = err.title; + this.detail = err.detail; + } else { + this.code = origin.status || -1; + this.title = origin.message; + } + } + + static from(err: AxiosError): ApiError { + return new ApiError(err); + } + + /** + * 是否认证失败(登录过期) + * @returns + */ + isAuthError(): boolean { + return this.origin.response?.status === 401; + } +} + +// Be careful when using SSR for cross-request state pollution +// due to creating a Singleton instance here; +// If any client changes this (global) instance, it might be a +// good idea to move this instance creation inside of the +// "export default () => {}" function below (which runs individually +// for each client) +const api = axios.create({ baseURL: getHttpBase() }); +let isOpenDialog = false; // 认证弹窗是否打开 + +//const CancelToken = axios.CancelToken; +//const source = CancelToken.source(); +export default boot(({ app, router }) => { + // for use inside Vue files (Options API) through this.$axios and this.$api + + // 拦截请求,添加 + /* api.interceptors.request.use( + (config) => { + config.headers.Authorization = getJwtToken(); + config.cancelToken = source.token; + if (isOpenDialog) { + source.cancel(); + } + return config; + }, + (err: AxiosError) => { + return Promise.reject(ApiError.from(err)); + } + ); */ + + api.interceptors.response.use( + (response) => { + return response; + }, + (err) => { + if (err.response && err.response.status === 401 && !isOpenDialog) { + isOpenDialog = true; + Dialog.create({ + title: '认证失败', + message: '认证失败或登录超时,请重新登录', + persistent: true, + }) + .onOk(() => { + router.push({ name: 'login' }); + isOpenDialog = false; + }) + .onCancel(() => { + isOpenDialog = false; + }); + } + return Promise.reject(ApiError.from(err)); + } + ); + + app.config.globalProperties.$axios = axios; + // ^ ^ ^ this will allow you to use this.$axios (for Vue Options API form) + // so you won't necessarily have to import axios in each vue file + + app.config.globalProperties.$api = api; + // ^ ^ ^ this will allow you to use this.$api (for Vue Options API form) + // so you can easily perform requests against your app's API +}); + +export { api }; diff --git a/src/configs/UrlManage.ts b/src/configs/UrlManage.ts new file mode 100644 index 0000000..aa6ff7e --- /dev/null +++ b/src/configs/UrlManage.ts @@ -0,0 +1,55 @@ +function getHost(): string { + if (process.env.URL_ENV == 'test') { + return 'test.joylink.club/bjrtsts-server'; + } else if (process.env.URL_ENV == 'publish') { + return 'joylink.club/bjrtsts-server'; + } else if (process.env.URL_ENV == 'local_test') { + return '192.168.33.233:8765'; + } else if (process.env.URL_ENV == 'local_pxf') { + //北京现场 + + return '172.29.5.168/bjrtss-server'; + } + + // return '192.168.3.7:9091'; + // return '192.168.3.47:9091'; + // return '192.168.3.37:9091'; + //return '192.168.33.207:9091'; // 张骞 + // return '192.168.33.93:9091'; + // return '192.168.3.37:9091'; //卫志宏 + // return 'test.joylink.club/bjrtsts-service'; // 测试 + return '192.168.33.233:8765'; +} + +export function getHttpBase() { + let protocol = 'http'; + if (['publish'].includes(process.env.URL_ENV as string)) { + protocol = 'https'; + } + return `${protocol}://${getHost()}`; +} + +export function getWebsocketUrl() { + let protocol = 'ws'; + let host = '192.168.33.233'; + // let host = 'test.joylink.club'; + let port = '8083'; + let url = `${protocol}://${host}:${port}`; + if (process.env.URL_ENV == 'test') { + // protocol = 'wss'; + host = 'test.joylink.club/bjrtsts-server'; + port = ''; + url = `${protocol}://${host}`; + } else if (process.env.URL_ENV == 'publish') { + protocol = 'wss'; + host = 'joylink.club/bjrtsts-server'; + port = ''; + url = `${protocol}://${host}`; + } else if (process.env.URL_ENV == 'local_test') { + host = '192.168.33.233'; + } else if (process.env.URL_ENV == 'local_pxf') { + host = '172.29.5.168'; + } + + return `${url}/mqtt`; +} diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index 53e5ab3..e542d8c 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -12,7 +12,7 @@ @click="toggleLeftDrawer" /> - 北京玖琏 + 城市轨道交通平台
+
+ + + + + + + + + + +
新建草稿图
+ + + + + +
+
+
+
+ + + + + +
草稿发布
+ + + + + + + + +
+
+
+
+
+ + + diff --git a/src/router/routes.ts b/src/router/routes.ts index e922f29..30a346b 100644 --- a/src/router/routes.ts +++ b/src/router/routes.ts @@ -17,8 +17,35 @@ const routes: RouteRecordRaw[] = [ // children: [{ path: '', component: () => import('pages/IndexPage.vue') }], }, - // Always leave this as last one, - // but you can also remove it + { + path: '/dataManage', + name: 'dataManage', + component: () => import('layouts/MainLayout.vue'), + meta: { + label: '数据管理', + icon: 'list_alt', + }, + children: [ + { + path: 'iscsDraft', + name: 'iscsDraft', + component: () => import('pages/IscsDraftManage.vue'), + meta: { + label: 'iscs草稿管理', + icon: 'app_registration', + }, + }, + { + path: 'iscsPublish', + name: 'iscsPublish', + component: () => import('pages/PublishManage.vue'), + meta: { + label: 'iscs发布数据管理', + icon: 'playlist_add_check', + }, + }, + ], + }, { path: '/:catchAll(.*)*', meta: {