diff --git a/application/admin/library/traits/Backend.php b/application/admin/library/traits/Backend.php
index 2c89d442..fbf60115 100644
--- a/application/admin/library/traits/Backend.php
+++ b/application/admin/library/traits/Backend.php
@@ -329,25 +329,35 @@ trait Backend
}
}
+ //导入文件首行类型,默认是注释,如果需要使用字段名称请使用name
+ $importHeadType = isset($this->importHeadType) ? $this->importHeadType : 'comment';
+
$table = $this->model->getQuery()->getTable();
$database = \think\Config::get('database.database');
$fieldArr = [];
$list = db()->query("SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database]);
foreach ($list as $k => $v)
{
- $fieldArr[$v['COLUMN_COMMENT']] = $v['COLUMN_NAME'];
+ if ($importHeadType == 'comment')
+ {
+ $fieldArr[$v['COLUMN_COMMENT']] = $v['COLUMN_NAME'];
+ }
+ else
+ {
+ $fieldArr[$v['COLUMN_NAME']] = $v['COLUMN_NAME'];
+ }
}
$PHPExcel = $PHPReader->load($filePath); //加载文件
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
- $allColumn = $currentSheet->getHighestColumn(); //取得最大的列号
+ $allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行
-
+ $maxColumnNumber = \PHPExcel_Cell::columnIndexFromString($allColumn);
for ($currentRow = 1; $currentRow <= 1; $currentRow++)
{
- for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++)
+ for ($currentColumn = 0; $currentColumn < $maxColumnNumber; $currentColumn++)
{
- $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();
+ $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$fields[] = $val;
}
}
@@ -355,11 +365,10 @@ trait Backend
for ($currentRow = 2; $currentRow <= $allRow; $currentRow++)
{
$values = [];
- for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++)
+ for ($currentColumn = 0; $currentColumn < $maxColumnNumber; $currentColumn++)
{
- $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue(); /* * ord()将字符转为十进制数 */
+ $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$values[] = is_null($val) ? '' : $val;
- //echo iconv('utf-8','gb2312', $val)."\t";
}
$row = [];
$temp = array_combine($fields, $values);
diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php
index 6533529c..fe52d733 100644
--- a/application/common/controller/Backend.php
+++ b/application/common/controller/Backend.php
@@ -77,6 +77,13 @@ class Backend extends Controller
*/
protected $multiFields = 'status';
+ /**
+ * 导入文件首行类型
+ * 支持comment/name
+ * 表示注释或字段名
+ */
+ protected $importHeadType = 'comment';
+
/**
* 引入后台控制器的traits
*/
diff --git a/public/assets/js/require-backend.min.js b/public/assets/js/require-backend.min.js
index 8679e87b..47514b26 100644
--- a/public/assets/js/require-backend.min.js
+++ b/public/assets/js/require-backend.min.js
@@ -9942,9 +9942,9 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
return '
';
},
images: function (value, row, index) {
- value = value.toString();
+ value = value === null ? '' : value.toString();
var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
- var arr = value.toString().split(',');
+ var arr = value.split(',');
var html = [];
$.each(arr, function (i, value) {
value = value ? value : '/assets/img/blank.gif';
@@ -9959,7 +9959,7 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
if (typeof this.custom !== 'undefined') {
colorArr = $.extend(colorArr, this.custom);
}
- value = value.toString();
+ value = value === null ? '' : value.toString();
var color = value && typeof colorArr[value] !== 'undefined' ? colorArr[value] : 'primary';
value = value.charAt(0).toUpperCase() + value.slice(1);
//渲染状态
@@ -9983,6 +9983,7 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
return '' + value + '';
},
flag: function (value, row, index) {
+ value = value === null ? '' : value.toString();
var colorArr = {index: 'success', hot: 'warning', recommend: 'danger', 'new': 'info'};
//如果字段列有定义custom
if (typeof this.custom !== 'undefined') {
@@ -9993,9 +9994,9 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
}
//渲染Flag
var html = [];
- var arr = value.toString().split(',');
+ var arr = value.split(',');
$.each(arr, function (i, value) {
- value = value.toString();
+ value = value === null ? '' : value.toString();
if (value == '')
return true;
var color = value && typeof colorArr[value] !== 'undefined' ? colorArr[value] : 'primary';
@@ -14394,6 +14395,10 @@ define("addtabs", function(){});
if ($(elem.combo_input).attr('placeholder'))
$(elem.combo_input).attr('placeholder_bak', $(elem.combo_input).attr('placeholder'));
}
+
+ if ($(elem.container).parent().hasClass("input-group")) {
+ $(elem.container).height($(elem.container).parent().height());
+ }
this.elem = elem;
};
diff --git a/public/assets/js/require-table.js b/public/assets/js/require-table.js
index 5b5b23b3..251f7444 100644
--- a/public/assets/js/require-table.js
+++ b/public/assets/js/require-table.js
@@ -341,9 +341,9 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
return '
';
},
images: function (value, row, index) {
- value = value.toString();
+ value = value === null ? '' : value.toString();
var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
- var arr = value.toString().split(',');
+ var arr = value.split(',');
var html = [];
$.each(arr, function (i, value) {
value = value ? value : '/assets/img/blank.gif';
@@ -358,7 +358,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
if (typeof this.custom !== 'undefined') {
colorArr = $.extend(colorArr, this.custom);
}
- value = value.toString();
+ value = value === null ? '' : value.toString();
var color = value && typeof colorArr[value] !== 'undefined' ? colorArr[value] : 'primary';
value = value.charAt(0).toUpperCase() + value.slice(1);
//渲染状态
@@ -382,6 +382,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
return '' + value + '';
},
flag: function (value, row, index) {
+ value = value === null ? '' : value.toString();
var colorArr = {index: 'success', hot: 'warning', recommend: 'danger', 'new': 'info'};
//如果字段列有定义custom
if (typeof this.custom !== 'undefined') {
@@ -392,9 +393,9 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
}
//渲染Flag
var html = [];
- var arr = value.toString().split(',');
+ var arr = value.split(',');
$.each(arr, function (i, value) {
- value = value.toString();
+ value = value === null ? '' : value.toString();
if (value == '')
return true;
var color = value && typeof colorArr[value] !== 'undefined' ? colorArr[value] : 'primary';