更新
This commit is contained in:
parent
286c480117
commit
d7695dab77
@ -162,12 +162,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item" style="margin-top: 80px;">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
<div class="layui-form-item" style="margin-top: 80px;">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -299,166 +299,167 @@
|
||||
|
||||
// 获取分类列表
|
||||
function loadCategories() {
|
||||
var categories = {$categories|json_encode|raw};
|
||||
var html = '<option value="">请选择分类</option>';
|
||||
categories.forEach(function (item) {
|
||||
var disabled = item.cid == 0 ? 'disabled' : '';
|
||||
html += '<option value="' + item.id + '" ' + disabled + '>' + item.name + '</option>';
|
||||
if (item.children && item.children.length > 0) {
|
||||
item.children.forEach(function (child) {
|
||||
html += '<option value="' + child.id + '">├─ ' + child.name + '</option>';
|
||||
});
|
||||
}
|
||||
});
|
||||
$('select[name="cate"]').html(html);
|
||||
form.render('select');
|
||||
window.categoryData = categories;
|
||||
}
|
||||
var categories = { $categories| json_encode | raw
|
||||
};
|
||||
var html = '<option value="">请选择分类</option>';
|
||||
categories.forEach(function (item) {
|
||||
var disabled = item.cid == 0 ? 'disabled' : '';
|
||||
html += '<option value="' + item.id + '" ' + disabled + '>' + item.name + '</option>';
|
||||
if (item.children && item.children.length > 0) {
|
||||
item.children.forEach(function (child) {
|
||||
html += '<option value="' + child.id + '">├─ ' + child.name + '</option>';
|
||||
});
|
||||
}
|
||||
});
|
||||
$('select[name="cate"]').html(html);
|
||||
form.render('select');
|
||||
window.categoryData = categories;
|
||||
}
|
||||
loadCategories();
|
||||
|
||||
// 递归查找分类信息的函数
|
||||
function findCategory(categories, targetId) {
|
||||
for (let category of categories) {
|
||||
if (category.id == targetId) {
|
||||
return {
|
||||
parent: null,
|
||||
current: category,
|
||||
total: category.total || 0
|
||||
};
|
||||
}
|
||||
if (category.children && category.children.length > 0) {
|
||||
for (let child of category.children) {
|
||||
if (child.id == targetId) {
|
||||
return {
|
||||
parent: category,
|
||||
current: child,
|
||||
total: child.total || 0
|
||||
};
|
||||
}
|
||||
if (child.children && child.children.length > 0) {
|
||||
const result = findCategory([child], targetId);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
// 递归查找分类信息的函数
|
||||
function findCategory(categories, targetId) {
|
||||
for (let category of categories) {
|
||||
if (category.id == targetId) {
|
||||
return {
|
||||
parent: null,
|
||||
current: category,
|
||||
total: category.total || 0
|
||||
};
|
||||
}
|
||||
if (category.children && category.children.length > 0) {
|
||||
for (let child of category.children) {
|
||||
if (child.id == targetId) {
|
||||
return {
|
||||
parent: category,
|
||||
current: child,
|
||||
total: child.total || 0
|
||||
};
|
||||
}
|
||||
if (child.children && child.children.length > 0) {
|
||||
const result = findCategory([child], targetId);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 监听分类选择变化
|
||||
form.on('select(cate)', function (data) {
|
||||
var selectedId = data.value;
|
||||
if (!selectedId) {
|
||||
$('input[name="number"]').val('');
|
||||
return;
|
||||
}
|
||||
const categoryInfo = findCategory(window.categoryData, selectedId);
|
||||
if (categoryInfo) {
|
||||
var nextNumber = categoryInfo.total + 1;
|
||||
var numberStr = nextNumber.toString().padStart(5, '0');
|
||||
var resourceNumber = categoryInfo.parent ? categoryInfo.parent.number + categoryInfo.current.number : categoryInfo.current.number;
|
||||
resourceNumber += numberStr;
|
||||
$('input[name="number"]').val(resourceNumber);
|
||||
}
|
||||
});
|
||||
// 监听分类选择变化
|
||||
form.on('select(cate)', function (data) {
|
||||
var selectedId = data.value;
|
||||
if (!selectedId) {
|
||||
$('input[name="number"]').val('');
|
||||
return;
|
||||
}
|
||||
const categoryInfo = findCategory(window.categoryData, selectedId);
|
||||
if (categoryInfo) {
|
||||
var nextNumber = categoryInfo.total + 1;
|
||||
var numberStr = nextNumber.toString().padStart(5, '0');
|
||||
var resourceNumber = categoryInfo.parent ? categoryInfo.parent.number + categoryInfo.current.number : categoryInfo.current.number;
|
||||
resourceNumber += numberStr;
|
||||
$('input[name="number"]').val(resourceNumber);
|
||||
}
|
||||
});
|
||||
|
||||
// 配置 wangeditor 编辑器
|
||||
const { createEditor, createToolbar } = window.wangEditor;
|
||||
const editorConfig = {
|
||||
MENU_CONF: {},
|
||||
placeholder: '请输入内容...',
|
||||
onChange(editor) {
|
||||
const html = editor.getHtml();
|
||||
},
|
||||
};
|
||||
editorConfig.MENU_CONF['uploadImage'] = {
|
||||
server: '{:url("index/upload_img")}',
|
||||
fieldName: 'file',
|
||||
maxFileSize: 50 * 1024 * 1024,
|
||||
maxNumberOfFiles: 10,
|
||||
allowedFileTypes: ['image/*'],
|
||||
meta: { token: 'xxx' },
|
||||
metaWithUrl: true,
|
||||
headers: { Accept: 'text/x-json' },
|
||||
timeout: 30 * 1000,
|
||||
onBeforeUpload(file) {
|
||||
console.log('准备上传图片', file);
|
||||
return file;
|
||||
},
|
||||
onProgress(progress) {
|
||||
console.log('上传进度', progress);
|
||||
},
|
||||
onSuccess(file, res) {
|
||||
console.log('上传成功', file, res);
|
||||
},
|
||||
onFailed(file, res) {
|
||||
layer.msg('上传失败:' + res.msg, { icon: 2 });
|
||||
console.log('上传失败', file, res);
|
||||
},
|
||||
onError(file, err, res) {
|
||||
layer.msg('上传出错:' + err.message, { icon: 2 });
|
||||
console.error('上传出错', file, err, res);
|
||||
},
|
||||
customInsert(res, insertFn) {
|
||||
if (res.code === 0 && res.url) {
|
||||
let imageUrl = res.url;
|
||||
if (!imageUrl.startsWith('http')) {
|
||||
imageUrl = 'https://' + imageUrl;
|
||||
}
|
||||
imageUrl = imageUrl.replace(/^https?:\/\/[^\/]+\/admin\/resources\//, 'https://www.yunzer.cn/');
|
||||
insertFn(imageUrl);
|
||||
} else {
|
||||
layer.msg('图片上传失败:' + (res.msg || '未知错误'), { icon: 2 });
|
||||
// 配置 wangeditor 编辑器
|
||||
const { createEditor, createToolbar } = window.wangEditor;
|
||||
const editorConfig = {
|
||||
MENU_CONF: {},
|
||||
placeholder: '请输入内容...',
|
||||
onChange(editor) {
|
||||
const html = editor.getHtml();
|
||||
},
|
||||
};
|
||||
editorConfig.MENU_CONF['uploadImage'] = {
|
||||
server: '{:url("index/upload_img")}',
|
||||
fieldName: 'file',
|
||||
maxFileSize: 50 * 1024 * 1024,
|
||||
maxNumberOfFiles: 10,
|
||||
allowedFileTypes: ['image/*'],
|
||||
meta: { token: 'xxx' },
|
||||
metaWithUrl: true,
|
||||
headers: { Accept: 'text/x-json' },
|
||||
timeout: 30 * 1000,
|
||||
onBeforeUpload(file) {
|
||||
console.log('准备上传图片', file);
|
||||
return file;
|
||||
},
|
||||
onProgress(progress) {
|
||||
console.log('上传进度', progress);
|
||||
},
|
||||
onSuccess(file, res) {
|
||||
console.log('上传成功', file, res);
|
||||
},
|
||||
onFailed(file, res) {
|
||||
layer.msg('上传失败:' + res.msg, { icon: 2 });
|
||||
console.log('上传失败', file, res);
|
||||
},
|
||||
onError(file, err, res) {
|
||||
layer.msg('上传出错:' + err.message, { icon: 2 });
|
||||
console.error('上传出错', file, err, res);
|
||||
},
|
||||
customInsert(res, insertFn) {
|
||||
if (res.code === 0 && res.url) {
|
||||
let imageUrl = res.url;
|
||||
if (!imageUrl.startsWith('http')) {
|
||||
imageUrl = 'https://' + imageUrl;
|
||||
}
|
||||
imageUrl = imageUrl.replace(/^https?:\/\/[^\/]+\/admin\/resources\//, 'https://www.yunzer.cn/');
|
||||
insertFn(imageUrl);
|
||||
} else {
|
||||
layer.msg('图片上传失败:' + (res.msg || '未知错误'), { icon: 2 });
|
||||
}
|
||||
};
|
||||
const editor = createEditor({
|
||||
selector: '#editor-container',
|
||||
html: '<p><br></p>',
|
||||
config: editorConfig,
|
||||
mode: 'default',
|
||||
});
|
||||
const toolbar = createToolbar({
|
||||
editor,
|
||||
selector: '#toolbar-container',
|
||||
config: {},
|
||||
mode: 'default',
|
||||
});
|
||||
}
|
||||
};
|
||||
const editor = createEditor({
|
||||
selector: '#editor-container',
|
||||
html: '<p><br></p>',
|
||||
config: editorConfig,
|
||||
mode: 'default',
|
||||
});
|
||||
const toolbar = createToolbar({
|
||||
editor,
|
||||
selector: '#toolbar-container',
|
||||
config: {},
|
||||
mode: 'default',
|
||||
});
|
||||
|
||||
// 表单提交
|
||||
form.on('submit(formSubmit)', function (data) {
|
||||
var content = editor.getHtml();
|
||||
if (!content || content === '<p><br></p>') {
|
||||
layer.msg('请输入文章内容', { icon: 2 });
|
||||
return false;
|
||||
}
|
||||
var loadIndex = layer.load(2);
|
||||
data.field.content = content;
|
||||
$.ajax({
|
||||
url: '{:url("resources/add")}',
|
||||
type: 'POST',
|
||||
data: data.field,
|
||||
success: function (res) {
|
||||
layer.close(loadIndex);
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
setTimeout(function () {
|
||||
window.location.href = '{:url("resources/lists")}';
|
||||
}, 1000);
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
}
|
||||
}
|
||||
});
|
||||
// 表单提交
|
||||
form.on('submit(formSubmit)', function (data) {
|
||||
var content = editor.getHtml();
|
||||
if (!content || content === '<p><br></p>') {
|
||||
layer.msg('请输入文章内容', { icon: 2 });
|
||||
return false;
|
||||
}
|
||||
var loadIndex = layer.load(2);
|
||||
data.field.content = content;
|
||||
$.ajax({
|
||||
url: '{:url("resources/add")}',
|
||||
type: 'POST',
|
||||
data: data.field,
|
||||
success: function (res) {
|
||||
layer.close(loadIndex);
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
setTimeout(function () {
|
||||
window.location.href = '{:url("resources/lists")}';
|
||||
}, 1000);
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
// 重置按钮点击事件
|
||||
$('button[type="reset"]').on('click', function () {
|
||||
loadCategories();
|
||||
});
|
||||
// 重置按钮点击事件
|
||||
$('button[type="reset"]').on('click', function () {
|
||||
loadCategories();
|
||||
});
|
||||
});
|
||||
|
||||
//返回资源列表
|
||||
|
||||
@ -1046,7 +1046,7 @@
|
||||
}
|
||||
|
||||
.lb-data .lb-caption {
|
||||
font-size: 14px;
|
||||
font-size: 1.3rem;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user