- 新增商家/信息详情页电话拨打接口,支持每日额度限制与拨打日志记录 - 新增平台免责声明内容及协议接口,完善用户服务协议相关配置 - 新增农产品分类图标与上市角标展示,优化分类管理界面样式 - 新增全国行政区划工具类与城市选择组件,重构地区数据结构 - 新增SSH自检与部署脚本,完善项目部署流程
319 行
15 KiB
JavaScript
319 行
15 KiB
JavaScript
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], function ($, undefined, Backend, Table, Form, Format) {
|
||
|
||
/**
|
||
* 解析分类图标/实拍图地址
|
||
* @param {string} iconKey 标识或路径
|
||
* @param {number} id 分类ID
|
||
* @param {string} image 实拍图路径(可选)
|
||
* @returns {string} 完整的静态图片URL
|
||
*/
|
||
function resolveIconUrl(iconKey, id, image) {
|
||
if (image && /^(https?:\/\/|\/uploads\/|\/static\/)/i.test(image)) {
|
||
return image;
|
||
}
|
||
if (!iconKey) {
|
||
iconKey = 'cat-veg';
|
||
}
|
||
if (/^(https?:\/\/|\/uploads\/|\/static\/)/i.test(iconKey)) {
|
||
return iconKey;
|
||
}
|
||
var file = (iconKey.indexOf('.') !== -1) ? iconKey : iconKey + '.png';
|
||
if (iconKey.indexOf('sub-') === 0 || iconKey === 'cat-veg' || iconKey === 'cat-fruit') {
|
||
return '/static/categories/' + file + '?v=2';
|
||
}
|
||
return '/static/icons/' + file + '?v=2';
|
||
}
|
||
|
||
var Controller = {
|
||
index: function () {
|
||
// 初始化表格参数配置
|
||
Table.api.init({
|
||
extend: {
|
||
index_url: 'fc/category/index' + location.search,
|
||
add_url: 'fc/category/add',
|
||
edit_url: 'fc/category/edit',
|
||
del_url: 'fc/category/del',
|
||
multi_url: 'fc/category/multi',
|
||
import_url: 'fc/category/import',
|
||
table: 'fc_category',
|
||
}
|
||
});
|
||
|
||
var table = $("#table");
|
||
|
||
// 初始化表格
|
||
table.bootstrapTable({
|
||
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
||
pk: 'id',
|
||
sortName: 'sort',
|
||
sortOrder: 'asc',
|
||
escape: false,
|
||
columns: [
|
||
[
|
||
{checkbox: true, width: '40px'},
|
||
{
|
||
field: 'id',
|
||
title: __('SerialNo'),
|
||
operate: false,
|
||
sortable: false,
|
||
align: 'center',
|
||
width: '60px',
|
||
class: 'fc-serial',
|
||
table: table,
|
||
formatter: Format.serial
|
||
},
|
||
|
||
// 1. 实拍图预览(大图圆角卡,object-fit:cover 保证「看图识物」效果)
|
||
{
|
||
field: 'image',
|
||
title: '实拍图',
|
||
operate: false,
|
||
align: 'center',
|
||
width: '90px',
|
||
formatter: function (value, row, index) {
|
||
var url = resolveIconUrl(row.icon_key, row.id, row.image);
|
||
var color = row.color || '#00E070';
|
||
return '<div class="fc-img-wrap">' +
|
||
'<div style="display:inline-block;width:60px;height:60px;border-radius:14px;overflow:hidden;background:' + color + '15;border:1px solid ' + color + '40;box-shadow:0 2px 8px rgba(4,48,30,0.08);cursor:zoom-in;">' +
|
||
'<img src="' + url + '" style="width:100%;height:100%;object-fit:cover;display:block;" onerror="this.src=\'/static/categories/cat-veg.png\'" />' +
|
||
'</div>' +
|
||
'<div class="fc-img-zoom"><img src="' + url + '" onerror="this.src=\'/static/categories/cat-veg.png\'" /></div>' +
|
||
'</div>';
|
||
}
|
||
},
|
||
|
||
// 2. 分类名称(含层级缩进,带主题色小圆点)
|
||
{
|
||
field: 'name',
|
||
title: __('Name'),
|
||
operate: 'LIKE',
|
||
align: 'left',
|
||
width: '200px',
|
||
formatter: function (value, row, index) {
|
||
var color = row.color || '#00E070';
|
||
var isSub = Number(row.pid || 0) > 0;
|
||
var dot = '<span style="flex:0 0 auto;display:inline-block;width:10px;height:10px;border-radius:50%;background:' + color + ';margin-right:10px;vertical-align:middle;box-shadow:0 0 6px ' + color + '99;"></span>';
|
||
var nameStyle = isSub
|
||
? 'font-weight:500;font-size:13.5px;color:#475569;'
|
||
: 'font-weight:700;font-size:14px;color:#1e293b;';
|
||
return '<div class="' + (isSub ? 'fc-tree-sub' : '') + '" style="display:flex;align-items:center;">' + dot + '<span style="' + nameStyle + '">' + value + '</span></div>';
|
||
}
|
||
},
|
||
|
||
// 2.5 所属大类
|
||
{
|
||
field: 'parent_name',
|
||
title: '上级分类',
|
||
operate: false,
|
||
align: 'center',
|
||
width: '120px',
|
||
formatter: function (value, row, index) {
|
||
if (!row.pid || Number(row.pid) === 0) {
|
||
return '<span class="label" style="background:#ecfdf5;color:#059669;border:1px solid #a7f3d0;border-radius:6px;padding:3px 8px;font-weight:600;">一级大类</span>';
|
||
}
|
||
return '<span class="label" style="background:#f1f5f9;color:#475569;border-radius:6px;padding:3px 8px;">' + (value || ('#' + row.pid)) + '</span>';
|
||
}
|
||
},
|
||
|
||
// 2.6 分类类型(决定发布页是否显示产地规格字段)
|
||
{
|
||
field: 'kind',
|
||
title: '类型',
|
||
operate: false,
|
||
align: 'center',
|
||
width: '100px',
|
||
formatter: function (value, row, index) {
|
||
if (value === 'farm') {
|
||
return '<span class="label" style="background:#ecfdf5;color:#059669;border:1px solid #a7f3d0;border-radius:6px;padding:3px 8px;font-weight:600;">农产品</span>';
|
||
}
|
||
return '<span class="label" style="background:#eff6ff;color:#2563eb;border:1px solid #bfdbfe;border-radius:6px;padding:3px 8px;">通用信息</span>';
|
||
}
|
||
},
|
||
|
||
// 4. 排序权重
|
||
{
|
||
field: 'sort',
|
||
title: __('Sort'),
|
||
align: 'center',
|
||
width: '110px',
|
||
sortable: true,
|
||
formatter: function (value, row, index) {
|
||
return '<span class="badge" style="background:#eef7f2;color:#04874a;font-weight:700;font-size:13px;padding:4px 10px;border-radius:8px;border:1px solid #bcead1;">' + value + '</span>';
|
||
}
|
||
},
|
||
|
||
// 5. 发布帖子数
|
||
{
|
||
field: 'post_count',
|
||
title: __('Post_count'),
|
||
align: 'center',
|
||
width: '120px',
|
||
sortable: true,
|
||
formatter: function (value, row, index) {
|
||
var count = Number(value || 0);
|
||
var bg = count > 0 ? '#f0fdf4' : '#f8f9fa';
|
||
var text = count > 0 ? '#15803d' : '#888';
|
||
return '<span class="label" style="background:' + bg + ';color:' + text + ';border-radius:8px;padding:4px 10px;font-size:12px;font-weight:600;display:inline-block;">' + count + ' 篇</span>';
|
||
}
|
||
},
|
||
|
||
// 6. 启用状态(原生点击切换开关)
|
||
{
|
||
field: 'enabled',
|
||
title: __('Enabled'),
|
||
align: 'center',
|
||
width: '100px',
|
||
searchList: {0: '已禁用', 1: '已启用'},
|
||
formatter: Table.api.formatter.toggle
|
||
},
|
||
|
||
// 7. 更新时间
|
||
{
|
||
field: 'updatetime',
|
||
title: __('Updatetime'),
|
||
operate: 'RANGE',
|
||
addclass: 'datetimerange',
|
||
autocomplete: false,
|
||
align: 'center',
|
||
width: '180px',
|
||
formatter: Table.api.formatter.datetime
|
||
},
|
||
|
||
// 8. 操作栏
|
||
{
|
||
field: 'operate',
|
||
title: __('Operate'),
|
||
table: table,
|
||
align: 'center',
|
||
width: '120px',
|
||
events: Table.api.events.operate,
|
||
formatter: Table.api.formatter.operate
|
||
}
|
||
]
|
||
]
|
||
});
|
||
|
||
// 为表格绑定事件
|
||
Table.api.bindevent(table);
|
||
},
|
||
|
||
add: function () {
|
||
Controller.api.bindFormInteractions();
|
||
Controller.api.bindevent();
|
||
},
|
||
|
||
edit: function () {
|
||
Controller.api.bindFormInteractions();
|
||
Controller.api.bindevent();
|
||
},
|
||
|
||
api: {
|
||
bindevent: function () {
|
||
Form.api.bindevent($("form[role=form]"));
|
||
},
|
||
|
||
/**
|
||
* 绑定新增与编辑表单的高级可视化交互
|
||
*/
|
||
bindFormInteractions: function () {
|
||
var $iconInput = $('#c-icon_key');
|
||
var $nameInput = $('#c-name');
|
||
var $colorInput = $('#c-color');
|
||
var $colorNative = $('#c-color-native');
|
||
var $colorAddon = $('#color-preview-addon');
|
||
var $previewBadge = $('#preview-badge');
|
||
var $previewIcon = $('#preview-icon');
|
||
var $previewName = $('#preview-name');
|
||
var $currentIconImg = $('#current-icon-img');
|
||
var $iconModal = $('#fc-icon-modal');
|
||
|
||
// 刷新界面预览元素(纯视觉图形,无死板业务文字)
|
||
function updateLivePreview() {
|
||
var name = $nameInput.val() || '未命名分类';
|
||
var key = $iconInput.val() || 'cat-veg';
|
||
var color = $colorInput.val() || '#00E070';
|
||
var iconUrl = resolveIconUrl(key);
|
||
|
||
if ($previewName.length) $previewName.text(name);
|
||
if ($previewIcon.length) $previewIcon.attr('src', iconUrl);
|
||
if ($currentIconImg.length) $currentIconImg.attr('src', iconUrl);
|
||
|
||
if ($previewBadge.length) {
|
||
$previewBadge.css({
|
||
'background': color + '22',
|
||
'border-color': color + '55'
|
||
});
|
||
}
|
||
if ($colorAddon.length) $colorAddon.css('background', color);
|
||
if ($colorNative.length) $colorNative.val(color);
|
||
}
|
||
|
||
// 确保初始状态完全隐藏
|
||
$iconModal.removeClass('open').attr('style', 'display:none !important;');
|
||
|
||
// 1. 打开纯插画挑选面板(只有用户主动点击按钮才打开)
|
||
$(document).on('click', '#btn-open-icon-picker', function (e) {
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
$iconModal.removeAttr('style').addClass('open').fadeIn(150);
|
||
});
|
||
|
||
// 关闭插画挑选面板
|
||
function closeIconModal() {
|
||
$iconModal.removeClass('open').fadeOut(120, function () {
|
||
$(this).attr('style', 'display:none !important;');
|
||
});
|
||
}
|
||
|
||
$(document).on('click', '#btn-close-icon-modal, .fc-modal-overlay', function (e) {
|
||
e.preventDefault();
|
||
closeIconModal();
|
||
});
|
||
|
||
// 2. 点选插画卡片(只设图标,绝不改写用户分类名称)
|
||
$(document).on('click', '.fc-icon-chip', function (e) {
|
||
e.preventDefault();
|
||
var key = $(this).data('key');
|
||
$iconInput.val(key).trigger('change');
|
||
$('.fc-icon-chip').removeClass('active');
|
||
$(this).addClass('active');
|
||
updateLivePreview();
|
||
closeIconModal();
|
||
});
|
||
|
||
// 3. 自定义上传图片监听
|
||
$iconInput.on('input change', function () {
|
||
updateLivePreview();
|
||
});
|
||
|
||
// 4. 监听分类名称输入
|
||
$nameInput.on('input', function () {
|
||
updateLivePreview();
|
||
});
|
||
|
||
// 5. 监听颜色输入与推荐调色板点选
|
||
$colorInput.on('input change', function () {
|
||
updateLivePreview();
|
||
});
|
||
|
||
// 5.1 原生取色器 → 十六进制输入框
|
||
$colorNative.on('input change', function () {
|
||
$colorInput.val($(this).val()).trigger('change');
|
||
});
|
||
|
||
$(document).on('click', '.fc-color-presets .fc-color-dot', function () {
|
||
var color = $(this).data('color');
|
||
$colorInput.val(color).trigger('change');
|
||
updateLivePreview();
|
||
});
|
||
|
||
// 初始化回显
|
||
var initKey = $iconInput.val() || 'cat-veg';
|
||
$('.fc-icon-chip[data-key="' + initKey + '"]').addClass('active');
|
||
updateLivePreview();
|
||
}
|
||
}
|
||
};
|
||
return Controller;
|
||
});
|