Fastadmin 等一些thinkphp5 larval的后台框架程序 bootstraptable 自定义js 实现动态列 的实现方法1 ,通过nginx apache rewrite 重定向
需要实现不定长度的列
fastadmin 为例
表格的实现是
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'supplier/product/index',
add_url: 'supplier/product/add',
edit_url: 'supplier/product/edit',
del_url: 'supplier/product/del',
multi_url: 'supplier/product/multi',
table: 'supplier_product',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'productName', title: __('Productname')},
{field: 'productCode', title: __('Productcode')},
{field: 'productWeight', title: __('Productweight'), operate:'BETWEEN'},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('normal'),"hidden":__('hidden')}},
{field: 'status_text', title: __('Status'), operate:false},
{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();
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'product/attr/value/index',
add_url: 'product/attr/value/add',
edit_url: 'product/attr/value/edit',
del_url: 'product/attr/value/del',
multi_url: 'product/attr/value/multi',
table: 'product_attr_value',
}
});
var table = $("#table");
// 点击添加SKU
$(document).on("click", ".btn-add-sku", function () {
var productCode = $("#c-productCode").val();
if(productCode == ""){
Layer.alert("产品编码不能为空");
}else{
Fast.api.open("product/attr/value/add?productCode=" + productCode, "添加子SKU");
}
});
// 点击添加属性
$(document).on("click", ".btn-add-attribute", function () {
var productCode = $("#c-productCode").val();
if(productCode == ""){
Layer.alert("产品编码不能为空");
}else{
Fast.api.open("product/attribute/add?productCode=" + productCode , "添加商品属性");
}
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'productCode',
sortName: 'productCode',
columns: [
[
{checkbox: true},
{field: 'attr_id', title: __('Attr_id')},
{field: 'attr_price', title: __('Attr_price')},
{
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
formatter: Table.api.formatter.operate
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
对应的是js 。无法实现动态列
实现方法1
apache win10 phpstudy测试
.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^/assets/js/backend/supplier/product.js$ /admin/supplier/product/js
#RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
RewriteRule ^((?!.*product\.js).*)$ index.php?/$1 [QSA,PT,L]
#RewriteRule ^assets/js/backend/supplier/product.js$ /admin/supplier/product/js
#RewriteRule /assets/js/backend/supplier/product.js /admin/supplier/product/js
</IfModule>
nginx 通过 win10 phpstudy测试
vhost.conf
server {
listen 80;
server_name 6.com ;
root "C:/phpStudy/WWW/6.com/fastadmin/public";
location / {
index index.html index.htm index.php;
#autoindex on;
if (!-e $request_filename) {
rewrite ^/assets/js/backend/supplier/product.js$ /admin/supplier/product/js;
rewrite ^((?!product\.js).*)$ /index.php?s=$1 last;
#rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
#include thinkphp5.conf;
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}