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