校验name

This commit is contained in:
joylink_zhaoerwei 2024-09-27 14:42:53 +08:00
parent 5c2bca34ee
commit c81a7db6cd
4 changed files with 72 additions and 2 deletions

View File

@ -106,6 +106,25 @@ export async function sharedDraftPageQuery(
return response.data.data.sharedDraftIscsDataPaging; 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 * @param params

View File

@ -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 * @param draftId 稿id

View File

@ -144,6 +144,7 @@
v-model="createForm.draftName" v-model="createForm.draftName"
lazy-rules lazy-rules
:rules="[(val) => val.length > 0 || '请输入名称!']" :rules="[(val) => val.length > 0 || '请输入名称!']"
@blur="checkDraftName"
/> />
<q-select <q-select
v-model="createForm.style" v-model="createForm.style"
@ -189,6 +190,7 @@
v-model="publishForm.pubName" v-model="publishForm.pubName"
lazy-rules lazy-rules
:rules="[(val) => val.length > 0 || '请输入名称!']" :rules="[(val) => val.length > 0 || '请输入名称!']"
@blur="checkPublishName"
/> />
<q-input <q-input
outlined outlined
@ -266,6 +268,7 @@ import {
PagingQueryParams, PagingQueryParams,
iscsStyleOption, iscsStyleOption,
searchTscsStyleOption, searchTscsStyleOption,
draftDataExist,
} from '../api/DraftApi'; } from '../api/DraftApi';
import { ApiError } from 'src/boot/axios'; import { ApiError } from 'src/boot/axios';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
@ -275,6 +278,7 @@ import {
PublishItem, PublishItem,
publishPageQuery, publishPageQuery,
setDefaultPublish, setDefaultPublish,
isReleaseDataNameExists,
} from 'src/api/PublishApi'; } from 'src/api/PublishApi';
import { useAuthStore } from 'src/stores/auth-store'; import { useAuthStore } from 'src/stores/auth-store';
import { PageDto } from 'src/api/ApiCommon'; import { PageDto } from 'src/api/ApiCommon';
@ -436,8 +440,20 @@ const createForm = reactive({
draftName: '', draftName: '',
style: IscsStyle.DA_SHI_ZHI_NENG, style: IscsStyle.DA_SHI_ZHI_NENG,
}); });
const myForm = ref<QForm | null>(null); const myForm = ref<QForm | null>(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() { function onCreate() {
myForm.value?.validate().then(async (res) => { myForm.value?.validate().then(async (res) => {
if (res) { if (res) {
@ -495,6 +511,20 @@ function newPublish(row: DraftItem) {
publishForm.note = ''; 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); const publishNameDisable = ref(false);
function publishToDefault(row: DraftItem) { function publishToDefault(row: DraftItem) {
if (!row.defaultReleaseDataId) { if (!row.defaultReleaseDataId) {
@ -530,6 +560,7 @@ function publishDraftGraphics() {
type: 'positive', type: 'positive',
message: '发布成功', message: '发布成功',
}); });
tableRef.value.requestServerInteraction();
} }
}); });
} else { } else {
@ -546,6 +577,7 @@ function publishDraftGraphics() {
} else { } else {
publishNameDisable.value = false; publishNameDisable.value = false;
publishFormShow.value = false; publishFormShow.value = false;
tableRef.value.requestServerInteraction();
$q.notify({ $q.notify({
type: 'positive', type: 'positive',
message: '发布成功', message: '发布成功',

View File

@ -3,7 +3,7 @@ import { RouteRecordRaw } from 'vue-router';
const routes: RouteRecordRaw[] = [ const routes: RouteRecordRaw[] = [
{ {
path: '/', path: '/',
redirect: '/home/1e2d0d5d96034f4a0805af6512051ddc', redirect: '/home/b82f4bb0398b01263b6ef12764c6eb20',
meta: { meta: {
hidden: true, hidden: true,
}, },