发布备用

This commit is contained in:
joylink_zhaoerwei 2024-09-20 18:08:18 +08:00
parent 09d48e3e7a
commit 469222e46f
7 changed files with 1024 additions and 32 deletions

View File

@ -1,8 +1,6 @@
import { api } from 'src/boot/axios'; import { api } from 'src/boot/axios';
import { PageDto } from './ApiCommon'; import { PageDto } from './ApiCommon';
const DraftUriBase = '';
export enum DraftDataType { export enum DraftDataType {
UNKNOWN, UNKNOWN,
EM = 'EM', EM = 'EM',
@ -18,9 +16,11 @@ export interface DraftItem {
options: string; options: string;
data: string; data: string;
userId: number; userId: number;
defaultReleaseDataId: number;
isShared: boolean; isShared: boolean;
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;
defaultReleaseDataName: string;
} }
interface PagingQueryParams { interface PagingQueryParams {
@ -51,7 +51,7 @@ export async function draftPageQuery(
userDraftIscsDataPaging(paging: $paging, query: $query) { userDraftIscsDataPaging(paging: $paging, query: $query) {
total total
items { items {
draftData {id name dataType createdAt updatedAt isShared } draftData {id name dataType userId defaultReleaseDataId createdAt updatedAt isShared defaultReleaseDataName}
options {style} options {style}
} }
} }
@ -161,7 +161,7 @@ export async function getDraft(id: number): Promise<DraftItem> {
* @param data * @param data
* @returns * @returns
*/ */
export function saveDraft(data: { id: number; data: string }) { export function saveDraft(variables: { id: number; data: string }) {
const mutation = ` const mutation = `
mutation updateDraftDataData($id: Int,$data: String) { mutation updateDraftDataData($id: Int,$data: String) {
updateDraftDataData(id: $id,data: $data){ updateDraftDataData(id: $id,data: $data){
@ -169,26 +169,48 @@ export function saveDraft(data: { id: number; data: string }) {
} }
} }
`; `;
const variables = {
id: 1,
data: data.data,
};
console.log(data);
return api.post('', { return api.post('', {
query: mutation, query: mutation,
variables: variables, variables,
}); });
} }
/** /**
* 稿 * 稿
* @param data * @param variables
* @returns * @returns
*/ */
export async function saveAsDraft( export async function saveAsDraft(variables: {
id: number, id: number;
data: { name: string; proto: string } name: string;
): Promise<DraftItem> { userId: number;
const response = await api.post(`${DraftUriBase}/${id}/saveAs`, data); }): Promise<DraftItem> {
return response.data; const mutation = `
mutation saveAsNewDraftData($id: Int,$name: String,$userId: Int) {
saveAsNewDraftData(id: $id,name: $name,userId: $userId){
id
}
}
`;
return api.post('', {
query: mutation,
variables,
});
}
/**
* 稿
* @param id id
* @param name
*/
export function setDraftRename(variables: { id: number; name: string }) {
const mutation = `
mutation updateDraftDataName($id: Int,$name: String) {
updateDraftDataName(id: $id,name: $name){id}
}
`;
return api.post('', {
query: mutation,
variables,
});
} }

251
src/api/PublishApi.ts Normal file
View File

@ -0,0 +1,251 @@
import { api } from 'src/boot/axios';
import { PageDto } from './ApiCommon';
import { DraftDataType, IscsDataOptions } from './DraftApi';
const PublishUriBase = '/api/v1/publishedGi';
export interface PublishItem {
id: number;
name: string;
dataType: DraftDataType;
options: string;
data: string;
usedVersionId: number;
userId: number;
isPublished: boolean;
createdAt: string;
updatedAt: string;
description: string;
}
interface PagingQueryParams {
page: {
page: number;
itemsPerPage: number;
};
query: {
userId: number;
dataType: DraftDataType;
name?: string;
isPublished?: boolean;
};
}
export interface PublishIscsDataDto {
releaseData: PublishItem;
options: IscsDataOptions;
}
/**
* 稿
* @param draftId 稿id
* @param note
*/
export function publishDraft(params: {
draftId: number;
name: string;
description: string;
}) {
const mutation = `
mutation releaseNewFromDraft($draftId: Int,$name: String,$description: String) {
releaseNewFromDraft(draftId: $draftId,name: $name,description: $description) {
releaseData {id}
}
}
`;
return api.post('', {
query: mutation,
variables: params,
});
}
/**
* 稿
* @param draftId 稿id
* @param description
*/
export function publishDraftToDefault(params: {
draftId: number;
description: string;
}) {
const mutation = `
mutation releaseToDefaultReleaseData($draftId: Int,$description: String) {
releaseToDefaultReleaseData(draftId: $draftId,description: $description) {
releaseData {id}
}
}
`;
return api.post('', {
query: mutation,
variables: params,
});
}
/**
*
* @param params
* @returns
*/
export async function publishPageQuery(
params: PagingQueryParams
): Promise<PageDto<PublishIscsDataDto>> {
const query = `
query releaseIscsDataPaging($page: PageQueryDto, $query: UserDraftIscsDataFilterDto) {
releaseIscsDataPaging(page: $page, query: $query) {
total
items {
releaseData {id name dataType usedVersionId userId isPublished createdAt updatedAt description }
options {style}
}
}
}
`;
const response = await api.post('', {
query,
variables: params,
});
return response.data.data.releaseIscsDataPaging;
}
/**
*
* @param id id
*/
export function deletePublish(id: number) {
return api.delete(`${PublishUriBase}/${id}`);
}
/**
*
* @param id id
*/
export async function getPublishMapInfoById(id: number): Promise<PublishItem> {
const response = await api.get(`${PublishUriBase}/${id}`);
return response.data;
}
/**
*
* @param name
*/
export async function getPublishMapInfoByName(params: {
name: string;
detail: boolean;
}): Promise<PublishItem> {
const response = await api.get(`${PublishUriBase}/name`, {
params: params,
});
return response.data;
}
/**
* 线
*/
export async function getPublishLineNet(): Promise<PublishItem> {
const response = await api.get(`${PublishUriBase}/publish/lineNetwork/info`);
return response.data;
}
/**
*
* @param id 线ID
*/
export async function getPublishMapInfoByLineId(
lineId: string
): Promise<PublishItem> {
const response = await api.get(`${PublishUriBase}/${lineId}`);
return response.data;
}
/**
* 稿
* @param id id
*/
export function saveToDraft(variables: { versionId: number; userId: number }) {
const mutation = `
mutation createDraftDataFromReleaseDataVersion($versionId: Int,$userId: Int) {
createDraftDataFromReleaseDataVersion(versionId: $versionId,userId: $userId){name}
}
`;
return api.post('', {
query: mutation,
variables,
});
}
export interface PublishHistoryItem {
id: number;
releaseDataId: number;
options: string;
description: string;
data: string;
userId: number;
createdAt: string;
}
/**
*
* @param id ID
*/
export async function getPublishHistoryById(variables: {
dataId: number;
page: { page: number; itemsPerPage: number };
}): Promise<PageDto<{ total: number; items: PublishHistoryItem[] }>> {
const query = `
query releaseDataVersionPaging($dataId: Int, $page: PageQueryDto) {
releaseDataVersionPaging(dataId: $dataId, page: $page) {
total
items {
id releaseDataId description userId createdAt
}
}
}
`;
const response = await api.post('', {
query,
variables,
});
return response.data.data.releaseDataVersionPaging;
}
/**
* 退
* @param id ID
*/
export function fallbackVersion(data: { mapId: number; versionId: number }) {
return api.post(`${PublishUriBase}/fallbackVersion`, data);
}
/**
*
* @param id id
* @param release
*/
export function setPublishRelease(variables: {
id: number;
isPublished: boolean;
}) {
const mutation = `
mutation updateReleaseDataPublished($id: Int,$isPublished: Boolean) {
updateReleaseDataPublished(id: $id,isPublished: $isPublished){id}
}
`;
return api.post('', {
query: mutation,
variables,
});
}
/**
*
* @param id id
* @param name
*/
export function setPublishRename(variables: { id: number; name: string }) {
const mutation = `
mutation updateReleaseDataName($id: Int,$name: String) {
updateReleaseDataName(id: $id,name: $name){id}
}
`;
return api.post('', {
query: mutation,
variables,
});
}

View File

@ -134,7 +134,6 @@
import DrawProperties from 'src/components/draw-app/IscsDrawProperties.vue'; import DrawProperties from 'src/components/draw-app/IscsDrawProperties.vue';
import { onMounted, reactive, ref, watch } from 'vue'; import { onMounted, reactive, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { successNotify } from 'src/utils/CommonNotify';
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
import { useDrawStore } from 'src/stores/draw-store'; import { useDrawStore } from 'src/stores/draw-store';
import { CCTVButton } from 'src/graphics/CCTV/cctvButton/CCTVButton'; import { CCTVButton } from 'src/graphics/CCTV/cctvButton/CCTVButton';
@ -142,8 +141,11 @@ import { Arrow } from 'src/graphics/arrow/Arrow';
import { TextContent } from 'src/graphics/textContent/TextContent'; import { TextContent } from 'src/graphics/textContent/TextContent';
import { Rect } from 'src/graphics/rect/Rect'; import { Rect } from 'src/graphics/rect/Rect';
import { getIscsStyleConfig } from 'src/configs/iscsStyleConfig'; import { getIscsStyleConfig } from 'src/configs/iscsStyleConfig';
import { IscsStyle } from 'src/api/DraftApi'; import { IscsStyle, saveAsDraft } from 'src/api/DraftApi';
import DraggableDialog from 'src/components/common/DraggableDialog.vue'; import DraggableDialog from 'src/components/common/DraggableDialog.vue';
import { ApiError } from 'src/boot/axios';
import { useAuthStore } from 'src/stores/auth-store';
import { successNotify } from 'src/utils/CommonNotify';
const $q = useQuasar(); const $q = useQuasar();
const route = useRoute(); const route = useRoute();
@ -151,6 +153,7 @@ const router = useRouter();
const searchId = ref(0); const searchId = ref(0);
const drawStore = useDrawStore(); const drawStore = useDrawStore();
const authStore = useAuthStore();
const showDrawTool = ref(true); const showDrawTool = ref(true);
watch( watch(
() => drawStore.drawMode, () => drawStore.drawMode,
@ -290,7 +293,21 @@ const saveAsDialog = ref(false);
const saveAsName = ref(''); const saveAsName = ref('');
async function saveAs(name: string) { async function saveAs(name: string) {
successNotify('另存为成功' + name); try {
await saveAsDraft({
id: +route.params.id as number,
name,
userId: authStore.userId,
});
successNotify('另存为草稿成功');
saveAsDialog.value = false;
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.title,
});
}
} }
function onTopMenuClick() { function onTopMenuClick() {

View File

@ -24,6 +24,38 @@
<q-btn flat round color="primary" icon="search" /> <q-btn flat round color="primary" icon="search" />
<q-btn color="primary" label="新建" @click="createFormShow = true" /> <q-btn color="primary" label="新建" @click="createFormShow = true" />
</template> </template>
<template v-slot:header-cell-name="props">
<q-th :props="props">
{{ props.col.label }}
<q-icon name="edit" />
</q-th>
</template>
<template v-slot:body-cell-name="props">
<q-td :props="props" class="cursor-pointer">
{{ props.row.name }}
<q-popup-edit
title="编辑名称"
v-model="props.row.name"
buttons
:cover="false"
:validate="caloriesRangeValidation"
@hide="caloriesRangeValidation"
@update:model-value="saveRowDataName(props.row)"
v-slot="scope"
>
<q-input
v-model="scope.value"
hint="请输入名称!"
:error="errorCalories"
:error-message="errorMessageCalories"
dense
autofocus
@keyup.enter="scope.set"
/>
</q-popup-edit>
</q-td>
</template>
<template v-slot:body-cell-operations="props"> <template v-slot:body-cell-operations="props">
<q-td :props="props"> <q-td :props="props">
@ -34,12 +66,21 @@
label="编辑" label="编辑"
@click="goToPath(props.row)" @click="goToPath(props.row)"
/> />
<q-btn <q-btn-dropdown color="primary" label="发布">
color="primary" <q-list>
:disable="operateDisabled" <q-item
label="发布" v-for="item in publishMenuConfig"
@click="prePublish(props.row)" :key="item.label"
/> clickable
v-close-popup
@click="item.click(props.row)"
>
<q-item-section>
<q-item-label>{{ item.label }}</q-item-label>
</q-item-section>
</q-item>
</q-list>
</q-btn-dropdown>
<q-btn <q-btn
color="info" color="info"
style="width: 80px" style="width: 80px"
@ -110,6 +151,7 @@
/> />
<q-input <q-input
outlined outlined
:disable="publishNameDisable"
label="发布名称 * " label="发布名称 * "
v-model="publishForm.pubName" v-model="publishForm.pubName"
lazy-rules lazy-rules
@ -146,9 +188,12 @@ import {
DraftIscsDataDto, DraftIscsDataDto,
IscsStyle, IscsStyle,
sharedDraft, sharedDraft,
setDraftRename,
} from '../api/DraftApi'; } from '../api/DraftApi';
import { ApiError } from 'src/boot/axios'; import { ApiError } from 'src/boot/axios';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { publishDraft, publishDraftToDefault } from 'src/api/PublishApi';
import { useAuthStore } from 'src/stores/auth-store';
const $q = useQuasar(); const $q = useQuasar();
const router = useRouter(); const router = useRouter();
@ -158,11 +203,18 @@ const props = withDefaults(
}>(), }>(),
{ sizeHeight: 500 } { sizeHeight: 500 }
); );
const authStore = useAuthStore();
const tableHeight = computed(() => { const tableHeight = computed(() => {
return props.sizeHeight - 32; return props.sizeHeight - 32;
}); });
const publishMenuConfig = [
{ label: '新发布', click: prePublish },
{ label: '发布到默认', click: publishToDefault },
{ label: '设置默认发布', click: setDefaultPublish },
];
onMounted(() => { onMounted(() => {
tableRef.value.requestServerInteraction(); tableRef.value.requestServerInteraction();
}); });
@ -175,6 +227,12 @@ const columnDefs: QTableColumn[] = [
required: true, required: true,
align: 'center', align: 'center',
}, },
{
name: 'userId',
label: '创建人',
field: 'userId',
align: 'center',
},
{ {
name: 'createdAt', name: 'createdAt',
label: '创建时间', label: '创建时间',
@ -195,6 +253,12 @@ const columnDefs: QTableColumn[] = [
}, },
align: 'center', align: 'center',
}, },
{
name: 'defaultReleaseDataName',
label: '默认发布',
field: 'defaultReleaseDataName',
align: 'center',
},
{ name: 'operations', label: '操作', field: 'operations', align: 'center' }, { name: 'operations', label: '操作', field: 'operations', align: 'center' },
]; ];
@ -225,7 +289,11 @@ async function onRequest(props: any) {
page: page, page: page,
itemsPerPage: rowsPerPage, itemsPerPage: rowsPerPage,
}, },
query: { userId: 1, dataType: DraftDataType.ISCS, name: filter.name }, query: {
userId: authStore.userId,
dataType: DraftDataType.ISCS,
name: filter.name,
},
}; };
try { try {
const response = await draftPageQuery(variables); const response = await draftPageQuery(variables);
@ -270,7 +338,7 @@ function onCreate() {
input: { input: {
name: createForm.draftName, name: createForm.draftName,
options: { style: createForm.style }, options: { style: createForm.style },
userId: 1, userId: authStore.userId,
}, },
}; };
await createDraft(variables); await createDraft(variables);
@ -290,6 +358,7 @@ function onCreate() {
} }
}); });
} }
const pubForm = ref<QForm | null>(null); const pubForm = ref<QForm | null>(null);
const publishFormShow = ref(false); const publishFormShow = ref(false);
const publishForm = reactive({ const publishForm = reactive({
@ -302,10 +371,77 @@ function prePublish(row: DraftItem) {
publishFormShow.value = true; publishFormShow.value = true;
publishForm.id = row.id + ''; publishForm.id = row.id + '';
publishForm.draftName = row.name; publishForm.draftName = row.name;
publishForm.pubName = row.name; publishForm.pubName = row.defaultReleaseDataName || row.name;
publishForm.note = ''; publishForm.note = '';
} }
const publishNameDisable = ref(false);
function publishToDefault(row: DraftItem) {
if (!row.defaultReleaseDataId) {
$q.notify({
type: 'negative',
message: '未设置默认发布,请新发布或设置默认发布',
});
} else {
publishNameDisable.value = true;
prePublish(row);
}
}
function setDefaultPublish(row: DraftItem) {
console.log(row);
}
function publishGraphics() {
pubForm.value?.validate().then((res) => {
if (res) {
if (!publishNameDisable.value) {
const params: { draftId: number; name: string; description: string } = {
draftId: +publishForm.id,
name: publishForm.pubName,
description: publishForm.note,
};
publishDraft(params)
.then(() => {
publishNameDisable.value = false;
publishFormShow.value = false;
$q.notify({
type: 'positive',
message: '发布成功',
});
})
.catch((err) => {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.title,
});
});
} else {
const params: { draftId: number; description: string } = {
draftId: +publishForm.id,
description: publishForm.note,
};
publishDraftToDefault(params)
.then(() => {
publishNameDisable.value = false;
publishFormShow.value = false;
$q.notify({
type: 'positive',
message: '发布成功',
});
})
.catch((err) => {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.title,
});
});
}
}
});
}
async function deleteData(row: DraftItem) { async function deleteData(row: DraftItem) {
operateDisabled.value = true; operateDisabled.value = true;
$q.dialog({ $q.dialog({
@ -316,7 +452,7 @@ async function deleteData(row: DraftItem) {
.onOk(async () => { .onOk(async () => {
try { try {
await deleteDraft(row.id); await deleteDraft(row.id);
tableRef.value.requestServerInteraction(); // tableRef.value.requestServerInteraction();
} catch (err) { } catch (err) {
const error = err as ApiError; const error = err as ApiError;
$q.notify({ $q.notify({
@ -335,7 +471,7 @@ async function sharedDraftData(row: DraftItem) {
try { try {
await sharedDraft(row.id, !row.isShared); await sharedDraft(row.id, !row.isShared);
operateDisabled.value = false; operateDisabled.value = false;
tableRef.value.requestServerInteraction(); // tableRef.value.requestServerInteraction();
} catch (err) { } catch (err) {
const error = err as ApiError; const error = err as ApiError;
$q.notify({ $q.notify({
@ -345,6 +481,38 @@ async function sharedDraftData(row: DraftItem) {
} }
} }
const errorCalories = ref(false);
const errorMessageCalories = ref('');
function caloriesRangeValidation(val?: string) {
if (val !== undefined) {
if (val.length == 0) {
errorCalories.value = true;
errorMessageCalories.value = '不能为空!';
return false;
}
}
errorCalories.value = false;
errorMessageCalories.value = '';
return true;
}
async function saveRowDataName(row: DraftItem) {
try {
const params = {
id: row.id,
name: row.name,
};
await setDraftRename(params);
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.title,
});
tableRef.value.requestServerInteraction();
}
}
function goToPath(row: DraftItem) { function goToPath(row: DraftItem) {
let path = `/iscsPainting/${row.id}`; let path = `/iscsPainting/${row.id}`;
const iscsStyle = allRequestData.find((item) => item.draftData.id == row.id) const iscsStyle = allRequestData.find((item) => item.draftData.id == row.id)

View File

@ -0,0 +1,522 @@
<template>
<div class="q-pa-md">
<q-table
ref="tableRef"
title="发布数据管理"
:style="{ height: tableHeight + 'px' }"
:rows="rows"
:columns="columnDefs"
row-key="id"
v-model:pagination="pagination"
:rows-per-page-options="[10, 20, 50, 100]"
:loading="loading"
:filter="filter"
:selection="isProject ? 'multiple' : 'none'"
v-model:selected="selected"
:selected-rows-label="getSelectedString"
binary-state-sort
@request="onRequest"
>
<template v-slot:top-right>
<q-input
dense
debounce="1000"
v-model="filter.name"
label="名称"
></q-input>
<q-btn flat round color="primary" icon="search" />
</template>
<template v-slot:header-cell-name="props">
<q-th :props="props">
{{ props.col.label }}
<q-icon name="edit" />
</q-th>
</template>
<template v-slot:body-cell-name="props">
<q-td :props="props" class="cursor-pointer">
{{ props.row.name }}
<q-popup-edit
title="编辑名称"
v-model="props.row.name"
buttons
:cover="false"
:validate="caloriesRangeValidation"
@hide="caloriesRangeValidation"
@update:model-value="saveRowDataName(props.row)"
v-slot="scope"
>
<q-input
v-model="scope.value"
hint="请输入名称!"
:error="errorCalories"
:error-message="errorMessageCalories"
dense
autofocus
@keyup.enter="scope.set"
/>
</q-popup-edit>
</q-td>
</template>
<template v-slot:body-cell-operations="props" v-if="!isProject">
<q-td :props="props" style="width: 400px">
<div class="q-gutter-sm row justify-start">
<q-btn
:color="!props.row.isPublished ? 'primary' : 'amber'"
:label="!props.row.isPublished ? '上架' : '下架'"
@click="dataReleaseFn(props.row)"
/>
<q-btn
color="primary"
label="另存到草稿"
@click="saveToDraftFn(props.row)"
/>
<q-btn
color="primary"
label="发布历史"
@click="showHistoryFn(props.row)"
/>
<q-btn
color="red"
:disable="operateDisabled"
label="删除"
@click="deleteData(props.row)"
/>
</div>
</q-td>
</template>
</q-table>
<q-dialog
v-model="historyInfoShow"
persistent
transition-show="scale"
transition-hide="scale"
>
<q-card style="width: 1400px; max-width: 80vw">
<q-card-section class="row items-center q-pb-none">
<div class="text-h6">{{ historyInfo.name }}发布历史</div>
<q-space />
<q-btn icon="close" flat round dense v-close-popup />
</q-card-section>
<q-card-section>
<q-table
ref="historyTableRef"
:rows="historyRows"
:style="{ height: tableHeight * 0.6 + 'px' }"
:columns="historyColumnDefs"
v-model:pagination="historyPagination"
:rows-per-page-options="[10, 20, 50, 100]"
:loading="historyLoading"
@request="historyOnRequest"
>
<template v-slot:body-cell-operations="props" v-if="!isProject">
<q-td :props="props" style="width: 150px">
<div class="q-gutter-sm row justify-center">
<q-btn
v-if="props.row.current === false"
color="warning"
label="回退到此版本"
@click="backVersion(props.row)"
/>
</div>
</q-td>
</template>
</q-table>
</q-card-section>
</q-card>
</q-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, computed, watch } from 'vue';
import { useQuasar, type QTableColumn } from 'quasar';
import {
publishPageQuery,
deletePublish,
saveToDraft,
PublishItem,
setPublishRename,
getPublishHistoryById,
setPublishRelease,
PublishHistoryItem,
fallbackVersion,
} from '../api/PublishApi';
import { useRoute } from 'vue-router';
import { ApiError } from 'src/boot/axios';
import { nextTick } from 'process';
import { DraftDataType } from 'src/api/DraftApi';
import { useAuthStore } from 'src/stores/auth-store';
const route = useRoute();
const $q = useQuasar();
const props = withDefaults(
defineProps<{
sizeHeight: number;
selects?: [];
}>(),
{ sizeHeight: 500, selects: () => [] }
);
const authStore = useAuthStore();
const tableHeight = computed(() => {
return props.sizeHeight - 32;
});
onMounted(() => {
tableRef.value.requestServerInteraction();
selected.value = props.selects;
});
const columnDefs: QTableColumn[] = [
{
name: 'name',
label: '名称',
field: 'name',
required: true,
align: 'center',
},
{
name: 'description',
label: '描述',
field: 'description',
required: true,
align: 'center',
},
{
name: 'userId',
label: '发布人',
field: 'userId',
align: 'center',
},
{
name: 'createdAt',
label: '创建时间',
field: (row) => new Date(row.createdAt).toLocaleString(),
align: 'center',
},
{
name: 'updatedAt',
label: '更新时间',
field: (row) => new Date(row.updatedAt).toLocaleString(),
align: 'center',
},
{ name: 'operations', label: '操作', field: 'operations', align: 'center' },
];
const operateDisabled = ref(false);
const tableRef = ref();
const rows = reactive([]);
const filter = reactive({
name: '',
});
const loading = ref(false);
const pagination = ref({
sortBy: 'desc',
descending: false,
page: 1,
rowsPerPage: 10,
rowsNumber: 10,
});
// eslint-disable-next-line
async function onRequest(props: any) {
const { page, rowsPerPage } = props.pagination;
const filter = props.filter;
loading.value = true;
const variables = {
page: {
page: page,
itemsPerPage: rowsPerPage,
},
query: {
userId: authStore.userId,
dataType: DraftDataType.ISCS,
name: filter.name,
},
};
try {
const response = await publishPageQuery(variables);
pagination.value.rowsNumber = response.total;
pagination.value.page = page;
pagination.value.rowsPerPage = rowsPerPage;
rows.splice(
0,
rows.length,
...(response.items.map((item) => item.releaseData) as [])
);
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.title,
});
} finally {
loading.value = false;
}
}
async function deleteData(row: PublishItem) {
operateDisabled.value = true;
$q.dialog({
title: '确认',
message: `确认删除发布图 "${row.name}" 吗?`,
cancel: true,
})
.onOk(async () => {
try {
await deletePublish(row.id);
tableRef.value.requestServerInteraction(); //
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.title,
});
}
})
.onDismiss(() => {
operateDisabled.value = false;
});
}
function saveToDraftFn(row: PublishItem) {
saveToDraft({
versionId: row.usedVersionId,
userId: row.userId,
})
.then((res) => {
const draftName =
res.data.data.createDraftDataFromReleaseDataVersion.name;
$q.notify({
type: 'positive',
message: `另存草稿成功且草稿图名字为${draftName}`,
});
})
.catch((err) => {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.title,
});
});
}
const isProject = computed(() => {
//
return route.path.includes('dataManage/project');
});
const selected = ref<PublishItem[] | []>([]);
function getSelectedString() {
const nameArr = selected.value.map((item) => {
return item.name;
});
const name = nameArr.join('');
return `已选:${name}`;
}
if (isProject.value) {
const index = columnDefs.findIndex((item) => {
return item.name == 'operations';
});
if (index >= 0) {
columnDefs.splice(index, 1);
}
}
const emit = defineEmits(['selectsed']);
watch(
() => selected.value,
(val) => {
if (val != props.selects) {
emit('selectsed', val);
}
}
);
const errorCalories = ref(false);
const errorMessageCalories = ref('');
function caloriesRangeValidation(val?: string) {
if (val !== undefined) {
if (val.length == 0) {
errorCalories.value = true;
errorMessageCalories.value = '不能为空!';
return false;
}
}
errorCalories.value = false;
errorMessageCalories.value = '';
return true;
}
async function saveRowDataName(row: PublishItem) {
try {
const params = {
id: row.id,
name: row.name,
};
await setPublishRename(params);
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.title,
});
tableRef.value.requestServerInteraction();
}
}
const historyInfoShow = ref(false);
const historyInfo = ref<PublishItem>({
id: 0,
name: '',
dataType: DraftDataType.ISCS,
options: '',
data: '',
usedVersionId: 0,
userId: 0,
isPublished: false,
createdAt: '',
updatedAt: '',
description: '',
});
const historyColumnDefs: QTableColumn[] = [
{
name: 'userId',
label: '发布人',
field: 'userId',
required: true,
align: 'center',
},
{
name: 'createdAt',
label: '发布时间',
field: 'createdAt',
align: 'center',
},
{
name: 'releaseDataId',
label: '版本',
field: 'releaseDataId',
align: 'center',
},
{
name: 'description',
label: '描述',
field: 'description',
required: true,
align: 'center',
},
{ name: 'operations', label: '操作', field: 'operations', align: 'center' },
];
const historyTableRef = ref();
const historyRows = reactive<PublishHistoryItem[]>([]);
const historyLoading = ref(false);
const historyPagination = ref({
sortBy: 'desc',
descending: false,
page: 1,
rowsPerPage: 10,
rowsNumber: 10,
});
async function historyOnRequest(props: any) {
historyLoading.value = true;
const { page, rowsPerPage } = props.pagination;
const variables = {
dataId: historyInfo.value.id,
page: {
page: page,
itemsPerPage: rowsPerPage,
},
};
console.log(page, rowsPerPage);
try {
const response = await getPublishHistoryById(variables);
historyPagination.value.rowsNumber = response.total;
historyPagination.value.page = page;
historyPagination.value.rowsPerPage = rowsPerPage;
historyRows.splice(0, historyRows.length, ...(response.items as []));
} catch (err) {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.title,
});
} finally {
historyLoading.value = false;
}
}
function showHistoryFn(row: PublishItem) {
historyInfo.value = row;
historyInfoShow.value = true;
nextTick(() => {
historyTableRef.value.requestServerInteraction();
});
}
function dataReleaseFn(row: PublishItem) {
if (row.isPublished) {
$q.dialog({
title: '确认',
message: `确定下架发布数据【${row.name}】吗?`,
cancel: true,
}).onOk(() => {
setPublishRelease({ id: row.id, isPublished: !row.isPublished })
.then(() => {
tableRef.value.requestServerInteraction();
})
.catch((err) => {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.title,
});
});
});
} else {
setPublishRelease({ id: row.id, isPublished: !row.isPublished })
.then(() => {
tableRef.value.requestServerInteraction();
})
.catch((err) => {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.title,
});
});
}
}
function backVersion(row: PublishHistoryItem) {
if (!historyInfo.value.id || !row.id) return;
$q.dialog({
title: '确认',
message: `确定把【${historyInfo.value.name}】回退到【${row.releaseDataId}】版本吗?`,
cancel: true,
}).onOk(() => {
fallbackVersion({ mapId: historyInfo.value.id, versionId: row.id })
.then(() => {
$q.notify({
type: 'positive',
message: '回退版本成功!',
});
tableRef.value.requestServerInteraction();
historyInfoShow.value = false;
})
.catch((err) => {
const error = err as ApiError;
$q.notify({
type: 'negative',
message: error.title,
});
});
});
}
</script>

View File

@ -38,7 +38,7 @@ const routes: RouteRecordRaw[] = [
{ {
path: 'iscsPublish', path: 'iscsPublish',
name: 'iscsPublish', name: 'iscsPublish',
component: () => import('pages/PublishManage.vue'), component: () => import('pages/IscsPublishManage.vue'),
meta: { meta: {
label: 'iscs发布数据管理', label: 'iscs发布数据管理',
icon: 'playlist_add_check', icon: 'playlist_add_check',

12
src/stores/auth-store.ts Normal file
View File

@ -0,0 +1,12 @@
import { defineStore } from 'pinia';
export const useAuthStore = defineStore('auth', {
state: () => ({
userId: 1 as number | null,
}),
actions: {
setUserId(id: number | null) {
this.userId = id;
},
},
});