新增检查所有者模板是否关联域名的api端点及修复全名和标题无法更新的问题
This commit is contained in:
parent
228b5afd78
commit
c1a938226b
@ -110,8 +110,13 @@
|
|||||||
@click="deleteOwner(owner)"
|
@click="deleteOwner(owner)"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
class="text-red-600 hover:text-red-700"
|
:disabled="isTemplateUsed(owner)"
|
||||||
title="删除"
|
:class="[
|
||||||
|
isTemplateUsed(owner)
|
||||||
|
? 'text-gray-400 cursor-not-allowed'
|
||||||
|
: 'text-red-600 hover:text-red-700'
|
||||||
|
]"
|
||||||
|
:title="isTemplateUsed(owner) ? '该模板已关联域名,无法删除' : '删除'"
|
||||||
>
|
>
|
||||||
<Trash2Icon class="h-4 w-4" />
|
<Trash2Icon class="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
@ -511,7 +516,8 @@ export default {
|
|||||||
c_ct_m: '',
|
c_ct_m: '',
|
||||||
c_adr_m: '',
|
c_adr_m: '',
|
||||||
c_pc: ''
|
c_pc: ''
|
||||||
}
|
},
|
||||||
|
templateUsageMap: {} // 新增:存储模板使用状态
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -614,6 +620,39 @@ export default {
|
|||||||
return typeMap[type] || type || '-';
|
return typeMap[type] || type || '-';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 检查模板是否被域名使用
|
||||||
|
isTemplateUsed(owner) {
|
||||||
|
// 从缓存中获取使用状态
|
||||||
|
return this.templateUsageMap[owner.name] || false;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 检查所有模板的使用状态
|
||||||
|
async checkAllTemplateUsage() {
|
||||||
|
if (this.owners.length === 0) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (const owner of this.owners) {
|
||||||
|
const checkRequest = createResource({
|
||||||
|
url: 'jcloud.api.domain_west.check_template_usage',
|
||||||
|
params: { template_name: owner.name },
|
||||||
|
onSuccess: (response) => {
|
||||||
|
if (response && response.status === 'Success') {
|
||||||
|
this.templateUsageMap[owner.name] = response.data.is_used;
|
||||||
|
} else {
|
||||||
|
this.templateUsageMap[owner.name] = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
this.templateUsageMap[owner.name] = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
checkRequest.submit();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// 静默处理错误
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// 获取域名所有者列表
|
// 获取域名所有者列表
|
||||||
async fetchOwners() {
|
async fetchOwners() {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
@ -637,6 +676,7 @@ export default {
|
|||||||
total: response.data.total || 0,
|
total: response.data.total || 0,
|
||||||
pagecount: response.data.pagecount || 0
|
pagecount: response.data.pagecount || 0
|
||||||
};
|
};
|
||||||
|
this.checkAllTemplateUsage(); // 检查所有模板的使用状态
|
||||||
} else {
|
} else {
|
||||||
this.error = response.message || '获取域名所有者列表失败';
|
this.error = response.message || '获取域名所有者列表失败';
|
||||||
}
|
}
|
||||||
@ -768,21 +808,13 @@ export default {
|
|||||||
this.fetchOwners(); // 刷新列表
|
this.fetchOwners(); // 刷新列表
|
||||||
this.closeEditDialog(); // 关闭编辑弹窗
|
this.closeEditDialog(); // 关闭编辑弹窗
|
||||||
} else {
|
} else {
|
||||||
console.error('更新失败 - response:', response);
|
|
||||||
toast.error(response.message || '更新失败');
|
toast.error(response.message || '更新失败');
|
||||||
}
|
}
|
||||||
// 确保在所有情况下都重置 loading 状态
|
// 确保在所有情况下都重置 loading 状态
|
||||||
this.editLoading = false;
|
this.editLoading = false;
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
console.error('=== onError 回调 ===');
|
|
||||||
console.error('error:', error);
|
|
||||||
console.error('error.message:', error.message);
|
|
||||||
console.error('error.response:', error.response);
|
|
||||||
|
|
||||||
const errorMessage = getToastErrorMessage(error);
|
const errorMessage = getToastErrorMessage(error);
|
||||||
console.error('errorMessage:', errorMessage);
|
|
||||||
|
|
||||||
toast.error(errorMessage);
|
toast.error(errorMessage);
|
||||||
this.editLoading = false;
|
this.editLoading = false;
|
||||||
}
|
}
|
||||||
@ -791,11 +823,6 @@ export default {
|
|||||||
editRequest.submit();
|
editRequest.submit();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('=== catch 错误 ===');
|
|
||||||
console.error('catch error:', error);
|
|
||||||
console.error('catch error.message:', error.message);
|
|
||||||
console.error('catch error.stack:', error.stack);
|
|
||||||
|
|
||||||
toast.error('更新失败,请稍后重试');
|
toast.error('更新失败,请稍后重试');
|
||||||
this.editLoading = false;
|
this.editLoading = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3376,6 +3376,44 @@ def update_domain_owner(name, **data):
|
|||||||
setattr(domain_owner, key, value)
|
setattr(domain_owner, key, value)
|
||||||
updated_fields.append(f"{key}: {old_value} -> {value}")
|
updated_fields.append(f"{key}: {old_value} -> {value}")
|
||||||
|
|
||||||
|
# 重新生成完整姓名和标题
|
||||||
|
if 'c_ln_m' in data or 'c_fn_m' in data or 'c_org_m' in data or 'c_regtype' in data:
|
||||||
|
# 获取最新的姓名信息
|
||||||
|
c_ln_m = data.get('c_ln_m', getattr(domain_owner, 'c_ln_m', ''))
|
||||||
|
c_fn_m = data.get('c_fn_m', getattr(domain_owner, 'c_fn_m', ''))
|
||||||
|
c_org_m = data.get('c_org_m', getattr(domain_owner, 'c_org_m', ''))
|
||||||
|
c_regtype = data.get('c_regtype', getattr(domain_owner, 'c_regtype', 'I'))
|
||||||
|
|
||||||
|
# 重新生成完整姓名
|
||||||
|
domain_owner.fullname = c_ln_m + c_fn_m
|
||||||
|
|
||||||
|
# 重新生成标题
|
||||||
|
if c_regtype == 'I': # 个人
|
||||||
|
domain_owner.title = f"{c_ln_m}{c_fn_m}"
|
||||||
|
else: # 企业
|
||||||
|
domain_owner.title = f"{c_org_m}"
|
||||||
|
|
||||||
|
# 重新生成英文姓名(如果中文姓名有变化)
|
||||||
|
if 'c_ln_m' in data or 'c_fn_m' in data:
|
||||||
|
if c_ln_m:
|
||||||
|
last_name_pinyin = ' '.join(lazy_pinyin(c_ln_m))
|
||||||
|
domain_owner.c_ln = last_name_pinyin.title()
|
||||||
|
if c_fn_m:
|
||||||
|
first_name_pinyin = ' '.join(lazy_pinyin(c_fn_m))
|
||||||
|
domain_owner.c_fn = first_name_pinyin.title()
|
||||||
|
|
||||||
|
# 重新生成英文单位名称(如果中文单位名称有变化)
|
||||||
|
if 'c_org_m' in data and c_org_m:
|
||||||
|
org_pinyin = ' '.join(lazy_pinyin(c_org_m))
|
||||||
|
domain_owner.c_org = org_pinyin.title()
|
||||||
|
|
||||||
|
updated_fields.append(f"fullname: 已更新")
|
||||||
|
updated_fields.append(f"title: 已更新")
|
||||||
|
if 'c_ln_m' in data or 'c_fn_m' in data:
|
||||||
|
updated_fields.append(f"英文姓名: 已更新")
|
||||||
|
if 'c_org_m' in data:
|
||||||
|
updated_fields.append(f"英文单位名称: 已更新")
|
||||||
|
|
||||||
# 保存更新,使用 ignore_permissions=True 忽略权限检查
|
# 保存更新,使用 ignore_permissions=True 忽略权限检查
|
||||||
domain_owner.save(ignore_permissions=True)
|
domain_owner.save(ignore_permissions=True)
|
||||||
jingrow.db.commit()
|
jingrow.db.commit()
|
||||||
@ -3445,3 +3483,28 @@ def delete_domain_owner(name):
|
|||||||
return {"status": "Error", "message": f"删除失败: {str(e)}"}
|
return {"status": "Error", "message": f"删除失败: {str(e)}"}
|
||||||
|
|
||||||
|
|
||||||
|
@jingrow.whitelist()
|
||||||
|
def check_template_usage(template_name):
|
||||||
|
"""检查模板是否被域名使用"""
|
||||||
|
try:
|
||||||
|
if not template_name:
|
||||||
|
return {"status": "Error", "message": "模板名称不能为空"}
|
||||||
|
|
||||||
|
# 检查是否有域名使用了这个模板
|
||||||
|
used_domains = jingrow.get_all(
|
||||||
|
"Jsite Domain",
|
||||||
|
{"domain_owner": template_name},
|
||||||
|
["name", "domain"]
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"status": "Success",
|
||||||
|
"data": {
|
||||||
|
"is_used": len(used_domains) > 0,
|
||||||
|
"used_domains": used_domains
|
||||||
|
}
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
return {"status": "Error", "message": f"检查模板使用情况失败: {str(e)}"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user