线路信息调整

This commit is contained in:
dong 2023-06-09 16:36:49 +08:00
parent 2c4f6b4a77
commit 89bbac94d7
3 changed files with 92 additions and 35 deletions

View File

@ -3,11 +3,14 @@ import { PageDto, PageQueryDto } from './ApiCommon';
const UriBase = '/api/lineInfo';
interface Item {
id: number;
export interface createParams {
name: string;
lineId: number;
config: string;
config?: string;
}
interface Item extends createParams {
id: number;
createdAt: string;
updateAt: string;
}
@ -35,11 +38,7 @@ export async function pageQuery(
* @param params
* @returns
*/
export function createLine(data: {
name: string;
lineId: number;
config?: string;
}) {
export function createLine(data: createParams) {
return api.post(`${UriBase}`, data);
}
@ -55,7 +54,7 @@ export function deleteLine(id: number) {
* 线
* @param id 稿id
*/
export function saveLineData(id: number, data: Item) {
export function saveLineData(id: number, data: createParams) {
return api.put(`${UriBase}/${id}`, data);
}

View File

@ -138,6 +138,7 @@ import { useQuasar, type QTableColumn, QForm } from 'quasar';
import { pageQuery, createDraft, deleteDraft } from '../api/DraftApi';
import { publishDraft } from '../api/PublishApi';
import { getLineList } from '../api/LineInfoApi';
import { ApiError } from 'src/boot/axios';
const $q = useQuasar();
@ -254,10 +255,11 @@ async function onRequest(props: any) {
pagination.value.sortBy = sortBy;
pagination.value.descending = descending;
rows.splice(0, rows.length, ...(pageData.records as []));
} catch (error: any) {
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.message,
message: error.title,
});
} finally {
loading.value = false;
@ -278,10 +280,11 @@ function onCreate() {
});
createFormShow.value = false;
tableRef.value.requestServerInteraction(); //
} catch (error: any) {
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.message,
message: error.title,
});
} finally {
operateDisabled.value = false;
@ -319,10 +322,11 @@ async function publishGraphics() {
type: 'positive',
message: '发布成功',
});
} catch (error: any) {
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.message,
message: error.title,
});
}
}
@ -340,10 +344,11 @@ async function deleteData(row: any) {
try {
await deleteDraft(row.id);
tableRef.value.requestServerInteraction(); //
} catch (error: any) {
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.message,
message: error.title,
});
}
})

View File

@ -28,6 +28,12 @@
<template v-slot:body-cell-operations="props">
<q-td :props="props">
<div class="q-gutter-sm row justify-center">
<q-btn
color="primary"
:disable="operateDisabled"
label="编辑"
@click="editData(props.row)"
/>
<q-btn
color="red"
:disable="operateDisabled"
@ -46,29 +52,37 @@
transition-hide="scale"
>
<q-card style="width: 300px">
<q-form ref="myForm" @submit="onCreate" class="q-gutter-md">
<q-form
ref="myForm"
@submit="onCreate"
@reset="onReset"
class="q-gutter-md"
>
<q-card-section>
<div class="text-h6">新建线路信息</div>
<div class="text-h6">
{{ editInfo.id ? '编辑线路信息' : '新建线路信息' }}
</div>
<q-input
outlined
label="名称"
v-model="LineName"
v-model="editInfo.lineName"
lazy-rules
:rules="[(val) => val.length > 0 || '请输入名称!']"
/>
<q-input
outlined
label="线路ID"
v-model.number="LineId"
v-model.number="editInfo.lineId"
type="number"
lazy-rules
:rules="[(val) => val || '请输入线路ID']"
/>
<q-input outlined label="配置" v-model="editInfo.config" />
</q-card-section>
<q-card-actions align="right">
<q-btn color="primary" label="创建" type="submit" />
<q-btn label="取消" v-close-popup />
<q-btn label="取消" type="reset" v-close-popup />
</q-card-actions>
</q-form>
</q-card>
@ -79,7 +93,14 @@
<script setup lang="ts">
import { ref, reactive, onMounted, computed } from 'vue';
import { useQuasar, type QTableColumn, QForm } from 'quasar';
import { pageQuery, createLine, deleteLine } from '../api/LineInfoApi';
import {
pageQuery,
createLine,
deleteLine,
saveLineData,
createParams,
} from '../api/LineInfoApi';
import { ApiError } from 'src/boot/axios';
const $q = useQuasar();
@ -155,10 +176,11 @@ async function onRequest(props: any) {
pagination.value.sortBy = sortBy;
pagination.value.descending = descending;
rows.splice(0, rows.length, ...(pageData.records as []));
} catch (error: any) {
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.message,
message: error.title,
});
} finally {
loading.value = false;
@ -166,24 +188,32 @@ async function onRequest(props: any) {
}
const createFormShow = ref(false);
const LineName = ref('');
const LineId = ref(1);
const myForm = ref<QForm | null>(null);
function onCreate() {
myForm.value?.validate().then(async (res) => {
if (res) {
operateDisabled.value = true;
try {
await createLine({
name: LineName.value,
lineId: LineId.value,
});
const params: createParams = {
name: editInfo.lineName,
lineId: editInfo.lineId,
};
if (editInfo.config) {
params.config = JSON.stringify(editInfo.config);
}
if (editInfo.id) {
await saveLineData(+editInfo.id, params);
} else {
await createLine(params);
}
onReset();
createFormShow.value = false;
tableRef.value.requestServerInteraction(); //
} catch (error: any) {
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.message,
message: error.title,
});
} finally {
operateDisabled.value = false;
@ -192,6 +222,14 @@ function onCreate() {
});
}
function onReset() {
editInfo.id = '';
editInfo.lineName = '';
editInfo.lineId = 1;
editInfo.config = '';
myForm.value?.resetValidation();
}
async function deleteData(row: any) {
operateDisabled.value = true;
$q.dialog({
@ -203,10 +241,11 @@ async function deleteData(row: any) {
try {
await deleteLine(row.id);
tableRef.value.requestServerInteraction(); //
} catch (error: any) {
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.message,
message: error.title,
});
}
})
@ -214,4 +253,18 @@ async function deleteData(row: any) {
operateDisabled.value = false;
});
}
const editInfo = reactive({
id: '',
lineName: '',
lineId: 1,
config: '',
});
function editData(row: any) {
editInfo.id = row.id;
editInfo.lineName = row.name;
editInfo.lineId = row.lineId;
editInfo.config = row.config || '';
createFormShow.value = true;
}
</script>