Merge pull request #13732 from dataease/pr@dev-v2@fixExcel

fix: 【数据源】API数据源复制设置了主键的表无法修改主键
This commit is contained in:
xuwei-fit2cloud
2024-12-02 17:06:57 +08:00
committed by GitHub
5 changed files with 38 additions and 2 deletions

View File

@@ -31,6 +31,7 @@ export interface ApiItem {
type: string
deTableName?: string
url: string
copy: boolean
method: string
request: ApiRequest
fields: Field[]
@@ -163,8 +164,12 @@ const rule = reactive<FormRules>({
})
const activeName = ref('table')
const editItem = ref(false)
const copyItem = ref(false)
const copyDs = ref(false)
provide('api-active-name', activeName)
const initApiItem = (val: ApiItem, from, name, edit) => {
copyItem.value = val.copy
copyDs.value = from.copy
activeName.value = name
editItem.value = edit
apiItemList = from.apiConfiguration
@@ -283,10 +288,20 @@ const saveItem = () => {
}
}
}
if (msg !== '') {
if (msg !== '' && !(copyDs.value || copyItem.value)) {
ElMessage.error(t('datasource.primary_key_change') + msg)
return
}
for (let i = 0; i < apiItem.fields.length; i++) {
if (
apiItem.fields[i].primaryKey &&
!apiItem.fields[i].length &&
apiItem.fields[i].deExtractType === 0
) {
ElMessage.error(t('datasource.primary_key_length') + apiItem.fields[i].name)
return
}
}
} else {
for (let i = 0; i < apiItem.fields.length; i++) {
if (
@@ -402,6 +417,22 @@ const disabledFieldLength = item => {
}
}
const disabledSetKey = item => {
if (item.hasOwnProperty('children') && item.children.length > 0) {
return true
}
if (copyItem.value || copyDs.value) {
return false
}
if (editItem.value) {
return true
}
if (!item.checked) {
return true
}
return false
}
const disabledChangeFieldByChildren = item => {
if (apiItem.type == 'params') {
return true
@@ -793,7 +824,7 @@ defineExpose({
<el-checkbox
:key="scope.row.jsonPath"
v-model="scope.row.primaryKey"
:disabled="editItem || !scope.row.checked"
:disabled="disabledSetKey(scope.row)"
>
</el-checkbox>
</template>

View File

@@ -367,6 +367,7 @@ const copyItem = (item?: ApiConfiguration) => {
newItem.deTableName = ''
newItem.serialNumber =
form.value.apiConfiguration[form.value.apiConfiguration.length - 1].serialNumber + 1
newItem.copy = true
const reg = new RegExp(item.name + '_copy_' + '([0-9]*)', 'gim')
let number = 0
for (let i = 1; i < form.value.apiConfiguration.length; i++) {

View File

@@ -39,6 +39,7 @@ interface Form {
id?: string
description: string
type: string
copy: boolean
configuration?: Configuration
apiConfiguration?: ApiConfiguration[]
paramsConfiguration?: ApiConfiguration[]

View File

@@ -156,6 +156,7 @@ export interface ApiConfiguration {
type: string
deTableName: string
method: string
copy: boolean
url: string
status: string
useJsonPath: boolean
@@ -178,6 +179,7 @@ export interface Node {
name: string
createBy: string
creator: string
copy: boolean
createTime: string
id: number | string
size: number

View File

@@ -806,6 +806,7 @@ const handleCopy = async data => {
lastSyncTime
})
datasource.id = ''
datasource.copy = true
datasource.name = t('datasource.copy')
if (datasource.type === 'API') {
for (let i = 0; i < datasource.apiConfiguration.length; i++) {