后端增加资源发布功能

This commit is contained in:
2025-05-16 17:38:54 +08:00
parent fff1a1cb3f
commit 02b21dcc6d
17 changed files with 2653 additions and 94 deletions
+25 -4
View File
@@ -411,10 +411,31 @@
// 更新父级分类选项
var $select = $('select[name="cid"]');
$select.empty().append('<option value="0">顶级分类</option>');
if (data && data.parentOptions) {
data.parentOptions.forEach(function (item) {
$select.append('<option value="' + item.id + '">' + item.name + '</option>');
});
// 获取所有分类作为父级选项
$.ajax({
url: '/admin/article/articlecate',
type: 'POST',
async: false,
success: function (res) {
if (res.code === 0) {
// 当前编辑的分类ID
var currentId = data ? data.info.id : 0;
// 递归构建分类选项
function buildOptions(categories, level) {
categories.forEach(function (category) {
// 不能选择自己或自己的子分类作为父级
if (category.id != currentId) {
var prefix = new Array(level + 1).join('├─ ');
$select.append('<option value="' + category.id + '">' + prefix + category.title + '</option>'); if (category.children && category.children.length > 0) { buildOptions(category.children, level + 1); }
}
});
} buildOptions(res.data, 0);
}
}
});
// 设置选中的父级分类
if (data && data.info.cid) {
$select.val(data.info.cid);
}
// 更新图片预览