1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'shop/collect/index' + location.search,
- add_url: 'shop/collect/add',
- edit_url: 'shop/collect/edit',
- del_url: 'shop/collect/del',
- multi_url: 'shop/collect/multi',
- import_url: 'shop/collect/import',
- table: 'shop_collect',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- // {field: 'user_id', title: __('User_id'), formatter: Table.api.formatter.search},
- {
- field: 'user.username',
- title: __('User'),
- operate: 'LIKE',
- formatter: function (value, row, index) {
- // 显示用户头像和用户名
- var avatar = row.user && row.user.avatar ? row.user.avatar : '/assets/img/avatar.png';
- var username = row.user && row.user.username ? row.user.username : '游客';
- var userId = row.user_id || '';
-
- // 处理头像URL
- var avatarUrl = avatar;
- if (avatar && !avatar.startsWith('http') && !avatar.startsWith('//')) {
- avatarUrl = Fast.api.cdnurl ? Fast.api.cdnurl(avatar) : avatar;
- }
-
- return '<div style="display:flex;align-items:center;">' +
- '<img src="' + avatarUrl + '" style="width:40px;height:40px;border-radius:50%;margin-right:10px;" />' +
- '<div>' +
- '<div style="color:#337ab7;font-weight:bold;">' + username + '</div>' +
- '<div style="color:#999;font-size:12px;">ID: ' + userId + '</div>' +
- '</div>' +
- '</div>';
- }
- },
- {field: 'goods.title', title: __('Goods')},
- {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
- {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
- {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|