diff --git a/src/api/DraftApi.ts b/src/api/DraftApi.ts index ce3f216..238a2b2 100644 --- a/src/api/DraftApi.ts +++ b/src/api/DraftApi.ts @@ -106,6 +106,25 @@ export async function sharedDraftPageQuery( return response.data.data.sharedDraftIscsDataPaging; } +/** + * 检查新建的草稿名字是否已有 + * @param id 草稿id + */ +export function draftDataExist(variables: { + dataType: DraftDataType; + name: string; +}) { + const query = ` + query draftDataExist($dataType: DataType,$name: String) { + draftDataExist(dataType: $dataType,name: $name) + } +`; + return api.post('', { + query, + variables, + }); +} + /** * 创建草稿 * @param params diff --git a/src/api/PublishApi.ts b/src/api/PublishApi.ts index 3e0ff64..3edf288 100644 --- a/src/api/PublishApi.ts +++ b/src/api/PublishApi.ts @@ -54,6 +54,25 @@ export function setDefaultPublish(variables: { }); } +/** + * 检查发布的草稿名字是否已有 + * @param id 草稿id + */ + export function isReleaseDataNameExists(variables: { + dataType: DraftDataType; + name: string; +}) { + const query = ` + query isReleaseDataNameExists($dataType: DataType,$name: String) { + isReleaseDataNameExists(dataType: $dataType,name: $name) + } +`; + return api.post('', { + query, + variables, + }); +} + /** * 草稿图发布 * @param draftId 草稿id diff --git a/src/pages/IscsDraftManage.vue b/src/pages/IscsDraftManage.vue index 4db1a1c..b1c191e 100644 --- a/src/pages/IscsDraftManage.vue +++ b/src/pages/IscsDraftManage.vue @@ -144,6 +144,7 @@ v-model="createForm.draftName" lazy-rules :rules="[(val) => val.length > 0 || '请输入名称!']" + @blur="checkDraftName" /> (null); +async function checkDraftName() { + if (!createForm.draftName) return; + const res = await draftDataExist({ + dataType: DraftDataType.ISCS, + name: createForm.draftName, + }); + if (res.data.data.draftDataExist) { + $q.notify({ + type: 'negative', + message: '草稿名字已存在,请换一个名字', + }); + } +} function onCreate() { myForm.value?.validate().then(async (res) => { if (res) { @@ -495,6 +511,20 @@ function newPublish(row: DraftItem) { publishForm.note = ''; } +async function checkPublishName() { + if (!publishForm.draftName) return; + const res = await isReleaseDataNameExists({ + dataType: DraftDataType.ISCS, + name: publishForm.draftName, + }); + if (res.data.data.isReleaseDataNameExists) { + $q.notify({ + type: 'negative', + message: '发布名字已存在,请换一个名字', + }); + } +} + const publishNameDisable = ref(false); function publishToDefault(row: DraftItem) { if (!row.defaultReleaseDataId) { @@ -530,6 +560,7 @@ function publishDraftGraphics() { type: 'positive', message: '发布成功', }); + tableRef.value.requestServerInteraction(); } }); } else { @@ -546,6 +577,7 @@ function publishDraftGraphics() { } else { publishNameDisable.value = false; publishFormShow.value = false; + tableRef.value.requestServerInteraction(); $q.notify({ type: 'positive', message: '发布成功', diff --git a/src/router/routes.ts b/src/router/routes.ts index 5d4a73d..8581e32 100644 --- a/src/router/routes.ts +++ b/src/router/routes.ts @@ -3,7 +3,7 @@ import { RouteRecordRaw } from 'vue-router'; const routes: RouteRecordRaw[] = [ { path: '/', - redirect: '/home/1e2d0d5d96034f4a0805af6512051ddc', + redirect: '/home/b82f4bb0398b01263b6ef12764c6eb20', meta: { hidden: true, },